fix: Strix rocm7.1 segfault bypass + Ubuntu 24.04 HIP gcc-install-dir

Issue 1 (install.sh): gfx1151/gfx1150 + ROCm 7.1 causes a segfault in
torch._grouped_mm (moe_utils.py:167). The Radeon repo now ships cp313
wheels for rocm-rel-7.1, so _amd_gpu_radeon=true silently lands on the
broken combo. When Strix Halo/Point is detected and TORCH_INDEX_URL is
rocm7.1, override to rocm7.2 PyTorch index, update TORCH_CONSTRAINT, and
set _amd_gpu_radeon=false to bypass the Radeon repo entirely. Emits a
clear [WARN] explaining the segfault and linking to the ROCm upgrade docs.

Issue 2 (setup.sh): ROCm 7.x ships clang-20 which on Ubuntu 24.04+ picks
/usr/lib/gcc/x86_64-linux-gnu/14/ (runtime dir, no C++ headers), causing
'cstdlib file not found' and a failed llama.cpp HIP build. Iterate gcc
versions 14→11 to find the first install dir that has both runtime and
/usr/include/c++/<ver> headers, then pass --gcc-install-dir to clang via
CMAKE_HIP_FLAGS. Fix confirmed by h34v3nzc0dex (llama.cpp 417/417 clean).

11 new tests across TestStrixRocm71Override and TestSetupShGccInstallDir;
total 203 passed, 2 skipped
This commit is contained in:
LeoBorcherding 2026-05-16 15:33:54 -05:00
commit bbf004c36b
3 changed files with 144 additions and 0 deletions

View file

@ -1746,6 +1746,36 @@ case "$TORCH_INDEX_URL" in
fi
;;
esac
# ── Strix Halo / Strix Point: force rocm7.2 wheels, bypass Radeon repo ───────
# gfx1151 (Strix Halo) and gfx1150 (Strix Point) have a ROCm 7.1 driver bug
# that causes a segfault in torch._grouped_mm (moe_utils.py line 167).
# The Radeon repo now ships cp313 wheels for rocm-rel-7.1, so when
# _amd_gpu_radeon=true the installer silently lands on the broken combo.
# Detect these GPUs when TORCH_INDEX_URL is rocm7.1 and override to rocm7.2.
case "$TORCH_INDEX_URL" in
*/rocm7.1|*/rocm7.1.*)
_strix_gfx=""
if command -v rocminfo >/dev/null 2>&1; then
_strix_gfx=$(rocminfo 2>/dev/null | grep -oE 'gfx1151|gfx1150' | head -1)
fi
if [ -z "$_strix_gfx" ] && command -v amd-smi >/dev/null 2>&1; then
_strix_gfx=$(amd-smi list 2>/dev/null | grep -oE 'gfx1151|gfx1150' | head -1)
fi
if [ -n "$_strix_gfx" ]; then
echo "" >&2
echo " [WARN] $_strix_gfx (Strix) + ROCm 7.1 detected -- known _grouped_mm segfault" >&2
echo " [WARN] ROCm 7.1 wheels are broken for gfx1150/gfx1151 (moe_utils.py:167)" >&2
echo " [WARN] Overriding to rocm7.2 PyTorch index to avoid the driver bug" >&2
echo " [WARN] Upgrade ROCm to 7.2+ to silence this warning:" >&2
echo " [WARN] https://rocm.docs.amd.com/en/latest/deploy/linux/index.html" >&2
echo "" >&2
_base="${UNSLOTH_PYTORCH_MIRROR:-https://download.pytorch.org/whl}"
TORCH_INDEX_URL="${_base%/}/rocm7.2"
TORCH_CONSTRAINT="torch>=2.11.0,<2.12.0"
_amd_gpu_radeon=false
fi
;;
esac
_TAURI_TORCH_INDEX_FAMILY=$(_tauri_torch_index_family "$TORCH_INDEX_URL")
if [ "$_amd_gpu_radeon" = true ] && [ "$SKIP_TORCH" = false ]; then
_TAURI_TORCH_INDEX_FAMILY="radeon"

View file

@ -1034,6 +1034,27 @@ else
_BUILD_DESC="building (ROCm)"
CMAKE_ARGS="$CMAKE_ARGS -DGGML_HIP=ON"
# ROCm 7.x ships clang-20 which on Ubuntu 24.04+ defaults to the
# highest-numbered gcc lib dir (/usr/lib/gcc/x86_64-linux-gnu/14/)
# which contains runtime objects but NOT C++ headers, causing:
# fatal error: 'cstdlib' file not found
# Find the newest gcc install dir that actually has both the
# runtime dir AND /usr/include/c++/<ver> headers, then pass it
# to clang via --gcc-install-dir so HIP builds succeed.
_GCC_INSTALL_DIR=""
for _gcc_ver in 14 13 12 11; do
if [ -d "/usr/lib/gcc/x86_64-linux-gnu/$_gcc_ver/include" ] && \
[ -d "/usr/include/c++/$_gcc_ver" ]; then
_GCC_INSTALL_DIR="/usr/lib/gcc/x86_64-linux-gnu/$_gcc_ver"
break
fi
done
if [ -n "$_GCC_INSTALL_DIR" ]; then
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_HIP_FLAGS=--gcc-install-dir=$_GCC_INSTALL_DIR"
substep "ROCm HIP gcc install dir: $_GCC_INSTALL_DIR"
fi
export ROCM_PATH="$ROCM_ROOT"
export HIP_PATH="$ROCM_ROOT"

View file

@ -2255,5 +2255,98 @@ class TestHipSdkDetectedSubstep:
assert "ROCmVersionFull" in source and "rocm" in source
# =============================================================================
# TEST: install.sh -- Strix Halo rocm7.1 → rocm7.2 override
# =============================================================================
_INSTALL_SH_PATH = PACKAGE_ROOT / "install.sh"
_SETUP_SH_PATH = PACKAGE_ROOT / "studio" / "setup.sh"
class TestStrixRocm71Override:
"""Verify install.sh skips Radeon repo and forces rocm7.2 for gfx1151/gfx1150
when ROCm 7.1 would otherwise be selected (known _grouped_mm segfault)."""
def test_strix_gfx_detection_in_install_sh(self):
"""install.sh must detect gfx1151 and gfx1150 for the override."""
source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")
assert "gfx1151" in source and "gfx1150" in source
def test_rocm71_override_to_rocm72_in_install_sh(self):
"""install.sh must override TORCH_INDEX_URL from rocm7.1 to rocm7.2 for Strix."""
source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")
# The override must explicitly reference rocm7.2 in context with Strix detection
assert "rocm7.2" in source
assert "_strix_gfx" in source
def test_radeon_repo_bypassed_for_strix_in_install_sh(self):
"""install.sh must set _amd_gpu_radeon=false when Strix + ROCm 7.1 detected."""
source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")
# After Strix detection the Radeon repo flag must be disabled
assert "_amd_gpu_radeon=false" in source
def test_strix_override_warns_with_moe_utils_reference(self):
"""install.sh must emit a [WARN] mentioning the moe_utils segfault."""
source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")
assert "moe_utils" in source or "_grouped_mm" in source
def test_strix_override_only_fires_on_rocm71(self):
"""install.sh must scope the Strix override to rocm7.1 only (not rocm7.2+)."""
source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")
# The Strix guard must be inside a rocm7.1 case branch
strix_idx = source.find("_strix_gfx")
assert strix_idx != -1
# Look back for the rocm7.1 pattern within 600 chars before _strix_gfx
context_before = source[max(0, strix_idx - 600) : strix_idx]
assert "rocm7.1" in context_before
def test_torch_constraint_updated_for_rocm72(self):
"""install.sh must update TORCH_CONSTRAINT to allow torch>=2.11 when forcing rocm7.2."""
source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")
# TORCH_CONSTRAINT must be set inside the Strix override block
assert "TORCH_CONSTRAINT" in source and "2.11" in source
# =============================================================================
# TEST: setup.sh -- gcc-install-dir fix for Ubuntu 24.04 + ROCm 7.x clang-20
# =============================================================================
class TestSetupShGccInstallDir:
"""Verify setup.sh applies the --gcc-install-dir flag when building llama.cpp
with HIP on Ubuntu 24.04+ to work around ROCm 7.x clang-20 header path bug."""
def test_gcc_install_dir_search_loop_present(self):
"""setup.sh must iterate gcc versions 14→11 to find one with C++ headers."""
source = _SETUP_SH_PATH.read_text(encoding = "utf-8")
assert "_GCC_INSTALL_DIR" in source
assert "/usr/lib/gcc/x86_64-linux-gnu" in source
def test_gcc_install_dir_checks_include_dir(self):
"""setup.sh must check that the gcc dir has an 'include' subdirectory."""
source = _SETUP_SH_PATH.read_text(encoding = "utf-8")
assert "include" in source and "_GCC_INSTALL_DIR" in source
def test_gcc_install_dir_appended_to_cmake_hip_flags(self):
"""setup.sh must pass --gcc-install-dir via CMAKE_HIP_FLAGS."""
source = _SETUP_SH_PATH.read_text(encoding = "utf-8")
assert "CMAKE_HIP_FLAGS" in source
assert "gcc-install-dir" in source
def test_gcc_install_dir_only_applied_in_hip_build_block(self):
"""The --gcc-install-dir fix must only apply in the HIP/ROCm build branch."""
source = _SETUP_SH_PATH.read_text(encoding = "utf-8")
# GGML_HIP=ON must appear before gcc-install-dir in the source
hip_idx = source.find("GGML_HIP=ON")
gcc_idx = source.find("gcc-install-dir")
assert hip_idx != -1 and gcc_idx != -1
assert hip_idx < gcc_idx
def test_gcc_install_dir_logs_substep(self):
"""setup.sh must print a substep when the gcc install dir is resolved."""
source = _SETUP_SH_PATH.read_text(encoding = "utf-8")
assert "gcc install dir" in source or "GCC_INSTALL_DIR" in source
if __name__ == "__main__":
pytest.main([__file__, "-v"])