okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ba8745e13
main
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 3python 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 ): 27import strata_tokenizer as ST 28tpath = pack / "tokenizer" 29vocab = json .loads ((tpath / "vocab.json" ).read_text (encoding = "utf-8" )) 30tokens = [None ]* len (vocab ) 31for t ,i in vocab .items (): 32tokens [i ]= t 33merges = (tpath / "merges.txt" ).read_text (encoding = "utf-8" ).split ("\n" ) 34types = json .loads ((tpath / "token_type.json" ).read_text ()) 35tcfg = {} 36try : 37tcfg = json .loads ((tpath / "tokenizer.json" ).read_text (encoding = "utf-8" )) 38except (OSError ,ValueError ): 39pass 40return 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.""" 45t = text .strip () 46words = re .findall (r"[A-Za-z]{2,}" ,t ) 47if not t : 48return False ,"the answer is empty" 49if "�" in t : 50return False ,"the answer has broken characters" 51if len (set (w .lower ()for w in words ))< 3 : 52return False ,"the answer is not made of words" 53letters = sum (c .isalpha ()or c .isspace ()or c in ".,'-" for c in t )/ len (t ) 54if letters < 0.8 : 55return False ,"the answer is mostly symbols" 56if "paris" not in t .lower (): 57return False ,"the answer to a question with a known answer (the capital of France) does not contain it" 58return True ,"ok" 59 60 61def main ()-> int : 62for st in (sys .stdout ,sys .stderr ):# the reply has DeepSeek's special tokens (fullwidth bars): a Windows console code page cannot print them 63try : 64st .reconfigure (encoding = "utf-8" ,errors = "replace" ) 65except (AttributeError ,OSError ): 66pass 67ap = argparse .ArgumentParser () 68ap .add_argument ("--exe" ,required = True ) 69ap .add_argument ("--pack" ,required = True ) 70ap .add_argument ("--gpus" ) 71ap .add_argument ("--tokens" ,type = int ,default = 16 ) 72ap .add_argument ("--timeout" ,type = int ,default = 5400 ) 73a = ap .parse_args () 74pack = Path (a .pack ) 75tok = tokenizer (pack ) 76ids = tok .encode (PROMPT ,parse_special = True ) 77with tempfile .TemporaryDirectory ()as d : 78f = Path (d )/ "ids.txt" 79f .write_text ("," .join (str (i )for i in ids ),encoding = "ascii" ) 80cmd = [a .exe ,"--pack" ,str (pack ),"--ids" ,"@" + str (f ),"--n" ,str (a .tokens ),"--max-context" ,"1024" ,"--dspark" ,"auto" , 81"--window" ,"16" ] 82if a .gpus : 83cmd += ["--gpus" ,a .gpus ] 84try : 85r = subprocess .run (cmd ,capture_output = True ,text = True ,encoding = "utf-8" ,errors = "replace" ,timeout = a .timeout ,env = dict (os .environ )) 86except (OSError ,subprocess .TimeoutExpired )as e : 87f"the engine did not finish the test run: { e } " ) 88return 2 89err = (r .stderr or "" ).strip ().splitlines () 90if r .returncode != 0 : 91f"the engine stopped with an error (exit { r . returncode } ): " + " | " .join (err [- 3 :])) 92return 2 93out = [int (x )for x in re .findall (r"-?\d+" , (r .stdout or "" ).strip ().splitlines ()[- 1 ]if (r .stdout or "" ).strip ()else "" )] 94text = tok .decode (out ) 95good ,why = sensible (text ) 96text .strip ()) 97if not good : 98f"test question failed: { why } " ) 99return 1 100return 0 101 102 103if __name__ == "__main__" : 104sys .exit (main ())