Repository navigation
Studio installer: torch 2.11 on Linux CPU, Vulkan for AMD without ROCm, gfx1033 gate, and three install fixes - #8412
Conversation
…m, gfx1033 gate, and three install fixes Split out of #8343, which also rewrites the Linux AppImage packaging. These six installer changes are independent of that work and verified on their own, so they land here while the AppImage side finishes. Original work by Thomas Eric (@ThomasEricB), who found all six on a Steam Deck. Co-authored-by: Thomas Eric <[email protected]>
|
Verification notes for this split, since the value here is that these six are independently checked. Nothing outside the intended cells moved. I lifted the real constraint table out of both revisions and diffed every cell of {linux, wsl, macos} x {x86_64, aarch64, arm64} x {cpu, cu118, cu124, cu126, cu128, cu130, rocm6.0-6.4, rocm7.0-7.2, gfx103X-all, gfx110X-all, gfx120X-all, gfx1150, gfx1151, gfx1152, gfx90a, gfx908, xpu, a mirror leaf whose base path contains "cpu"}. 216 cells, six changed, all Same for llama.cpp routing against the real One behaviour change worth naming. A headless server whose only display device is an ATI/AMD BMC chip (ES1000 and similar are also PCI vendor 0x1002) now gets the Vulkan llama.cpp bundle instead of the CPU one. The superset argument covers it, since that bundle ships the same One upgrade note. Moving The AppImage rewrite from #8343 is deliberately not here. It has a Noble-specific renderer failure that is still open, and none of the above depends on it. |
|
@danielhanchen Since you did this split, please add #6982 on here as well. |
#8479 moved venv creation behind _run_uv_venv, so the label this test grepped for no longer exists and the ordering assertion read as a too-late cache rather than a stale grep. Also drop a .studio-test-root artifact that a local test run left behind in the commit.
…he fallback Match gfx1033 as a TOKEN in the multiline ROCm probe. _probe_amd_gfx_arch keeps every `grep -oE` hit, and rocminfo names each GPU agent twice: once as the agent's own "Name: gfx1033" and once in its ISA Info block as "amdgcn-amd-amdhsa--gfx1033". A single-GPU Steam Deck therefore already probes as "gfx1033\ngfx1033", which the exact-string case did not match, so the host fell through to the version-keyed ROCm index and installed the very wheels the gate exists to avoid. Flatten to one space-delimited, lowercased, suffix-stripped line; the surrounding spaces keep gfx10330 out. Stop forwarding a rejected gfx1033 override to llama.cpp. Clearing the local _linux_inferred_gfx is not enough: setup.sh copies UNSLOTH_ROCM_GFX_ARCH straight into --rocm-gfx, and _apply_host_overrides reads any forwarded gfx as proof of ROCm (has_rocm = True). On a Van Gogh host with no ROCm that skips the AMD-without-ROCm Vulkan branch this release adds and asks for a ROCm prebuilt or a HIP source build the host cannot run. Unset the rejected override so setup.sh re-probes; a host that really does have ROCm still finds gfx1033 through its own rocminfo call, and a UNSLOTH_TORCH_INDEX_URL pin returns long before this block. Fall back to uv's default cache when the colocated one cannot be created. uv aborts with "Failed to initialize cache at ..." on a cache path it cannot create, so ignoring the mkdir status while keeping the export turned a disk optimisation into a hard install failure on a host where uv's own default would have worked. Measured: with STUDIO_HOME writable and its "cache" entry a file, `uv venv` exits 2 with the export and 0 without it. Tests: the gate test fed the gate a hand-built one-token probe, which is not what the probe produces, so it passed throughout. Drive the real get_torch_index_url against a real rocminfo shape instead, and assert first that the probe really is multi-line so a future single-hit probe cannot turn that into a vacuous pass.
Returning None from _amd_arch_index_url only stops a gfx1033 host from being GIVEN ROCm wheels. A venv that already holds them -- installed before the gate existed, and carried through the legacy-venv migration untouched because its forward-only validation passes on this arch -- was never demoted: install.sh resolves UNSLOTH_TORCH_BACKEND=cpu, which returns _ensure_rocm_torch at its first line; _ensure_cpu_torch fired only for an EXPLICIT pin; and the base update does not reinstall an already-satisfied torch. Upgrading therefore left in place exactly the build the gate exists to remove, on the machines that most need it removed. Treat the arch itself as CPU authority so _ensure_cpu_torch does the demotion. Scoped tightly: every AMD arch on the host must be a measured-bad one (a healthy dGPU beside the APU keeps ROCm), an explicit UNSLOTH_TORCH_INDEX_URL / _FAMILY still wins, and the disk label is read before any probe so hosts with no ROCm torch pay nothing. The arch probe ignores HSA_OVERRIDE_GFX_VERSION, which is the usual Van Gogh workaround and would otherwise make rocminfo answer gfx1030 and hide the arch being judged.
ROCR_VISIBLE_DEVICES filters the HSA runtime's agent list, so it removes GPUs from rocminfo's output too. A masked-out AMD device on a ROCm host therefore leaves the ROCm probe empty and reads as a driver-only box, and the new DRM sysfs pass set has_amd_gpu_without_rocm anyway. Vulkan honours none of the HIP masks -- it selects through GGML_VK_VISIBLE_DEVICES -- so the install would hand llama.cpp the exact GPU the caller hid, which _should_auto_vulkan_for_amd_windows already refuses on Windows and the has_physical_nvidia gate already refuses for CUDA_VISIBLE_DEVICES. Conjoin the mask check with a ROCm probe actually being installed rather than reusing _hip_visible_device_mask_set alone: the driver-only AMD host this branch exists for ships no rocminfo or amd-smi, and measuring it showed a bare exported CUDA_VISIBLE_DEVICES would otherwise cost a Steam Deck the Vulkan bundle. Intel is not addressed by HIP masks and keeps its plain detection.
install.sh was the only conflict. Main replaced this branch's _persist_local_bin_on_path with a more capable _persist_login_path_dir: any directory rather than one hardcoded path, a fish conf.d arm (fish reads none of the POSIX rc files, so an export line there is a no-op for a fish user), and a _PATH_LINE_RE that distinguishes a line which SETS PATH from one that merely names the directory, so UV_CACHE=/opt/uv and PYTHONPATH=/opt/uv no longer count as an existing entry. Taking main's side wholesale would have reintroduced what this branch fixed: its three appends are unguarded, and with set -e at install.sh:20 an rc file that cannot be written aborts the installer at its very last cosmetic step, after the venv, llama.cpp and the shim are already in place. The user sees "Unsloth Studio Installed" followed by a hard failure, and the Tauri/AppImage path reports the whole install as failed. Immutable and managed homes hit this every time: NixOS and home-manager symlink ~/.bashrc into the read-only Nix store, and chezmoi, stow and yadm do the same. So this keeps main's structure and puts the guard back around the appends in both arms: one redirect rather than three, so a write that dies midway cannot leave a dangling comment with no export under it, and a failure is a warning carrying the line to add by hand rather than a non-zero exit. tests/sh/test_shell_rc_path_append.sh retargeted onto the new function. Every clause it guards is a property of the append, not of the old signature, so they all still apply; the rc file goes in through the optional $5 so the selection cascade stays out of it, SHELL is pinned so a developer running the suite under fish does not silently exercise the other arm, and the fish arm gets the same three cases. 25 passed. Also green: get_torch_index_url 64, torch_constraint 56, rocm_bad_arch_gate 40, install_rollback_lifecycle 19, uv_cache_colocation 11, install_host_defaults 11.
|
Confirmed main still maps gfx1033 into gfx103X-all at install.sh:3147 and still gates every Vulkan branch on has_intel_gpu in studio/install_llama_prebuilt.py, so both fixes are needed. The direction is right, but six independent installer changes plus the RDNA2 doc in one branch is hard to review or revert individually; could you split the gfx1033 gate and the Vulkan routing into their own PRs and keep the rc-write, uv cache, torch 2.11 and ROCm path fixes together? @LeoBorcherding could you take a look at this one? |
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: Didn't find any major issues. Keep them coming! 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". |
|
@oobabooga please don't forget to merge the pr #6982 together with this one |
The gfx1033 gate declined to INSTALL ROCm when the selected runtime target is a miscomputing arch, but it did not remove a ROCm build the venv already held. On a mixed host, a gfx1033 APU beside a healthy dGPU, _rocm_miscomputing_host() is False by design (it requires every physical AMD arch to be miscomputing), so _ensure_cpu_torch() had no authority to demote either. A device mask selecting the APU therefore printed "keeping CPU torch" while ROCm torch stayed installed, and the selected APU kept producing incorrect gradients under it. The message was wrong at the same time as the state. The two gates answer different questions and only the first could demote: _rocm_miscomputing_host() reads the inventory, while this branch reads the selected target, which is the one that decides what actually runs. Recorded the selected-target verdict and taught _ensure_cpu_torch to treat it as CPU authority, which is the path the inventory gate already used. Scoped to the case: with no such verdict a mixed host is untouched, so a machine whose selected target is the healthy dGPU keeps ROCm.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da89c3be8a
ℹ️ 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".
| if pin is None and _ROCM_DECLINED_FOR_TARGET: | ||
| # The mixed host: _rocm_miscomputing_host() is False because a healthy dGPU is | ||
| # present, but the selected target is the miscomputing one, so ROCm wheels must not | ||
| # stay in the venv even though the inventory alone would allow them. | ||
| pin = f"{_PYTORCH_WHL_BASE}/cpu" |
There was a problem hiding this comment.
Preserve the selected-target verdict on CPU handoffs
When install.sh resolves the backend to CPU, _ensure_rocm_torch() returns immediately at its _TORCH_BACKEND == "cpu" guard, so it never sets _ROCM_DECLINED_FOR_TARGET. On a mixed gfx1033 + healthy AMD host, _rocm_miscomputing_host() is deliberately false; consequently a migrated environment that already contains ROCm torch is not demoted even when a visibility mask selects gfx1033, leaving the build that produces incorrect training results in place. Derive the selected-target demotion independently of _ensure_rocm_torch(), or run that target check before its CPU-backend return.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining this, and reverting the change it builds on. You are right that the CPU-backend return skips the verdict, but chasing that led me to the invariant both items are asking me to break.
test_a_mask_cannot_shrink_the_host_to_its_bad_gpu states it: "Every arch is bad" is a question about the HOST, so it is asked of the whole host. ROCR_VISIBLE_DEVICES hiding a healthy dGPU would otherwise leave gfx1033 as the only arch and demote a working ROCm install to CPU. The demotion path calls _detect_amd_gfx_codes(ignore_hsa_override = True, ignore_visible_masks = True) for exactly that reason, and install.sh's _probe_amd_gfx_arch unsets both masks too.
Keying demotion off the selected runtime target is that bypass, one door over from the HSA_OVERRIDE spoof the neighbouring tests cover. Deriving it independently of _ensure_rocm_torch, as suggested here, would make it fire on the install path as well and complete the contradiction. Reverted in d7c7120.
I accepted a review item asking for this and was wrong: it contradicts a deliberate invariant this file already documents and tests. test_a_mask_cannot_shrink_the_host_to_its_bad_gpu states it directly. "Every arch is bad" is a question about the HOST, so it is asked of the whole host: ROCR_VISIBLE_DEVICES hiding a healthy dGPU would otherwise leave gfx1033 as the only arch and demote a working ROCm install to CPU. The demotion path calls _detect_amd_gfx_codes(ignore_hsa_override = True, ignore_visible_masks = True) for that reason, and install.sh's _probe_amd_gfx_arch unsets both masks too. Keying demotion off the selected runtime target is exactly the bypass that guards against, one door over from the HSA_OVERRIDE spoof the same tests cover. It went in green only because the demotion tests call _ensure_cpu_torch() directly, so the flag set inside _ensure_rocm_torch() was never exercised. What remains true is narrower and not worth this risk: on a masked mixed host the branch prints "keeping CPU torch" while a ROCm build stays installed, so the wording is inaccurate even though keeping it is the intended outcome.
It printed "keeping CPU torch", which it cannot promise: whether an already-installed ROCm build is removed is _ensure_cpu_torch's call, and that asks about the whole host with the visible-device masks stripped, so a mixed host with a healthy dGPU keeps ROCm on purpose. The branch only declines to install ROCm for this target, so it now says that. The whole-host message above is unchanged, since there the demotion really does follow.
|
Correcting an earlier call of mine on this PR. I agreed with the review item about demoting ROCm torch when the selected target is gfx1033, shipped it in da89c3b, and it was wrong. Reverted in d7c7120. The original thread has since been pruned, so this is the record. The demotion is deliberately not keyed on the selected target. My change passed CI only because the demotion tests call What was real is narrower and is fixed: the branch printed "keeping CPU torch" when it cannot promise that, since removing an installed ROCm build is
|
|
Codex Review: Didn't find any major issues. Swish! 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". |
Compress the explanatory blocks to their load-bearing content: 584 added comment lines down to 313. No behaviour change; every test suite this PR touches still passes.
|
The one red check here, The job fails on The preceding six runs of that workflow on |
Same content, fewer lines. Comments and docstrings only; no code changed.
Split out of #8343. Original work by @ThomasEricB, who found all six of these running Unsloth Studio on a Steam Deck.
#8343 does two separable things: it fixes six installer bugs, and it rewrites the Linux AppImage packaging. The AppImage half is still in progress and needs hardware I do not have to sign off on. These six do not depend on it, so they land here rather than waiting.
What is in here
install: keep gfx1033 off the ROCm torch index— the most valuable one. The ROCm wheel index is chosen from the runtime version, never the arch, and gfx1033 (Van Gogh, the Steam Deck APU) maps togfx103X-all. Those wheels install and then return wrong answers: with identical seed and data over 60 SGD steps, CPU converges0.9710 -> 0.1148while the GPU gives-0.7765 -> nanon rocm7.1/torch 2.10,0.0 -> 1.0 -> 17.4674on rocm7.2/torch 2.11, andnanon AMD's own native gfx1033 build. A negative MSE loss is not attainable.gradcheckfails in float64 on all three while forward math matches CPU to4.2e-07.The gate asks whether a prohibited arch is present, not which GPU the runtime will select. That distinction is the whole design. Presence is answerable from a flat probe and no environment variable can move it; selection needs per-device identity, the ROCr/HIP mask layering, ordinals and UUIDs, and knowledge of which probe applied which mask — and no probe applies both (rocminfo honours
ROCR_VISIBLE_DEVICESand ignores the HIP pair; amd-smi reads the driver and honours neither).install_python_stack.pyalready resolves selection properly in_runtime_gfx_target()/_rocr_visible_subset(), so the shell gate does not attempt it.The probe runs in "physical" mode, so neither
HSA_OVERRIDE_GFX_VERSION=10.3.0(the circulated Van Gogh workaround, which makes ROCr rename the agentgfx1030) nor a staleUNSLOTH_ROCM_GFX_ARCHcan hide the silicon from a presence test. Scope is exactly the arch measured: gfx906 keeps its rocm6.3 legacy index and gfx1030-gfx1036 keepgfx103X-all(#7277).Cost of the simpler rule: a mixed host — a Van Gogh APU beside a healthy AMD dGPU — takes the cpu index even when the healthy card is selected. Van Gogh ships in handhelds, so such a host is vanishingly rare; it keeps the documented
UNSLOTH_TORCH_INDEX_URLescape hatch, and_ensure_rocm_torch()can still route it to ROCm on a later run, where the selected device is resolved properly. Demotion of an already-installed ROCm torch stays on the every-arch rule deliberately: giving CPU wheels to a fresh install is cheap and reversible, force-reinstalling over a working multi-GPU setup is not.llama.cpp: use the Vulkan prebuilt on Linux AMD GPUs without usable ROCm— every AMD branch was gated onhas_rocmand the Vulkan branch requiredhas_intel_gpu, so an AMD GPU with no working ROCm was indistinguishable from a headless CPU box and got the CPU bundle. Measured on a Deck (Qwen2.5-0.5B Q4_0,llama-bench, pp128/tg64):HSA_OVERRIDE_GFX_VERSIONWidening this cannot regress anyone: the Vulkan bundle is a superset of the CPU bundle, shipping the same
libggml-cpu-*.sonext tolibggml-vulkan.so, and with no usable Vulkan device it enumerates zero devices and runs on the CPU backend. Verified on the real b10726 assets — all 15libggml-cpu-*.sovariants are present in both, and with the ICD hidden the same binary lists(none), exits 0, and still generates.ROCR_VISIBLE_DEVICESsuppresses the automatic route, since Vulkan honours no ROCm mask; the HIP-layer variables do not, because they cannot be why a ROCm inventory came back empty.install: torch 2.11 on the Linux CPU index— the cpu index ships the whole trio for cp310-cp314 onmanylinux_2_28. Floored at Python 3.10 and glibc 2.28, both of which are load-bearing. The constraint being replaced is a window,>=2.4,<2.11.0, whose lower end still has pre-manylinux_2_28wheels: resolved against the live index atx86_64-manylinux_2_17, the window yields torch 2.6.0+cpu for cp310-cp313 while>=2.11.0yields "No solution found"._uv_pinned_assetbootstraps uv on x86_64 from glibc 2.17 up, so that range is supported here — CentOS 7 (2.17), Debian 9 (2.24), Amazon Linux 2 (2.26), Ubuntu 18.04 (2.27). The floor therefore applies only where a 2.11 wheel exists; musl or an unreadable ldd keeps the old window. macOS is excluded (it shares this leaf and has had no smoke pass) andinstall.ps1is untouched.install: keep uv's cache on the same filesystem as the venv— uv hardlinks wheels out of its cache into the venv when both are on one filesystem and copies when they are not. Measured with torch 2.11.0+cpu: co-located, a 749 MB cache and a 748 MB venv occupy 755 MB between them; across a boundary the same files are duplicated. uv's default cache is$HOME/.cache/uvwhileSTUDIO_HOMEcan be moved anywhere, so every redirected install paid twice and left the cache on the drive the user moved off. Set instudio/setup.shas well asinstall.sh, because setup.sh is the standaloneunsloth studio updateentry point and an export made only in install.sh would grow a second cache on the first update. The writability probe usesmktemp, not a$$-derived name: this branch exists for a cache directory another account can write, and there a predictable path can be pre-created as a symlink for: >to follow.install: don't report a ROCm SDK path that isn't there— the GPU summary printedROCm: /opt/rocmunconditionally, but that is a fallback, not a detection.install: carry the manual PATH line when a shell rc cannot be written—mainalready guards the append and warns instead of failing (NixOS, home-manager, chezmoi and stow all symlink rc files read-only). What this adds is the exact line to paste, so the warning is actionable rather than just non-fatal.Plus
studio/ROCM_RDNA2_APU.mdrecording the RDNA2 APU measurements, referenced from the routing code so the Vulkan choice is not later "fixed" back to ROCm.Verification
Simulated against the previous behaviour rather than reasoned about.
Torch constraints: 792 cells, 8 changed. The real
case "$_torch_index_leaf"table lifted from both revisions and diffed across {linux, wsl, macos} x {x86_64, aarch64} x 11 index leaves x {py3.9, py3.13} x {glibc 2.17, 2.26, 2.27, 2.28, 2.39, unreadable}. Every changed cell is(linux|wsl) x cpu x py>=3.10 x glibc>=2.28. Every CUDA, ROCm, per-gfx, XPU and macOS cell is byte-identical.llama.cpp routing: unchanged for every non-AMD host.
detect_hostplus the selection paths run on a real 2x NVIDIA box are byte-identical between this branch andmainacross no mask,CUDA_VISIBLE_DEVICES="",ROCR_VISIBLE_DEVICES=""andHIP_VISIBLE_DEVICES=-1. An Intel iGPU + AMD dGPU host is also identical tomainunder a ROCm mask.Suites:
tests/shgreen end to end (gate suite 55/55), and 3301 passed / 100 skipped acrosstests/studio/installplus the routing tests.I have no Van Gogh hardware, so the gfx1033 miscomputation itself and the Deck throughput numbers are @ThomasEricB's measurements, not mine.
Not in here
The AppImage rewrite,
release-desktop.yml, and their tests stay in #8343.