okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
263c99b96
main
1"""Speed sweep against the live :8080, in the docs/COMMUNITY_BENCHMARKS.md format. 2 3Prompts are built from this repository's text the way tools/needle_bench.py does, with a fresh 4slice per run so no prompt is reused (cache_n must stay 0; a run that shows reuse is reported). 5Greedy, thinking off, 256 output tokens, 1 warm-up + 3 measured runs per cell. Throughput comes 6from the engine's own clock (the response's `timings`, llama.cpp names); TTFT is measured at the 7client on one streaming run per cell (the server is a FIFO, so TTFT can include queue time). 8Decode runs under 75% of the cell median are flagged as possible WDDM stalls (PR #279). 9 10python bench/results/2026-10-02-community-rtx-5090-iq3s/bench.py 11""" 12from __future__import annotations 13 14import json 15import re 16import statistics 17import subprocess 18import sys 19import threading 20import time 21import urllib .request 22from pathlib import Path 23 24ROOT = Path (__file__ ).resolve ().parents [3 ]# the Strata runtime folder 25sys .path .insert (0 ,str (ROOT / "tools" )) 26from needle_bench import haystack ,CHARS_PER_TOKEN # noqa: E402 27 28URL = "http://127.0.0.1:8080/v1/chat/completions" 29MODEL = "qwen3.8-flash-next-iq3_s" 30LOG = ROOT / "strata-iq3_s.log" 31LENGTHS = [1024 ,4096 ,32768 ,131072 ] 32MAX_NEW = 256 33OUT = Path (__file__ ).with_name ("runs.json" ) 34 35TAIL = re .compile (r"(decode expert cache hit rate: [\d.]+%[^\n]*|KV streaming: [\d.]+%[^\n]*)" ) 36 37 38def post (payload :dict ,timeout :float = 1800.0 )-> dict : 39req = urllib .request .Request (URL ,data = json .dumps (payload ).encode (), 40headers = {"Content-Type" :"application/json" }) 41with urllib .request .urlopen (req ,timeout = timeout )as r : 42return json .load (r ) 43 44 45def make_prompt (n_tokens :int ,off :int )-> str : 46n_chars = int (n_tokens * CHARS_PER_TOKEN ) 47text = haystack (n_chars + off + 4096 )[off :off + n_chars ] 48return (text + "\n\nQuestion: In at least 150 words, summarize what kinds of files the text " 49"above is made of and what they are for. Name three of them.\n" ) 50 51 52def log_tails (n_lines :int = 400 )-> dict : 53try : 54lines = LOG .read_text (encoding = "utf-8" ,errors = "replace" ).splitlines ()[- n_lines :] 55except OSError : 56return {} 57hits = [m for l in lines for m in TAIL .findall (l )] 58out = {} 59for h in hits [::- 1 ]: 60if h .startswith ("decode" )and "hit" not in out : 61out ["hit" ]= h 62if h .startswith ("KV" )and "kv" not in out : 63out ["kv" ]= h 64if len (out )== 2 : 65break 66return out 67 68 69def one_run (n_tokens :int ,off :int )-> dict : 70body = {"model" :MODEL ,"max_tokens" :MAX_NEW ,"temperature" :0 , 71"chat_template_kwargs" : {"enable_thinking" :False }, 72"messages" : [{"role" :"user" ,"content" :make_prompt (n_tokens ,off )}]} 73t0 = time .time () 74r = post (body ) 75t = r .get ("timings" )or {} 76u = r .get ("usage" )or {} 77return {"prompt_target" :n_tokens ,"prompt_tokens" :u .get ("prompt_tokens" ), 78"cache_n" :t .get ("cache_n" ),"generated" :t .get ("predicted_n" )or u .get ("completion_tokens" ), 79"prompt_tok_s" :t .get ("prompt_per_second" ),"decode_tok_s" :t .get ("predicted_per_second" ), 80"draft_n" :t .get ("draft_n" ),"draft_ok" :t .get ("draft_n_accepted" ), 81"total_s" :round (time .time ()- t0 ,2 ),"wall_s" :round (t .get ("prompt_ms" ,0 )/ 1000 + t .get ("predicted_ms" ,0 )/ 1000 ,2 ), 82** log_tails ()} 83 84 85def ttft_run (n_tokens :int ,off :int )-> float | None : 86body = {"model" :MODEL ,"max_tokens" :MAX_NEW ,"temperature" :0 ,"stream" :True , 87"chat_template_kwargs" : {"enable_thinking" :False }, 88"messages" : [{"role" :"user" ,"content" :make_prompt (n_tokens ,off )}]} 89req = urllib .request .Request (URL ,data = json .dumps (body ).encode (), 90headers = {"Content-Type" :"application/json" }) 91t0 = time .time () 92with urllib .request .urlopen (req ,timeout = 1800 )as r : 93for raw in r : 94line = raw .decode ("utf-8" ,"replace" ).strip () 95if not line .startswith ("data: " )or line == "data: [DONE]" : 96continue 97try : 98d = json .loads (line [6 :])["choices" ][0 ].get ("delta" )or {} 99except (KeyError ,ValueError ): 100continue 101if d .get ("content" )or d .get ("reasoning_content" ): 102return round (time .time ()- t0 ,2 ) 103return None 104 105 106class Vram (threading .Thread ): 107def __init__ (self )-> None : 108super ().__init__ (daemon = True ) 109self .stop_at ,self .mins = time .time ()+ 100000 , [] 110 111def run (self )-> None : 112while time .time ()< self .stop_at : 113try : 114s = subprocess .run (["nvidia-smi" ,"-i" ,"0" ,"--query-gpu=memory.free" , 115"--format=csv,noheader,nounits" ],capture_output = True ,text = True ,timeout = 10 ) 116self .mins .append (int (s .stdout .strip ())) 117except Exception : 118pass 119time .sleep (5 ) 120 121 122def main ()-> int : 123vram = Vram () 124vram .start () 125rows = [] 126for L in LENGTHS : 127for i in range (4 ):# run 0 = warm-up, not counted 128row = one_run (L ,i * 1_000_003 + L ) 129row ["length" ],row ["run" ],row ["warmup" ]= L ,i ,i == 0 130rows .append (row ) 131f" { L :>7 } run { i } : prompt { row [ 'prompt_tok_s' ] } tok/s, decode { row [ 'decode_tok_s' ] } tok/s, " 132f"cache_n { row [ 'cache_n' ] } , gen { row [ 'generated' ] } , { row [ 'total_s' ] } s" ,flush = True ) 133rows .append ({"length" :L ,"ttft_s" :ttft_run (L ,4 * 1_000_003 + L ),"stream_ttft" :True }) 134f" { L :>7 } TTFT { rows [ - 1 ][ 'ttft_s' ] } s" ,flush = True ) 135vram .stop_at = time .time () 136time .sleep (0.2 ) 137 138"\n| Prompt | prompt tok/s (3 runs) | decode tok/s (3 runs) | TTFT s | draft accept |" ) 139"| --- | --- | --- | --- | --- |" ) 140for L in LENGTHS : 141m = [r for r in rows if r .get ("length" )== L and not r .get ("warmup" )and not r .get ("stream_ttft" )] 142p = [r ["prompt_tok_s" ]for r in m if r ["prompt_tok_s" ]] 143d = [r ["decode_tok_s" ]for r in m if r ["decode_tok_s" ]] 144tt = next ((r ["ttft_s" ]for r in rows if r .get ("length" )== L and r .get ("stream_ttft" )),None ) 145dr = sum (r ["draft_ok" ]or 0 for r in m )/ max (1 ,sum (r ["draft_n" ]or 0 for r in m )) 146med = statistics .median (d )if d else 0 147stall = [r ["decode_tok_s" ]for r in m if r ["decode_tok_s" ]and r ["decode_tok_s" ]< 0.75 * med ] 148f"| { L :, } | { statistics . median ( p ):,.0f } ( { min ( p ):,.0f } - { max ( p ):,.0f } ) | " 149f" { med :,.1f } ( { min ( d ):,.1f } - { max ( d ):,.1f } ) | { tt } | { dr :.0% } |" 150+ (f" STALL: { stall } " if stall else "" )) 151reused = [r for r in rows if not r .get ("warmup" )and not r .get ("stream_ttft" )and r .get ("cache_n" )] 152f"\nruns with prompt reuse (cache_n>0): { len ( reused ) } ; VRAM free min during sweep: { min ( vram . mins ) } MiB" ) 153OUT .write_text (json .dumps (rows ,indent = 1 ),encoding = "utf-8" ) 154f"wrote { OUT } " ) 155return 0 156 157 158if __name__ == "__main__" : 159sys .exit (main ())