okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2a7db0422
main
1#!/usr/bin/env python3 2"""Strata community benchmark runner: warm-up + N measured runs per prompt, server timings, one JSON per config. 3 4Follows docs/COMMUNITY_BENCHMARKS.md: prompt and decode throughput from the engine's own timings, actual token 5counts, reused (cache_n) vs fresh prompt tokens, every run kept (median and range computed from them). 6""" 7import argparse ,hashlib ,json ,statistics ,time ,urllib .request 8from pathlib import Path 9 10def call (base ,prompt ,max_tokens ): 11body = {"messages" : [{"role" :"user" ,"content" :prompt }],"temperature" :0 ,"seed" :42 , 12"max_tokens" :max_tokens ,"cache_prompt" :False } 13req = urllib .request .Request (base + "/v1/chat/completions" ,data = json .dumps (body ).encode (), 14headers = {"content-type" :"application/json" }) 15t0 = time .perf_counter () 16with urllib .request .urlopen (req ,timeout = 1800 )as r : 17d = json .load (r ) 18wall = time .perf_counter ()- t0 19t = d .get ("timings" , {}) 20text = d ["choices" ][0 ]["message" ].get ("content" )or "" 21return {"wall_s" :round (wall ,3 ),"timings" :t ,"usage" :d .get ("usage" ), 22"finish_reason" :d ["choices" ][0 ].get ("finish_reason" ), 23"content_sha256" :hashlib .sha256 (text .encode ()).hexdigest ()} 24 25def summary (runs ,key ): 26v = [r ["timings" ].get (key )for r in runs if r ["timings" ].get (key )is not None ] 27return {"median" :statistics .median (v ),"min" :min (v ),"max" :max (v )}if v else None 28 29def main (): 30p = argparse .ArgumentParser (description = __doc__ ) 31p .add_argument ("--base" ,required = True ) 32p .add_argument ("--label" ,required = True ) 33p .add_argument ("--prompts" ,default = str (Path (__file__ ).parent / "prompts" )) 34p .add_argument ("--sizes" ,default = "short,medium,long" ) 35p .add_argument ("--runs" ,type = int ,default = 3 ) 36p .add_argument ("--warmup" ,type = int ,default = 1 ) 37p .add_argument ("--max-tokens" ,type = int ,default = 256 ) 38p .add_argument ("--out" ,required = True ) 39a = p .parse_args () 40props = json .load (urllib .request .urlopen (a .base + "/props" ,timeout = 30 )) 41res = {"label" :a .label ,"build_info" :props .get ("build_info" ),"model_path" :props .get ("model_path" ), 42"n_ctx" :props .get ("default_generation_settings" , {}).get ("n_ctx" ),"max_tokens" :a .max_tokens , 43"sampling" :"temperature 0, seed 42, cache_prompt false" ,"sizes" : {}} 44for size in a .sizes .split ("," ): 45prompt = (Path (a .prompts )/ f" { size } .txt" ).read_text (encoding = "utf-8" ) 46# The server reuses a matching prefix even with cache_prompt false, so every request starts with a unique 47# line: each run then reads the whole prompt fresh (cache_n stays at the chat template's few tokens). 48tag = lambda kind ,i :f"[ { a . label } { size } { kind } { i } { time . time_ns () } ]\n" 49warm = [call (a .base ,tag ("warmup" ,i )+ prompt ,a .max_tokens )for i in range (a .warmup )] 50runs = [] 51for i in range (a .runs ): 52r = call (a .base ,tag ("run" ,i + 1 )+ prompt ,a .max_tokens ) 53r ["run" ]= i + 1 54runs .append (r ) 55t = r ["timings" ] 56f" { a . label } { size } run { i + 1 } : prompt { t . get ( 'prompt_n' ) } (+ { t . get ( 'cache_n' ) } reused) " 57f" { t . get ( 'prompt_per_second' ) } tok/s, decode { t . get ( 'predicted_n' ) } tok " 58f" { t . get ( 'predicted_per_second' ) } tok/s, wall { r [ 'wall_s' ] } s" ,flush = True ) 59res ["sizes" ][size ]= {"warmup" :warm ,"runs" :runs , 60"prompt_tps" :summary (runs ,"prompt_per_second" ), 61"decode_tps" :summary (runs ,"predicted_per_second" ), 62"prompt_ms" :summary (runs ,"prompt_ms" )} 63Path (a .out ).write_text (json .dumps (res ,indent = 2 ),encoding = "utf-8" ) 64"written" ,a .out ) 65 66if __name__ == "__main__" : 67main ()