Repository navigation
Studio: prefer discrete GPUs over unified-memory APUs in automatic GGUF placement; clamp Vulkan free to total - #14372
Conversation
…and clamp Vulkan free to total
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 |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
…in, fall back to base split pricing - Drafter probe walks the same discrete-then-full subsets as the auto loop, so a drafter only the APU holds no longer costs the dGPU placement its context. - Join integrated CUDA ids to nvidia-smi rows only under PCI_BUS_ID and a mappable mask, as _widen_integrated_cuda_rows does. - _select_gpus_split_aware applies the discrete tier as a whole split-aware check, then prices the full pool exactly as before. - Discrete-tier subsets are not charged host checkpoints or a CPU-pinned projector. - An idle discrete GPU is promoted ahead of an idle APU. - Update tests that pinned the APU-first ranking. [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: 3c6cdc7de4
ℹ️ 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".
| min_gpus = _layer_min_gpus, | ||
| split_extra_bytes = _cc_split_extra(effective_ctx), | ||
| shared = _shared_gpus, | ||
| integrated = _integrated_gpus, |
There was a problem hiding this comment.
Exclude the CPU projector from discrete-tier pricing
When a mixed APU/dGPU vision load moves its projector to the CPU, requested_total still includes _shared_pool_mmproj so that an APU candidate accounts for those host pages. Passing the same total into the new discrete-tier recursion also charges those bytes to the dGPU, unlike the auto-context path's _subset_ms adjustment. Consequently, an explicit-context model that fits the dGPU only after projector offload is falsely rejected and falls back to the APU or --fit offload; price the discrete tier without this host-only term before retrying the full pool.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 768bd8a: the explicit-context call now prices the discrete-tier attempt without the CPU-pinned projector bytes (_select_gpus takes an optional discrete_size_bytes, used only for that attempt), with the same gate as _subset_ms; the full-pool pass is unchanged. Test: test_explicit_ctx_discrete_tier_is_not_charged_a_host_projector, plus a no-integrated-GPU control.
| ubatch_for_slots = _ubatch_for_slots, | ||
| mtp_bytes_for_slots = lambda s, ub: _mtp_bytes(_reduce_ctx, s, ub), | ||
| ctx_checkpoints = _placement_ctx_checkpoints, | ||
| integrated = _integrated_gpus, |
There was a problem hiding this comment.
Reprice checkpoints before selecting the discrete slot tier
On a mixed unified/discrete host with --ctx-checkpoints and multiple serving slots, _slots_that_fit_on_gpu adds ctx_checkpoints to the KV footprint before it invokes the integrated-aware selector. The discrete recursive attempt therefore pays host-RAM checkpoint bytes even though a dGPU does not share that pool, so a lower slot count that would remain fully resident on the dGPU can be rejected and the load stays on --fit offload. This search needs a zero-checkpoint discrete attempt followed by the checkpoint-priced full-pool attempt.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 768bd8a: _slots_that_fit_on_gpu prices each slot count twice on a mixed host, a checkpoint-free (and host-projector-free) discrete attempt first, then the checkpoint-priced full pool as before. Hosts without an integrated GPU pass nothing new. Test: test_slot_search_discrete_tier_is_not_charged_host_checkpoints.
…heckpoint bytes to the discrete tier [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: 768bd8a9b8
ℹ️ 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".
| per_device_overhead_bytes = _pipeline_overhead_bytes, | ||
| min_gpus = _layer_min_gpus, | ||
| shared = _shared_gpus, | ||
| integrated = _integrated_gpus, |
There was a problem hiding this comment.
Remove host projector bytes from file-size dGPU pricing
When a mixed APU/dGPU vision load has no usable KV estimate and moves its projector to the CPU, _fs_total still contains _shared_pool_mmproj, but this call supplies no discrete_size_bytes. The new discrete-tier recursion therefore charges the host-only projector to the dGPU, rejects a card that actually holds the model weights, and falls through to the APU or --fit; pass _fs_total - _discrete_host_only() for the discrete attempt as the explicit-context path does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 31470e4: the file-size path now passes the discrete size without the host-only projector bytes (_discrete_host_only()), as the explicit-context path already did. Test: test_host_projector_is_not_charged_to_the_discrete_tier[filesize].
| integrated = _integrated_gpus, | ||
| discrete_host_only_bytes = _discrete_host_only(), |
There was a problem hiding this comment.
Keep host-only bytes out of the slot context re-fit
When a mixed APU/dGPU load with checkpoints or a CPU-pinned projector reaches serving-slot reduction, this first call can now select the dGPU using the corrected footprint, but the subsequent _slots_hold call uses the full model_size_fit and _placement_ctx_checkpoints on the already narrowed dGPU-only _plan_gpus. Since there is no integrated row left in that list, the helper cannot activate its discrete tier, so _largest_ctx can unnecessarily lower or fail the context re-fit even though those host allocations consume no dGPU VRAM; construct the narrowed re-fit with the host-only terms removed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 31470e4: when the narrowed device list holds no integrated GPU, _slots_that_fit_on_gpu prices against the total without checkpoints or the host projector, and _slots_hold passes integrated and discrete_host_only_bytes through. Test: test_slot_refit_on_narrowed_dgpus_drops_host_only_terms.
| pooled = True, | ||
| total_mib = None, | ||
| ctx_checkpoints = _placement_ctx_checkpoints, | ||
| ctx_checkpoints = _subset_ckpts(_subset), |
There was a problem hiding this comment.
Preserve the subset when retrying drafter slot counts
On a mixed host using context checkpoints, a checkpoint-free dGPU result from this probe is later stored in _target_placements only as (count, context, budget). If target plus drafter requires fewer serving slots, _ctx_with_drafter consequently loses the subset identity and passes the full _placement_ctx_checkpoints count, making a fitting dGPU plan appear too large and potentially dropping the drafter instead of reducing slots. Carry whether the recorded placement is discrete and use the same _subset_ckpts decision in that retry.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 31470e4: each target placement now carries its own checkpoint count (_subset_ckpts(subset)), and the drafter slot retry uses it, so a discrete placement stays checkpoint-free. Test: test_drafter_slot_search_keeps_the_discrete_placement_checkpoint_free.
| if not use_fit and picked and len(picked) >= min_gpus: | ||
| return picked, False |
There was a problem hiding this comment.
Prefer an unshared APU over an occupied dGPU
When another loaded model already occupies the only dGPU but an unshared integrated GPU can hold the new model, the recursive discrete-tier call returns the occupied dGPU before the full-pool selector can apply its existing shared preference. The Auto-context loop has the same ordering problem: it moves the unshared APU to the front of ranked, then still tests _discrete_ranked first. This makes two models share dGPU compute even though the established placement policy chooses an otherwise fitting unshared card; only accept the discrete tier after ruling out fitting unshared devices, while still checking unshared dGPUs first.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 31470e4: the discrete tier only considers unshared dGPUs; if none fits, the base full-pool selector runs unchanged, so an unshared APU still wins over an occupied dGPU. The Auto-context loop uses the same tier and its sort is back to base. Tests: test_discrete_tier_respects_the_shared_card_preference (file-size, Auto and explicit context) and test_select_gpus_discrete_tier_skips_shared_dgpus.
| LlamaCppBackend._integrated_cuda_mask_key(), () | ||
| ) | ||
| ) | ||
| _integrated_gpus = frozenset(idx for idx, _free in gpus if idx in _unified) |
There was a problem hiding this comment.
Exclude classified APUs from the projector fit probe
On a mixed host where the integrated GPU reports a nonzero total, _mm_budgeted_gpus still treats that APU as a device with private VRAM. If model weights fit the dGPU but weights plus projector do not, the projector preflight sees the combined footprint fit the APU and declines the CPU pin; the new discrete tier then cannot fit the combined footprint and falls back to the APU, defeating discrete-first placement. Use the newly computed _integrated_gpus classification, rather than total > 0 alone, when deciding which devices can actually free VRAM by moving the projector to host memory.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 31470e4, narrowed: the base preflight verdict stays, plus one extra case that moves the projector to host: the base check would keep it on GPU, the dGPUs cannot hold model plus projector, but can hold the model without it. Dropping the APU from the budget outright would also move the projector to CPU where that does not make the model fit on the dGPUs, which only slows image encoding. Test: test_projector_preflight_does_not_count_an_apu_as_private_vram, with a dGPU control.
… path, keep the shared-card preference - File-size path prices the discrete attempt without the host-RAM projector. - Slot re-fit on dGPUs narrowed from a mixed pool drops checkpoints and the host projector. - Drafter slot search keeps each recorded placement's checkpoint charge. - Discrete tier only considers unshared dGPUs; otherwise the base shared-aware pick runs. - Projector preflight also pins when only that lets the dGPUs hold the model beside an APU. [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: 31470e4b73
ℹ️ 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".
| _mm_discrete = LlamaCppBackend._discrete_tier( | ||
| _mm_budgeted_gpus, _integrated_gpus | ||
| ) |
There was a problem hiding this comment.
Exclude shared dGPUs from the projector probe
When the only dGPU is already occupied and an unshared APU can hold the model plus projector, this builds _mm_discrete without _shared_gpus. If that occupied dGPU fits only after projector offload, the probe forces --no-mmproj-offload; the later placement selector does exclude the occupied dGPU from its discrete tier and chooses the APU, where moving the projector to CPU frees no shared memory and only slows image encoding. Pass _shared_gpus to this tier calculation so the preflight evaluates the same candidates as placement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 204dbb3: the preflight's discrete tier now gets _shared_gpus, so it evaluates the same unshared candidates as placement. With the only dGPU occupied, placement takes the APU and the projector stays offloaded. Test: test_projector_preflight_skips_a_shared_dgpu_like_placement (shared case fails before, unshared control pins as before).
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
…tching context ceiling; in-process Rosetta check (unslothai#14492) ## Summary Follow-up to unslothai#14372 and unslothai#14373 from a post-merge regression review. ## What changes - **unslothai#14372: explicit device choices win again.** An explicit `--device` / `LLAMA_ARG_DEVICE` / `LLAMA_ARG_MAIN_GPU` kept 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. - **unslothai#14372: a preference cap is not a shortfall.** With `refuse_partial_gpu_fit` on an APU + dGPU host, the discrete tier capped Auto context and raised `GpuMemoryShortError(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. - **unslothai#14372: the reported context ceiling matches the launch.** `best_cap` and 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. - **unslothai#14373: no `sysctl` subprocess per call.** The Rosetta check read `hw.optional.arm64` with a subprocess on every call, Intel Macs included; it now reads it in-process via `sysctlbyname` and caches it. ## Tests - Installer suites: 3656 passed on this branch; against main's source exactly the 5 new or rewritten tests fail. - Placement suites: this branch fails only the 5 tests that already fail on main (no `gguf` module, drafter tests); against main's source 19 fail (the new tests). --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…; 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>
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.
Summary
On a ROCm host with a Strix APU (gfx1150/1151/1152) next to a discrete Radeon, automatic GGUF placement ranked GPUs by usable free memory alone. The APU's "free" is sized from system RAM, so the APU won single-GPU placement even when the model fit the discrete card (#7624). llama.cpp and Ollama both prefer discrete devices.
Separately, Intel's Windows Vulkan driver can report a heap's free memory above its total, and Studio passed that through.
What changes
_select_gpustakes anintegratedset.load_modelbuilds that set only for automatic, non-Vulkan placement on hosts with 2 or more GPUs. It comes from the existing ROCm unified-memory classifier and the integrated CUDA cache.CUDA_DEVICE_ORDER=PCI_BUS_IDwith a mappable mask); otherwise placement is as before._run_vulkan_probeclamps each device's free memory to its total when the total is known, matching ggml's own clamp.Hosts affected
Tests
load_model: