Skip to content

Studio: keep an AMD dGPU and a Vulkan choice through install and update - #11442

Merged
shimmyshimmer merged 8 commits into
mainfrom
amd-igpu-installer-gfx-pick-and-backend-request
Sep 21, 2026
Merged

shimmyshimmer merged 8 commits into
mainfrom
amd-igpu-installer-gfx-pick-and-backend-request

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Stacked on #11437 (base branch is that PR's branch, so review that one first). Same report on #11143: a Fedora host with an integrated GPU driving the desktop plus a discrete RX 9060 XT (gfx1200) kept using the iGPU and ROCm despite the discrete card and Vulkan being selected. #11437 fixed the studio/setup.sh entry point; these are the two defects inside the installer itself.

1. _pick_rocm_gfx_target ended return _tokens[0]

It honoured HIP_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES, then fell back to whatever enumerated first. With no mask set, a leading integrated GPU decided the arch for the whole install and stranded the discrete card.

Applied the same preference install.sh uses for #7776, reusing the SHADOWING_INTEGRATED_GFX table already in this file rather than adding a second copy, and only when the arch that would be picked is itself a shadowing iGPU. An explicit mask still wins outright, including one that cannot be resolved (UUID, out of range), so masking a device remains the documented workaround from #7624 and #7669.

probe order before after
gfx1036, gfx1200 gfx1036 gfx1200
gfx1200, gfx1036 gfx1200 gfx1200
gfx1036 alone gfx1036 gfx1036
gfx1036, gfx1033 (all integrated) gfx1036 gfx1036
gfx1036, gfx906 gfx1036 gfx1036
gfx1036, gfx906, gfx1100 gfx1036 gfx1100
gfx1151, gfx1100 (Strix, not shadowing) gfx1151 gfx1151
any mask set mask's pick mask's pick
mask -1 or empty None None

2. A Vulkan choice was erased when the install fell back

persisted_marker_backend_request recorded "auto" whenever the request and the landed bundle disagreed. So a Vulkan choice that fell back to the ROCm bundle was erased from disk; every later update then re-detected, and on an AMD host detection means ROCm. The setting could not survive, which is exactly what the reporter described.

The request is now recorded verbatim, with the shortfall marked separately as backend_request_unsatisfied. Absent means satisfied, so every marker written before this change reads exactly as it does today.

Preserving it in that one function was not enough: the BackendUnavailable handler reassigns backend = "auto" before the marker is written, destroying the request a second time. Without also capturing it there the fix is inert on the reported path.

Retry policy (also in a comment at the check): a request named by this run via --llama-backend, UNSLOTH_LLAMA_CPP_BACKEND or Settings is re-asserted immediately; one read off the marker is retried only when a check below it fails, such as a new release tag, changed hardware, or a bundle that no longer covers the card. Retrying unconditionally would pay the release listing plus re-validation cost on every update forever on a host that cannot serve the choice. Never retrying would wedge it.

Two supporting changes outside the installer

Both required, not cosmetic:

  • _selection_applied treated any concrete request as applied by definition, which held only while the installer refused to record an unhonoured one. With the request preserved, _plan_llama_phase would have answered already_selected, and a user re-picking Vulkan in Settings could never retry it.
  • marker_backend_was_chosen now reports a flagged marker as detected, because the bundle on disk is the one detection picked. This keeps crash recovery reading exactly as it did before the request was preserved.

Tests

tests/studio/install/test_amd_hybrid_igpu_routing_11143.py is new (18 tests), plus 4 added to test_install_llama_prebuilt_logic.py. Confirmed failing at the merge base in a detached worktree, including:

FAILED test_a_leading_igpu_does_not_strand_the_discrete_card    - assert 'gfx1036' == 'gfx1200'
FAILED test_gfx906_is_never_the_repick                          - assert 'gfx1036' == 'gfx1200'
FAILED test_a_vulkan_request_that_landed_rocm_keeps_the_request - assert 'auto' == 'vulkan'
FAILED test_only_a_flagged_marker_may_disagree_with_its_own_backend
FAILED test_an_unsatisfied_choice_read_off_the_marker_does_not_reinstall_every_update

Nine of the new tests pass at the merge base by design: they are the must-not-move guards (mask wins, empty and unresolvable masks, all-integrated host, non-shadowing first arch, satisfied-request recording), not demonstrators.

Full runs on this branch: tests/studio/install 6882 passed, 59 skipped, 0 failed. studio/backend/tests/test_llama_backend_{selection,marker,switch}.py plus test_llama_cpp_update.py and test_setup_llama_cpp_backend.py 302 passed. ruff==0.15.12 clean.

Three existing tests changed deliberately

test_only_a_request_the_install_honours_is_recorded (renamed test_the_request_is_recorded_verbatim) and test_a_recorded_choice_this_host_cannot_serve_falls_back_to_detection asserted the old erasing behaviour. The assertion they made is the defect: erasing the choice at the re-detect is what made a configured Vulkan install return as ROCm on every subsequent update. test_a_marker_whose_request_and_backend_disagree_is_not_current needed no assertion change, since an unflagged disagreement is still rejected as a foreign marker; only its docstring was updated.

Limits

I could not reproduce the reporter's throughput recovery or their desktop glitches, which need that hardware. The GPU pin handling and the integrated-GPU ranking at load time are a further follow-up.

Before and after, in the UI

_selection_applied feeds the Compute backend row in Settings > Resources, so the change is visible there. Both halves are separate Studio installs built with install.sh --local, BEFORE from this PR's merge base and AFTER from its head.

Settings > Resources, Compute backend row, before and after

The install event put to both sides is the same one: the user asked for Vulkan, and the install landed something else. Each side then computed its own marker by importing its own install_llama_prebuilt.py and calling persisted_marker_backend_request("vulkan", <a linux-rocm bundle>), so the two halves differ only because the two installers answer differently.

before after
what the installer records auto vulkan
backend_request_unsatisfied function does not exist True
selection_applied true false
the row shows Automatic (CUDA) Vulkan
Apply greyed out live

That is the reported complaint in one frame: the choice is gone and there is no control left to retry it. After the change the row still names what is actually running, and Apply is offered so the request can be re-asserted.

Both halves report the same landed backend, which is the point: only the recorded request moved. That backend is this host's real CUDA install rather than the reporter's ROCm one, since no hybrid AMD machine was available. The mechanism does not depend on which backend landed, only on its differing from the request.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 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-09-21T14:07:55.488087Z 7e70239 New commits
🔒 Security Review ✅ Completed 2026-09-21T12:16:44.111565Z d125e63 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

Simulation report

Ran the full before/after/what-else-moved pass on this branch against merge base b32e63e, in isolated worktrees, with base arms. It found three defects, two of them in my own first follow-up commit, so this is worth reading before the diff.

issue: REAL | PR as submitted: DEFECTIVE, 1 reverted + 2 fixed | merge: YES once the windows-latest base arm lands

Is the change real

  • It executes. Line-traced rather than read: on the reported path head runs 22 statements against base's 15, and the result moves gfx1036 to gfx1200. On an untouched no-mask host the path is not byte-identical, it runs two extra statements (one frozenset membership test) for an identical result. Worth stating precisely rather than claiming "no change".
  • Reverting each hunk alone breaks only its own tests. Revert the repick block and 3 tests fail, 15 still pass. Restore the marker erasure and 4 fail, 76 pass. Nothing here passes against its own mocks.
  • Not already fixed. fix(studio/rocm): don't install for a shadowing iGPU on mixed AMD hosts (#7776) #7778, the original [Bug] AMD GPU not loading into VRAM or detected #7776 fix, touched install_python_stack.py and setup.ps1 but not studio/setup.sh, and left a comment at install_llama_prebuilt.py:3093 saying outright that _pick_rocm_gfx_target() does not apply the preference, using _apply_host_overrides as a compensation that only works when setup forwards a corrected arch. Linux never forwarded one. The gap was documented in the source by the author who left it.

What else moved

Enumerated every changed predicate over its full input space, all 1- and 2-device permutations of every shadowing, discrete and gfx906 arch against 9 mask values:

cells identical changed violations narrowed
_pick_rocm_gfx_target 2313 2257 56 0 0
_apply_host_overrides 840 840 0 0 0
marker readers 4320 3120 1200 0 on a marker without the new field n/a

Every changed cell is the intended repick. No input that previously found an arch stops finding one. _apply_host_overrides is output-invariant even though the active arch it receives differs in 140 of its 840 cells, so the repick cannot make torch and llama.cpp disagree about the card.

Detection is only reachable from the installer, with one exception: marker_backend_was_chosen is read by crash recovery in core/inference. That one is at model load, not per token. Across 168 unhonoured-request install shapes a flagged marker answers it identically to the marker the old code would have written, so the recovery path is unchanged.

Defects found

  1. Reverted, not patched. My first follow-up added a fallback in published_rocm_choice_for_host trying the host's other physical arches. Two independent adversarial passes found it broke two things: _kept_install_covers_host reads only host.rocm_gfx_target, so the bundle the fallback had just installed was rejected on every later run; and it ignored the visibility masks, so with HIP_VISIBLE_DEVICES=1 pinning the discrete card it selected a bundle for the masked-off iGPU. Rather than patch three more consumers I reverted it: test_rdna1_unsupported_message_8529 already records that CPU is the correct outcome on RDNA1, and quietly running the iGPU while the discrete card idles is the complaint in [Bug] b10995-mix-3e83366: Qwen3.8-Flash-Next MTP aborts at load (nextn.hc_head_norm still [hc_dim] after rebase) #11143, not the fix for it. The trade-off is now pinned by a test that explains it.
  2. Fixed. install_prebuilt passed the fast path its route but not override_has_rocm / override_rocm_gfx. An unsatisfied recorded request re-derives that route as auto, so without them it rebuilt the host profile from a bare probe. On every Linux AMD host, and setup.sh always forwards --rocm-gfx, the rebuilt profile then cannot match the recorded one, the fast path fails, and every update pays the whole release listing plus re-validation. The retry policy was defeating itself on exactly the hosts this PR is about.
  3. Fixed. An explicit backend_request_unsatisfied: false was not canonicalised away, giving readers two spellings of satisfied.

Release safety

4320 marker shapes compared, and none that lack the new field reads differently, so every existing install is untouched. An older build reading a new marker does not raise, the unknown key is ignored, and its own self-consistency check sends it down the full install path once, rewriting the marker. One extra reinstall on a downgrade, then consistent, no loop. The request and flag are written together through a temp file and atomic replace, so an interruption cannot leave half the pair.

Cross platform, with base arms

leg head base read
ubuntu-latest success clean
macos-15 2 failed, 531 passed 2 failed, 54 passed, same two tests, same assert 2 == 5 pre-existing
windows-latest 43 failed, 474 passed queued undetermined

macOS is structural and outlives this PR: preserve_backend is backend in CONCRETE_BACKENDS and host is not None and not host.is_macos, so on macOS it is always false and the path returns EXIT_FALLBACK where those two tests expect EXIT_BACKEND_UNAVAILABLE. Named, not fixed here.

Windows I am not calling yet. 34 of the 43 are test_setup_ps1_routing_matches_setup_sh, a Windows-only parity test between setup.ps1 and setup.sh, and #11437 modified setup.sh, so it cannot be waved away. That whole cluster passes on a Linux host with pwsh installed, 73 passed, which points at a Git-bash difference on the runner rather than a logic regression, but the base arm is what settles it.

Local: tests/studio/install plus the llama backend suites, 7423 passed, 60 skipped, 0 failed. ruff==0.15.12 clean.

What I could not prove

The reporter's throughput recovery and their desktop glitches, which need that hardware. Any of this on real AMD silicon: every routing claim is a control-flow reproduction over spoofed probe output. The windows-latest base arm at the time of writing. The name-inference fallback, where a record set with marketing names but no arches can still yield a shadowing arch for device 0, is out of scope and declared in #11437. ARM64 and Intel macOS legs were not run.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 21, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: d125e6368c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@shimmyshimmer
shimmyshimmer force-pushed the amd-igpu-installer-gfx-pick-and-backend-request branch from d125e63 to c4b788f Compare September 21, 2026 12:19
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: d125e6368c

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

@shimmyshimmer

Copy link
Copy Markdown
Member

Cross-platform follow-up: the Windows leg is resolved

The simulation report above left one leg undetermined, because the windows-latest baseline arm was still queued. It has now reported, and the answer is that nothing on Windows regressed.

The baseline arm was built as base code with the head tests, and I verified that rather than assuming it: install_llama_prebuilt.py on the baseline branch contains zero occurrences of backend_request_unsatisfied, while test_forwarded_gpu_detection_is_not_a_selection_change is present. That is the arm a differential needs.

leg head baseline read
ubuntu-latest success - clean
macos-15 2 failed, 531 passed 2 failed, 54 passed, same two tests, same assert 2 == 5 pre-existing
windows-latest 43 failed, 474 passed, 17 skipped 43 failed, 433 passed, 17 skipped pre-existing

On Windows both arms fail the same 43 tests. Sorting the two name sets and diffing them gives an empty result in both directions, so nothing regressed and nothing was masked.

34 of the 43 are test_setup_ps1_routing_matches_setup_sh. On windows-latest the shell shim exits before the assertion is reached (setup_fail: 3, UTF-16 stdout, SystemExit 2 or 5), so that leg cannot distinguish base from head at all. It is a Git bash harness limitation on the hosted runner, not a logic difference: the same cluster passes locally where pwsh runs (73 passed). Three of this PR's own tests sit in that set and fail identically on the baseline for the same reason, so Windows CI proves "no regression" here, not "verified on Windows". Local coverage is what verifies them: 7425 passed, 60 skipped, 0 failed across tests/studio/install plus the llama backend suites.

So the verdict is now unconditional rather than conditional on that leg.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 21, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 21, 2026
Base automatically changed from amd-igpu-linux-setup-sh-discrete-preference to main September 21, 2026 14:00
danielhanchen and others added 8 commits September 21, 2026 14:01
Two defects behind the same report on #11143, where a Fedora host with an
integrated GPU driving the desktop and a discrete RX 9060 XT (gfx1200) kept
using the iGPU and ROCm even though the discrete card and Vulkan were selected.

_pick_rocm_gfx_target honoured HIP_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES and
CUDA_VISIBLE_DEVICES and then ended "return _tokens[0]", so with no mask set a
leading integrated GPU decided the arch for the whole install and stranded the
discrete card. Apply the same preference install.sh uses for #7776, reusing the
SHADOWING_INTEGRATED_GFX table already in this file rather than adding a second
copy, and only when the arch that would be picked is itself a shadowing iGPU.
An explicit mask still wins outright, including one that cannot be resolved, so
masking a device stays the documented workaround from #7624 and #7669.

persisted_marker_backend_request recorded "auto" whenever the request and the
landed bundle disagreed, so a Vulkan choice that fell back to the ROCm bundle
was erased from disk. Every later update then re-detected, and on an AMD host
detection means ROCm, so the setting could not survive. Record the request
verbatim and mark the shortfall separately with backend_request_unsatisfied.
Absent means satisfied, so markers written before this change read exactly as
they do today.

Preserving the request in that one function was not enough on its own: the
BackendUnavailable handler reassigns backend = "auto" before the marker is
written, which destroyed the request a second time. Capture it first and persist
the unhonoured name.

Retry policy, also in a comment at the check: a request named by this run is
re-asserted immediately, while one read off the marker is retried only when a
check below it fails, such as a new release tag, changed hardware or a bundle
that no longer covers the card. Retrying unconditionally would pay the release
listing and re-validation cost on every update forever on a host that cannot
serve the choice; never retrying would wedge it.

Two supporting changes outside the installer, both required rather than
cosmetic. _selection_applied treated any concrete request as applied by
definition, which was true only while the installer refused to record an
unhonoured one; with the request preserved, _plan_llama_phase would have
answered already_selected and a user re-picking Vulkan in Settings could never
retry it. marker_backend_was_chosen now reports a flagged marker as detected,
because the bundle on disk is the one detection picked, which keeps crash
recovery reading exactly as it did before the request was preserved.

Three existing tests asserted the erasing behaviour and are updated: the
assertion they made is the defect.
Found by simulating the discrete-GPU preference in the previous commit against
the release manifest's real arch coverage, rather than against the pairs the
tests happened to name.

published_rocm_choice_for_host matched only host.rocm_gfx_target, and returned
None so the caller source-builds when no bundle covered it. That was safe while
the active arch was whatever enumerated first. Now that the preference moves it
onto the discrete card, a host whose discrete arch this release does not build
loses a bundle it used to get: among the shadowing arches only gfx1103 is served,
by the gfx110X family, so a gfx1103 APU beside an RDNA1 gfx1010 to gfx1012, or a
gfx1152, went from a working prebuilt to a source build. Four such pairs over the
published coverage, and a source build is slower and can fail outright.

Try the preferred arch first, then the host's remaining physical arches, and
source build only when NO physical arch is served, which is the case the None
return exists for. The selection log names the fallback and the arch that had no
bundle, so a host running the iGPU's bundle says why.

This only adds attempts where there were none, so it cannot narrow: over every
shadowing-iGPU and discrete pair, hosts served a published bundle go from 12 to
60 of 84, and no pair loses one.
…he fast path

Simulating the previous commit surfaced three defects, two of them in that commit.

Revert the published_rocm_choice_for_host fallback. It tried the host's other
physical arches when no bundle covered the preferred one, and it was wrong twice
over. _kept_install_covers_host reads only host.rocm_gfx_target, so the bundle the
fallback had just installed was rejected on every later run, three consecutive
checks returning False. And it ignored the visibility masks: with
HIP_VISIBLE_DEVICES=1 pinning the discrete card it chose a bundle for the masked
off iGPU, which contradicts the rule the repick itself follows.

Patching the three downstream consumers to match was the wrong trade. The case the
fallback existed for is a gfx1103 APU beside a discrete arch this release does not
build, and test_rdna1_unsupported_message_8529 already records that CPU is the
correct outcome on RDNA1. Quietly running the iGPU while the discrete card sits
idle is the complaint in #11143, not the fix for it. The trade-off is pinned by a
test that says so, so moving it later is a decision rather than an accident.

install_prebuilt passed the fast path its route but not override_has_rocm or
override_rocm_gfx. An unsatisfied recorded request re-derives that route as "auto"
inside existing_install_current_without_plan, so without them it rebuilt the host
profile from a bare probe. On every Linux AMD host, and setup.sh always forwards
--rocm-gfx, the rebuilt profile then cannot match the one the install recorded, the
fast path fails, and every update pays the whole release listing plus
re-validation. That is the cost the recorded-request retry policy exists to avoid,
so it was defeating itself on exactly the hosts this PR is about.

Canonicalise an explicit backend_request_unsatisfied of false away on reuse.
Absent is meant to be the only spelling of satisfied, and leaving a false behind
gave readers two ways to say one thing.

tests/studio/install plus the llama backend suites: 7423 passed, 60 skipped.
On macOS the universal Metal bundle is the only build, and "metal" is kept out of
REQUESTABLE_BACKENDS for exactly that reason, so a recorded "cpu" or "vulkan"
there can never become the installed backend. Preserving it left Settings holding
a selection the picker has no option for: resolve_backends_payload iterates
("auto",) on macOS, _selection_applied reports the stored request as unapplied,
and the Apply it offers is then refused as backend_unavailable. Permanently, with
no later release able to resolve it.

Record detection in that case, as the erasing rule did. The test is the landed
backend not being requestable at all, rather than a macOS check, because that is
the actual condition: a platform that publishes one build cannot owe a request.
marker_backend_request_was_satisfied agrees, so no flag is written either.

Preservation is untouched where a later release could still honour the request,
which is the case this PR exists for: vulkan landing on linux-rocm is still
recorded as vulkan and still flagged unsatisfied.

tests/studio/install plus the llama backend suites: 7425 passed, 60 skipped.
Comment and docstring only, no code change.
@shimmyshimmer
shimmyshimmer force-pushed the amd-igpu-installer-gfx-pick-and-backend-request branch from 17f2f5a to 7e70239 Compare September 21, 2026 14:02
@shimmyshimmer
shimmyshimmer merged commit 6770853 into main Sep 21, 2026
46 of 49 checks passed
@shimmyshimmer
shimmyshimmer deleted the amd-igpu-installer-gfx-pick-and-backend-request branch September 21, 2026 14:02
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…te (unslothai#11442)

Two changes, both from the unslothai#11143 follow-up.

_pick_rocm_gfx_target() ended at the first enumerated arch, so on a hybrid host an integrated GPU that enumerated first decided the llama.cpp bundle for the whole machine. It now prefers the first arch that is neither in SHADOWING_INTEGRATED_GFX nor gfx906, the same rule the shells apply. An explicit visibility mask is never second-guessed at any value, and an all-integrated host keeps its own arch.

persisted_marker_backend_request() recorded "auto" whenever the request and the bundle that landed disagreed, which erased the choice permanently: every later update re-detected, and on an AMD host detection means ROCm, so a configured Vulkan install kept coming back as ROCm with Settings showing Automatic. The request is now recorded verbatim with backend_request_unsatisfied alongside it, so a later update can retry it. Markers written before this field read as satisfied by absence, so no existing install changes. Single-build platforms still record detection, since a named backend there could never be offered or applied.

Also carries the routing tests, the marker back-compat tests, and before/after UI evidence for the Settings backend row in the description.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants