Repository navigation
Studio: discrete-first GGUF placement keeps explicit device picks, matching context ceiling; in-process Rosetta check - #14492
Conversation
… masks, prices the context ceiling as Auto does, and does not report a preference cap as a shortfall - A user --device / --main-gpu (argv or LLAMA_ARG_DEVICE / LLAMA_ARG_MAIN_GPU) or an unmappable (UUID) visibility mask turns the discrete tier off, so the base pick stands. - The UI context ceiling walks the same tiered subsets Auto does, with the same discrete-tier checkpoint and projector pricing; the q8 notice probe passes the tier too. - A context capped only because the dGPU was preferred over an APU that holds the full context no longer raises GpuMemoryShortError(capped) under refuse_partial_gpu_fit.
platform_only_host() runs on every desktop launch preflight; on an x86_64 macOS Python it spawned a sysctl subprocess per call. Read the key via sysctlbyname once instead.
…get fit, not only the last The preference-cap check now re-prices the base walk after the discrete subset, so the last _fit_context_to_vram call can be the APU subset.
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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b891968f8
ℹ️ 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".
| ): | ||
| # Capped only by the discrete preference: the base walk | ||
| # holds the full context, so nothing evicted would help. | ||
| _base_ctx = next( |
There was a problem hiding this comment.
Inspect every base prefix before reporting a shortfall
When a discrete GPU ranks ahead of an integrated GPU, the first base prefix can return a valid but capped context while a later prefix containing both GPUs holds the full requested context. Using next(...) stops at that first capped result, leaves _ctx_capped_for_vram true, and causes refuse_partial_gpu_fit=True to raise GpuMemoryShortError or evict an unrelated resident even though the full pool already fits. Continue through the base prefixes until a full-context fit is found (or compare the maximum result) rather than accepting the first non-None result.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Kept as is, on purpose. The base walk is what main launches, and main takes its first fitting prefix even when it is capped: on a host whose second card is a dGPU instead of an APU, the same load raises the same capped shortfall (test_a_real_vram_cap_still_refuses_a_partial_fit, homogeneous case). Evicting a resident does help there, since it frees the card the load lands on. So the exemption only applies when main's own pick would have held the full context. 199ea0a adds test_a_capped_dgpu_first_shortfall_matches_a_host_without_an_apu, which pins the mixed host to the no-APU control's answer.
| ) | ||
| or self._visibility_mask_is_unmappable() | ||
| ): | ||
| _integrated_gpus = frozenset() |
There was a problem hiding this comment.
Keep integrated identity when disabling discrete preference
On a mixed APU/dGPU host where an explicit device flag leaves the base ranking on the dGPU, clearing _integrated_gpus also changes memory accounting rather than only disabling the discrete-first preference. _subset_ckpts can no longer recognize the dGPU-only subset and _discrete_host_only no longer removes a CPU-pinned projector, so host-only bytes are charged against discrete VRAM; for example, a load that fits 32K on the selected dGPU can be cut to 8K solely by adding --device ROCm0. Preserve the integrated-device set for accounting and use a separate switch to disable tiered selection.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 199ea0a. The explicit pick now only clears a separate tier set used where the discrete-first choice is made (_tiered_subsets, the projector tier, the three selectors and the preference-cap check). _integrated_gpus is kept, so checkpoints and a CPU-pinned projector are still not charged to the dGPU the pick lands on. test_a_user_device_flag_keeps_host_ram_off_the_dgpu_budget: --device ROCm0 and --main-gpu 0 now launch at the same 32K as the flagless load (was capped before).
| for n_gpus in range(1, len(ranked_for_cap) + 1): | ||
| subset = ranked_for_cap[:n_gpus] | ||
| # Every subset Auto may take, discrete tier included, priced as Auto prices it. | ||
| for n_gpus, subset in _tiered_subsets(ranked_for_cap, 1): |
There was a problem hiding this comment.
Respect the forced GPU floor in the ceiling sweep
When preserve_multi_gpu_on_layer or a tensor-to-layer downgrade raises _layer_min_gpus, Auto cannot select subsets below that floor, but this sweep still calls _tiered_subsets(..., 1). The new per-subset checkpoint accounting can therefore derive best_cap from a dGPU-only tier that the launch is forbidden to use; with a required two-GPU APU+dGPU split and host checkpoints, the published maximum can remain 32768 while the actual launch is capped near 10K. Start the ceiling sweep at the same effective GPU floor as Auto placement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 199ea0a. With a discrete tier the ceiling sweep now starts at the same floor Auto uses (_layer_min_gpus bounded by the cards that clear the per-device overhead). Your case (forced two-GPU APU + dGPU split, host checkpoints) now publishes the context it launches: test_the_context_ceiling_starts_at_a_forced_gpu_floor (max_context_length was 32768 against a 20480 launch). Hosts without an integrated GPU keep the previous sweep byte for byte.
…ice, the context ceiling starts at Auto's GPU floor [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 199ea0aa70
ℹ️ 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".
| # Every subset Auto may take, discrete tier included, priced as Auto prices it. | ||
| # With a tier, start at Auto's GPU floor: a forced split skips a short tier. | ||
| _cap_floor = 1 | ||
| if _tier_gpus: |
There was a problem hiding this comment.
Enforce the GPU floor after disabling tiered selection
When an explicit --device/--main-gpu setting clears _tier_gpus on a mixed APU/dGPU host, this condition leaves _cap_floor at 1 even if a tensor-to-layer downgrade or preserve_multi_gpu_on_layer requires multiple GPUs. The ceiling sweep can then take a checkpoint-free single-dGPU prefix and publish its larger context, while Auto placement must start with the APU+dGPU subset and pay the host-checkpoint cost, so the launched context can be lower than max_context_length. Apply the effective _layer_min_gpus floor regardless of whether the discrete-first tier remains enabled.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 41658b9: the floor now applies whenever an integrated GPU is present, not only while the tier is on. On a 192-cell grid of explicit picks (--device ROCm0 / --main-gpu 0, both GPU orders, forced split on and off, checkpoints on and off) every forced-split cell now matches pre-#14372 exactly, pin, context and ceiling. test_the_context_ceiling_starts_at_a_forced_gpu_floor covers both flags.
| integrated = _tier_gpus, | ||
| discrete_size_bytes = requested_total - _discrete_host_only(), |
There was a problem hiding this comment.
Preserve host-only accounting when the base pick is discrete
On a mixed APU/dGPU vision host where an explicit device setting disables the tier and the projector has been CPU-pinned, the base ranking can still select only the dGPU. Fresh evidence that the earlier accounting issue remains is that this call passes the now-empty _tier_gpus; _select_gpus_split_aware consequently never enters its discrete path and ignores the supplied discrete_size_bytes, charging _shared_pool_mmproj against dGPU VRAM even though those bytes reside in host RAM. A tight fully resident load can therefore fall back to --fit and offload layers solely because the user supplied a device flag; keep selection preference disabled without disabling subset-specific host-only accounting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this one on purpose. Under an explicit --device / --main-gpu the flag's ordinals index the mask Studio pins, so that subset has to stay exactly the pre-#14372 one. Repricing the full-pool pick at the discrete size can shrink it (for example 0,1 to 1), and then ROCm0 names a different card and ROCm1 no longer exists. The same 192-cell grid shows 0 pin changes against pre-#14372; the only differences are a larger launched context where the pick already lands on the dGPU alone, which never moves the mask.
…device pick too [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 41658b91ac
ℹ️ 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".
| or 1, | ||
| ), | ||
| ) | ||
| for n_gpus, subset in _tiered_subsets(ranked_for_cap, _cap_floor): |
There was a problem hiding this comment.
Apply the per-device reserve in the ceiling sweep
When an iGPU ranks between two discrete GPUs and the first dGPU cannot fit alone, the newly enumerated dGPU-only tier can pool the first card's spare memory with a low-memory second card and publish capped as best_cap, even though that second card cannot hold its replicated pipeline/compute reserve. The Auto path explicitly detects this with _every_gpu_holds_reserve and lowers the context via _cap_ctx_to_per_device_reserve, but this ceiling loop only checks the pooled total, so max_context_length can exceed the context that the same tier can actually launch. Apply the same per-device reserve check/cap before accepting this subset.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 44d9b75. A multi-card dGPU-only subset in the ceiling sweep now gets the same _every_gpu_holds_reserve / _cap_ctx_to_per_device_reserve treatment as Auto's walk before it can set best_cap. Hosts without an integrated GPU keep the previous sweep. test_the_context_ceiling_holds_a_dgpu_tier_to_each_cards_reserve (ceiling was 13312 against a 12288 launch).
| split_extra_bytes = _cc_split_extra( | ||
| effective_ctx, cache_type = "q8_0" | ||
| ), | ||
| integrated = _tier_gpus, |
There was a problem hiding this comment.
Honor shared GPUs in the q8 fit probe
On a mixed APU/dGPU host where the dGPU is already used by another resident model, this probe omits shared = _shared_gpus, so _select_gpus_split_aware treats that shared card as an eligible discrete-first tier and may declare q8_0 sufficient after dropping host-only bytes. The real placement call above does pass _shared_gpus, excludes that card from the discrete tier, and can still require --fit; consequently the emitted notice can promise that q8_0 makes the requested context fit when applying that setting does not. Pass the same shared set used by the real placement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 44d9b75: the q8 probe passes shared = _shared_gpus like the real placement call, so a shared dGPU never forms the discrete tier there. The full-pool answer is unchanged by it (only which card is preferred, not whether it fits).
… probe and slot fit pick like the real placement [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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". |
…e compute buffer wiring test (#14560) Backend CI `(Python 3.13, a-k)` is red on main (run 39659390757 on 4a5a3e5, the only failure out of 32116): ``` TestPerDeviceSplitReserve.test_wired_into_the_auto_context_loop E assert 4 == 3 E + where 4 = ...count('ifnotself._every_gpu_holds_reserve(') ``` The test reads `LlamaCppBackend.load_model`'s source and pins where the per-device reserve gate is wired. #14492 changed two things it pins, both on purpose: 1. It added a fourth gate: the context ceiling now caps a dGPU-only tier to the smallest card's reserve, as Auto's walk does, because pooling can hide a small card there. 2. It moved the Auto walk's body into a helper, so a subset the cap empties now `return None`s instead of `continue`. The behaviour is the same. The product is right; the test pinned the old shape. ## Change - The gate count is 4, and the new site is pinned by its own line (`_usable_mib = [_gpu_usable(g, _cap_fraction) for g in subset]`), so losing it fails by name rather than only by count. - The walk's "cap, then reject an emptied subset" check now matches `if capped <= 0: return None`. ## Testing - `studio/backend/tests/test_compute_buffer.py`: main 1 failed, this branch 279 passed. - Sabotage: removing #14492's ceiling cap fails with `3 == 4`; removing the walk's `capped <= 0` rejection fails the second assertion.
…; explicit picks keep host-only bytes off the dGPU (unslothai#14615) ## Summary Follow-up to unslothai#14372 and unslothai#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.** unslothai#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 - **Strict Auto rule.** A discrete-only subset wins only when it matches the base walk (the pick before unslothai#14372) on context; otherwise the base walk's subset is used. The ceiling sweep and the drafter probe use the same comparison (target context, drafter kept, slots), so the published maximum matches the launch and the drafter / slots never drop because of the tier. A dGPU that holds the full context still wins, so the speed benefit of unslothai#14372 stays where it costs nothing. - **Accounting split from preference.** `_select_gpus`, `_select_gpus_split_aware` and `_slots_that_fit_on_gpu` take the integrated set (which GPUs share host RAM) and a separate `prefer_discrete` flag. Under an explicit pick, a dGPU-only subset is priced without host-only bytes, but only when it keeps the leading ordinals, so the user's device numbers still name the same cards. - Hosts without an integrated GPU do no new work. ## 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 unslothai#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). --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
Follow-up to #14372 and #14373 from a post-merge regression review.
What changes
--device/LLAMA_ARG_DEVICE/LLAMA_ARG_MAIN_GPUkept naming ordinal 0 while the discrete-first mask made ordinal 0 the dGPU. With any explicit device flag, or a visibility mask that cannot be mapped (UUID entries), the discrete tier is off and the previous pick applies. The integrated-GPU set itself is kept, so host-only bytes (context checkpoints, a CPU-pinned projector) are still not charged to a dGPU the pick lands on. Checked only after an integrated GPU is found, so other hosts pay nothing.refuse_partial_gpu_fiton an APU + dGPU host, the discrete tier capped Auto context and raisedGpuMemoryShortError(capped=True)although the APU held the full context. When the full pool fits the uncapped context, the cap is no longer reported as VRAM-bound.best_capand the q8 probe now price discrete subsets the same way Auto does, and with a discrete tier the ceiling sweep starts at Auto's GPU floor (a forced multi-GPU split never takes the dGPU-only tier), so the launched context no longer exceeds the reported maximum.sysctlsubprocess per call. The Rosetta check readhw.optional.arm64with a subprocess on every call, Intel Macs included; it now reads it in-process viasysctlbynameand caches it.Tests
ggufmodule, drafter tests); against main's source 19 fail (the new tests).