okami.mom/strata

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

Niko1221Merge f-clean-3 (321794636): docs and history (cleanup step 3, items 3.0-3.10); release manifest and capability table with checks, history/ with pointers, link check, tools/ split, bench index; owner OK'd the wording 11-082b36e8a02

main
4.7 KiB107 linesraw
1#!/usr/bin/env python3
2"""One server, several repeats per cell: the warm-state runner (the per-start page cache and the tens-of-GB expert
3prefetch are the main variance sources on a unified-memory box, so repeats inside one server are the comparable ones).
4
5    python research/tools/dgx-spark-2026-10/dgx_warm.py CONFIG TAG OUTDIR [--cells 4096,16384,32768] [--repeats 3] [--port 8091] [--new 256]
6
7Writes <OUTDIR>/<TAG>.jsonl rows in tools/dgx_bench.py's schema (round, arm, len, temp, max_new, prompt_n,
8prompt_per_second, predicted_n, predicted_per_second, ttft_s, cache_n) so research/tools/dgx-spark-2026-10/dgx_compare.py reads them.
9"""
10import argparse
11import json
12import random
13import subprocess
14import sys
15import time
16import urllib.request
17from pathlib import Path
18
19ROOT = Path(__file__).resolve().parents[3]
20WORDS = ("river stone market lantern copper winter garden signal harbor needle orbit velvet canyon ember ledger quartz "
21         "meadow anchor violet thunder cedar marble piston ribbon cobalt falcon glacier hollow ivory juniper kernel").split()
22
23
24def prompt_for(tokens, nonce):
25    rng = random.Random(tokens)
26    body = " ".join(rng.choice(WORDS) for _ in range(max(8, int(tokens / 1.35))))
27    return (f"Request nonce {nonce}. Read the word list below carefully.\n\n{body}\n\n"
28            "Write a long, detailed analysis of the word list above. Keep writing for at least 400 words.")
29
30
31def post(port, prompt, max_new):
32    body = json.dumps({"messages": [{"role": "user", "content": prompt}], "max_tokens": max_new, "temperature": 0,
33                       "stream": False, "chat_template_kwargs": {"enable_thinking": False}}).encode()
34    req = urllib.request.Request(f"http://127.0.0.1:{port}/v1/chat/completions", data=body,
35                                 headers={"Content-Type": "application/json"})
36    t0 = time.time()
37    with urllib.request.urlopen(req, timeout=3600) as r:
38        out = json.loads(r.read())
39    return out, time.time() - t0
40
41
42def status(port):
43    try:
44        with urllib.request.urlopen(f"http://127.0.0.1:{port}/v1/status", timeout=10) as r:
45            return json.loads(r.read()).get("last_timings") or {}
46    except Exception:
47        return {}
48
49
50def main():
51    ap = argparse.ArgumentParser()
52    ap.add_argument("config")
53    ap.add_argument("tag")
54    ap.add_argument("outdir")
55    ap.add_argument("--cells", default="512,2048,4096")
56    ap.add_argument("--repeats", type=int, default=4)
57    ap.add_argument("--port", type=int, default=8091)
58    ap.add_argument("--new", type=int, default=256)
59    a = ap.parse_args()
60    out = Path(a.outdir)
61    out.mkdir(parents=True, exist_ok=True)
62    cfg = json.loads(Path(a.config).read_text())
63    cfg["port"] = a.port
64    cfg["log"] = str(out / f"{a.tag}.engine.log")
65    cpath = out / f"{a.tag}.config.json"
66    cpath.write_text(json.dumps(cfg, indent=1))
67    log = open(out / f"{a.tag}.jsonl", "a", encoding="utf-8")
68    proc = subprocess.Popen([sys.executable, str(ROOT / "serve" / "server.py"), "--engine", "strata", "--config",
69                             str(cpath), "--port", str(a.port)], cwd=str(ROOT),
70                            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
71    try:
72        t0 = time.time()
73        while time.time() - t0 < 3600:
74            if proc.poll() is not None:
75                raise SystemExit(f"server exited with {proc.returncode}")
76            try:
77                with urllib.request.urlopen(f"http://127.0.0.1:{a.port}/v1/models", timeout=5) as r:
78                    if r.status == 200:
79                        break
80            except Exception:
81                pass
82            time.sleep(3)
83        print(f"{a.tag}: ready in {time.time() - t0:.0f} s", flush=True)
84        post(a.port, prompt_for(256, "warm"), 8)
85        for rep in range(a.repeats):
86            for length in [int(x) for x in a.cells.split(",")]:
87                nonce = f"{random.getrandbits(48):012x}"
88                outj, wall = post(a.port, prompt_for(length, nonce), a.new)
89                t = status(a.port)
90                row = {"round": rep, "arm": a.tag, "len": length, "temp": 0.0, "max_new": a.new,
91                       "wall_s": round(wall, 2), "ttft_s": (t.get("prompt_ms") or 0) / 1000.0 or None,
92                       "cache_n": t.get("cache_n", 0), **t}
93                log.write(json.dumps(row) + "\n")
94                log.flush()
95                print(f"  {length:5d} prompt_n {t.get('prompt_n')} prompt {t.get('prompt_per_second')} tok/s "
96                      f"decode {t.get('predicted_per_second')} tok/s", flush=True)
97    finally:
98        proc.terminate()
99        try:
100            proc.wait(90)
101        except subprocess.TimeoutExpired:
102            proc.kill()
103        log.close()
104
105
106if __name__ == "__main__":
107    main()