Skip to content

install.sh: route Strix to the AMD arch index on rocm7.2 (#7264) + PCI detection hint - #7293

Merged
danielhanchen merged 8 commits into
mainfrom
fix/install-amd-linux
Jul 22, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
fix/install-amd-linux

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What

Two Linux-installer fixes for AMD Strix Halo (gfx1151) / Strix Point (gfx1150).

1. Strix reverts torch to rocm7.2 (#7264)

Strix should install torch 2.11+rocm7.13 from repo.amd.com/rocm/whl/gfx<arch>/, which carries AMD's real gfx1150/gfx1151 fixes. But:

  • modern ROCm (7.3+) caps to the generic download.pytorch.org/whl/rocm7.2 index, and
  • the Radeon repo (repo.radeon.com) can be unavailable,

and the reroute to the arch-specific index only fired on */rocm7.1. So a gfx1151 box on ROCm 7.14 whose Radeon repo was down fell back to rocm7.2 (the reported "found 7.14, reverts to 7.2"). This broadens the reroute trigger to rocm7.2 as well. The inner logic already only acts when a gfx1151/gfx1150 is actually detected (via rocminfo/amd-smi, honoring HIP_VISIBLE_DEVICES), so every other arch on rocm7.2 passes through unchanged. This matches the Windows installer, which already maps gfx1151 to repo.amd.com/.../gfx1151.

2. Strix not detected -> silent CPU-only

Reports of Strix Halo installing CPU-only PyTorch on bare-metal Linux (Arch, AI Max). When ROCm cannot see the GPU (no /dev/kfd, rocminfo, or amd-smi) the installer fell back to CPU-only with only a generic docs pointer. Added _amd_gpu_present_via_pci (vendor 0x1002 + display class 0x03*) so that when an AMD GPU is on the PCI bus but ROCm can't use it, the installer prints a targeted hint (install the ROCm kernel stack so /dev/kfd exists; Strix needs kernel 6.11+ and ROCm 7.x). Purely additive diagnostic, no change to the torch-index decision.

Verification

bash -n clean; no behavior change for non-Strix arches or non-AMD hosts.

…cm7.2, add PCI hint

Two Linux install fixes for AMD Strix Halo / Strix Point:

1. #7264: Strix reverts to rocm7.2. Modern ROCm (7.3+) caps to the generic
   rocm7.2 index and the Radeon repo can be unavailable, so gfx1151/gfx1150
   landed on a non-arch-specific build (torch 2.11+rocm7.2) instead of
   repo.amd.com/rocm/whl/gfx<arch> (torch 2.11+rocm7.13, AMD's real Strix
   fixes). The reroute to that arch index only fired on rocm7.1; broaden it to
   rocm7.2 too. Only acts when a gfx1151/gfx1150 is actually detected, so other
   arches on rocm7.2 pass through unchanged.

2. Rows about Strix not detected -> CPU-only: when no GPU is detected but an AMD
   display GPU is on the PCI bus, print a targeted hint (ROCm kernel stack /
   /dev/kfd missing) instead of only the generic docs pointer. Purely
   additive diagnostic; does not change the torch index decision.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a helper function _amd_gpu_present_via_pci to detect AMD display GPUs on the PCI bus, improving the "no GPU detected" warning when ROCm is not properly configured. It also extends the Strix Halo/Point routing logic to cover ROCm 7.2 and refines the associated warning messages. The reviewer suggested optimizing the PCI device check by using the shell's built-in read command instead of spawning external cat processes, and adding a defensive check for the existence of the /sys/bus/pci/devices directory.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread install.sh
Comment on lines +2134 to +2143
_amd_gpu_present_via_pci() {
for _pci_vendor in /sys/bus/pci/devices/*/vendor; do
[ -r "$_pci_vendor" ] || continue
[ "$(cat "$_pci_vendor" 2>/dev/null)" = "0x1002" ] || continue
case "$(cat "${_pci_vendor%vendor}class" 2>/dev/null)" in
0x03*) return 0 ;;
esac
done
return 1
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Spawning external cat processes twice for every PCI device in a loop can be highly inefficient, especially on systems with many PCI devices or in virtualized/containerized environments where process creation is expensive. Since this script is executed with POSIX sh, we can use the shell's built-in read command to read the sysfs files directly without spawning any subprocesses. Additionally, we should defensively check if the /sys/bus/pci/devices directory exists before attempting to iterate over it.

Suggested change
_amd_gpu_present_via_pci() {
for _pci_vendor in /sys/bus/pci/devices/*/vendor; do
[ -r "$_pci_vendor" ] || continue
[ "$(cat "$_pci_vendor" 2>/dev/null)" = "0x1002" ] || continue
case "$(cat "${_pci_vendor%vendor}class" 2>/dev/null)" in
0x03*) return 0 ;;
esac
done
return 1
}
_amd_gpu_present_via_pci() {
[ -d /sys/bus/pci/devices ] || return 1
for _pci_vendor in /sys/bus/pci/devices/*/vendor; do
[ -r "$_pci_vendor" ] || continue
read -r _vendor < "$_pci_vendor" 2>/dev/null || continue
[ "$_vendor" = "0x1002" ] || continue
_class_file="${_pci_vendor%vendor}class"
if [ -r "$_class_file" ] && read -r _class < "$_class_file" 2>/dev/null; then
case "$_class" in
0x03*) return 0 ;;
esac
fi
done
return 1
}

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 115e147931

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

Comment thread install.sh Outdated
Comment on lines +3049 to +3052
if _amd_gpu_present_via_pci; then
substep "An AMD GPU is on the PCI bus but ROCm cannot see it (no /dev/kfd," "$C_WARN"
substep " rocminfo, or amd-smi). Install the ROCm kernel stack so /dev/kfd exists;"
substep " Strix Halo (gfx1151/gfx1150) needs a recent kernel (6.11+) and ROCm 7.x."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit the PCI hint to failed ROCm detection

This predicate is evaluated for every CPU-index fallback, not only when ROCm failed to enumerate the GPU. For example, an AMD GPU with ROCm 5.x is successfully detected by rocminfo, but get_torch_index_url intentionally selects CPU wheels because supported wheels require ROCm 6.0+; the PCI check then incorrectly tells the user that ROCm cannot see the GPU and to install the kernel stack. Gate this message on the failed _has_amd_rocm_gpu case (or retain that result from detection) so unsupported/unknown ROCm versions receive the correct upgrade guidance instead.

Useful? React with 👍 / 👎.

Comment thread install.sh
# The Radeon repo now ships cp313 wheels for rocm-rel-7.1, so when
# _amd_gpu_radeon=true the installer silently lands on the broken combo.
# Detect these GPUs when TORCH_INDEX_URL is rocm7.1 and override to rocm7.2.
# ── Strix Halo / Strix Point: route to the AMD arch-specific index ───────────

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the marker used by the previous-torch-pin test

tests/sh/test_previous_torch_pin.sh still locates this block by grepping for Strix Halo / Strix Point: force rocm7.2 wheels; after this heading changed, its “pin evaluated after the Strix reroute” assertion fails and the script exits 1, despite the ordering being unchanged. Update that test's marker (or retain a stable marker here) so the repository's existing installer validation passes.

Useful? React with 👍 / 👎.

…fix test marker, use read builtin

- Only show the 'ROCm cannot see the GPU' hint when _has_amd_rocm_gpu fails;
  a detected-but-too-old ROCm (rocminfo works, wheels need 6.0+) has its own path.
- Update test_previous_torch_pin.sh to the stable 'Strix Halo / Strix Point:'
  marker after the heading reworded (the old grep broke the ordering assert).
- _amd_gpu_present_via_pci: read builtin instead of spawning cat twice per
  device, and guard /sys/bus/pci/devices existence.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: b8de095713

ℹ️ 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 Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Generalize the Strix reroute from the hardcoded rocm7.1/rocm7.2 match to a
version compare against the arch index's own build (rocm7.13):

- backwards: rocm6.0-6.4 and rocm7.0 now reroute (were silently missed)
- forwards: any future intermediate rocm7.x below 7.13 reroutes; rocm7.13+
  is left alone so a generic index that already carries the fix is not
  downgraded to the arch build

_rocm_index_below does an integer major.minor compare (so rocm7.2 < rocm7.13);
non-rocm, arch (gfx), and unparseable URLs return false, so NVIDIA/CPU and the
arch index itself are untouched. Reroute still fires only for gfx1150/gfx1151.
@danielhanchen

Copy link
Copy Markdown
Member Author

Generalized the Strix reroute so it is forwards and backwards compatible instead of matching the literal rocm7.1/rocm7.2 tags.

The rule is now a version compare against the arch index's own build (rocm7.13): reroute a detected Strix GPU whenever the auto-picked generic index is older than that. _rocm_index_below does an integer major.minor compare, so rocm7.2 < rocm7.13, and non-rocm / arch (gfx) / unparseable URLs return false.

What this changes (verified against the reroute matrix):

  • Backwards: rocm6.0-rocm6.4 and rocm7.0 now reroute for Strix. The old */rocm7.1|*/rocm7.2 glob silently missed these, so a Strix box that resolved to an older generic index stayed on a build without AMD's gfx1150/gfx1151 fixes.
  • Forwards: any future intermediate rocm7.x below 7.13 reroutes too, while rocm7.13+ is left untouched. Once a generic index actually ships the fix (>= the arch build), we no longer downgrade it to the arch wheels.
  • Unchanged: rocm7.1/rocm7.2 still reroute; non-Strix AMD GPUs, NVIDIA (cu*), CPU, and the arch index itself are never rerouted.

Testing: extracted the real _rocm_index_below from install.sh and replayed the full decision (glob match + runtime gfx + version floor) across the tag universe rocm6.0-rocm8.0 x {gfx1151, gfx1150, gfx1100, gfx1030, gfx1201, none} plus cu128/cpu. 120/120 assertions pass under git-bash (Windows), bash (Linux/WSL) and dash. bash -n / dash -n clean, and the existing tests/sh suites still pass (test_previous_torch_pin.sh 46/0, test_strixhalo_wsl_reroute.sh 53/0, test_torch_flavor.sh 69/0, test_get_torch_index_url.sh 49/0 under WSL).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42ebed8501

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

Comment thread install.sh Outdated
# 0 when URL's generic rocmX.Y tag is older than floor $2.$3 (int compare, so
# rocm7.2 < rocm7.13). Non-rocm / arch (gfx) / unparseable URLs return 1.
_rocm_index_below() {
_rb=$(printf '%s' "$1" | grep -oE 'rocm[0-9]+\.[0-9]+' | head -1 || true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse the ROCm version from the index leaf

When UNSLOTH_PYTORCH_MIRROR contains a ROCm-looking path segment, this extracts that earlier segment rather than the selected index family. For example, a Strix system using https://mirror.example/rocm7.13/cache with its automatically selected .../rocm7.2 index makes _rb equal rocm7.13; the comparison then skips the arch-specific reroute and installs the generic wheels the change is intended to avoid. Extract and validate the final URL path segment (as the nearby index-family logic does) before comparing versions.

Useful? React with 👍 / 👎.

Comment thread install.sh Outdated
Comment on lines +2856 to +2857
case "$TORCH_INDEX_URL" in
*/rocm7.1|*/rocm7.1.*)
*/rocm[0-9]*)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the obsolete Strix routing test

TestStrixRocm71Override.test_strix_override_only_fires_on_rocm71 still asserts that this routing is limited to ROCm 7.1. It now passes accidentally because its source-text search for rocm7.1 matches the new rocm7.13 comment, not because it verifies the case selector. Consequently, the test suite will not catch a future regression that removes the intended ROCm 7.2 routing; replace it with assertions for the new version-comparison behavior.

Useful? React with 👍 / 👎.

@danielhanchen

Copy link
Copy Markdown
Member Author

Both addressed in 65f221a.

  1. Parse the ROCm version from the index leaf. The helper now works on the final path segment via the existing _torch_index_leaf (renamed to _rocm_leaf_below, and the case selector switched from $TORCH_INDEX_URL to $_torch_index_leaf, matching the nearby rocm7.2|gfx120x-all|... and UNSLOTH_TORCH_BACKEND blocks). So a mirror like https://mirror.example/rocm7.13/cache/rocm7.2 now compares the leaf rocm7.2 and reroutes, instead of reading rocm7.13 from the base and skipping it. A mirror whose base holds a rocm token but whose leaf is cu128/gfx1151 no longer enters the block at all.

  2. Obsolete test replaced. test_strix_override_only_fires_on_rocm71 is gone; test_strix_override_scoped_below_arch_floor now extracts _rocm_leaf_below from install.sh and executes it, asserting rocm6.0, rocm7.0, rocm7.1, rocm7.2, rocm7.12 reroute while rocm7.13, rocm7.14, rocm8.0, gfx1151, cu128, cpu do not. It fails if the floor is wrong (verified by mutating the floor to 7.0), so it no longer passes on a stale text match.

Testing: temp/sim/verify_7293_general.sh extended to exercise the real leaf extraction from install.sh plus the mirror regression, 117/117 under git-bash, WSL bash and dash. TestStrixRocm71Override 9/9, and the tests/sh reroute suites still pass (46/0, 53/0, 69/0, 49/0-under-WSL).

danielhanchen and others added 2 commits July 21, 2026 18:12
…review)

Address two review points on the rocm-version reroute:

- Parse the final path segment (_torch_index_leaf) instead of grepping the whole
  URL. A custom mirror whose base path holds its own rocm token (e.g.
  .../rocm7.13/cache/rocm7.2) previously matched the base and skipped the reroute;
  now it compares the leaf (rocm7.2) like the nearby index-family logic. Renamed
  the helper to _rocm_leaf_below and switched the case selector to $_torch_index_leaf.
- Replace the stale test_strix_override_only_fires_on_rocm71 (which passed by
  matching the new rocm7.13 comment) with an executed test that runs _rocm_leaf_below
  and asserts rocm6.0-7.12 reroute while rocm7.13+/gfx/cu leaves do not.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

unsloth/install.sh

Lines 2865 to 2867 in 299873a

if command -v rocminfo >/dev/null 2>&1; then
_gfx_all=$(rocminfo 2>/dev/null | grep -oE 'gfx[1-9][0-9a-z]{2,3}')
fi

P1 Badge Preserve the amd-smi fallback when rocminfo has no gfx output

On an AMD host where amd-smi successfully identifies the GPU but an installed rocminfo fails or emits no matching gfx token, this assignment exits with status 1 because grep -oE finds no match; under the script's global set -e, the installer terminates before the subsequent amd-smi fallback can run. The prior code exposed this only for the rocm7.1 path, but the widened rocm[0-9]* selector now makes ordinary ROCm 6.x/7.2 installations fail in that mixed-tool state. Make this probe non-fatal (for example, append || true) so the fallback is reachable.

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

The Strix reroute now matches every rocm* index, not just rocm7.1, so its gfx
detection runs on all AMD installs. Each `_gfx_all=$(rocminfo|amd-smi | grep -oE
gfx...)` returns 1 when grep finds no match, which under set -euo pipefail aborts
the installer before the next fallback runs (e.g. rocminfo present but emitting no
gfx token). Append `|| true` to the three probes, matching the display block that
already guards this. Add an executed regression test (shimmed rocminfo/amd-smi)
that fails if any probe becomes fatal again.
@danielhanchen

Copy link
Copy Markdown
Member Author

Fixed in 6333a31. This was a real regression from widening the selector.

The gfx-detection probes (_gfx_all=$(rocminfo|amd-smi | grep -oE gfx...)) return 1 when grep finds no match, and under set -euo pipefail a bare var=$(pipeline) that exits non-zero aborts the script. While the case only matched rocm7.1 this was reachable only by Strix-on-7.1 (where rocminfo does emit gfx1151), but the widened rocm[0-9]* selector now runs the probe on every AMD ROCm install, so an ordinary 6.x/7.2 host with a rocminfo that emits no gfx token (broken/misconfigured) would abort before the amd-smi fallback.

Appended || true to all three probes (rocminfo, amd-smi list, amd-smi static --asic), matching the display block below that already guards it. The _runtime_gfx awk substitution is unaffected (awk exits 0 on empty input).

Verified empirically that var=$(... grep-no-match) aborts under set -euo pipefail and that || true reaches the fallback. Added an executed regression test (test_gfx_probe_survives_no_match_under_set_e) that shims rocminfo (no gfx) + amd-smi (gfx1151), runs the real extracted block under set -euo pipefail, and asserts it does not abort and recovers gfx1151 from the fallback; it fails if any probe becomes fatal again. TestStrixRocm71Override 10/10, and a standalone sim confirms 7/7 across git-bash and WSL, including a control that the un-guarded block still aborts.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 943991439c

ℹ️ 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
danielhanchen merged commit 4e1cb4a into main Jul 22, 2026
45 checks passed
@danielhanchen
danielhanchen deleted the fix/install-amd-linux branch July 22, 2026 02:41
danielhanchen added a commit to Souravrajvi0/unsloth that referenced this pull request Jul 22, 2026
install.sh and test_previous_torch_pin.sh Strix changes already landed via unslothai#7293/unslothai#7264, so drop them (main is a superset). The remaining fix is studio/install_python_stack.py: replace the ver < (7, 2) gate with _strix_needs_amd_arch_index, which reroutes gfx1150/gfx1151 off any generic pytorch.org rocm index below the 7.13 AMD arch floor. This fixes ROCm 7.14 (unslothai#7280) and stays correct if pytorch.org later adds rocm7.3+. Keep the two Python-side tests; main's install.sh-scoped tests replace the old text-match one.
danielhanchen added a commit to Souravrajvi0/unsloth that referenced this pull request Jul 22, 2026
…slothai#7305

The _amd_gpu_present_via_pci helper and the PCI-bus 'no GPU detected' hint already landed in main via unslothai#7293 / unslothai#7264, so this drops the duplicated copies and keeps main's versions. The unique part of unslothai#7301 stays: _infer_linux_amd_gfx_arch (UNSLOTH_ROCM_GFX_ARCH, /proc/cpuinfo, lspci) plus the install.sh + install_python_stack.py routing that installs AMD per-arch wheels when no ROCm runtime is visible, mirroring install.ps1 on Windows. This does not touch _has_amd_rocm_gpu, so it is complementary to unslothai#7314 (which fixes detection when the kernel driver is present).
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.

1 participant