You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Server crashes with 'There is no Stream(gpu, 0) in current thread' on mlx 0.31.2 #1181
mlx_lm.server crashes on the first request with RuntimeError: There is no Stream(gpu, 0) in current thread when running with mlx 0.31.2.
mlx 0.31.2 made streams thread-local (ml-explore/mlx#3281, ml-explore/mlx#3405). The module-level generation_stream in generate.py is created at import time on the main thread, but BatchGenerator.next() uses it from the server's worker thread (Thread-2 (_generate)). Streams created on one thread can no longer be used from another.
Send any chat completion request. The server returns 200 but the generation thread crashes:
Exception in thread Thread-2 (_generate):
File "mlx_lm/server.py", line 825, in _generate
prompt_responses, gen_responses = batch_generator.next()
File "mlx_lm/generate.py", line 1847, in next
return self._next()
File "mlx_lm/generate.py", line 1833, in _next
self._prompt_batch.prompt(prompts)
File "mlx_lm/generate.py", line 1161, in prompt
mx.eval([c.state for c in self.prompt_cache])
RuntimeError: There is no Stream(gpu, 0) in current thread.
Root cause
generate.py:226 creates a module-level stream on the main thread:
Activity
angeloskath commentedon Apr 22, 2026
Closing like the other 2 issues.