Skip to content

Studio (AMD Linux): keep the bundled ROCm runtime when the system ROCm prepend hides the GPU - #14933

Merged
danielhanchen merged 3 commits into
mainfrom
studio-rocm-prepend-hides-gpu
Oct 23, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-rocm-prepend-hides-gpu

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Fixes #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 (#7233, for #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 [Bug] [ROCm] llama-server silently falls back to CPU on native Linux AMD: bundled ROCR runtime crashes in hsa_init(), system-ROCm override only applied on WSL #7208 / RDNA4 (gfx1201 / Radeon AI PRO R9700): prebuilt llama-server segfaults on startup — plus an iGPU/HIP crash Studio doesn't guard against #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:

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

@danielhanchen danielhanchen self-assigned this Oct 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T05:55:10.679853Z afcd27c Manual request
🔒 Security Review ✅ Completed 2026-10-23T05:45:30.606745Z 38fb8c2 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 38fb8c2dda

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 38fb8c2dda

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: afcd27caa3

ℹ️ 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 1fd1640 into main Oct 23, 2026
4 of 46 checks passed
@danielhanchen
danielhanchen deleted the studio-rocm-prepend-hides-gpu branch October 23, 2026 09:37
danielhanchen added a commit that referenced this pull request Oct 23, 2026
`Repo tests (CPU, studio-install)` fails on `main` (c5482a5). Four
tests fail in two groups, and both reproduce on a clean `main` checkout.

##
`test_uv_boolish_parity.py::test_every_resolver_variable_in_shipped_powershell_goes_through_a_reader[install.ps1,
setup.ps1]`

#14686 added `Test-MirrorConfigured`'s uv config discovery. It decides
`UV_NO_SYSTEM_CONFIG` and `UV_NO_CONFIG` with an inlined copy of uv's
boolish set, because `setup.ps1` reaches that code before it defines
`Test-UvEnvFlag`. The guard exists so every `UV_*` / `PIP_*` switch goes
through the one reader, so the code is what needed to change:

- Both scripts now call `Test-UvEnvFlag 'UV_NO_SYSTEM_CONFIG'` and
`Test-UvEnvFlag 'UV_NO_CONFIG'`.
- `setup.ps1` defines `Test-UvEnvFlag` / `Test-PipEnvFlag` ahead of
`Test-MirrorConfigured`. The block moved unchanged, with one added
comment line. `install.ps1` already defines it earlier in the same
function.
- New test
`test_setup_defines_the_uv_reader_before_its_first_mirror_probe` pins
that order. This hazard is what led to the inline copy in the first
place.

Behaviour is unchanged. Under `Set-StrictMode -Version Latest`,
`Test-MirrorConfigured -Tool uv` returns the same answer on base and
head, in both scripts, with a user `uv.toml` carrying an index and
`UV_NO_CONFIG` set to each of unset, `off`, `0`, `no`, `YES`, ` 1 `,
`true`.

##
`test_rocm_native_linux_lib_dirs.py::TestLlamaCppRuntimeNativeOrdering`

#14933 now holds the native-Linux ROCm dirs in `_system_rocm`, so it can
skip them when they hide the GPU. The source check still looked for the
old one-line
`lib_dirs.extend(_native_linux_system_rocm_lib_dirs(binary_dir))`. The
test was out of date. It now finds the helper call, follows the local it
is assigned to, and still asserts two orderings:
- helper call, then `lib_dirs.extend(...)`, then
`lib_dirs.append(binary_dir)`
- the WSL DXG decision comes before the native dirs

## Verification

- `tests/studio/install/test_rocm_native_linux_lib_dirs.py` and
`test_uv_boolish_parity.py`: 4 failed on `main`, 581 passed on this
branch.
- `tests/studio/install/test_denied_llama_cpp_preflight.py` (byte parity
of the shared install/setup helpers): passes.
- `pwsh tests/studio/test_mirror_fallback.ps1`: 142 PASS, 0 FAIL.
- Sabotage checks:
- Moving `lib_dirs.append(binary_dir)` above the native block fails the
ROCm ordering test.
- Restoring `main`'s `setup.ps1` fails both the reader test and the new
ordering test.
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] Silent CPU fallback on native Linux AMD (RDNA3/gfx1100): studio-prepended /opt/rocm/lib hides the GPU from the bundled llama-server

1 participant