Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
#!/usr/bin/env bash
# Environment for exllamav3 on a Strix Halo machine (AMD Strix Halo / gfx1151).
#
# RUN: source tools/strix_halo/env.sh (from the repository root)
# BUILD: source tools/strix_halo/env.sh build
# CHECK: bash tools/strix_halo/env.sh --check
#
# ===========================================================================
# FIVE TRAPS, all verified on this box (2026-09-16). Do not "simplify" these.
# ===========================================================================
#
# TRAP 1 -- torch's bundled HSA runtime SEGFAULTS on gfx1151.
# torch 2.10.0+rocm7.0 lists gfx1151 in get_arch_list() and
# torch.cuda.is_available() returns True, but the FIRST device allocation
# segfaults -- even torch.zeros(4, device="cuda"):
# segfault at 34 ... in libhsa-runtime64.so (error 4) -> exit 139
# The fault is inside libhsa-runtime64.so, NOT PyTorch. No env var avoids it
# (HSA_ENABLE_SDMA=0, HSA_ENABLE_IPC=0, AMD_SERIALIZE_KERNEL=3,
# TORCH_BLAS_PREFER_HIPBLASLT=0 all still segfault).
# The kernel is fine: KFD reports gfx_target_version 110501 on node 1.
# FIX: preload the system ROCm 7 libhsa-runtime64 (1.18) over torch's copy.
# Verified: without -> exit 139; with -> 31.5 TFLOP/s fp16 4096^3.
#
# TRAP 2 -- ROCm 6.4 has NO gfx1151 code object (HIP error: invalid device
# function on every kernel). Requires ROCm 7.0+. HSA_OVERRIDE_GFX_VERSION
# must stay UNSET: gfx1151 is native on 7.0 and overriding corrupts kernel
# selection.
#
# TRAP 3 -- the torch wheel ships runtime libs but no hipcc, and reports
# ROCM_HOME=None / IS_HIP_EXTENSION=False, so the build dies with
# "CUDA_HOME environment variable is not set". We borrow the HIP toolchain
# from the AMD gfx1151 nightly's rocm-sdk-devel wheel.
#
# TRAP 4 -- those wheels put device bitcode at lib/llvm/amdgcn/bitcode, not
# the $ROCM_PATH/amdgcn/bitcode clang probes ("cannot find ROCm device
# library"). Passed explicitly below. Also note _rocm_sdk_core lacks
# hipsparse.h and thrust/, so ROCM_HOME must be _rocm_sdk_devel.
#
# TRAP 5 -- those same SDK paths must NOT be exported at RUNTIME. The SDK
# ships its own HSA runtime that wins over the LD_PRELOAD and re-triggers
# the Trap 1 segfault. Build-time only, hence the `build` guard below.
# ===========================================================================
# Repository root = two levels above this file (works for any clone location).
_SELF="${BASH_SOURCE[0]:-$0}"
EXL3_ROOT="${EXL3_ROOT:-$(cd "$(dirname "$_SELF")/../.." && pwd)}"
EXL3_VENV="${EXL3_VENV:-$EXL3_ROOT/.venv}"
export PATH="$EXL3_VENV/bin:$HOME/.local/bin:$PATH"
export PYTHONPATH="$EXL3_ROOT:${PYTHONPATH:-}" # exllamav3 and the built exllamav3_ext*.so live in the repo root
# Needs a ROCm 7 libhsa-runtime64.so.1 (HSA 1.18 or newer). Ubuntu 24.04's own libhsa-runtime64-1 is ROCm 5.7 (1.11)
# and is too old: torch then fails with "undefined symbol: hsa_amd_enable_logging". Looked for, in this order: EXL3_HSA_LIB; the rocm-sdk wheel
# (EXL3_ROCM_SDK/lib, else the root `rocm-sdk path --root` of the venv prints; it matches the torch wheel, so it is tried first); the system ROCm 7
# (EXL3_HSA_SYSTEM_DIRS, default /opt/rocm/lib /usr/lib/x86_64-linux-gnu: install ROCm 7 from AMD's apt repository).
# When none exists this stops with an error: torch would segfault on the first GPU allocation (Trap 1). EXL3_ALLOW_NO_HSA=1 only warns (CPU-only use).
_SDK_ROOT="${EXL3_ROCM_SDK:-}"
if [ -z "$_SDK_ROOT" ] && command -v rocm-sdk >/dev/null 2>&1; then
_SDK_ROOT="$(rocm-sdk path --root 2>/dev/null || true)"
fi
_HSA=""
for _c in "${EXL3_HSA_LIB:-}" "${_SDK_ROOT:-/nonexistent}/lib/libhsa-runtime64.so.1" $(for _d in ${EXL3_HSA_SYSTEM_DIRS:-/opt/rocm/lib /usr/lib/x86_64-linux-gnu}; do echo "$_d/libhsa-runtime64.so.1"; done); do
if [ -n "$_c" ] && [ -e "$_c" ]; then _HSA="$_c"; break; fi
done
if [ -n "$_HSA" ]; then
export LD_PRELOAD="$_HSA"
elif [[ "${LD_PRELOAD:-}" == *libhsa-runtime64* ]]; then
: # the caller already preloads one (a lane script, serve.py): keep it
elif [ "${EXL3_ALLOW_NO_HSA:-0}" = "1" ]; then
echo "[env.sh] WARNING: no libhsa-runtime64.so.1 found (EXL3_ALLOW_NO_HSA=1): any GPU use of torch will segfault on gfx1151 (Trap 1)." >&2
else
echo "[env.sh] ERROR: no libhsa-runtime64.so.1 (ROCm 7) found: torch would segfault on the first GPU allocation on gfx1151 (Trap 1). Install ROCm 7 (/opt/rocm), activate the venv that holds the rocm-sdk wheel (rocm-sdk path --root), or set EXL3_ROCM_SDK or EXL3_HSA_LIB. Set EXL3_ALLOW_NO_HSA=1 for CPU-only use." >&2
return 1 2>/dev/null || exit 1
fi
unset _SDK_ROOT _HSA _c _d
# Uncomment to force reconstruct+hgemm instead of HIP GEMV (debugging):
# export EXL3_GEMV=0
# --- BUILD-ONLY toolchain (Trap 5: never export these for inference) ---
if [ "${1:-}" = "build" ] || [ "${EXL3_BUILD:-0}" = "1" ]; then
_SDK="${EXL3_ROCM_SDK:-$EXL3_ROOT/.venv-gfx1151/lib/python3.12/site-packages/_rocm_sdk_devel}"
export ROCM_HOME="$_SDK"
export ROCM_PATH="$_SDK"
export HIP_PATH="$_SDK"
export HIPCXX="$_SDK/bin/hipcc"
export PATH="$_SDK/bin:$_SDK/llvm/bin:$_SDK/lib/llvm/bin:$PATH"
if [ -d "$_SDK/lib/llvm/amdgcn/bitcode" ]; then
HIP_DEVICE_LIB_PATH="$_SDK/lib/llvm/amdgcn/bitcode"
else
HIP_DEVICE_LIB_PATH="$_SDK/amdgcn/bitcode"
fi
export HIP_DEVICE_LIB_PATH
GCC_INSTALL_DIR="${EXL3_GCC_INSTALL_DIR:-$(dirname "$(gcc -print-libgcc-file-name)")}"
export HIPCC_COMPILE_FLAGS_APPEND="--gcc-install-dir=$GCC_INSTALL_DIR --rocm-device-lib-path=$HIP_DEVICE_LIB_PATH --rocm-path=$_SDK"
if [ -n "${EXL3_ROCM_DEV_INCLUDE:-}" ]; then
export HIPCC_COMPILE_FLAGS_APPEND="$HIPCC_COMPILE_FLAGS_APPEND -I$EXL3_ROCM_DEV_INCLUDE"
fi
export PYTORCH_ROCM_ARCH=gfx1151
export MAX_JOBS="${MAX_JOBS:-6}" # 32 threads exist, but unbounded ninja OOMs the box
echo "[env.sh] BUILD mode: ROCM_HOME=$(basename "$_SDK") arch=$PYTORCH_ROCM_ARCH jobs=$MAX_JOBS"
fi
if [ "${1:-}" = "--check" ]; then
if [ ! -x "$EXL3_VENV/bin/python" ]; then
echo "[env.sh] no venv at $EXL3_VENV. Create it (python3.12 -m venv .venv) or set EXL3_VENV." >&2
exit 1
fi
"$EXL3_VENV/bin/python" - <<'PY'
import sys
import torch
print(f"torch {torch.__version__} hip {torch.version.hip}")
n = torch.cuda.device_count()
if n == 0:
print("no HIP devices visible")
sys.exit(1)
def key_of(p):
# ROCm: gcnArchName ("gfx1151"); CUDA: sm_XY from major/minor.
arch = getattr(p, "gcnArchName", "") or ""
arch = arch.split(":", 1)[0]
return arch or f"sm_{p.major}{p.minor}"
keys = []
for i in range(n):
p = torch.cuda.get_device_properties(i)
keys.append(key_of(p))
warp = getattr(p, "warp_size", None)
extra = f" / warp={warp}" if warp else ""
print(f"[{i}] {p.name} / {keys[-1]}{extra} / "
f"{p.total_memory/2**30:.1f} GiB / {p.multi_processor_count} CUs")
# gfx1151 is the primary target; with an eGPU visible it is not necessarily device 0.
target = keys.index("gfx1151") if "gfx1151" in keys else 0
print(f"checking device [{target}] ({keys[target]})")
a = torch.randn(512, 512, dtype=torch.float16, device=f"cuda:{target}")
(a @ a).sum().item()
torch.cuda.synchronize()
print("GPU compute: OK")
try:
import exllamav3_ext
print("exllamav3_ext: OK")
print(f"exl3_gemv_supported({target}):", exllamav3_ext.exl3_gemv_supported(target))
except ImportError as e:
print("exllamav3_ext: NOT BUILT --", e)
import exllamav3
print("exllamav3:", exllamav3.__version__ if hasattr(exllamav3, "__version__") else "imported")
from exllamav3.util import hip_compiler
hip_compiler.report(print)
PY
fi