Files
UnbiasedStrata/tools/dsv41/smoke.py
T
Robert KarlandClaude Fable 5.1 bd2dbb92f1 Import Strata v0.2.4's DeepSeek-V4.1 engine (strata-dsv41) and the CPU kernels it needs
From Niko1221/Strata tag v0.2.4 (commit 96ca4383, 2026-10-24), unmodified: src/dsv41/ (the engine and its vendored
EXL3 / sampler / window kernels), include/strata/dsv41/, tests/dsv41/, tools/dsv41/{pack_gguf,smoke,tune}.py,
data/dsv41/ (the shipped hot-expert profiles), tools/trellis/tqenc.{cpp,hpp} (the tests' encoder),
third_party/project-maya/ (the MIT notice: the engine is a port of Project Maya's maya-ds4),
third_party/ggml/ggml-common-tq.h, docs/DEEPSEEK41.md (upstream's text, to be rewritten for this fork).

src/kernels/cpu: upstream's iq_avx2.{cpp,hpp}, iq_avx2_rows.inl, iq_avx512.{cpp,hpp} replace this fork's
(v0.1.45-poly.1) copies - they add the engine's CPU lane rows iq256x_rows / iq512x_rows and leave the main engine's
iq256_* / iq512_* as they were (upstream's statement; iq_avx2_parity is the check) - and the trellis CPU lane
tq_cpu.{hpp,cpp}, tq_avx2.cpp, tq_avx512.cpp, tq_states.hpp, tq_computed.hpp is new.  expert_layout.hpp stays at
layout version 4 (upstream's 5 adds Hadamard-folded packs this fork has no use for yet).

CMakeLists.txt: upstream's strata-dsv41 block, with ggml.h / ggml-cpu.h coming through strata_kernels_cpu's ggml-cpu
link from the submodule (no FetchContent), the tq sources and flags in strata_kernels_cpu, and iq_avx512.cpp built
with -mavx512vpopcntdq -mbmi2 as upstream does (iq512x_rows uses them).  Makefile: STRATA_BUILD_DSV41=ON and
strata-dsv41 among the targets `make build` produces.

Target: ISTA-DASLab/DeepSeek-V4.1-Flash-1017-GSQ-RCO-GGUF (IQ1_M / IQ2_XXS + the IQ4_NL Engram) on the A6000 VM.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-23 20:14:35 -07: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())