Files
leleka/engine/strata/tools/dsv41/smoke.py
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

105 lines
4.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""16 tokens of a fixed prompt through strata-dsv41 and a check of the TEXT (setup runs this once after the pack is built).
python tools/dsv41/smoke.py --exe strata-dsv41 --pack <pack> [--gpus 0] [--tokens 16]
A pack that loads can still give garbage (a wrong pack recipe does exactly that), so the answer is read, not just the exit code:
the 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
and 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.
"""
from __future__ import annotations
import argparse
import json
import os
import re
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "tools"))
PROMPT = "<|begin▁of▁sentence|><|User|>What is the capital of France? Answer in one short sentence.<|Assistant|></think>"
def tokenizer(pack: Path):
import strata_tokenizer as ST
tpath = pack / "tokenizer"
vocab = json.loads((tpath / "vocab.json").read_text(encoding="utf-8"))
tokens = [None] * len(vocab)
for t, i in vocab.items():
tokens[i] = t
merges = (tpath / "merges.txt").read_text(encoding="utf-8").split("\n")
types = json.loads((tpath / "token_type.json").read_text())
tcfg = {}
try:
tcfg = json.loads((tpath / "tokenizer.json").read_text(encoding="utf-8"))
except (OSError, ValueError):
pass
return ST.Tokenizer(tokens, merges, types, tcfg.get("pre") or "qwen35", tcfg.get("special_ids") or None)
def sensible(text: str) -> tuple[bool, str]:
"""Words, not noise: letters in a normal share, more than two different words, no replacement characters, and Paris in it."""
t = text.strip()
words = re.findall(r"[A-Za-z]{2,}", t)
if not t:
return False, "the answer is empty"
if "�" in t:
return False, "the answer has broken characters"
if len(set(w.lower() for w in words)) < 3:
return False, "the answer is not made of words"
letters = sum(c.isalpha() or c.isspace() or c in ".,'-" for c in t) / len(t)
if letters < 0.8:
return False, "the answer is mostly symbols"
if "paris" not in t.lower():
return False, "the answer to a question with a known answer (the capital of France) does not contain it"
return True, "ok"
def main() -> int:
for st in (sys.stdout, sys.stderr): # the reply has DeepSeek's special tokens (fullwidth bars): a Windows console code page cannot print them
try:
st.reconfigure(encoding="utf-8", errors="replace")
except (AttributeError, OSError):
pass
ap = argparse.ArgumentParser()
ap.add_argument("--exe", required=True)
ap.add_argument("--pack", required=True)
ap.add_argument("--gpus")
ap.add_argument("--tokens", type=int, default=16)
ap.add_argument("--timeout", type=int, default=5400)
a = ap.parse_args()
pack = Path(a.pack)
tok = tokenizer(pack)
ids = tok.encode(PROMPT, parse_special=True)
with tempfile.TemporaryDirectory() as d:
f = Path(d) / "ids.txt"
f.write_text(",".join(str(i) for i in ids), encoding="ascii")
cmd = [a.exe, "--pack", str(pack), "--ids", "@" + str(f), "--n", str(a.tokens), "--max-context", "1024", "--dspark", "auto",
"--window", "16"]
if a.gpus:
cmd += ["--gpus", a.gpus]
try:
r = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=a.timeout, env=dict(os.environ))
except (OSError, subprocess.TimeoutExpired) as e:
print(f"the engine did not finish the test run: {e}")
return 2
err = (r.stderr or "").strip().splitlines()
if r.returncode != 0:
print(f"the engine stopped with an error (exit {r.returncode}): " + " | ".join(err[-3:]))
return 2
out = [int(x) for x in re.findall(r"-?\d+", (r.stdout or "").strip().splitlines()[-1] if (r.stdout or "").strip() else "")]
text = tok.decode(out)
good, why = sensible(text)
print(text.strip())
if not good:
print(f"test question failed: {why}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())