fix(win32): scope ROCm workarounds to AMD hosts only

Three Codex-flagged issues where Windows ROCm workarounds incorrectly
applied to Windows CUDA (NVIDIA) machines:

main.py (P1): BNB_ROCM_VERSION was set unconditionally on all win32
hosts. On NVIDIA, bitsandbytes sees BNB_ROCM_VERSION and looks for a
ROCm DLL that doesn't exist, breaking bitsandbytes initialisation.
Fix: gate the block on HIP_PATH/ROCM_PATH being present (ROCm hosts only).

worker.py (P2): torchao stubs were seeded for all win32 runs, shadowing
real torchao on Windows CUDA and silently disabling torchao quantization
for NVIDIA users. Fix: gate on HIP_PATH/ROCM_PATH (win32 ROCm only).

install_python_stack.py (P1): _detect_windows_gfx_arch() only checked
shutil.which("hipinfo"), skipping the HIP_PATH/ROCM_PATH fallback that
the PowerShell installers use. On installs where the HIP SDK bin dir is
not on PATH, _ensure_rocm_torch() returned early without installing
ROCm wheels or bitsandbytes. Fix: mirror the env-var fallback.
This commit is contained in:
LeoBorcherding 2026-05-16 17:08:57 -05:00
commit 4e75d42e4a
3 changed files with 27 additions and 3 deletions

View file

@ -1248,7 +1248,13 @@ def run_training_process(
sys.meta_path.append(_StubSubpackageFinder())
if sys.platform == "win32":
# Only stub torchao on Windows ROCm hosts -- on Windows CUDA (NVIDIA) torchao
# is real and shadowing it breaks torchao-based quantization paths.
# HIP_PATH / ROCM_PATH are set by the AMD HIP SDK installer on ROCm machines.
_is_win32_rocm = sys.platform == "win32" and bool(
os.environ.get("HIP_PATH") or os.environ.get("ROCM_PATH")
)
if _is_win32_rocm:
# Seed torchao top-level + key submodules; the finder handles the rest.
for _tao_name in (
"torchao",

View file

@ -54,7 +54,11 @@ if sys.platform == "win32":
# this the server process crashes with "Configured ROCm binary not found".
# Detect the available DLL, fall back to "72", and set BNB_ROCM_VERSION
# before any import that pulls in bitsandbytes (mirrors worker.py logic).
if "BNB_ROCM_VERSION" not in os.environ:
# Guard: only set on ROCm hosts (HIP_PATH/ROCM_PATH present) -- setting
# BNB_ROCM_VERSION on a Windows CUDA machine makes bitsandbytes look for a
# ROCm DLL that doesn't exist and fail to initialise the CUDA backend.
_is_rocm_host = bool(os.environ.get("HIP_PATH") or os.environ.get("ROCM_PATH"))
if _is_rocm_host and "BNB_ROCM_VERSION" not in os.environ:
import glob as _glob
_bnb_rocm_ver = None

View file

@ -228,10 +228,24 @@ def _detect_rocm_version() -> tuple[int, int] | None:
def _detect_windows_gfx_arch() -> str | None:
"""Return the gcnArchName from hipinfo on Windows (e.g. 'gfx1200'), or None."""
"""Return the gcnArchName from hipinfo on Windows (e.g. 'gfx1200'), or None.
Resolves hipinfo via PATH first, then HIP_PATH\\bin and ROCM_PATH\\bin as
fallbacks -- the AMD HIP SDK installer sets these env vars but does not
always add the bin dir to the system PATH.
"""
import re
hipinfo = shutil.which("hipinfo")
if not hipinfo:
# Fallback: AMD HIP SDK sets HIP_PATH / ROCM_PATH even when bin isn't on PATH
for _env_var in ("HIP_PATH", "ROCM_PATH"):
_root = os.environ.get(_env_var)
if _root:
_candidate = os.path.join(_root, "bin", "hipinfo.exe")
if os.path.isfile(_candidate):
hipinfo = _candidate
break
if not hipinfo:
return None
try: