Repository navigation
Studio: stop read aloud from waiting on a model catalog rescan - #16831
Merged
danielhanchen merged 2 commits intoNov 6, 2026
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This was referenced Nov 5, 2026
danielhanchen
added a commit
that referenced
this pull request
Nov 6, 2026
…s are added (#16856) ## Summary From 21:00 UTC yesterday until #16809 merged, `Frontend unit tests (Windows)` and `Frontend build + bundle sanity` failed on every frontend PR (#16826, #16829, #16831, #16839, #16854 and others) with the same test: ``` not ok 4712 - family options follow the backend registry, deduplicated, and every backend family has a label location: 'studio/frontend/tests/family-override.test.ts:54:1' + [ [ 'chroma', 'chroma' ], [ 'anima', 'anima' ] ] - [] ``` #16710 added the `chroma` and `anima` image families to the backend registry. That part is fine, and #16809 added the missing picker labels. The test caught it correctly, but on the wrong PR: it reads `diffusion_families.py` and `video_families.py`, yet only Frontend CI runs it, and Frontend CI only triggers on `studio/frontend/**`. So the backend-only PR that added the families never ran it and merged green, and the next frontend PR inherited the failure. ## Change `studio/backend/tests/test_family_override_labels.py`, a new test only. It takes every family name from `diffusion_families._FAMILIES` and `video_families._FAMILIES`, reads the keys of `LABELS` in `family-override.ts`, and fails if a family has no label, naming the missing ones. Backend CI triggers on `studio/**`, so the PR that adds a family now has to add its label too. A second small test pins the `LABELS` parser on quoted (`"flux.1":`) and bare (`sdxl:`) keys, so a reformatted table cannot quietly read as empty. Running Frontend CI on every family registry change would also work, but those files change many times a day and the frontend jobs include Windows and macOS legs. One backend test costs under a second. No product code changes, and the frontend test stays as it is. ## Testing - On main (with #16809): 2 passed. - Deleting `chroma: "Chroma"` from `LABELS` again: fails with `add these families to LABELS in family-override.ts: ['chroma']`. - The file sorts into the existing `a-f` backend shard by glob. `tests/test_ci_backend_pytest_shards.py`: 26 passed.
LeoBorcherding
added a commit
to LeoBorcherding/unsloth
that referenced
this pull request
Nov 6, 2026
danielhanchen
added a commit
to Imagineer99/unsloth
that referenced
this pull request
Nov 7, 2026
…nstead of after the whole reply (unslothai#16955) ## What this fixes A user in the Discord help thread reported that read aloud in chat takes 10 to 20 seconds before it says anything, while the same voice on the Audio › Text to Speech page answers in about half a second. Two separate delays were behind that report: 1. **Finding the speech model.** Before each read, chat looked up which speech model was loaded by asking for the full model catalog (`/v1/models`), which can rescan everything on disk. unslothai#16831 fixed that: it now asks only for loaded models (`/api/inference/loaded-models`, a few milliseconds). 2. **Making the whole reply before playing any of it.** Chat sends the entire reply as one speech request and waits for all of the audio before playing a single word. The Text to Speech page feels fast because you usually give it a sentence or two; a chat reply is often several paragraphs. **This PR fixes that part.** unslothai#16831 removed the wait before the request; this PR removes the wait inside it. Together they cover the report. ## How it works Read aloud now splits the reply into sentences and speaks it in pieces: - The **first piece is one sentence**, so playback starts as soon as that sentence is ready. - While a piece is playing, the **next one is already being made**, so there's normally no gap. - Later pieces bundle sentences together (about 220 characters, never more than 320) so each request isn't too tiny. - **Stop** works at any point: it stops the current audio and nothing further is requested. It uses **the same sentence splitter and chunk planner as voice mode** (unslothai#14084): `voice/tts-chunk-plan.ts` is identical to voice mode's, and `voice/speech-text.ts` carries only `splitIntoSentences` (voice mode's streaming and text-cleanup helpers are not needed here, so they are left to unslothai#14084). Whichever of the two lands second keeps the splitter fixes below. A few splitter cases were fixed here along the way, and should be carried into voice mode's copy too: - initialisms like "the U.S. is" and "e.g., the docs" - a closing quote before a new sentence - names like `llama.cpp`, `config.json` and "J. R. R. Tolkien" - "etc. Then" - a sentence now ends only where `.`, `!` or `?` (plus any closing quote) is followed by whitespace or the end, so `3.5`, `.75`, `.env`, `./train.py`, `llama.cpp` and `D.C.` are never cut, and a stray quote or `...` never becomes a request of its own It covers the "Unsloth model" read-aloud engine (the one that uses a loaded Unsloth Studio speech model). A one-sentence reply is still one request, exactly as before. | Read aloud playing a long reply | Audio › Text to Speech with the same model loaded | |---|---| |  |  | Colab NVIDIA L4, Unsloth Studio at 20719f8, Kokoro 82M loaded. In the server log for this click, the first piece came back 0.95 s after pressing Read aloud, the second right after it, and the third was requested 8.3 s later, the moment the first piece (8.2 s of audio) finished playing. ## Numbers All runs: Colab NVIDIA L4 (22.5 GB), Linux, torch 2.11 + CUDA 13.0. "Before" sends main's single whole-reply request to the same Unsloth Studio backend; this PR only changes the frontend, so the backend is identical either way. ### Time to first audio  Measured at 48de6f3 (latest main with unslothai#16831 and this PR), median of 5 runs after 1 warm-up. The first piece of every reply is byte-identical at 20719f8, and a rerun there gave 0.48 to 0.52 s (Kokoro) and 17.2 to 18.6 s (Orpheus) for the long reply. | model | reply | before | with this PR | |---|---|---|---| | Kokoro 82M (GGUF) | short, 15 words | 0.25 | 0.25 | | | medium, 117 words | 2.48 | 0.37 | | | long, 386 words | 8.03 | 0.50 | | Orpheus 3B (bf16) | short, 15 words | 10.8 | 12.0 (same request, run-to-run noise) | | | medium, 117 words | 96.9 | 10.7 | | | long, 386 words | 106.9 | 18.2 | ### The whole reply, start to finish  Measured at 20719f8, long reply (2,132 characters, 10 pieces), median of 5 runs per model. Playback is modelled from each request's return time and the length of its audio: a piece plays once it has arrived and the one before has finished. | model | | time to hear all of it | speech actually played | |---|---|---|---| | Kokoro 82M | before | 153 s | 145 s | | | with this PR | 146 s | 146 s | | Orpheus 3B | before | 164 s | 47 s (about a third of the reply) | | | with this PR | 339 s, of which about 185 s is pauses | 133 s (all of it) | Two things to know about the slow model (Orpheus on an L4): - **It now speaks the whole reply.** Before, the single request for the long reply ended on its own (finish_reason `stop`) after 32 to 51 s of speech, and the rest, roughly two thirds of the text, was never spoken. With this PR every piece is spoken. - **It pauses between pieces.** Orpheus makes audio slower than it plays on this GPU, so the next piece usually isn't ready yet. The math below shows why, and predicts the pauses to within a few seconds. Kokoro never paused. ### GPU memory  Measured at 20719f8, whole-GPU memory sampled every 100 ms through NVML (what `nvidia-smi` reports) while reading the long reply aloud. Empty GPU before any load: 0 GB. | model | model loaded, idle | peak, before | peak, with this PR | |---|---|---|---| | Kokoro 82M (GGUF) | 0.92 GB | 3.74 GB | 3.61 GB | | Orpheus 3B (bf16) | 6.93 GB | 9.94 GB | 8.83 GB | Speaking in pieces never needs more memory than the single request, and on Orpheus it peaks about 1.1 GB lower, because each request carries a shorter text and generates less audio. Kokoro: 5 runs of each, alternated on one load. Orpheus keeps its high-water mark in PyTorch's cache, so each pattern ran twice from its own fresh load. In an earlier session that alternated the two on one load, the whole-reply requests pushed it to 10.8 and then 11.9 GB, and the pieces never raised it. ## The math Each model makes speech at a fairly steady rate, so a request's time is roughly its length divided by that rate. From every piece request on the L4 (at 48de6f3 and 20719f8, same backend): | | Kokoro 82M | Orpheus 3B | |---|---|---| | synthesis rate (characters made per second) | 252.5 | 6.5 | | speaking rate (characters per second of audio) | 14.4 | 15.8 | | realtime factor (audio seconds per second of work) | 17.5x | 0.41x | **Time to first audio ≈ characters in the first request ÷ synthesis rate.** Before, the first request is the whole reply; now it's one sentence. | | before: predicted / measured | with this PR: predicted / measured | |---|---|---| | Kokoro, medium | 596 ÷ 252.5 = 2.4 s / 2.48 s | 56 ÷ 252.5 = 0.22 s / 0.37 s | | Kokoro, long | 2,132 ÷ 252.5 = 8.4 s / 8.03 s | 137 ÷ 252.5 = 0.54 s / 0.50 s | | Orpheus, medium | 596 ÷ 6.5 = 92 s / 96.9 s | 56 ÷ 6.5 = 8.7 s / 10.7 s | | Orpheus, long | 2,132 ÷ 6.5 = 330 s / **106.9 s** | 137 ÷ 6.5 = 21 s / 18.2 s | The one miss is the point: the long Orpheus request should have taken about 330 s, but it stopped early. Its 43 to 51 s of audio at 0.41x realtime is 105 to 125 s of work, which is what was measured. **Why a model below 1x realtime pauses.** Piece *n+1* is requested when piece *n* arrives. If the model can't keep up, piece *n* starts playing the moment it arrives, so the gap before piece *n+1* is pause ≈ time to make piece *n+1* − time to play piece *n* and there's no pause when that comes out negative. With a realtime factor *r*, making a piece takes (its audio length) ÷ *r*, so for two pieces of similar size the pause is about (audio length) × (1/*r* − 1). - **Orpheus, r = 0.41:** a typical 220-character piece plays for 220 ÷ 15.8 = 13.9 s and takes 220 ÷ 6.5 = 34 s to make, so each pause is about 20 s (13.9 × 1.44). Doing this piece by piece on the long reply predicts pauses of 36.5, 19.2, 17.5, 20.0, 23.7, 17.7, 12.7, 37.6 and 0 s, 185 s in all; the runs measured 184 to 189 s. The last pause is 0 because the final piece (81 characters) is short enough to be made while the 313-character piece before it plays. Total: 21 s to first audio + 135 s of speech + 185 s of pauses ≈ 341 s, against 332 to 342 s measured. - **Kokoro, r = 17.5:** even the largest piece (320 characters) takes 1.3 s to make, while the shortest piece before it plays for 9.5 s, so it never pauses and finishes in about the length of the speech (146.5 s for 146 s of audio). In general there's no pause when the next piece is no more than *r* times the length of the current one. Kokoro has 17x headroom; Orpheus on an L4 has none. The model lookup that unslothai#16831 replaced took 0.07 to 2.9 s on this VM, against 3 to 5 ms now. That box had only a couple of models on disk, so it understates what a full model folder costs. ## Tests `tests/read-aloud-sentence-chunks.test.ts` (new) covers: - how a reply is split into pieces - that a one-sentence reply is one request - that playback starts before the rest is ready - that Stop requests nothing further - the splitter cases above The existing read-aloud tests are updated to load the shared splitter. --------- Co-authored-by: Daniel Han <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the "Unsloth model" read-aloud engine, Read aloud in chat can take seconds longer than Generate on the Audio page for the same text and the same loaded speech model. A user on Discord reported 10 to 20 s in chat against about half a second on the Audio page.
Cause
Before every utterance,
generateStudioTtsAudiolooks up the loaded speech model withGET /v1/models(resolveReadAloudModel, added in #14191) so it can name it in/audio/generate./v1/modelslists every downloaded model, and the scan behind it is cached for only 30 s (_CATALOG_TTL_S). A click more than 30 s after the last listing, which is the usual case for reading a finished reply, waits for a full rescan of the downloaded models. The Audio page never lists the catalog, so it does not pay this cost. Auto read-aloud and the Settings › Voice preview use the same function and wait the same way.Fix
Read aloud now lists models from
GET /api/inference/loaded-models, which #10728 added so agent startup would not wait on the same scan. Its rows are the same_openai_model_objectsentries that/v1/modelsmarksloaded: true, includingtaskandaudio_workflowsfor a speech model kept beside the chat model, so the chosen model id does not change.There are no backend changes. The "Custom endpoint" engine and system voices do not use this lookup and are unchanged. If the reporter was using "Custom endpoint", this PR does not address their delay.
Not addressed: the same report says auto read-aloud does not speak a scheduled task's reply when the chat is opened.
AutoReadAloudonly speaks a reply that finishes while the chat is open, which is how it treats every chat opened from history. Speaking unread scheduled results on open would need a separate product decision.Verification
Live on
origin/main(16060aba73) with a CPU-only Studio,gemma-4-E2B-itQ4_K_M as the chat model and Kokoro-82M loaded beside it. I sent the request sequence the adapter sends (the listing, then/audio/generatenaming the speech model it found), waiting 35 s before each one. Listing time:/v1/models(main)/api/inference/loaded-models(this PR)Generation took about 9 s on both (Kokoro on the CPU). Both listings returned the same loaded rows, and every response came from Kokoro.
read-aloud-studio-voice.test.tsnow serves the loaded-models listing, and a new test checks that read aloud never requests/v1/models. It fails on main.tts-custom-connections-disabled.test.tsmocks the new path.