okami.mom/strata

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

Efs-Obench: community results, 2x RTX 5060 Ti 16 GB (PCIe gen3), Strata 0.1.34 (#483)99b9311c1

main
5.5 KiB111 linesraw
1"""Strata speed test following docs/COMMUNITY_BENCHMARKS.md.
2
3Three conditions, 3 measured runs each after one unmeasured warm-up, output capped at 256 tokens:
4  short       104-token prompt, fully processed (a unique first line defeats prefix reuse)
5  long-cold   ~21K-token prompt, fully processed (unique first line)
6  long-reuse  the same ~21K prefix as the previous request, new question at the end
7Throughput comes from the engine's own timings (prompt_ms / predicted_ms); TTFT and total
8latency are measured at the client. The engine's log lines for each request are kept.
9
10Usage: python speed_bench.py <folder of .ts files used as filler text> <path to the strata serve log>
11"""
12import json, pathlib, subprocess, sys, time, urllib.request, uuid
13
14URL = "http://127.0.0.1:8080/v1/chat/completions"
15if len(sys.argv) != 3:
16    sys.exit(__doc__)
17SRC = pathlib.Path(sys.argv[1])  # a folder of .ts files, used as filler text
18LOG = pathlib.Path(sys.argv[2])  # the log file named in the run configuration
19OUT = pathlib.Path(__file__).with_name("runs.json")
20MAX_TOKENS = 256
21
22
23def filler(chars):
24    parts, n = [], 0
25    for p in sorted(SRC.rglob("*.ts")):
26        t = p.read_text(encoding="utf-8", errors="replace")
27        parts.append(f"// ===== {p.name} =====\n{t}")
28        n += len(t)
29        if n > chars:
30            break
31    return "\n".join(parts)
32
33
34def vram():
35    q = subprocess.run(["nvidia-smi", "--query-gpu=index,memory.used", "--format=csv,noheader,nounits"],
36                       capture_output=True, text=True).stdout.split("\n")
37    return {f"gpu{l.split(',')[0].strip()}_mib": int(l.split(",")[1]) for l in q if l.strip()}
38
39
40def call(label, messages):
41    log_pos = LOG.stat().st_size
42    body = {"model": "x", "messages": messages, "max_tokens": MAX_TOKENS, "stream": True, "temperature": 0.6,
43            "stream_options": {"include_usage": True}}
44    req = urllib.request.Request(URL, json.dumps(body).encode(), {"Content-Type": "application/json"})
45    t0 = time.perf_counter(); first = None; first_kind = None; text = []; reasoning = []; timings = usage = None
46    with urllib.request.urlopen(req, timeout=1800) as r:
47        for raw in r:
48            line = raw.decode("utf-8", "replace").strip()
49            if not line.startswith("data:") or line == "data: [DONE]":
50                continue
51            ev = json.loads(line[5:])
52            timings = ev.get("timings") or timings
53            usage = ev.get("usage") or usage
54            for ch in ev.get("choices", []):
55                d = ch.get("delta", {})
56                rc = d.get("reasoning_content") or d.get("reasoning")
57                if (d.get("content") or rc) and first is None:
58                    first, first_kind = time.perf_counter(), ("reasoning" if rc else "answer")
59                if rc: reasoning.append(rc)
60                if d.get("content"): text.append(d["content"])
61    t1 = time.perf_counter()
62    time.sleep(1.0)
63    with LOG.open("rb") as f:
64        f.seek(log_pos)
65        log_lines = [l for l in f.read().decode("utf-8", "replace").splitlines() if l.startswith("strata serve:")]
66    t = timings or {}
67    row = {
68        "label": label,
69        "prompt_tokens": (usage or {}).get("prompt_tokens"),
70        "reused_tokens": t.get("cache_n"), "read_tokens": t.get("prompt_n"), "prompt_ms": t.get("prompt_ms"),
71        "prompt_tok_s": t.get("prompt_per_second"),
72        "generated_tokens": t.get("predicted_n"), "decode_ms": t.get("predicted_ms"),
73        "decode_tok_s": t.get("predicted_per_second"),
74        "draft_n": t.get("draft_n"), "draft_accepted": t.get("draft_n_accepted"),
75        "ttft_s": round((first or t1) - t0, 3), "first_token_kind": first_kind,
76        "total_latency_s": round(t1 - t0, 3),
77        "vram_after": vram(),
78        "engine_log": log_lines,
79        "reasoning_chars": len("".join(reasoning)), "answer": "".join(text),
80    }
81    print(f"{label:14s} read {row['read_tokens']:>6} reused {row['reused_tokens']:>6} | prompt {row['prompt_tok_s']:7.1f} t/s"
82          f" | decode {row['generated_tokens']} tok {row['decode_tok_s']:5.1f} t/s | TTFT {row['ttft_s']:6.2f}s total {row['total_latency_s']:6.2f}s",
83          flush=True)
84    return row
85
86
87def main():
88    ask = "Write a TypeScript function that parses a unified diff into hunks. Code only."
89    big = filler(80_000)
90    q = "Above is part of a codebase. In 5 bullet points, name the main modules and what each does."
91    runs = []
92    call("warm-up", [{"role": "user", "content": f"run {uuid.uuid4()}\n" + ask}])
93    for i in range(3):
94        runs.append(call(f"short-{i+1}", [{"role": "user", "content": f"run {uuid.uuid4()}\n" + ask}]))
95    for i in range(3):
96        prefix = f"run {uuid.uuid4()}\n" + big
97        runs.append(call(f"long-cold-{i+1}", [{"role": "user", "content": prefix + "\n\n" + q}]))
98        runs.append(call(f"long-reuse-{i+1}", [{"role": "user", "content": prefix + "\n\nList the 3 largest files you saw."}]))
99    OUT.write_text(json.dumps({"date": time.strftime("%Y-%m-%d %H:%M"), "max_tokens": MAX_TOKENS,
100                               "temperature": 0.6, "runs": runs}, indent=1), encoding="utf-8")
101
102    def summary(prefix, key):
103        v = sorted(r[key] for r in runs if r["label"].startswith(prefix) and r[key] is not None)
104        return f"median {v[len(v)//2]:.1f} (range {v[0]:.1f}-{v[-1]:.1f}, n={len(v)})" if v else "n/a"
105    for c in ("short", "long-cold", "long-reuse"):
106        print(f"\n{c}: prompt t/s {summary(c, 'prompt_tok_s')} | decode t/s {summary(c, 'decode_tok_s')}"
107              f" | TTFT s {summary(c, 'ttft_s')} | total s {summary(c, 'total_latency_s')}")
108
109
110if __name__ == "__main__":
111    main()