Skip to content

fix(rocm): prepend system ROCm libs on native Linux to avoid bundled HIP crash - #7233

Merged
danielhanchen merged 6 commits into
unslothai:mainfrom
InfoSage05:fix/native-linux-rocm-system-libs
Jul 22, 2026
Merged

danielhanchen merged 6 commits into
unslothai:mainfrom
InfoSage05:fix/native-linux-rocm-system-libs

Conversation

@InfoSage05

@InfoSage05 InfoSage05 commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two fixes:

  1. ROCm native Linux GPU fallback: On native Linux AMD hosts, prebuilt llama-server bundles ship bundled ROCR/HIP runtimes incompatible with the host's amdkfd kernel driver, causing silent CPU fallback. The existing workaround was gated to WSL only. This PR adds _native_linux_system_rocm_lib_dirs() that dynamically resolves the ROCm path from HIP_PATH, HIP_PATH_57, ROCM_PATH env vars (with /opt/rocm fallback) and prepends system libs to LD_LIBRARY_PATH.

  2. CI: opencode agent guide timeout: opencode run hangs in headless CI. Added --format json which makes it output structured JSON events non-interactively instead of blocking on TTY.

Root Cause

  1. _wsl_system_rocm_lib_dirs() at llama_cpp.py:210 and install_llama_prebuilt.py:5693 gates on /dev/dxg, so native Linux never gets the system-ROCm library prepend. Bundled HIP runtime crashes in hsa_init() -> silent CPU fallback.

  2. opencode run without --format json hangs in TTY-less CI environments waiting for interactive output.

Changes

  • studio/backend/core/inference/llama_cpp.py: Added _bundled_hip_present() and _native_linux_system_rocm_lib_dirs() helpers; integrated into _llama_server_env_for_binary()
  • studio/install_llama_prebuilt.py: Same helpers mirrored; integrated into binary_env()
  • .github/scripts/agent-guides-drive.sh: Added --format json to opencode run invocations for both connection and file-edit modes

Fixes #7208

@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 changes to load native Linux system ROCm libraries before the prebuilt's bundled HIP runtime to prevent crashes caused by incompatibilities with the host's kernel driver. This is implemented in both studio/backend/core/inference/llama_cpp.py and studio/install_llama_prebuilt.py. The reviewer suggests dynamically resolving the ROCm installation path using environment variables like ROCM_PATH or HIP_PATH instead of hardcoding /opt/rocm, which could fail on systems with custom installation directories.

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 studio/install_llama_prebuilt.py Resolved
@InfoSage05
InfoSage05 force-pushed the fix/native-linux-rocm-system-libs branch from 8529257 to 447ac40 Compare July 19, 2026 10:10
@InfoSage05
InfoSage05 marked this pull request as ready for review July 20, 2026 13:14

@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: ddeaa31d2b

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

return []
if not _bundled_hip_present(binary_dir):
return []
candidates = ["/opt/rocm"]

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 Prefer ROCm env paths over the fallback

On native Linux hosts with multiple ROCm installs, this searches /opt/rocm before the explicitly configured HIP_PATH/ROCM_PATH, and the returned dirs are prepended to LD_LIBRARY_PATH; if /opt/rocm is stale while the env vars point at the driver-matching ROCm root, llama-server and install validation will still load the stale libhsa-runtime64 first and can hit the same hsa_init crash this change is trying to avoid. The mirrored helper in install_llama_prebuilt.py has the same ordering, so please put env-derived roots first and use /opt/rocm only as the fallback.

Useful? React with 👍 / 👎.

Comment thread .github/scripts/agent-guides-drive.sh Resolved
Comment on lines +5921 to +5922
if _native_rocm:
ld_dirs = [*_native_rocm, *ld_dirs]

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 Keep bundled ROCm libraries ahead of system ROCm

On native Linux machines with a full ROCm install, prepending the entire system ROCm lib dir before binary_dir makes the dynamic loader resolve standard ROCm libs such as librocblas/hipblaslt from /opt/rocm before the bundle; however the installer explicitly copies the bundle's lib*.so* plus rocblas/hipblaslt payloads for linux-rocm, so this can bypass the per-bundle kernels and reintroduce missing/unsupported gfx failures. The serve-time helper has the same ordering, so please avoid putting the broad system ROCm directory before the bundled runtime libraries unless only the intended HIP/HSA libraries can be selected.

Useful? React with 👍 / 👎.

danielhanchen added a commit to InfoSage05/unsloth that referenced this pull request Jul 21, 2026
…preference for PR unslothai#7233

Lets a host where the bundled runtime works but system ROCm is mismatched keep
the bundle. Mirrored in llama_cpp.py and install_llama_prebuilt.py.
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for this, the native-Linux gating (bundled HIP present + /dev/kfd) is the right general shape and it subsumes the Strix Halo #6276 case, so I closed my narrower #7295 in favor of this.

I pushed two small maintainer edits:

  1. Added an UNSLOTH_LLAMA_NO_SYSTEM_ROCM=1 opt-out to _native_linux_system_rocm_lib_dirs in both llama_cpp.py and install_llama_prebuilt.py, so a host where the bundled runtime works but system ROCm is mismatched can keep the bundle.
  2. Reverted the opencode --format json CI change so this PR stays scoped to the ROCm fix. Please open that as its own PR and I will merge it separately.

The ROCm change now stands on its own and looks good to me.

@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: d0240e030b

ℹ️ 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 added a commit to InfoSage05/unsloth that referenced this pull request Jul 21, 2026
…hai#7233

Put HIP_PATH/HIP_PATH_57/ROCM_PATH-derived roots before /opt/rocm so a stale
/opt/rocm can't shadow the driver-matching install the env vars point at.
Mirrored in llama_cpp.py and install_llama_prebuilt.py.
danielhanchen added a commit to InfoSage05/unsloth that referenced this pull request Jul 21, 2026
…hai#7233

Put HIP_PATH/HIP_PATH_57/ROCM_PATH-derived roots before /opt/rocm so a stale
/opt/rocm can't shadow the driver-matching install the env vars point at.
Mirrored in llama_cpp.py and install_llama_prebuilt.py.
@danielhanchen
danielhanchen force-pushed the fix/native-linux-rocm-system-libs branch from e3dfd93 to 1b5e275 Compare July 21, 2026 12:30

@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

https://github.com/unslothai/unsloth/blob/e3dfd937ac3be40aca81f7fb7adf35451d4268ac/temp/c14/pr.tar#L1
P1 Badge Remove the checked-in temporary workspace

This commit adds 4,777 files under temp/ (about 309 MB), including this 62 MB archive, cloned upstream source trees, model/checkpoint artifacts, and local test logs. These files are unrelated to the ROCm change and will permanently inflate repository history and clone/checkout costs even if removed in a follow-up; drop the entire accidental temp/ import before merging.

ℹ️ 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 temp/c15_sim/apikey.txt Resolved
@danielhanchen

Copy link
Copy Markdown
Member

Pushed one more edit for the review: env-configured roots (HIP_PATH / HIP_PATH_57 / ROCM_PATH) now come before /opt/rocm in the candidate list, so a stale /opt/rocm can't shadow the driver-matching install those vars point at (addresses the codex ordering note). The gemini env-resolution suggestion is already covered by that same candidate list.

On the codex point about system librocblas/hipblaslt shadowing the bundle's per-gfx kernels: LD_LIBRARY_PATH is directory-granular, so there is no ordering that gives system libhsa-runtime64 while keeping the bundle's librocblas, and the /dev/kfd + libhsa gate already implies a real driver-matched ROCm that carries the gfx kernels. This is the same whole-dir prepend the existing WSL helper does, so keeping it consistent; the env-first ordering above is the actionable mitigation for the stale-root case.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 1b5e275085

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

InfoSage05 and others added 3 commits July 21, 2026 15:23
…HIP crash

Prebuilt llama.cpp bundles ship their own ROCR/HIP runtime which can be
incompatible with the host's amdkfd kernel driver, causing hsa_init()
to crash or report zero devices. The llama-server then silently falls
back to CPU while the UI reports GPU.

The existing workaround (_wsl_system_rocm_lib_dirs) that prepends
/opt/rocm/lib to LD_LIBRARY_PATH was gated on WSL (/dev/dxg) only,
leaving native Linux AMD hosts unprotected.

This commit adds _native_linux_system_rocm_lib_dirs(), a parallel
helper gated on:
- Linux platform (not WSL)
- /dev/kfd present (bare-metal AMD compute)
- Bundle contains bundled HIP libs (libggml-hip.so)
- System has libhsa-runtime64.so(.1)

It is called from both _llama_server_env_for_binary (serve-time)
and binary_env (install-time validation), directly after the WSL
block in both paths.

Fixes unslothai#7208

Fixes unslothai#7208
…preference for PR unslothai#7233

Lets a host where the bundled runtime works but system ROCm is mismatched keep
the bundle. Mirrored in llama_cpp.py and install_llama_prebuilt.py.
…hai#7233

Put HIP_PATH/HIP_PATH_57/ROCM_PATH-derived roots before /opt/rocm so a stale
/opt/rocm can't shadow the driver-matching install the env vars point at.
Mirrored in llama_cpp.py and install_llama_prebuilt.py.
@danielhanchen
danielhanchen force-pushed the fix/native-linux-rocm-system-libs branch from 1b5e275 to 37609b3 Compare July 21, 2026 22:24
@danielhanchen

Copy link
Copy Markdown
Member

Rebased onto current main to clear the merge conflict (the branch was based on a pre-rewrite history, so it had no common ancestor with main and the two files had drifted). Your original commit is preserved; I dropped the net-zero opencode CI add/revert pair and kept the two refinements (UNSLOTH_LLAMA_NO_SYSTEM_ROCM opt-out, env-configured ROCm root before /opt/rocm). Net diff is unchanged at the two files, and it is MERGEABLE now.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

Added 629491f: _bundled_hip_present now globs libggml-hip.so* instead of checking only the exact libggml-hip.so / .so.0 names. The ROCm bundles ship the backend lib with a version suffix (e.g. libggml-hip.so.0.11.1), which the installer already matches via glob in runtime_payload_health_groups; the exact-name check would miss that and silently no-op the whole workaround.

This branch is the native-Linux (bare-metal, non-WSL) generalization of the WSL-only system-ROCm prepend, so it covers the same-root-cause reports: #7208 (gfx1100 hsa_init crash -> silent CPU fallback), #7310 (gfx1151 Strix Halo startup segfault), and the prebuilt-segfault half of #7307 (gfx1201). The multi-GPU AllReduce crash in #7307 is a separate source-build issue in llama.cpp and is not in scope here.

@danielhanchen

Copy link
Copy Markdown
Member

@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

Here are some automated review suggestions for this pull request.

Reviewed commit: 629491f3f2

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

/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.

@danielhanchen

Copy link
Copy Markdown
Member

Good catch on the docstring, corrected in 2b1bd89. The prepend of the whole system ROCm lib dir is deliberate, not an oversight, so I updated the wording (it no longer claims the bundle keeps librocblas, since it does not).

The reasoning: the crash is bundled libhsa-runtime64 failing hsa_init against the host amdkfd driver, and ROCR / HIP / rocBLAS are a version-coupled chain. The bundle is a self-consistent set for its ROCm version and the host system ROCm is usually a different version, so keeping the bundle per-gfx rocBLAS while loading a different-version system HIP/ROCR risks missing-symbol failures. Prepending the whole system dir instead gives one consistent, driver-matched stack. That is correct whenever the host ROCm supports this GPU, which it must for the ROCm torch build to run, so it holds for every reported case (#7208 gfx1100 / 7.2.4, #7310 gfx1151 / 7.13, #7307 gfx1201 / 7.2.3, all with system ROCm that already drives the GPU).

The narrow case you describe, a system ROCm that has HIP for the GPU but no rocBLAS/hipBLASLt kernels for that arch, is real but rare, and mixing versions would be riskier there, not safer. UNSLOTH_LLAMA_NO_SYSTEM_ROCM=1 is the escape hatch to keep the pure bundle for that host.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 2b1bd89b84

ℹ️ 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 c1947ed into unslothai:main Jul 22, 2026
52 checks passed
LeoBorcherding added a commit that referenced this pull request Jul 25, 2026
* ROCm/AMD CI coverage: arch-table parity, native-Linux lib prepend, RDNA4 grouped_mm, discovery-based shell suite

Three merged ROCm fixes shipped without tests, and the CI wiring that
would have run them was gated on files the fixes do not touch.

Tests added (113):
  tests/studio/install/test_rocm_arch_table_parity.py (27)
    diffs the four duplicated gfx -> AMD pip-index tables across
    install.sh, install.ps1, studio/setup.ps1 and install_python_stack.py,
    plus the GPU-name -> arch tables and the torch 2.11 pin allowlist.
  tests/studio/install/test_rocm_native_linux_lib_dirs.py (26)
    covers #7233: system-ROCm lib dirs prepended ahead of bundled
    libggml-hip, the /dev/kfd + not-WSL + libhsa gate, the opt-out env
    var, root resolution order, and source parity between the two copies.
  studio/backend/tests/test_grouped_mm_rdna4_fallback.py (46)
    covers #7292: registration on the CUDA dispatch key, grouped and
    ungrouped numerics, bias/dtype promotion, and the Linux HIP<7.13 +
    RDNA4 name gate, executed from the shipped source rather than a copy.
  tests/studio/test_ci_shell_suite_coverage.py (14)
    fails if either shell runner goes back to a hardcoded list or skips
    a file without a recorded reason.

CI wiring:
  studio-backend-ci.yml: add install.sh / install.ps1 to the path filter
    (the suites it runs assert against those two files, so install-only
    changes -- the shape most AMD/ROCm routing fixes take -- skipped it),
    and replace the 13-file hardcoded shell list with directory
    discovery. That list had fallen seven files behind, including
    test_strixhalo_wsl_reroute.sh, the only shell coverage of the ROCm
    WSL reroute, which had never run on a PR.
  tests/run_all.sh: same discovery loop so local and CI agree.

* Test review fixes: assert on outcomes, not on the code under test

Self-review of the previous commit found four tests that passed for the
wrong reason.

1. The arch-table parity test pinned expected gfx ids copied out of the
   shipped tables, which enshrined three upstream inaccuracies as
   correct: RX 9070 (non-XT) is gfx1201 not gfx1200, RX 7800 XT is
   gfx1101 not gfx1100, and PRO V710 is gfx1101 not gfx1102 per AMD's
   ROCm compatibility matrix. The expectation is now the AMD pip index
   leaf -- the thing the tables exist to produce, and what a wrong
   answer costs the user. The three known drifts are listed explicitly
   with a test asserting they stay cosmetic, i.e. that the wrong and
   right ids still map to the same wheel index. That test turns red the
   day one of them starts routing users to the wrong wheel.

2. The RDNA4 device-name test extracted the regex from worker.py and
   then matched with it, so it could not fail. Widening the pattern --
   the dangerous edit, since it forces the slow Python mm fallback onto
   RDNA3 users -- would have been silently accepted. It now reads the
   live pattern and checks it against fixed cases, plus asserts the
   name match stays guarded by `not _lin_arch` and that the name is
   lowercased before matching.

3. The CI-coverage test matched a verbatim line of studio-backend-ci.yml,
   so reindenting the step would fail the build while a real regression
   to a hardcoded list could slip past a reformat. It now parses the
   YAML, finds the step by name, and asserts on the glob plus the
   absence of individual filenames. The path-filter test likewise reads
   the parsed trigger instead of scanning raw text.

4. A set comprehension in the parity helper had a ternary whose branches
   were identical.

Mutation-tested: widening the RDNA4 regex, desyncing one copy of the
name table, dropping install.sh from the path filter, and re-skipping
the ROCm WSL shell suite each fail at least two tests. Verified on
Linux (WSL Ubuntu 24.04) with CI's torch pin: 86 + 48 pass.

* Fix three wrong gfx ids in the GPU-name arch tables

The name -> gfx tables disagreed with AMD's ROCm compatibility matrix on
three entries. Corrected against the "Radeon GPU" list at
rocm.docs.amd.com/en/latest/compatibility/compatibility-matrix.html:

  RX 9070, RX 9070 GRE   gfx1200 -> gfx1201   (Navi 48, same die as the XT)
  RX 7800 XT, RX 7700 XT gfx1100 -> gfx1101   (Navi 32, not Navi 31)
  PRO W7700              gfx1100 -> gfx1101
  PRO V710               gfx1102 -> gfx1101   (Navi 32, not Navi 33)

No wheel changes for anyone: gfx1200/gfx1201 both resolve to gfx120X-all
and gfx1100/gfx1101/gfx1102 all resolve to gfx110X-all, in all four copies
of the index-family map. That collapse is why the errors survived being
copied into six places -- the leaf-level tests could not see them.

It was not purely cosmetic, though. install.sh's second copy feeds
"Tip: set UNSLOTH_ROCM_GFX_ARCH=<arch>", so a 7800 XT user following the
printed advice exported gfx1100 and made a wrong id authoritative for
every later run. It would also have become a real misroute the moment AMD
split a family across index leaves, as they already do for gfx1151/gfx1150.

Fixed in all six places, which is two more than the table's own "kept in
sync with" comments claim exist:

  install.sh   _infer_amd_gfx_arch_from_gpu_name
  install.sh   case "$_gpu_disp_mkt"          (banner + env tip; undocumented)
  studio/setup.sh
  install.ps1
  studio/setup.ps1
  studio/install_python_stack.py

Ordering is preserved: the gfx1102 arm still precedes gfx1101 in the shell
copies so "RX 7700S" cannot fall onto the "RX 7700" glob, and the
PowerShell copies keep the (?!S) lookahead.

Test changes:
  - test_rocm_arch_table_parity.py gains _AMD_DOCUMENTED_ARCH, exact gfx
    ids transcribed from AMD rather than from the tables. Agreement between
    six copies proves nothing when all six were transcribed from the same
    mistake, so the ground truth has to come from outside. Verified it
    catches the bug: against the pre-fix tables it fails 6 tests.
  - The parity check now covers all six copies. It had four; the two
    install.sh copies were being treated as one, and
    _WIN_GPU_NAME_ARCH_TABLE was not checked at all.
  - test_rocm_support.py's TestGfxArchNameFallback pinned two of the wrong
    ids as expected values; updated, and extended with a 9060 XT and a
    7900 XTX case so each RDNA3/4 die is represented.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Guard against unregistered copies of the GPU-name arch table

Counting the copies by hand is what let them drift: the in-code "kept in
sync with" comments claimed four, the arch-id fix found six, and scanning
the tree turns up a seventh.

TestNoUnregisteredArchTable rediscovers the copies from the source tree
instead of trusting a hand-maintained list. A table line is one that names
a card and gives its arch; real tables score 9-17 such lines and the only
other hits in the repo are two single-line prose comments, so the
three-line threshold is not load-bearing. A companion test asserts the
scan still finds the known copies, so the heuristic cannot go blind and
pass by finding nothing.

The seventh copy is tests/_zoo_rocm_spoof.py, the fixture other ROCm tests
build their fake AMD host from. It states the mapping backwards (gfx ->
the name torch should report), which makes it an independent witness: it
had gfx1101 -> RX 7800 XT and gfx1201 -> RX 9070 XT right while all six
installer copies were wrong, and nothing compared the two. Now they are
round-tripped against each other.

RX 6700 XT is pinned as a known divergence rather than normalised. AMD's
compatibility matrix documents no consumer RX 6000 card and no gfx1031 at
all, the installer arm is commented "gfx103X family", and gfx1031 appears
only as an index-family key, never as a value a name table emits. With no
external source to correct against, changing shipped behaviour would be
guesswork. A test fails if the divergence ever disappears, so the
exemption cannot go stale.

Also adds the reverse of the AMD-matrix check: a documented card that
matches no arm anywhere is a silent CPU fallback rather than a wrong id.
This cannot detect hardware nobody transcribed, which would need a live
fetch of AMD's matrix and a non-hermetic suite; the docstring says so
rather than implying coverage that is not there.

Verified on Linux: 478 passed, plus all five new guards mutation-tested
to confirm each fails when its invariant is broken.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Docstring said six copies; the list under it now has seven

* tests: run discovered shell tests with bash, not sh

tests/run_all.sh discovered tests/sh/ instead of listing files, but still
invoked each one with sh. Every file there declares a bash shebang, and on
Debian/Ubuntu /bin/sh is dash: test_apt_distro_prompt.sh,
test_studio_home_node_dir.sh and test_with_llama_cpp_dir_link_behavior.sh
fail on bashisms under dash and pass under bash. The old hand-written list
happened to name only dash-clean files, so switching to discovery is what
surfaced it. Backend CI already used bash, so this was a local-only break.

Guarded by a new test asserting both runners invoke tests/sh/ with bash.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix Krackan Point (Radeon 860M/840M) routed to the gfx1150 wheel index

The GPU-name tables map 860M/840M and the Ryzen AI 7 350 / AI 5 340 CPU
strings to gfx1150, but Krackan Point is gfx1152. AMD's own lemonade table
(src/cpp/server/system_info.cpp) maps both Krackan iGPUs to gfx1152.

Unlike the three ids already fixed here, this one is not wheel-neutral:
repo.amd.com publishes gfx1150 and gfx1152 as separate index leaves with
separately built torch wheels, so these laptops were installing wheels
built for a different LLVM target. gfx1152 was absent from the codebase
entirely, so it needed the index-family maps, the torch 2.11 floor lists
(same _grouped_mm bug as gfx1150/1151), the Strix reroute set and the
Windows arch allowlist as well as the seven name tables.

The parity test added in this PR did not catch it because its AMD-matrix
expectations stopped at 890M/880M. Added the APU rows, so the case that
actually changes a wheel is now covered: reverting the tables fails 9
tests naming 860M, 840M and Krackan.

gfx1153 (Ryzen AI 5 430 era) is left alone; AMD publishes no gfx1153
wheel family, so there is nothing to route it to.

Verified: bash -n on both shell installers, PowerShell AST parse on both
.ps1 files, python ast.parse on all touched modules, install suite 1334
passed with no new failures against main, shell suite 20 files.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add gfx1152 to unified-memory classifiers, make parity allowlist set-based

Krackan Point (gfx1152, Radeon 860M/840M) is the third RDNA 3.5 APU and
shares one GPU/system-RAM pool exactly like Strix Point (gfx1150) and
Strix Halo (gfx1151), but only the installers knew about it. The two
runtime classifiers still had two-element arch sets, so a Krackan laptop
got the 0.90 discrete headroom factor on a shared pool and ran llama.cpp
without GGML_CUDA_ENABLE_UNIFIED_MEMORY.

- worker.py _rocm_classify_unified_memory: add gfx1152 to the arch set,
  and 860m/840m to the device-name fallback. The NVIDIA GeForce 840M
  cannot collide there: the function is only reached under _hw.IS_ROCM.
- llama_cpp.py _amd_apu_wants_unified_memory: add gfx1152 to the arch set.
- Tests for both, including the :sramecc-:xnack- suffix form.

TestGfx211AllowlistParity compared four hardcoded allowlist strings, so
adding gfx1152 to all four installers correctly turned three assertions
red without any installer actually disagreeing with another. Each test
now extracts the set its installer holds and compares it to one EXPECTED
constant. Order and spacing are free, membership is not, and the next
leaf is a one-line edit instead of four.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
@InfoSage05
InfoSage05 deleted the fix/native-linux-rocm-system-libs branch July 31, 2026 15:12
LeoBorcherding added a commit to indrajeetapache/unsloth that referenced this pull request Aug 18, 2026
unslothai#7233 prepends the whole system ROCm dir, so any lib in it can be the one that
fails to resolve, not just HIP. Parse glibc's ``symbol lookup error: <object>:
undefined symbol: <sym>`` line and match the ROCm family on the object's
basename, so librocblas / libhipblaslt reach the same bundle-only retry instead
of the generic 127 text plus a --fit retry that cannot load a missing symbol.
The message now names the object and symbol the loader reported: it hardcoded
hsa_amd_queue_create while the predicate also fired on any rocr_ match.

_run_full_offload_spawns recorded every subprocess.Popen, so a host with the
rocm_sdk wheel installed also captured the offload-arch probe that
discover_current_target_family() shells out to from inside load_model. That
landed at index 0 and shifted the assertions onto the wrong process, which is
why the test passed in a full-file run and failed on its own. Record only the
fake server and delegate the rest.

Also guard the empty LD_LIBRARY_PATH case, cover the mix the retry does not fix
(both fit-branch guards had no test), and drop three source-text assertions the
behavioural tests already prove.
LeoBorcherding added a commit to indrajeetapache/unsloth that referenced this pull request Aug 18, 2026
Twelve issue citations across four files for one fix, several of them
restating the line below. Keep unslothai#8998 where it identifies the crash signature
and unslothai#7233 where it names the prepend being undone, drop the rest, and cut the
prose that repeated the code. One was already stale: the ggml test said the
ROCm branch "names libamdhip64", which stopped being true when the detector
started matching the whole ROCm family.
LeoBorcherding added a commit to indrajeetapache/unsloth that referenced this pull request Aug 18, 2026
The retry repaired one launch and recorded nothing, so each load paid another
crashing spawn, and the STT sidecar never recovered at all: it builds its child
env through the same _llama_server_env_for_binary and has no retry of its own,
leaving dictation broken on the host chat had just been fixed on.

Record the build dir once a bundle-only launch reaches health and skip the
prepend there from then on. Written only from that proof, so a host the unslothai#7233
prepend is right for cannot land in it, and kept in-process so a ROCm or driver
upgrade re-tests on restart.
Etherll added a commit that referenced this pull request Aug 19, 2026
…ch (#9002)

* Studio: retry ROCm llama-server with bundled HIP on HIP/ROCR mismatch

System ROCm on LD_LIBRARY_PATH plus bundled libamdhip64.so dies on
hsa_amd_queue_create@ROCR_1 (exit 127). That is not a VRAM miss, so do
not flip --fit; retry once without the system prepend instead.

Co-authored-by: Cursor <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: give the ROCm HIP/ROCR fallback its own spawn retry

The library-mix retry was sharing the (0, 1) slot with --fit, so a later
VRAM crash after bundled HIP could not fit-retry. Keep the two recoveries
independent and pin the mix → bundled HIP → --fit on sequence.

Co-authored-by: Cursor <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: widen the ROCm symbol-lookup detector and fix the retry harness

#7233 prepends the whole system ROCm dir, so any lib in it can be the one that
fails to resolve, not just HIP. Parse glibc's ``symbol lookup error: <object>:
undefined symbol: <sym>`` line and match the ROCm family on the object's
basename, so librocblas / libhipblaslt reach the same bundle-only retry instead
of the generic 127 text plus a --fit retry that cannot load a missing symbol.
The message now names the object and symbol the loader reported: it hardcoded
hsa_amd_queue_create while the predicate also fired on any rocr_ match.

_run_full_offload_spawns recorded every subprocess.Popen, so a host with the
rocm_sdk wheel installed also captured the offload-arch probe that
discover_current_target_family() shells out to from inside load_model. That
landed at index 0 and shifted the assertions onto the wrong process, which is
why the test passed in a full-file run and failed on its own. Record only the
fake server and delegate the rest.

Also guard the empty LD_LIBRARY_PATH case, cover the mix the retry does not fix
(both fit-branch guards had no test), and drop three source-text assertions the
behavioural tests already prove.

* Studio: bound the ROCm loader object and symbol in the failure message

Both captures are runs of non-whitespace taken straight from the child, and
_drain_stdout keeps an unterminated line whole, so a wrapper on
LLAMA_SERVER_PATH printing a megabyte-scale token would put all of it in the
API error. _short is the existing bound for exactly this and every other
capture in _classify_start_failure_text already uses it.

* Studio: tighten the ROCm retry comments

Twelve issue citations across four files for one fix, several of them
restating the line below. Keep #8998 where it identifies the crash signature
and #7233 where it names the prepend being undone, drop the rest, and cut the
prose that repeated the code. One was already stale: the ggml test said the
ROCm branch "names libamdhip64", which stopped being true when the detector
started matching the whole ROCm family.

* Studio: keep the bundle-only ROCm correction for every later child

The retry repaired one launch and recorded nothing, so each load paid another
crashing spawn, and the STT sidecar never recovered at all: it builds its child
env through the same _llama_server_env_for_binary and has no retry of its own,
leaving dictation broken on the host chat had just been fixed on.

Record the build dir once a bundle-only launch reaches health and skip the
prepend there from then on. Written only from that proof, so a host the #7233
prepend is right for cannot land in it, and kept in-process so a ROCm or driver
upgrade re-tests on restart.

* Studio: keep a spaced object path whole in the ROCm symbol-lookup match

glibc echoes the object verbatim, so a custom LLAMA_SERVER_PATH under a
directory with spaces kept them and \S+? stopped at the first one, dropping the
crash into the generic 127 text instead of the bundle-only retry. Split on the
": undefined symbol:" that follows the object, the same way the missing-library
branch above already keeps "/opt/My Runtime/libfoo.so" whole.

Bounded at PATH_MAX rather than to end of line: no longer path can exist, and
an unbounded lazy capture let one hostile line drive the scan quadratically
(200 prefixes on a 400 KB line went 3ms -> 803ms; with the bound, 16ms).

* Studio: record the ROCm correction from any launch in the load, not the first

_did_rocm_retry lived in _spawn_and_wait, but the correction edits the shared
env, so it outlives that call: the drafterless, no-flash, arch-fallback and CPU
replay paths all call _spawn_and_wait again with the corrected env and a fresh
flag. A load that recovered through one of those came up healthy without
recording anything, and the STT sidecar kept the prepend it had already proved
wrong.

Hoist the flag to the load scope. Verified both ways: mix, signal crash, fit
retry, then a healthy no-flash launch now records; with the per-call flag that
same sequence does not.

* Invalidate ROCm preference after runtime replacement

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Leo Borcherding <[email protected]>
Co-authored-by: Etherl <[email protected]>
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 23, 2026
…m prepend hides the GPU (unslothai#14933)

Fixes unslothai#14906

## Problem

On native Linux AMD hosts, Studio puts the system ROCm lib dir
(`/opt/rocm/lib`, or the `HIP_PATH` / `ROCM_PATH` root) ahead of the
prebuilt's bundled ROCm runtime when it spawns `llama-server` (unslothai#7233,
for unslothai#7208 where the bundled ROCR crashed in `hsa_init`). On hosts where
the bundled runtime is the working one and the system copy is the
mismatch, HIP initialisation fails without a crash: `llama-server
--list-devices` prints `(none)`, `-ngl -1` becomes a no-op and the model
runs on the CPU with no error. The existing bundle-only retry in
`load_model` only fires on a startup crash with a ROCm symbol lookup
error, so it never triggers here.

Reporter's bisection (RX 7900 XTX, ROCm 7.2, CachyOS):

```
~/.unsloth/llama.cpp/llama-server --list-devices
#   ROCm0: AMD Radeon RX 7900 XTX (24560 MiB, ...)
LD_LIBRARY_PATH=/opt/rocm/lib ~/.unsloth/llama.cpp/llama-server --list-devices
#   (none)
```

## Fix

When the system ROCm prepend would apply, `_llama_server_env_for_binary`
now asks the binary once per build (keyed on build dir +
inode/size/mtime, like the existing bundle-only latch):

1. `--list-devices` with the prepend. Lists a GPU, crashes, or gives no
parseable answer: keep the prepend (today's behaviour, so unslothai#7208 / unslothai#7307
hosts are unchanged and pay one probe).
2. Only when that lists no device at all: `--list-devices` with the
bundled runtime only. If that lists a GPU, log a warning and latch the
existing bundle-only preference, so every later child (chat server, STT
sidecar, device enumeration) uses the bundle.

No probe runs off native Linux, without `/dev/kfd`, without a bundled
`libggml-hip`, without a system ROCm install, or with
`UNSLOTH_LLAMA_NO_SYSTEM_ROCM=1`, so CUDA, Vulkan, CPU, macOS, Windows
and WSL hosts see no change.

## Tests

`studio/backend/tests/test_system_rocm_hides_gpu.py` drives a stub
`llama-server` whose `--list-devices` answer depends on
`LD_LIBRARY_PATH`:

- prepend hides the GPU, bundle shows it: bundle-only env, latched for
the STT sidecar, 2 probes total, `_run_list_devices` then reports
`ROCm0`
- prepend shows the GPU (unslothai#7208 shape): prepend kept on 3 env builds, 1
probe
- no GPU either way, unparseable mix answer, crashing mix probe,
unexecutable binary: prepend kept
- no system ROCm: no probe
- a build swapped in place is probed again

With only the call-site hunk reverted, the three behavioural tests fail
and the five keep-the-prepend guards pass. The related backend suites
(17 files, 4078 tests) give the same failure set on the merge base and
on this branch (7 pre-existing failures, all also red on main).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants