Skip to content

Studio GGUF placement: the dGPU wins Auto only without losing context; explicit picks keep host-only bytes off the dGPU - #14615

Merged
danielhanchen merged 9 commits into
mainfrom
gguf-tier-accounting-ctx-floor
Oct 25, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
gguf-tier-accounting-ctx-floor

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Follow-up to #14372 and #14492 from a post-merge review. Two ways the discrete-first GGUF placement used less of a mixed APU + dGPU host than it could.

  1. Auto context shrank to fit the dGPU. The Auto walk took the first discrete-only subset that fit at any context. On a host where the APU pool held a model's native 131072 context, a 6 GiB model went to an 8 GB dGPU at 9984 tokens (a 12 GB dGPU: 62464). The drafter probe walked the same order, and its early stop could drop the drafter and cut serving slots from 4 to 1 before trying the APU.
  2. Explicit picks overcharged the dGPU. Studio: discrete-first GGUF placement keeps explicit device picks, matching context ceiling; in-process Rosetta check #14492 turned the discrete tier off under an explicit --device / --main-gpu (or an unmappable mask) to keep the user's ordinals stable, but the same set also told the selectors which bytes live in host RAM. A CPU-pinned projector or host context checkpoints were then charged to the dGPU, giving a false GpuMemoryShortError or --fit on (fewer layers on the GPU).

What changes

Spoofed grid (2304 cells, main vs this branch)

APU first or second; no flag, --device ROCm0 or --main-gpu 0; 0 or 6 checkpoints; Auto or 8K; 6 / 11 / 13 GiB; native 32K or 131K; 16 or 12 GB dGPU; 1 or 4 slots; 60 GB or 1 GB free on the APU; no projector or a 4 GiB host projector.

Result Cells
Identical 2164
Errors, lower context, launch above its ceiling, explicit pin renumbering ordinals 0
Auto: dGPU at a capped context -> APU at the full context 52
Explicit pick: unpinned --fit on -> dGPU "0" fully resident, --fit off 80
Explicit pick: more slots at the same pin and context 8

In 56 of the 80 explicit-pick cells the slot search now settles on 1 to 3 fully resident slots instead of 4 slots with --fit offload; that is Studio's existing rule of full GPU residency over offload, and matches what #14372 did.

Tests

test_llama_cpp_placement.py: the review's spoof cells (6 GiB, native 131072, dGPU 7600/8192 and 11000/12288 MiB, APU total 0 and 131072) land on the APU at 131072 with --parallel 4 -ngl -1; the drafter probe at 1 and 4 slots keeps the drafter and slots; projector and checkpoint pricing under explicit picks via argv and env; the leading-ordinal rule; controls (a dGPU holding the full context wins, an 8K model and an explicit 8K stay on the dGPU, no-APU hosts unchanged). 14 new tests fail on main and pass here. Related placement suites: no failure appears only on this branch (the shared ones are the known test_mmproj_placement_policy and gguf-module / drafter failures).

… picks; discrete tier only while it keeps 32K of Auto context

Explicit --device / --main-gpu / LLAMA_ARG_DEVICE picks (and unmappable masks) turn the
discrete-first tier off (#14492), but the same cleared set also told the selectors which
GPUs share host RAM, so a CPU-pinned projector and host context checkpoints were charged to
a dGPU-only subset: a false GpuMemoryShortError or --fit on. The selectors now take the
integrated set for accounting and a separate prefer_discrete flag; under an explicit pick a
dGPU-only subset is priced without host-only bytes only when it keeps the leading ordinals,
so the user's device ordinals still name the same cards.

Auto context on an APU + dGPU host took the dGPU at any context down to the floor (#14372),
e.g. ~29K on a 16 GB card beside 131K on the APU. The discrete tier now wins only while it
keeps min(base walk context, 32768); the drafter probe applies the same rule.
… the base walk's context, drafter and slots

A 32K floor still let the dGPU take 62K where the APU held 131K. Auto, the published
ceiling sweep and the speculative-drafter probe now keep a discrete-tier subset only when
it matches the base walk (the pick before #14372) in every term: context, and for the
probe, whether the drafter fits beside the target. The probe's early break on the dGPU
had dropped the drafter or cut the default slots 4 -> 1.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T03:26:10.990546Z a1e443f 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.

@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: 92a0babc46

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

Comment on lines 29455 to +29458
ctx_checkpoints = _placement_ctx_checkpoints,
# Picks a subset, so an explicit device pick keeps the base pick.
integrated = _tier_gpus,
# An explicit device pick skips the discrete tier; host-only accounting still applies.
integrated = _integrated_gpus,
prefer_discrete = bool(_tier_gpus),

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 Retain ordinary KV when discounting host checkpoints

Passing _integrated_gpus here newly enables checkpoint discounting for explicit device selections, but _slots_that_fit_on_gpu computes it as kv - _kv(0). The production _estimate_kv_cache_bytes returns zero whenever n_ctx <= 0, so this expression subtracts the entire target KV cache rather than only the host-resident checkpoint snapshots. When an explicit-device load with checkpoints enters slot reduction, the dGPU can therefore be declared fully resident at too many slots and launched with --fit off, risking an OOM; the checkpoint component must be isolated without evaluating the estimator at context zero.

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.

I don't think this one happens: _kv(0) here means zero checkpoints, not context zero. The helper calls _estimate_kv_cache_bytes(effective_ctx, ..., ctx_checkpoints=ckpts), so both terms use the same context and the difference is only the host snapshots; the n_ctx <= 0 early return would make both terms 0 and subtract nothing. Added test_the_checkpoint_discount_removes_only_the_checkpoints: with the real estimator on hybrid metadata, the dGPU slot count with 8 discounted checkpoints equals the count with no checkpoints, at three free-memory levels.

…needs a leading run of the inherited mask order that keeps every ordinal the flags name
@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: 6458ccfc0e

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

Comment on lines +5124 to +5125
if not token or token.lower() == "none":
continue

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 Exclude CPU-only selections from GPU discount prefixes

When --device none or LLAMA_ARG_DEVICE=none is used on a mixed host whose leading device is a dGPU, skipping this token returns need == 0, so _discount_prefixes whitelists that dGPU prefix even though the child disables every GPU. The newly discounted calls, particularly _slots_that_fit_on_gpu, can then treat CPU-resident checkpoint/projector bytes as absent from the selected device and reduce --parallel or mark the load fully GPU-resident based on a card the child will never use; the equivalent supported spelling --device cpu correctly declines the discount. Treat none as a CPU-only/unpriceable selection here rather than as an ordinal-free GPU selection.

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 e07d7c1. _explicit_device_ordinals_needed now returns None when --device/-dev or LLAMA_ARG_DEVICE names none (any case), the same as an unreadable value, so a CPU-only pick never makes a GPU subset priceable at the lighter size. The launch goes to --fit on with no pin, as without the accounting. Tests cover the helper and the full launch for both the flag and the env var.

Comment on lines +28278 to +28280
return (
_ctx,
int(_need <= _pool_budget_mib(_subset, _probe_frac(True))),

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 Compare reducible slot counts before preferring the dGPU

When neither the discrete tier nor the base APU placement can hold the drafter at the originally requested slot count, both receive the same (context, 0) score here, so the dGPU remains first. The probe then breaks after recording that placement, and the later slot search can clamp, for example, four slots to one even when the base placement could retain three slots at the same context with the same drafter. Include each placement's best fitting slot count in this comparison rather than only whether all requested slots fit.

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 e07d7c1. The drafter probe score is now (context, drafter fits at the requested slots, slots kept). When the drafter does not fit at the requested slots, the slot term is the most slots the slot search keeps the drafter at on that placement (same context-keep rule and one-slot trim), or 0 when slots are pinned. The discrete tier is kept only when it matches the base walk on slots too. In the test the APU keeps the drafter at three slots and the dGPU only at one, so the launch now takes the APU at three; when both keep one slot the tier still wins.

…ted card is tried alone before spreading; the drafter probe keeps the placement with more slots

[skip ci]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: e07d7c1bf8

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

Seven conflicts in studio/backend/core/inference/llama_cpp.py, all where this
branch's explicit-pick accounting (prefer_discrete, discount_prefixes) and
main's #12650 shared-memory iGPU ranking (shared_gpu_ids) touched the same
signatures and forwarding calls. Both policies are kept; they do not contradict:

- _select_gpus, _select_gpus_split_aware, _slots_that_fit_on_gpu signatures:
  keep prefer_discrete and discount_prefixes, and add shared_gpu_ids.
- _select_gpus_split_aware's three _select_gpus calls (first pick, split retry,
  single-card re-price): forward shared_gpu_ids unconditionally, and keep the
  explicit-pick accounting kwargs (integrated, prefer_discrete=False,
  discount_prefixes, discrete_size_bytes) when the caller made an explicit pick.
- _slots_that_fit_on_gpu's _select_gpus_split_aware call: forward all three.

shared_gpu_ids only reorders ranking (iGPUs after every discrete card);
discount_prefixes only lowers the price of a vetted dGPU-only subset under an
explicit pick. The auto-merged call sites already pass both.

[skip ci]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: a1e443fa6d

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

@danielhanchen danielhanchen self-assigned this Oct 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 25, 2026
@danielhanchen
danielhanchen merged commit 69d6ab9 into main Oct 25, 2026
2 of 47 checks passed
@danielhanchen
danielhanchen deleted the gguf-tier-accounting-ctx-floor branch October 25, 2026 07:47
LeoBorcherding added a commit to LeoBorcherding/unsloth that referenced this pull request Oct 29, 2026
Conflicts kept both sides: the host-pinned discount, tied output and per-candidate
discounts beside main's input-embedding pricing (unslothai#14465), discrete tier (unslothai#14372,
unslothai#14615), restructured drafter and Auto probes, and the arch-crash retry that now
reads memory before the kill. main's input-embedding discount takes only what the
host-pinned discount does not already cover. Non-Vulkan APUs and integrated CUDA
move from _shared_gpu_ids to _unclassified_gpu_ids, so the discount still waits on
them while main's ranking and host-pool checks keep the Vulkan iGPU set.
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.

1 participant