Skip to content

Qwen TTS generation fails 100% with Stream(gpu, 1) not in current thread on Apple Silicon (v0.5.0) #699

Closed

Description

@xinzhuzi

Environment

  • Voicebox v0.5.0 (macOS .app bundle, PyInstaller-packaged)
  • macOS Darwin 25.4.0, arm64 (Apple Silicon, 128 GB RAM)
  • Python 3.12.10 (bundled)
  • mlx==0.31.2, mlx_audio==0.4.1, qwen_tts==0.1.1
  • Model: mlx-community/Qwen3-TTS-12Hz-1.7B-Base-bf16 (downloaded, 4.2 GB)
  • /health reports: backend_type: mlx, backend_variant: cpu, gpu_type: MPS (Apple Silicon), model_loaded: true, gpu_available: true

Symptom

Every generation fails immediately with:

There is no Stream(gpu, 1) in current thread.

The UI stays on "Loading model..." but the SQLite row in voicebox.db is already status=failed. No Python traceback is written to the server log — only the message is captured in the generations.error column.

Reproduction (100% repeatable)

After a clean app start (Ready logged, model loaded), call the API directly:

curl -X POST http://127.0.0.1:17493/generate \
  -H 'Content-Type: application/json' \
  -d '{"profile_id":"<any-existing-profile>","text":"hello","language":"en","engine":"qwen","model_size":"1.7B"}'

Polling /generate/{id}/status flips to failed within ~1 second, every time. Confirmed across multiple profiles, languages (zh/en), and short/long inputs.

Likely root cause

mlx_audio/stt/generate.py:224 (and almost certainly similar code on the TTS path):

generation_stream = mx.new_stream(mx.default_device())

The stream is created on the main/import thread, but inference runs in a uvicorn worker thread (run_in_executor / asyncio.to_thread). MLX streams are thread-local, so the worker thread sees no Stream(gpu, 1) and raises.

Fix direction: either recreate the stream inside the worker thread, or use mlx.core.new_thread_local_stream (added in MLX 0.31).

Suggested follow-ups

  1. Move mx.new_stream into the worker that actually runs inference, or switch to new_thread_local_stream.
  2. Let the exception traceback through to the server log on generation failure — currently the message is silently captured in SQLite only, which makes the issue look like "model still loading" in the UI.
  3. The backend_variant: cpu while backend_type: mlx and gpu_type: MPS reported by /health looks inconsistent and is worth a sanity check.

Workaround

None found from the user side — backend cannot be switched away from MLX in the bundled build, and the error is raised before any inference happens.

Activity

  1. wutijin2 commented on May 25, 2026

    @wutijin2

    我可能也遇到了类似的情况,模型下载了,也创建好声音了,结果生成不了,我说Windows

  2. davidstrouk commented on Jun 23, 2026

    @davidstrouk
    Contributor

    Reproduced 100% on a different chip + newer macOS, which rules out a couple of variables.

    Environment

    • Voicebox v0.5.0 (macOS .app bundle, PyInstaller — same build as the OP, so presumably mlx==0.31.2 / mlx_audio==0.4.1 / qwen_tts==0.1.1; the frozen bundle doesn't expose dist-info to confirm)
    • macOS 26.5.1 (build 25F80) — Darwin 25.5.0, arm64
    • Apple M4 Pro (Mac16,8), 24 GB RAM
    • Model: Qwen3-TTS-12Hz-1.7B, model_loaded: true

    What this adds

    Repro (identical to OP, 100% repeatable)

    curl -s -X POST http://127.0.0.1:17493/generate \
      -H 'Content-Type: application/json' \
      -d '{"profile_id":"<existing>","text":"hello world","language":"en","engine":"qwen","model_size":"1.7B"}'
    # POST returns status:"generating", then within ~1s:
    # GET /generate/{id}/status →
    # data: {"id":"...","status":"failed","duration":0.0,
    #        "error":"There is no Stream(gpu, 1) in current thread.","source":"manual"}

    Corroborating the OP's follow-up #3

    /health here shows the same inconsistency — backend_type: mlx + gpu_type: MPS (Apple Silicon) but backend_variant: cpu:

    {"status":"healthy","model_loaded":true,"model_downloaded":true,"model_size":"1.7B",
     "gpu_available":true,"gpu_type":"MPS (Apple Silicon)","vram_used_mb":null,
     "backend_type":"mlx","backend_variant":"cpu","gpu_compatibility_warning":null}

    Cmd-Q + relaunch did not clear it for the generation path (unlike the recoverable dictation banner in #675) — every /generate fails immediately. The thread-local-stream root cause in the OP matches what we see.

  3. AlexStephenLytton commented on Jul 12, 2026

    @AlexStephenLytton

    Ran into this exact error on a fresh Apple Silicon (M4) setup and tracked it down. Two things going on:

    1. just setup-python doesn't actually install mlx-audio/mlx-lm on Apple Silicon (separate bug, filed as just setup-python doesn't install mlx-audio/mlx-lm — MLX backend fails on fresh Apple Silicon dev setup #823) — worth checking /health's backend_type first; if it says "pytorch" instead of "mlx", that's why, and this specific crash won't apply to you (you're not on the MLX path at all).

    2. Assuming MLX is active: this crash is a thread-affinity issue. mlx_backend.py runs every model load/generate/transcribe call through asyncio.to_thread(), which uses the event loop's default thread pool — nothing guarantees two calls land on the same worker thread. MLX's Metal command encoder/stream is thread-local (bound to whichever thread first touched the GPU device), so if model load and a later generate() end up on different pool threads, MLX raises exactly There is no Stream(gpu, N) in current thread.

    Opened #886 with a fix: pins every MLX call to a single dedicated worker thread instead of the shared pool, plus the missing mlx-lm/mlx-audio install step for #823 (and a /health reporting fix while I was in there — backend_variant never had an mlx branch so it always said "cpu"). Verified on M4 hardware: repeated generations with no crash, and Qwen CustomVoice loads/generates successfully post-fix.

  4. leighton-tidwell commented on Jul 19, 2026

    @leighton-tidwell

    Confirming this on Voicebox 0.5.0 (macOS 26.5.1, Apple Silicon / arm64). Same RuntimeError: There is no Stream(gpu, 1) in current thread. — for us it surfaces in dictation refinement, i.e. the Qwen3 LLM backend, not only TTS:

    backend/routes/captures.py refine_capture_endpoint
      → backend/services/refinement.py refine_transcript
        → backend/backends/qwen_llm_backend.py _generate_sync   (runs via asyncio.to_thread)
          → mlx_lm/generate.py stream_generate → wired_limit → mx.synchronize(s)
    RuntimeError: There is no Stream(gpu, 1) in current thread.
    

    Model loads fine (reproduced with mlx-community/Qwen3-4B-4bit) and only fails once generation starts. #909 looks like the targeted fix for this LLM-backend path (it extends #886 to qwen_llm_backend.py). +1 on getting that merged.

  5. added a commit that references this issue on Oct 4, 2026
    99d05b9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions