Report the MLX backend as unavailable on the iOS simulator - #22336
Open
shoumikhin wants to merge 1 commit into
Open
Report the MLX backend as unavailable on the iOS simulator#22336shoumikhin wants to merge 1 commit into
shoumikhin wants to merge 1 commit into
Conversation
Loading a model that delegates to MLX crashes the process on an iOS simulator instead of failing
cleanly. The demo app in the examples repository crashes on the MLX menu entry, and the llama and
image classifier tests crash with it.
The simulator's Metal device is real enough to build and dispatch a compute pipeline, but two of
the things MLX needs unconditionally are missing from it: `architecture` reports nothing, and a
shared storage heap is refused by an assertion inside Metal. MLX reads the first without a null
check, so it faults during device construction, and if that is bypassed it aborts on the second.
Neither is reachable as an error, so nothing downstream can report it.
`is_available()` is the interface's own answer to whether a backend can run here, and the runtime
already asks before loading a delegate, so returning false is enough to turn the crash into
`Error::NotFound`. MLX's own `is_available()` returns a constant and checks nothing.
Test plan:
The macro decides everything here, so it is checked on all three targets it affects:
simulator TARGET_OS_SIMULATOR 1, is_available() false
device TARGET_OS_SIMULATOR 0, is_available() defers to MLX
macOS TARGET_OS_SIMULATOR 0, is_available() defers to MLX
so a real GPU is unaffected. Compiling the same function with the guard disabled returns true on
the simulator again, which is the crashing path, so the guard is doing the work.
Confirmed separately that a delegate whose backend reports unavailable makes `load_method` return
`Error::NotFound` rather than crash. The include is explicit because an undefined macro is zero in
`#if`, which would make the guard silently do nothing.
This does not make MLX work on the simulator. It makes the answer honest, so a caller gets an
error it can handle.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22336
Note: Links to docs will display an error until the docs builds have been completed. ❌ You can merge normally! (1 Unrelated Failure), 4 Unclassified FailuresAs of commit 825820c with merge base c27baa8 ( UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
Summary
Loading a model that delegates to MLX crashes the process on an iOS simulator instead of failing
cleanly. In the examples repository the demo app crashes on its MLX menu entry, and the llama and
image classifier tests crash with it.
The simulator's Metal device is real enough to build and dispatch a compute pipeline, but two of the
things MLX needs unconditionally are missing from it:
device.architectureThe first faults during device construction. Bypassing it reaches the second, which aborts. Neither
is reachable as an error, so nothing downstream can report it.
is_available()is the interface's own answer to whether a backend can run here, and the runtimealready asks before loading a delegate, so returning false is enough to turn the crash into
Error::NotFound. MLX's ownis_available()returns a constant and checks nothing, which is whythe answer has to come from here.
This does not make MLX work on the simulator. It makes the answer honest, so a caller gets an error
it can handle.
Test plan
The macro decides everything, so it is checked on all three targets it affects:
A real GPU is unaffected. Compiling the same function with the guard disabled returns true on the
simulator again, which is the crashing path, so the guard is doing the work.
Confirmed separately that a delegate whose backend reports unavailable makes
load_methodreturnError::NotFoundrather than crash.The include is explicit because an undefined macro is zero in
#if, which would make the guardsilently do nothing while still compiling.
Follow-ups, not in this change
one. That belongs in the examples repository.
of leaving it untested.