You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MLX] Probe the usable Metal compiler in Apple CMake presets #22683
buggood first issueGood for newcomersmodule: build/installIssues related to the cmake and buck2 builds, and to installing ExecuTorchmodule: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon
The Apple and pybind presets use xcrun -sdk macosx --find metal. On current Xcode releases this can locate a launcher even when the separately installed Metal Toolchain component is unavailable, so configuration enables MLX and fails later during compilation.
The documentation correction is part of #22620. The preset behavior change is intentionally excluded from that documentation-only PR.
Proposed change
Probe xcrun -sdk macosx metal --version in both presets and update the fallback message to point to xcodebuild -downloadComponent MetalToolchain.
Test plan
Configure on Apple silicon with Xcode and the Metal Toolchain installed; verify MLX remains enabled.
Configure with Xcode but without the Metal Toolchain; verify MLX is disabled cleanly.
I measured this on a GitHub-hosted runner where the Metal Toolchain is genuinely absent,
rather than reasoning about it. Three findings that refine the issue, and one that partly
defends the current probe.
The false positive reproduces end to end, with no stub
$ xcrun -sdk macosx --find metal
rc=0 /Applications/Xcode_27.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metal
$ xcrun -sdk macosx metal --version
rc=1 error: error: cannot execute tool 'metal' due to missing Metal Toolchain; use: xcodebuild -downloadComponent MetalToolchain
Then, on the same machine:
$ cmake --preset macos -B cmake-out
rc=0 # the configure succeeds, no error, no warning
$ grep ^EXECUTORCH_BUILD_MLX cmake-out/CMakeCache.txt
EXECUTORCH_BUILD_MLX:STRING=ON
$ cmake --build cmake-out
rc=65
So the probe at tools/cmake/preset/apple_common.cmake:30 enables MLX, configuration
completes cleanly, and the first sign of trouble is a compile failure much later.
The mechanism: with the component absent, --find metal resolves a launcher shipped
inside Xcode.app (XcodeDefault.xctoolchain/usr/bin/metal). Once the component is
installed, the same command resolves a cryptex-mounted toolchain instead
(/var/run/com.apple.security.cryptexd/mnt/com.apple.MobileAsset.MetalToolchain-.../Metal.xctoolchain/usr/bin/metal)
and metal --version returns 0. --find finds the launcher either way.
metal --version is sufficient as the replacement probe. It returned 1 both for --version and for compiling a trivial .metal, so the probe does not need to fall back
to a real compilation.
The current probe is incomplete rather than wrong
Worth stating, because it changes what the fix is for. The comment at apple_common.cmake:21-24 says the Metal compiler "ships with Xcode, not the Command Line
Tools" and probes in order to degrade gracefully. That case is covered. Under xcode-select -s /Library/Developer/CommandLineTools, measured on two different images:
$ xcrun -sdk macosx --find metal
rc=72 xcrun: error: unable to find utility "metal", not a developer tool or in PATH
So --find metal does catch "no full Xcode". What it misses is the second scenario this
issue is about: full Xcode present, component not installed. The change is additive.
Where the build actually dies, and why configuration stays silent
During MLX's own sub-configure:
-- Building for macOS 14.0
error: error: cannot execute tool 'metal' due to missing Metal Toolchain; use: xcodebuild -downloadComponent MetalToolchain
-- Metal version:
The error lands on stderr, Metal version: comes out empty, and the sub-configure
continues. MLX probes the version through a shell pipe (CMakeLists.txt:217-222 at the
pinned submodule 1f8e74e3f1) whose exit status is tail's, so COMMAND_ERROR_IS_FATAL ANY never sees the failure. Measured in isolation on the same machine: the pipeline
returns 0, the same pipeline with set -o pipefail returns 1, and the execute_process
block replicated through cmake -P returns 0 with an empty version.
The build then fails at the first kernel:
[ 0%] Building arg_reduce.air
error: error: cannot execute tool 'metal' due to missing Metal Toolchain; ...
make[2]: *** [mlx/backend/metal/kernels/arg_reduce.air] Error 1
This is why the check belongs in ExecuTorch's own configure rather than being left to the
sub-build: the sub-build does not report it. I will raise the pipe separately upstream, and
it is not a prerequisite for fixing this issue.
Incidentally, MLX already points at the same command when its JIT preamble step fails. mlx/backend/metal/make_compiled_preamble.sh:48 prints Try running: xcrun -sdk macosx metal --version. The proposed probe is the one the
dependency itself recommends, moved to where it can prevent the failure instead of
explaining it afterwards.
Three smaller things the same runs settled
xcodebuild -showComponent MetalToolchain -json reports status as installed or uninstalled. Useful for a bug report or a doc note, but not a substitute for the probe,
since it says the component is declared installed rather than that the compiler runs.
Probing per target SDK would not help. With the component present, metal --version
returns the same version for -sdk macosx, -sdk iphoneos and -sdk iphonesimulator,
because it is one shared binary. What does discriminate a missing platform is xcrun -sdk iphoneos --show-sdk-path (rc=1, SDK "iphoneos" cannot be located under
Command Line Tools).
The cache entry is a STRING, as EXECUTORCH_BUILD_MLX:STRING=ON above shows. set_overridable_option (tools/cmake/common/preset.cmake:98-106) writes CACHE STRING
while tools/cmake/preset/default.cmake:130 declares the option BOOL. And because that
macro is guarded by if(NOT DEFINED ...), an existing cmake-out keeps ON across a
reconfigure, which is worth a line in the PR description so testers purge their build
directory.
Two other entry points enable MLX without this probe
tools/cmake/preset/mlx.cmake:21 sets EXECUTORCH_BUILD_MLX ON unconditionally, and the
pybind probe (tools/cmake/preset/pybind.cmake:70) is nested inside if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") at line 67. Fixing the two probes leaves --preset mlx-release and a manual -DEXECUTORCH_BUILD_MLX=ON reaching the same late
failure. A single FATAL_ERROR in backends/mlx/CMakeLists.txt, beside the existing
submodule and deployment-target checks, would cover all four paths. Happy to split that
from the preset change if you prefer the narrow fix first.
Reproducing this
Logs for everything above, on both images, before and after installing the component:
The runner label xcode-27 is GitHub-hosted and schedulable from a fork, which makes the
negative case reachable in CI without a dedicated machine. .github/workflows/coreai.yml
already uses it and installs the component explicitly, downloading 838.9 MB, so the image
really does lack it.
Happy to send the preset change, the single check in backends/mlx/CMakeLists.txt, or
both.
Measurements and this write-up were produced with Claude Code.
buggood first issueGood for newcomersmodule: build/installIssues related to the cmake and buck2 builds, and to installing ExecuTorchmodule: mlxIssues related to MLX Backend: Metal-accelerated inference on Apple Silicon
Activity
[docs] Refresh README, runtime APIs, and success stories (#22620)
Mesurer les mécanismes restés en inférence et reproduire pytorch#22683 …
AxelNoun commentedon Oct 6, 2026
I measured this on a GitHub-hosted runner where the Metal Toolchain is genuinely absent,
rather than reasoning about it. Three findings that refine the issue, and one that partly
defends the current probe.
The false positive reproduces end to end, with no stub
Runner
xcode-27(GitHub-hosted, macOS 27.0, Xcode 27.0 / 27A266a).xcodebuild -showComponent MetalToolchain -jsonreports"status": "uninstalled":Then, on the same machine:
So the probe at
tools/cmake/preset/apple_common.cmake:30enables MLX, configurationcompletes cleanly, and the first sign of trouble is a compile failure much later.
The mechanism: with the component absent,
--find metalresolves a launcher shippedinside
Xcode.app(XcodeDefault.xctoolchain/usr/bin/metal). Once the component isinstalled, the same command resolves a cryptex-mounted toolchain instead
(
/var/run/com.apple.security.cryptexd/mnt/com.apple.MobileAsset.MetalToolchain-.../Metal.xctoolchain/usr/bin/metal)and
metal --versionreturns 0.--findfinds the launcher either way.metal --versionis sufficient as the replacement probe. It returned 1 both for--versionand for compiling a trivial.metal, so the probe does not need to fall backto a real compilation.
The current probe is incomplete rather than wrong
Worth stating, because it changes what the fix is for. The comment at
apple_common.cmake:21-24says the Metal compiler "ships with Xcode, not the Command LineTools" and probes in order to degrade gracefully. That case is covered. Under
xcode-select -s /Library/Developer/CommandLineTools, measured on two different images:So
--find metaldoes catch "no full Xcode". What it misses is the second scenario thisissue is about: full Xcode present, component not installed. The change is additive.
Where the build actually dies, and why configuration stays silent
During MLX's own sub-configure:
The error lands on stderr,
Metal version:comes out empty, and the sub-configurecontinues. MLX probes the version through a shell pipe (
CMakeLists.txt:217-222at thepinned submodule
1f8e74e3f1) whose exit status istail's, soCOMMAND_ERROR_IS_FATAL ANYnever sees the failure. Measured in isolation on the same machine: the pipelinereturns 0, the same pipeline with
set -o pipefailreturns 1, and theexecute_processblock replicated through
cmake -Preturns 0 with an empty version.The build then fails at the first kernel:
This is why the check belongs in ExecuTorch's own configure rather than being left to the
sub-build: the sub-build does not report it. I will raise the pipe separately upstream, and
it is not a prerequisite for fixing this issue.
Incidentally, MLX already points at the same command when its JIT preamble step fails.
mlx/backend/metal/make_compiled_preamble.sh:48printsTry running: xcrun -sdk macosx metal --version. The proposed probe is the one thedependency itself recommends, moved to where it can prevent the failure instead of
explaining it afterwards.
Three smaller things the same runs settled
xcodebuild -showComponent MetalToolchain -jsonreportsstatusasinstalledoruninstalled. Useful for a bug report or a doc note, but not a substitute for the probe,since it says the component is declared installed rather than that the compiler runs.
metal --versionreturns the same version for
-sdk macosx,-sdk iphoneosand-sdk iphonesimulator,because it is one shared binary. What does discriminate a missing platform is
xcrun -sdk iphoneos --show-sdk-path(rc=1,SDK "iphoneos" cannot be locatedunderCommand Line Tools).
EXECUTORCH_BUILD_MLX:STRING=ONabove shows.set_overridable_option(tools/cmake/common/preset.cmake:98-106) writesCACHE STRINGwhile
tools/cmake/preset/default.cmake:130declares the optionBOOL. And because thatmacro is guarded by
if(NOT DEFINED ...), an existingcmake-outkeepsONacross areconfigure, which is worth a line in the PR description so testers purge their build
directory.
Two other entry points enable MLX without this probe
tools/cmake/preset/mlx.cmake:21setsEXECUTORCH_BUILD_MLX ONunconditionally, and thepybind probe (
tools/cmake/preset/pybind.cmake:70) is nested insideif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")at line 67. Fixing the two probes leaves--preset mlx-releaseand a manual-DEXECUTORCH_BUILD_MLX=ONreaching the same latefailure. A single
FATAL_ERRORinbackends/mlx/CMakeLists.txt, beside the existingsubmodule and deployment-target checks, would cover all four paths. Happy to split that
from the preset change if you prefer the narrow fix first.
Reproducing this
Logs for everything above, on both images, before and after installing the component:
--findagainst--version, per-SDK, Core AI:https://github.com/AxelNoun/executorch-fork/actions/runs/37382379995
zip, pipefail and Command Line Tools mechanisms:https://github.com/AxelNoun/executorch-fork/actions/runs/37422154581
cmake --preset macosand build:https://github.com/AxelNoun/executorch-fork/actions/runs/37422598615
The runner label
xcode-27is GitHub-hosted and schedulable from a fork, which makes thenegative case reachable in CI without a dedicated machine.
.github/workflows/coreai.ymlalready uses it and installs the component explicitly, downloading 838.9 MB, so the image
really does lack it.
Happy to send the preset change, the single check in
backends/mlx/CMakeLists.txt, orboth.
Measurements and this write-up were produced with Claude Code.