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
5.0 KiB109 linesraw
1#!/usr/bin/env python3
2"""A wider identity gate than research/tools/dgx-spark-2026-10/dgx_quality.py's five: 24 prompts across code, prose, math, multilingual and tool-shaped
3asks, greedy, comparing the fused prompt path against MMQ byte for byte.
4
5    python quality24.py CONFIG_A CONFIG_B OUT.json [--port 8091]
6"""
7import json
8import subprocess
9import sys
10import time
11import urllib.request
12from pathlib import Path
13
14ROOT = Path(__file__).resolve().parents[3]
15PROMPTS = [
16    "Write a Python function that returns the longest palindromic substring of a string, with a docstring.",
17    "In C, what does `static inline` mean at file scope and when should it be used? Two sentences.",
18    "Explain the difference between a mutex and a semaphore to a junior developer, in under 100 words.",
19    "Translate 'The server is down and we are investigating' into German, French and Spanish, one line each.",
20    "Summarise the plot of Pride and Prejudice in exactly three sentences.",
21    "What is the time complexity of building a binary heap, and why?",
22    "Write a SQL query that returns the five customers with the highest total order value.",
23    "List four failure modes of a distributed lock and one mitigation each, as a table.",
24    "给一个刚学编程的人解释什么是递归,100字以内。",
25    "Erkläre den Unterschied zwischen TCP und UDP in drei Sätzen.",
26    "Écris une fonction JavaScript qui inverse une chaîne sans utiliser reverse().",
27    "What happens in a Linux system when you run `rm -rf /` as root? Be technical and brief.",
28    "Give me a shell one-liner that finds the ten largest files under /var/log.",
29    "Why does a transformer need positional encodings? Answer in two sentences.",
30    "Write a haiku about a GPU fan spinning up.",
31    "What is the difference between `git rebase` and `git merge` for a shared branch? Two sentences.",
32    "Explain Bloom filters and give one production use case, under 80 words.",
33    "Sort these numbers ascending and show the result: 42, 7, 19, 3, 88, 15.",
34    "What does the error `CUDA error: an illegal memory access was encountered` usually mean?",
35    "Describe how to measure the power draw of a single process on Linux.",
36    "Write a regex that matches ISO-8601 dates and explain each part.",
37    "What is the difference between a process and a thread in one sentence?",
38    "Give me a JSON object with three fields describing a book, and no prose.",
39    "Explain why 0.1 + 0.2 != 0.3 in floating point, briefly.",
40]
41
42
43def wait(port, proc):
44    t0 = time.time()
45    while time.time() - t0 < 900:
46        if proc.poll() is not None:
47            raise SystemExit(f"server exited {proc.returncode}")
48        try:
49            with urllib.request.urlopen(f"http://127.0.0.1:{port}/v1/models", timeout=5) as r:
50                if r.status == 200:
51                    return
52        except Exception:
53            pass
54        time.sleep(3)
55    raise SystemExit("server did not come up")
56
57
58def ask(port, prompt, max_new=96):
59    body = json.dumps({"messages": [{"role": "user", "content": prompt}], "max_tokens": max_new, "temperature": 0,
60                       "chat_template_kwargs": {"enable_thinking": False}}).encode()
61    req = urllib.request.Request(f"http://127.0.0.1:{port}/v1/chat/completions", data=body,
62                                 headers={"Content-Type": "application/json"})
63    with urllib.request.urlopen(req, timeout=1800) as r:
64        out = json.loads(r.read())
65    return out["choices"][0]["message"].get("content", "")
66
67
68def run_config(cfg_path, port, tag):
69    cfg = json.loads(Path(cfg_path).read_text())
70    cfg["port"] = port
71    cfg["log"] = f"/tmp/quality24-{tag}.log"
72    tmp = Path(f"/tmp/quality24-{tag}.json")
73    tmp.write_text(json.dumps(cfg, indent=1))
74    proc = subprocess.Popen([sys.executable, str(ROOT / "serve" / "server.py"), "--engine", "strata", "--config",
75                             str(tmp), "--port", str(port)], cwd=str(ROOT),
76                            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
77    answers = []
78    try:
79        wait(port, proc)
80        ask(port, "Say hi.", 8)
81        for p in PROMPTS:
82            answers.append(ask(port, p))
83    finally:
84        proc.terminate()
85        try:
86            proc.wait(120)
87        except subprocess.TimeoutExpired:
88            proc.kill()
89    return answers
90
91
92def main():
93    a_cfg, b_cfg, out_json = sys.argv[1], sys.argv[2], sys.argv[3]
94    port = int(sys.argv[4]) if len(sys.argv) > 4 else 8091
95    a = run_config(a_cfg, port, "a")
96    b = run_config(b_cfg, port, "b")
97    same = sum(1 for x, y in zip(a, b) if x == y)
98    rows = [{"prompt": p, "a": x, "b": y, "identical": x == y} for p, x, y in zip(PROMPTS, a, b)]
99    Path(out_json).write_text(json.dumps({"identical": same, "total": len(PROMPTS), "rows": rows}, indent=1))
100    print(f"{same} of {len(PROMPTS)} answers identical")
101    for i, r in enumerate(rows):
102        if not r["identical"]:
103            print(f"  differs at prompt {i}: {r['prompt'][:60]!r}")
104            print(f"    A: {r['a'][:90]!r}")
105            print(f"    B: {r['b'][:90]!r}")
106
107
108if __name__ == "__main__":
109    main()