fix(gpu): canonicalize GPU UUIDs in the module-placement qualification driver

torch reports device UUIDs without the "GPU-" prefix that nvidia-smi,
CUDA_VISIBLE_DEVICES and schedulers use. The driver (#356) compared raw
strings, so on real NVIDIA hardware:

- model workers were masked with the bare UUID, which CUDA does not
  accept ("No CUDA GPUs are available");
- select_uuids rejected nvidia-smi-form --uuids;
- visible_device_records could not join the nvidia-smi inventory, leaving
  pci_bus_id, physical_ordinal and topology empty.

Add normalize_uuid (bare or GPU- prefixed, case-insensitive, to
GPU-<lowercase>; MIG identifiers left distinct) and use it at discovery,
selection, inventory join, worker UUID checks and evidence validation.
Found on an A100 run of module-placement-gpu at 7fee696.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Joseph MaglyandClaude Opus 5.5 committed 2026-10-22 08:20:10 -04:00
1 parent 7fee696874
commit 260674a9fa
5 files changed
+217 -19

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ explicit maps must also keep them together.
Select UUIDs with `--uuids GPU-... GPU-...`. A disposable discovery worker
resolves the current visible CUDA ordinals before masking model workers by UUID.
Both bare and `GPU-` UUID forms are accepted case-insensitively and canonicalized to `GPU-<lowercase uuid>`.
Selections must be distinct and within that visible allocation; an existing
scheduler mask is never expanded. Evidence records the original visible ordinal,
selected worker ordinal, physical inventory ordinal, UUID, PCI bus ID, compute
+25 -8
View File
@@ -92,13 +92,28 @@ def smi_diagnostics(run=subprocess.run) -> dict:
return result
def normalize_uuid(value: str | None) -> str:
"""Canonicalize bare/prefixed GPU UUIDs; leave MIG identifiers distinct and unchanged."""
if not isinstance(value, str) or not value.strip():
raise ValueError("every requested GPU needs a resolved UUID")
value = value.strip()
if value.lower().startswith("mig-"):
return value
if value.lower().startswith("gpu-"):
value = value[4:]
if not value:
raise ValueError("every requested GPU needs a resolved UUID")
return "GPU-" + value.lower()
def visible_device_records(properties: list[dict], diagnostics: dict) -> list[dict]:
by_uuid = {item["uuid"].lower(): item for item in diagnostics["inventory"]}
by_uuid = {normalize_uuid(item["uuid"]): item for item in diagnostics["inventory"]}
result = []
for ordinal, properties_record in enumerate(properties):
uuid = properties_record.get("uuid")
physical = by_uuid.get(str(uuid).lower(), {})
result.append({**physical, **properties_record, "visible_ordinal": ordinal,
uuid = normalize_uuid(uuid) if uuid else None
physical = by_uuid.get(uuid, {})
result.append({**physical, **properties_record, "uuid": uuid, "visible_ordinal": ordinal,
"physical_ordinal": physical.get("physical_ordinal"),
"pci_bus_id": physical.get("pci_bus_id")})
return result
@@ -118,10 +133,11 @@ def topology_links(devices: list[dict], topology: dict) -> list[dict]:
def select_uuids(visible: list[dict], count: int, requested: list[str] | None = None) -> list[str]:
if count < 1 or len(visible) < count:
raise ValueError(f"required {count} visible GPUs; discovered {len(visible)}")
available = [item.get("uuid") for item in visible]
available = [normalize_uuid(item["uuid"]) if item.get("uuid") else None for item in visible]
selected = requested if requested is not None else available[:count]
if len(selected) != count or any(not value for value in selected):
raise ValueError("every requested GPU needs a resolved UUID")
selected = [normalize_uuid(value) for value in selected]
if len(set(selected)) != count:
raise ValueError("requested GPUs must have distinct UUIDs")
if not set(selected).issubset(available):
@@ -298,11 +314,11 @@ def validate_evidence(payload: dict) -> None:
raise ValueError("selected reference did not pass")
requested = payload["configuration"].get("requested_devices", [])
if requested:
selected = payload.get("granted_uuids", [])
selected = [normalize_uuid(value) for value in payload.get("granted_uuids", [])]
mapping = payload.get("device_mapping", [])
if (len(selected) != len(requested) or any(not isinstance(value, str) or not value for value in selected)
if (len(selected) != len(requested)
or len(set(selected)) != len(selected)
or [record.get("uuid") for record in mapping] != selected
or [normalize_uuid(record.get("uuid")) for record in mapping] != selected
or [record.get("visible_ordinal") for record in mapping] != list(range(len(requested)))):
raise ValueError("evidence lacks the granted UUID/ordinal mapping")
if "topology_links" not in payload:
@@ -322,7 +338,8 @@ def validate_evidence(payload: dict) -> None:
raise ValueError("required worker did not pass")
if type(worker.get("pid")) is not int or worker["pid"] <= 0:
raise ValueError("worker PID is missing or invalid")
if requested and [record.get("uuid") for record in worker.get("hardware", {}).get("devices", [])] != selected:
if requested and [normalize_uuid(record.get("uuid"))
for record in worker.get("hardware", {}).get("devices", [])] != selected:
raise ValueError("worker UUIDs differ from the granted allocation")
for phase in required:
metrics = worker.get("phases", {}).get(phase, {})
+5 -5
View File
@@ -14,7 +14,7 @@ from contextlib import contextmanager
from pathlib import Path
from obliteratus.qualification import (
canonical_json, enforce_occupancy, file_inventory, plan_modules,
canonical_json, enforce_occupancy, file_inventory, normalize_uuid, plan_modules,
smi_diagnostics, topology_links, validate_plan, visible_device_records,
)
@@ -44,8 +44,8 @@ def discover() -> dict:
uuid = getattr(prop, "uuid", None)
if isinstance(uuid, bytes):
import uuid as uuid_module
uuid = "GPU-" + str(uuid_module.UUID(bytes=uuid))
properties.append(dict(uuid=str(uuid) if uuid else None, name=prop.name,
uuid = str(uuid_module.UUID(bytes=uuid))
properties.append(dict(uuid=normalize_uuid(str(uuid)) if uuid else None, name=prop.name,
total_bytes=prop.total_memory,
compute_capability=list(torch.cuda.get_device_capability(ordinal))))
devices = visible_device_records(properties, diagnostics)
@@ -575,8 +575,8 @@ def worker(directory: Path, role: str) -> int:
torch.manual_seed(configuration["seed"])
if role in {"edit", "reload"} and configuration["mode"] == "hardware":
result["hardware"] = discover()
actual = [item["uuid"] for item in result["hardware"]["devices"]]
if actual != configuration["granted_uuids"]:
actual = [normalize_uuid(item["uuid"]) for item in result["hardware"]["devices"]]
if actual != [normalize_uuid(value) for value in configuration["granted_uuids"]]:
raise ValueError("worker visible UUIDs differ from the selected allocation")
if configuration["dtype"] == "bfloat16":
for ordinal in range(len(actual)):
+3 -3
View File
@@ -19,7 +19,7 @@ REPOSITORY = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPOSITORY))
from obliteratus.qualification import ( # noqa: E402
canonical_json, digest_file, file_inventory, select_uuids, write_evidence,
canonical_json, digest_file, file_inventory, normalize_uuid, select_uuids, write_evidence,
)
@@ -199,8 +199,8 @@ def supervise(args) -> int:
config["granted_uuids"] = selected
environment["CUDA_VISIBLE_DEVICES"] = ",".join(selected)
from obliteratus.qualification import topology_links
by_uuid = {item["uuid"]: item for item in discovery["devices"]}
payload["device_mapping"] = [dict(by_uuid[value], visible_ordinal=index,
by_uuid = {normalize_uuid(item["uuid"]): item for item in discovery["devices"] if item.get("uuid")}
payload["device_mapping"] = [dict(by_uuid[value], uuid=value, visible_ordinal=index,
allocation_visible_ordinal=by_uuid[value]["visible_ordinal"])
for index, value in enumerate(selected)]
payload["topology_links"] = topology_links(payload["device_mapping"], discovery["diagnostics"]["topology"])
+183 -3
View File
@@ -5,14 +5,18 @@ import copy
import errno
import hashlib
import json
import logging
import stat
import subprocess
import sys
import uuid
from types import SimpleNamespace
from unittest.mock import Mock, call
import pytest
from obliteratus import qualification as qualification
from obliteratus import qualification_runtime as runtime
from obliteratus.capacity_planning import PHASES as CAPACITY_PHASES
from scripts import gpu_qualification as driver
@@ -27,13 +31,39 @@ Legend:
"""
FIRST_UUID = "3538758b-6ba7-fa1b-a80c-e315a606c3f0"
SECOND_UUID = "9e1069b2-f073-4ab7-8066-37a04bf9e112"
@pytest.mark.parametrize("value", [FIRST_UUID, "GPU-" + FIRST_UUID, FIRST_UUID.upper(),
"GPU-" + FIRST_UUID.upper(), "gpu-" + FIRST_UUID.upper()])
def test_uuid_normalization_accepts_bare_prefixed_and_uppercase(value):
assert qualification.normalize_uuid(value) == "GPU-" + FIRST_UUID
@pytest.mark.parametrize("value", ["MIG-" + FIRST_UUID, "MIG-GPU-" + FIRST_UUID + "/1/2",
"mig-" + FIRST_UUID.upper()])
def test_uuid_normalization_keeps_mig_identifiers_distinct(value):
assert qualification.normalize_uuid(value) == value
assert qualification.normalize_uuid(value) != "GPU-" + FIRST_UUID
with pytest.raises(ValueError, match="outside the current visible allocation"):
qualification.select_uuids([{"uuid": FIRST_UUID}], 1, [value])
@pytest.mark.parametrize("value", [None, "", " ", "GPU-", "gpu-"])
def test_uuid_normalization_rejects_unresolved_identifiers(value):
with pytest.raises(ValueError, match="resolved UUID"):
qualification.normalize_uuid(value)
def test_topology_preserves_nvlink_and_pcie_paths_with_visible_reordering():
raw = ('0, GPU-first, 00000000:01:00.0, Example GPU, 580.10, 81920, 40960\n'
'2, GPU-second, 00000000:81:00.0, Example GPU, 580.10, 81920, 1024\n')
raw = (f'0, GPU-{FIRST_UUID}, 00000000:01:00.0, Example GPU, 580.10, 81920, 40960\n'
f'2, GPU-{SECOND_UUID}, 00000000:81:00.0, Example GPU, 580.10, 81920, 1024\n')
diagnostics = {"inventory": qualification.parse_gpu_inventory(raw),
"topology": qualification.parse_topology(TOPOLOGY)}
records = qualification.visible_device_records(
[{"uuid": "GPU-second"}, {"uuid": "GPU-first"}], diagnostics)
[{"uuid": SECOND_UUID.upper()}, {"uuid": FIRST_UUID}], diagnostics)
assert [item["uuid"] for item in records] == ["GPU-" + SECOND_UUID, "GPU-" + FIRST_UUID]
assert [item["physical_ordinal"] for item in records] == [2, 0]
assert records[0]["pci_bus_id"] == "00000000:81:00.0"
assert qualification.topology_links(records, diagnostics["topology"]) == [
@@ -76,6 +106,66 @@ def test_uuid_selection_is_ordered_distinct_and_cannot_expand_visibility():
qualification.select_uuids([{"uuid": None}], 1)
@pytest.mark.parametrize("visible_prefix,requested_prefix", [("", "GPU-"), ("GPU-", "")])
def test_uuid_selection_compares_forms_canonically_without_expanding(visible_prefix, requested_prefix):
visible = [{"uuid": visible_prefix + value} for value in (FIRST_UUID, SECOND_UUID)]
requested = [requested_prefix + value.upper() for value in (SECOND_UUID, FIRST_UUID)]
assert qualification.select_uuids(visible, 2, requested) == ["GPU-" + SECOND_UUID, "GPU-" + FIRST_UUID]
assert qualification.select_uuids(visible, 1) == ["GPU-" + FIRST_UUID]
with pytest.raises(ValueError, match="distinct UUIDs"):
qualification.select_uuids(visible, 2, [FIRST_UUID, "GPU-" + FIRST_UUID.upper()])
with pytest.raises(ValueError, match="outside the current visible allocation"):
qualification.select_uuids(visible[:1], 1, [requested_prefix + SECOND_UUID])
@pytest.mark.parametrize("torch_uuid", [FIRST_UUID, "GPU-" + FIRST_UUID,
FIRST_UUID.upper(), uuid.UUID(FIRST_UUID).bytes])
def test_discovery_records_canonical_uuids_from_torch_properties(monkeypatch, torch_uuid):
cuda = SimpleNamespace(device_count=lambda: 1,
get_device_properties=lambda ordinal: SimpleNamespace(
uuid=torch_uuid, name="Example GPU", total_memory=81920 * 1024**2),
get_device_capability=lambda ordinal: (8, 0))
monkeypatch.setitem(sys.modules, "torch", SimpleNamespace(cuda=cuda))
monkeypatch.setattr(runtime, "runtime_identity", lambda: {"torch": "mock"})
inventory = [{"uuid": "GPU-" + FIRST_UUID, "physical_ordinal": 2,
"pci_bus_id": "00000000:81:00.0"}]
monkeypatch.setattr(runtime, "smi_diagnostics", lambda: {"inventory": inventory, "topology": {}})
result = runtime.discover()
assert result["devices"][0]["uuid"] == "GPU-" + FIRST_UUID
assert result["devices"][0]["physical_ordinal"] == 2
assert result["devices"][0]["pci_bus_id"] == "00000000:81:00.0"
@pytest.mark.parametrize("role", ["edit", "reload"])
@pytest.mark.parametrize("actual,passed", [([FIRST_UUID.upper(), SECOND_UUID], True),
(["gpu-" + FIRST_UUID, "GPU-" + SECOND_UUID], True),
([SECOND_UUID, FIRST_UUID], False),
([FIRST_UUID, "outside"], False)])
def test_worker_uuid_order_check_accepts_forms_but_rejects_reordering_and_expansion(
tmp_path, monkeypatch, role, actual, passed):
configuration = {"mode": "hardware", "dtype": "float32", "seed": 17,
"admission_mode": "strict", "device_memory_ceilings": {},
"granted_uuids": ["GPU-" + FIRST_UUID, "GPU-" + SECOND_UUID]}
(tmp_path / "configuration.json").write_text(json.dumps(configuration))
monkeypatch.setenv("OBLITERATUS_PHASE_ADMISSION", "strict")
monkeypatch.setenv("OBLITERATUS_DEVICE_MEMORY_CEILINGS", "{}")
logger = logging.getLogger("obliteratus.phase_admission")
monkeypatch.setattr(logger, "handlers", [])
monkeypatch.setattr(logger, "level", logging.DEBUG)
monkeypatch.setitem(sys.modules, "torch", SimpleNamespace(set_num_threads=Mock(), manual_seed=Mock()))
monkeypatch.setattr(runtime, "discover", lambda: {"devices": [{"uuid": value} for value in actual]})
lifecycle, reload = Mock(), Mock()
monkeypatch.setattr(runtime, "lifecycle", lifecycle)
monkeypatch.setattr(runtime, "reload_and_verify", reload)
assert runtime.worker(tmp_path, role) == (0 if passed else 1)
report = json.loads((tmp_path / f"{role}.json").read_text())
assert report["status"] == ("passed" if passed else "failed")
assert lifecycle.call_count == int(passed and role == "edit")
assert reload.call_count == int(passed and role == "reload")
if not passed:
assert "worker visible UUIDs differ" in report["error"]
def placement_fixture(count=6):
blocks = [f"model.layers.{index}" for index in range(count)]
sizes = {f"{block}.{projection}.weight": 32 for block in blocks for projection in ("q", "o")}
@@ -236,6 +326,26 @@ def test_success_evidence_requires_identity_and_reference_decision(field):
qualification.validate_evidence(payload)
def test_evidence_uuid_checks_compare_bare_and_prefixed_forms_canonically():
payload = evidence_fixture()
payload["granted_uuids"] = [FIRST_UUID.upper()]
payload["device_mapping"][0]["uuid"] = "gpu-" + FIRST_UUID.upper()
for role in ("edit", "reload"):
payload["workers"][role]["hardware"] = {"devices": [{"uuid": FIRST_UUID}]}
qualification.validate_evidence(payload)
@pytest.mark.parametrize("location", ["mapping", "edit", "reload"])
def test_evidence_uuid_checks_still_reject_outside_devices(location):
payload = evidence_fixture()
if location == "mapping":
payload["device_mapping"][0]["uuid"] = "GPU-outside"
else:
payload["workers"][location]["hardware"] = {"devices": [{"uuid": "outside"}]}
with pytest.raises(ValueError, match="UUID"):
qualification.validate_evidence(payload)
def test_digest_tampering_and_reference_omission_fail(tmp_path):
payload = evidence_fixture()
payload["reference_policy"]["selected"] = "cpu"
@@ -442,6 +552,76 @@ def test_missing_hardware_worker_failure_creates_failed_evidence(tmp_path, monke
driver.supervise(args)
@pytest.mark.parametrize("count", [1, 2])
@pytest.mark.parametrize("request_form", [None, "bare", "prefixed"])
def test_supervisor_masks_model_workers_with_canonical_uuids_from_bare_discovery(
tmp_path, monkeypatch, count, request_form):
output = tmp_path / "attempt"
visible = [FIRST_UUID, SECOND_UUID]
selected = (list(reversed(visible)) if request_form else visible)[:count]
canonical = ["GPU-" + value for value in selected]
arguments = ["--output", str(output), "--devices", str(count), "--reference", "none"]
if request_form:
prefix = "GPU-" if request_form == "prefixed" else ""
arguments += ["--uuids", *(prefix + value.upper() for value in selected)]
args = driver.parser().parse_args(arguments)
allocation_mask = ",".join("GPU-" + value for value in visible)
monkeypatch.setenv("CUDA_VISIBLE_DEVICES", allocation_mask)
prepared = evidence_fixture()
capacity = capacity_fixture()
capacity["reference_policy"] = {"selected": "none", "reason": "explicit operator choice"}
devices = [f"cuda:{index}" for index in range(count)]
capacity["device_map"] = {f"model.layers.{index}": device for index, device in enumerate(devices)}
for rows in capacity["phases"].values():
for device in devices:
rows[device] = copy.deepcopy(rows["cuda:0"])
prepared["workers"]["prepare"]["capacity_plan"] = capacity
for role in ("edit", "reload"):
report = prepared["workers"][role]
report["hardware"] = {"devices": [{"uuid": value} for value in canonical]}
report["occupancy"]["modules"] = {device: {f"model.layers.{index}": 128}
for index, device in enumerate(devices)}
for metric in report["phases"].values():
metric["gpu"] = {device: copy.deepcopy(metric["gpu"]["cuda:0"]) for device in devices}
roles = []
def execute(directory, role, environment, timeout):
roles.append(role)
if role == "discover":
assert environment["CUDA_VISIBLE_DEVICES"] == allocation_mask
return {"status": "passed", "devices": [
{"uuid": value, "visible_ordinal": index, "physical_ordinal": index * 2}
for index, value in enumerate(visible)],
"diagnostics": {"topology": qualification.parse_topology(TOPOLOGY), "errors": []}}
assert environment["CUDA_VISIBLE_DEVICES"] == ",".join(canonical)
config = json.loads((directory / "configuration.json").read_text())
assert config["granted_uuids"] == canonical
if role == "prepare":
source = directory / "source"
source.mkdir()
(source / "config.json").write_text("{}")
else:
assert config["capacity_plan"] == capacity
report = copy.deepcopy(prepared["workers"][role])
if role == "edit":
exported = directory / "edit-export"
exported.mkdir()
(exported / "config.json").write_text("{}")
report["export"] = qualification.file_inventory(exported)
return report
monkeypatch.setattr(driver, "run_worker", execute)
monkeypatch.setattr(driver, "repository_identity", lambda: prepared["identity"])
assert driver.supervise(args) == 0
assert roles == ["discover", "prepare", "edit", "reload"]
evidence = qualification.read_evidence(next(output.glob("evidence-*.json")))
assert evidence["granted_uuids"] == canonical
assert [record["uuid"] for record in evidence["device_mapping"]] == canonical
assert [record["visible_ordinal"] for record in evidence["device_mapping"]] == list(range(count))
assert [record["allocation_visible_ordinal"] for record in evidence["device_mapping"]] == [
visible.index(value) for value in selected]
@pytest.mark.parametrize("reference", ["none", "cpu", "auto"])
def test_supervisor_freezes_prepared_capacity_before_edit_and_reload(tmp_path, monkeypatch, reference):
from safetensors import torch as safetensors_torch