Skip to content

Studio: stop one audio chat from blocking every other chat - #11483

Merged
Lyxot merged 4 commits into
unslothai:mainfrom
NilayYadav:audio-kv-admission-cost
Sep 22, 2026
Merged

Lyxot merged 4 commits into
unslothai:mainfrom
NilayYadav:audio-kv-admission-cost

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

When audio is sent to a GGUF model, Studio treats it as far longer than it is and reserves all of the model's memory for it. Every other chat then waits until the audio reply finishes. In testing, a 20 second recording made a simple "Say hi" wait 32 seconds.

Studio now works out the audio's real length from the file and reserves memory for that length. If the length can't be read, it charges the same as before, so it never reserves too little. Video is unchanged. Tested with two browser tabs on Qwen2.5-Omni-3B: on main the second chat waited, on this branch it answered while the audio was still being processed. This will clash with #10120, which changes the same code.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + reproduction evidence

Pinned head: 83a8e505b657b0db5e4e8e985327a1693614efdb. No P1/P2/P3 findings, and Codex review on the same diff rebased onto current main (2cf72ef227) reported no major issues.

I checked the 25 embeddings/second bound against every audio projector in llama.cpp's current clip_n_output_tokens. qwen2a, music_flamingo and gemma4a/ua top out at 25/s; voxtral, glma, lfm2a, dots3note_a and parakeet at 12.5; qwen3a at 13; granite_speech at ~10; ultravox, meralion and mimo_audio lower still. The Whisper-style preprocessor pads 30 s of silence and cuts 3000-frame windows, so 25 * (seconds + 30) is an upper bound on all of them. The [audio] placeholder in the estimate is also safe: input_audio parts are lifted onto audio_base64 before admission, so the recording is still charged exactly once, including on tool-loop recosts.

GitHub Actions A/B. The same workflow and probe ran on two branches that differ only in studio/backend/routes/inference.py:

  • Fix reverted (expected-failing run): a 5 s and a 20 s 16 kHz WAV are each charged 32768 of 32768, and a concurrent "Say hi" is not admitted. 7 of 11 PR tests fail on the intended assertions (e.g. 20 s of audio reserved 32768 of 32768).
  • PR head (passing run): the same clips are charged 1269 and 1644, and the text chat is admitted alongside. 11/11 PR tests pass, and the 387 admission tests across studio/backend/tests pass too.

End-to-end in the Studio UI. Modal L4, unsloth/Qwen2.5-Omni-3B-GGUF Q4_K_M + mmproj-F16, 4 parallel slots, 16k context, identical llama-server flags on both sides. Tab A sends a 20 s speech recording with a long-answer prompt, and tab B sends "Say hi" while A is still generating:

main 1d8a608 this PR
B wait to first token 30.69 s (40.13 s on a repeat) 0.43 s (0.54 s on a repeat)
B answered while A still generating no yes
Admission log queued ... free=3 then granted-after-wait wait_ms=30077 no queueing

The "before" run queued B even though three slots were free: the only thing holding it back was A's KV reservation.

PR 11483 tab B 8 s after send, before vs after

Full composite (tab B mid/final, tab A at the same moment)

PR 11483 full composite

Conclusion: the bug reproduces on main and the fix is verified, both in CI and end to end. There are no open review items. As the description says, this will conflict with #10120.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed against main that inference.py still charges audio_base64 by base64 length, so one recording reserves the whole KV pool and every other chat queues behind it, and the duration path with the byte-count fallback looks right; note this overlaps #10120 in the same admission code, so please keep an eye on that while I get this reviewed.

@Lyxot Lyxot self-assigned this Sep 22, 2026
… receives

Admission read the duration off the uploaded recording's header, which only wav and mp3 state, so ogg, webm, m4a and flac uploads still fell back to the byte charge and reserved the whole cache. The GGUF path has already converted the upload to the wav/mp3 it forwards by then, so charge that instead.
_wav_seconds trusted nBlockAlign for byte-aligned PCM, which miniaudio ignores, so an inflated value made a ten-minute file read as 0.6 s. That let it past the 30-minute passthrough cap and undercharged its KV admission by about 15K tokens.
@Lyxot

Lyxot commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Staging review + CI for 6a8919815b

I pushed two fixes to this branch and merged the latest main (5e045904c5):

  • 3cfa9fdbb7 Charge admission for the recording llama-server actually receives. The GGUF path has already converted the upload to wav/mp3 before admission runs. Without this, ogg, webm, m4a and flac uploads, whose headers state no length, still fell back to the byte charge: 55K–202K tokens for 20 s, i.e. the whole cache. They now charge about 1378. Adds a route-level test with a WAV and an ogg upload. All existing tests are kept.
  • 0446a576bc _wav_seconds sizes PCM frames the way llama.cpp's decoder (miniaudio ma_dr_wav_get_bytes_per_pcm_frame) does. It used to trust nBlockAlign, so an inflated value made a 10-minute WAV read as 0.6 s. That bypassed the 30-minute passthrough cap and, with the duration charge, undercharged KV by about 15K tokens.

Codex: Didn't find any major issues on staging PR Lyxot#70, whose head is identical (6a8919815b).

CI (staging, same head): 45 passed, 4 skipped, 5 failed. None of the failures involve this change:

  • Repo tests (CPU, studio): the same 12 frontend source-contract failures as on main 5e045904c5 (test_desktop_reliability_frontend_contract.py, test_update_release_notes.py). The failing-test list is identical.
  • Chat UI Tests (chat), Chat UI Tests (Windows), and the Mac Chat UI, API, Update and GGUF inference: the same Update banner Playwright check (2 of 1877) that fails on main.
  • connection (dsh, stable): npm install @deepseek-ai/dsh fails with ETARGET, meaning an upstream package version is missing.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Codex converged on 6a8919815b. The CI failures are the same ones already failing on main, and none of them involve this change.

@Lyxot
Lyxot merged commit aabbadb into unslothai:main Sep 22, 2026
51 of 55 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…#11483)

Charge a recording's KV admission by its duration, not its base64 length, so one audio chat no longer reserves the whole cache. Admission charges the wav/mp3 forwarded to llama-server, so ogg, webm, m4a and flac uploads are measured too, and _wav_seconds sizes PCM frames the way llama.cpp's decoder does.
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.

3 participants