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
3.1 KiB70 linesraw
1#!/usr/bin/env python3
2"""Clean long-context decode comparison: same 47K-token prompt, but a request that generates ~200 tokens in both cases, so
3the decode rate is not dominated by per-request overhead. Compares --kv-resident 32768 against 65536.
4
5    python dgx_kvresident2.py OUT.json [--tokens 47000]
6"""
7import json
8import random
9import subprocess
10import sys
11import time
12import urllib.request
13from pathlib import Path
14
15ROOT = Path(__file__).resolve().parents[3]
16root = Path.home() / "workspace" / "strata-spark"
17WORDS = ("river stone market lantern copper winter garden signal harbor needle orbit velvet canyon ember ledger quartz "
18         "meadow anchor violet thunder cedar marble piston ribbon cobalt falcon glacier hollow ivory juniper kernel").split()
19
20
21def build(tokens, rng):
22    body = [rng.choice(WORDS) for _ in range(int(tokens / 1.35))]
23    return ("Read the following log carefully.\n\n" + " ".join(body) +
24            "\n\nWrite a detailed 250-word analysis of the vocabulary and tone of the log above. Do not stop early.")
25
26
27def run(cfg_name, tag, port=8091):
28    cfg = json.loads((root / cfg_name).read_text())
29    cfg["port"] = port
30    cfg["log"] = f"/tmp/kvres2-{tag}.log"
31    tmp = Path(f"/tmp/kvres2-{tag}.json")
32    tmp.write_text(json.dumps(cfg, indent=1))
33    proc = subprocess.Popen([sys.executable, str(ROOT / "serve" / "server.py"), "--engine", "strata", "--config",
34                             str(tmp), "--port", str(port)], cwd=str(ROOT),
35                            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
36    try:
37        t0 = time.time()
38        while time.time() - t0 < 1800:
39            if proc.poll() is not None:
40                raise SystemExit(f"server exited {proc.returncode}")
41            try:
42                with urllib.request.urlopen(f"http://127.0.0.1:{port}/v1/models", timeout=5) as r:
43                    if r.status == 200:
44                        break
45            except Exception:
46                pass
47            time.sleep(3)
48        prompt = build(int(sys.argv[2]) if len(sys.argv) > 2 else 47000, random.Random(7))
49        body = json.dumps({"messages": [{"role": "user", "content": prompt}], "max_tokens": 256, "temperature": 0,
50                           "chat_template_kwargs": {"enable_thinking": False}}).encode()
51        req = urllib.request.Request(f"http://127.0.0.1:{port}/v1/chat/completions", data=body,
52                                     headers={"Content-Type": "application/json"})
53        with urllib.request.urlopen(req, timeout=3600) as r:
54            out = json.loads(r.read())
55        t = out.get("timings") or {}
56        return {"kv_resident": cfg["args"][cfg["args"].index("--kv-resident") + 1],
57                "prompt_n": t.get("prompt_n"), "prompt_per_second": t.get("prompt_per_second"),
58                "predicted_n": t.get("predicted_n"), "predicted_per_second": t.get("predicted_per_second")}
59    finally:
60        proc.terminate()
61        try:
62            proc.wait(180)
63        except subprocess.TimeoutExpired:
64            proc.kill()
65
66
67rows = [run("strata-iq3_s.json", "a"), run("strata-iq3s-kv64k.json", "b")]
68Path(sys.argv[1]).write_text(json.dumps(rows, indent=1))
69for r in rows:
70    print(json.dumps(r))