okami.mom/strata

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

waveringanaserve: restore the DeepSeek V4.1 server paths, tools and headers removed upstream, keeping the native picture tower firstba8745e13

main
4.3 KiB104 linesraw
1"""16 tokens of a fixed prompt through strata-dsv41 and a check of the TEXT (setup runs this once after the pack is built).
2
3    python tools/dsv41/smoke.py --exe strata-dsv41 --pack <pack> [--gpus 0] [--tokens 16]
4
5A pack that loads can still give garbage (a wrong pack recipe does exactly that), so the answer is read, not just the exit code:
6the model is asked for the capital of France and the reply must be words, with "Paris" in it.  Exit 0 and the text on success; exit 1
7and one plain line (and the engine's last lines) when the reply is not sensible; exit 2 when the engine did not run at all.
8"""
9from __future__ import annotations
10
11import argparse
12import json
13import os
14import re
15import subprocess
16import sys
17import tempfile
18from pathlib import Path
19
20ROOT = Path(__file__).resolve().parents[2]
21sys.path.insert(0, str(ROOT / "tools"))
22
23PROMPT = "<|begin▁of▁sentence|><|User|>What is the capital of France? Answer in one short sentence.<|Assistant|></think>"
24
25
26def tokenizer(pack: Path):
27    import strata_tokenizer as ST
28    tpath = pack / "tokenizer"
29    vocab = json.loads((tpath / "vocab.json").read_text(encoding="utf-8"))
30    tokens = [None] * len(vocab)
31    for t, i in vocab.items():
32        tokens[i] = t
33    merges = (tpath / "merges.txt").read_text(encoding="utf-8").split("\n")
34    types = json.loads((tpath / "token_type.json").read_text())
35    tcfg = {}
36    try:
37        tcfg = json.loads((tpath / "tokenizer.json").read_text(encoding="utf-8"))
38    except (OSError, ValueError):
39        pass
40    return ST.Tokenizer(tokens, merges, types, tcfg.get("pre") or "qwen35", tcfg.get("special_ids") or None)
41
42
43def sensible(text: str) -> tuple[bool, str]:
44    """Words, not noise: letters in a normal share, more than two different words, no replacement characters, and Paris in it."""
45    t = text.strip()
46    words = re.findall(r"[A-Za-z]{2,}", t)
47    if not t:
48        return False, "the answer is empty"
49    if "�" in t:
50        return False, "the answer has broken characters"
51    if len(set(w.lower() for w in words)) < 3:
52        return False, "the answer is not made of words"
53    letters = sum(c.isalpha() or c.isspace() or c in ".,'-" for c in t) / len(t)
54    if letters < 0.8:
55        return False, "the answer is mostly symbols"
56    if "paris" not in t.lower():
57        return False, "the answer to a question with a known answer (the capital of France) does not contain it"
58    return True, "ok"
59
60
61def main() -> int:
62    for st in (sys.stdout, sys.stderr):       # the reply has DeepSeek's special tokens (fullwidth bars): a Windows console code page cannot print them
63        try:
64            st.reconfigure(encoding="utf-8", errors="replace")
65        except (AttributeError, OSError):
66            pass
67    ap = argparse.ArgumentParser()
68    ap.add_argument("--exe", required=True)
69    ap.add_argument("--pack", required=True)
70    ap.add_argument("--gpus")
71    ap.add_argument("--tokens", type=int, default=16)
72    ap.add_argument("--timeout", type=int, default=5400)
73    a = ap.parse_args()
74    pack = Path(a.pack)
75    tok = tokenizer(pack)
76    ids = tok.encode(PROMPT, parse_special=True)
77    with tempfile.TemporaryDirectory() as d:
78        f = Path(d) / "ids.txt"
79        f.write_text(",".join(str(i) for i in ids), encoding="ascii")
80        cmd = [a.exe, "--pack", str(pack), "--ids", "@" + str(f), "--n", str(a.tokens), "--max-context", "1024", "--dspark", "auto",
81               "--window", "16"]
82        if a.gpus:
83            cmd += ["--gpus", a.gpus]
84        try:
85            r = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=a.timeout, env=dict(os.environ))
86        except (OSError, subprocess.TimeoutExpired) as e:
87            print(f"the engine did not finish the test run: {e}")
88            return 2
89    err = (r.stderr or "").strip().splitlines()
90    if r.returncode != 0:
91        print(f"the engine stopped with an error (exit {r.returncode}): " + " | ".join(err[-3:]))
92        return 2
93    out = [int(x) for x in re.findall(r"-?\d+", (r.stdout or "").strip().splitlines()[-1] if (r.stdout or "").strip() else "")]
94    text = tok.decode(out)
95    good, why = sensible(text)
96    print(text.strip())
97    if not good:
98        print(f"test question failed: {why}")
99        return 1
100    return 0
101
102
103if __name__ == "__main__":
104    sys.exit(main())