Skip to content
Discussion options

You must be logged in to vote

Is it safe to run mx.eval(results1) and mx.eval(results2) in separate worker threads at the same time? Supposing embeddings is not changed.

No unfortunately MLX is not in general thread safe at that level.

If you are looking to explicitly multi-thread the eval, the way it is supported in MLX is using two CPU streams. You can make a new stream on the CPU with mx.new_stream(mx.cpu).

Note, not every workload will actually go faster with multi-threading. For example, matmuls use the co-processor and if there is only one, then you won't see much speedup.. so they probably won't get faster.

Here is an example of something which runs almost twice as fast with two streams:

import mlx.core as mx

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by zcbenz
Comment options

You must be logged in to vote
0 replies
Comment options

zcbenz
Sep 30, 2024
Maintainer Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

zcbenz
Oct 1, 2024
Maintainer Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

zcbenz
Oct 1, 2024
Maintainer Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants