okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3f4d44ece
main
1#!/usr/bin/env python3 2"""summarize.py <raw-dir-or-files...> — per-arm table: accuracy / completeness / reliability / speed, + cross-arm agreement. 3 4Reads the *.jsonl records written by bench.py. If an arm has several files or reps, they are pooled (rep count shown). 5Speed uses server-reported timings when present (llama-server/Strata `timings`, Ollama eval_duration), else client-side. 6""" 7import glob ,json ,os ,statistics as st ,sys ,difflib ,collections 8 9def load (paths ): 10recs = [] 11for p in paths : 12for f in (glob .glob (os .path .join (p ,"*.jsonl" ))if os .path .isdir (p )else [p ]): 13for line in open (f ): 14line = line .strip () 15if line : 16r = json .loads (line );r ["_file" ]= os .path .basename (f );recs .append (r ) 17return recs 18 19def med (xs ): 20xs = [x for x in xs if x is not None ] 21return st .median (xs )if xs else None 22 23def fmt (x ,nd = 1 ): 24return "-" if x is None else ("%.*f" % (nd ,x )) 25 26def decode_tps (r ): 27res = r .get ("res" )or {} 28t = res .get ("server_timings" )or {} 29if t .get ("predicted_per_second" ): 30return t ["predicted_per_second" ],"srv" 31n ,tf ,tt = res .get ("completion_tokens" ),res .get ("t_first" ),res .get ("t_total" ) 32if n and n > 1 and tf is not None and tt and tt > tf : 33return (n - 1 )/ (tt - tf ),"cli" 34return None ,None 35 36def prefill_tps (r ): 37res = r .get ("res" )or {} 38t = res .get ("server_timings" )or {} 39if t .get ("prompt_per_second" ): 40return t ["prompt_per_second" ] 41return None 42 43def main (paths ): 44recs = load (paths ) 45arms = collections .defaultdict (list ) 46for r in recs : 47arms [r ["arm" ]].append (r ) 48cats = ["reasoning" ,"code" ,"tools" ,"complete" ,"longctx" ] 49"## Quality (pass rate = passed/total across pooled reps; errors count as fails)\n" ) 50"| arm | think | " + " | " .join (cats )+ " | truncated(length) | errors |" ) 51"|---|---|" + "---|" * (len (cats )+ 2 )) 52for a ,rs in sorted (arms .items ()): 53row = [] 54for c in cats : 55xs = [r for r in rs if r ["category" ]== c ] 56if not xs :row .append ("-" );continue 57ok = sum (1 for r in xs if r ["passed" ]);row .append ("%d/%d (%.0f%%)" % (ok ,len (xs ),100 * ok / len (xs ))) 58gen = [r for r in rs if r ["category" ]not in ("speed" ,)] 59trunc = sum (1 for r in gen if (r .get ("res" )or {}).get ("finish_reason" )== "length" ) 60errs = sum (1 for r in rs if r .get ("error" )) 61"| %s | %s | %s | %d | %d |" % (a ,rs [0 ].get ("think" )," | " .join (row ),trunc ,errs )) 62"\n## Long-context recall fraction (mean of 3 needles) by size\n" ) 63sizes = sorted ({r ["id" ]for r in recs if r ["category" ]== "longctx" },key = lambda s :int (s .split ("-" )[1 ][:- 1 ])) 64if sizes : 65"| arm | " + " | " .join (sizes )+ " |" );"|---|" + "---|" * len (sizes )) 66for a ,rs in sorted (arms .items ()): 67cells = [] 68for s in sizes : 69xs = [(r .get ("grade" )or {}).get ("fraction" )for r in rs if r ["id" ]== s and r .get ("res" )] 70cells .append (fmt (100 * st .mean (xs ),0 )+ "%" if xs else "-" ) 71"| %s | %s |" % (a ," | " .join (cells ))) 72"\n## Speed (median over reps; srv = server-reported, cli = client-side)\n" ) 73"| arm | decode tok/s (all gen tasks) | decode tok/s (speed-short) | prefill tok/s by prompt size | TTFT short (s) | first-request total (s) |" ) 74"|---|---|---|---|---|---|" ) 75for a ,rs in sorted (arms .items ()): 76dec = [decode_tps (r )[0 ]for r in rs if r .get ("res" )] 77short = [decode_tps (r )[0 ]for r in rs if r ["id" ]== "speed-short" and r .get ("res" )] 78pf = collections .defaultdict (list ) 79for r in rs : 80if r ["id" ].startswith ("speed-prefill" )or r ["id" ].startswith ("longctx" ): 81p = prefill_tps (r ) 82if p :pf [r ["id" ].replace ("speed-prefill-" ,"" ).replace ("longctx-" ,"lc-" )].append (p ) 83pfs = ", " .join ("%s:%s" % (k ,fmt (med (v ),0 ))for k ,v in sorted (pf .items (),key = lambda kv : (len (kv [0 ]),kv [0 ]))) 84ttft = med ([(r .get ("res" )or {}).get ("t_first" )for r in rs if r ["id" ]== "speed-short" ]) 85first = (sorted (rs ,key = lambda r :r ["ts" ])[0 ].get ("res" )or {}).get ("t_total" ) 86"| %s | %s | %s | %s | %s | %s |" % (a ,fmt (med (dec )),fmt (med (short )),pfs or "-" ,fmt (ttft ,2 ),fmt (first ))) 87# agreement: same task id, text-level, between arms (think off, rep 0) 88"\n## Cross-arm output agreement (greedy, same prompts; similarity = difflib ratio of final text; exact = identical)\n" ) 89texts = {a : {r ["id" ]: (r .get ("res" )or {}).get ("text" ,"" )for r in rs if r .get ("res" )and r ["rep" ]== 0 and r ["category" ]!= "speed" }for a ,rs in arms .items ()} 90names = sorted (texts ) 91if len (names )> 1 : 92"| arm A | arm B | tasks | exact | mean similarity |" );"|---|---|---|---|---|" ) 93for i in range (len (names )): 94for j in range (i + 1 ,len (names )): 95ids = sorted (set (texts [names [i ]])& set (texts [names [j ]])) 96if not ids :continue 97ex = sum (texts [names [i ]][t ]== texts [names [j ]][t ]for t in ids ) 98sim = st .mean (difflib .SequenceMatcher (None ,texts [names [i ]][t ],texts [names [j ]][t ]).ratio ()for t in ids ) 99"| %s | %s | %d | %d | %.3f |" % (names [i ],names [j ],len (ids ),ex ,sim )) 100# within-arm determinism across reps 101"\n## Within-arm repeatability (reps of identical greedy requests)\n" ) 102for a ,rs in sorted (arms .items ()): 103by = collections .defaultdict (list ) 104for r in rs : 105if r .get ("res" )and r ["category" ]!= "speed" :by [r ["id" ]].append (r ["res" ]["text" ]) 106multi = {k :v for k ,v in by .items ()if len (v )> 1 } 107if multi : 108same = sum (len (set (v ))== 1 for v in multi .values ()) 109"- %s: %d/%d tasks gave identical text on every rep" % (a ,same ,len (multi ))) 110 111if __name__ == "__main__" : 112main (sys .argv [1 :]or ["results/raw" ])