The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(local-models): identify N1X by PCI vendor/device ID
Ryan Hilldd2a04760734
diff --git a/hermes_cli/local_runtime/catalog.py b/hermes_cli/local_runtime/catalog.pyindex 09dd85a5ae6..b4594f5e261 100644--- a/hermes_cli/local_runtime/catalog.py+++ b/hermes_cli/local_runtime/catalog.py@@ -20,6 +20,7 @@ from hermes_cli.local_runtime.context_policy import (FLOOR, RUNTIME_OVERHEAD_BYTES, TARGET_WINDOW, LaunchPlan, plan_launch)from hermes_cli.local_runtime.estimator import HardwareBudget, LayerKind, ModelProfile, PhysicsRefusalfrom hermes_cli.local_runtime.gguf import model_id_from_stem+from hermes_platform.host.products import is_nvidia_n1x_pci_idlogger = logging.getLogger(__name__)@@ -181,7 +182,7 @@ PLEASANT_FLOOR_TOK_S = 20.0# 18.82 tok/s: this is a baseline estimate, not a context-independent guarantee.# Unmatched hardware, backend, quant or draft depth retains the bandwidth estimate._MEASURED_DECODE_TOK_S = {- ("win32", "cuda", "NVIDIA RTX Spark N1X",+ ("win32", "cuda", "n1x","qwen3.8-27b", "UD-Q4_K_M", 2): 21.9,}@@ -189,11 +190,16 @@ _MEASURED_DECODE_TOK_S = {def predicted_decode_tok_s(entry: CatalogEntry, variant: QuantVariant, budget: HardwareBudget, *,spilled: bool = False, backend: str = "auto") -> float:"""Shipped measured baseline where matched, otherwise the memory-bound estimate."""- # A named NVIDIA device uses CUDA under the normal automatic backend policy.- effective_backend = "cuda" if backend == "auto" and budget.gpu_name else backend- # Drivers may append a parenthesized description to the stable device name.- gpu_name = budget.gpu_name.partition(" (")[0]- key = (budget.platform, effective_backend, gpu_name, entry.id, variant.quant, entry.mtp_draft_depth)+ # PCI identity is authoritative. Names are only a fallback for unavailable IDs.+ if budget.gpu_pci_id is not None:+ nvidia = budget.gpu_pci_id[0] == 0x10DE+ n1x = is_nvidia_n1x_pci_id(budget.gpu_pci_id)+ else:+ nvidia = bool(budget.gpu_name)+ n1x = budget.gpu_name.partition(" (")[0] == "NVIDIA RTX Spark N1X"+ effective_backend = "cuda" if backend == "auto" and nvidia else backend+ family = "n1x" if n1x else ""+ key = (budget.platform, effective_backend, family, entry.id, variant.quant, entry.mtp_draft_depth)if budget.uma and entry.mtp and not spilled and (measured := _MEASURED_DECODE_TOK_S.get(key)) is not None:return measuredbandwidth = (_HOST_BANDWIDTH_GB_S if spilleddiff --git a/hermes_cli/local_runtime/estimator.py b/hermes_cli/local_runtime/estimator.pyindex 867c18c3af6..0f322ef6ad9 100644--- a/hermes_cli/local_runtime/estimator.py+++ b/hermes_cli/local_runtime/estimator.py@@ -89,8 +89,9 @@ class HardwareBudget:total_device_bytes: intram_available_bytes: intuma: bool = False- gpu_name: str = "" # detected identity for shipped performance estimates+ gpu_name: str = "" # display name; legacy fallback for performance estimatesplatform: str = "" # sys.platform of the machine being priced+ gpu_pci_id: tuple[int, int] | None = None # (vendor, device); None when unavailabledef profile_from_gguf(header: GGUFHeader) -> ModelProfile:diff --git a/hermes_cli/local_runtime/hardware.py b/hermes_cli/local_runtime/hardware.pyindex a3b09e5bc0f..1805d69609d 100644--- a/hermes_cli/local_runtime/hardware.py+++ b/hermes_cli/local_runtime/hardware.py@@ -199,20 +199,31 @@ def _nvidia_smi_path() -> str | None:return found-def _nvidia_vram() -> tuple[int, int, str] | None:- """(total bytes, free bytes, name) from the same nvidia-smi query, or None."""+def _nvidia_vram() -> tuple[int, int, str, tuple[int, int] | None] | None:+ """Memory, name and optional (vendor, device) from the same GPU row."""exe = _nvidia_smi_path()if exe is None:return Nonewith suppress(OSError, ValueError, subprocess.TimeoutExpired):- out = subprocess.run(- [exe, "--query-gpu=memory.total,memory.free,name",- "--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 = next(csv.reader(out.stdout.strip().splitlines()))- return int(total_mib) << 20, int(free_mib) << 20, name.strip()+ # 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]+ raw_id = row[3].strip() if len(row) == 4 else ""+ pci_id = None+ if re.fullmatch(r"(?:0[xX])?[0-9a-fA-F]{8}", raw_id):+ # NVML packs device in the high 16 bits and vendor in the low 16.+ packed = int(raw_id, 16)+ pci_id = (packed & 0xFFFF, packed >> 16)+ return int(total_mib) << 20, int(free_mib) << 20, name.strip(), pci_idreturn None@@ -305,10 +316,12 @@ def _unified_pool_bytes(smi_total: int, ram_total: int) -> int | None:return None-def _uma_budget(base: int, total: int, *, gpu_name: str = "") -> HardwareBudget:+def _uma_budget(base: int, total: int, *, gpu_name: str = "",+ gpu_pci_id: tuple[int, int] | None = None) -> HardwareBudget:usable = max(0, int(base * (1 - _UMA_HEADROOM_FRACTION)))return HardwareBudget(usable_vram_bytes=usable, total_device_bytes=total,- ram_available_bytes=0, uma=True, gpu_name=gpu_name, platform=sys.platform)+ ram_available_bytes=0, uma=True, gpu_name=gpu_name, platform=sys.platform,+ gpu_pci_id=gpu_pci_id)def probe_budget(*, planning: bool = False) -> HardwareBudget:@@ -342,19 +355,20 @@ def probe_budget(*, planning: bool = False) -> HardwareBudget:# measured soft cliff: decode collapses ~3.5x when concurrent demand hits it).live = (vram[1] + ram_avail) if vram else ram_availbase = min(unified, live)- return _uma_budget(base, unified, gpu_name=vram[2] if vram else "")+ return _uma_budget(base, unified, gpu_name=vram[2] if vram else "",+ gpu_pci_id=vram[3] if vram else None)if vram is None:# No NVIDIA device visible: Metal/Vulkan/CPU paths budget from RAM as UMA (Apple# Silicon) — conservative for discrete AMD until a vendor probe lands.return _uma_budget(ram_total if planning else ram_avail, ram_total)- total, free, gpu_name = vram+ total, free, gpu_name, gpu_pci_id = vrammargin = max(_MARGIN_FLOOR, int(total * _MARGIN_FRACTION))return HardwareBudget(usable_vram_bytes=max(0, (total if planning else free) - margin),total_device_bytes=total,ram_available_bytes=ram_total if planning else ram_avail,- uma=False, gpu_name=gpu_name, platform=sys.platform)+ uma=False, gpu_name=gpu_name, platform=sys.platform, gpu_pci_id=gpu_pci_id)def launch_budget(capacity: HardwareBudget, *, own_bytes: int = 0) -> HardwareBudget | None:@@ -376,7 +390,7 @@ def launch_budget(capacity: HardwareBudget, *, own_bytes: int = 0) -> HardwareBuvram = _nvidia_vram()if vram is None:return None- total, free, _name = vram+ total, free, _name, _pci_id = vramothers = max(0, total - free - max(0, own_bytes))usable = min(capacity.usable_vram_bytes, max(0, total - others - _LAUNCH_HEADROOM))return replace(capacity, usable_vram_bytes=usable)diff --git a/hermes_platform/host/products.py b/hermes_platform/host/products.pyindex 273930ac68c..70ad0dc6769 100644--- a/hermes_platform/host/products.py+++ b/hermes_platform/host/products.py@@ -1,6 +1,6 @@"""Vendor SoC recognizers derived from host facts.-Recognition uses OS-reported CPU identity without environment-variable input.+Recognition uses OS-reported CPU or PCI identity without environment-variable input."""from __future__ import annotations@@ -12,6 +12,12 @@ _NVIDIA_SOC_VENDOR = "NVIDIA"_NVIDIA_SOC_MODEL_MARKERS = ("N1X", "SPARK")+def is_nvidia_n1x_pci_id(pci_id: tuple[int, int]) -> bool:+ """Recognize N1X / GB20B by (vendor, device), independent of driver branding."""+ vendor, device = pci_id+ return vendor == 0x10DE and 0x2E00 <= device <= 0x2E3F++def looks_like_nvidia_arm_soc(*, native_arch: str, cpu_model: str, cpu_vendor: str) -> bool:"""Return whether the supplied facts identify an NVIDIA ARM SoC."""if native_arch != "arm64":diff --git a/tests/hermes_cli/test_local_launch_budget.py b/tests/hermes_cli/test_local_launch_budget.pyindex 30bb3a59e5e..18bd0f9327e 100644--- a/tests/hermes_cli/test_local_launch_budget.py+++ b/tests/hermes_cli/test_local_launch_budget.py@@ -32,7 +32,7 @@ def hermes_home(tmp_path, monkeypatch):def _card(monkeypatch, others_gib: float, *, total: int = CARD_TOTAL):monkeypatch.setattr(hardware, "_nvidia_vram",- lambda: (total, total - int(others_gib * GIB), "NVIDIA GeForce RTX 5090"))+ lambda: (total, total - int(others_gib * GIB), "NVIDIA GeForce RTX 5090", None))@pytest.fixturediff --git a/tests/hermes_cli/test_local_n1x_pci_identity.py b/tests/hermes_cli/test_local_n1x_pci_identity.pynew file mode 100644index 00000000000..f94c8aedffb--- /dev/null+++ b/tests/hermes_cli/test_local_n1x_pci_identity.py@@ -0,0 +1,92 @@+"""N1X recommendations follow PCI identity through the real memory-budget path."""++from dataclasses import replace+from types import SimpleNamespace++import pytest++from hermes_cli.local_runtime import catalog, hardware++[email protected]("windows")[email protected]("pci_id, name, matches", [+ ("0x2E0010DE", "Renamed, GPU", True),+ ("0x2e0310de", "", True),+ ("0x2E0610DE", "Renamed GPU", True),+ ("0x2E1310DE", "Renamed GPU", True),+ ("0x2E2A10DE", "Renamed GPU", True),+ ("0x2E3F10DE", "Renamed GPU", True),+ ("0x2DFF10DE", "NVIDIA RTX Spark N1X", False),+ ("0x2E4010DE", "NVIDIA RTX Spark N1X", False),+ ("0x2E8610DE", "NVIDIA RTX Spark N1X", False),+ ("0x2E031002", "NVIDIA RTX Spark N1X", False),+ ("0x00000000", "NVIDIA RTX Spark N1X", False),+ ("N/A", "NVIDIA RTX Spark N1X (updated description)", True),+ ("[Not Supported]", "NVIDIA RTX Spark N1X", True),+ ("malformed", "Renamed GPU", False),+ ("0x2E0310DE00", "Renamed GPU", False),+])+def test_pci_identity_controls_recommendations_without_changing_memory(+ monkeypatch, pci_id, name, matches):+ calls = []+ monkeypatch.setattr(hardware, "_nvidia_smi_path", lambda: "nvidia-smi")+ monkeypatch.setattr(hardware, "_ram_bytes", lambda: (64 << 30, 22 << 30))+ monkeypatch.setattr(hardware, "_device_pool_view", lambda: (48 << 30, True))++ def run(argv, **kwargs):+ calls.append(argv)+ assert argv[1] == "--query-gpu=memory.total,memory.free,name,pci.device_id"+ # A second adapter must not supply identity for the first adapter's budget.+ output = (f'32704, 31423, "{name}", {pci_id}\n'+ '32704, 31423, NVIDIA RTX Spark N1X, 0x2E0310DE\n')+ return SimpleNamespace(returncode=0, stdout=output)++ monkeypatch.setattr(hardware.subprocess, "run", run)+ budget = hardware.probe_budget(planning=True)+ reference = replace(budget, gpu_name="NVIDIA RTX Spark N1X", gpu_pci_id=None)+ generic = replace(budget, gpu_name="", gpu_pci_id=None)+ expected = reference if matches else generic+ assert catalog.recommended_entry(budget) == catalog.recommended_entry(expected)+ entry = next(e for e in catalog.CATALOG if e.id == "qwen3.8-27b")+ variant = entry.variants[0]+ assert catalog.predicted_decode_tok_s(entry, variant, reference) != (+ catalog.predicted_decode_tok_s(entry, variant, generic))+ assert catalog.predicted_decode_tok_s(entry, variant, budget) == (+ catalog.predicted_decode_tok_s(entry, variant, expected))+ # Identity never overrides platform/recipe/placement eligibility.+ for backend in ("cpu", "vulkan"):+ assert catalog.predicted_decode_tok_s(entry, variant, budget, backend=backend) == (+ catalog.predicted_decode_tok_s(entry, variant, generic, backend=backend))+ assert catalog.predicted_decode_tok_s(entry, variant, budget, spilled=True) == (+ catalog.predicted_decode_tok_s(entry, variant, generic, spilled=True))+ assert budget.total_device_bytes == 48 << 30+ assert budget.usable_vram_bytes == int((48 << 30) * .8)+ assert budget.gpu_name == name+ assert len(calls) == 1++[email protected]("integrated", [False, True])+def test_unsupported_pci_query_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))+ monkeypatch.setattr(hardware, "_device_pool_view", lambda: (48 << 30, integrated))+ name = "NVIDIA RTX Spark N1X"++ def 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")++ monkeypatch.setattr(hardware.subprocess, "run", run)+ budget = hardware.probe_budget(planning=True)+ assert budget.gpu_name == name+ assert budget.gpu_pci_id is None+ assert budget.uma == integrated+ total = 48 << 30 if integrated else 32704 << 20+ usable = int(total * .8) if integrated else total - max(2 << 30, int(total * .09))+ assert budget.total_device_bytes == total+ assert budget.usable_vram_bytes == usable+ assert len(calls) == 2diff --git a/tests/hermes_cli/test_unified_pool_quirk.py b/tests/hermes_cli/test_unified_pool_quirk.pyindex 74581c8520b..04e89e49fcb 100644--- a/tests/hermes_cli/test_unified_pool_quirk.py+++ b/tests/hermes_cli/test_unified_pool_quirk.py@@ -94,7 +94,7 @@ def test_no_probe_available_stays_discrete(monkeypatch):def _uma_machine(monkeypatch, *, view):_no_cache(monkeypatch)monkeypatch.setattr(hw, "_nvidia_vram",- lambda: (UMA_SMI_TOTAL, 14848 << 20, ""))+ lambda: (UMA_SMI_TOTAL, 14848 << 20, "", None))monkeypatch.setattr(hw, "_ram_bytes",lambda: (UMA_RAM, 32 * GIB))monkeypatch.setattr(hw, "_device_pool_view", lambda: view)@@ -204,12 +204,13 @@ def test_memory_probe_carries_identity_without_another_process(monkeypatch):def run(argv, **kwargs):calls.append(argv)assert argv[0] == "nvidia-smi"- output = f"32704, 31423, {name}\n" if argv[1].endswith(",name") else "32704, 31423\n"+ output = f"32704, 31423, {name}, 0x2E0310DE\n"return SimpleNamespace(returncode=0, stdout=output)monkeypatch.setattr(hw.subprocess, "run", run)budget = hw.probe_budget(planning=True)assert budget.gpu_name == name+ assert budget.gpu_pci_id == (0x10DE, 0x2E03)assert budget.platform == sys.platformassert budget.total_device_bytes == UMA_POOLassert budget.usable_vram_bytes == int(UMA_POOL * .8)