interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / evidence / amd-speed-20261114 / recompute / specdecode.py

109 lines · 9157 bytes Raw Blame History
1#!/usr/bin/env python3
2# Several tokens per pass: SpecDecode's acceptance counts (CPU float32 reference, not the card).
3import json, re
4from fractions import Fraction
5from common import ROOT, Book, sha256
6
7b = Book('specdecode')
8for name in ('lighthouse', 'freerun'):
9 f = f'spec-decode/acceptance/accept-mtp-{name}.json'
10 p = ROOT / f
11 if not p.exists():
12 b.add(f'{name}.state', 'PENDING', '', 'RECORD', 'spec-decode/acceptance', f'{f} not present yet')
13 continue
14 d = json.loads(p.read_text())
15 for variant, seqs in d['results'].items():
16 vk = 'full' if variant == 'full' else 'shortlist'
17 for seq, rows in seqs.items():
18 sk = seq.replace('lighthouse-', '')
19 best = max(rows, key=lambda r: Fraction(r['tokens_per_pass']))
20 for r in rows:
21 tpp = Fraction(r['tokens_per_pass'])
22 b.check(f'{name} {variant} {seq} k={r["k"]} fraction', tpp == Fraction(r['tokens'], r['passes']))
23 if r['k'] in (1, 2, 3):
24 b.add(f'{name}.{vk}.{sk}.k{r["k"]}', round(float(tpp), 3), 'tokens/pass', 'MEASURED', f,
25 'tokens / passes from the exact speculative loop over the recorded sequence (CPU reference)')
26 b.add(f'{name}.{vk}.{sk}.max', round(float(Fraction(best['tokens_per_pass'])), 3), 'tokens/pass', 'MEASURED', f,
27 f'maximum over k = 0..8 (reached at k = {best["k"]})')
28fr = ROOT / 'spec-decode/acceptance/accept-mtp-freerun.json'
29if fr.exists():
30 rows = json.loads(fr.read_text())['results']['full']
31 varied = {k: v for k, v in rows.items() if not k.startswith('lighthouse')}
32 k1 = {k: float(Fraction(next(r for r in v if r['k'] == 1)['tokens_per_pass'])) for k, v in varied.items()}
33 f = 'spec-decode/acceptance/accept-mtp-freerun.json'
34 b.add('varied.prompts', len(k1), 'prompts', 'COUNT', f, 'free-run prompts other than the lighthouse essay')
35 b.add('varied.k1_min', round(min(k1.values()), 2), 'tokens/pass', 'MEASURED', f, f'k = 1, full head, lowest prompt ({min(k1, key=k1.get)})')
36 b.add('varied.k1_max', round(max(k1.values()), 2), 'tokens/pass', 'MEASURED', f, f'k = 1, full head, highest prompt ({max(k1, key=k1.get)})')
37 b.add('varied.tokens_each', sorted({next(r for r in v if r['k'] == 1)['tokens'] for v in varied.values()}), 'tokens', 'COUNT', f, 'generated tokens per varied prompt')
38# extra-row cost (rho) measured on the card, session 3a2e29e5: rho = (median_R / median_1 - 1) / (R - 1),
39# as in spec-decode/card-rho/spec_rho.py line 118
40import statistics
41RS = 'spec-decode/card-s4/results/jupyter-user-261114025237-3a2e29e5'
42rr = json.loads((ROOT / f'{RS}/rho-results.json').read_text())['kernels']
43log = (ROOT / f'{RS}/rho.log').read_text()
44one = statistics.median(rr['fp8gemv_b128f_r1']['per_dispatch_ns'])
45b.check('fp8 R=1 median equals the file', abs(one - rr['fp8gemv_b128f_r1']['median_ns']) < 1e-6)
46b.add('rho.fp8_r1_us', round(one / 1e3, 3), 'us', 'MEASURED', f'{RS}/rho-results.json', 'fp8gemv_b128f 81920x5120, R=1, median per dispatch of 5 trials')
47for R in (2, 3, 8):
48 k = rr[f'fp8gemv_b128f_r{R}']
49 med = statistics.median(k['per_dispatch_ns'])
50 rho = (med / one - 1) / (R - 1)
51 b.check(f'fp8 R={R} rho equals the file and the log', abs(rho - k['rho']) < 1e-12 and f'rho={rho:.4f}' in log)
52 b.check(f'fp8 R={R} rows bit-identical to the one-row kernel', k['rows_bit_identical_to_one_row'] is True and k['finite'])
53 b.add(f'rho.fp8_r{R}_us', round(med / 1e3, 3), 'us', 'MEASURED', f'{RS}/rho-results.json', f'R={R} rows, median per dispatch')
54 b.add(f'rho.fp8_r{R}', round(rho, 4), 'fraction', 'DERIVED', f'{RS}/rho-results.json', '(median_R / median_1 - 1) / (R - 1)')
55b.add('rho.bf16_r1_us', round(statistics.median(rr['bf16gemv2_r1']['per_dispatch_ns']) / 1e3, 3), 'us', 'MEASURED', f'{RS}/rho-results.json',
56 'bf16gemv2 248320x5120 (output head), R=1; R>1 not reached')
57# CPU gates of the speculative step (seeded Omega and the seeded gfx942 executor; hardware NOT_RUN in every file).
58for name, f in (('s0', 'spec-decode/om/gate-spec-results.json'), ('s1', 'spec-decode/om/gate-loop-results.json')):
59 g = json.loads((ROOT / f).read_text())
60 b.check(f'{name} gate verdict PASS, positive output as expected', g['verdict'] == 'PASS' and g['positive']['ok'] and g['positive']['stdout'] == g['positive']['expected'])
61 b.add(f'gate_{name}.cases', int(g['positive']['stdout'][0]), 'cases', 'COUNT', f, 'first line of the positive run: cases (S0) or runs (S1)')
62 b.add(f'gate_{name}.mutants', len(g['mutants']), 'mutants', 'COUNT', f, 'mutants listed')
63 b.add(f'gate_{name}.mutants_caught', sum(m['caught'] is True for m in g['mutants']), 'mutants', 'COUNT', f, 'of those, caught')
64K = 'spec-decode/kernels'
65for run in ('s2-run6', 's2b-conv-run3', 's2b-run4', 's2c-run2', 's2d-run2', 's3a-run1', 's3c-pos-run1', 's3c-select-run1'):
66 g = json.loads((ROOT / f'{K}/{run}/report.json').read_text())
67 b.check(f'{run} report verdict PASS, hardware NOT_RUN', g['verdict'] == 'PASS' and g['hardware'] == 'NOT_RUN')
68S3C = 'spec-decode/s3c/run3'
69g = json.loads((ROOT / f'{S3C}/report.json').read_text())
70r3 = (ROOT / f'{S3C}/run3.log').read_text()
71m3 = re.search(r'^SPEC-S3C PASS rows=(\d+) pass=(\d+) required_mutants=(\d+) caught=(\d+) hardware=NOT_RUN$', r3, re.M)
72b.check('s3c whole-pass gate: report PASS and every required mutant caught', g['verdict'] == 'PASS' and bool(m3) and m3.group(3) == m3.group(4))
73b.add('gate_s3c.required_mutants_caught', int(m3.group(4)), 'mutants', 'COUNT', f'{S3C}/run3.log', 'SPEC-S3C PASS line')
74b.add('gate_s3c.rows', int(m3.group(1)), 'rows', 'COUNT', f'{S3C}/run3.log', 'SPEC-S3C PASS line: rows')
75b.add('gate_s3c.rows_pass', int(m3.group(2)), 'rows', 'COUNT', f'{S3C}/run3.log', 'SPEC-S3C PASS line: rows that pass')
76info = [(i, l) for i, l in enumerate(r3.splitlines(), 1) if l.startswith('S3C INFO-FAIL MUTANT ')]
77b.check('s3c: the one INFO-FAIL row is accept-after-mismatch on line 105, caught_by false on both prompts',
78 info == [(105, 'S3C INFO-FAIL MUTANT object spec_accept_r3 accept-after-mismatch caught {"caught_by": [false, false]}')])
79b.add('gate_s3c.info_mutants_not_caught', len(info), 'mutants', 'COUNT', f'{S3C}/run3.log', 'INFO-FAIL MUTANT lines with caught_by false on both prompts')
80S3A = f'{K}/s3a-run1/report.json'
81aam = [m for m in json.loads((ROOT / S3A).read_text())['mutants'] if m['mutant'] == 'accept-after-mismatch']
82b.check('s3a accept kernel gate lists accept-after-mismatch once', len(aam) == 1)
83b.add('gate_s3a.accept_after_mismatch_failing', aam[0]['failing_cases'], 'cases', 'COUNT', S3A, 'failing cases of that mutant')
84b.add('gate_s3a.accept_after_mismatch_cases', aam[0]['cases'], 'cases', 'COUNT', S3A, 'cases run against that mutant')
85HL = 'amd-report/extracted/spark-logs-20261114/hostloop-gate-final-20261114T022658Z.log'
86hl = (ROOT / HL).read_text()
87hp = re.findall(r'^AMD-KFD-LAUNCH CPU PASS (\{.*\})$', hl, re.M)
88hj = json.loads(hp[0]) if len(hp) == 1 else {}
89b.check('host loop gate: one PASS line, 0 failures, head f859c88f clean', hj.get('failures') == 0 and hj.get('device') == 'NOT_RUN'
90 and bool(re.search(r'^repo \S+ head f859c88fc05f7ecc9d4afcefc328e2515d3647e8 dirty=0 ', hl, re.M)))
91b.add('hostloop.gate_checks', int(hj.get('checks', -1)), 'checks', 'COUNT', HL, '"checks" in the AMD-KFD-LAUNCH CPU PASS line, branch spec-decode2 head f859c88f')
92DRY = 'spec-decode/card-s4/dry4.log'
93dry = (ROOT / DRY).read_text().splitlines()
94b.check('card bundle Spark rehearsal: SPEC-S4 PASS, both controls, DRY-S4 OK', 'SPEC-S4 PASS' in dry and 'DRY-S4 CONTROL corrupted bundle refused' in dry
95 and 'DRY-S4 CONTROL wrong id caught' in dry and dry[-1] == 'DRY-S4 OK')
96dp = [x for x in dry if x.startswith('DRY-PLAN ')]
97b.check('card bundle Spark rehearsal: every DRY-PLAN line OK', bool(dp) and all(x.startswith('DRY-PLAN OK ') for x in dp))
98b.add('s4_dry.plans_ok', len(dp), 'plan checks', 'COUNT', DRY, 'DRY-PLAN OK lines: a real launcher under qemu accepted the plan and stopped at the device (dry_s4.sh lines 4 to 5)')
99b.add('s4_dry.plans_ok_spec', sum(x.endswith(' launch-spec') for x in dp), 'plan checks', 'COUNT', DRY, 'of those, with launch-spec')
100b.add('s4_dry.plans_ok_x86', sum(x.endswith(' launch-x86') for x in dp), 'plan checks', 'COUNT', DRY, 'of those, with launch-x86')
101pl = [x for x in dry if re.match(r'^PLAN \S+ OK [0-9a-f]{64}$', x)]
102b.check('every DRY-PLAN line names a plan from a PLAN ... OK line', {x.split()[2] for x in dp} == {x.split()[1] for x in pl})
103b.add('s4_dry.plans', len(pl), 'plans', 'COUNT', DRY, 'PLAN ... OK lines')
104sm = {float(v) for v in re.findall(r'^RUN \S+ ids_ok complete tok/pass=1\.0 ms/token=([\d.]+) *$', '\n'.join(dry), re.M)}
105b.check('rehearsal RUN lines: one stand-in figure', len(sm) == 1)
106b.add('s4_dry.standin_ms', sm.pop(), 'ms/token', 'RECORD', [DRY, 'spec-decode/card-s4/fake_launch.py'],
107 'printed by the stand-in fake_launch.py (us = 26000 + step), not a measurement')
108b.add('card.state', 'NOT_RUN', '', 'RECORD', [], 'no speculative step has run on the card (spec-decode/RESULT.md section 6, lane notes)')
109b.close()