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.6 KiB81 linesraw
1#!/usr/bin/env python3
2"""Live parity check for STRATA_SPLIT_MTP_BATCH (needs a running engine; no model on the build box).
3
4  split_mtp_batch_parity.py dump OUT.json [--url URL] [--key-file FILE] [--long-words N]
5  split_mtp_batch_parity.py compare A.json B.json
6
7`dump` sends 5 fixed greedy prompts x 256 tokens and one long prompt (default ~25k tokens) x 256 tokens to a
8server started WITHOUT the env (A) or WITH STRATA_SPLIT_MTP_BATCH=1 (B), and stores the texts.  `compare` exits 0
9when every text is identical, 1 otherwise, printing PASS/FAIL lines.  The drafter's K/V is not bit-identical
10(Q8_1 x Q8_0 MMQ instead of mmvq), so only the target's tokens are compared here; read `drafts accepted X of Y`
11from the engine log for each arm (expect within +-3 points).
12"""
13import json
14import sys
15import urllib.request
16
17PROMPTS = [
18    "Write a 200 word story about a lighthouse keeper who finds a message in a bottle.",
19    "Explain how a binary search tree stays balanced, with a short Python example.",
20    "List the planets of the solar system with one fact each.",
21    "Translate to French and then explain the grammar: 'The quick brown fox jumps over the lazy dog.'",
22    "Write a C function that reverses a singly linked list and explain its complexity.",
23]
24
25
26def haystack(n_entries):
27    w = ["amber", "birch", "cedar", "delta", "ember", "fjord", "grove", "harbor", "iris", "juniper"]
28    return "\n".join(
29        f"Entry {i}: the {w[(i * 3) % 10]} station {(i * 7) % 997} logged a reading of {(i * 31) % 1009}."
30        for i in range(n_entries)
31    )
32
33
34def ask(url, key, content, n):
35    body = json.dumps({"model": "qwen3.8-flash-next-ud-q4_k_xl", "messages": [{"role": "user", "content": content}],
36                       "max_tokens": n, "temperature": 0.0, "chat_template_kwargs": {"enable_thinking": False}}).encode()
37    hdr = {"Content-Type": "application/json"}
38    if key:
39        hdr["Authorization"] = "Bearer " + key
40    d = json.load(urllib.request.urlopen(urllib.request.Request(url, body, hdr), timeout=3600))
41    return d["choices"][0]["message"]["content"], d["usage"]
42
43
44def main(argv):
45    if len(argv) >= 3 and argv[0] == "compare":
46        a, b = (json.load(open(p)) for p in argv[1:3])
47        bad = 0
48        for k in a:
49            same = a[k]["text"] == b.get(k, {}).get("text")
50            print(("PASS" if same else "FAIL"), k, f"({a[k]['completion_tokens']} vs {b.get(k, {}).get('completion_tokens')} tokens)")
51            bad += not same
52        print("PARITY", "OK" if not bad else f"BROKEN ({bad} differ)")
53        return 1 if bad else 0
54    if len(argv) >= 2 and argv[0] == "dump":
55        url = "http://127.0.0.1:8000/v1/chat/completions"
56        key = None
57        words = 1100
58        i = 2
59        while i < len(argv):
60            if argv[i] == "--url":
61                url = argv[i + 1]
62            elif argv[i] == "--key-file":
63                key = open(argv[i + 1]).read().strip()
64            elif argv[i] == "--long-words":
65                words = int(argv[i + 1])
66            i += 2
67        out = {}
68        for n, p in enumerate(PROMPTS):
69            t, u = ask(url, key, p, 256)
70            out[f"short{n}"] = {"text": t, "completion_tokens": u["completion_tokens"], "prompt_tokens": u["prompt_tokens"]}
71        t, u = ask(url, key, "Summarise the log below in three sentences.\n" + haystack(words), 256)
72        out["long"] = {"text": t, "completion_tokens": u["completion_tokens"], "prompt_tokens": u["prompt_tokens"]}
73        json.dump(out, open(argv[1], "w"), indent=1)
74        print({k: v["prompt_tokens"] for k, v in out.items()})
75        return 0
76    print(__doc__)
77    return 2
78
79
80if __name__ == "__main__":
81    sys.exit(main(sys.argv[1:]))