Fix HIP_VISIBLE_DEVICES empty-string handling in GPU visibility spec

Use explicit None checks instead of Python `or` operator when reading
HIP_VISIBLE_DEVICES / ROCR_VISIBLE_DEVICES, so that an empty string
("") is correctly honored as "no visible GPUs" rather than silently
falling through to CUDA_VISIBLE_DEVICES on mixed ROCm+CUDA systems.
This commit is contained in:
Daniel Han 2026-03-31 11:58:03 +00:00
commit 2d55e770f0

View file

@ -572,11 +572,16 @@ def _get_parent_visible_gpu_spec() -> Dict[str, Any]:
# ROCm uses HIP_VISIBLE_DEVICES / ROCR_VISIBLE_DEVICES in addition to
# CUDA_VISIBLE_DEVICES (which HIP also respects). Check ROCm-specific
# env vars first so multi-GPU AMD setups are handled correctly.
# Use explicit None checks (not `or`) so empty string "" is honoured
# as "no visible GPUs" rather than falling through to CUDA_VISIBLE_DEVICES.
cuda_visible = None
if IS_ROCM:
cuda_visible = os.environ.get("HIP_VISIBLE_DEVICES") or os.environ.get(
"ROCR_VISIBLE_DEVICES"
)
hip_vis = os.environ.get("HIP_VISIBLE_DEVICES")
rocr_vis = os.environ.get("ROCR_VISIBLE_DEVICES")
if hip_vis is not None:
cuda_visible = hip_vis
elif rocr_vis is not None:
cuda_visible = rocr_vis
if cuda_visible is None:
cuda_visible = os.environ.get("CUDA_VISIBLE_DEVICES")