okami.mom/strata

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

Niko1221Merge f-142b-serve into f-1426e1085c1d

main
3.1 KiB77 linesraw
1"""Strata community bench driver: sends prompts.jsonl (from gen.py) one at a time, records engine timings.
2
3usage: bench.py prompts.jsonl OUT.jsonl
4Streaming chat completions, temperature 0 (greedy), reasoning_effort none, 256-token cap. After each
5request the engine's own timings are read from /v1/status (last_timings), with RAM and VRAM use.
6"""
7
8import json
9import sys
10import time
11import urllib.request
12
13URL = "http://127.0.0.1:8086"
14MODEL = "strata-ista-iq3s"
15CAP = 256
16
17
18def status() -> dict:
19    with urllib.request.urlopen(URL + "/v1/status", timeout=30) as r:
20        return json.load(r)
21
22
23def request(content: str) -> dict:
24    body = {
25        "model": MODEL,
26        "stream": True,
27        "stream_options": {"include_usage": True},
28        "temperature": 0,
29        "reasoning_effort": "none",
30        "max_tokens": CAP,
31        "messages": [{"role": "user", "content": content}],
32    }
33    req = urllib.request.Request(URL + "/v1/chat/completions", data=json.dumps(body).encode(),
34                                 headers={"Content-Type": "application/json"})
35    t0_wall, t0 = time.time(), time.perf_counter()
36    t_first = None
37    usage, finish, reasoning_chars, answer_chars = {}, None, 0, 0
38    with urllib.request.urlopen(req, timeout=1800) as resp:
39        for raw in resp:
40            line = raw.decode().strip()
41            if not line.startswith("data:") or line == "data: [DONE]":
42                continue
43            ev = json.loads(line[5:])
44            usage = ev.get("usage") or usage
45            for ch in ev.get("choices") or []:
46                d = ch.get("delta") or {}
47                a, r = d.get("content") or "", d.get("reasoning_content") or ""
48                if (a or r) and t_first is None:
49                    t_first = time.perf_counter()
50                answer_chars += len(a)
51                reasoning_chars += len(r)
52                finish = ch.get("finish_reason") or finish
53    t1 = time.perf_counter()
54    st = status()
55    lt = st.get("last_timings") or {}
56    machine = st.get("machine") or {}
57    return {
58        "t_start": round(t0_wall, 3), "t_end": round(time.time(), 3),
59        "prompt_tokens": usage.get("prompt_tokens"), "completion_tokens": usage.get("completion_tokens"),
60        "finish_reason": finish, "answer_chars": answer_chars, "reasoning_chars": reasoning_chars,
61        "ttft_s": round(t_first - t0, 3) if t_first else None, "total_s": round(t1 - t0, 3),
62        "engine": {k: lt.get(k) for k in ("cache_n", "prompt_n", "prompt_ms", "prompt_per_second",
63                                          "predicted_n", "predicted_ms", "predicted_per_second",
64                                          "draft_n", "draft_n_accepted")},
65        "ram_used_gib": machine.get("ram", {}).get("used_gib"),
66        "gpu_used_mib": machine.get("gpu", {}).get("used_mib"),
67    }
68
69
70prompts = [json.loads(line) for line in open(sys.argv[1])]
71with open(sys.argv[2], "a") as out:
72    for p in prompts:
73        rec = {k: p[k] for k in ("label", "target", "counted", "offset", "content_tokens")}
74        rec.update(request(p["content"]))
75        print(json.dumps(rec), flush=True)
76        out.write(json.dumps(rec) + "\n")
77print("BENCH_DONE", flush=True)