diff --git a/install.sh b/install.sh index 41130f200d..a5767705c8 100755 --- a/install.sh +++ b/install.sh @@ -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" diff --git a/studio/setup.sh b/studio/setup.sh index c5beb7ebd3..0227bfcaf7 100755 --- a/studio/setup.sh +++ b/studio/setup.sh @@ -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++/ 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" diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.py index 0d680b77fd..7116b979de 100644 --- a/tests/studio/install/test_rocm_support.py +++ b/tests/studio/install/test_rocm_support.py @@ -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"])