Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

spec2: python-side FIRES counters (depth2, gate skipped / run), per-arm fires check, tau per class table

YanissAmz5a9aa4891229
diff --git a/tools/hy4/engine.py b/tools/hy4/engine.py
index 9dd9832..a6378fc 100644
--- a/tools/hy4/engine.py
+++ b/tools/hy4/engine.py
@@ -64,6 +64,7 @@ class Hy4Engine:
from draft_policy import CostPolicy
os.environ["HY4_DRAFT_CONF"] = "1" # the draft graph appends the confidences (read at the import of mtp_head, i.e. in load())
self.policy = CostPolicy.from_env()
+ self.fires = {"rounds": 0, "depth2": 0, "gate_skip": 0, "gate_run": 0} # python-side lever counters (cumulative over the server life): rounds drafted, rounds with 2 draft rows, gate tail skipped / run
self.gate = None # HY4_SPEC2_GATE=1: draft kb steps, then a tail step only when the confidence gate says it pays (tools/hy4/depth_gate.py); single session only
if os.environ.get("HY4_SPEC2_GATE", "0") == "1":
from depth_gate import DepthGate
@@ -367,6 +368,10 @@ class Hy4Engine:
d = d[:k]
if self.policy is not None:
d = d[:self.policy.choose(confs, 1 if ng is not None else 0)]
+ self.fires["rounds"] += 1
+ self.fires["depth2"] += len(d) == 2
+ if gb is not None:
+ self.fires["gate_run" if gext else "gate_skip"] += 1
tb = pc()
ext = []
if ng is not None and not skip:
@@ -443,6 +448,7 @@ class Hy4Engine:
st["policy"] = self.policy.stats()
if self.gate is not None:
st["gate"] = self.gate.stats()
+ st["fires"] = dict(self.fires)
st["ngram"] = {"ext": self.ngram_ext, "min": self.ngram_min, "fill": self.ngram_fill, "hit_rounds": n_hit, "ext_rows": n_ext, "ext_accepted": n_extacc, "long": self.ngram_long, "long_rounds": n_long}
else:
while out_n < max_new and not stop and not cancel():
diff --git a/tools/hy4/serve.py b/tools/hy4/serve.py
index 16e976b..c78cf62 100644
--- a/tools/hy4/serve.py
+++ b/tools/hy4/serve.py
@@ -270,7 +270,9 @@ def build_app(st: State):
print(f"req {st.served}: prompt {stats['prompt_tokens']} tok prefill {pf:.2f} s ({stats['prompt_tokens'] / pf:.0f} tok/s; trunk {stats.get('prefill_trunk_s', 0):.2f} s, "
f"draft fill {stats.get('prime_s', 0):.2f} s {stats.get('prime_mode')}) | decode {stats['decode_tokens']} tok {dc:.2f} s = "
f"{stats['decode_tokens'] / dc if dc else 0:.2f} tok/s spec={stats['speculative']} rounds {stats['rounds']} tau {stats['tau']} hist {stats['accept_hist']} | {finish}"
- + (f" | gate {stats['gate']}" if stats.get("gate") else ""),
+ + (f" | gate {stats['gate']}" if stats.get("gate") else "") + (f" | fires {stats['fires']}" if stats.get("fires") else "")
+ + (f" | round_ms {[round(x, 1) for x in stats['round_ms']]} gap_ms {[round(x, 1) for x in stats['gap_ms']]} busy_ms {stats['busy_ms']:.1f} ngram {stats['ngram']}"
+ if os.environ.get("HY4_REQ_ROUNDLOG", "0") == "1" and "round_ms" in stats and "ngram" in stats else ""),
flush=True)
yield ("end", stats, finish, n_gen)
diff --git a/tools/hy4/step/spec2_arms.py b/tools/hy4/step/spec2_arms.py
index c467b05..e850a5a 100644
--- a/tools/hy4/step/spec2_arms.py
+++ b/tools/hy4/step/spec2_arms.py
@@ -6,7 +6,7 @@ Metric per class: tok/s, tau, ms per round = 1000 * tau / tok/s, paired delta vs
B ships alone when C does not beat it; neither when both lose to A on code by more than 2 %.
env: OD_PORT OD_NAME GGUF N1119 B2_H B2_DIR B2_GM B2_CO B2_PASSES SP2_ORDER SP2_REPS (default 2) SP2_LEVERS (default 1)
Output: table on stdout + <N1119>/out/<OD_NAME>.spec2.json. ~50 min GPU: TMAX 3300."""
-import hashlib, json, os, re, signal, statistics, subprocess, sys, time, urllib.request
+import ast, hashlib, json, os, re, signal, statistics, subprocess, sys, time, urllib.request
E = os.environ; tree = os.getcwd(); t0 = time.time()
H = E.get("B2_H", "/home/kamel"); N = E.get("N1119", f"{H}/scratch/n1119")
name, port = E["OD_NAME"], E["OD_PORT"]; tmax = int(E.get("OD_TMAX", "3300"))
@@ -51,6 +51,25 @@ def gate_lines(path):
prev = cur or prev
return out
+def fires_check(letter, path):
+ """CLAUDE.md fires-check: the engine's python-side counters (last 'fires {...}' of the server log, cumulative). Returns (ok, reasons). A must show 0 firings, B depth2 > 0,
+ C depth2 > 0 and the gate both skipping and running; any logged fallback reason about the lever fails the arm."""
+ f, fb = {}, []
+ for l in open(path, errors="replace"):
+ m = re.search(r"fires (\{[^}]*\})", l)
+ if m: f = ast.literal_eval(m.group(1))
+ if re.search(r"fallback|disabled|not supported", l, re.I) and re.search(r"spec2|gate|depth", l, re.I): fb.append(l.strip()[:200])
+ d2, gs, gr = f.get("depth2", 0), f.get("gate_skip", 0), f.get("gate_run", 0)
+ log(f"FIRES depth2 {d2}")
+ log(f"FIRES gate {gs}/{gr} (skipped/run)")
+ why = []
+ if letter == "A" and (d2 or gs or gr): why.append("arm A shows firings")
+ if letter == "B" and d2 == 0: why.append("FIRES depth2 = 0")
+ if letter == "C" and (d2 == 0 or gs == 0 or gr == 0): why.append(f"gate lever not firing (depth2 {d2}, skipped {gs}, run {gr})")
+ if not f and letter != "A": why.append("no fires counter in the server log")
+ why += [f"fallback: {x}" for x in fb]
+ return not why, why
+
def precapture_line(path):
return next((l.strip() for l in open(path, errors="replace") if l.startswith("precapture:")), None)
@@ -114,6 +133,9 @@ def main():
if key in res["arms"]:
res["arms"][key]["reqs"] = gate_lines(sl)
res["arms"][key]["precapture"] = precapture_line(sl)
+ ok, why = fires_check(letter, sl)
+ res["arms"][key]["fires_ok"], res["arms"][key]["fires_why"] = ok, why
+ if not ok: log(f"FIRES FAIL arm {key}: {why}")
for q, c in zip(res["arms"][key]["reqs"][1:], [p["cls"] for p in res["arms"][key]["points"].values()]): # request 1 = the discarded warm-up
q["cls"] = c
save()
@@ -141,7 +163,19 @@ def main():
t = {l: mean_cls(l, cls) for l in "ABC"}
if all(t.values()):
print(f"SPEC2_VERDICT {cls}: A {t['A']:.2f} B(k=2) {t['B']:.2f} C(gate) {t['C']:.2f} tok/s B vs A {100 * (t['B'] / t['A'] - 1):+.1f} % C vs A {100 * (t['C'] / t['A'] - 1):+.1f} % C vs B {100 * (t['C'] / t['B'] - 1):+.1f} %")
- log("SPEC2_DONE", name, f"{time.time() - t0:.0f}s")
+ print("\nSPEC2 TAU per class (6 head_tau prompts x reps), gate: tau must not drop > 2 % vs A")
+ for cls in ("code", "prose", "chat"):
+ ta = [a["classes"][cls]["tau"] for a in arms.values() if a["letter"] == "A" and cls in a["classes"]]
+ row = f"{cls:<6}" + (f" A {statistics.mean(ta):.3f}" if ta else "")
+ for l in "BC":
+ tl = [a["classes"][cls]["tau"] for a in arms.values() if a["letter"] == l and cls in a["classes"]]
+ if tl and ta:
+ m = statistics.mean(tl); row += f" | {l} {m:.3f} {100 * (m / statistics.mean(ta) - 1):+.1f} % {'OK' if m >= 0.98 * statistics.mean(ta) else 'FAIL (> 2 % drop)'}"
+ print(row)
+ bad = [k for k, a in arms.items() if not a.get("fires_ok", False)]
+ missing = [l for l in "ABC" if not any(a["letter"] == l for a in arms.values())]
+ log("SPEC2_DONE", name, f"{time.time() - t0:.0f}s", "FIRES_FAIL " + ",".join(bad) if bad else "fires ok", "MISSING_ARMS " + ",".join(missing) if missing else "")
+ if bad or missing: sys.exit(1)
if __name__ == "__main__":
main()