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.

Add pub_to_figures: publication measurements to figures.json, charts and README tables

YanissAmz776aa4381871
diff --git a/tests/fixtures/pub/figures.json b/tests/fixtures/pub/figures.json
new file mode 100644
index 0000000..0dded5a
--- /dev/null
+++ b/tests/fixtures/pub/figures.json
@@ -0,0 +1,254 @@
+{
+ "_comment": "Single source for the README table and the charts. null = not measured (left out of the chart). Qwen and GLM: new-user recipe at the commit below (MiMo: at 39dc956); all three: new-user recipe at the commit below. Rebuild: python3 tools/make_charts.py && python3 tools/make_readme_table.py. before = previous release, as published.",
+ "machine": "Ryzen AI Max+ 395, Radeon 8060S (gfx1151), 128 GB",
+ "method": "new-user install, published packs, default environment, card prompts, greedy, server-reported prefill",
+ "date": "2026-10-15",
+ "commit": "1ef53ad",
+ "models": [
+ {
+ "id": "qwen",
+ "name": "Qwen3.8-Flash-Next",
+ "pack_gb": 95.0,
+ "prefill": {
+ "8192": 1494,
+ "32768": 1478,
+ "65536": 1466,
+ "131072": 1406,
+ "262144": 1353
+ },
+ "spec": {
+ "prose": 47.5,
+ "chat": 52.8,
+ "code": 73.2
+ },
+ "decode": {
+ "8192": 52.4,
+ "32768": 48.1,
+ "65536": 49.3,
+ "131072": 43.0,
+ "262144": 44.3
+ },
+ "table": {
+ "prefill": "1494 at 8K",
+ "decode": "47.5 to 73.2"
+ },
+ "before": {
+ "prefill": {
+ "8192": 1481,
+ "32768": 1477,
+ "65536": 1436,
+ "131072": 1396,
+ "262144": 1347
+ },
+ "decode": {
+ "8192": 46.5,
+ "32768": 46.4,
+ "65536": 46.4,
+ "131072": 45.1,
+ "262144": 44.3
+ },
+ "spec": {
+ "prose": 45.7,
+ "chat": 48.3,
+ "code": 66.8
+ }
+ }
+ },
+ {
+ "id": "glm",
+ "name": "GLM-5.3-Flash",
+ "pack_gb": 99.73,
+ "prefill": {
+ "8192": 652,
+ "32768": 645,
+ "65536": 598,
+ "131072": 566,
+ "262144": 554
+ },
+ "spec": {
+ "prose": 27.4,
+ "chat": 30.0,
+ "code": 36.8
+ },
+ "decode": {
+ "8192": 30.1,
+ "32768": 30.6,
+ "65536": 31.5,
+ "131072": 27.3,
+ "262144": 28.8
+ },
+ "table": {
+ "prefill": "652 at 8K",
+ "decode": "27.4 to 36.8"
+ },
+ "before": {
+ "prefill": {
+ "8192": 634,
+ "32768": 637,
+ "65536": 613,
+ "131072": 589,
+ "262144": 567
+ },
+ "decode": {
+ "8192": 31.1,
+ "32768": 30.7,
+ "65536": 30.0,
+ "131072": 32.1,
+ "262144": 32.3
+ },
+ "spec": {
+ "prose": 26.2,
+ "chat": 31.4,
+ "code": 33.4
+ }
+ }
+ },
+ {
+ "id": "mimo",
+ "name": "MiMo-V2.6-Flash",
+ "earlier": "1.5",
+ "pack_gb": 105.8,
+ "prefill": {
+ "8192": 760,
+ "32768": 702,
+ "65536": 599,
+ "131072": 458
+ },
+ "spec": {
+ "prose": 28.9,
+ "chat": 31.2,
+ "code": 37.0
+ },
+ "decode": {
+ "8192": 29.8,
+ "32768": 23.4,
+ "65536": 17.4,
+ "131072": 12.9
+ },
+ "table": {
+ "prefill": "760 at 8K",
+ "decode": "28.9 to 37.0"
+ },
+ "before": {
+ "prefill": {
+ "8192": 812,
+ "32768": 698
+ },
+ "decode": {
+ "8192": 35.1,
+ "32768": 27.2
+ },
+ "spec": {
+ "prose": 29.1,
+ "chat": 32.4,
+ "code": 38.9
+ }
+ }
+ }
+ ],
+ "headline_prompt": "chat",
+ "headline_prefill_ctx": "8192",
+ "rivals": {
+ "strata": {
+ "name": "Strata",
+ "version": "v0.1.40",
+ "pack": "UD-IQ4_XS",
+ "pack_gb": 93.7,
+ "repo": "https://github.com/Niko1221/Strata",
+ "source_url": "https://github.com/Niko1221/Strata/releases/tag/v0.1.40",
+ "seen": "2026-10-07",
+ "prefill_independent": {
+ "32768": 795.1,
+ "65536": 762.5,
+ "120000": 709.1
+ },
+ "independent": {
+ "lab": "Ciru Inference Lab",
+ "date": "6 October 2026",
+ "url": "https://llm.ciru.ai/strataflash/",
+ "audit_url": "https://github.com/ciru-ai/strataflash/blob/main/benchmark/advertised-prefill-audit.json",
+ "sizes": "32K, 64K and 120K tokens"
+ },
+ "decode_measured": {
+ "8192": 39.0,
+ "32768": 38.7,
+ "65536": 36.4,
+ "131072": 35.0,
+ "262144": 37.5
+ },
+ "card_measured": {
+ "chat": 46.7,
+ "prose": 41.5,
+ "code": 61.6
+ },
+ "latest_release_note": "v0.1.40.1 (2026-10-06) is a server hotfix, same engine as v0.1.40: figures unchanged"
+ },
+ "gufo": {
+ "name": "Gufo",
+ "version": "v0.8.0",
+ "pack": "UD-Q4_K_XL",
+ "pack_gb": 111.3,
+ "repo": "https://github.com/gufo-org/gufo",
+ "source_url": "https://github.com/gufo-org/gufo/blob/main/docs/models/qwen3.8-flash-next/BENCHMARKS.md",
+ "seen": "2026-10-07",
+ "prefill_measured": {
+ "8192": 1250.5,
+ "32768": 1308.1,
+ "65536": 1289.0,
+ "131072": 1230.2
+ },
+ "decode_measured": {
+ "8192": 35.3,
+ "32768": 31.9,
+ "65536": 35.8,
+ "131072": 31.4
+ },
+ "card_measured": {
+ "chat": 37.3,
+ "prose": 32.5,
+ "code": 52.3
+ },
+ "note_256K": "the 256K prompt (about 264K tokens by Gufo's count) exceeds its 262144-token window",
+ "prev_seen_2026_10_06": {
+ "prefill_readme": {
+ "8K": 1492.95,
+ "32K": 1449.56,
+ "64K": 1316.7,
+ "128K": 1335.91
+ },
+ "decode_readme": {
+ "8K": 36.08,
+ "32K": 31.03,
+ "64K": 32.63,
+ "128K": 34.2
+ }
+ },
+ "source_commit_note": "benchmarks page updated 2026-10-06 21:57 UTC (perf: reduce prefill work at long context, #463), single-user figures dated October 6, 2026 (4c5a00d2); latest release v0.8.1"
+ }
+ },
+ "quality": {
+ "reference": "official FP8 release of the model",
+ "set": "200 public neutral texts, 3,084 scored positions, one scorer for all three engines, row-cluster bootstrap",
+ "positions": 3084,
+ "texts": 200,
+ "kyojin": {
+ "top1": 93.81,
+ "kl": 0.0216,
+ "kl_variation": 0.0008,
+ "pack_gb": 95.0
+ },
+ "strata": {
+ "top1": 93.64,
+ "kl": 0.0316,
+ "kl_variation": 0.0074,
+ "pack_gb": 93.7
+ },
+ "gufo": {
+ "top1": 95.36,
+ "kl": 0.0156,
+ "kl_variation": 0.0,
+ "pack_gb": 111.3
+ }
+ },
+ "method_ladder_reps": 1
+}
diff --git a/tests/fixtures/pub/scratch/bench_glm_c272384.md b/tests/fixtures/pub/scratch/bench_glm_c272384.md
new file mode 100644
index 0000000..57111b4
--- /dev/null
+++ b/tests/fixtures/pub/scratch/bench_glm_c272384.md
@@ -0,0 +1,47 @@
+### Kyojin benchmark
+
+| Measurement | Result |
+|---|---|
+
+```json
+{
+ "model": "glm-fixture",
+ "cpu": "fixture",
+ "date": "2026-10-17",
+ "prefill": {
+ "prompt_tokens": 3500,
+ "max_tokens": 1,
+ "temperature": 0,
+ "tok_s": 1000.0,
+ "runs": [
+ 3.5
+ ]
+ },
+ "decode": {
+ "prose": {
+ "max_tokens": 256,
+ "temperature": 0,
+ "tok_s": 27.55,
+ "runs": [
+ 27.55
+ ]
+ },
+ "chat": {
+ "max_tokens": 256,
+ "temperature": 0,
+ "tok_s": 30.21,
+ "runs": [
+ 30.21
+ ]
+ },
+ "code": {
+ "max_tokens": 256,
+ "temperature": 0,
+ "tok_s": 36.93,
+ "runs": [
+ 36.93
+ ]
+ }
+ }
+}
+```
diff --git a/tests/fixtures/pub/scratch/bench_qwen_c272384.md b/tests/fixtures/pub/scratch/bench_qwen_c272384.md
new file mode 100644
index 0000000..4a8aef4
--- /dev/null
+++ b/tests/fixtures/pub/scratch/bench_qwen_c272384.md
@@ -0,0 +1,47 @@
+### Kyojin benchmark
+
+| Measurement | Result |
+|---|---|
+
+```json
+{
+ "model": "qwen-fixture",
+ "cpu": "fixture",
+ "date": "2026-10-17",
+ "prefill": {
+ "prompt_tokens": 3500,
+ "max_tokens": 1,
+ "temperature": 0,
+ "tok_s": 1000.0,
+ "runs": [
+ 3.5
+ ]
+ },
+ "decode": {
+ "prose": {
+ "max_tokens": 256,
+ "temperature": 0,
+ "tok_s": 48.02,
+ "runs": [
+ 48.02
+ ]
+ },
+ "chat": {
+ "max_tokens": 256,
+ "temperature": 0,
+ "tok_s": 53.14,
+ "runs": [
+ 53.14
+ ]
+ },
+ "code": {
+ "max_tokens": 256,
+ "temperature": 0,
+ "tok_s": 74.61,
+ "runs": [
+ 74.61
+ ]
+ }
+ }
+}
+```
diff --git a/tests/fixtures/pub/scratch/curve_glm_c272384.json b/tests/fixtures/pub/scratch/curve_glm_c272384.json
new file mode 100644
index 0000000..365fe0f
--- /dev/null
+++ b/tests/fixtures/pub/scratch/curve_glm_c272384.json
@@ -0,0 +1,106 @@
+{
+ "model": "glm",
+ "max_tokens": 256,
+ "points": {
+ "8192": {
+ "tag": "point-8192",
+ "usage": {
+ "prompt_tokens": 8192,
+ "completion_tokens": 256,
+ "total_tokens": 8448,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 8192,
+ "predicted_n": 256,
+ "prompt_per_second": 655.8,
+ "predicted_per_second": 30.12
+ },
+ "target": 8192,
+ "calibrated_tokens": 8192
+ },
+ "32768": {
+ "tag": "point-32768",
+ "usage": {
+ "prompt_tokens": 32771,
+ "completion_tokens": 256,
+ "total_tokens": 33027,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 32771,
+ "predicted_n": 256,
+ "prompt_per_second": 648.2,
+ "predicted_per_second": 30.55
+ },
+ "target": 32768,
+ "calibrated_tokens": 32768
+ },
+ "65536": {
+ "tag": "point-65536",
+ "usage": {
+ "prompt_tokens": 65539,
+ "completion_tokens": 256,
+ "total_tokens": 65795,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 65539,
+ "predicted_n": 256,
+ "prompt_per_second": 601.7,
+ "predicted_per_second": 31.47
+ },
+ "target": 65536,
+ "calibrated_tokens": 65536
+ },
+ "131072": {
+ "tag": "point-131072",
+ "usage": {
+ "prompt_tokens": 131075,
+ "completion_tokens": 256,
+ "total_tokens": 131331,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 131075,
+ "predicted_n": 256,
+ "prompt_per_second": 569.4,
+ "predicted_per_second": 27.34
+ },
+ "target": 131072,
+ "calibrated_tokens": 131072
+ },
+ "262144": {
+ "tag": "point-262144",
+ "usage": {
+ "prompt_tokens": 262147,
+ "completion_tokens": 256,
+ "total_tokens": 262403,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 262147,
+ "predicted_n": 256,
+ "prompt_per_second": 557.0,
+ "predicted_per_second": 28.79
+ },
+ "target": 262144,
+ "calibrated_tokens": 262144
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/fixtures/pub/scratch/curve_glm_c524288.json b/tests/fixtures/pub/scratch/curve_glm_c524288.json
new file mode 100644
index 0000000..6903528
--- /dev/null
+++ b/tests/fixtures/pub/scratch/curve_glm_c524288.json
@@ -0,0 +1,26 @@
+{
+ "model": "glm",
+ "max_tokens": 256,
+ "points": {
+ "499712": {
+ "tag": "point-499712",
+ "usage": {
+ "prompt_tokens": 499715,
+ "completion_tokens": 256,
+ "total_tokens": 499971,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 499715,
+ "predicted_n": 256,
+ "prompt_per_second": 402.5,
+ "predicted_per_second": 22.06
+ },
+ "target": 499712,
+ "calibrated_tokens": 499712
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/fixtures/pub/scratch/curve_qwen_c272384.json b/tests/fixtures/pub/scratch/curve_qwen_c272384.json
new file mode 100644
index 0000000..0b7bb60
--- /dev/null
+++ b/tests/fixtures/pub/scratch/curve_qwen_c272384.json
@@ -0,0 +1,106 @@
+{
+ "model": "qwen",
+ "max_tokens": 256,
+ "points": {
+ "8192": {
+ "tag": "point-8192",
+ "usage": {
+ "prompt_tokens": 8192,
+ "completion_tokens": 256,
+ "total_tokens": 8448,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 8192,
+ "predicted_n": 256,
+ "prompt_per_second": 1502.4,
+ "predicted_per_second": 52.44
+ },
+ "target": 8192,
+ "calibrated_tokens": 8192
+ },
+ "32768": {
+ "tag": "point-32768",
+ "usage": {
+ "prompt_tokens": 32771,
+ "completion_tokens": 256,
+ "total_tokens": 33027,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 32771,
+ "predicted_n": 256,
+ "prompt_per_second": 1481.9,
+ "predicted_per_second": 48.07
+ },
+ "target": 32768,
+ "calibrated_tokens": 32768
+ },
+ "65536": {
+ "tag": "point-65536",
+ "usage": {
+ "prompt_tokens": 65539,
+ "completion_tokens": 256,
+ "total_tokens": 65795,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 65539,
+ "predicted_n": 256,
+ "prompt_per_second": 1469.3,
+ "predicted_per_second": 49.31
+ },
+ "target": 65536,
+ "calibrated_tokens": 65536
+ },
+ "131072": {
+ "tag": "point-131072",
+ "usage": {
+ "prompt_tokens": 131075,
+ "completion_tokens": 256,
+ "total_tokens": 131331,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 131075,
+ "predicted_n": 256,
+ "prompt_per_second": 1412.8,
+ "predicted_per_second": 43.02
+ },
+ "target": 131072,
+ "calibrated_tokens": 131072
+ },
+ "262144": {
+ "tag": "point-262144",
+ "usage": {
+ "prompt_tokens": 262147,
+ "completion_tokens": 256,
+ "total_tokens": 262403,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 262147,
+ "predicted_n": 256,
+ "prompt_per_second": 1358.1,
+ "predicted_per_second": 44.27
+ },
+ "target": 262144,
+ "calibrated_tokens": 262144
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/fixtures/pub/scratch/curve_qwen_c524288.json b/tests/fixtures/pub/scratch/curve_qwen_c524288.json
new file mode 100644
index 0000000..6ae12f3
--- /dev/null
+++ b/tests/fixtures/pub/scratch/curve_qwen_c524288.json
@@ -0,0 +1,26 @@
+{
+ "model": "qwen",
+ "max_tokens": 256,
+ "points": {
+ "499712": {
+ "tag": "point-499712",
+ "usage": {
+ "prompt_tokens": 499715,
+ "completion_tokens": 256,
+ "total_tokens": 499971,
+ "prompt_tokens_details": {
+ "cached_tokens": 0
+ }
+ },
+ "timings": {
+ "cache_n": 0,
+ "prompt_n": 499715,
+ "predicted_n": 256,
+ "prompt_per_second": 1290.6,
+ "predicted_per_second": 36.21
+ },
+ "target": 499712,
+ "calibrated_tokens": 499712
+ }
+ }
+}
\ No newline at end of file
diff --git a/tools/pub_to_figures.py b/tools/pub_to_figures.py
new file mode 100644
index 0000000..6602807
--- /dev/null
+++ b/tools/pub_to_figures.py
@@ -0,0 +1,200 @@
+#!/usr/bin/env python3
+"""Turn the publication measurements into doc/figures.json, then regenerate the charts and the README tables.
+
+Inputs, in the scratch directory (default ~/hermes-work/pub159/scratch):
+ curve_{glm,qwen}_c272384.json served depth curve: points["8192"].."262144" (timings, usage)
+ curve_{glm,qwen}_c524288.json served depth curve: points["499712"] (the 500K point)
+ bench_{glm,qwen}_c272384.md tools/bench.py --json output: card prompts (fenced JSON block)
+
+Writes doc/figures.json, keeping its schema: the previous current values become "before", the new
+values replace prefill / decode / spec, "table" is recomputed, "date" is the bench run date and
+"commit" is the measured commit. Then runs tools/make_charts.py and tools/make_readme_table.py.
+Refuses to write anything when an expected point or card value is missing or inconsistent.
+
+usage: python3 tools/pub_to_figures.py [--scratch DIR] [--commit HASH] [--dry-run] [--no-render] [--add-500k]
+"""
+import argparse
+import copy
+import difflib
+import json
+import os
+import re
+import subprocess
+import sys
+
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+DEFAULT_SCRATCH = os.path.expanduser("~/hermes-work/pub159/scratch")
+MODELS = ("qwen", "glm")
+SHORT_FILE, LONG_FILE = "c272384", "c524288"
+POINTS = (8192, 32768, 65536, 131072, 262144)
+POINT_500K = 499712
+CARD = ("prose", "chat", "code")
+CARD_MAX_TOKENS = 256
+TOL_TOKENS = 64 # calibration lands on or just above the target: allowed |prompt_tokens - target|
+
+
+class InputError(Exception):
+ pass
+
+
+def load_curve(path, targets):
+ """Return {target: (prefill_tok_s, decode_tok_s)} from the server-reported timings."""
+ if not os.path.exists(path):
+ raise InputError(f"missing input {path}")
+ with open(path, encoding="utf-8") as f:
+ points = json.load(f).get("points", {})
+ out = {}
+ for t in targets:
+ p = points.get(str(t))
+ if not p:
+ raise InputError(f"{os.path.basename(path)}: no point {t}")
+ tm = p.get("timings") or {}
+ pre, dec = tm.get("prompt_per_second"), tm.get("predicted_per_second")
+ if not all(isinstance(v, (int, float)) and v > 0 for v in (pre, dec)):
+ raise InputError(f"{os.path.basename(path)}: point {t} has no server-reported prefill/decode")
+ ptok = (p.get("usage") or {}).get("prompt_tokens")
+ if not isinstance(ptok, int) or abs(ptok - t) > max(TOL_TOKENS, t * 0.001):
+ raise InputError(f"{os.path.basename(path)}: point {t} has prompt_tokens={ptok}")
+ out[t] = (float(pre), float(dec))
+ return out
+
+
+def load_bench(path):
+ """Return ({prose, chat, code: tok/s}, date) from the fenced JSON block of tools/bench.py --json."""
+ if not os.path.exists(path):
+ raise InputError(f"missing input {path}")
+ with open(path, encoding="utf-8") as f:
+ m = re.search(r"```json\n(.*?)\n```", f.read(), re.S)
+ if not m:
+ raise InputError(f"{os.path.basename(path)}: no JSON block (bench not finished?)")
+ d = json.loads(m.group(1))
+ dec, spec = d.get("decode") or {}, {}
+ for k in CARD:
+ c = dec.get(k) or {}
+ v = c.get("tok_s")
+ if not isinstance(v, (int, float)) or v <= 0:
+ raise InputError(f"{os.path.basename(path)}: no decode {k} tok_s")
+ if c.get("max_tokens") != CARD_MAX_TOKENS:
+ raise InputError(f"{os.path.basename(path)}: decode {k} max_tokens={c.get('max_tokens')}")
+ spec[k] = round(float(v), 1)
+ if not d.get("date"):
+ raise InputError(f"{os.path.basename(path)}: no date")
+ return spec, d["date"]
+
+
+def collect(scratch):
+ """Return ({model: {prefill: {int: v}, decode: {int: v}, spec: {...}}}, date, warnings)."""
+ data, dates = {}, []
+ for mid in MODELS:
+ short = load_curve(os.path.join(scratch, f"curve_{mid}_{SHORT_FILE}.json"), POINTS)
+ long = load_curve(os.path.join(scratch, f"curve_{mid}_{LONG_FILE}.json"), [POINT_500K])
+ spec, date = load_bench(os.path.join(scratch, f"bench_{mid}_{SHORT_FILE}.md"))
+ pts = dict(short)
+ pts.update(long)
+ data[mid] = {
+ "prefill": {t: pts[t][0] for t in pts},
+ "decode": {t: pts[t][1] for t in pts},
+ "spec": spec,
+ }
+ dates.append(date)
+ return data, max(dates)
+
+
+def build(F, data, date, commit, add_500k):
+ """Return (new figures dict, warnings). Does not touch the input dict."""
+ G = copy.deepcopy(F)
+ warnings = []
+ ids = {m["id"] for m in G["models"]}
+ for mid in MODELS:
+ if mid not in ids:
+ raise InputError(f"figures.json has no model {mid!r}")
+ for m in G["models"]:
+ if m["id"] not in data:
+ continue
+ d = data[m["id"]]
+ m["before"] = {"prefill": m["prefill"], "decode": m["decode"], "spec": m["spec"]}
+ published = set(m["prefill"]) | set(m["decode"])
+ keys = list(POINTS) + ([POINT_500K] if (add_500k or str(POINT_500K) in published) else [])
+ if POINT_500K not in keys:
+ warnings.append(f"{m['id']}: 500K point measured ({d['prefill'][POINT_500K]:.1f} prefill, "
+ f"{d['decode'][POINT_500K]:.1f} decode) but figures.json has no {POINT_500K} key; "
+ f"not published (use --add-500k)")
+ m["prefill"] = {str(t): round(d["prefill"][t]) for t in keys}
+ m["decode"] = {str(t): round(d["decode"][t], 1) for t in keys}
+ m["spec"] = dict(d["spec"])
+ vals = list(m["spec"].values())
+ m["table"] = {"prefill": f"{m['prefill']['8192']} at 8K",
+ "decode": f"{min(vals):.1f} to {max(vals):.1f}"}
+ G["date"] = date
+ G["commit"] = commit
+ return G, warnings
+
+
+def dump(F):
+ return json.dumps(F, indent=1, ensure_ascii=False) + "\n"
+
+
+def git_head(root):
+ try:
+ return subprocess.run(["git", "-C", root, "rev-parse", "--short", "HEAD"], capture_output=True,
+ text=True, check=True).stdout.strip()
+ except (OSError, subprocess.CalledProcessError):
+ return None
+
+
+def render(root):
+ for script in ("make_charts.py", "make_readme_table.py"):
+ subprocess.run([sys.executable, os.path.join(root, "tools", script)], cwd=root, check=True)
+
+
+def main(argv=None):
+ ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
+ ap.add_argument("--scratch", default=DEFAULT_SCRATCH, help="directory with the curve_*.json and bench_*.md inputs")
+ ap.add_argument("--root", default=ROOT, help="repository root (doc/figures.json, tools/, README templates)")
+ ap.add_argument("--commit", help="short hash of the measured commit (default: git HEAD of --root)")
+ ap.add_argument("--dry-run", action="store_true", help="print the diff of doc/figures.json; write nothing")
+ ap.add_argument("--no-render", action="store_true", help="update figures.json only; skip the charts and tables")
+ ap.add_argument("--add-500k", action="store_true",
+ help="publish the 500K point under key 499712 even if figures.json has no such key yet")
+ a = ap.parse_args(argv)
+
+ fig_path = os.path.join(a.root, "doc", "figures.json")
+ try:
+ with open(fig_path, encoding="utf-8") as f:
+ old_text = f.read()
+ commit = a.commit or git_head(a.root)
+ if not commit:
+ raise InputError("no --commit given and git HEAD is unavailable")
+ data, date = collect(a.scratch)
+ G, warnings = build(json.loads(old_text), data, date, commit, a.add_500k)
+ except (InputError, OSError, json.JSONDecodeError) as e:
+ print(f"pub_to_figures: {e}", file=sys.stderr)
+ print("pub_to_figures: nothing written", file=sys.stderr)
+ return 1
+
+ new_text = dump(G)
+ for w in warnings:
+ print(f"warning: {w}", file=sys.stderr)
+ diff = list(difflib.unified_diff(old_text.splitlines(True), new_text.splitlines(True),
+ "a/doc/figures.json", "b/doc/figures.json"))
+ if a.dry_run:
+ sys.stdout.write("".join(diff) if diff else "no changes\n")
+ return 0
+ if new_text != old_text:
+ with open(fig_path, "w", encoding="utf-8") as f:
+ f.write(new_text)
+ print(f"wrote {fig_path} ({len(diff)} diff lines)")
+ else:
+ print("figures.json unchanged")
+ if not a.no_render:
+ try:
+ render(a.root)
+ except subprocess.CalledProcessError as e:
+ print(f"pub_to_figures: render failed ({e.cmd[1]}, rc {e.returncode}); doc/figures.json is already "
+ "updated: fix the renderer, then run the renderers again", file=sys.stderr)
+ return 1
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/test_pub_to_figures.py b/tools/test_pub_to_figures.py
new file mode 100644
index 0000000..34b7954
--- /dev/null
+++ b/tools/test_pub_to_figures.py
@@ -0,0 +1,142 @@
+#!/usr/bin/env python3
+"""pub_to_figures.py against synthetic inputs (tests/fixtures/pub). CPU only, no model, no GPU.
+
+Every run happens in a temporary copy of the repository's figure tooling, so the real doc/ and README.md are never written."""
+import importlib.util
+import json
+import os
+import shutil
+import sys
+
+import pytest
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+ROOT = os.path.dirname(HERE)
+FIX = os.path.join(ROOT, "tests", "fixtures", "pub")
+SPEC = importlib.util.spec_from_file_location("pub_to_figures", os.path.join(HERE, "pub_to_figures.py"))
+p2f = importlib.util.module_from_spec(SPEC)
+sys.modules["pub_to_figures"] = p2f
+SPEC.loader.exec_module(p2f)
+
+
+def make_root(tmp_path):
+ """A copy of the figure tooling and templates, with the fixture figures.json."""
+ root = tmp_path / "repo"
+ (root / "tools").mkdir(parents=True)
+ (root / "doc").mkdir()
+ for name in ("make_charts.py", "make_readme_table.py", "pub_to_figures.py"):
+ shutil.copy(os.path.join(HERE, name), root / "tools" / name)
+ shutil.copy(os.path.join(FIX, "figures.json"), root / "doc" / "figures.json")
+ shutil.copy(os.path.join(ROOT, "README.tmpl.md"), root / "README.tmpl.md")
+ shutil.copy(os.path.join(ROOT, "doc", "benchmarks.tmpl.md"), root / "doc" / "benchmarks.tmpl.md")
+ return root
+
+
+def make_scratch(tmp_path):
+ scratch = tmp_path / "scratch"
+ shutil.copytree(os.path.join(FIX, "scratch"), scratch)
+ return scratch
+
+
+def load(root):
+ with open(root / "doc" / "figures.json", encoding="utf-8") as f:
+ return json.load(f)
+
+
+def model(F, mid):
+ return next(m for m in F["models"] if m["id"] == mid)
+
+
+def test_fixture_round_trips_byte_exact():
+ """The writer reproduces the existing file format, so an update only changes the measured lines."""
+ with open(os.path.join(FIX, "figures.json"), encoding="utf-8") as f:
+ text = f.read()
+ assert p2f.dump(json.loads(text)) == text
+
+
+def test_dry_run_prints_diff_and_writes_nothing(tmp_path, capsys):
+ root, scratch = make_root(tmp_path), make_scratch(tmp_path)
+ before = (root / "doc" / "figures.json").read_text(encoding="utf-8")
+ rc = p2f.main(["--root", str(root), "--scratch", str(scratch), "--commit", "abc1234", "--dry-run"])
+ assert rc == 0
+ assert (root / "doc" / "figures.json").read_text(encoding="utf-8") == before
+ assert not (root / "README.md").exists() and not (root / "doc" / "img").exists()
+ out = capsys.readouterr().out
+ assert out.startswith("--- a/doc/figures.json")
+ assert '+ "commit": "abc1234",' in out
+ assert '- "commit": "1ef53ad",' in out
+ assert '+ "8192": 1502,' in out
+
+
+def test_writes_schema_and_renders(tmp_path, capsys):
+ root, scratch = make_root(tmp_path), make_scratch(tmp_path)
+ old = load(root)
+ rc = p2f.main(["--root", str(root), "--scratch", str(scratch), "--commit", "abc1234"])
+ assert rc == 0
+ F = load(root)
+ assert F["commit"] == "abc1234" and F["date"] == "2026-10-17"
+ assert list(F) == list(old) # same top-level keys, same order
+ q, g, mimo = model(F, "qwen"), model(F, "glm"), model(F, "mimo")
+ assert list(q) == list(model(old, "qwen"))
+ assert q["prefill"] == {"8192": 1502, "32768": 1482, "65536": 1469, "131072": 1413, "262144": 1358}
+ assert q["decode"] == {"8192": 52.4, "32768": 48.1, "65536": 49.3, "131072": 43.0, "262144": 44.3}
+ assert q["spec"] == {"prose": 48.0, "chat": 53.1, "code": 74.6}
+ assert q["table"] == {"prefill": "1502 at 8K", "decode": "48.0 to 74.6"}
+ assert g["prefill"]["8192"] == 656 and g["table"]["prefill"] == "656 at 8K"
+ # before = the previous current values, verbatim
+ assert q["before"] == {"prefill": old["models"][0]["prefill"], "decode": old["models"][0]["decode"],
+ "spec": old["models"][0]["spec"]}
+ assert g["before"]["spec"] == model(old, "glm")["spec"]
+ assert mimo == model(old, "mimo") # not measured in this pass: untouched
+ assert F["rivals"] == old["rivals"] and F["quality"] == old["quality"]
+ # the renderers ran
+ assert (root / "doc" / "img" / "prefill.svg").exists()
+ assert "1502 at 8K" in (root / "README.md").read_text(encoding="utf-8")
+ assert "wrote" in capsys.readouterr().out
+
+
+def test_500k_point_not_published_without_flag(tmp_path, capsys):
+ root, scratch = make_root(tmp_path), make_scratch(tmp_path)
+ assert p2f.main(["--root", str(root), "--scratch", str(scratch), "--commit", "abc1234", "--no-render"]) == 0
+ assert "499712" not in model(load(root), "qwen")["prefill"]
+ assert "499712 key" in capsys.readouterr().err
+
+
+def test_500k_point_with_flag_writes_key(tmp_path):
+ # make_charts.py has no 499712 tick yet: rendering a published 500K point fails (see NOTEBOOK.md)
+ root, scratch = make_root(tmp_path), make_scratch(tmp_path)
+ assert p2f.main(["--root", str(root), "--scratch", str(scratch), "--commit", "abc1234",
+ "--add-500k", "--no-render"]) == 0
+ q = model(load(root), "qwen")
+ assert q["prefill"]["499712"] == 1291 and q["decode"]["499712"] == 36.2
+ assert list(q["prefill"])[-1] == "499712"
+
+
+def test_missing_point_refuses_and_writes_nothing(tmp_path, capsys):
+ root, scratch = make_root(tmp_path), make_scratch(tmp_path)
+ before = (root / "doc" / "figures.json").read_text(encoding="utf-8")
+ path = scratch / "curve_qwen_c272384.json"
+ d = json.loads(path.read_text(encoding="utf-8"))
+ del d["points"]["262144"]
+ path.write_text(json.dumps(d), encoding="utf-8")
+ assert p2f.main(["--root", str(root), "--scratch", str(scratch), "--commit", "abc1234"]) == 1
+ assert (root / "doc" / "figures.json").read_text(encoding="utf-8") == before
+ err = capsys.readouterr().err
+ assert "no point 262144" in err and "nothing written" in err
+
+
+def test_bench_without_json_block_refuses(tmp_path, capsys):
+ root, scratch = make_root(tmp_path), make_scratch(tmp_path)
+ (scratch / "bench_glm_c272384.md").write_text("", encoding="utf-8") # bench still running
+ assert p2f.main(["--root", str(root), "--scratch", str(scratch), "--commit", "abc1234"]) == 1
+ assert "no JSON block" in capsys.readouterr().err
+
+
+def test_bad_prompt_token_count_refuses(tmp_path, capsys):
+ root, scratch = make_root(tmp_path), make_scratch(tmp_path)
+ path = scratch / "curve_glm_c272384.json"
+ d = json.loads(path.read_text(encoding="utf-8"))
+ d["points"]["65536"]["usage"]["prompt_tokens"] = 40000 # a different prompt than the target
+ path.write_text(json.dumps(d), encoding="utf-8")
+ assert p2f.main(["--root", str(root), "--scratch", str(scratch), "--commit", "abc1234"]) == 1
+ assert "prompt_tokens=40000" in capsys.readouterr().err