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 a --json option to tools/bench.sh

Victor Nogueira161505dda6a9
diff --git a/README.md b/README.md
index 894b29c..a85cbe8 100644
--- a/README.md
+++ b/README.md
@@ -72,7 +72,7 @@ llama.cpp (ROCm, UD-IQ1_S 1.56 bpw, `-fa 1 -ub 2048`, no MTP), same machine: pp4
Quality against the official FP8 weights (129 held-out rows): see the model cards.
## Share your numbers
-Start a server from the quickstart, then run `tools/bench.sh` (standard library only, `--base` and `--model` select the server). It measures prefill on a prompt of about 3.5K tokens and decode on prose, chat and code with the prompts behind the table above, and prints one Markdown block with your hardware and versions.
+Start a server from the quickstart, then run `tools/bench.sh` (standard library only, `--base` and `--model` select the server). It measures prefill on a prompt of about 3.5K tokens and decode on prose, chat and code with the prompts behind the table above, and prints one Markdown block with your hardware and versions (`--json` adds the same numbers, with every run, as a JSON block).
Paste it into a [benchmark report](https://github.com/Yamz-Labs/kyojin/issues/new?template=benchmark_report.yml). Results from other gfx1151 machines and other ROCm GPUs are the most useful contribution. See `CONTRIBUTING.md`.
## Optional refusal hook
diff --git a/tests/test_bench_cpu.py b/tests/test_bench_cpu.py
index cfce8db..9475ef6 100644
--- a/tests/test_bench_cpu.py
+++ b/tests/test_bench_cpu.py
@@ -171,3 +171,43 @@ def test_table_reports_medians_not_means(server, monkeypatch, tmp_path):
assert "| Prefill, ~1000 tokens (median of 3) | 200.0 tok/s |" in md, md
for cat in bench.DECODE_PROMPTS:
assert f"(median of 3) | 20.0 tok/s |" in [line[line.index("(median"):] for line in md.splitlines() if line.startswith(f"| Decode, {cat},")][0]
+
+
+def test_json_block_matches_the_table(server, monkeypatch, tmp_path):
+ # Unequal runs, so the JSON must carry the median (not the mean) and every run; "code" never gives a rate.
+ def prefill(base, model, text):
+ salt = text[1:text.index("]")]
+ return (300, 1.0) if salt.endswith("warm") else (1000, [100.0, 200.0, 600.0][int(salt.rsplit("-", 1)[1])])
+
+ def decode(base, model, prompt, max_tokens):
+ if prompt in bench.DECODE_PROMPTS["code"]:
+ return None
+ return next([10.0, 20.0, 60.0][p.index(prompt)] for p in bench.DECODE_PROMPTS.values() if prompt in p)
+
+ corpus = tmp_path / "corpus.txt"
+ corpus.write_text(" ".join(f"w{i}" for i in range(9000)))
+ monkeypatch.setattr(bench, "prefill", prefill)
+ monkeypatch.setattr(bench, "decode", decode)
+ monkeypatch.setattr(bench, "gpu_name", lambda: "gfx-test")
+ monkeypatch.setattr(bench, "rocm_version", lambda: "rocm-test")
+ argv = ["bench.py", "--base", server, "--model", MODEL, "--corpus", str(corpus)]
+ outs = []
+ for extra in ([], ["--json"]):
+ monkeypatch.setattr(sys, "argv", argv + extra)
+ out = io.StringIO()
+ with contextlib.redirect_stdout(out), contextlib.redirect_stderr(io.StringIO()):
+ bench.main()
+ outs.append(out.getvalue())
+ plain, with_json = outs
+ assert "```json" not in plain
+ assert with_json.startswith(plain.rstrip("\n")) # the Markdown block itself is unchanged
+ d = json.loads(re.search(r"```json\n(.*)\n```", with_json, re.S).group(1))
+ assert (d["model"], d["gpu_target"], d["rocm"], d["server"]) == (MODEL, "gfx-test", "rocm-test", server)
+ assert d["prefill"] == {"prompt_tokens": 1000, "max_tokens": 1, "temperature": 0, "tok_s": 200.0, "runs": [100.0, 200.0, 600.0]}
+ assert d["decode"]["prose"] == d["decode"]["chat"] == {"max_tokens": 128, "temperature": 0, "tok_s": 20.0, "runs": [10.0, 20.0, 60.0]}
+ assert d["decode"]["code"] == {"max_tokens": 128, "temperature": 0, "tok_s": None, "runs": []}
+ # the table shows the same medians
+ assert "| Prefill, ~1000 tokens (median of 3) | 200.0 tok/s |" in plain
+ for cat in ("prose", "chat"):
+ assert f"| Decode, {cat}, 128 tokens, temperature 0 (median of 3) | 20.0 tok/s |" in plain
+ assert "| Decode, code, 128 tokens, temperature 0 (median of 0) | n/a tok/s |" in plain
diff --git a/tools/bench.py b/tools/bench.py
index f8b294a..4fdef7d 100755
--- a/tools/bench.py
+++ b/tools/bench.py
@@ -16,7 +16,8 @@ file). Each request starts with a unique tag so no prompt cache can answer it. T
after a build or a first launch is slow while the kernels tune: a short warm-up runs first, and
you should run the script twice on a fresh install.
-Prints one Markdown block to paste into a benchmark report issue.
+Prints one Markdown block to paste into a benchmark report issue. With --json, a fenced JSON block with the
+same measurements (and every run) follows it, so results can be collected into a table.
"""
import argparse
import json
@@ -184,6 +185,7 @@ def main():
ap.add_argument("--reps", type=int, default=3, help="runs per measurement (default 3)")
ap.add_argument("--max-tokens", type=int, default=128)
ap.add_argument("--corpus", help="text file for the prefill prompt (default: Markdown files of this repository)")
+ ap.add_argument("--json", action="store_true", help="also print the measurements as a fenced JSON block")
a = ap.parse_args()
base = a.base.rstrip("/")
reps = max(1, min(a.reps, 3))
@@ -224,30 +226,44 @@ def main():
dec.setdefault(cat, []).append(v)
def med(xs):
- return f"{statistics.median(xs):.1f}" if xs else "n/a"
+ return round(statistics.median(xs), 1) if xs else None
+
+ def fmt(x):
+ return f"{x:.1f}" if x is not None else "n/a"
ptok = int(statistics.median(n for n, _ in pf))
+ info = {"model": model, "cpu": cpu_name(), "ram": ram_gib(), "gpu_target": gpu_name(), "kernel": platform.release(),
+ "rocm": rocm_version(), "server": base, "date": time.strftime('%Y-%m-%d')}
+ prefill_med = med([t for _, t in pf])
lines = [
"### Kyojin benchmark",
"",
- f"- Model: `{model}`",
- f"- CPU: {cpu_name()}",
- f"- RAM: {ram_gib()}",
- f"- GPU target: {gpu_name()}",
- f"- Kernel: {platform.release()}",
- f"- ROCm: {rocm_version()}",
- f"- Server: {base}",
- f"- Date: {time.strftime('%Y-%m-%d')}",
+ f"- Model: `{info['model']}`",
+ f"- CPU: {info['cpu']}",
+ f"- RAM: {info['ram']}",
+ f"- GPU target: {info['gpu_target']}",
+ f"- Kernel: {info['kernel']}",
+ f"- ROCm: {info['rocm']}",
+ f"- Server: {info['server']}",
+ f"- Date: {info['date']}",
"",
"| Measurement | Result |",
"|---|---|",
- f"| Prefill, ~{ptok} tokens (median of {len(pf)}) | {med([t for _, t in pf])} tok/s |",
+ f"| Prefill, ~{ptok} tokens (median of {len(pf)}) | {fmt(prefill_med)} tok/s |",
]
for cat in DECODE_PROMPTS:
xs = dec.get(cat, [])
- lines.append(f"| Decode, {cat}, {a.max_tokens} tokens, temperature 0 (median of {len(xs)}) | {med(xs)} tok/s |")
+ lines.append(f"| Decode, {cat}, {a.max_tokens} tokens, temperature 0 (median of {len(xs)}) | {fmt(med(xs))} tok/s |")
lines += ["", "Method: prefill = prompt tokens / wall time (1 output token); decode = (tokens - 1) / streaming time. "
"Same prompts as the numbers in the README."]
+ if a.json:
+ result = info | {
+ "prefill": {"prompt_tokens": ptok, "max_tokens": 1, "temperature": 0, "tok_s": prefill_med,
+ "runs": [round(t, 1) for _, t in pf]},
+ "decode": {cat: {"max_tokens": a.max_tokens, "temperature": 0, "tok_s": med(dec.get(cat, [])),
+ "runs": [round(v, 1) for v in dec.get(cat, [])]} for cat in DECODE_PROMPTS},
+ }
+ lines += ["", "```json", json.dumps(result, indent=2), "```"]
print("\n".join(lines))