Merged
Conversation
- these mutate global state and are not thread safe - fix #337
davidkoski
commented
Jan 16, 2026
| // but will be able to re-evaluate with fresh state if needed | ||
| evalLock.lock() | ||
| var compiled = mlx_closure_new() | ||
| mlx_detail_compile(&compiled, innerClosure, id, shapeless, [], 0) |
Collaborator
Author
There was a problem hiding this comment.
Of course this is mutating global state so it needs to be protected -- it is infrequent enough that it escaped notice for so long.
davidkoski
commented
Jan 16, 2026
| evalLock.withLock { | ||
| let closure = new_mlx_closure(f) | ||
| _ = inAxes32.withUnsafeBufferPointer { inAxesBuf in | ||
| mlx_detail_vmap_trace( |
Collaborator
Author
There was a problem hiding this comment.
vmap has a similar call
davidkoski
commented
Jan 16, 2026
| assertEqual(gv(x), x * 2) | ||
| } | ||
|
|
||
| func testCompileThreadSafety() async throws { |
Collaborator
Author
There was a problem hiding this comment.
Repro cases from the issue -- these crash reliably (maybe not 100% because it is a race, but mostly) without the fix.
Merged
4 tasks
awni
approved these changes
Jan 22, 2026
Member
awni
left a comment
There was a problem hiding this comment.
Thanks! We should really fix that in MLX core as well.
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.
Proposed changes
Please include a description of the problem or feature this PR is addressing. If there is a corresponding issue, include the issue #.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes