Repository navigation
Let audio models load into CPU RAM instead of the GPU - #10054
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. |
|
Found and fixed a real bug in the first version of this while re-checking it, worth flagging since it is exactly the kind of thing that would have bitten after merge. I was reading
Two regression tests cover both directions: a no-opinion call leaves the placement alone, and an explicit change still reloads after one. Also worth recording the scope limit, which has not changed: this covers dictation on all three engines and the native audio TTS models. Audio models that load through the Unsloth backend instead ( |
|
Went through all nine of these against the code rather than taking them at face value. Eight were correct and are now fixed; one I am pushing back on. Details below. FixedTraining guard (P1), GPU arbitration (P1), validate, and the already-loaded shortcut. These are one bug wearing four hats: the placement only ever reached the loader, so every guard above it still treated a CPU audio load as a GPU one. Confirmed each:
All four now go through one MiniMax on CPU. Correct, and my earlier comment saying the backend handles it was wrong. The CUDA check lives inside GGUF TTS (P1). Correct. Deferred device changes. Correct. The control is disabled during a load, generation or recording, since the eject that applies it cannot run then. Training eviction. Correct and worth fixing, since Not takingMTMD device change during an in-flight request. The behaviour is real, but the ChecksTwo new backend test files, 36 cases. I verified the guard tests actually fail without the fix rather than trusting a green run. Broad sweep across stt, audio, mtmd, ggml, training_vram, validate, orchestrator and placement: 3518 passing, 10 failures all confirmed pre-existing on Still not verified: none of this has run on real CUDA hardware, and the UI controls have not been exercised in a browser. |
|
Both of these check out, and both are now fixed. Direct GGUF picks. Correct. Worth noting the variant path was already covered: picking a quant sets CPU native audio during training. Correct, and the precedent is three lines below the bug: the GGUF branch already skips a server whose Checks. 39 backend cases across the two new files, 51 in the audio policy suite, 191 frontend audio and dictation tests. Backend sweep over stt, audio, mtmd, ggml, training, training_vram, validate, orchestrator and placement: 6277 passing against 6274 on Unchanged caveat: none of this has run on CUDA hardware, and the UI has not been exercised in a browser. |
|
Both P1s are real, both were mine, and both are fixed. The first one is the worst thing in this PR so far. Unbound The check now reads the resident entry rather than the requested config, which is both the thing it is actually deciding about and available at that point, so it needs no config. Proven by walking the function AST rather than by eye: before, first read 13192 against first assignment 13271; after, first read follows the assignment. Worth saying plainly why this got through: there is no test anywhere for the non-GGUF already-loaded path. All 17 Over-broad The marker is now written only for a native audio result. I also gated the reader on the audio type, so both sides check it: a stale or wrong marker cannot reach that decision from either direction. That belt-and-braces is deliberate given the failure mode is an OOM rather than a slow load. Verified load-bearing by removing the gate and watching the new test fail. Checks. 41 cases across the two files. Sweep over stt, audio, mtmd, ggml, training, training_vram, validate, orchestrator, placement, already_loaded, reload and reuse: 6549 passing against 6547 on |
|
@codex review |
|
One of these I am declining, and checking it showed that a fix I made last round was built on the same wrong premise, so I have reverted that too. In-flight CPU audio loads: declining, premise does not hold. The claim is that starting training "does not require reclaiming anything" from an in-flight CPU audio load. It does. And that retracts my previous change. The last round's comment made the same argument for the resident case, I accepted "it holds no VRAM" without checking, and it is wrong for the same reason. Rather than keep the exemption with a caveat, I have removed it: the failure mode is training OOMing, and a needless model reload is the much cheaper mistake. Chat-backend teardown is back to what it was before this branch. The STT sidecars keep their exemption, and I checked rather than assumed: Placement stated as fact: correct, fixed. A correction to my own earlier numbers. I have been saying "same failures as main". My baseline runs used 37 cases across the two files after removing the four that covered the reverted exemption. Frontend typechecks, builds, 157 audio tests passing. |
|
Correct, and fixed. The unload API takes Two details I checked while doing it. Passing the nominal engine is fine, since the route maps it through I have deliberately left the three other New test in the source-assertion style this repo already uses for component behaviour, covering the scoped unload and the two places the device preference has to travel. Verified load-bearing by reverting the scoping and watching it fail. Typecheck clean, eslint clean on the file, 204 frontend audio, dictation, stt and voice tests passing. Also noting #10055, the download icon change, merged. |
|
Codex Review: Didn't find any major issues. 👍 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". |
b7ec47a to
526e675
Compare
526e675 to
855c217
Compare
6333825 to
90b687a
Compare
|
Rebased onto main and the conflicts are resolved. Squashed to one commit first so the resolution happened once rather than thirteen times. Three conflicts, all in code main had refactored underneath this branch:
The full suite then turned up a real regression, which is worth spelling out because a targeted run would have missed it. On whether this touches anything else, measured rather than asserted. Full backend suite both sides, 38k tests: exactly one test failed on this branch and not on main, the one above, now fixed. Two failed on main and not here, both in I also exercised the two functions that now run on paths non-audio loads take. After the fix: 7594 passing in the audio, training, placement, context and arbiter sweep, with no failures outside main's known set. Frontend typechecks, builds, strict i18n parity passes, 208 audio, dictation, stt and voice tests pass. |
90b687a to
9f55f1d
Compare
|
Went through the latest round of comments. Six were right and are fixed; one is real but predates this branch, so I left it alone and explained why. FixedPost-load ownership check unloaded the model it had just loaded (the severe one). In the non-GGUF path the check was a bare Already-loaded branch took the arbiter unconditionally. Repeating a load of a resident CPU-placed audio model called CPU GGUF audio loads still declared as GPU-bearing. The load sent The worker took a CUDA context regardless of placement. mtmd dropped the device choice on the training-pinned reuse branch. With training active, an explicit Switching the dictation device could kill a live transcription. The unload defaulted to I also corrected a comment in Not fixed, and whySTT VerificationEvery fix has a test that fails on the pre-fix source and passes after; I checked that both directions rather than just the passing one. The eight new guard tests, plus the mtmd and unload ones, were each run against stashed source to confirm they were not vacuous. One existing test in Full backend suite on this branch and on Standing caveats unchanged from earlier: none of this has run on CUDA hardware, so the masking path in particular is verified by source and by the precedent it copies rather than by execution, and I have not exercised the UI in a browser. |
|
@codex review |
… does not need Three placements a CPU RAM audio load still got wrong. The GGUF codec now loads on CPU, but decoding still asked for CUDA whenever a card existed. The decoders build their input tensors on the device they are handed, so SNAC and DAC failed on a device mismatch and BiCodec moved the codec onto the card, taking the VRAM the mode exists to avoid. The codec manager records where each codec actually went and decoding follows it. That also covers the reuse case, where a codec already resident from an earlier load never moves to the device a later request asked for. Releasing the CHAT claim before the load left a still-resident GPU model unowned, and acquire_for evicts nobody when the arbiter has no owner, so an Images or Video load could allocate straight over it. The release is now handed to load_model, which runs it once the previous worker has exited and its memory is back: after the danger, still ahead of the download that made holding the claim untenable. A worker that will not exit keeps the claim, which is then telling the truth. The export teardown ran unconditionally to free VRAM for the incoming model. A CPU load masks the accelerators and wants none of it, so this was killing a running export for nothing.
…alog's GGUF answer Two ways a CPU RAM choice still ended up on the GPU. whisper.cpp chose between GPU and --no-gpu before publishing _loading. The training hook reads is_loading() without that method's lock, so a switch from a CPU-resident model to Auto landing in that window was invisible to a training run starting concurrently: training saw no load in flight, read the outgoing model's CPU placement, preserved it as holding no VRAM, and the command already built then started a GPU-backed server beside the run. The decision now happens after the flag is published, where the hook cancels the startup and waits for it to settle. The Audio picker identifies some GGUF repos only from the catalog, when no exact variant exists and neither the repo id nor the load id spells gguf. That answer was recomputed from the ids alone at load time and lost, so a CPU RAM load of one omitted gpu_layers: 0 and speculative_type off, and the backend, which ignores audio_device for GGUF, put it on the card. The catalog's answer now travels with the load through both queue points and both staged replays.
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
Measured both sides on the same build. This branch's merge base comes in at 1,560.9 KB transfer, 1.6 KB under the old 1,562.5 KB ceiling; the branch comes in at 1,562.6 KB. The control costs about 1.7 KB of startup transfer and the headroom left was 1.6 KB, so it went over by a tenth of a kilobyte. What actually reaches the first screen is small and none of it is deferrable: the new control's en strings, its persisted voice-settings preference, and the pill-tabs variant. The Audio page and the Voice settings tab are both already split out of the entry, so the page itself costs nothing until it is opened. Raw is untouched, with 126.7 KB still to spare.
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
Two sweeps over the 269 comment lines the branch introduced, down to 132. Section banners and restatements deleted outright; multi-line rationales collapsed to the fact that keeps someone from reintroducing the bug. What survives names a specific mistake: the ordering the whisper.cpp loading flag depends on, why the CHAT claim is dropped mid-load rather than at either end, why the export teardown is gated, and why decoding follows the codec's recorded placement.
|
You have reached your Codex usage limits for security reviews. Please try again later. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 389980df5e
ℹ️ 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".
| <Select | ||
| value={sttDevicePreference} | ||
| onValueChange={(value) => { |
There was a problem hiding this comment.
Disable placement changes while an external STT load is running
When another tab or API client is currently loading this same model, this control remains enabled and the wait: false unload cannot acquire the sidecar lock, so it silently leaves that load running. The handler nevertheless persists the new preference and marks the model on-demand; once the old load finishes, the status poll accepts it as ready without checking placement, leaving a GPU model resident after the user selected CPU until another transcription triggers a reload. Disable the control while the reported sidecar is loading, or arrange a follow-up unload/reload after that load settles.
Useful? React with 👍 / 👎.
What
Audio models currently take an accelerator whenever one is present, and there is no way to ask for anything else. This adds a device preference so the user can keep the weights in CPU RAM instead.
The default is unchanged:
autodetects exactly as it does today. Nothing moves unless someone asks it to.Why
The automatic choice is right until the GPU is the scarce resource:
Whisper and the smaller TTS checkpoints are perfectly usable on CPU, and system RAM is usually the plentiful side. Today the only way to reach CPU is to make the GPU load fail first.
Where the option lives
UNSLOTH_AUDIO_DEVICE=cpuas a server wide default for headless and CLI installs, matching howRAG_EMBED_DEVICEalready works.deviceonSttLoadRequest,TranscribeRequestand/audio/transcribe/raw;audio_deviceonLoadRequest.How
core/inference/audio_device.pynormalises the preference toauto,cpuorgpu. Anything unrecognised falls back toauto, so an unknown value never fails a load.All three audio stacks honour it through the CPU path each one already had for training:
_pick_devicereturns cpu/float32--no-gpu-ngl 0gpuis deliberately not offered in the UI. It differs fromautoonly on a machine with no accelerator, where it cannot be honoured anyway.Two decisions worth review
A resident model under a different preference is reloaded, not reused. The preference is a request about placement, so serving from the old device would make the setting silently do nothing. The Transformers sidecar tracks the preference it loaded under and skips the resident-snapshot shortcut when replacing, since that shortcut answers without a path. A model loaded before this existed records no preference and is still reused, so nobody pays for a reload on upgrade.
A CPU TTS load skips the VRAM preflight. Nothing goes on the card, so there is no free memory to size, reserve or wait for, and sizing it anyway would refuse the load on a full GPU, which is precisely the case this option exists for. It is placed after the Python and adapter guards so those still apply. MiniMax Music 3 is still refused on CPU because its runtime needs CUDA, but the message now says CPU was chosen rather than implying the hardware is missing.
Tests
New
tests/test_audio_device_preference.py, 22 cases covering normalisation, the environment default, CPU winning over a working CUDA, auto and gpu still detecting, the reload-vs-reuse rules, registry forwarding, and the native audio constructor.I also widened several existing test stubs whose fake signatures were narrower than the real interface.
Checked against
mainso the pre-existing failures are not read as new:Not verified
I have not confirmed the two new controls visually in a browser. Everything else above is checked.