[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
134638dd0e
commit
4dc1dcaaec
3 changed files with 32 additions and 12 deletions
|
|
@ -48,12 +48,14 @@ def _parse_numeric(value: Any) -> Optional[float]:
|
|||
return _parse_numeric(value.get("value"))
|
||||
if isinstance(value, (int, float)):
|
||||
import math
|
||||
|
||||
f = float(value)
|
||||
return f if math.isfinite(f) else None
|
||||
if isinstance(value, str):
|
||||
# Strip units like "W", "C", "%", "MB", "MiB", "GB", "GiB" etc.
|
||||
import re
|
||||
cleaned = re.sub(r'\s*[A-Za-z/%]+$', '', value.strip())
|
||||
|
||||
cleaned = re.sub(r"\s*[A-Za-z/%]+$", "", value.strip())
|
||||
if not cleaned or cleaned.lower() in ("n/a", "none", "unknown"):
|
||||
return None
|
||||
try:
|
||||
|
|
@ -219,14 +221,22 @@ def get_visible_gpu_utilization(
|
|||
"index_kind": "physical",
|
||||
}
|
||||
|
||||
gpu_list = data if isinstance(data, list) else data.get("gpus", data.get("gpu", [data]))
|
||||
gpu_list = (
|
||||
data if isinstance(data, list) else data.get("gpus", data.get("gpu", [data]))
|
||||
)
|
||||
visible_set = set(parent_visible_ids)
|
||||
ordinal_map = {gpu_id: ordinal for ordinal, gpu_id in enumerate(parent_visible_ids)}
|
||||
|
||||
devices = []
|
||||
for fallback_idx, gpu_data in enumerate(gpu_list):
|
||||
# Use AMD-reported GPU ID when available, fall back to enumeration index
|
||||
raw_id = gpu_data.get("gpu", gpu_data.get("gpu_id", gpu_data.get("id", fallback_idx))) if isinstance(gpu_data, dict) else fallback_idx
|
||||
raw_id = (
|
||||
gpu_data.get(
|
||||
"gpu", gpu_data.get("gpu_id", gpu_data.get("id", fallback_idx))
|
||||
)
|
||||
if isinstance(gpu_data, dict)
|
||||
else fallback_idx
|
||||
)
|
||||
try:
|
||||
idx = int(raw_id)
|
||||
except (TypeError, ValueError):
|
||||
|
|
|
|||
|
|
@ -117,10 +117,10 @@ def _has_usable_nvidia_gpu() -> bool:
|
|||
try:
|
||||
result = subprocess.run(
|
||||
[exe, "-L"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True,
|
||||
timeout=10,
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = subprocess.DEVNULL,
|
||||
text = True,
|
||||
timeout = 10,
|
||||
)
|
||||
except Exception:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -533,7 +533,9 @@ class TestEnsureRocmTorch:
|
|||
@patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)
|
||||
@patch.object(stack_mod, "_has_rocm_gpu", return_value = True)
|
||||
@patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))
|
||||
def test_torch_already_has_cuda_skips(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):
|
||||
def test_torch_already_has_cuda_skips(
|
||||
self, mock_ver, mock_gpu, mock_nvidia, mock_pip
|
||||
):
|
||||
"""If torch already has CUDA, should skip ROCm reinstall."""
|
||||
mock_probe = MagicMock()
|
||||
mock_probe.returncode = 0
|
||||
|
|
@ -547,7 +549,9 @@ class TestEnsureRocmTorch:
|
|||
@patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)
|
||||
@patch.object(stack_mod, "_has_rocm_gpu", return_value = True)
|
||||
@patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))
|
||||
def test_torch_already_has_hip_skips(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):
|
||||
def test_torch_already_has_hip_skips(
|
||||
self, mock_ver, mock_gpu, mock_nvidia, mock_pip
|
||||
):
|
||||
"""If torch already has HIP, should skip ROCm reinstall."""
|
||||
mock_probe = MagicMock()
|
||||
mock_probe.returncode = 0
|
||||
|
|
@ -561,7 +565,9 @@ class TestEnsureRocmTorch:
|
|||
@patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)
|
||||
@patch.object(stack_mod, "_has_rocm_gpu", return_value = True)
|
||||
@patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))
|
||||
def test_cpu_torch_gets_rocm_reinstall(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):
|
||||
def test_cpu_torch_gets_rocm_reinstall(
|
||||
self, mock_ver, mock_gpu, mock_nvidia, mock_pip
|
||||
):
|
||||
"""CPU-only torch on ROCm host should trigger reinstall."""
|
||||
mock_probe = MagicMock()
|
||||
mock_probe.returncode = 0
|
||||
|
|
@ -580,7 +586,9 @@ class TestEnsureRocmTorch:
|
|||
@patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)
|
||||
@patch.object(stack_mod, "_has_rocm_gpu", return_value = True)
|
||||
@patch.object(stack_mod, "_detect_rocm_version", return_value = (6, 3))
|
||||
def test_rocm_63_selects_correct_tag(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):
|
||||
def test_rocm_63_selects_correct_tag(
|
||||
self, mock_ver, mock_gpu, mock_nvidia, mock_pip
|
||||
):
|
||||
"""ROCm 6.3 should select rocm6.3 tag."""
|
||||
mock_probe = MagicMock()
|
||||
mock_probe.returncode = 0
|
||||
|
|
@ -638,7 +646,9 @@ class TestEnsureRocmTorch:
|
|||
@patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)
|
||||
@patch.object(stack_mod, "_has_rocm_gpu", return_value = True)
|
||||
@patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))
|
||||
def test_probe_timeout_triggers_reinstall(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):
|
||||
def test_probe_timeout_triggers_reinstall(
|
||||
self, mock_ver, mock_gpu, mock_nvidia, mock_pip
|
||||
):
|
||||
"""Probe subprocess timeout should not crash; should proceed to reinstall."""
|
||||
with patch("os.path.isdir", return_value = True):
|
||||
with patch(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue