okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7b52a0b62
main
1#!/usr/bin/env python3 2"""Aggregate the runs in ../data into medians, ranges and memory peaks. 3 4python summarize.py # print the tables 5python summarize.py --write # also write ../data/summary.json 6 7Throughput comes from the engine timing lines that tools/hip/bench_prefill.py 8records per request. Memory peaks come from the sampler CSVs in ../data/memory. 9""" 10import argparse 11import csv 12import json 13import re 14import statistics 15from pathlib import Path 16 17DATA = Path (__file__ ).resolve ().parent .parent / 'data' 18QUANTS = ['coder-iq1_m' ,'iq2_xs' ,'iq3_xxs' ] 19 20 21def runs (quant ): 22out = [] 23for n in (1 ,2 ,3 ): 24out .extend (json .load ((DATA / f' { quant } -run { n } .json' ).open ())) 25return out 26 27 28def agg (values ): 29return dict (median = round (statistics .median (values ),1 ),min = round (min (values ),1 ), 30max = round (max (values ),1 ),n = len (values )) 31 32 33def peak_vram (quant ,suffix ): 34path = DATA / 'memory' / f' { quant } -mem- { suffix } .csv' 35rows = list (csv .DictReader (path .open ())) 36cols = [c for c in rows [0 ]if c .endswith ('_vram_used' )] 37return dict (samples = len (rows ), 38vram_peak_gib = round (max (max (int (r [c ])for r in rows )for c in cols )/ 2 ** 30 ,2 ), 39ram_used_peak_gib = round (max (float (r ['ram_used_mib' ])for r in rows )/ 1024 ,2 )) 40 41 42def engine_facts (quant ): 43text = (DATA / f' { quant } .engine.log' ).read_text (errors = 'replace' ) 44facts = {} 45m = re .search (r'expert cache (\d+) slots, ([\d.]+) GiB of VRAM' ,text ) 46if m : 47facts ['expert_cache_slots' ]= int (m .group (1 )) 48facts ['expert_cache_vram_gib' ]= float (m .group (2 )) 49m = re .search (r'PCIe probe: ([\d.]+) GB/s' ,text ) 50if m : 51facts ['pcie_probe_gb_s' ]= float (m .group (1 )) 52m = re .search (r'profile \S+: (\d+) ranked pairs' ,text ) 53if m : 54facts ['profile_ranked_pairs' ]= int (m .group (1 )) 55accepted = drafted = hits = lookups = 0 56for m in re .finditer (r'drafts accepted (\d+) of (\d+)' ,text ): 57accepted += int (m .group (1 )) 58drafted += int (m .group (2 )) 59for m in re .finditer (r'decode expert cache hit rate: [\d.]+% \((\d+) hits / (\d+) lookups\)' ,text ): 60if int (m .group (2 ))> 20000 :# the per-request windows, not the short warm-up ones 61hits += int (m .group (1 )) 62lookups += int (m .group (2 )) 63facts ['drafts_accepted' ]= accepted 64facts ['drafts_drafted' ]= drafted 65facts ['draft_acceptance_pct' ]= round (100 * accepted / drafted ,1 ) 66facts ['decode_cache_hit_pct' ]= round (100 * hits / lookups ,1 ) 67return facts 68 69 70def main (): 71p = argparse .ArgumentParser (description = __doc__ ) 72p .add_argument ('--write' ,action = 'store_true' ) 73args = p .parse_args () 74summary = {} 75for q in QUANTS : 76rs = runs (q ) 77entry = {'engine' :engine_facts (q ), 78'memory' : {s :peak_vram (q ,s )for s in ('run1' ,'run2' ,'run3' ,'needle' )}, 79'needles' :json .load ((DATA / f' { q } -needles.json' ).open ())} 80for kind in ('fresh' ,'followup' ): 81got = [r for r in rs if r ['kind' ]== kind ] 82entry [kind ]= { 83'prefill_tps' :agg ([r ['metrics' ]['prefill_tps' ]for r in got ]), 84'decode_tps' :agg ([r ['metrics' ]['decode_tps' ]for r in got ]), 85'wall_s' :agg ([r ['wall_s' ]for r in got ]), 86'reused_tokens' :sorted ({int (r ['metrics' ]['reused' ])for r in got }), 87'prompt_tokens' :sorted ({int (r ['metrics' ]['prompt_tokens' ])for r in got }), 88'generated_tokens' :sorted ({int (r ['metrics' ]['generated' ])for r in got }), 89 } 90summary [q ]= entry 91'=' * 72 ) 92q ) 93for kind in ('fresh' ,'followup' ): 94for field in ('prefill_tps' ,'decode_tps' ,'wall_s' ): 95a = entry [kind ][field ] 96f" { kind :9s } { field :12s } median { a [ 'median' ]:8.1f } [ { a [ 'min' ]:.1f } - { a [ 'max' ]:.1f } ] n= { a [ 'n' ] } " ) 97f" needles { sum ( 1 for x in entry [ 'needles' ] if x [ 'found' ]) } / { len ( entry [ 'needles' ]) } found" ) 98f" engine { entry [ 'engine' ] } " ) 99if args .write : 100 (DATA / 'summary.json' ).write_text (json .dumps (summary ,indent = 2 )+ '\n' ) 101'wrote' ,DATA / 'summary.json' ) 102 103 104if __name__ == '__main__' : 105main ()