Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Pin the ROCm-on-WSL bootstrap to immutable refs (#8540)
Daniel Hane468965b43e8
diff --git a/install.sh b/install.shindex a00a7b552ad..4872bc17360 100755--- a/install.sh+++ b/install.sh@@ -3867,11 +3867,34 @@ _maybe_bootstrap_rocm_wsl() {# Locate the helper: prefer the copy shipped beside install.sh, else fetch it. The local# copy counts only for a --local checkout run, since this executes with no prompt and# _REPO_ROOT may otherwise be the caller's cwd. The fetch pulls the same script.+ #+ # PINNED, never a branch: this runs unattended and installs with sudo, so a moving ref+ # would turn any rewrite of that branch into root code on every affected WSL box. Bump+ # it whenever the helper changes; lagging only means an older helper, and the gate below+ # rejects one too old to be safe.+ _ROCM_WSL_HELPER_REF="d3367edd9a1de7a0ac15aa899bd9cb97173679dc"+ # librocdxg pin (v1.2.2), forwarded to the helper. The ref IS the commit, so an older+ # helper that ignores the SHA still resolves this exact revision: its `--branch <sha>`+ # attempt fails and the full clone plus checkout land on it. Kept equal to the helper's+ # defaults; a test enforces that. A user-set ref wins and, with no SHA of its own, turns+ # the helper's check off rather than failing against our pin.+ _rw_dxg_ref="${UNSLOTH_LIBROCDXG_REF:-}"+ _rw_dxg_sha="${UNSLOTH_LIBROCDXG_SHA:-}"+ if [ -z "$_rw_dxg_ref" ]; then+ _rw_dxg_ref="4955d12888a3ec57057f1cf8660c2485e415e74c"+ [ -n "$_rw_dxg_sha" ] || _rw_dxg_sha="$_rw_dxg_ref"+ fi+ # A known SHA is authoritative, so forward it AS the ref: an operator pinning a branch+ # plus its expected commit would otherwise have that symbolic ref cloned unverified by a+ # helper old enough to ignore the SHA.+ if [ -n "$_rw_dxg_sha" ]; then+ _rw_dxg_ref="$_rw_dxg_sha"+ fi_rw_helper="${_REPO_ROOT:-.}/scripts/install_rocm_wsl_strixhalo.sh"_rw_tmp=""if [ "$_REPO_IS_CHECKOUT" != "1" ] || [ ! -r "$_rw_helper" ]; then_rw_tmp="$(mktemp 2>/dev/null || echo /tmp/_unsloth_rocm_wsl.sh)"- if download "https://raw.githubusercontent.com/unslothai/unsloth/main/scripts/install_rocm_wsl_strixhalo.sh" "$_rw_tmp" 2>/dev/null; then+ if download "https://raw.githubusercontent.com/unslothai/unsloth/${_ROCM_WSL_HELPER_REF}/scripts/install_rocm_wsl_strixhalo.sh" "$_rw_tmp" 2>/dev/null; then_rw_helper="$_rw_tmp"elsesubstep "Could not fetch the ROCm-on-WSL helper; using CPU fallback." "$C_WARN"@@ -3880,6 +3903,17 @@ _maybe_bootstrap_rocm_wsl() {fifi+ # Run ONLY a helper declaring the contract (defined in its header): verifies the clone+ # against the pinned SHA, and treats an unresolvable checkout as fatal. One without it+ # swallows that failure and would build the repo's default HEAD as root once the pinned+ # ref stopped existing. Gating on the declaration is what makes this fail closed whatever+ # the pin, or a user's older checkout, supplies.+ if ! grep -q "^UNSLOTH_ROCM_WSL_HELPER_CONTRACT=2$" "$_rw_helper" 2>/dev/null; then+ substep "ROCm-on-WSL helper predates the pinned-source check; using CPU fallback." "$C_WARN"+ [ -n "$_rw_tmp" ] && rm -f "$_rw_tmp"+ return 0+ fi+# Consent: the narrow guarded case is exactly the GPU setup the user ran the# installer for, so it proceeds AUTOMATICALLY by default (works with no TTY,# e.g. `curl ... | sh`). Opt out via UNSLOTH_SKIP_ROCM_WSL_SETUP=1 (top of@@ -3895,7 +3929,9 @@ _maybe_bootstrap_rocm_wsl() {if [ "$_rw_go" = "1" ]; then# Helper does its own sudo + is idempotent. SMOKE_TEST=0: install.sh# installs torch itself right after, into the real venv.- if UNSLOTH_WSL_SMOKE_TEST=0 bash "$_rw_helper"; then+ if UNSLOTH_WSL_SMOKE_TEST=0 \+ UNSLOTH_LIBROCDXG_REF="$_rw_dxg_ref" UNSLOTH_LIBROCDXG_SHA="$_rw_dxg_sha" \+ bash "$_rw_helper"; then# Pull the helper's persisted env into THIS shell so detection# (rocminfo) now enumerates the GPU and routes to gfx1151.if [ -r /etc/profile.d/unsloth-rocm-wsl.sh ]; thendiff --git a/scripts/install_rocm_wsl_strixhalo.sh b/scripts/install_rocm_wsl_strixhalo.shindex 697aae933fb..c3423c26665 100644--- a/scripts/install_rocm_wsl_strixhalo.sh+++ b/scripts/install_rocm_wsl_strixhalo.sh@@ -33,12 +33,30 @@# ──────────────────────────────────────────────────────────────────────────────set -euo pipefail+# What this helper guarantees about the third-party source it builds as root. install.sh+# refuses to run a copy that does not declare the contract it requires, so a helper fetched+# from an older pin can never quietly drop one of these. Bump BOTH on any change here.+# 1: builds LIBROCDXG_REF, no verification.+# 2: verifies the clone against LIBROCDXG_SHA before building, and treats a failed+# checkout with no SHA to verify against as fatal rather than building default HEAD.+UNSLOTH_ROCM_WSL_HELPER_CONTRACT=2+# ── Tunables (override via env) ──────────────────────────────────────────────ROCM_VER="${UNSLOTH_WSL_ROCM_VER:-7.2.1}" # ROCm release to install# GPU arch: empty = auto-detect from rocminfo after install (override UNSLOTH_WSL_GFX=gfx1200).# The ROCm + librocdxg setup is arch-agnostic; only verify + the smoke test need the arch.GFX="${UNSLOTH_WSL_GFX:-}"-LIBROCDXG_REF="${UNSLOTH_LIBROCDXG_REF:-develop}" # ROCm/librocdxg git ref to build+# ROCm/librocdxg source to build. This is compiled and `sudo make install`ed, so it is+# pinned to a commit, not to a branch (rewritten by definition) or a tag (movable): the+# ref IS the commit and the clone is verified against it below. This is v1.2.2, the+# current release, which is also what develop points at, so the build is unchanged.+LIBROCDXG_REF="${UNSLOTH_LIBROCDXG_REF:-4955d12888a3ec57057f1cf8660c2485e415e74c}"+LIBROCDXG_SHA="${UNSLOTH_LIBROCDXG_SHA:-4955d12888a3ec57057f1cf8660c2485e415e74c}"+# An explicit UNSLOTH_LIBROCDXG_REF with no SHA is a deliberate operator choice (e.g.+# testing a fix branch) -- honour it and skip the pin check rather than hard-failing.+if [ -n "${UNSLOTH_LIBROCDXG_REF:-}" ] && [ -z "${UNSLOTH_LIBROCDXG_SHA:-}" ]; then+ LIBROCDXG_SHA=""+fi# AMD's wheel index for the (optional) smoke test; resolved after arch detection.TORCH_INDEX=""# Optional torch smoke test (throwaway venv). OFF by default: install.sh installs@@ -197,11 +215,30 @@ elsenote "Windows SDK: ${_win_sdk}"_src="${HOME}/.unsloth/librocdxg"rm -rf "$_src"- git clone --depth 1 --branch "$LIBROCDXG_REF" https://github.com/ROCm/librocdxg.git "$_src" \- || git clone "https://github.com/ROCm/librocdxg.git" "$_src"+ # --branch takes a branch/tag, never a commit, so a 40 char ref goes straight to the+ # full clone (librocdxg is ~29 MB, about a second) and is reached by checkout below.+ if [ "${#LIBROCDXG_REF}" = "40" ]; then+ git clone "https://github.com/ROCm/librocdxg.git" "$_src"+ else+ git clone --depth 1 --branch "$LIBROCDXG_REF" https://github.com/ROCm/librocdxg.git "$_src" \+ || git clone "https://github.com/ROCm/librocdxg.git" "$_src"+ fi(cd "$_src"- git checkout "$LIBROCDXG_REF" 2>/dev/null || true+ _co_failed=0+ git checkout "$LIBROCDXG_REF" 2>/dev/null || _co_failed=1+ # A failed checkout leaves the default branch in place. With a SHA the check below+ # catches that; without one (a deliberate ref-only override) nothing else would, and+ # building whatever HEAD happens to be is not what was asked for.+ if [ "$_co_failed" = "1" ] && [ -z "$LIBROCDXG_SHA" ]; then+ die "could not check out librocdxg ref '${LIBROCDXG_REF}'. Refusing to build the repository's default branch instead."+ fi+ # Verify the pin BEFORE cmake/make/`sudo make install` run anything from this+ # tree: a moved tag or a mirror serving something else stops here.+ if [ -n "$LIBROCDXG_SHA" ]; then+ _got_sha="$(git rev-parse HEAD 2>/dev/null || true)"+ [ "$_got_sha" = "$LIBROCDXG_SHA" ] || die "librocdxg ${LIBROCDXG_REF} resolved to ${_got_sha:-unknown}, expected ${LIBROCDXG_SHA}. Refusing to build and install unverified source as root. Set UNSLOTH_LIBROCDXG_REF (and optionally UNSLOTH_LIBROCDXG_SHA) to build a different revision on purpose."+ fimkdir -p build && cd buildcmake .. -DWIN_SDK="${_win_sdk}/shared"make -j"$(nproc)"diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.pyindex 4b541b989ca..0b9ceeb3a56 100644--- a/tests/studio/install/test_rocm_support.py+++ b/tests/studio/install/test_rocm_support.py@@ -6455,5 +6455,83 @@ class TestLlamaCppRuntimeWslOrdering:assert idx_helper < idx_binary+class TestRocmWslSupplyChainPins:+ """The ROCm-on-WSL bootstrap runs unattended and installs with sudo, so every piece of+ code it fetches must come from an immutable ref: a moving branch would turn any rewrite+ of that branch into root code execution on affected WSL hosts."""++ def test_helper_is_fetched_from_a_pinned_commit_not_a_branch(self):+ source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")+ start = source.find("_maybe_bootstrap_rocm_wsl()")+ assert start != -1+ body = source[start : source.find("\n}", start)]+ assert (+ "unsloth/main/scripts/install_rocm_wsl_strixhalo.sh" not in body+ ), "the helper must not be fetched from the mutable main branch"+ ref = re.search(r'_ROCM_WSL_HELPER_REF="([0-9a-f]+)"', body)+ assert ref is not None, "the helper fetch must pin a full commit SHA"+ assert len(ref.group(1)) == 40+ assert "${_ROCM_WSL_HELPER_REF}/scripts/install_rocm_wsl_strixhalo.sh" in body+ # And whatever that pin (or a user's older checkout) supplies, a helper without the+ # pinned-source check is refused rather than trusted.+ assert 'grep -q "^UNSLOTH_ROCM_WSL_HELPER_CONTRACT=2$" "$_rw_helper"' in body+ assert "predates the pinned-source check" in body++ def test_librocdxg_ref_is_pinned_and_verified_before_build(self):+ source = _STRIXHALO_WSL_PATH.read_text(encoding = "utf-8")+ assert (+ "UNSLOTH_LIBROCDXG_REF:-develop" not in source+ ), "librocdxg must not default to a moving branch"+ sha = re.search(r'LIBROCDXG_SHA="\$\{UNSLOTH_LIBROCDXG_SHA:-([0-9a-f]{40})\}"', source)+ assert sha is not None, "librocdxg must default to a pinned commit SHA"+ # The ref itself must be that commit, so even a helper with no SHA check (an older+ # fetched copy) resolves the same immutable revision rather than a movable tag.+ ref = re.search(r'LIBROCDXG_REF="\$\{UNSLOTH_LIBROCDXG_REF:-([0-9a-f]{40})\}"', source)+ assert ref is not None and ref.group(1) == sha.group(1)+ # The SHA check must run before anything from the clone is built or installed.+ # A failed checkout must not fall through to the default branch.+ assert "_co_failed=1" in source+ assert "Refusing to build the repository's default branch instead" in source+ idx_check = source.find("git rev-parse HEAD")+ idx_cmake = source.find("cmake .. -DWIN_SDK")+ idx_install = source.find("$SUDO make install")+ assert idx_check != -1 and idx_check < idx_cmake < idx_install++ def test_install_sh_forwards_the_same_librocdxg_pin_as_the_helper(self):+ # install.sh forwards the pin so it also applies to a helper fetched from an older+ # commit. The two copies must never disagree, or a bumped helper would be handed a+ # stale pin by install.sh and build the wrong revision.+ install_sh = _INSTALL_SH_PATH.read_text(encoding = "utf-8")+ helper = _STRIXHALO_WSL_PATH.read_text(encoding = "utf-8")+ fwd_ref = re.search(r'_rw_dxg_ref="([0-9a-f]{40})"', install_sh)+ fwd_sha = re.search(r'_rw_dxg_sha="\$_rw_dxg_ref"', install_sh)+ own_ref = re.search(r'LIBROCDXG_REF="\$\{UNSLOTH_LIBROCDXG_REF:-([0-9a-f]{40})\}"', helper)+ own_sha = re.search(r'LIBROCDXG_SHA="\$\{UNSLOTH_LIBROCDXG_SHA:-([0-9a-f]{40})\}"', helper)+ assert None not in (fwd_ref, fwd_sha, own_ref, own_sha)+ assert fwd_ref.group(1) == own_ref.group(1) == own_sha.group(1)+ # A SHA, whether ours or the operator's, is forwarded AS the ref, so even a helper+ # that ignores UNSLOTH_LIBROCDXG_SHA resolves exactly the authorised commit.+ assert 'if [ -n "$_rw_dxg_sha" ]; then\n _rw_dxg_ref="$_rw_dxg_sha"' in install_sh+ # A ref-only override must reach the helper untouched, so that path still works.+ assert '_rw_dxg_ref="${UNSLOTH_LIBROCDXG_REF:-}"' in install_sh+ assert (+ 'UNSLOTH_LIBROCDXG_REF="$_rw_dxg_ref" UNSLOTH_LIBROCDXG_SHA="$_rw_dxg_sha"'+ in install_sh+ )++ def test_helper_contract_matches_what_install_sh_requires(self):+ # install.sh runs only a helper declaring this contract, so the level it requires and+ # the level the helper declares must move together, and the helper must actually+ # implement both guarantees the level stands for.+ install_sh = _INSTALL_SH_PATH.read_text(encoding = "utf-8")+ helper = _STRIXHALO_WSL_PATH.read_text(encoding = "utf-8")+ required = re.search(r'grep -q "\^UNSLOTH_ROCM_WSL_HELPER_CONTRACT=(\d+)\$"', install_sh)+ declared = re.search(r"^UNSLOTH_ROCM_WSL_HELPER_CONTRACT=(\d+)$", helper, re.M)+ assert required is not None and declared is not None+ assert required.group(1) == declared.group(1)+ assert "git rev-parse HEAD" in helper+ assert "_co_failed=1" in helper++if __name__ == "__main__":pytest.main([__file__, "-v"])