Skip to content

fix(rocm): prefer system LLVM runtime on native Linux - #7448

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
Oxygen56:fix/rocm-system-llvm-runtime
Jul 28, 2026
Merged

fix(rocm): prefer system LLVM runtime on native Linux#7448
danielhanchen merged 3 commits into
unslothai:mainfrom
Oxygen56:fix/rocm-system-llvm-runtime

Conversation

@Oxygen56

Copy link
Copy Markdown
Contributor

Fixes #7446

Summary

  • Include ROCm's nested lib/llvm/lib directory in the native-Linux system runtime paths.
  • Keep the install-time validator and serve-time launcher helpers in sync.
  • Add regression coverage for the nested LLVM runtime ordering.

Root Cause

The native-Linux ROCm path already puts the system lib directory ahead of the llama.cpp prebuilt bundle. However, ROCm installs its versioned LLVM runtime under lib/llvm/lib. When libamd_comgr.so.3 came from the system ROCm installation, the loader could still fall through to an incompatible libLLVM.so.* in build/bin, causing the missing LLVMInitializeSPIRVTarget symbol.

The nested system LLVM directory is now placed after the corresponding system ROCm lib directory and before the prebuilt bundle.

Verification

  • uv run --no-project --python 3.11 --with pytest pytest tests/studio/install/test_rocm_native_linux_lib_dirs.py -q --tb=short -> 27 passed
  • uv run --no-project --python 3.11 --with pytest pytest tests/studio/install/test_install_llama_prebuilt_logic.py -q --tb=short -> 60 passed, 1 skipped
  • uvx --from pre-commit pre-commit run --files studio/install_llama_prebuilt.py studio/backend/core/inference/llama_cpp.py tests/studio/install/test_rocm_native_linux_lib_dirs.py -> passed
  • uv run --no-project --python 3.11 --with pytest pytest tests/studio/install/test_rocm_support.py -q --tb=short -> 358 passed, 16 failed, 3 skipped; the same 16 TestEnsureRocmTorch failures reproduce on an unmodified main worktree in this macOS environment

Notes for Reviewers

  • Full hardware reproduction was not run because this environment does not have the reported Ubuntu 24.04 / ROCm 7.14 / gfx1201 host. The regression test covers both mirrored helpers and the required path order.

@Oxygen56
Oxygen56 requested a review from danielhanchen as a code owner July 26, 2026 01:26
@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: 46ce872a85

ℹ️ 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 studio/install_llama_prebuilt.py Outdated
Comment on lines +4737 to +4738
llvm_lib = os.path.join(d, "llvm", "lib")
if llvm_lib not in seen and os.path.exists(llvm_lib):

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 Resolve the LLVM directory from the ROCm root

On the supported lib64 layout (covered by test_lib64_layout_is_found), d is <root>/lib64, so this constructs <root>/lib64/llvm/lib. ROCm's nested runtime path described by this change is <root>/lib/llvm/lib; therefore hosts with HSA under lib64 but LLVM in the standard nested path omit the system LLVM directory and can still bind libamd_comgr to the incompatible bundled libLLVM. Build the LLVM candidate from base, or probe both layouts, rather than deriving it only from the HSA directory.

Useful? React with 👍 / 👎.

danielhanchen and others added 2 commits July 28, 2026 05:33
…nd non-directories

Two gaps found while simulating the fix against real ROCm layouts.

1. lib64 hosts got no LLVM dir. The candidate was built from the HSA dir, so a
   host with libhsa-runtime64 under lib64 probed <root>/lib64/llvm/lib. ROCm
   installs LLVM under <root>/lib/llvm regardless, so that host kept binding
   system libamd_comgr to the bundle's libLLVM: exactly the bug unslothai#7446 reports.
   Probe both spellings, the HSA dir's own first so a genuine lib64 layout still
   wins. When lib_sub is already "lib" the seen set collapses them.

2. os.path.exists accepted a non-directory. The serve-time caller joins these
   straight into LD_LIBRARY_PATH with no is-dir filter, so a file named
   llvm/lib reached the loader. os.path.isdir instead.

Verified on a 27-case matrix built from real directory trees (not mocks), run on
both Windows and Linux against three revisions: main, this PR as-is, and this
commit. Zero regressions and zero reorderings of the pre-existing entries in
every case, and the installer and launcher copies never disagree. The lib64 case
goes [lib64] -> [lib64, lib/llvm/lib]; the file case drops the bogus entry; a
symlinked llvm/lib resolves correctly on Linux.

End-to-end loader check: built real ELF objects mirroring the shipped bundle
(RUNPATH=$ORIGIN, an incomplete libLLVM.so.23.0git next to llama-server, system
comgr from /opt/rocm/lib) and reproduced the reported failure verbatim, then
confirmed the prepend clears it:
  before  undefined symbol: LLVMInitializeSPIRVTarget  ->  after  exit 0

Test helper now patches os.path.isdir alongside os.path.exists, else every fake
host reports its nested llvm dir as missing. New cases: lib64 finding llvm under
lib, lib64 preferring its own when both exist, and a real-filesystem check that a
non-directory is not prepended. Removing the lib fallback from one copy reddens
three tests including the two-copy parity guard.

tests/studio/install: 1361 passed on Linux, 4 pre-existing environmental
failures unchanged (3 managed-node-runtime under root, 1 the real /opt/rocm case
already covered by unslothai#7397). 30/30 on the helper suite on Windows and Linux.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 1ff2eedc53

ℹ️ 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 77971d0 into unslothai:main Jul 28, 2026
1 check passed
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.

[Bug] undefined symbol: LLVMInitializeSPIRVTarget

2 participants