← Back to Pull requests

Add experimental ZeroGPU STT, LLM, and TTS handlers #783

Closed
unknown closed this pull request without merging on Nov 13, 2026 13:52 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 10:43 UTC
Author

Adds optional ZeroGPU STT, LLM, and TTS handlers that share a bounded GPU allocation. Existing handlers retain conversation state, history, streaming, and interruption semantics; model inference runs in the allocated worker.

Closes #782.

Scope

  • Register zerogpu backends and optional dependencies.

  • Explicitly initialize model weights before ZeroGPU startup, then warm models inside each allocation. CPU fallback is rejected.

  • Share one allocation across STT, LLM, and TTS, with separate execution lanes so generation and synthesis can overlap.

  • Keep cancellation in the host-side broker; abandoned requests signal the worker without serializing session objects or callbacks.

  • Separate TTS model selection from execution: one model-independent TTS handler supports native Qwen CustomVoice and Kokoro providers.
  • This PR contains no demo changes, Space launcher, deployment scripts, readiness middleware, or browser protocol/UI changes. Those belong to the deployment. The existing private Spaces remain available for integration testing.

    Usage boundary

    A ZeroGPU application must import spaces before CUDA libraries, call speech_to_speech.zerogpu.runtime.initialize(...) before ZeroGPU startup, register the returned worker's decorated lease_worker with its hosting integration, and select the registered zerogpu backends when constructing the pipeline. Selecting the CLI backend alone does not perform this startup sequence.

    runtime.prepare() waits for model warmup; the application decides when to call it and how to display readiness. runtime.prefetch() requests allocation without blocking. Models are selected once per process:

    import spaces
    from speech_to_speech.zerogpu import runtime
    
    worker = runtime.initialize(tts_backend="kokoro")
    # Default: Qwen CustomVoice; optional tts_model and tts_voice.
    

    STT currently uses Parakeet (default nvidia/parakeet-tdt-0.6b-v3), and LLM uses the Transformers causal-model path (tested with Qwen/Qwen3.5-4B). Adding another TTS architecture requires a loading/synthesis provider, not another conversation-side handler.

    Review order

    1. STT/LLM/TTS zerogpu_handler.py files and backend registration.
    2. zerogpu/runtime.py and _tts_provider.py: initialization and model selection.
    3. zerogpu/_worker.py and _model_.py: GPU lifecycle, IPC, and model loading.
    4. tests/test_zerogpu
    .py: lifecycle, cancellation, history, and provider coverage.

    Validation

    Rebased onto main 5108a3ea, including PR #792 and the WebRTC audio-clearing fix. The main ZeroGPU Space is deployed at 4874b621a067b2d44bba4b2fb89771ac0c766c59 with library source at f1a01e12. Its live browser checks passed on desktop and mobile. An automated conversation test cancelled the first response by speech, then verified that the completed reply remembered Alex (1.23 s server E2E).

    251 targeted Python tests passed (ZeroGPU, backend registry, Realtime pipeline builder, latency tracking, and WebRTC). All 62 frontend adapter/WebSocket/WebRTC tests passed. Repository-wide Ruff and formatting checks passed; Mypy passed for 169 source files.

    Real ZeroGPU integration tests used external private Spaces with all three models on CUDA. Qwen and Kokoro both passed automatic turns, interruption, and conversation memory. Individual warm server E2E measurements reached 1.15 s and 1.03 s respectively; these exclude browser playback and are not a controlled model benchmark.

    The simplified cancellation path was also tested in the Qwen lab at d9d5b4dc8c84ef5a00264da1701fe450f23b61df: speech cancelled the first response, the next response remembered Alex, and the second reply measured 1.14 s server E2E. Removing deployment files does not alter that inference implementation. The author also manually tested the deployed demo using a microphone and confirmed that it worked well. That testing covered an earlier deployed revision; the subsequent cancellation refactor was validated with the automated real-ZeroGPU tests described above.

    A regression test reproduces allocation-deadline truncation through the real worker generation function and native LLM handler. Expiry now produces an error terminal with incomplete history, while normal completion and caller abandonment retain their semantics. The independent reviewer rechecked the fix and ran 16 LLM/lease-broker tests successfully.

    The 120-second allocation update passed all 59 ZeroGPU tests and was exercised in the live Space. The deployment uses the existing frontend startup-greeting hook: a browser test confirmed exactly one spoken greeting after model readiness, with generated audio received. Greeting UI/configuration remains outside this library PR.

    Experimental limits

  • Conversation languages are limited to the intersection of the selected STT/TTS models (seven with Parakeet v3 + Qwen TTS); text-only LLM, no background history compaction. All three models load together; deployment tests admit one session.

  • Leases request at most 120 seconds, stop admitting work at 95 seconds, and retire after 15 idle seconds. Renewal can introduce cold-start latency.

  • Host cancellation returns promptly; active native synthesis stops at its next yield boundary.

  • Command files are retained to avoid late-worker/replay races; long-lived deployments need a safe retention policy.

  • TTS support is Qwen CustomVoice and Kokoro. GGML and voice cloning are not claimed.
  • Multilingual follow-up: automatic transcription language metadata and session reset, shared model-language dropdown, 114 routing/pipeline tests passing, and real text language detection checked for all seven enabled languages. Live browser verification confirmed the seven enabled choices plus Auto, accepted a French session selection without protocol errors, and completed a French text-prompt response with generated audio. The startup greeting also passed.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jackboyla Review duration: 14588m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #783"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%