Skip to content

[Unsloth Studio] Prebuilt ROCm llama.cpp binary crashes with "out of memory" (hipStreamCreateWithFlags); source build of the same commit works fine #12205

Closed as not planned

Description

@italopaesano

Prebuilt ROCm binary crashes with "out of memory" on hipStreamCreateWithFlags; source build of the same exact commit works fine

Summary

The prebuilt linux/rocm release asset for tag b11160-mix-a6922cc crashes on load with a ROCm "out of memory" error at the very first hipStreamCreateWithFlags call. Building llama-server from source at the exact same commit (119fa9dc43cd4d63e89a7b5d11f9378b84c52822), with a standard Nix-packaged ROCm 7.2.3 toolchain, works correctly and produces real generation output at ~121 tok/s. This points to something specific to how the prebuilt asset bundles/links its ROCm runtime, not a hardware or driver problem.

Environment

  • OS: NixOS 26.05, kernel 7.2.7 (amdgpu driver in-tree, no dmesg/kfd errors at any point)
  • GPU: AMD Radeon 680M (Rembrandt iGPU), reports as gfx1035. Not on AMD's or llama.cpp's officially validated gfx list, so HSA_OVERRIDE_GFX_VERSION=10.3.0 is set to present as gfx1030 (RDNA2 desktop) — without this the runtime refuses to initialize at all, which is expected/unrelated to this bug.
  • rocminfo (from a Nix-packaged ROCm 7.2.3 SDK) correctly enumerates the device as gfx1030, 12 CUs, reports a 13.6GB GLOBAL/COARSE_GRAINED memory pool.
  • ulimit -l (memlock): tested at both the OS default (8MB, soft+hard) and after raising it to 8GB via security.pam.loginLimits + full reboot. No difference in behavior — ruled out as the cause.
  • No amdgpu/kfd-related messages in journalctl -k at the time of the crash — the failure appears to be purely userspace (inside the bundled HIP/HSA runtime), not a kernel/driver rejection.

Steps to reproduce (prebuilt asset — crashes)

  1. Install via unsloth studio update (this pulls unslothai/llama.cpp@b11160-mix-a6922cc, which for this platform resolves to a prebuilt binary bundling its own libamdhip64.so.7, libhsa-runtime64.so.1, libhipblas.so.3, etc. directly alongside the binary).
  2. Run:
    ./llama-server -m <any GGUF, tested with bartowski/Qwen2.5-0.5B-Instruct-GGUF Q4_K_M> \
      --port 38999 -ngl 99
    
  3. Observe:
    ggml/src/ggml-cuda/ggml-cuda.cu:134: ROCm error
    ROCm error: out of memory
      current device: 0, in function stream at ggml/src/ggml-hip/../ggml-cuda/common.cuh:1561
      hipStreamCreateWithFlags(&streams[device][stream], 0x01)
    
    Crash is immediate, before any real model-memory allocation. -ngl value doesn't matter; happens the same with -ngl 1.

Steps to reproduce the fix (source build — works)

git clone --branch b11160-mix-a6922cc https://github.com/unslothai/llama.cpp.git src
# ROCm 7.2.3 toolchain from nixpkgs (rocmPackages: clr, hipcc, rocm-cmake, rocminfo,
# rocm-comgr, rocm-device-libs, rocm-runtime, hipblas(+common/lt), rocblas, rocsolver)
cmake -B build -S src -DGGML_HIP=ON -DAMDGPU_TARGETS=gfx1030 -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \
  -DCMAKE_HIP_COMPILER=<rocm-toolchain>/bin/clang
cmake --build build -j16 --target llama-server llama-quantize

(Note: had to force gcc/g++ for host C/C++ — using the ROCm-vendored clang for host code too hits an unrelated mm_malloc.h/glibc posix_memalign noexcept conflict on this glibc version, orthogonal to the GPU issue.)

Running the resulting binary with the exact same flags Studio uses (--parallel 4 --flash-attn on --no-context-shift -c 32768 -ngl -1 --fit off --metrics --kv-unified --jinja --spec-default --load-mode none) against the same model works correctly:

model loaded
listening on http://127.0.0.1:38997

and a real /v1/chat/completions request returns a valid completion at 121.6 tok/s (predicted_per_second in the response timings).

What this suggests

Since it's the same source commit, the difference must be in how the prebuilt release asset was built/linked (possibly a different exact ROCm runtime version than the 7.2.3 SDK used here, different AMDGPU_TARGETS set baked into the prebuilt multi-arch "mix" bundle, or a build/link flag difference specific to the release pipeline). Given the "mix" naming in the release tag, this may be specific to how the multi-architecture prebuilt bundle is assembled for gfx1030/RDNA2 targets — possibly not exercised in that pipeline's own testing since gfx1035 (and the override-to-gfx1030 path) is an unofficial combination to begin with, but worth checking whether genuine gfx1030 hardware (RX 6600/6700/etc.) hits the same prebuilt-vs-source discrepancy, since that would point to a real packaging bug rather than something override-specific.

What I'm not certain about

  • Whether this reproduces on officially-supported gfx1030 hardware (I only have the override case to test).
  • The exact ROCm runtime version bundled in the prebuilt asset (I didn't extract/inspect it beyond ldd showing local libamdhip64.so.7 / libhsa-runtime64.so.1 files bundled next to the binary, vs. our source build linking against the Nix-packaged ROCm 7.2.3 versions of the same).

Happy to run any additional diagnostics against the prebuilt asset if useful — I already have both binaries side by side for comparison.

Activity

  1. danielhanchen commented on Oct 8, 2026

    @danielhanchen
    Member

    Thanks for the very thorough report, the side by side source build made this much easier to narrow down.

    The llama.cpp source is the same, but the ROCm userspace is not. The gfx103X Linux bundle ships a TheRock runtime (libamdhip64.so.7.16.26332, libhsa-runtime64.so.1.21.0), while your working build uses stock ROCm 7.2.3. One relevant difference between the two:

    Could you run these three checks so we can confirm it on your 680M?

    1. KFD topology values (no root needed):

      grep -H -E 'simd_count|simd_per_cu|max_waves_per_simd|gfx_target_version' /sys/class/kfd/kfd/topology/nodes/*/properties

      With simd_per_cu 2, a max_waves_per_simd below 16 means the bundled runtime reserves less queue save space than the kernel requires, which the kernel always rejects. A value above 16 (for example 20) is only rejected when the runtime is not using SVM for that buffer (check 2). If it reads exactly 16, this mismatch is not your cause and we need to look elsewhere.

    2. Whether the size check is involved at all. Run the prebuilt with SVM turned off for the runtime's queue buffers:

      HSA_USE_SVM=0 ./llama-server -m <model.gguf> -ngl 99

      Please tell us whether that run and your normal run each start. With SVM off you can also see the kernel side:

      echo 'file kfd_queue.c +p' | sudo tee /sys/kernel/debug/dynamic_debug/control
      HSA_USE_SVM=0 ./llama-server -m <model.gguf> -ngl 99
      sudo dmesg | grep -i 'expected size'

      A line like expected size 0x... not equal to mapping addr ... size 0x... confirms it.

    3. Same prebuilt binary, but with your Nix ROCm 7.2.3 runtime loaded first (the bundle uses RUNPATH=$ORIGIN, so LD_LIBRARY_PATH takes precedence):

      # lib dirs your working source build resolves to:
      ldd ./build/bin/llama-server | grep -E 'amdhip64|hsa-runtime64|amd_comgr|rocblas|hipblas'
      export LD_LIBRARY_PATH=<those dirs, colon separated>
      # which libs actually loaded (should be the /nix/store ones):
      LD_DEBUG=libs ./llama-server -m <model.gguf> -ngl 99 2>&1 | grep -E 'calling init: .*(hsa-runtime64|amdhip64)'
      # then a normal run plus one chat request:
      ./llama-server -m <model.gguf> -ngl 99 --port 38999

      If the prebuilt loads and generates this way, the bundled runtime is confirmed as the cause.

    Until this is fixed in the bundle, the source build you already have is the right workaround. Studio puts a system ROCm ahead of the bundled one when it finds it under ROCM_PATH, HIP_PATH, or /opt/rocm. On NixOS, pointing ROCM_PATH at a root whose lib/ contains libhsa-runtime64.so.1 before starting Studio should also work. The bundle side fix is unslothai/llama.cpp#255: it rebuilds the bundled libhsa-runtime64 with the kernel's wave count, which clears the reproduction above. Your results from the checks will tell us whether it also covers your 680M. We are also looking at making Studio find split Nix ROCm packages on its own.

  2. danielhanchen commented on Oct 9, 2026

    @danielhanchen
    Member

    A correction to my previous comment: the queue sizing mismatch I described is not your cause. Public rocminfo dumps from other Radeon 680M machines show Compute Unit: 12, SIMDs per CU: 2, Max Waves Per CU: 32, which is exactly what the kernel driver expects, so on a 680M the bundled runtime and the kernel agree. That mismatch only hits gfx10.1 cards (RX 5000 series), which report 40. unslothai/llama.cpp#255 fixes that case, not yours. Sorry for the noise.

    So check 1 from my previous comment is no longer needed. Checks 2 and 3 are still the most useful next step, since they separate the bundled runtime from everything else:

    1. The prebuilt with SVM off for the runtime's queue buffers, to see whether the failure changes at all:
      HSA_USE_SVM=0 ./llama-server -m <model.gguf> -ngl 99
    2. The same prebuilt binary with your Nix ROCm 7.2.3 runtime loaded first (the bundle uses RUNPATH=$ORIGIN, so LD_LIBRARY_PATH wins):
      ldd ./build/bin/llama-server | grep -E 'amdhip64|hsa-runtime64|amd_comgr|rocblas|hipblas'
      export LD_LIBRARY_PATH=<those dirs, colon separated>
      LD_DEBUG=libs ./llama-server -m <model.gguf> -ngl 99 2>&1 | grep -E 'calling init: .*(hsa-runtime64|amdhip64)'
      ./llama-server -m <model.gguf> -ngl 99 --port 38999
      If this loads and generates, the bundled TheRock runtime is the problem on your machine and we can narrow it from there.

    If you can, please also run the failing prebuilt once with AMD_LOG_LEVEL=4 and attach the last 100 or so lines before the ROCm error, so we can see which HSA call fails underneath hipStreamCreateWithFlags.

    Until then, your source build against ROCm 7.2.3 remains the right workaround.

  3. danielhanchen commented on Oct 15, 2026

    @danielhanchen
    Member

    Closing this for now since we have not been able to reproduce it on our side.

    To be clear about the earlier llama.cpp change: unslothai/llama.cpp#255 fixes a queue sizing crash on gfx10.1 (RX 5000 series) cards, which is a different problem from yours. We do not have a fix for the Radeon 680M crash yet.

    Your source build against ROCm 7.2.3 remains the right workaround. If you can run the two checks from my last comment (HSA_USE_SVM=0, and the prebuilt with your Nix ROCm 7.2.3 libraries loaded first), please post the results here and we will reopen and pick it up from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions