okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

brenoperucchibench: community report, RTX 5090 + Ryzen 9 5950X (AVX2), UD-Q4_K_XL / IQ3_S / Swift IQ3_XXS on engines 0.1.31-0.1.39 (#433)2a7db0422

main
3.7 KiB67 linesraw
1#!/usr/bin/env python3
2"""Strata community benchmark runner: warm-up + N measured runs per prompt, server timings, one JSON per config.
3
4Follows docs/COMMUNITY_BENCHMARKS.md: prompt and decode throughput from the engine's own timings, actual token
5counts, reused (cache_n) vs fresh prompt tokens, every run kept (median and range computed from them).
6"""
7import argparse, hashlib, json, statistics, time, urllib.request
8from pathlib import Path
9
10def call(base, prompt, max_tokens):
11    body = {"messages": [{"role": "user", "content": prompt}], "temperature": 0, "seed": 42,
12            "max_tokens": max_tokens, "cache_prompt": False}
13    req = urllib.request.Request(base + "/v1/chat/completions", data=json.dumps(body).encode(),
14                                 headers={"content-type": "application/json"})
15    t0 = time.perf_counter()
16    with urllib.request.urlopen(req, timeout=1800) as r:
17        d = json.load(r)
18    wall = time.perf_counter() - t0
19    t = d.get("timings", {})
20    text = d["choices"][0]["message"].get("content") or ""
21    return {"wall_s": round(wall, 3), "timings": t, "usage": d.get("usage"),
22            "finish_reason": d["choices"][0].get("finish_reason"),
23            "content_sha256": hashlib.sha256(text.encode()).hexdigest()}
24
25def summary(runs, key):
26    v = [r["timings"].get(key) for r in runs if r["timings"].get(key) is not None]
27    return {"median": statistics.median(v), "min": min(v), "max": max(v)} if v else None
28
29def main():
30    p = argparse.ArgumentParser(description=__doc__)
31    p.add_argument("--base", required=True)
32    p.add_argument("--label", required=True)
33    p.add_argument("--prompts", default=str(Path(__file__).parent / "prompts"))
34    p.add_argument("--sizes", default="short,medium,long")
35    p.add_argument("--runs", type=int, default=3)
36    p.add_argument("--warmup", type=int, default=1)
37    p.add_argument("--max-tokens", type=int, default=256)
38    p.add_argument("--out", required=True)
39    a = p.parse_args()
40    props = json.load(urllib.request.urlopen(a.base + "/props", timeout=30))
41    res = {"label": a.label, "build_info": props.get("build_info"), "model_path": props.get("model_path"),
42           "n_ctx": props.get("default_generation_settings", {}).get("n_ctx"), "max_tokens": a.max_tokens,
43           "sampling": "temperature 0, seed 42, cache_prompt false", "sizes": {}}
44    for size in a.sizes.split(","):
45        prompt = (Path(a.prompts) / f"{size}.txt").read_text(encoding="utf-8")
46        # The server reuses a matching prefix even with cache_prompt false, so every request starts with a unique
47        # line: each run then reads the whole prompt fresh (cache_n stays at the chat template's few tokens).
48        tag = lambda kind, i: f"[{a.label} {size} {kind} {i} {time.time_ns()}]\n"
49        warm = [call(a.base, tag("warmup", i) + prompt, a.max_tokens) for i in range(a.warmup)]
50        runs = []
51        for i in range(a.runs):
52            r = call(a.base, tag("run", i + 1) + prompt, a.max_tokens)
53            r["run"] = i + 1
54            runs.append(r)
55            t = r["timings"]
56            print(f"{a.label} {size} run {i+1}: prompt {t.get('prompt_n')} (+{t.get('cache_n')} reused) "
57                  f"{t.get('prompt_per_second')} tok/s, decode {t.get('predicted_n')} tok "
58                  f"{t.get('predicted_per_second')} tok/s, wall {r['wall_s']} s", flush=True)
59        res["sizes"][size] = {"warmup": warm, "runs": runs,
60                              "prompt_tps": summary(runs, "prompt_per_second"),
61                              "decode_tps": summary(runs, "predicted_per_second"),
62                              "prompt_ms": summary(runs, "prompt_ms")}
63    Path(a.out).write_text(json.dumps(res, indent=2), encoding="utf-8")
64    print("written", a.out)
65
66if __name__ == "__main__":
67    main()