Skip to content

Unsloth Studio (Vulkan): fill the discrete GPU before a shared-memory iGPU in a mixed pin - #12650

Merged
danielhanchen merged 33 commits into
unslothai:mainfrom
LeoBorcherding:igpu-split-weight
Oct 22, 2026
Merged

danielhanchen merged 33 commits into
unslothai:mainfrom
LeoBorcherding:igpu-split-weight

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  1. _select_gpus ranks devices by usable memory, so the iGPU ranks first. A model that fits on either device alone lands on the iGPU.
  2. When the model needs both, the pin launches -ngl -1 --fit off with 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:

Same model (Qwen3.8-27B UD-IQ4_XS), same box Placement Generation
7700 XT only, --fit on 36/66 layers on the card, rest on CPU 4.4 tok/s
7700 XT + iGPU picked 4.8 GB on the card, 8.3 GB on the iGPU 1.05 tok/s

The UI shows "66/66 layers on GPU" for the slow run.

Changes

  • _select_gpus / _select_gpus_split_aware / _slots_that_fit_on_gpu take shared_gpu_ids and rank those devices after every discrete card. load_model passes the existing _shared_gpu_ids, which is Vulkan-only. Every other caller keeps the old ranking.
  • The full-offload pin emits a --tensor-split when 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:
    • tensor parallelism, or the user's own -ts;
    • -sm row / -sm tensor in argv (an inherited non-layer LLAMA_ARG_SPLIT_MODE is popped before launch, so it doesn't count);
    • RPC devices (--rpc or LLAMA_ARG_RPC), which llama.cpp puts ahead of the local ones;
    • a --fit in the pass-through args, which comes after the generated --fit off and makes the fitter reject a multi-device split;
    • a KV cache whose per-layer shape is unknown (MLA, hybrid recurrent, an unsized sliding window). A plain cache is spread evenly, which is correct for it.

Auto mode without a GPU pick is unchanged: _vulkan_auto_gpu_memory already 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.py now pins the iGPU-aware ranking call. With the new test file, that's 218 passed at 1678bbd.

Hardware

No hosted runner has an AMD GPU or an iGPU next to a discrete card. The amd_ci Strix Halo runner is a single APU, so it can't exercise a mixed pin. This table is the test report.

Measured at 0072081 (1678bbd only 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.

GPUs picked merge base fb372c1 this PR
R9700 + iGPU iGPU only (--device Vulkan1): 3.0 tok/s R9700 only (--device Vulkan0): ~90 tok/s
2x R9700 (control) R9700, ~90 tok/s R9700, ~90 tok/s
Shape Changed by this PR What ran Still needed
Discrete + iGPU, model fits on the card (Vulkan, Windows) yes the run above: iGPU-only at 3 tok/s before, card-only at ~90 after nothing
Discrete + iGPU, model needs both yes unit tests on the reporter's numbers a real load over 31.7 GB, where the generated --tensor-split is emitted. Nothing on the test box is that big
Discrete + iGPU, auto no n/a nothing
Two discrete cards no (empty shared set) the control row above nothing

Bottom 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.

… 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.
@danielhanchen danielhanchen self-assigned this Oct 8, 2026
…cards too full for their split buffers, keep the projector out of the layer total
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 8, 2026
…xed-pin split, respect an inherited LLAMA_ARG_TENSOR_SPLIT
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Oct 8, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Oct 8, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 8, 2026
# Conflicts:
#	studio/backend/core/inference/llama_cpp.py

[skip ci]
@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 ⚠️ Failed 2026-10-22T12:42:48.196804Z
We couldn’t complete this review. Comment @codex review to try again.
9e9660f 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[bot]

This comment was marked as resolved.

… projector device, charge trailing nextn rows a layer of cache

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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

Copy link
Copy Markdown
Member

@codex review

3 similar comments
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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".

# Conflicts:
#	studio/backend/tests/test_mtp_vram_budget.py
@danielhanchen
danielhanchen merged commit 3f11b2e into unslothai:main Oct 22, 2026
danielhanchen added a commit that referenced this pull request Oct 23, 2026
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]
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.

3 participants