gpu-head-to-head
aien-dev/gpu-head-to-head
Brought by drakestapleton
gpu-head-to-head / bench / test-extract-admission.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Prove that rejected, unobserved and ambiguous cells cannot reach report data.""" |
| 3 | import json |
| 4 | import os |
| 5 | from pathlib import Path |
| 6 | import subprocess |
| 7 | import sys |
| 8 | import tempfile |
| 9 | import unittest |
| 10 | |
| 11 | HERE = Path(__file__).resolve().parent |
| 12 | |
| 13 | class AdmissionTests(unittest.TestCase): |
| 14 | def extract(self, statuses, arm='CONTROL', chunks=None, completion_tokens=2, stdout=False): |
| 15 | with tempfile.TemporaryDirectory() as tmp: |
| 16 | root = Path(tmp) |
| 17 | raw = root / 'results/raw' |
| 18 | raw.mkdir(parents=True) |
| 19 | row = dict(cell_run=arm + '-R0-decode-t1', warmup=False, arm=arm, |
| 20 | round='R0', metric='decode', rep=0, batch_id='fixture', stream_index=0, |
| 21 | load1_start=0, t_send=1, t_first=2, t_last=3, error=None, http_status=200, |
| 22 | usage=dict(prompt_tokens=5, completion_tokens=completion_tokens)) |
| 23 | if chunks is not None: |
| 24 | row['chunks'] = chunks |
| 25 | (raw / (arm + '-R0.jsonl')).write_text(json.dumps(row) + '\n') |
| 26 | if statuses is not None: |
| 27 | entries = [dict(cell_run=row['cell_run'], status=status) for status in statuses] |
| 28 | (root / 'results/cell-status.jsonl').write_text(''.join(json.dumps(x)+'\n' for x in entries)) |
| 29 | result = subprocess.run([sys.executable, os.environ.get('H2H_EXTRACT_SCRIPT', str(HERE / 'extract.py')), tmp], |
| 30 | text=True, capture_output=True, timeout=5, check=True) |
| 31 | return result.stdout if stdout else json.dumps(arm) in result.stdout |
| 32 | |
| 33 | def test_only_single_pass_is_admitted(self): |
| 34 | self.assertTrue(self.extract(['PASS'])) |
| 35 | def test_failed_or_unobserved_cells_are_excluded(self): |
| 36 | for statuses in [[], ['FAIL'], ['NOT_RUN'], ['VOID'], ['UNKNOWN']]: |
| 37 | with self.subTest(statuses=statuses): |
| 38 | self.assertFalse(self.extract(statuses)) |
| 39 | def test_duplicate_or_conflicting_admissions_are_excluded(self): |
| 40 | for statuses in [['PASS', 'PASS'], ['FAIL', 'PASS'], ['PASS', 'FAIL']]: |
| 41 | with self.subTest(statuses=statuses): |
| 42 | self.assertFalse(self.extract(statuses)) |
| 43 | def test_historical_runs_keep_explicit_legacy_behavior(self): |
| 44 | self.assertTrue(self.extract(None)) |
| 45 | def test_profiled_arm_rows_never_enter_timing(self): |
| 46 | # A10: *_NSYS rows are excluded; the same row under the unprofiled arm name is the control |
| 47 | self.assertFalse(self.extract(['PASS'], arm='VLLM_NVFP4_NSYS')) |
| 48 | self.assertTrue(self.extract(['PASS'], arm='VLLM_NVFP4')) |
| 49 | def test_mtp_rows_count_usage_tokens_not_stream_chunks(self): |
| 50 | # A10: an MTP stream delivers several tokens per chunk; the row carries usage.completion_tokens |
| 51 | out = self.extract(['PASS'], arm='VLLM_FP8_MTP', chunks=3, completion_tokens=9, stdout=True) |
| 52 | fields = out[out.index('{"VLLM_FP8_MTP"'):].split('}')[0].split(', ') |
| 53 | self.assertEqual(fields[11], '9') |
| 54 | |
| 55 | if __name__ == '__main__': |
| 56 | unittest.main() |