Fix for MTLLibraryErrorDomain Code=1 "Invalid library file" #4373
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MTLLibraryErrorDomain Code=1 "Invalid library file" is caused by conda.
Conda python binaries are built with a target for older macOS versions. 11.0 for M series and 10.9 for Intel Macs.
Using
otool -L
on the conda python binaries show/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
while the working python binaries (system and homebrew) show/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
.Conda team does not seem to want to change the target anytime soon.
I managed to build a python binary via conda forge with only a target change for 13.3. And the metal compilation works fine.
As this is a conda issue, the PR sets the XCODE_METAL flag to 1 when conda environment is detected and uses xcrun for metal compilation. Also include a message for users about the conda incompatibility. I’ve tested the performance and it is actually faster to use xcrun although the cost is to install the Xcode library.
Those who had already ran tinygrad on conda before will need to clear cache by deleting ~/Library/Caches/tinygrad/cache.db for this to work. So the DISABLE_COMPILER_CACHE flag is no longer required.