The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(local-models): simplify PCI identity matching
Ryan Hillcba90a19b8b3
diff --git a/hermes_cli/local_runtime/catalog.py b/hermes_cli/local_runtime/catalog.pyindex b4594f5e261..86f42987731 100644--- a/hermes_cli/local_runtime/catalog.py+++ b/hermes_cli/local_runtime/catalog.py@@ -182,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", "n1x",+ ("win32", "cuda", "NVIDIA RTX Spark N1X","qwen3.8-27b", "UD-Q4_K_M", 2): 21.9,}@@ -190,16 +190,13 @@ _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."""- # PCI identity is authoritative. Names are only a fallback for unavailable IDs.+ # Drivers may append a parenthesized description to the stable device name.+ gpu_name = budget.gpu_name.partition(" (")[0]+ # Resolve PCI identity to the existing reference key; names only backfill missing 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)+ gpu_name = "NVIDIA RTX Spark N1X" if is_nvidia_n1x_pci_id(budget.gpu_pci_id) else ""+ effective_backend = "cuda" if backend == "auto" and gpu_name else backend+ key = (budget.platform, effective_backend, gpu_name, 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 0f322ef6ad9..3605cc73af7 100644--- a/hermes_cli/local_runtime/estimator.py+++ b/hermes_cli/local_runtime/estimator.py@@ -91,7 +91,7 @@ class HardwareBudget:uma: bool = Falsegpu_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 unavailable+ gpu_pci_id: int | None = None # nvidia-smi's packed PCI device/vendor IDdef profile_from_gguf(header: GGUFHeader) -> ModelProfile:diff --git a/hermes_cli/local_runtime/hardware.py b/hermes_cli/local_runtime/hardware.pyindex 1805d69609d..11f2f9a4c5c 100644--- a/hermes_cli/local_runtime/hardware.py+++ b/hermes_cli/local_runtime/hardware.py@@ -199,8 +199,8 @@ def _nvidia_smi_path() -> str | None:return found-def _nvidia_vram() -> tuple[int, int, str, tuple[int, int] | None] | None:- """Memory, name and optional (vendor, device) from the same GPU row."""+def _nvidia_vram() -> tuple[int, int, str, int | None] | None:+ """Memory, name and optional packed PCI ID from the same GPU row."""exe = _nvidia_smi_path()if exe is None:return None@@ -217,12 +217,9 @@ def _nvidia_vram() -> tuple[int, int, str, tuple[int, int] | None] | None:return Nonerow = 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)+ with suppress(ValueError): # N/A or unsupported identity must not lose memory data.+ pci_id = int(row[3], 16) if len(row) > 3 else Nonereturn int(total_mib) << 20, int(free_mib) << 20, name.strip(), pci_idreturn None@@ -317,7 +314,7 @@ def _unified_pool_bytes(smi_total: int, ram_total: int) -> int | None:def _uma_budget(base: int, total: int, *, gpu_name: str = "",- gpu_pci_id: tuple[int, int] | None = None) -> HardwareBudget:+ gpu_pci_id: 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,diff --git a/hermes_platform/host/products.py b/hermes_platform/host/products.pyindex 70ad0dc6769..b6862aee7a8 100644--- a/hermes_platform/host/products.py+++ b/hermes_platform/host/products.py@@ -12,10 +12,9 @@ _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 is_nvidia_n1x_pci_id(pci_id: int) -> bool:+ """Recognize N1X / GB20B; NVML packs device above the 16-bit vendor ID."""+ return pci_id & 0xFFFF == 0x10DE and 0x2E00 <= pci_id >> 16 <= 0x2E3Fdef looks_like_nvidia_arm_soc(*, native_arch: str, cpu_model: str, cpu_vendor: str) -> bool:diff --git a/tests/hermes_cli/test_local_n1x_pci_identity.py b/tests/hermes_cli/test_local_n1x_pci_identity.pyindex f94c8aedffb..9336f2b374a 100644--- a/tests/hermes_cli/test_local_n1x_pci_identity.py+++ b/tests/hermes_cli/test_local_n1x_pci_identity.py@@ -21,6 +21,8 @@ from hermes_cli.local_runtime import catalog, hardware("0x2E8610DE", "NVIDIA RTX Spark N1X", False),("0x2E031002", "NVIDIA RTX Spark N1X", False),("0x00000000", "NVIDIA RTX Spark N1X", False),+ ("-0x2E0310DE", "NVIDIA RTX Spark N1X", False),+ ("0x12E0310DE", "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),diff --git a/tests/hermes_cli/test_unified_pool_quirk.py b/tests/hermes_cli/test_unified_pool_quirk.pyindex 04e89e49fcb..08c09f04e43 100644--- a/tests/hermes_cli/test_unified_pool_quirk.py+++ b/tests/hermes_cli/test_unified_pool_quirk.py@@ -210,7 +210,7 @@ def test_memory_probe_carries_identity_without_another_process(monkeypatch):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.gpu_pci_id == 0x2E0310DEassert budget.platform == sys.platformassert budget.total_device_bytes == UMA_POOLassert budget.usable_vram_bytes == int(UMA_POOL * .8)