okami.mom/strata

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

Amboliobench: community report, RTX 5090 + Ryzen 9 9950X3D, IQ3_S at the full 262K window; prefill auto:32768 A/B; conversation-cache 32 GiB demo (#440)263c99b96

main
3.6 KiB79 linesraw
1"""Conversation-cache demo: two long agent-style conversations interleaved through the live server.
2
3The engine's `--conversation-cache-mib` defaults to 0 (off): every follow-up re-reads the whole
4conversation. With 32 GiB / 8 slots (our production config), a follow-up restores the parked K/V
5instead. This script runs five requests — doc A, doc B, follow-up on A, follow-up on B, second
6follow-up on A — and reports, per request, the reused tokens (`usage.prompt_tokens_details.cached_tokens`),
7the freshly read tokens and the wall time, plus the engine's own `restored/parked` log lines.
8
9    python bench/results/2026-10-02-community-rtx-5090-iq3s/conversation_cache_demo.py
10"""
11from __future__ import annotations
12
13import json
14import re
15import sys
16import time
17import urllib.request
18from pathlib import Path
19
20ROOT = Path(__file__).resolve().parents[3]
21sys.path.insert(0, str(ROOT / "tools"))
22from needle_bench import haystack, CHARS_PER_TOKEN  # noqa: E402
23
24URL = "http://127.0.0.1:8080/v1/chat/completions"
25MODEL = "qwen3.8-flash-next-iq3_s"
26LOG = ROOT / "strata-iq3_s.log"
27DOC_TOKENS = 60_000
28
29
30def ask(messages) -> dict:
31    body = {"model": MODEL, "max_tokens": 128, "temperature": 0,
32            "chat_template_kwargs": {"enable_thinking": False}, "messages": messages}
33    req = urllib.request.Request(URL, data=json.dumps(body).encode(), headers={"Content-Type": "application/json"})
34    t0 = time.time()
35    with urllib.request.urlopen(req, timeout=1200) as r:
36        out = json.load(r)
37    u = out["usage"]
38    return {"prompt_tokens": u["prompt_tokens"], "cached_tokens": (u.get("prompt_tokens_details") or {}).get("cached_tokens", 0),
39            "completion_tokens": u["completion_tokens"], "seconds": round(time.time() - t0, 2),
40            "answer": (out["choices"][0]["message"].get("content") or "")[:120]}
41
42
43def main() -> int:
44    base = int(time.time()) % 20_000_000          # a fresh text window per run, printed for reproducibility
45    print(f"haystack window base: {base}")
46    n = int(DOC_TOKENS * CHARS_PER_TOKEN)
47    doc_a = haystack(n + base)[base:]
48    doc_b = haystack(n + base + 5_000_003)[base + 5_000_003:]
49    q = "\n\nIn three sentences: what kinds of files make up the text above?"
50    fu1 = "\n\nAnd which of those file types would I edit to change compiler flags?"
51    fu2 = "\n\nGive one concrete example of a line you would change there."
52
53    conv_a, conv_b, rows = [], [], []
54    steps = ["A1 fresh doc A", "B1 fresh doc B", "A2 follow-up on A", "B2 follow-up on B",
55             "A3 follow-up on A again"]
56    for name in steps:
57        conv = conv_a if name.startswith("A") else conv_b
58        if name.startswith("A1"):
59            conv.append(("user", doc_a + q))
60        elif name.startswith("B1"):
61            conv.append(("user", doc_b + q))
62        else:
63            conv.append(("user", fu1 if name[1] == "2" else fu2))
64        msgs = list(conv)
65        mark = len(LOG.read_text(encoding="utf-8", errors="replace"))
66        r = ask([{"role": m[0], "content": m[1]} for m in msgs])
67        conv.append(("assistant", r["answer"]))
68        new = [l for l in re.findall(r"strata serve: (?:conversation cache:|prompt) [^\n]*", LOG.read_text(encoding="utf-8", errors="replace")[mark:])]
69        r["step"], r["engine_lines"] = name, new
70        rows.append(r)
71        print(f"{name:24} prompt {r['prompt_tokens']:>7,}  reused {r['cached_tokens']:>7,}  "
72              f"fresh {r['prompt_tokens'] - r['cached_tokens']:>6,}  {r['seconds']:>6.2f} s", flush=True)
73    Path(__file__).with_name("demo.json").write_text(json.dumps(rows, indent=1), encoding="utf-8")
74    print("wrote demo.json")
75    return 0
76
77
78if __name__ == "__main__":
79    sys.exit(main())