okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5025324c2
main
1#!/usr/bin/env python3 2"""bench.py LOGFILE LABEL [--runs 3] - fixed prompts straight to the engine (BENCH_PORT, default 8081): thinking off, 3temperature 0, a random first line so nothing is reused from the prompt / conversation cache; then the speeds the 4engine itself logged. short = ~565-token prompt + 200 tokens out; long = ~7,047-token prompt + 60 tokens out. 5Prints every request and the medians: prompt tok/s and decode tok/s per case.""" 6import json ,os ,random ,re ,statistics ,sys ,time ,urllib .request 7LOG ,LABEL = sys .argv [1 ],sys .argv [2 ];RUNS = int (sys .argv [sys .argv .index ("--runs" )+ 1 ])if "--runs" in sys .argv else 3 8WORDS = ("the engine reads a prompt and writes an answer while the cache keeps the experts that were used most often " 9"in the last rounds so a second request with a different first line has to be read again from the start" ).split () 10def text (n ,seed ): 11r = random .Random (seed );return " " .join (r .choice (WORDS )for _ in range (n )) 12def ask (prompt ,max_tokens ): 13body = {"model" :"qwen3.8-flash-next-iq3_s" ,"messages" : [{"role" :"user" ,"content" :prompt }],"max_tokens" :max_tokens ,"temperature" :0 , 14"reasoning_effort" :"none" ,"stream" :False } 15req = urllib .request .Request ("http://127.0.0.1:%s/v1/chat/completions" % os .environ .get ("BENCH_PORT" ,"8081" ),json .dumps (body ).encode (), {"Content-Type" :"application/json" }) 16t = time .time ();out = json .load (urllib .request .urlopen (req ,timeout = 1800 ));return time .time ()- t ,out 17PAT = re .compile (r"prompt (\d+) tokens = (\d+) reused \+ (\d+) read in (\d+) ms \(([\d.]+) tok/s\), (\d+) generated in (\d+) ms \(([\d.]+) tok/s\)" ) 18res = {} 19for case ,n ,mt in (("short" ,520 ,200 ), ("long" ,7000 ,60 )): 20for i in range (RUNS ): 21nonce = "%016x" % random .getrandbits (64 );before = sum (1 for _ in open (LOG ,errors = "replace" )) 22wall ,out = ask (f"Run { nonce } . Continue this text with a long plain description of a harbour town, no lists.\n\n" + text (n ,case ),mt ) 23time .sleep (1.5 );lines = open (LOG ,errors = "replace" ).read ().split ("\n" )[before :];m = [PAT .search (l )for l in lines ];m = [x for x in m if x ] 24if not m :case ,i ,"no log line" ,wall );continue 25g = m [- 1 ].groups ();res .setdefault (case , []).append ((float (g [4 ]),float (g [7 ]),int (g [0 ]),int (g [2 ]),int (g [5 ]),wall )) 26f" { LABEL } { case } run { i } : prompt { g [ 0 ] } tok ( { g [ 2 ] } read) at { g [ 4 ] } tok/s | { g [ 5 ] } generated at { g [ 7 ] } tok/s | wall { wall :.1f } s" ,flush = True ) 27for case ,v in res .items (): 28f"== { LABEL } { case } : prompt median { statistics . median ( x [ 0 ] for x in v ):.0f } tok/s | decode median { statistics . median ( x [ 1 ] for x in v ):.1f } tok/s | n= { len ( v ) } " )