Skip to content

Add new_thread_unsafe_stream API#3578

Open
zcbenz wants to merge 1 commit into
ml-explore:mainfrom
zcbenz:thread-unsafe-stream
Open

Add new_thread_unsafe_stream API#3578
zcbenz wants to merge 1 commit into
ml-explore:mainfrom
zcbenz:thread-unsafe-stream

Conversation

@zcbenz
Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz commented May 22, 2026

Add an API to let users create streams that can be freely passed to and evaluated on any thread, but as the API name implies MLX is not applying any synchronization around the streams and it is users' responsibility to ensure there is no race conditions.

This provides a way for language bindings (like Swift) to evaluate graph asynchronously via threads, on the condition that they add locks on themselves. Hopefully after making streams fully thread-safe in future and we would be able to remove this API, but it is going to be very tricky and might not come any time soon.

@zcbenz zcbenz force-pushed the thread-unsafe-stream branch from 188782d to ddd7b95 Compare May 22, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant