The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(local-runtime): drop the Spark-class UMA workarounds; physics owns unified memory
emozilla6f5ccf16d7c9
diff --git a/hermes_cli/local_runtime/context_policy.py b/hermes_cli/local_runtime/context_policy.pyindex ac34b15d8e4..b7e26011480 100644--- a/hermes_cli/local_runtime/context_policy.py+++ b/hermes_cli/local_runtime/context_policy.py@@ -48,7 +48,6 @@ FLOOR = 64 * 1024 # = target; one internal constant_LADDER_GROWTH = 1.5_GROW_AT_OCCUPANCY = 0.85 # of the current window, at turn boundarySPEED_FLOOR_TOK_S = 6.0 # deepest measured spill bottomed near this-_UMA_CTX_FRACTION = 0.25 # UMA guard: ctx mem <= 25% of unified_EARLY_COST_CTX_FRACTION = 0.15 # bounded early cost when weights spill# TARGET_WINDOW: the smallest ladder rung at which compression becomes the@@ -91,20 +90,6 @@ class WindowDecision:return self.spill_bytes > 0-def _uma_cap(profile: ModelProfile, budget: HardwareBudget) -> int | None:- if not budget.uma:- return None- cap_bytes = int(budget.total_device_bytes * _UMA_CTX_FRACTION)- # Largest window whose ctx fits the cap (monotone -> scan the ladder).- best = FLOOR- for rung in ladder(profile.n_ctx_train or FLOOR):- if ctx_bytes(profile, rung) <= cap_bytes:- best = rung- else:- break- return best--def initial_window(profile: ModelProfile, budget: HardwareBudget,*, flash_attention: bool = True,overhead_bytes: int = 0) -> WindowDecision | PhysicsRefusal:@@ -113,7 +98,7 @@ def initial_window(profile: ModelProfile, budget: HardwareBudget,Zero-spill rung: weights + ctx + overhead fit usable VRAM entirely.Bounded-early-cost rung: weights already exceed VRAM; take the largestrung whose ctx stays <= ~15% of usable VRAM.- Floor everywhere, capped at native and the UMA guard.+ Floor everywhere, capped at native.``overhead_bytes``: runtime cost beyond weights+KV (RUNTIME_OVERHEADplus the vision projector when one loads). Zero keeps this function@@ -124,10 +109,7 @@ def initial_window(profile: ModelProfile, budget: HardwareBudget,return refusalnative = profile.n_ctx_train or FLOOR- uma_cap = _uma_cap(profile, budget)- rungs = [r for r in ladder(native) if uma_cap is None or r <= uma_cap]- if not rungs:- rungs = [min(FLOOR, native)]+ rungs = ladder(native)reasons: list[str] = []best_zero_spill: int | None = Nonediff --git a/hermes_cli/local_runtime/estimator.py b/hermes_cli/local_runtime/estimator.pyindex 12b5b88bed7..72c01070bbf 100644--- a/hermes_cli/local_runtime/estimator.py+++ b/hermes_cli/local_runtime/estimator.py@@ -75,9 +75,10 @@ class ModelProfile:class HardwareBudget:"""Memory the physics check may budget against.- Budget-source rule: discrete cards may trust the device- query (V0LITE); UMA devices must budget from OS free physical memory- minus headroom (day 1 — the device query lies 3x). Callers construct+ Budget-source rule: discrete cards may trust the device query+ (measured honest); unified-memory devices must budget from OS free+ physical memory minus headroom — their device queries have been+ observed off by 3x. Callers constructthis accordingly; the estimator just consumes it."""diff --git a/hermes_cli/local_runtime/hardware.py b/hermes_cli/local_runtime/hardware.pyindex 7b8dfe0cfe3..90d5ec149c1 100644--- a/hermes_cli/local_runtime/hardware.py+++ b/hermes_cli/local_runtime/hardware.py@@ -1,10 +1,10 @@"""Live hardware budget probe.-Budget-source rule: discrete cards may trust the device query-(V0LITE — honest within rounding); UMA devices must budget from OS free-physical memory minus headroom (day 1 — the device query lies 3x in both-directions). The probe classifies the device and constructs the right-HardwareBudget for the estimator.+Budget-source rule: discrete cards may trust the device query (measured+honest within rounding); unified-memory devices must budget from OS free+physical memory minus headroom — their device queries have been observed+off by 3x in both directions. The probe classifies the device and+constructs the right HardwareBudget for the estimator."""from __future__ import annotations@@ -21,8 +21,9 @@ _GIB = 1 << 30# 1 GiB is regressive on 8 GB cards and generous on 24 GB ones._MARGIN_FLOOR = 512 << 20_MARGIN_FRACTION = 0.07-# UMA heuristic: a "GPU" whose reported memory is within this fraction of-# system RAM shares it (Apple Silicon, DGX/RTX Spark class).+# UMA headroom: on unified-memory machines (Apple Silicon) the model shares+# physical memory with the OS and every app, so budget from RAM minus this+# fraction._UMA_HEADROOM_FRACTION = 0.20@@ -110,15 +111,6 @@ def probe_budget(*, planning: bool = False) -> HardwareBudget:ram_available_bytes=0, uma=True)total, free = vram- if ram_total and total >= ram_total * 0.9:- # Reported VRAM ≈ system RAM: UMA class (Spark). Never trust the- # device query here — OS physical memory minus headroom.- base = ram_total if planning else ram_avail- 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)-margin = max(_MARGIN_FLOOR, int(total * _MARGIN_FRACTION))base = total if planning else freereturn HardwareBudget(usable_vram_bytes=max(0, base - margin),diff --git a/tests/hermes_cli/test_context_policy.py b/tests/hermes_cli/test_context_policy.pyindex f098cb6eb3c..b3c2cbed6e4 100644--- a/tests/hermes_cli/test_context_policy.py+++ b/tests/hermes_cli/test_context_policy.py@@ -230,12 +230,17 @@ def test_dense_on_small_card_holds_floor_and_spills():assert d.spilled-def test_uma_guard_caps_context_memory():+def test_uma_budget_caps_the_window_through_physics():+ """Unified memory needs no special context rule: the budget already+ encodes the constraint (usable = RAM minus headroom, ram_available=0),+ so the ladder stops where weights + KV genuinely stop fitting."""p = hybrid(weights_gib=8, native=1024 * KIB)- unified = card(48, ram_gib=0, uma=True)+ unified = card(38.4, ram_gib=0, uma=True) # 48 GiB machine, 20% headroomd = initial_window(p, unified)assert isinstance(d, WindowDecision)- assert ctx_bytes(p, d.window) <= unified.total_device_bytes * 0.25 + 1+ assert not d.spilled, "UMA budget must produce a resident decision"+ need = 8 * GIB + ctx_bytes(p, d.window)+ assert need <= unified.usable_vram_bytes# ── growth ───────────────────────────────────────────────────