okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2b36e8a02
main
1#!/usr/bin/env python3 2"""One server, several repeats per cell: the warm-state runner (the per-start page cache and the tens-of-GB expert 3prefetch are the main variance sources on a unified-memory box, so repeats inside one server are the comparable ones). 4 5python research/tools/dgx-spark-2026-10/dgx_warm.py CONFIG TAG OUTDIR [--cells 4096,16384,32768] [--repeats 3] [--port 8091] [--new 256] 6 7Writes <OUTDIR>/<TAG>.jsonl rows in tools/dgx_bench.py's schema (round, arm, len, temp, max_new, prompt_n, 8prompt_per_second, predicted_n, predicted_per_second, ttft_s, cache_n) so research/tools/dgx-spark-2026-10/dgx_compare.py reads them. 9""" 10import argparse 11import json 12import random 13import subprocess 14import sys 15import time 16import urllib .request 17from pathlib import Path 18 19ROOT = Path (__file__ ).resolve ().parents [3 ] 20WORDS = ("river stone market lantern copper winter garden signal harbor needle orbit velvet canyon ember ledger quartz " 21"meadow anchor violet thunder cedar marble piston ribbon cobalt falcon glacier hollow ivory juniper kernel" ).split () 22 23 24def prompt_for (tokens ,nonce ): 25rng = random .Random (tokens ) 26body = " " .join (rng .choice (WORDS )for _ in range (max (8 ,int (tokens / 1.35 )))) 27return (f"Request nonce { nonce } . Read the word list below carefully.\n\n { body } \n\n" 28"Write a long, detailed analysis of the word list above. Keep writing for at least 400 words." ) 29 30 31def post (port ,prompt ,max_new ): 32body = json .dumps ({"messages" : [{"role" :"user" ,"content" :prompt }],"max_tokens" :max_new ,"temperature" :0 , 33"stream" :False ,"chat_template_kwargs" : {"enable_thinking" :False }}).encode () 34req = urllib .request .Request (f"http://127.0.0.1: { port } /v1/chat/completions" ,data = body , 35headers = {"Content-Type" :"application/json" }) 36t0 = time .time () 37with urllib .request .urlopen (req ,timeout = 3600 )as r : 38out = json .loads (r .read ()) 39return out ,time .time ()- t0 40 41 42def status (port ): 43try : 44with urllib .request .urlopen (f"http://127.0.0.1: { port } /v1/status" ,timeout = 10 )as r : 45return json .loads (r .read ()).get ("last_timings" )or {} 46except Exception : 47return {} 48 49 50def main (): 51ap = argparse .ArgumentParser () 52ap .add_argument ("config" ) 53ap .add_argument ("tag" ) 54ap .add_argument ("outdir" ) 55ap .add_argument ("--cells" ,default = "512,2048,4096" ) 56ap .add_argument ("--repeats" ,type = int ,default = 4 ) 57ap .add_argument ("--port" ,type = int ,default = 8091 ) 58ap .add_argument ("--new" ,type = int ,default = 256 ) 59a = ap .parse_args () 60out = Path (a .outdir ) 61out .mkdir (parents = True ,exist_ok = True ) 62cfg = json .loads (Path (a .config ).read_text ()) 63cfg ["port" ]= a .port 64cfg ["log" ]= str (out / f" { a . tag } .engine.log" ) 65cpath = out / f" { a . tag } .config.json" 66cpath .write_text (json .dumps (cfg ,indent = 1 )) 67log = open (out / f" { a . tag } .jsonl" ,"a" ,encoding = "utf-8" ) 68proc = subprocess .Popen ([sys .executable ,str (ROOT / "serve" / "server.py" ),"--engine" ,"strata" ,"--config" , 69str (cpath ),"--port" ,str (a .port )],cwd = str (ROOT ), 70stdout = subprocess .DEVNULL ,stderr = subprocess .DEVNULL ) 71try : 72t0 = time .time () 73while time .time ()- t0 < 3600 : 74if proc .poll ()is not None : 75raise SystemExit (f"server exited with { proc . returncode } " ) 76try : 77with urllib .request .urlopen (f"http://127.0.0.1: { a . port } /v1/models" ,timeout = 5 )as r : 78if r .status == 200 : 79break 80except Exception : 81pass 82time .sleep (3 ) 83f" { a . tag } : ready in { time . time () - t0 :.0f } s" ,flush = True ) 84post (a .port ,prompt_for (256 ,"warm" ),8 ) 85for rep in range (a .repeats ): 86for length in [int (x )for x in a .cells .split ("," )]: 87nonce = f" { random . getrandbits ( 48 ):012x } " 88outj ,wall = post (a .port ,prompt_for (length ,nonce ),a .new ) 89t = status (a .port ) 90row = {"round" :rep ,"arm" :a .tag ,"len" :length ,"temp" :0.0 ,"max_new" :a .new , 91"wall_s" :round (wall ,2 ),"ttft_s" : (t .get ("prompt_ms" )or 0 )/ 1000.0 or None , 92"cache_n" :t .get ("cache_n" ,0 ),** t } 93log .write (json .dumps (row )+ "\n" ) 94log .flush () 95f" { length :5d } prompt_n { t . get ( 'prompt_n' ) } prompt { t . get ( 'prompt_per_second' ) } tok/s " 96f"decode { t . get ( 'predicted_per_second' ) } tok/s" ,flush = True ) 97finally : 98proc .terminate () 99try : 100proc .wait (90 ) 101except subprocess .TimeoutExpired : 102proc .kill () 103log .close () 104 105 106if __name__ == "__main__" : 107main ()