Repository navigation
Description
Summary
On a native Linux machine with an AMD RDNA3 GPU (RX 7800 XT, gfx1100) and system ROCm 7.2.4, the prebuilt ROCm llama-server bundle fails to initialize the GPU at startup:
E ggml_cuda_init: failed to initialize ROCm: no ROCm-capable device is detected
llama-server then silently serves the model on CPU, while PyTorch (ROCm build) sees the GPU fine — so the Studio UI reports "GPU" even though all inference runs on the CPU.
Root cause: the bundle ships its own ROCR/HIP runtime (libhsa-runtime64.so.1 = 1.21.0-local-build-1b2a555677, libamdhip64.so.7), which is incompatible with the host's ROCm 7.2.4 kernel driver (amdkfd) and segfaults inside hsa_init() (rocr::AMD::GpuAgent::InitDma()). The code path that works around this by prepending the system ROCm libs — _wsl_system_rocm_lib_dirs() — is gated on WSL (/dev/dxg) only, so native Linux never gets the workaround.
Prepending /opt/rocm/lib to LD_LIBRARY_PATH at launch fixes it completely (GPU detected, model offloaded, ~58 tok/s on a 12B Q4_K).
Environment
| Component | Version |
|---|---|
| GPU | AMD Radeon RX 7800 XT (Navi 32, gfx1100), 16 GB |
| System ROCm | 7.2.4 (/opt/rocm, works fine with torch 2.11.0+rocm7.2) |
| OS | Native Linux (x86_64, not WSL; /dev/kfd present, no /dev/dxg) |
| unsloth / unsloth_zoo | 2026.7.3 |
| Prebuilt bundle | b10043-mix-0ac9dfb, asset app-b10043-mix-0ac9dfb-linux-x64-rocm-gfx110X.tar.gz |
| Bundled ROCR runtime | libhsa-runtime64.so.1 → "1.21.0-local-build-1b2a555677" |
| Env | HSA_OVERRIDE_GFX_VERSION=11.0.0, HIP_VISIBLE_DEVICES=0 |
Steps to reproduce
cd ~/.unsloth/llama.cpp/build/bin
# 1. With the env HSA_OVERRIDE_GFX_VERSION=11.0.0 set: clean error, zero devices
LD_LIBRARY_PATH=$PWD ./llama-server --list-devices
# E ggml_cuda_init: failed to initialize ROCm: no ROCm-capable device is detected
# Available devices:
# (empty)
# 2. Without the override: hard crash
env -u HSA_OVERRIDE_GFX_VERSION LD_LIBRARY_PATH=$PWD ./llama-server --list-devices
# Segmentation fault (core dumped)Backtrace of the segfault (gdb):
#0 0x0000000100000001 in ?? ()
#1 rocr::AMD::GpuAgent::InitDma() libhsa-runtime64.so.1 (bundled)
#2 rocr::AMD::GpuAgent::PostToolsInit() libhsa-runtime64.so.1
#3 rocr::core::Runtime::Load() libhsa-runtime64.so.1
#4 rocr::core::Runtime::Acquire() libhsa-runtime64.so.1
#5 rocr::HSA::hsa_init() libhsa-runtime64.so.1
...
#13 hipGetDeviceCount() libamdhip64.so.7 (bundled)
#14 ggml_cuda_init() libggml-hip.so.0
#15 ggml_backend_cuda_reg() libggml.so.0
So the bundled ROCR runtime dies during hsa_init() while initializing DMA for the GPU agent — a runtime/kernel-driver mismatch. With HSA_OVERRIDE_GFX_VERSION=11.0.0 set, the same mismatch surfaces as the clean "no ROCm-capable device" error instead of a crash; either way, llama-server starts with CPU only.
In Studio this shows up in logs/llama-server/llama-*.log as the ggml_cuda_init error line, after which the model loads and serves normally — on CPU.
Why torch works but llama.cpp doesn't
PyTorch in the Studio venv (torch 2.11.0+rocm7.2) links against the system ROCm 7.2.4 libraries, which match the installed kernel driver — torch.cuda.is_available() is True and reports the RX 7800 XT correctly. The prebuilt llama.cpp bundle, by contrast, loads its own bundled ROCR/HIP runtime (because the launcher puts build/bin first on LD_LIBRARY_PATH), and that bundled runtime is the piece that's broken against this host's driver.
Workaround / verified fix
Put the system ROCm lib dir before the bundle dir:
cd ~/.unsloth/llama.cpp/build/bin
LD_LIBRARY_PATH=/opt/rocm/lib:$PWD ./llama-server --list-devices
# Available devices:
# ROCm0: AMD Radeon RX 7800 XT (16368 MiB, 16154 MiB free)Full inference validation (gemma-4-12B-it-qat-UD-Q4_K_XL.gguf, -ngl 99):
rocm-smi --showpids:llama-serverusing 8.76 GB VRAM on GPU0- ~58 tok/s generation, ~267 tok/s prompt processing (CPU would be single-digit tok/s)
- Works with or without
HSA_OVERRIDE_GFX_VERSION=11.0.0
The bundle's libggml-hip.so / librocblas.so (with the gfx kernels) still load from the bundle dir — only the ROCR/HIP user-mode runtime comes from /opt/rocm/lib.
Root cause in the code
The workaround for exactly this class of problem exists but is WSL-only:
studio/backend/core/inference/llama_cpp.py—_llama_server_env_for_binary()builds the serve-timeLD_LIBRARY_PATH. It calls_wsl_system_rocm_lib_dirs(), which returns[]unless/dev/dxgexists and/proc/versioncontains "microsoft" — i.e. WSL2 only. On native Linux, onlybuild/bin(+ CUDA dirs) end up on the path, so the bundled ROCR runtime always wins.studio/install_llama_prebuilt.py— same pattern in the install/validation env builder (binary_env, host.is_linux branch), so install-time validation has the same blind spot.
The docstrings even note the bundled bare-metal HIP "segfaults on the first GPU call" on WSL — the same thing happens on native Linux when the bundled ROCR and the host amdkfd driver are out of sync.
Suggested fix
Extend the system-ROCm prepend to native Linux, gated conservatively. Sketch (applied locally, verified):
def _bundled_hip_present(binary_dir) -> bool:
if not binary_dir:
return False
try:
return os.path.exists(os.path.join(str(binary_dir), "libggml-hip.so")) or \
os.path.exists(os.path.join(str(binary_dir), "libggml-hip.so.0"))
except OSError:
return False
def _native_linux_system_rocm_lib_dirs(binary_dir=None) -> list[str]:
"""System ROCm lib dir(s) to load before a prebuilt's bundled HIP, on native Linux."""
if sys.platform != "linux" or os.path.exists("/dev/dxg"):
return [] # WSL handled by _wsl_system_rocm_lib_dirs; non-Linux no-op.
if not os.path.exists("/dev/kfd"):
return [] # No bare-metal AMD compute node.
if not _bundled_hip_present(binary_dir):
return [] # Only relevant for HIP-enabled bundles.
out = []
for d in ("/opt/rocm/lib", "/opt/rocm/lib64"):
if os.path.exists(os.path.join(d, "libhsa-runtime64.so")) or \
os.path.exists(os.path.join(d, "libhsa-runtime64.so.1")):
out.append(d)
return outThen, in _llama_server_env_for_binary() (llama_cpp.py), right after the WSL block:
lib_dirs.extend(_native_linux_system_rocm_lib_dirs(binary_dir))and equivalently in binary_env() (install_llama_prebuilt.py, host.is_linux branch):
_native_rocm = _native_linux_system_rocm_lib_dirs(binary_path.parent)
if _native_rocm:
ld_dirs = [*_native_rocm, *ld_dirs]With this, the serve-time LD_LIBRARY_PATH becomes /opt/rocm/lib:<bundle>/build/bin:..., and GPU inference works out of the box on native-Linux ROCm hosts whose driver is newer/different than the bundle's ROCR.
Secondary suggestion: fail loudly on GPU-init failure
The silent CPU fallback is what makes this painful to diagnose — the UI says GPU, logs are terse at default verbosity, and the only signal is slow tokens. When the user requested GPU offload (-ngl > 0) and every GPU backend fails to initialize, consider warning prominently (or refusing to start with a clear message) instead of quietly serving on CPU.
Activity
fix(rocm): prepend system ROCm libs on native Linux to avoid bundled …
fix(rocm): prepend system ROCm libs on native Linux to avoid bundled …
fix(rocm): prepend system ROCm libs on native Linux to avoid bundled …
carottemendoza commentedon Oct 23, 2026
Following up on this thread since it might look like the fix here (prepending /opt/rocm/lib on native Linux, commit 447ac40) regressed on my setup: same profile as this report — RX 7900 XTX (gfx1100), native Linux, system ROCm 7.2 - but with the opposite outcome. With the system ROCm libs prepended, the bundled llama-server silently drops the GPU entirely (--list-devices reports none), while it detects the card fine with a clean LD_LIBRARY_PATH. Details, minimal repro, and a very basic wrapper workaround in #14906.
Looks like two native-Linux gfx1100 hosts might need opposite LD_LIBRARY_PATH orderings ? Possibly worth probing GPU visibility at spawn time instead of fixing an ordering, if that's practical.
Studio (AMD Linux): keep the bundled ROCm runtime when the system ROC…