Request MSL 4.1 from the runtime compiler on macOS 27 - #4052
Merged
Conversation
The runtime Metal compiler on macOS 27 accepts language version 4.1 (e.g. int2b_format tensor operands compile and execute), but get_metal_version() had no macOS 27 branch, so every metal_kernel JIT compile was capped at MSL 4.0 and 4.1-only features were unreachable through MLX even on an OS that supports them. metal-cpp_26 predates the LanguageVersion4_1 enum, so the value is spelled with MTLLanguageVersion's (major << 16) + minor encoding.
zcbenz
force-pushed
the
msl-4.1-macos-27
branch
from
August 8, 2026 01:40
23206d7 to
d50b94e
Compare
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
get_metal_version()has no macOS 27 branch, so everymx.fast.metal_kernelJIT compile iscapped at MSL 4.0 — even on macOS 27, whose runtime compiler supports MSL 4.1. This makes
4.1-only features (notably
metal::int2b_formattensor operands for MetalPerformancePrimitivesmatmul2d) unreachable through MLX on an OS that executes them fine.This PR adds the availability branch, gated at macOS/iOS/tvOS/visionOS 27, so released OSes are
unaffected.
One spelling note:
metal-cpp_26.zip(the version pinned in CMakeLists) predates theLanguageVersion4_1enum, so the value is written withMTLLanguageVersion's documented(major << 16) + minorencoding and a comment. Happy to switch toMTL::LanguageVersion4_1once Apple publishes metal-cpp_27 (404 as of today) if you'd rather wait for that.
Why it's real (measured, not inferred)
On macOS 27.0 beta (build 26A5388g, M5):
matmul2dkernel with anint2b_formatweight operand throughMTLDevice newLibraryWithSource:options:withlanguageVersion = 4.1succeeds andexecutes bit-exactly against an integer reference (ternary-valued weights, exact
representation,
max_abs_diff = 0) — on a machine with no developer tools installed;the OS runtime compiler alone does this.
mx.fast.metal_kernelfails withno type named 'int2b_format' in namespace 'metal'and reports__METAL_VERSION__400,because MLX pins the request to 4.0.
(
invalid value 'metal4.1' in '-std=metal4.1'), so gating at 27 is correct — there is no4.1 anywhere below it.
With this patch (wheel built from this branch), the identical
metal_kernelsource compiles atJIT on macOS 27 and reports
__METAL_VERSION__410; behavior on macOS 26.x is unchanged(falls through to the
LanguageVersion4_0branch, verified). The patch builds with thereleased toolchain (Xcode 26.5 SDK, no beta toolchain required) —
__builtin_availableresolves the macOS 27 branch at runtime.
Minimal repro (macOS 27)
Context
Found while measuring 2-bit weight formats for LLM inference on M5: with the runtime capped at
4.0, int2b weights (half the bytes of int4b at parity throughput through the same MPP kernels
in our measurements) can only be used via pre-compiled metallibs or direct Metal API calls,
not through MLX's JIT path.