Repository navigation
Unsloth Studio (Vulkan): fill the discrete GPU before a shared-memory iGPU in a mixed pin - #12650
Conversation
… iGPU in a mixed pin An iGPU reports its whole shared pool as free, so it outranked the discrete card in _select_gpus and, with no --tensor-split, took the larger share of llama.cpp's free-memory layer split. Rank shared devices after discrete ones and emit a split that fills the discrete card first.
…oop so the fixed-point test passes
…cards too full for their split buffers, keep the projector out of the layer total
…xed-pin split, respect an inherited LLAMA_ARG_TENSOR_SPLIT
…after, report the emitted ratio in status
…evice list in the mixed-pin split
…rojector stays in host memory
…that fits into a shared pin
…ve, keep llama.cpp's split for a downgraded tensor request
…locks, per-layer KV and adapters
… leave adapters to llama.cpp's split
…e the iGPU remainder by largest remainder
…ed-pin split gate
…-aware ranking in the MTP budget test
…shape is unpriced; format the test
# Conflicts: # studio/backend/core/inference/llama_cpp.py [skip ci]
[skip ci]
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. |
… projector device, charge trailing nextn rows a layer of cache [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
# Conflicts: # studio/backend/tests/test_mtp_vram_budget.py
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]
When a Vulkan host has a discrete card and an iGPU and both are selected in the GPUs picker, the iGPU ends up with most of the model. It reports its whole shared RAM pool as free (14.3 GB vs 11.3 GB on the reporter's RX 7700 XT), and that leads to two problems:
_select_gpusranks devices by usable memory, so the iGPU ranks first. A model that fits on either device alone lands on the iGPU.-ngl -1 --fit offwith no--tensor-split. llama.cpp then splits layers by free memory, so the larger "free" device, the iGPU, takes the larger share.Reported in the Discord help thread: RX 7700 XT (12 GB) + Ryzen iGPU, Windows 11, Vulkan, v0.1.902-beta. From their logs:
--fit onThe UI shows "66/66 layers on GPU" for the slow run.
Changes
_select_gpus/_select_gpus_split_aware/_slots_that_fit_on_gputakeshared_gpu_idsand rank those devices after every discrete card.load_modelpasses the existing_shared_gpu_ids, which is Vulkan-only. Every other caller keeps the old ranking.--tensor-splitwhen the pin mixes discrete and shared devices. The split fills each discrete card up to its usable budget, minus its compute buffer, and gives the iGPU only the overflow. It leaves the split to llama.cpp (the pre-PR behaviour) wherever the shares can't be priced or wouldn't describe the real allocation:-ts;-sm row/-sm tensorin argv (an inherited non-layerLLAMA_ARG_SPLIT_MODEis popped before launch, so it doesn't count);--rpcorLLAMA_ARG_RPC), which llama.cpp puts ahead of the local ones;--fitin the pass-through args, which comes after the generated--fit offand makes the fitter reject a multi-device split;Auto mode without a GPU pick is unchanged:
_vulkan_auto_gpu_memoryalready drops the iGPU when a discrete card exists. This only changes what happens when someone ticks both.Related: #8847 (same host shape on an RX 7800 XT). This fixes the placement half of it, not the VRAM display half.
Testing
tests/test_vulkan_igpu_split.py(new, 22 tests) uses the reporter's probe numbers. It covers the discrete card winning when either device fits, both being pinned when both are needed, the split favouring the card (9880 / 4320 MiB for a 14.2 GB load), positional order, overflow across two iGPUs, the launch gate, and each decline above. Every decline test fails without its guard.test_mtp_vram_budget.pynow pins the iGPU-aware ranking call. With the new test file, that's 218 passed at1678bbd.Hardware
No hosted runner has an AMD GPU or an iGPU next to a discrete card. The
amd_ciStrix Halo runner is a single APU, so it can't exercise a mixed pin. This table is the test report.Measured at
0072081(1678bbdonly adds declines that this run doesn't reach). Ryzen 9 9950X (its Radeon iGPU) + 2x Radeon AI PRO R9700, Windows 11, llama.cpp b11734 Vulkan prebuilt, Qwen3.5-9B UD-Q4_K_XL, ctx 8192, speculation off, 3 x 256-token generations. Vulkan sees VK0 R9700 31,707 MiB free, VK1 iGPU 46,346 MiB free (45,322 after the host reserve), VK2 R9700 31,707 MiB. Both columns use the same Unsloth Studio env and llama.cpp binary; only the backend code differs.fb372c1--device Vulkan1): 3.0 tok/s--device Vulkan0): ~90 tok/s--tensor-splitis emitted. Nothing on the test box is that bigBottom line: the reporter's case reproduces and is fixed on a real Ryzen + Radeon box, about 30x faster. The gap is the both-devices split on real hardware, which only unit tests cover.