Skip to content

Studio: keep the chat model loaded when an API request loads a speech model - #14369

Merged
danielhanchen merged 7 commits into
mainfrom
studio-api-speech-beside-chat
Oct 21, 2026
Merged

danielhanchen merged 7 commits into
mainfrom
studio-api-speech-beside-chat

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #14320

Summary

With Keep multiple models loaded set to When they fit or Always, a speech model loaded from the Audio page already stays beside the chat model (#14191). An API request does not. When /v1/audio/speech names a speech model while a chat model is loaded:

  • Always: the request is refused with Loading this model would unload the chat model ..., and Keep multiple models loaded is set to Always.
  • When they fit: the speech model replaces the chat model, and the next chat request swaps them back.

The same happens in the other order, a chat request naming the chat model while a speech model is loaded.

The automatic load behind API requests always loaded into the primary seat. It never asked for a kept slot the way the Audio page and the chat auto-load do with alongside.

Changes

  • Under When they fit or Always, when the requested model and the loaded one are different kinds (speech vs text), the automatic load now goes through load_model_gated with alongside=True. That is the same path POST /load uses: the kept slot, the fit checks, unloading idle models first under When they fit, and the refusal under Always when the new model does not fit. The request is then served from the new slot.
  • Off is unchanged. So is a request naming another model of the same kind: a second chat model still replaces the chat model, and a second speech model still replaces the speech model.
  • load_model_gated and _run_tracked_load_model_impl take an optional impl_kwargs, so the speech codec staging the switch prepares still reaches the load.

Testing

Kaggle T4x2, both Studios installed with install.sh --local from main 4b8447f63a (base on GPU0, base plus this change on GPU1). Chat model unsloth/Qwen3.5-2B-GGUF Q4_K_M, speech model audio-cpp/audio.cpp-gguf/Kokoro-82M-GGUF through the API. "Serving" is what /api/inference/status reports.

Mode Scenario main this PR
When they fit chat loaded, then /v1/audio/speech 200, serving only Kokoro 200, serving Qwen and Kokoro
When they fit then /v1/chat/completions, then speech again 200 / 200, chat reloaded, then Kokoro reloaded 200 / 200, no reload
When they fit speech first, then chat serving only Qwen serving Kokoro and Qwen
Always chat loaded, then /v1/audio/speech 409 (the error in the issue) 200, serving Qwen and Kokoro
Always speech first, then chat chat 409 200, serving Kokoro and Qwen
Off chat loaded, then /v1/audio/speech speech model replaces chat unchanged
any Audio page load with alongside: true both kept unchanged

The clips are the same size on both sides (106844, 75644 and 72044 bytes).

Unit tests in tests/test_openai_auto_switch.py:

  • A speech switch under When they fit and Always loads beside a chat model.
  • A chat switch loads beside a speech model.
  • Off, or a second speech model, still replaces the primary.

The three beside cases fail on main. test_openai_auto_switch.py, test_multi_model_always.py and test_multi_model_serving.py all pass (965 passed). The 65 backend test files that touch the changed functions pass too. The 5 failures under -n 24 also pass serially on both main and this branch, so they are parallel-run flakes.

Before / after

Colab T4, both Studios built with install.sh --local (main 4b8447f63 and this PR at c74df642c), Keep multiple models loaded set to When they fit. One /v1/chat/completions request naming unsloth/Qwen3.5-2B-GGUF, then one /v1/audio/speech request naming audio-cpp/audio.cpp-gguf/Kokoro-82M-GGUF, then the loaded-models card on the chat page.

Loaded models card after an API chat request and then an API speech request: main lists only Kokoro, this PR lists Qwen and Kokoro

The same run on the final head repeats the table above: under When they fit and Always both models stay served in either order, Off still replaces, and the Kokoro clips are the same size on both sides (121244 bytes).

@danielhanchen danielhanchen self-assigned this Oct 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T08:09:04.677933Z 250b5fa Manual request
🔒 Security Review ⚠️ Failed 2026-10-20T15:10:57.244617Z
We couldn’t complete this review. Comment @codex security review to try again.
3e9b163 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e9b16391b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/backend/routes/inference.py Outdated
async with model_load_gate(), inference_lifecycle_gate():
# A load kept beside the primary goes through load_model_gated, which takes the
# load gate itself and leaves the primary serving while it loads.
beside = await asyncio.to_thread(_switch_loads_beside, require_speech)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Decide alongside placement under the load gate

When a concurrent manual /load changes the primary model after this check but before load_model_gated acquires model_load_gate, beside describes the old primary. For example, a speech request can observe a text primary, then a manual load can replace it with another speech model; the request still submits alongside=True, so _select_load_slot keeps two speech models instead of replacing the now-current one and may even return an Always-mode fit refusal that replacement would avoid. Re-evaluate the primary's kind while holding the load gate that selects the slot.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: it needs a manual /load to land in the window between the check and the gate, and the result is a second speech model kept under Keep multiple models loaded (When they fit unloads idle ones if short), not a lost or wrong load.

… cancel, refuses cached copies and waits for running chats

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…t cancel into the load attempt, refuse an unreserved kept slot, recheck the sidecar after the drain

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 250b5fad7e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 21, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 21, 2026
@danielhanchen
danielhanchen merged commit 00cf280 into main Oct 21, 2026
@danielhanchen
danielhanchen deleted the studio-api-speech-beside-chat branch October 21, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Loading TTS model unloads the chat model

1 participant