okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2b36e8a02
main
1#!/usr/bin/env python3 2"""Multi-turn (agent-style) comparison: one conversation, five turns of ~1,200 new tokens each, cache reuse measured. 3 4python research/tools/dgx-spark-2026-10/dgx_turns.py CONFIG TAG OUTDIR [--turns 5] [--tokens 1200] [--port 8091] 5 6Per turn it records the engine's prompt_n / cache_n, prompt tok/s and TTFT, so the cache path is compared, not just the 7fresh-prompt path the other tools measure. 8""" 9import argparse 10import json 11import random 12import subprocess 13import sys 14import time 15import urllib .request 16from pathlib import Path 17 18ROOT = Path (__file__ ).resolve ().parents [3 ] 19WORDS = ("river stone market lantern copper winter garden signal harbor needle orbit velvet canyon ember ledger quartz " 20"meadow anchor violet thunder cedar marble piston ribbon cobalt falcon glacier hollow ivory juniper kernel " 21"lattice mirror nectar oasis pepper quarry raven saddle tundra umber vessel willow xenon yellow zephyr" ).split () 22 23 24def blob (n ,seed ): 25rng = random .Random (seed ) 26return " " .join (rng .choice (WORDS )for _ in range (n )) 27 28 29def chat (port ,messages ,max_tokens = 64 ): 30body = json .dumps ({"messages" :messages ,"max_tokens" :max_tokens ,"temperature" :0 ,"stream" :False , 31"chat_template_kwargs" : {"enable_thinking" :False }}).encode () 32req = urllib .request .Request (f"http://127.0.0.1: { port } /v1/chat/completions" ,data = body , 33headers = {"Content-Type" :"application/json" }) 34t0 = time .time () 35with urllib .request .urlopen (req ,timeout = 3600 )as r : 36out = json .loads (r .read ()) 37return out ,time .time ()- t0 38 39 40def main (): 41ap = argparse .ArgumentParser () 42ap .add_argument ("config" ) 43ap .add_argument ("tag" ) 44ap .add_argument ("outdir" ) 45ap .add_argument ("--turns" ,type = int ,default = 5 ) 46ap .add_argument ("--tokens" ,type = int ,default = 1200 ) 47ap .add_argument ("--port" ,type = int ,default = 8091 ) 48a = ap .parse_args () 49out = Path (a .outdir ) 50out .mkdir (parents = True ,exist_ok = True ) 51cfg = json .loads (Path (a .config ).read_text ()) 52cfg ["port" ]= a .port 53cfg ["log" ]= str (out / f" { a . tag } .engine.log" ) 54cpath = out / f" { a . tag } .config.json" 55cpath .write_text (json .dumps (cfg ,indent = 1 )) 56log = open (out / f" { a . tag } .jsonl" ,"a" ,encoding = "utf-8" ) 57proc = subprocess .Popen ([sys .executable ,str (ROOT / "serve" / "server.py" ),"--engine" ,"strata" ,"--config" , 58str (cpath ),"--port" ,str (a .port )],cwd = str (ROOT ), 59stdout = subprocess .DEVNULL ,stderr = subprocess .DEVNULL ) 60try : 61t0 = time .time () 62while time .time ()- t0 < 3600 : 63try : 64with urllib .request .urlopen (f"http://127.0.0.1: { a . port } /v1/models" ,timeout = 5 )as r : 65if r .status == 200 : 66break 67except Exception : 68pass 69time .sleep (3 ) 70f" { a . tag } : ready in { time . time () - t0 :.0f } s" ,flush = True ) 71msgs = [{"role" :"user" ,"content" :"Read this note and answer with one short sentence.\n" + blob (a .tokens ,1 )}] 72outj ,wall = chat (a .port ,msgs ) 73msgs .append ({"role" :"assistant" ,"content" :outj ["choices" ][0 ]["message" ].get ("content" ,"" )}) 74for turn in range (a .turns ): 75msgs .append ({"role" :"user" ,"content" :"More notes.\n" + blob (a .tokens ,100 + turn )+ 76"\nSummarise the last note in one sentence." }) 77outj ,wall = chat (a .port ,msgs ) 78t = outj .get ("timings" )or {} 79msgs .append ({"role" :"assistant" ,"content" :outj ["choices" ][0 ]["message" ].get ("content" ,"" )}) 80row = {"round" :turn ,"arm" :a .tag ,"len" :0 ,"temp" :0.0 ,"max_new" :64 ,"wall_s" :round (wall ,2 ), 81"ttft_s" : (t .get ("prompt_ms" )or 0 )/ 1000.0 or None ,** t } 82log .write (json .dumps (row )+ "\n" ) 83log .flush () 84f" turn { turn } : prompt_n { t . get ( 'prompt_n' ) } cache_n { t . get ( 'cache_n' ) } " 85f"prompt { t . get ( 'prompt_per_second' ) } tok/s decode { t . get ( 'predicted_per_second' ) } tok/s " 86f"ttft { row [ 'ttft_s' ] } " ,flush = True ) 87finally : 88proc .terminate () 89try : 90proc .wait (90 ) 91except subprocess .TimeoutExpired : 92proc .kill () 93log .close () 94 95 96if __name__ == "__main__" : 97main ()