Fix M5 metallib swap silently skipping on source-built (namespace) mlx wheels#18
Merged
Merged
Conversation
…x wheels setup.sh derived the metallib path from mlx.__file__, but on source-built git-SHA dev wheels mlx is a namespace package and mlx.__file__ is None. os.path.dirname(None) raises, _mlx_lib comes back empty, and the [ -f "$_mlx_lib" ] guard skips the swap silently — so the M5 NAX miscompile is detected but the broken metallib is never replaced. Resolve the path from mlx.core (mx.__file__ is always a real .so path), matching the line directly above which already imports mlx.core as mx.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a macOS setup.sh edge case where the M5 metallib swap could be skipped on source-built mlx wheels that use a namespace package layout (where mlx.__file__ can be None). By resolving the mlx.metallib path via mlx.core (which has a concrete __file__), the existing “detect miscompile → swap metallib → re-verify” flow reliably performs the swap when needed.
Changes:
- Resolve
mlx.metalliblocation usingmlx.core as mxinstead of the top-levelmlxpackage. - Align metallib path resolution with the existing version resolution logic that already imports
mlx.core.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
One-line fix in
setup.sh: resolve themlx.metallibpath frommlx.coreinstead of the top-levelmlxpackage, so the M5 NAX metallib swap actually runs on source-built mlx wheels.Why
#15 made the NAX miscompile detector robust across M5 variants (model-sized probe), but the swap that follows it still skipped silently.
On source-built / git-SHA dev wheels (e.g. our fork
0.31.1.dev…+b9effaf6),mlxis a namespace package andmlx.__file__isNone. So:os.path.dirname(None)raisesTypeError_mlx_libcomes back empty[ -f "$_mlx_lib" ]guard skips the entire swap block — no error, no messageNet effect on M5: the miscompile is correctly detected, but the broken source-built metallib is never replaced, so generation stays gray-brown noise. This is exactly the detect-but-no-swap state behind the two most recent reports in #6:
applegpu_g17g) — diagnosed this precisely and verified the fix.cpof the prebuilt metallib works (because the auto-swap never fired).The line directly above (
_mlx_ver) already importsmlx.core as mx; this just brings the metallib-path line in line with it.mx.__file__is always a real.../mlx/core.cpython-*.sopath, namespace package or not.How verified
Per @ramiono on M5 Air (
applegpu_g17g, macOS 26.5, Xcode 26.5 /metalfe-32023.883), clean./setup.shafter the change:Closes the last gap on #6 for source-built wheels. Detection (#15) was already solid; this makes the swap fire.
Credit: diagnosis and on-device verification by @ramiono; ties off @godrm's M5 Pro report.