okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

jase100kCommunity benchmark: RX 7900 GRE (gfx1100, 16 GB), three Flash-Next quants (#740)7b52a0b62

main
4.2 KiB105 linesraw
1#!/usr/bin/env python3
2"""Aggregate the runs in ../data into medians, ranges and memory peaks.
3
4    python summarize.py            # print the tables
5    python 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):
22    out = []
23    for n in (1, 2, 3):
24        out.extend(json.load((DATA / f'{quant}-run{n}.json').open()))
25    return out
26
27
28def agg(values):
29    return dict(median=round(statistics.median(values), 1), min=round(min(values), 1),
30                max=round(max(values), 1), n=len(values))
31
32
33def peak_vram(quant, suffix):
34    path = DATA / 'memory' / f'{quant}-mem-{suffix}.csv'
35    rows = list(csv.DictReader(path.open()))
36    cols = [c for c in rows[0] if c.endswith('_vram_used')]
37    return dict(samples=len(rows),
38                vram_peak_gib=round(max(max(int(r[c]) for r in rows) for c in cols) / 2 ** 30, 2),
39                ram_used_peak_gib=round(max(float(r['ram_used_mib']) for r in rows) / 1024, 2))
40
41
42def engine_facts(quant):
43    text = (DATA / f'{quant}.engine.log').read_text(errors='replace')
44    facts = {}
45    m = re.search(r'expert cache (\d+) slots, ([\d.]+) GiB of VRAM', text)
46    if m:
47        facts['expert_cache_slots'] = int(m.group(1))
48        facts['expert_cache_vram_gib'] = float(m.group(2))
49    m = re.search(r'PCIe probe: ([\d.]+) GB/s', text)
50    if m:
51        facts['pcie_probe_gb_s'] = float(m.group(1))
52    m = re.search(r'profile \S+: (\d+) ranked pairs', text)
53    if m:
54        facts['profile_ranked_pairs'] = int(m.group(1))
55    accepted = drafted = hits = lookups = 0
56    for m in re.finditer(r'drafts accepted (\d+) of (\d+)', text):
57        accepted += int(m.group(1))
58        drafted += int(m.group(2))
59    for m in re.finditer(r'decode expert cache hit rate: [\d.]+% \((\d+) hits / (\d+) lookups\)', text):
60        if int(m.group(2)) > 20000:  # the per-request windows, not the short warm-up ones
61            hits += int(m.group(1))
62            lookups += int(m.group(2))
63    facts['drafts_accepted'] = accepted
64    facts['drafts_drafted'] = drafted
65    facts['draft_acceptance_pct'] = round(100 * accepted / drafted, 1)
66    facts['decode_cache_hit_pct'] = round(100 * hits / lookups, 1)
67    return facts
68
69
70def main():
71    p = argparse.ArgumentParser(description=__doc__)
72    p.add_argument('--write', action='store_true')
73    args = p.parse_args()
74    summary = {}
75    for q in QUANTS:
76        rs = runs(q)
77        entry = {'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())}
80        for kind in ('fresh', 'followup'):
81            got = [r for r in rs if r['kind'] == kind]
82            entry[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            }
90        summary[q] = entry
91        print('=' * 72)
92        print(q)
93        for kind in ('fresh', 'followup'):
94            for field in ('prefill_tps', 'decode_tps', 'wall_s'):
95                a = entry[kind][field]
96                print(f"  {kind:9s} {field:12s} median {a['median']:8.1f}  [{a['min']:.1f}-{a['max']:.1f}]  n={a['n']}")
97        print(f"  needles {sum(1 for x in entry['needles'] if x['found'])}/{len(entry['needles'])} found")
98        print(f"  engine {entry['engine']}")
99    if args.write:
100        (DATA / 'summary.json').write_text(json.dumps(summary, indent=2) + '\n')
101        print('wrote', DATA / 'summary.json')
102
103
104if __name__ == '__main__':
105    main()