okami.mom/strata

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

gravitomagneticbench: community report — RTX 5090, IQ3_S at 1M context (YaRN), agent-style workload (#466)f129082f0

main
5.4 KiB143 linesraw
1#!/usr/bin/env python3
2"""Community benchmark: Strata at 1M context under an agent-like workload.
3
4Follows docs/COMMUNITY_BENCHMARKS.md conventions:
5- prompt and decode throughput come from the server's own `timings` block,
6  never from dividing tokens by wall time;
7- time to first token (TTFT) is measured at the client on the first
8  non-empty streamed delta (reasoning or answer text — flagged per run);
9- each size runs three fresh prompts plus one immediate repeat (warm prefix
10  reuse), plus one greedy no-thinking run;
11- actual prompt token counts are reported from the server, since the
12  synthetic prompt length is only approximate.
13
14Writes one JSON record per run to the file given as argv[1]
15(default: agent_bench.jsonl). Contains no credentials.
16
17Requires a running server on 127.0.0.1:8080 (edit SERVER_URL if needed).
18"""
19
20import json
21import sys
22import time
23import urllib.request
24
25SERVER_URL = "http://127.0.0.1:8080/v1/chat/completions"
26MODEL = "qwen3.8-flash-next-iq3_s"
27
28# A paragraph of plain English; repeated to build synthetic prompts.
29PARAGRAPH = (
30    "The lighthouse keeper recorded the weather each hour: "
31    "wind from the northwest, sea moderate, visibility good. "
32)
33# Rough paragraphs-per-token for this text; the real count is reported by
34# the server in `prompt_n`, so this only sizes the request.
35PARAGRAPHS_PER_TOKEN = 22
36
37TASK_SUFFIX = "\n\nSummarize the pattern in these records in two sentences."
38
39
40def build_prompt(target_tokens: int) -> str:
41    paragraphs = target_tokens // PARAGRAPHS_PER_TOKEN + 2
42    return PARAGRAPH * paragraphs + TASK_SUFFIX
43
44
45def _first_delta(chunk: dict) -> dict:
46    """The streamed delta of a chunk, defensively typed (malformed chunks
47    simply yield {}, which the caller treats as 'no token yet')."""
48    choices = chunk.get("choices")
49    if isinstance(choices, list) and choices and isinstance(choices[0], dict):
50        delta = choices[0].get("delta")
51        return delta if isinstance(delta, dict) else {}
52    return {}
53
54
55def run_once(prompt: str, *, max_tokens: int, temperature: float | None,
56             top_p: float | None, thinking: bool) -> dict:
57    """Stream one chat completion; return the server's timings plus client TTFT."""
58    payload = {
59        "model": MODEL,
60        "messages": [{"role": "user", "content": prompt}],
61        "max_tokens": max_tokens,
62        "stream": True,
63    }
64    if temperature is not None:
65        payload["temperature"] = temperature
66    if top_p is not None:
67        payload["top_p"] = top_p
68    if not thinking:
69        payload["chat_template_kwargs"] = {"enable_thinking": False}
70
71    request = urllib.request.Request(
72        SERVER_URL,
73        data=json.dumps(payload).encode("utf-8"),
74        headers={"Content-Type": "application/json"},
75    )
76
77    started = time.monotonic()
78    ttft_s = None
79    last_chunk: dict = {}
80    with urllib.request.urlopen(request, timeout=900) as response:
81        for line in response:
82            if not line.startswith(b"data: "):
83                continue
84            data = line[len(b"data: "):].strip()
85            if data == b"[DONE]":
86                break
87            chunk = json.loads(data)
88            if isinstance(chunk, dict):
89                last_chunk = chunk
90            if ttft_s is None:
91                delta = _first_delta(chunk if isinstance(chunk, dict) else last_chunk)
92                if delta.get("content") or delta.get("reasoning_content"):
93                    ttft_s = time.monotonic() - started
94
95    if not last_chunk:
96        raise RuntimeError("server streamed no completion chunks")
97    timings = last_chunk.get("timings") or {}
98
99    record = {
100        "t_wall_s": round(time.monotonic() - started, 3),
101        "ttft_s": round(ttft_s, 3) if ttft_s is not None else None,
102        "thinking": thinking,
103        "temperature": temperature,
104        "prompt_n": timings.get("prompt_n"),
105        "prompt_ms": timings.get("prompt_ms"),
106        "predicted_n": timings.get("predicted_n"),
107        "predicted_ms": timings.get("predicted_ms"),
108        "cache_n": timings.get("cache_n"),
109        "prompt_per_second": timings.get("prompt_per_second"),
110        "predicted_per_second": timings.get("predicted_per_second"),
111    }
112    return record
113
114
115def main() -> None:
116    out_path = sys.argv[1] if len(sys.argv) > 1 else "agent_bench.jsonl"
117    sizes = (4096, 32768, 131072, 524288)
118    with open(out_path, "w", encoding="utf-8") as out:
119        for size in sizes:
120            prompt = build_prompt(size)
121            for run_index in range(1, 4):
122                record = run_once(prompt, max_tokens=256,
123                                  temperature=1.0, top_p=0.95, thinking=True)
124                record["tag"] = f"think_{size}_run{run_index}"
125                out.write(json.dumps(record) + "\n")
126                out.flush()
127            # Immediate repeat: exercises prefix reuse (see cache_n / prompt_n).
128            record = run_once(prompt, max_tokens=256,
129                              temperature=1.0, top_p=0.95, thinking=True)
130            record["tag"] = f"think_{size}_warm_repeat"
131            out.write(json.dumps(record) + "\n")
132            out.flush()
133            # Instruct mode: greedy, thinking suppressed at the template.
134            record = run_once(prompt, max_tokens=256,
135                              temperature=0.0, top_p=None, thinking=False)
136            record["tag"] = f"instruct_{size}_greedy"
137            out.write(json.dumps(record) + "\n")
138            out.flush()
139    print(f"wrote {out_path}")
140
141
142if __name__ == "__main__":
143    main()