Repository navigation
Conversation
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. |
|
@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". |
… bytes (builds on unslothai#19148) (unslothai#19249) Builds on unslothai#19148 (includes its commits); merging this merges unslothai#19148. ## Problem unslothai#19148 prices the large compute reserve that unslothai/llama.cpp#386 added in `b12649-mix`. The next llama.cpp prebuild may ship the fix to that reserve. In the fixed build, several slots run the banded kernel over cell positions, and short ubatches run banded over the padded cache. The reserve then drops to almost nothing: | Inkling-2-Mini, 1 slot, 1M context, ub 512 | `b12649-mix` | fixed build | |---|---|---| | f16 K/V | 5866 MiB | 1248 MiB | | q8_0 K/V | 9962 MiB | 1248 MiB | With unslothai#19148 alone, Studio would keep pricing the fixed build with the `b12649-mix` reserve. On the measured points that overestimates the compute buffer by 0.2 to 55 GB, so Studio would place fewer layers on the GPU than fit. This PR prices the fixed build separately, which makes unslothai#19148 safe to merge. ## Fix - Detect the fixed build by two graph input names it adds to `libllama`: `attn_inp_k_pos_swa` (several slots, banded over cell positions) and `attn_inp_rel_shift_swa` (short ubatches over the padded cache). No earlier build has either name. Both survive `strip`. Both must be present. - Price its reserve as the f16 KQ mask over the padded cache (2 bytes per cell per ubatch token, twice with `--swa-full`) plus 160 KiB per ubatch token, for any slot count and K/V type. A layer split adds its mask copies as before. - Keep only the CUDA pool margin (256 KiB per ubatch token) in `--fit-target`, as unslothai#19148 does for `b12649-mix`. The markers identify the build even when its build number cannot be read. - `b12649-mix` and the merge-only rebuild of #386 keep unslothai#19148's pricing. Older builds keep the pricing on `main`. - Split a `--fit off` multi-GPU load by bytes when llama.cpp's split by layer count would overflow a card. Unsloth Dynamic quants keep some layers at higher precision: the last four layers of Inkling-2-Mini UD-Q8_K_XL are about 2 GB each, against 0.6 GB for the rest, so a split by count can put several GB more on the smaller card than it holds. Studio now emits a `--tensor-split` whose layer runs fit each card. When no split fits, it lets `--fit on` place the model with the slots the user asked for, not a count cut only to fit every layer on the GPUs. A load whose count split already fits keeps llama.cpp's own split. Which pricing each build gets (`grep -c` of each string in the built `libllama`): | Build | `inkling2_loop: %zu cache slots exceed` | `attn_inp_k_pos_swa` | `attn_inp_rel_shift_swa` | Pricing | |---|---|---|---|---| | `b12631-mix` | 1 | 0 | 0 | as on `main` (build below 12649) | | `b12649-mix` | 1 | 0 | 0 | unslothai#19148 | | #386 merge-only rebuild | 1 | 0 | 0 | unslothai#19148 | | fixed build (#386 plus the banded-position fix) | 1 | 1 | 1 | this PR | ## Accuracy Compute buffer at load from `llama-server`, Inkling-2-Mini, flash attention, B200, on the fixed build. The table is a sample of 116 points: 1 to 64 slots, ub 256 to 2048, f16 / bf16 / q8_0 / q4_0 / q4_1 / q5_0 / q5_1 / mixed K/V, 4K to 1M context, with and without `--swa-full`, and with a DSpark drafter. | Setup | Measured (MiB) | This PR (MiB) | unslothai#19148 (MiB) | |---|---|---|---| | 4 slots, 32K, ub 512 | 256 | 298 | 3050 | | 4 slots, 256K, ub 512, q5_1 | 480 | 522 | 6506 | | 4 slots, 1M, ub 2048, q8_0 | 4999 | 5156 | 60388 | | 1 slot, 512K, ub 512 | 734 | 773 | 3429 | | 1 slot, 1M, ub 512, q4_0, DSpark | 1248 | 1285 | 10597 | | 1 slot, 415,488, ub 2048, q4_0, `--swa-full` | 4124 | 4292 | 10932 | | 4 slots, 274,688, ub 512, q4_0, `--swa-full` | 758 | 803 | 18577 | | 64 slots, 64K, ub 512 | 352 | 440 | 9496 | Across all 116 points the estimate is 1.01x to 1.25x the measurement (+14 to +184 MiB) and never under it. The highest ratio is 64 slots at 64K, where the flat estimate's output rows lead. After two concurrent 13.5K-token prompts at ub 2048 with 4 slots, the compute buffer grew by 120 MiB past the load reserve. The 512 MiB pool margin in `--fit-target` covers that. ## unslothai#19137 on the fixed build The unslothai#19137 setup with Inkling-2-Mini UD-Q8_K_XL: 2 GPUs, 32K context, 4 slots requested, the Windows reserve floor. Studio's planner ran for each free VRAM pair. The command it produced then ran on two B200s, with `cudaMemGetInfo` capped to that pair. The cap only changes what llama.cpp sees as free memory; it does not stop an allocation. So for every load, the table checks llama.cpp's own per-card memory (weights, cache, compute, unaccounted) against the card. Every load answered two concurrent 13.5K-token prompts. | Free VRAM | `main` | unslothai#19148 | This PR | |---|---|---|---| | 14848 + 11264 MiB | `--fit on`, target 3714: 12.3 GiB of weights on GPU | `--fit on`, target 1536: 16.6 GiB on GPU | same command as unslothai#19148 | | 15360 + 11264 MiB | `--fit on`, target 3714: 12.8 GiB on GPU | `--fit on`, target 1536: 16.6 GiB on GPU | same command as unslothai#19148 (4 slots, `--fit on`, target 1536) | | 16384 + 12288 MiB | all layers on GPU, 4 slots, split by count: 13.5 GB on the 12 GB card, so it fails at load | all layers on GPU, 1 slot, split by count: 13.9 GB on the 12 GB card, so it fails at load | all layers on GPU, 4 slots, `--tensor-split 19.5,5.5`: 15.0 GB and 11.1 GB, under 16 and 12 GB | Decode speed, median of 5 runs of 256 tokens after a warmup, in tok/s. These numbers are noise-dominated: the host CPU was shared with other jobs, and loads with every layer on the GPUs measured anywhere from 91 to 698 tok/s across rounds of the same setup. They do not rank the versions; the placement above is the result. | Free VRAM | `main` | unslothai#19148 | This PR | |---|---|---|---| | 14848 + 11264 MiB | 134 | 155 | same command as unslothai#19148 | | 15360 + 11264 MiB | 155 | 208 | same command as unslothai#19148 | | 16384 + 12288 MiB | 110 (would not load on the real cards) | 184 (would not load on the real cards) | 91 | `main` on the fixed build reproduces the report: 11.6 and 7.9 GB used of the two cards with expert weights on the CPU, as in the Task Manager readings in unslothai#19137. With 16 + 12 GB free, this PR keeps the whole model on the GPUs and loads. `main` and unslothai#19148 plan the same placement but split by layer count, so the 12 GB card cannot hold its share. The 1024 MiB per-device overhead matches what llama.cpp reports as unaccounted per device (0.8 to 1.3 GB), so this PR leaves the multi-GPU margins as they are. ## Boundaries - The byte split shares the cards by the lowest fill they can all hold, in device order. With three or more cards it can leave a middle card lightly used. - `llama-completion` reserves a logit row per ubatch token, so its single-slot buffers are larger than `llama-server`'s at the same settings (819 vs about 252 MiB at 32K, ub 512). Studio launches `llama-server`, which is what this PR prices. - The DSpark drafter's own compute buffer (203 MiB with f16 draft K/V and 663 MiB with q4_0 at 128K) is unchanged by the fix and priced as before. ## Tests - `test_inkling2_banded_quant_kv.py` adds: - the marker detection, including each marker alone, a longer name, an unknown build number and an older build number; - 48 measured points, plus mixed K/V types; - context monotonicity, with no slot or K/V type dependence; - the layer-split mask copies; - the `--fit-target` margin; - the dense fallback with flash attention off or ubatches of 32 or fewer. - `test_byte_balanced_layer_split.py` covers: - an even model keeping llama.cpp's split; - the unslothai#19137 rows split by bytes at 16 + 12 GB, and handed to the fitter at 15 + 11 GB; - each run fitting its card, the positional order over three cards; - the planner path from the layout, and the launch falling back to `--fit on`. - a slot cut whose pin has no layer split that fits: the launch keeps the 4 slots asked with `--fit on`. - The 31 Studio planner suites give the same failing test IDs on `main`, unslothai#19148 and this PR. All 321 come from this host's CUDA probe guard (a CPU test reaching `torch.cuda` on a GPU host without a queried device), not from these changes. --------- Co-authored-by: oobabooga <[email protected]>
|
Thanks @oobabooga, this landed through #19249, which carried your commits unchanged (you are credited as co-author on the squash, ba41ecf). #19249 adds pricing for the next prebuild's banded reserve fix on top, with the b12649-mix pricing from this PR kept for the current prebuild, plus a byte-balanced |
Problem
On the current llama.cpp prebuild (
b12649-mix-c7059d6), Studio underestimates Inkling 2's compute buffer by up to 16 GB. Loads that Studio plans as fitting fail at startup with the error from #19137:Studio then retries with
--fit on, which moves expert weights to the CPU and slows decoding.Cause
unslothai/llama.cpp#386 (first in
b12649-mix) reserves Inkling 2's worst case at load time: the dense relative bias for several slots, and the banded graph plus a small dense bias for one slot. Studio still priced the earlier, much smaller reserve.Fix
_inkling2_reserve_bytes. Older builds price as before.--fit-target, instead of 2.4 GB for growth that no longer happens.main vs this PR
Studio loads with the
b12649-mixbundle, Inkling-2-Mini, on an RTX 6000 Ada with VRAM held to simulate the smaller cards:--fit on--fit on--swa-full--fit-targetabout 3.9 GB--fit-target1.5 GBEvery PR load answered two concurrent 13.5K-token prompts.
Compute buffer, measured on
b12649-mixagainst each side's estimate (MiB, ub 512, f16 cache unless noted):--swa-full--swa-full, ub 2048The PR never underestimates on the 51 measured points in the tests; it overestimates by up to 2.1x, mostly at large ubatch sizes.
#19137
The issue's error is this underestimate: the reporter's llama-server failed to allocate 3081 MiB at 32K with 4 slots, which
mainprices at 842 MiB and this PR at 3050. With the PR, Studio plans for that buffer and keeps more of the model on the GPUs, but it does not restore the 35 to 40 tok/s the reporter had before. That load still needs--fit on, because Studio's multi-GPU margins (a fixed per-device overhead, and the compute buffer counted once more than the number of GPUs) leave too little room. That needs a separate change, so this PR does not close the issue.Boundaries
--swa-fulland a prompt of about 100K tokens hitsGGML_ASSERT(obj_new)inside llama.cpp. That is a separate llama.cpp bug, not a memory estimate issue.Tests
test_inkling2_banded_quant_kv.pycovers the measured points, the build gate, the--fitmargin per build, the per-slot pricing, and unchanged pricing for older builds. The Studio planner suites pass, apart fromtest_linux_smt_and_non_smt_core_counts, which depends on this host's CPU layout and also fails onmain.