okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2b36e8a02
main
1#!/usr/bin/env python3 2"""The drop's acceptance gate in one command: setup detection, one benchmark cell, the identity gate and a needle, each 3with a band that the numbers on a DGX Spark should land in. Exit code 0 = all passed. 4 5python research/tools/dgx-spark-2026-10/dgx_smoke.py [--config strata-iq3_s.json] [--tokens 12000] [--data-dir ~/Strata-data] 6 7Bands are deliberately loose (they must survive page-cache state and drift); a failure means something is wrong, not that 8the machine is 5% slower than the number in the documents. 9""" 10from __future__import annotations 11 12import argparse 13import json 14import os 15import re 16import subprocess 17import sys 18import tempfile 19import time 20from pathlib import Path 21 22ROOT = Path (__file__ ).resolve ().parents [3 ] 23PY = sys .executable 24WORK = Path (tempfile .mkdtemp (prefix = "dgx-smoke-" ))# this run's own scratch folder (never a fixed /tmp name another run could share) 25 26 27def sh (cmd :str )-> tuple [int ,str ]: 28p = subprocess .run (cmd ,shell = True ,cwd = str (ROOT ),capture_output = True ,text = True ,timeout = 3600 ) 29return p .returncode , (p .stdout or "" )+ (p .stderr or "" ) 30 31 32def check_setup (data_dir :str )-> tuple [bool ,str ]: 33rc ,out = sh (f" { PY } setup.py --check --yes --data-dir ' { data_dir } ' 2>&1 | head -8" ) 34low = out .lower () 35ok = "unified memory" in low and "arm64" in low 36gpu = next ((line .strip ()for line in out .splitlines ()if "GPU:" in line ),"" ) 37return ok ,gpu or (out .strip ().splitlines ()[0 ]if out .strip ()else "no output" ) 38 39 40def bench (config :str ,cell :str ,out_dir :str )-> dict | None : 41rc ,out = sh (f" { PY } tools/dgx_bench.py --config { config } --tag smoke --cells { cell } --rounds 1 --port 8093 " 42f"--out { out_dir } 2>&1" ) 43m = re .search (r"prompt_n\s+(\d+)\s+prompt\s+([0-9.]+)\s+tok/s\s+decode\s+([0-9.]+)" ,out ) 44if not m : 45return None 46return {"prompt_n" :int (m .group (1 )),"prompt" :float (m .group (2 )),"decode" :float (m .group (3 ))} 47 48 49def identity (config :str )-> tuple [bool ,str ]: 50base = json .loads ((ROOT / config ).read_text ()) 51off = dict (base ) 52off ["args" ]= list (base ["args" ]) 53env = dict (base .get ("env" )or {}) 54env ["STRATA_PF_FUSED" ]= "0" 55off ["env" ]= env 56off_path = WORK / "nofused.json" 57off_path .write_text (json .dumps (off ,indent = 1 )) 58rc ,out = sh (f" { PY } research/tools/dgx-spark-2026-10/dgx_quality.py { off_path } { config } { WORK / 'quality.json' } 2>&1" ) 59m = re .search (r"(\d+) of (\d+) answers identical" ,out ) 60if not m : 61return False ,out .strip ()[- 200 :] 62return m .group (1 )== m .group (2 ),out .strip ().splitlines ()[- 1 ] 63 64 65def needle (config :str ,tokens :int )-> tuple [bool ,str ]: 66rc ,out = sh (f" { PY } research/tools/dgx-spark-2026-10/dgx_needle.py --config { config } --tokens { tokens } --runs 2 2>&1" ) 67m = re .search (r"(\d+) of (\d+) recalled" ,out ) 68if not m : 69return False ,out .strip ()[- 200 :] 70return m .group (1 )== m .group (2 ),out .strip ().splitlines ()[- 1 ] 71 72 73def main ()-> int : 74ap = argparse .ArgumentParser () 75ap .add_argument ("--config" ,default = "strata-iq3_s.json" ) 76ap .add_argument ("--cell" ,default = "4096:0:256" ) 77ap .add_argument ("--tokens" ,type = int ,default = 12000 ) 78ap .add_argument ("--data-dir" ,default = os .environ .get ("STRATA_DATA_DIR" )or str (Path .home ()/ "Strata-data" ), 79help = "the data folder setup uses (default: $STRATA_DATA_DIR or ~/Strata-data)" ) 80a = ap .parse_args () 81results = [] 82t0 = time .time () 83 84ok ,detail = check_setup (a .data_dir ) 85results .append (("setup detection" ,ok ,detail )) 86 87b = bench (a .config ,a .cell ,str (WORK / "bench" )) 88if b is None : 89results .append (("bench cell" ,False ,"no parsable cell" )) 90else : 91ok = b ["prompt" ]> 800 and b ["decode" ]> 30 92results .append (("bench cell" ,ok ,f" { b [ 'prompt' ]:.0f } prompt / { b [ 'decode' ]:.1f } decode tok/s" )) 93 94ok ,detail = identity (a .config ) 95results .append (("identity, fused vs MMQ" ,ok ,detail )) 96 97ok ,detail = needle (a .config ,a .tokens ) 98results .append (("needle, recall" ,ok ,detail )) 99 100width = max (len (n )for n ,_ ,_ in results ) 102for name ,ok ,detail in results : 103f" { 'PASS' if ok else 'FAIL' } { name :<{ width } } { detail } " ) 104bad = [n for n ,ok ,_ in results if not ok ] 105f"\n { len ( results ) - len ( bad ) } of { len ( results ) } passed in { time . time () - t0 :.0f } s" 106+ (f"; failed: { ', ' . join ( bad ) } " if bad else "" )) 107return 0 if not bad else 1 108 109 110if __name__ == "__main__" : 111sys .exit (main ())