Repository navigation
Studio: prefer the discrete AMD GPU when an iGPU enumerates first on Linux - #11437
Conversation
…Linux studio/setup.sh resolved the AMD gfx arch at visible index 0 and forwarded it as --rocm-gfx, with no preference for a discrete card. On a hybrid host whose integrated GPU enumerates first, that forwards the iGPU's arch, and install_llama_prebuilt.py reads a forwarded --rocm-gfx as implying the host has ROCm. The iGPU's arch then matches no published linux-rocm bundle, so the install falls through to a source build. The preference that avoids this landed for #7776 in install.sh, studio/setup.ps1 and studio/install_python_stack.py, but never in studio/setup.sh, which is the script that "unsloth studio update" runs in full. So the Linux update path was the one entry point still picking whatever enumerated first. Port the two helpers from install.sh and apply the repick before the arch reaches either consumer (_PREBUILT_CMD and _WHISPER_CMD). The table is copied verbatim so the existing parity test keeps both copies in step. The wheel-route filter is deliberately not copied: install.sh uses it to pick a torch wheel family, while the consumer here is the llama.cpp prebuilt bundle. Unchanged by construction: single GPU hosts, NVIDIA hosts, hosts whose first arch is not a known shadowing iGPU, and any host where the user set HIP_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES or CUDA_VISIBLE_DEVICES, since masking a device is a deliberate choice the repick must not second guess. An iGPU only host keeps its iGPU, which is what ROCM_RDNA2_APU.md documents. UNSLOTH_ROCM_GFX_ARCH still wins outright. The parity test guarded the gfx tables but not whether anything applied them, which is how this gap survived: its own docstring describes install_llama_prebuilt.py as honouring "setup's repick", and on Linux there was no repick to honour. Extend it to assert the preference is reached on each shell entry point's resolution path, that it runs before the arch is forwarded to both consumers, that all three visibility masks are honoured, and that gfx906 is never a repick candidate. Reported on #11143 by a user on Fedora with an integrated GPU driving the desktop and a discrete RX 9060 XT (gfx1200).
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 security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
Comment and docstring only, no code change.
…unslothai#11472) test_setup_gpu_summary_probe_sources.sh builds a runnable block by pulling named functions out of studio/setup.sh. unslothai#11437 added _amd_prefer_discrete_gfx and _amd_gfx_is_shadowing_integrated and called them from the selection block, but not from a function the test extracts, so the block ran with both undefined: 8 passed, 29 failed, every case that reaches a discrete versus integrated choice dying on command not found. Both helpers are now extracted into both halves the test builds, and a guard fails loudly if either stops arriving, the way the existing ones do for the record parsers. 37 passed, 0 failed on main, and every other suite under tests/sh stays green.
…othai#11538) The harness builds a runnable block by sed-ing named functions out of studio/setup.sh. When setup.sh gains a helper and the selection block calls it, nothing here notices until the block runs with it undefined, and then every case that reaches the call dies on a bare "command not found". unslothai#11437 did exactly that with _amd_prefer_discrete_gfx: 8 passed, 29 failed, and not one of the 29 named the cause. unslothai#11472 added the helper to the sed lines and a named grep guard for it, which fixes that helper and only that helper. The next one repeats it. Give each extracted artifact a command_not_found_handle instead, so the first call that is actually reached says which function is missing and which sed line would supply it. Reached, not merely present: setup.sh arms this test never takes do call helpers it never extracts (the NVIDIA banner, the step/substep printers), so a static scan of the text reports those as defects when they are not. A static version of this guard failed the suite on all three.
…Linux (unslothai#11437) studio/setup.sh resolved the AMD gfx arch at visible-index 0 and forwarded it as --rocm-gfx, so on a hybrid host an integrated GPU that enumerated first decided the llama.cpp bundle for the whole machine while torch targeted the discrete card. install.sh, setup.ps1 and install_python_stack.py all applied the shadowing-iGPU preference; setup.sh had neither the table nor the preference, and it is the script `unsloth studio update` runs in full. Ports _amd_gfx_is_shadowing_integrated and _amd_prefer_discrete_gfx into setup.sh and applies the repick before the UNSLOTH_ROCM_GFX_ARCH override. An explicit HIP_/ROCR_/CUDA_VISIBLE_DEVICES mask is never second-guessed, gfx906 is never a repick candidate, and an all-integrated host keeps its own arch. Extends tests/studio/install/test_rocm_arch_table_parity.py to hold the APPLICATION of the preference in parity across installers, not just the table, which is how this gap escaped.
…unslothai#11472) test_setup_gpu_summary_probe_sources.sh builds a runnable block by pulling named functions out of studio/setup.sh. unslothai#11437 added _amd_prefer_discrete_gfx and _amd_gfx_is_shadowing_integrated and called them from the selection block, but not from a function the test extracts, so the block ran with both undefined: 8 passed, 29 failed, every case that reaches a discrete versus integrated choice dying on command not found. Both helpers are now extracted into both halves the test builds, and a guard fails loudly if either stops arriving, the way the existing ones do for the record parsers. 37 passed, 0 failed on main, and every other suite under tests/sh stays green.
…othai#11538) The harness builds a runnable block by sed-ing named functions out of studio/setup.sh. When setup.sh gains a helper and the selection block calls it, nothing here notices until the block runs with it undefined, and then every case that reaches the call dies on a bare "command not found". unslothai#11437 did exactly that with _amd_prefer_discrete_gfx: 8 passed, 29 failed, and not one of the 29 named the cause. unslothai#11472 added the helper to the sed lines and a named grep guard for it, which fixes that helper and only that helper. The next one repeats it. Give each extracted artifact a command_not_found_handle instead, so the first call that is actually reached says which function is missing and which sed line would supply it. Reached, not merely present: setup.sh arms this test never takes do call helpers it never extracts (the NVIDIA banner, the step/substep printers), so a static scan of the text reports those as defects when they are not. A static version of this guard failed the suite on all three.
Follow-up to a report on #11143: on Fedora with an integrated AMD GPU driving the desktop plus a discrete RX 9060 XT (
gfx1200), Studio kept using the iGPU and ROCm even though the user had configured the discrete card and Vulkan. Desktop glitches, out of memory errors on settings that previously worked, and throughput dropping from 21 tok/s to 5 tok/s. Only a full uninstall and reinstall cleared it.The gap
studio/setup.shresolves the AMD gfx arch at visible index 0 and forwards it as--rocm-gfx, with no preference for a discrete card.install_llama_prebuilt.pyreads a forwarded--rocm-gfxas implying the host has ROCm. So on a hybrid host whose iGPU enumerates first, the iGPU's arch is forwarded, matches no publishedlinux-rocmbundle, and the install falls through to a source build.The preference that avoids exactly this landed for #7776 in
install.sh,studio/setup.ps1andstudio/install_python_stack.py. It never landed instudio/setup.sh, which is the scriptunsloth studio updateruns in full, so the Linux update path was the one entry point still picking whatever enumerated first. That is also why the Windows and macOS reporters on the same thread did not see this.What changed
Ported
_amd_gfx_is_shadowing_integratedand_amd_prefer_discrete_gfxfrominstall.shintostudio/setup.sh, applied before the arch reaches either consumer (_PREBUILT_CMDand_WHISPER_CMD). The table is copied verbatim so the existing parity test keeps both copies in step.install.shadditionally filters candidates through a wheel-route predicate. That is deliberately not copied: there the consumer is a torch wheel family, here it is the llama.cpp prebuilt bundle. There is a comment saying so, so it does not get "restored" later.Not affected
Verified by executing the helpers under both
dashandbash:gfx1036iGPU first,gfx1200discretegfx1036gfx1200gfx1200gfx1200gfx1200gfx1200gfx1036gfx1036gfx1036gfx1036gfx906gfx1036gfx1036gfx1036,gfx906,gfx1100gfx1036gfx1100gfx1151+gfx1100gfx1151gfx1151Any of
HIP_VISIBLE_DEVICES,ROCR_VISIBLE_DEVICESorCUDA_VISIBLE_DEVICESbeing set returns the pick unchanged, since masking a device is a deliberate choice and it is the documented workaround on #7624 and #7669. An iGPU only host keeps its iGPU, which is whatROCM_RDNA2_APU.mddocuments.UNSLOTH_ROCM_GFX_ARCHstill wins outright. NVIDIA hosts never enter the branch.The parity test guarded the wrong half
test_rocm_arch_table_parity.pykept the gfx tables in step across installers but never checked that anything applied them. Its own docstring describesinstall_llama_prebuilt.pyas honouring "setup's repick", and on Linux there was no repick to honour. That is how this survived.Extended it to assert the preference is reached on each shell entry point's resolution path, that it runs before the arch is forwarded to both consumers, that all three visibility masks are honoured, and that
gfx906is never a repick candidate. These fail on the current tree forstudio/setup.shand pass forinstall.sh, so the guard discriminates rather than failing blanket.One note for reviewers: the ordering assertion anchors on
_PREBUILT_CMD+=(--rocm-gfxrather than a bare--rocm-gfx, because the flag is named in eight comments before the first real argv site and a substring search there cannot be satisfied by any correct placement.Tests
tests/studio/install/:test_rocm_arch_table_parity.py106 passed, plustest_rocm_support.py,test_selection_logic.py,test_rocm_rdna_routing.py,test_rocm_gfx_spoof_7331.py,test_gpu_detection_followups.py,test_unsupported_arch_routing_guards_8529.pyandtest_setup_keeps_gpu_prebuilt_over_cpu_source_fallback.py: 1259 passed, 1 skipped.bash -nclean and shellcheck unchanged at 50 findings before and after.sh -nfails at line 124 both before and after this change: the file is#!/usr/bin/env bashand already uses bash arrays.Scope and limits
This covers the
rocminfoandamd-smiarch paths. It does not cover the name inference fallback: if a record set carries marketing names but no arches, device 0 can still yield an integrated arch. Fixing that means inferring an arch for every record and changes the inference path's behaviour, so it is left for a follow-up._pick_rocm_gfx_targetininstall_llama_prebuilt.pyhas the same missing preference and endsreturn _tokens[0]. That fix, the marker handling that erases an unsatisfied Vulkan choice, and the GPU pin handling are a stacked follow-up.I could not reproduce the reporter's throughput recovery or their desktop glitches, which need that hardware.