okami.mom/strata

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

Niko1221bench: community report, Intel Arc Pro B65 32 GB (SYCL), IQ2_XS (PR #955)98d1c8d4f

main
6.0 KiB108 linesraw
1#!/usr/bin/env python3
2"""Validate three repetitions and summarize native timings without mixing tasks."""
3import argparse
4import csv
5import hashlib
6import json
7from pathlib import Path
8import re
9import statistics
10
11METRICS = ('prompt_tps', 'decode_tps', 'ttft_s', 'post_first_tps', 'total_s')
12def stats(values):
13    return {'median': statistics.median(values), 'minimum': min(values), 'maximum': max(values)}
14
15def main():
16    ap = argparse.ArgumentParser()
17    ap.add_argument('input', type=Path)
18    ap.add_argument('output', type=Path)
19    a = ap.parse_args()
20    rows_path = a.input / 'requests.json'
21    if not rows_path.exists():
22        rows_path = a.input / 'results.json'
23    rows = json.loads(rows_path.read_text())
24    runs = json.loads((a.input / 'runs.json').read_text())
25    result = json.loads((a.input / 'result.json').read_text())
26    assert result['failure'] is None
27    assert len(runs) == 3 and all(r['native_exit'] == 0 for r in runs)
28    assert all(r['valid'] for r in rows)
29    measured = [r for r in rows if r['measured']]
30    assert len(measured) == 30
31    for r in rows:
32        n = r['native']
33        assert r['native_done_line'].startswith('DONE ')
34        assert n['generated'] == r['output_tokens'] and n['prompt_tokens'] == r['input_tokens']
35        assert n['reused'] == 0 and n['prompt_read'] == r['input_tokens']
36        assert abs(r['prompt_tps'] - n['prompt_read'] * 1000 / n['prompt_ms']) < 1e-10
37        assert abs(r['decode_tps'] - n['generated'] * 1000 / n['decode_ms']) < 1e-10
38        # Independent stderr format: timings/rates are rounded more coarsely
39        # than DONE; validate counts and allow only that documented rounding.
40        assert len(r['native_timing_lines']) == 1
41        line = re.search(r'prompt (\d+) tokens = (\d+) reused \+ (\d+) read in ([\d.]+) ms '
42                         r'\(([\d.]+) tok/s\), (\d+) generated in ([\d.]+) ms \(([\d.]+) tok/s\)',
43                         r['native_timing_lines'][0])
44        assert line is not None
45        assert (int(line[1]), int(line[2]), int(line[3]), int(line[6])) == (n['prompt_tokens'], n['reused'], n['prompt_read'], n['generated'])
46        assert abs(float(line[4]) - n['prompt_ms']) <= 1 and abs(float(line[7]) - n['decode_ms']) <= 1
47        assert abs(float(line[5]) - r['prompt_tps']) <= 0.11 and abs(float(line[8]) - r['decode_tps']) <= 0.11
48    per_task = []
49    for length in (512, 7000):
50        for i in range(5):
51            label = f'bench-{length}-{i}'
52            rr = [r for r in measured if r['label'] == label]
53            assert len(rr) == 3 and sorted(r['run'] for r in rr) == [1, 2, 3]
54            assert len({r['input_ids_sha256'] for r in rr}) == 1
55            assert all(r['output_tokens'] == 640 and r['native']['finish'] == 'length' for r in rr)
56            same = len({r['output_ids_sha256'] for r in rr}) == 1
57            assert same, f'greedy stream changed: {label}'
58            accepted = sum(r['native']['drafts_accepted'] for r in rr)
59            offered = sum(r['native']['drafts_offered'] for r in rr)
60            per_task.append({'label': label, 'input_tokens': length, 'task_index': i,
61                             'runs': 3, 'generated_tokens': 640, 'reused_tokens': 0,
62                             'all_output_ids_equal': same, 'draft_acceptance_pooled': accepted / offered,
63                             **{k: stats([r[k] for r in rr]) for k in METRICS}})
64    per_run = []
65    for run in (1, 2, 3):
66        for length in (512, 7000):
67            rr = [r for r in measured if r['run'] == run and r['input_tokens'] == length]
68            assert len(rr) == 5
69            per_run.append({'run': run, 'input_tokens': length, 'tasks': 5,
70                            **{k: statistics.median(r[k] for r in rr) for k in METRICS}})
71    across_run_medians = []
72    for length in (512, 7000):
73        rr = [r for r in per_run if r['input_tokens'] == length]
74        across_run_medians.append({'input_tokens': length, 'runs': 3, 'tasks_per_run': 5,
75                                  **{k: stats([r[k] for r in rr]) for k in METRICS}})
76    summary = {'native_timing_definition': 'prompt_read*1000/prompt_ms; generated*1000/decode_ms from DONE',
77               'per_task_three_repetitions': per_task, 'five_task_medians_per_run': per_run,
78               'range_of_three_five_task_medians': across_run_medians,
79               'successful_measured_requests': 30, 'failed_requests': 0,
80               'excluded_warmups_and_checks': len(rows) - 30,
81               'all_greedy_output_ids_equal_across_three_runs': True,
82               'all_native_exits_zero': True}
83    a.output.mkdir(parents=True, exist_ok=True)
84    (a.output / 'summary.json').write_text(json.dumps(summary, indent=2) + '\n')
85    # Raw JSON retains excluded checks and warmups, not just selected successes.
86    (a.output / 'results.json').write_text(json.dumps(rows, indent=2) + '\n')
87    fields = ['run', 'label', 'measured', 'input_tokens', 'output_tokens', 'prompt_ms', 'decode_ms',
88              'reused_tokens', 'drafts_accepted', 'drafts_offered', *METRICS, 'valid']
89    with (a.output / 'results.csv').open('w', newline='') as f:
90        w = csv.DictWriter(f, fieldnames=fields, lineterminator='\n')
91        w.writeheader()
92        for r in rows:
93            n = r['native']
94            w.writerow({**{k: r[k] for k in fields if k in r},
95                        'prompt_ms': n['prompt_ms'], 'decode_ms': n['decode_ms'],
96                        'reused_tokens': n['reused'], 'drafts_accepted': n['drafts_accepted'],
97                        'drafts_offered': n['drafts_offered']})
98    lines = []
99    for r in rows:
100        lines.append(f"# run={r['run']} label={r['label']} measured={r['measured']}")
101        lines.append(r['native_done_line'].strip())
102        lines.extend(r['native_timing_lines'])
103    (a.output / 'native-timings.log').write_text('\n'.join(lines) + '\n')
104    print(json.dumps({'validated_measured_requests': 30, 'native_exits': [r['native_exit'] for r in runs],
105                      'output_hashes_identical': True, 'summary': across_run_medians}))
106
107if __name__ == '__main__':
108    main()