Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
doctor --gpus: read NVML P2P enum constants as ints (#14164)
Daniel Han355985f3e99f
diff --git a/unsloth_cli/commands/doctor.py b/unsloth_cli/commands/doctor.pyindex f1eb6d4a0c0..a5a4711410a 100644--- a/unsloth_cli/commands/doctor.py+++ b/unsloth_cli/commands/doctor.py@@ -143,6 +143,18 @@ def driver_version(pynvml = None) -> Optional[str]:return None+def _nvml_int(pynvml, name, default):+ """An NVML enum constant as an int. nvidia-ml-py defines NVML_P2P_CAPS_INDEX_READ = 0, (a+ 1-tuple, stray comma), which ctypes refuses, so every P2P read query would fail."""+ value = getattr(pynvml, name, default)+ if isinstance(value, (tuple, list)):+ value = value[0] if len(value) == 1 else default+ try:+ return int(value)+ except (TypeError, ValueError):+ return default++def nvml_topology(pynvml, gpus: List[dict]):"""({(a, b): {"level": "PHB", "nvlink": bool, "p2p_read": bool}} keyed by torch index, error).@@ -154,9 +166,9 @@ def nvml_topology(pynvml, gpus: List[dict]):return None, "nvidia-ml-py is not installed"if len(gpus) < 2 or any(g["pci"] is None and not g.get("uuid") for g in gpus):return None, "torch reports neither PCI bus ids nor device UUIDs"- read_idx = getattr(pynvml, "NVML_P2P_CAPS_INDEX_READ", 0)- nvlink_idx = getattr(pynvml, "NVML_P2P_CAPS_INDEX_NVLINK", 2)- status_ok = getattr(pynvml, "NVML_P2P_STATUS_OK", 0)+ read_idx = _nvml_int(pynvml, "NVML_P2P_CAPS_INDEX_READ", 0)+ nvlink_idx = _nvml_int(pynvml, "NVML_P2P_CAPS_INDEX_NVLINK", 2)+ status_ok = _nvml_int(pynvml, "NVML_P2P_STATUS_OK", 0)def query(fn, *args):try:diff --git a/unsloth_cli/tests/test_doctor_gpus.py b/unsloth_cli/tests/test_doctor_gpus.pyindex a63159453b8..f360532b8dc 100644--- a/unsloth_cli/tests/test_doctor_gpus.py+++ b/unsloth_cli/tests/test_doctor_gpus.py@@ -128,6 +128,22 @@ def test_nvml_topology_keys_by_torch_index_via_pci_bus():assert nvml.shutdown+def test_nvml_topology_accepts_tuple_p2p_read_constant():+ # nvidia-ml-py ships `NVML_P2P_CAPS_INDEX_READ = 0,` (a tuple); its ctypes call rejects it.+ class TupleConstant(_FakeNvml):+ NVML_P2P_CAPS_INDEX_READ = (0,)++ def nvmlDeviceGetP2PStatus(self, a, b, idx):+ if not isinstance(idx, int):+ raise TypeError("Don't know how to convert parameter 3")+ return super().nvmlDeviceGetP2PStatus(a, b, idx)++ gpus = [_gpu(0, pci = "bus-a"), _gpu(1, pci = "bus-b")]+ topo, err = doctor_mod.nvml_topology(TupleConstant(), gpus)+ assert err is None+ assert topo[(0, 1)] == {"level": "PHB", "nvlink": True, "p2p_read": True}++def test_nvml_topology_absent_without_pynvml_or_pci():topo, err = doctor_mod.nvml_topology(None, [_gpu(0, pci = "a"), _gpu(1, pci = "b")])assert topo is None and "nvidia-ml-py" in err