Skip to content

Studio: price the fixed Inkling 2 reserve and split multi-GPU pins by bytes (builds on #19148) - #19249

Merged
danielhanchen merged 9 commits into
mainfrom
inkling2-fixed-reserve-pricing
Nov 24, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
inkling2-fixed-reserve-pricing

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Builds on #19148 (includes its commits); merging this merges #19148.

Problem

#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 #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 #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 Studio: price Inkling 2's compute reserve on the b12649-mix llama.cpp prebuild #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 There is no 12.1 or 11.6 versions of pytorch-cuda for MacOS. Which should I use? #386 keep Studio: price Inkling 2's compute reserve on the b12649-mix llama.cpp prebuild #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 #19148
#386 merge-only rebuild 1 0 0 #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) #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.

#19137 on the fixed build

The #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 #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 #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 #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 #19148 This PR
14848 + 11264 MiB 134 155 same command as #19148
15360 + 11264 MiB 155 208 same command as #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 #19137. With 16 + 12 GB free, this PR keeps the whole model on the GPUs and loads. main and #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:
  • The 31 Studio planner suites give the same failing test IDs on main, Studio: price Inkling 2's compute reserve on the b12649-mix llama.cpp prebuild #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.

oobabooga and others added 6 commits November 23, 2026 18:12
The fix to unslothai/llama.cpp#386 runs several slots banded over cell positions and short
ubatches over the padded cache, so its load-time reserve is the f16 KQ masks plus a per-ubatch
remainder for any slot count or K/V type. Detect it by the two graph inputs it adds to libllama
and price it from 116 llama-server measurements; b12649-mix keeps the dense pricing.
…uld overflow a card

llama.cpp cuts a --fit off layer split by layer count, weighted by free memory. Unsloth Dynamic
quants keep some layers at higher precision, so the count cut can land several GB more on the
smaller card than it holds (Inkling-2-Mini UD-Q8_K_XL on 16 + 12 GB: 13.4 GB on the 12 GB card).
When that happens, emit a --tensor-split whose runs fit each card, or let --fit place the model
when no cut fits. Pins whose count split fits keep llama.cpp's own split.
…lit that fits

Fewer serving slots are only worth it when the smaller pin loads. If no layer split puts the cut
pin's share within each card, launch --fit on with the slots asked, as before the cut, instead of
the cut count.
…ments

Name every KV argument at the call, as the planner's seam tests require, and count the split
check among the micro-batch re-derivations.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T12:37:27.254448Z 3c1fb21 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c1fb21784

ℹ️ 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".

"No layer split over GPUs %s fits each card; using --fit on",
list(gpu_indices),
)
use_fit, gpu_indices, _mixed_split = True, None, None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve explicitly selected GPUs when falling back to the fitter

When a user selects multiple CUDA/ROCm GPUs and no contiguous layer split fits, clearing gpu_indices also removes the launch-time device restriction. The visibility-mask branch later requires gpu_indices is not None, while its alternative explicitly excludes requests with gpu_ids; competing device flags are also stripped for an explicit GPU selection. Consequently, on a host with additional visible GPUs, this fallback lets the fitter allocate on cards the user did not select. Retain the requested device list when switching to --fit on.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 431b67c. The fallback keeps gpu_indices when the user picked GPUs, so the launch takes the --fit on branch with the pick still pinned in the child's visibility mask (an auto Vulkan fit keeps its discrete pool; only an unpinned auto load goes back to every card). test_the_fitter_fallback_keeps_an_explicit_gpu_pick: 3 cards, gpu_ids = [0, 1], no layer split fits, launches --fit on with CUDA_VISIBLE_DEVICES=0,1 (unset before the fix).

"No layer split over GPUs %s fits each card; using --fit on",
list(gpu_indices),
)
use_fit, gpu_indices, _mixed_split = True, None, None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply the partial-fit refusal to the new fitter fallback

For loads with intent.refuse_partial_gpu_fit=True, a pooled fit that fails this per-card split check now silently switches to CPU offload instead of raising GpuMemoryShortError. The partial-fit guard has already run, and _placement_verdict_partial was recorded while use_fit was still false. The later host-memory guard only rejects a host-RAM shortfall, so it does not enforce this policy when RAM is sufficient. This bypasses the route's refusal behavior for alongside loads and prevents its eviction/retry flow from running; perform this check before that guard or explicitly enforce the refusal here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 431b67c. The refusal body is now one local function, _refuse_partial_fit, called by the existing guard and by the fallback, which also marks the placement partial before handing the load to the fitter. test_the_fitter_fallback_honours_the_partial_fit_refusal: with refuse_partial_gpu_fit = True the fallback raises GpuMemoryShortError (it launched --fit on before), and a split that fits still launches --fit off.

@danielhanchen
danielhanchen merged commit ba41ecf into main Nov 24, 2026
1 check was pending
@danielhanchen
danielhanchen deleted the inkling2-fixed-reserve-pricing branch November 24, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants