okami.mom/strata

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

Niko1221Merge f-141-fixb: Python, docs and bench fixes and portsef8071303

main
3.8 KiB98 linesraw
1#!/usr/bin/env python3
2"""bench_report.py — community-report battery for the V100+P100 helper rig.
3
4Fresh salted prompts (no prefix reuse), output cap 256 tokens, greedy,
5reasoning_effort none (matches other community reports), streaming TTFT.
6Sizes: ~550 / ~13.5K / ~33K x3 runs; ~90K x1 (single run, marked).
7Saves per-run results to /root/benchpr-results.json and prints them.
8"""
9import json, sys, time, urllib.request
10
11BASE = "http://127.0.0.1:8082"
12OUT = "/root/benchpr-results.json"
13unit = "The following is a technical report excerpt that must be summarized. "
14
15TASK = ("\n\nTask: using general knowledge (the excerpt above is filler), explain in "
16        "about 220 words how TCP congestion control works, covering slow start, congestion "
17        "avoidance, fast retransmit and fast recovery, with rough numbers. Plain text.")
18
19def run(tag, rep, n=256, timeout=2400):
20    salt = f"[{tag}-{time.time_ns()}] "
21    prompt = salt + unit * rep + TASK
22    body = json.dumps({
23        "model": "q",
24        "messages": [{"role": "user", "content": prompt}],
25        "max_tokens": n, "temperature": 0, "stream": True,
26        "reasoning_effort": "none",
27    }).encode()
28    req = urllib.request.Request(BASE + "/v1/chat/completions", data=body,
29                                 headers={"Content-Type": "application/json"})
30    t0 = time.time()
31    ttft = None
32    content = ""
33    timings = None
34    usage = None
35    with urllib.request.urlopen(req, timeout=timeout) as r:
36        for raw in r:
37            line = raw.decode("utf-8", "ignore").strip()
38            if not line.startswith("data:"):
39                continue
40            payload = line[5:].strip()
41            if payload == "[DONE]":
42                break
43            try:
44                d = json.loads(payload)
45            except Exception:
46                continue
47            ch = d.get("choices") or []
48            if ch:
49                delta = ch[0].get("delta") or {}
50                txt = delta.get("content")
51                if txt:
52                    if ttft is None:
53                        ttft = time.time() - t0
54                    content += txt
55            if d.get("timings"):
56                timings = d["timings"]
57            if d.get("usage"):
58                usage = d["usage"]
59    wall = time.time() - t0
60    res = {
61        "tag": tag, "rep": rep,
62        "ttft_s": round(ttft, 3) if ttft is not None else None,
63        "wall_s": round(wall, 2),
64        "ttft_is_first_content_delta": True,
65        "timings": timings, "usage": usage,
66        "out_chars": len(content),
67        "out_head": content[:120],
68    }
69    print(json.dumps({k: res[k] for k in ("tag", "ttft_s", "wall_s")}
70                     | {"pn": (timings or {}).get("prompt_n"),
71                        "reused": (timings or {}).get("cache_n"),
72                        "gen": (timings or {}).get("predicted_n"),
73                        "ptps": round((timings or {}).get("prompt_per_second", 0), 1),
74                        "dtps": round((timings or {}).get("predicted_per_second", 0), 1)}), flush=True)
75    return res
76
77def main():
78    print(f"=== BENCH REPORT START {time.strftime('%Y-%m-%d %H:%M:%S')} ===", flush=True)
79    results = []
80
81    # warm-up (not part of results)
82    w = run("warmup", 60, n=64)
83    print("warmup done", flush=True)
84    results.append(dict(w, tag="warmup", counted=False))
85
86    sizes = [("tokens550", 60, 3), ("tokens13500", 1490, 3), ("tokens33000", 3660, 3), ("tokens90000", 9970, 1)]
87    for name, rep, reps in sizes:
88        for i in range(reps):
89            r = run(f"{name}-run{i+1}", rep)
90            r["counted"] = True
91            results.append(r)
92
93    with open(OUT, "w") as f:
94        json.dump(results, f, indent=1)
95    print(f"=== BENCH REPORT DONE {time.strftime('%Y-%m-%d %H:%M:%S')} -> {OUT} ===", flush=True)
96
97if __name__ == "__main__":
98    main()