-
Notifications
You must be signed in to change notification settings - Fork 147
guard compile and vmap tracing calls #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- these mutate global state and are not thread safe - fix #337
| // 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course this is mutating global state so it needs to be protected -- it is infrequent enough that it escaped notice for so long.
| evalLock.withLock { | ||
| let closure = new_mlx_closure(f) | ||
| _ = inAxes32.withUnsafeBufferPointer { inAxesBuf in | ||
| mlx_detail_vmap_trace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vmap has a similar call
| assertEqual(gv(x), x * 2) | ||
| } | ||
|
|
||
| func testCompileThreadSafety() async throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repro cases from the issue -- these crash reliably (maybe not 100% because it is a race, but mostly) without the fix.
awni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! We should really fix that in MLX core as well.
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