The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(local-models): use a single GPU identity query
Ryan Hillec2341e4f652
diff --git a/hermes_cli/local_runtime/hardware.py b/hermes_cli/local_runtime/hardware.pyindex 1f96b3fcccd..332c1d54fdd 100644--- a/hermes_cli/local_runtime/hardware.py+++ b/hermes_cli/local_runtime/hardware.py@@ -205,22 +205,18 @@ def _nvidia_vram() -> tuple[int, int, str, int | None] | None:if exe is None:return Nonewith suppress(OSError, ValueError, subprocess.TimeoutExpired):- # Older drivers may reject the identity field; preserve their memory probe.- for fields in ("memory.total,memory.free,name,pci.device_id",- "memory.total,memory.free,name"):- out = subprocess.run(- [exe, f"--query-gpu={fields}", "--format=csv,noheader,nounits"],- capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=10)- if out.returncode != 0:- continue- if not out.stdout.strip():- return None- row = next(csv.reader(out.stdout.strip().splitlines(), skipinitialspace=True))- total_mib, free_mib, name = row[:3]- pci_id = None- with suppress(ValueError): # N/A or unsupported identity must not lose memory data.- pci_id = int(row[3], 16) if len(row) > 3 else None- return int(total_mib) << 20, int(free_mib) << 20, name.strip(), pci_id+ out = subprocess.run(+ [exe, "--query-gpu=memory.total,memory.free,name,pci.device_id",+ "--format=csv,noheader,nounits"],+ capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=10)+ if out.returncode != 0 or not out.stdout.strip():+ return None+ total_mib, free_mib, name, raw_id = next(+ csv.reader(out.stdout.strip().splitlines(), skipinitialspace=True))+ pci_id = None+ with suppress(ValueError): # N/A or unsupported identity must not lose memory data.+ pci_id = int(raw_id, 16)+ return int(total_mib) << 20, int(free_mib) << 20, name.strip(), pci_idreturn Nonediff --git a/tests/hermes_cli/test_local_n1x_pci_identity.py b/tests/hermes_cli/test_local_n1x_pci_identity.pyindex 9336f2b374a..086a076e738 100644--- a/tests/hermes_cli/test_local_n1x_pci_identity.py+++ b/tests/hermes_cli/test_local_n1x_pci_identity.py@@ -68,7 +68,7 @@ def test_pci_identity_controls_recommendations_without_changing_memory(@pytest.mark.parametrize("integrated", [False, True])-def test_unsupported_pci_query_preserves_memory_and_name_fallback(monkeypatch, integrated):+def test_unavailable_pci_id_preserves_memory_and_name_fallback(monkeypatch, integrated):calls = []monkeypatch.setattr(hardware, "_nvidia_smi_path", lambda: "nvidia-smi")monkeypatch.setattr(hardware, "_ram_bytes", lambda: (64 << 30, 22 << 30))@@ -77,10 +77,8 @@ def test_unsupported_pci_query_preserves_memory_and_name_fallback(monkeypatch, idef run(argv, **kwargs):calls.append(argv)- if argv[1].endswith(",pci.device_id"):- return SimpleNamespace(returncode=1, stdout="")- assert argv[1] == "--query-gpu=memory.total,memory.free,name"- return SimpleNamespace(returncode=0, stdout=f"32704, 31423, {name}\n")+ assert argv[1] == "--query-gpu=memory.total,memory.free,name,pci.device_id"+ return SimpleNamespace(returncode=0, stdout=f"32704, 31423, {name}, N/A\n")monkeypatch.setattr(hardware.subprocess, "run", run)budget = hardware.probe_budget(planning=True)@@ -91,4 +89,4 @@ def test_unsupported_pci_query_preserves_memory_and_name_fallback(monkeypatch, iusable = int(total * .8) if integrated else total - max(2 << 30, int(total * .09))assert budget.total_device_bytes == totalassert budget.usable_vram_bytes == usable- assert len(calls) == 2+ assert len(calls) == 1