The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(local-runtime): Qwen3.8 MTP on; stacking MTP with the prefill microbatch becomes a fit decision
emozillab69f02e53227
diff --git a/hermes_cli/local_runtime/catalog.json b/hermes_cli/local_runtime/catalog.jsonindex 65bc4a38806..2a791a06ae3 100644--- a/hermes_cli/local_runtime/catalog.json+++ b/hermes_cli/local_runtime/catalog.json@@ -27,6 +27,8 @@"size_bytes": 931146432,"local": "mmproj-Qwen3.8-27B-BF16.gguf"},+ "mtp": true,+ "mtp_draft_depth": 2,"sampling": {"temp": "1.0","top-p": "0.95",diff --git a/hermes_cli/local_runtime/context_policy.py b/hermes_cli/local_runtime/context_policy.pyindex 82f19ff732d..558ed630f8a 100644--- a/hermes_cli/local_runtime/context_policy.py+++ b/hermes_cli/local_runtime/context_policy.py@@ -226,7 +226,8 @@ def launch_args(profile: ModelProfile, decision: WindowDecision, *,flash_attention: bool = True,mtp_capable: bool = False,mtp_draft_depth: int = 3,- uma: bool = False) -> list[str]:+ uma: bool = False,+ mtp_prefill: bool = False) -> list[str]:"""Per-model launch flags from a window decision. Explicit -c puts fitinto spill-weights-and-hold-ctx; q8 KV cache wherever flash attentionexists; -ot placement on spilled configs — DISCRETE cards only.@@ -238,18 +239,23 @@ def launch_args(profile: ModelProfile, decision: WindowDecision, *,~1.75x win the -ot pattern encodes does not transfer; a spilled UMAconfig runs unpinned.- MTP and the large prefill microbatch are BOTH wins but must not stack:- backend sampling keeps a ubatch x vocab x fp32 logits buffer on the- GPU, and MTP's draft context doubles it — at large vocab sizes and- -ub 2048 that buffer runs multiple GiB past what a fit that ignores- it would price. So MTP models run decode-optimized (-ub 512) and- non-MTP models run prefill-optimized (-ub 2048, measured ~+27%- prefill); ub_logits_bytes() prices whichever was chosen."""+ MTP and the large prefill microbatch both win, and whether they may+ STACK is a fit question, not a rule: backend sampling keeps a+ ubatch x vocab x fp32 logits buffer on the GPU and MTP's draft+ context doubles it, so the stacked posture costs a few GiB extra at+ large vocab. Where it fits, it measures best on both axes (Qwen3.8+ Q4 on a 32 GiB card: 93.3 tok/s decode vs 89.5 at ub512, prefill+ slightly better too); where it doesn't, ub512 keeps the decode win+ without packing the card. ``mtp_prefill`` is that fit verdict —+ presets decide it against the priced margin, and ub_logits_bytes()+ prices the same choice so the flag and its cost travel together."""args = ["-c", str(decision.window)]if mtp_capable:args += ["--spec-type", "draft-mtp","--spec-draft-n-max", str(mtp_draft_depth),- "--backend-sampling"]+ "--backend-sampling", "--spec-draft-backend-sampling"]+ if mtp_prefill:+ args += ["-b", "4096", "-ub", "2048"]else:args += ["-b", "2048", "-ub", "2048"]if flash_attention:@@ -259,10 +265,11 @@ def launch_args(profile: ModelProfile, decision: WindowDecision, *,return args-def ub_logits_bytes(n_vocab: int, *, mtp_capable: bool) -> int:+def ub_logits_bytes(n_vocab: int, *, mtp_capable: bool,+ mtp_prefill: bool = False) -> int:"""GPU logits-buffer cost of the microbatch choice made bylaunch_args, priced from the model's own vocab: ubatch x vocab x fp32,doubled by MTP's draft context. Callers add this to RUNTIME_OVERHEADper model — the flag and its price travel together or the fit lies."""- ubatch = 512 if mtp_capable else 2048+ ubatch = 2048 if (not mtp_capable or mtp_prefill) else 512return ubatch * max(0, int(n_vocab)) * 4 * (2 if mtp_capable else 1)diff --git a/hermes_cli/local_runtime/presets.py b/hermes_cli/local_runtime/presets.pyindex 8297f65f5f8..8bc9739f6fd 100644--- a/hermes_cli/local_runtime/presets.py+++ b/hermes_cli/local_runtime/presets.py@@ -105,7 +105,22 @@ def generate_presets(models_dir: Path, budget: HardwareBudget,mmproj_path = assets_dir() / entry.mmproj.local_nameif mmproj_path.exists():mmproj_bytes = entry.mmproj.size_bytes+ # MTP posture ladder: try the stacked posture first (MTP + large+ # prefill microbatch — best on both axes where it fits), fall back+ # to the decode-only posture (ub512), whose smaller logits buffer+ # may fit where the stack doesn't. Whichever survives is priced+ # into the window decision — flag and cost from the same call.+ mtp_prefill = Falselogits_bytes = ub_logits_bytes(profile.n_vocab, mtp_capable=is_mtp)+ if is_mtp:+ stacked = ub_logits_bytes(profile.n_vocab, mtp_capable=True,+ mtp_prefill=True)+ probe = initial_window(+ profile, budget,+ overhead_bytes=RUNTIME_OVERHEAD_BYTES + mmproj_bytes + stacked)+ if (not isinstance(probe, PhysicsRefusal) and not probe.spilled):+ mtp_prefill = True+ logits_bytes = stackeddecision = initial_window(profile, budget,overhead_bytes=RUNTIME_OVERHEAD_BYTES + mmproj_bytes + logits_bytes)@@ -143,13 +158,15 @@ def generate_presets(models_dir: Path, budget: HardwareBudget,args = launch_args(profile, decision, mtp_capable=is_mtp,mtp_draft_depth=(entry.mtp_draft_depthif entry is not None else 3),- uma=budget.uma)+ uma=budget.uma, mtp_prefill=mtp_prefill)keys = _args_to_keys(args)if entry is not None and is_mtp:- # Integrated-MTP targets sample on the backend (their- # measured pairing; draft sampling stays default).+ # Integrated-MTP targets sample on the backend, and so does+ # the draft (vendor-measured pairing; the draft flag shipped+ # in their September recipe drop).keys["backend-sampling"] = "on"+ keys["spec-draft-backend-sampling"] = "on"# Sampling deference ladder, under the policy keys (policy wins# on clash). The GGUF's own general.sampling.* metadata is thediff --git a/tests/hermes_cli/test_catalog_variants.py b/tests/hermes_cli/test_catalog_variants.pyindex af89b2d2cc9..81b8956b444 100644--- a/tests/hermes_cli/test_catalog_variants.py+++ b/tests/hermes_cli/test_catalog_variants.py@@ -119,10 +119,10 @@ def test_floor_fallback_when_target_window_does_not_fit():quality that zero-spills at the 64K floor (reason 'best-fits'), nevera needless step down."""entry = catalog_by_id()["qwen3.8-27b"]- # ~24.5 GiB usable: Q4 weights (16.7 GiB in-memory) + floor KV (2.2)- # + overhead (1.5 + 0.9 mmproj + 1.9 vocab logits) fits, but no- # variant reaches 144K-target KV (+2.7 more for Q4, more for Q5+).- choice = select_variant(entry, budget(24.5))+ # ~23.5 GiB usable: Q4 weights (16.7 GiB in-memory) + floor KV (2.2)+ # + overhead (1.5 + 0.9 mmproj + ~1.0 MTP-posture logits) fits, but+ # the 144K-target KV (+2.7 more) does not.+ choice = select_variant(entry, budget(23.5))assert choice is not None and choice.zero_spillassert choice.reason_key == "best-fits"assert choice.variant.quant == "UD-Q4_K_M"diff --git a/tests/hermes_cli/test_context_policy.py b/tests/hermes_cli/test_context_policy.pyindex ad225cae7f8..ccc4d10a10e 100644--- a/tests/hermes_cli/test_context_policy.py+++ b/tests/hermes_cli/test_context_policy.py@@ -323,12 +323,25 @@ def test_launch_args_contract():assert "--spec-type" in b, "MTP must run on resident configs too"assert b[b.index("--spec-draft-n-max") + 1] == "2"assert "--backend-sampling" in b-- # MTP and the large microbatch are mutually exclusive: backend- # sampling keeps ubatch x vocab fp32 logits on the GPU and MTP- # doubles it — stacked, they packed a 32 GiB card 3.9 GiB past the- # priced overhead. MTP configs stay at the default ubatch.- assert "-ub" not in b, "MTP configs must not carry the large microbatch"+ assert "--spec-draft-backend-sampling" in b++ # Stacking MTP with the large microbatch is a FIT question, decided+ # by the caller (presets' posture ladder) and passed as mtp_prefill.+ # Default (no headroom proven): decode posture, small ubatch — the+ # stacked logits buffers once packed a 32 GiB card 3.9 GiB past a+ # fit that ignored them.+ assert "-ub" not in b, "default MTP posture stays at the small ubatch"++ # Headroom proven: the stacked posture carries the large microbatch+ # (measured best on both axes where it fits: 93.3 vs 89.5 tok/s+ # decode on Qwen3.8 Q4). ub_logits_bytes must price the same choice.+ s = launch_args(p, resident, mtp_capable=True, mtp_draft_depth=2,+ mtp_prefill=True)+ assert "-ub" in s and s[s.index("-ub") + 1] == "2048"+ assert "--spec-type" in s+ v = 248320+ assert ub_logits_bytes(v, mtp_capable=True) == 512 * v * 4 * 2+ assert ub_logits_bytes(v, mtp_capable=True, mtp_prefill=True) == 2048 * v * 4 * 2c = launch_args(p, resident, mtp_capable=False)assert "-ub" in c and c[c.index("-ub") + 1] == "2048" # prefill hint