Repository navigation
Studio: shrink and cap the context when respawning after a GPU OOM - #18920
Conversation
After a served GPU OOM the reload adds 1024 MiB of headroom per strike, but only to --fit-target. A Studio-planned load runs with --fit off and never passes --fit-target, so the respawn relaunched the same -c that had just run out of memory (#18757: 162048 -> 162048). Subtract the headroom from the planner's usable VRAM as well, so each strike frees about 1 GiB of context.
Codex Review Summary: ✅ CompletedThis 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. |
[skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
The headroom can push a one-card plan onto more cards, where Auto then filled them with a far bigger context than the load that ran out of memory (2x24 GiB: 23808 -> 383744). A respawn after a GPU OOM now plans its Auto context no larger than the crashed child's; a fixed -c and first loads are unchanged.
With the headroom moving a one-card plan onto two cards, Auto found room for the DSpark drafter it had dropped for ngram-mod and loaded it in the recovery, a new memory consumer right after an out-of-memory crash. While a GPU OOM strike stands, Auto keeps the drafter off if the crashed load ran without one; a user-chosen drafter is unchanged. The slot re-fit's context search also honours the crashed-context cap. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
…i#18941) ## Summary Follow-up to unslothai#18919. When Studio hands an Inkling 2 load to llama.cpp's fitter (`--fit on`), the fitter measures only the load-time compute reserve and leaves `--fit-target` free on each device (1024 MiB by default). The Inkling 2 banded compute buffer grows past that reserve after the first prompt. At the `-ub 2048` raise Studio applies when MoE experts sit in RAM, the measured growth is 1.5 to 2.5 GB, more than the margin, so a session can OOM mid-prompt after a clean load. This adds the expected growth to the `--fit-target` margin, for Inkling 2 `--fit on` launches only: - Growth = runtime estimate minus a calibrated lower bound of llama.cpp's load-time reserve, at the launched micro-batch, K/V type and context. - The runtime side is unslothai#18919's banded estimate, unchanged, with a floor for the margin only, because past about 262K cells at `-ub 2048` the estimate reads under the measured runtime (524K: 5572 vs 5836 MiB). - The reserve bound is fitted under every Inkling-2-Mini reading we have on both builds, for ub 512 to 2048 and 32K to 1M cells. On unslothai#399 it is the larger of an activation floor and the 4 B per cell shared mask. On older builds it is the activations plus 16 B per cell. - Both sides use Mini's activation estimate as a fixed scale, so the growth follows the micro-batch and context the way unslothai#18919's runtime term does, not a larger model's activation size. - With no `-c` (Manual + Auto), the fitter picks the context, so the largest growth from the `--fit-ctx` floor up to the native length is used. - It is added on top of the margin Studio already emits: the budget slider delta, the small-card trim, the per-device list and the mid-session OOM headroom. A user's own `--fit-target` still wins. - It is 0 where there is no banded path: Metal, Vulkan, SYCL, pre-unslothai#399 quantized K/V, or no flash attention. - Non-Inkling 2 models, including Inkling 1, never reach the new code. ## Measured growth vs emitted Inkling-2-Mini UD-IQ1_S, CUDA, `-np 4 --kv-unified -fa on`, slot 0 filled to 90% of the context. The compute buffer is read from the load log and from `memory_breakdown_print` at exit. The ub 2048 rows and the 32K ub 1024 row are `--fit on` launches on the unslothai#399 build b12628; the other rows are earlier `--fit off` readings. The 32K ub 1024 row reproduces the earlier `--fit off` reading (1080 vs 1081 MiB). | build | ub | ctx | K/V | reserve at load | after prompt | measured growth | emitted growth | pad | |---|---|---|---|---|---|---|---|---| | unslothai#399 | 512 | 32K | f16 / q8_0 | 258 | 747 | 489 | 617 | +128 | | unslothai#399 | 512 | 128K | f16 | 382 | 837 | 455 | 689 | +234 | | unslothai#399 | 512 | 128K | q8_0 | 541 | 837 | 296 | 689 | +393 | | unslothai#399 | 512 | 512K | f16 | 1078 | 1077 | 0 | 421 | +422 | | unslothai#399 | 512 | 1M | f16 | 2102 | 2101 | 0 | 173 | +174 | | unslothai#399 | 1024 | 32K | f16 | 514 | 1594 | 1080 | 1249 | +169 | | unslothai#399 | 1024 | 1M | f16 | 4206 | 4205 | 0 | 393 | +394 | | unslothai#399 | 2048 | 32K | f16 / q8_0 | 1035 | 3582 | 2547 | 2690 | +143 | | unslothai#399 | 2048 | 128K | f16 / q8_0 | 1443 | 3925 | 2482 | 2866 | +384 | | unslothai#399 | 2048 | 256K | f16 | 2275 | 4492 | 2217 | 2397 | +180 | | unslothai#399 | 2048 | 512K | f16 | 4323 | 5836 | 1513 | 1681 | +168 | | b12602 | 512 | 32K | f16 | 541 | 811 | 270 | 379 | +109 | | b12602 | 512 | 128K | f16 | 1357 | 1497 | 140 | 323 | +183 | All values are MiB. The emitted growth is added on top of the existing margin (1024 MiB by default), so the real headroom is larger than the pad shown. ## Inkling-2-Small launch matrix 432 simulated launches (sparse real-header GGUFs, 24 / 48 / 80 / 96 / 180 GB and 2x80 GB cards, auto and fixed context, f16 and q8_0, shipped b12602 and unslothai#399 builds), unslothai#18919 head versus this branch: - 421 launches go `--fit on`. 315 now carry a larger `--fit-target`. The other 106 are q8_0 on the shipped build, which runs dense attention and has no banded growth. - unslothai#399 build at `-ub 2048`, f16 and q8_0: +2978 to +3250 MiB (margin 4002 to 4274 MiB), 159 launches. - unslothai#399 build at the default micro-batch: +601 to +689 MiB (margin 1337 to 1713 MiB), 51 launches. - Shipped build, f16 at `-ub 2048`: +1964 to +2204 MiB, 78 launches. - Shipped build, f16 at the default micro-batch: +347 to +540 MiB, 27 launches. - Every launch still loads. Outside `--fit-target`, all 432 argv are identical. ## Non-Inkling models 384 launches of qwen3moe, llama, inkling, gemma3, deepseek4 and glm4moe (8 / 24 / 48 GB and mixed cards, 1 to 80 GiB weights, f16 and q8_0, GPU and Manual + Auto, 276 of them `--fit on`) produce byte-identical argv on unslothai#18919 head and on this branch. ## Tests `studio/backend/tests/test_inkling2_fit_target_regrowth.py`: - for every measured row, emitted growth >= measured growth + 100 MiB, and the reserve bound <= the measured reserve; - unslothai#18919's runtime estimate is unchanged; - the growth does not scale with a larger model's activations; - an unknown context takes the largest growth; - no growth without a banded path; - the launched `--fit-target` with the default margin, the small-card trim and the per-device list; - non-Inkling 2 argv is unchanged even with the growth forced to 4096 MiB. On unslothai#18919 head, 5 of the 49 tests pass (the unchanged cases) and the rest fail. The neighbouring fit, placement, compute buffer, OOM respawn, sidecar and Inkling suites give the same results, with the same failing test IDs, as unslothai#18919 head. ## Not covered - No real Inkling-2-Small `--fit on` run. The Small numbers come from the simulated matrix, with the growth calibrated on Inkling-2-Mini. - Pre-unslothai#399 readings exist only at ub 512. - unslothai#18919's own runtime estimate reads 264 MiB under the measurement at 524K `-ub 2048`. That affects its `--fit off` decisions and is left to unslothai#18919. - A launch that only reaches `--fit on` through a later retry keeps the margin of its first attempt. ## Test fix `test_mixed_cards_keep_their_own_margins_plus_the_headroom` (from unslothai#18920) reached `torch.cuda` through the datacenter and integrated-GPU probes on a host with visible GPUs, so the CPU-test guard failed it at teardown. It now fakes the device info the way `test_auto_fit_target_trim.py` does. On CI runners with no GPU it already passed. ## Review fixes - On the currently shipped llama.cpp build (pre-unslothai#399 banded path), the margin counted unslothai#18919's upper-bound load reserve as post-prompt growth past about 262K cells, which kept up to 4.7 GB free that the measurements show is never used (for example 5228 MiB on 12 and 16 GB cards at 1M context). Growth on that build is now priced from the runtime term only; every measured row keeps its value. - The budget delta is floored first (the same 512 MiB floor the emitter applies), then the regrowth is added on top, for the single margin and every per-device entry, so a low budget slider can no longer eat the reserve. - The mixed-card respawn test also stays off `torch.cuda` when run alone. A base vs head launch matrix (516 pairs: 8 to 24 GB cards, 2 x 24 GB and 24 + 8 GB, sparse header-only GGUFs) loads on both sides, and nothing differs outside `--fit-target`.
Fixes the GPU OOM respawn path that #18757 runs into. Related to #18757.
Problem
After a served GPU OOM, Studio reloads llama-server with 1024 MiB more headroom per strike, but it only adds that headroom to
--fit-target. A Studio-planned load runs with--fit offand never passes--fit-target, so the respawn relaunched the same-cthat had just run out of memory. On the #18757 case (24122 MiB card, 23857 MiB free, Inkling-2-Mini UD-IQ4_XS + mmproj, 4 slots, Auto context) the reload asked for 162048 again after the OOM.Fix
The respawn headroom now also comes out of the planner's usable VRAM, so a
--fit offplan shrinks its context after each strike. Auto context per strike on the 24 GiB case: 162048 -> 136448 -> 110848 -> 85248 (about 25600 tokens per 1024 MiB strike). With--fit onthe headroom is now counted in both places; that only applies after a crash.A respawn after a GPU OOM also caps its Auto context at the context of the load that crashed. Without the cap, the headroom could push a one-card plan onto more cards and Auto would then fill them: Inkling-2-Mini UD-Q8_K_XL on 2x24 GiB went from
CUDA_VISIBLE_DEVICES=0 -c 23808toCUDA_VISIBLE_DEVICES=0,1 -c 383744after one strike (24+12 GiB:-c 169728). It now stays at 23808. The slot re-fit's context search honours the same cap. A fixed-cis left alone, and first loads are unchanged.A recovery also adds no memory consumer the crashed load did not have: while a GPU OOM strike stands, Auto speculative decoding does not turn on a drafter (DSpark, DFlash, MTP) if the load that crashed ran without one, and keeps ngram-mod instead. On the 2x24 GiB case above, the two-card respawn would otherwise have found room for the DSpark drafter the one-card load had dropped. A drafter the user picked is unchanged.
Tests
studio/backend/tests/test_llama_cpp_gpu_oom_respawn.py: a new test fails on main (assert 0.0 >= 921.6) and passes here. A second one covers the 2x24 GiB case (one card at a small Auto context, the respawn on both cards): it fails without the cap (assert 664064 <= 22016) and passes with it, and checks a fixed-c 65536is kept. A third covers the drafter: after the strike the Auto respawn on two cards keeps ngram-mod and passes no--model-draft(without the guard it loadsdraft-dspark), while a forced DSpark load keeps its drafter.-cis kept (256 of 256), no strike plans a larger-cthan the strike before it, and no strike loads a drafter model the strike before it lacked.test_mixed_cards_keep_their_own_margins_plus_the_headroomerrors at teardown on main and on this branch alike on this host (a CUDA device property probe in the teardown), unrelated to this change.Not covered