0.5.0: model hash check, energy per phase, honest bandwidth %, CI
ci / check (push) Successful in 58s

- The served model is hashed (cached) and checked against dev/models.tsv;
  the model_file note says standard or not, with warnings for a foreign
  file or a --quant that doesn't match. HASH_MODEL=0 skips it.
- The BetterBench build (git commit or describe) goes into meta and, when
  it isn't the release, into the run note.
- Energy per phase from a timestamped timeline.tsv: J/token for decode and
  each concurrency level, J/1k tokens for prefill.
- Bandwidth %: vLLM's loaded weight size when available, MTP files left out
  of the stored size, bandwidth scaled by tp.
- The notes and post-run Python moved to dev/notes.py and dev/postrun.py,
  with pytest tests; CI runs shellcheck, build --check and the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-29 14:00:00 +01:00
1 parent b892e7b14d
commit 5bb750cece
17 files changed
+1482 -622

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
"""model_hash.py must match the README's commands exactly."""
import os
import subprocess
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import model_hash # noqa: E402
def sh(cmd, cwd):
return subprocess.run(["sh", "-c", cmd], cwd=cwd, capture_output=True, text=True,
check=True).stdout.split()[0]
def test_directory_hash_matches_sha256sum(tmp_path):
# model_mtp sorts before model. in en_US but after it in C: the README pins C
(tmp_path / "model.safetensors").write_bytes(b"weights" * 1000)
(tmp_path / "model_mtp.safetensors").write_bytes(b"mtp head")
(tmp_path / "config.json").write_text("{}")
want = sh("sha256sum *.safetensors | LC_ALL=C sort -k2 | sha256sum", tmp_path)
assert model_hash.model_sha256(str(tmp_path), cache={}) == want
def test_file_hash_and_cache(tmp_path):
f = tmp_path / "m.gguf"
f.write_bytes(b"gguf" * 5000)
cache = {}
assert model_hash.model_sha256(str(f), cache) == sh("sha256sum m.gguf", tmp_path)
key = next(iter(cache))
cache[key] = "cached"
assert model_hash.model_sha256(str(f), cache) == "cached" # same size and mtime: no rehash
+106
View File
@@ -0,0 +1,106 @@
"""notes.py: launch parsing, the model check, the thinking check, the run note."""
import json
import os
import subprocess
import sys
DEV = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STD_GGUF = "322e194ff79741c7baa497c240f677f54b201b0efab44ca8e50f122b39123482"
MANDATORY = {"submitter": "pascal", "tp": "1", "pp": "1", "quant": "UD-Q4_K_M", "kv": "q8_0",
"spec": "none", "thinking": "default", "power_limit": "200",
"power_limit_source": "detected", "betterbench": "0.6.1", "betterbench_build": "v0.6.1",
"bench_standard": "0.4.1", "run_mode": "full", "concurrency": "on"}
COLLECTED = {"engine": "llama.cpp", "engine_version": "b11913-7aca0d2ea", "gpu_vendor": "intel",
"gpu_count": "1", "gpu_model": "Arc Pro B65", "model_file": "/models/x.gguf",
"model_bytes": "16464440224", "model_sha256": STD_GGUF}
MEASURED = {"greedy_check": "identical", "greedy_runs": "3", "greedy_variants": "1",
"greedy_hash": "1d5105fe09dc", "greedy_reasoning": "yes"}
LLAMA_CMD = ("GGML_SYCL_DISABLE_OPT=0 ZES_ENABLE_SYSMAN=1 HF_HUB_OFFLINE=1 /app/llama-server "
"-m /models/x.gguf -c 32768 -ngl 99 -fa on -b 4096 -ub 1024 -ctk q8_0 -ctv q8_0 "
"-np 4 --no-mmap --port 9000")
VLLM_CMD = ("docker run --rm --name v -e K8V4_PREFILL=onednn -e HF_TOKEN=<redacted> img /model "
"--max-num-batched-tokens=4224 --max-num-seqs=4 --kv-cache-dtype=int8_k_int4_v "
"--no-enable-prefix-caching "
"'--compilation-config={\"cudagraph_mode\": \"FULL_DECODE_ONLY\"}'")
def run(tmp_path, cmd=LLAMA_CMD, **over):
files = {}
for name, base in (("m", MANDATORY), ("c", COLLECTED), ("x", MEASURED)):
d = {**base, **over.get(name, {})}
files[name] = tmp_path / name
files[name].write_text("".join(f"{k}={v}\n" for k, v in d.items()))
(tmp_path / "cmd").write_text(cmd)
p = subprocess.run([sys.executable, os.path.join(DEV, "notes.py"), files["m"], files["c"],
files["x"], tmp_path / "cmd", tmp_path / "launch.json",
os.path.join(DEV, "models.tsv")], capture_output=True, text=True, check=True)
notes = dict(line.split("=", 1) for line in p.stdout.splitlines())
return notes, p.stderr, json.loads((tmp_path / "launch.json").read_text())
def test_llama_launch_and_env(tmp_path):
notes, err, launch = run(tmp_path)
assert notes["launch"] == "b 4096 · ub 1024 · fa on · ctk q8_0 · ctv q8_0 · ngl 99 · np 4 · no-mmap"
assert notes["env_flags"] == "GGML_SYCL_DISABLE_OPT=0 · ZES_ENABLE_SYSMAN=1" # offline switch left out
assert launch["env"]["HF_HUB_OFFLINE"] == "1" # but kept in meta
assert "warning" not in err
def test_llama_defaults_shown(tmp_path):
notes, _, _ = run(tmp_path, cmd="llama-server -m /m.gguf -ngl 99 -fa", m={"kv": "f16"})
assert notes["launch"] == "b default · ub default · fa on · ctk default · ctv default · ngl 99"
def test_vllm_launch_env_and_kv_warning(tmp_path):
notes, err, _ = run(tmp_path, cmd=VLLM_CMD, c={"engine": "vllm"})
assert "max-num-batched-tokens 4224" in notes["launch"]
assert "no-enable-prefix-caching" in notes["launch"]
assert 'compilation-config {"cudagraph_mode":"FULL_DECODE_ONLY"}' in notes["launch"]
assert notes["env_flags"] == "K8V4_PREFILL=onednn · HF_TOKEN=<redacted>"
assert "--kv q8_0 but the launch command sets int8_k_int4_v" in err
def test_no_command(tmp_path):
notes, _, _ = run(tmp_path, cmd="")
assert notes["launch"] == "unknown (pass --server-cmd-file)"
assert notes["env_flags"] == "unknown"
def test_standard_model(tmp_path):
notes, err, _ = run(tmp_path)
assert notes["model_file"].endswith("standard: Qwen3.8-27B UD-Q4_K_M")
assert "standard models" not in err
def test_standard_model_wrong_quant(tmp_path):
_, err, _ = run(tmp_path, m={"quant": "Q4_K_M"})
assert "declare --quant UD-Q4_K_M" in err
def test_other_model(tmp_path):
notes, err, _ = run(tmp_path, c={"model_sha256": "ab" * 32})
assert "not a standard model (sha256 abababababab)" in notes["model_file"]
assert "won't count" in err
def test_model_not_hashed(tmp_path):
notes, _, _ = run(tmp_path, c={"model_sha256": ""})
assert notes["model_file"].endswith("hash not checked")
def test_thinking_checked_against_replies(tmp_path):
notes, err, _ = run(tmp_path, m={"thinking": "off"})
assert notes["thinking"] == "off · reasoning seen"
assert "--thinking off, but the greedy replies contain reasoning" in err
notes, err, _ = run(tmp_path, m={"thinking": "high"}, x={"greedy_reasoning": "no"})
assert "--thinking high, but the greedy replies contain no reasoning" in err
_, err, _ = run(tmp_path, m={"thinking": "default"}, x={"greedy_reasoning": "no"})
assert "thinking" not in err
def test_run_note_betterbench_build(tmp_path):
notes, _, _ = run(tmp_path)
assert notes["run"] == "full · concurrency on · bench-standard 0.4.1 · betterbench 0.6.1"
notes, _, _ = run(tmp_path, m={"betterbench_build": "v0.6.1-3-gabc1234-dirty"})
assert notes["run"].endswith("betterbench 0.6.1 @ v0.6.1-3-gabc1234-dirty")
+58
View File
@@ -0,0 +1,58 @@
"""postrun.py: energy per phase and the bandwidth figure."""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import postrun # noqa: E402
def test_joules_between_interpolates():
ts, cum = [0.0, 10.0, 20.0], [0.0, 1000.0, 3000.0]
assert postrun.joules_between(ts, cum, 5, 15) == 1500.0
assert postrun.joules_between(ts, cum, -5, 30) == 3000.0
def test_energy_curve_counter_or_integrated():
rows = [(0, 100, 50.0, 0), (10, 100, 1050.0, 0)]
assert postrun.energy_curve(rows)[1] == [0.0, 1000.0]
rows = [(0, 100, None, 0), (10, 300, None, 0)]
ts, cum, src = postrun.energy_curve(rows)
assert cum == [0.0, 2000.0] and src == "integrated power"
def test_phase_energy_with_warmup_and_levels():
# a steady 100 W, so energy = 100 J per second of each piece
rows = [(float(t), 100.0, 100.0 * t, 2000.0) for t in range(0, 101)]
timeline = [(0.0, "[single] chat: warmup 1 + 4 runs"),
(10.0, "[prefill] depth ~2000 tok: warmup 2 + 8"),
(20.0, "[prefill] skip depth ~64000: needs more"),
(30.0, "[concurrency] level 2: 48 requests")]
res = {"single_stream": {"chat": [{"ok": True, "completion_tokens": 100}] * 4},
"prefill": [{"target_depth": 2000, "prompt_tokens": [1000] * 8}],
"concurrency": [{"level": 2, "aggregate_tps": 10.0, "wall_s": 50.0}]}
ph = postrun.phase_energy(res, rows, timeline, 80.0)
# decode: 10 s = 1000 J; 400 measured tokens, x 5/4 for the warm-up pass
assert ph["decode"] == {"joules": 1000, "avg_w": 100.0, "tokens_incl_warmup_est": 500,
"j_per_token": 2.0}
# prefill runs until the concurrency line (the skip line starts nothing): 20 s
assert ph["prefill"]["joules"] == 2000
assert ph["prefill"]["j_per_1k_tokens"] == round(2000 / (8000 * 10 / 8) * 1000, 3)
# level 2: 50 s = 5000 J for 500 tokens
assert ph["concurrency"]["2"]["j_per_token"] == 10.0
def test_roofline_prefers_loaded_weights_and_scales_with_tp():
single = [{"decode_tps": 100.0}]
c = {"gpu_mem_bw_gbs": "500", "model_bytes": "4000000000", "model_loaded_gib": "1.0"}
r = postrun.roofline(single, c, {"tp": "2"})
assert r["weight_source"] == "loaded (engine log)"
assert r["weight_bytes"] == 2 * 2**30
assert r["mem_bw_gbs"] == 1000.0
assert r["pct_of_mem_bw"] == round(100 * 100 * 2 * 2**30 / 1e9 / 1000, 1)
def test_roofline_falls_back_to_stored_and_declared_bw():
r = postrun.roofline([{"decode_tps": 50.0}], {"model_bytes": "4000000000"},
{"tp": "1", "mem_bw": "400"})
assert r["weight_source"] == "stored files" and r["pct_of_mem_bw"] == 50.0
assert postrun.roofline([{"decode_tps": 50.0}], {}, {"tp": "1", "mem_bw": "400"}) is None