gpu-head-to-head
aien-dev/gpu-head-to-head
Brought by drakestapleton
gpu-head-to-head / bench / test-run-arm-dra74.py
| 1 | #!/usr/bin/env python3 |
| 2 | """PROTOCOL.md A10 (DRA-74): print-launch argv, OURS binary pin, in-window lock, deadline, cell sets, |
| 3 | TTFT cell sets, the turn-2 prefix-cache override and the session completion (DONE) path.""" |
| 4 | import hashlib |
| 5 | import os |
| 6 | from pathlib import Path |
| 7 | import shlex |
| 8 | import subprocess |
| 9 | import tempfile |
| 10 | import time |
| 11 | import unittest |
| 12 | |
| 13 | HERE = Path(__file__).resolve().parent |
| 14 | SOURCE = (HERE / 'run_arm.sh').read_text() |
| 15 | LEGACY_VARGV = ['vllm', 'serve', '/model', '--served-model-name', 'q36', '--host', '127.0.0.1', '--port', '18191', |
| 16 | '--max-model-len', '49152', '--max-num-seqs', '32', '--gpu-memory-utilization', '0.50', |
| 17 | '--language-model-only'] |
| 18 | |
| 19 | |
| 20 | def piece(start, end): |
| 21 | return SOURCE[SOURCE.index(start):SOURCE.index(end)] |
| 22 | |
| 23 | |
| 24 | def print_launch(arm, **env): |
| 25 | with tempfile.TemporaryDirectory() as tmp: |
| 26 | full = dict(os.environ, H2H_PRINT_LAUNCH='1', H2H_RESULTS=tmp + '/results', H2H_BOARD=tmp + '/BOARD') |
| 27 | full.update(env) |
| 28 | r = subprocess.run(['bash', str(HERE / 'run_arm.sh'), arm, 'D1'], env=full, capture_output=True, |
| 29 | text=True, timeout=30) |
| 30 | touched = os.listdir(tmp) |
| 31 | return r, touched |
| 32 | |
| 33 | |
| 34 | class PrintLaunchTests(unittest.TestCase): |
| 35 | def test_legacy_vllm_argv_is_unchanged(self): |
| 36 | r, touched = print_launch('VLLM') |
| 37 | self.assertEqual(r.returncode, 0, r.stderr) |
| 38 | lines = r.stdout.splitlines() |
| 39 | self.assertEqual(lines[0:2], ['-v', '/home/drakestapleton/models/qwen3.6-35b-a3b-fp8-95a723d0:/model:ro']) |
| 40 | self.assertEqual(lines[3:], LEGACY_VARGV) |
| 41 | self.assertEqual(touched, [], 'print mode must not create the session') |
| 42 | |
| 43 | def test_comparator_arms_append_their_hooks(self): |
| 44 | cases = { |
| 45 | 'VLLM_FP8': ['--kv-cache-dtype', 'auto', '--attention-backend', 'FLASH_ATTN', '--moe-backend', 'deep_gemm', |
| 46 | '--no-enable-prefix-caching'], |
| 47 | 'VLLM_FP8_MTP': ['--kv-cache-dtype', 'auto', '--attention-backend', 'FLASH_ATTN', '--moe-backend', 'deep_gemm', |
| 48 | '--speculative-config', '{"method":"mtp","num_speculative_tokens":3}', |
| 49 | '--no-enable-prefix-caching'], |
| 50 | 'VLLM_NVFP4': ['--quantization', 'modelopt', '--kv-cache-dtype', 'fp8', '--attention-backend', 'FLASHINFER', |
| 51 | '--moe-backend', 'marlin', '--no-enable-prefix-caching'], |
| 52 | } |
| 53 | for arm, tail in cases.items(): |
| 54 | with self.subTest(arm=arm): |
| 55 | r, _ = print_launch(arm) |
| 56 | self.assertEqual(r.returncode, 0, r.stderr) |
| 57 | lines = r.stdout.splitlines() |
| 58 | self.assertEqual(lines[3:3 + len(LEGACY_VARGV)], LEGACY_VARGV) |
| 59 | self.assertEqual(lines[3 + len(LEGACY_VARGV):], tail) |
| 60 | |
| 61 | def test_profile_arm_runs_only_its_cell_set(self): |
| 62 | r, _ = print_launch('VLLM_NVFP4_NSYS', H2H_CELLS='dra74') |
| 63 | self.assertEqual(r.returncode, 4) |
| 64 | r, _ = print_launch('VLLM_NVFP4_NSYS', H2H_CELLS='nsys-c8') |
| 65 | self.assertEqual(r.returncode, 0, r.stderr) |
| 66 | lines = r.stdout.splitlines() |
| 67 | self.assertIn('/nsys/bin/nsys', lines) |
| 68 | self.assertIn('--capture-range=cudaProfilerApi', lines) |
| 69 | self.assertEqual(lines[-2:], ['--profiler-config', '{"profiler":"cuda"}']) |
| 70 | r, _ = print_launch('VLLM_FP8', H2H_CELLS='nsys-c8') |
| 71 | self.assertEqual(r.returncode, 4, 'an unprofiled arm must refuse the profile cell set') |
| 72 | |
| 73 | def test_ours_binary_pin(self): |
| 74 | with tempfile.TemporaryDirectory() as tmp: |
| 75 | Path(tmp, 'aien-serve-http').write_bytes(b'fixture server\n') |
| 76 | sha = hashlib.sha256(b'fixture server\n').hexdigest() |
| 77 | r, _ = print_launch('OURS', OURS_BIN_DIR=tmp, OURS_BIN_SHA256=sha) |
| 78 | self.assertEqual(r.returncode, 0, r.stderr) |
| 79 | self.assertEqual(r.stdout.splitlines(), ['AIEN_OMEGA_FP8_GROUPED_WAVE=0', tmp + '/aien-serve-http']) |
| 80 | r, _ = print_launch('OURS', OURS_BIN_DIR=tmp, OURS_BIN_SHA256='0' * 64) |
| 81 | self.assertEqual(r.returncode, 4) |
| 82 | self.assertIn('sha256', r.stderr) |
| 83 | r, _ = print_launch('OURS', OURS_BIN_DIR=tmp, OURS_BIN_SHA256=sha, OURS_WAVE='2') |
| 84 | self.assertEqual(r.returncode, 4) |
| 85 | |
| 86 | def test_deadline_and_cell_set_are_checked(self): |
| 87 | now = int(time.time()) |
| 88 | self.assertEqual(print_launch('VLLM_FP8', H2H_DEADLINE_EPOCH=str(now + 2000))[0].returncode, 0) |
| 89 | for bad in [str(now + 100), 'soon']: |
| 90 | with self.subTest(deadline=bad): |
| 91 | self.assertEqual(print_launch('VLLM_FP8', H2H_DEADLINE_EPOCH=bad)[0].returncode, 4) |
| 92 | self.assertEqual(print_launch('VLLM_FP8', H2H_CELLS='bogus')[0].returncode, 4) |
| 93 | |
| 94 | def test_client_core_guard(self): |
| 95 | r, _ = print_launch('VLLM_FP8', H2H_CLIENT_CPUS='5', H2H_CLIENT_NICE='19') |
| 96 | self.assertEqual(r.returncode, 0, r.stderr) |
| 97 | self.assertIn('client_cpus 5 client_nice 19', r.stderr) |
| 98 | self.assertNotIn(',5,', ',' + r.stderr.split()[1] + ',') |
| 99 | self.assertEqual(print_launch('VLLM_FP8', H2H_CLIENT_CPUS='12')[0].returncode, 4) |
| 100 | |
| 101 | def ours(self, **env): |
| 102 | with tempfile.TemporaryDirectory() as tmp: |
| 103 | Path(tmp, 'aien-serve-http').write_bytes(b'fixture server\n') |
| 104 | sha = hashlib.sha256(b'fixture server\n').hexdigest() |
| 105 | return print_launch('OURS', OURS_BIN_DIR=tmp, OURS_BIN_SHA256=sha, **env)[0] |
| 106 | |
| 107 | def test_turn2_prefix_override(self): |
| 108 | r, touched = print_launch('VLLM_FP8', H2H_CELLS='ttft-turn2', H2H_PREFIX='on') |
| 109 | self.assertEqual(r.returncode, 0, r.stderr) |
| 110 | self.assertEqual(touched, []) |
| 111 | lines = r.stdout.splitlines() |
| 112 | self.assertEqual(lines[-1], '--enable-prefix-caching') |
| 113 | self.assertNotIn('--no-enable-prefix-caching', lines) |
| 114 | self.assertEqual(self.ours(H2H_CELLS='ttft-turn2').returncode, 0, 'OURS turn 2 is a labelled re-read') |
| 115 | |
| 116 | def test_turn2_prefix_override_negative_controls(self): |
| 117 | for arm, env in [('VLLM_FP8', dict(H2H_CELLS='ttft-turn2')), # cached row needs the cache |
| 118 | ('VLLM_FP8', dict(H2H_CELLS='dra74', H2H_PREFIX='on')), # never on timing cells |
| 119 | ('VLLM_FP8', dict(H2H_CELLS='ttft-turn2,ttft-fresh', H2H_PREFIX='on')), |
| 120 | ('VLLM_FP8', dict(H2H_CELLS='ttft-turn2', H2H_PREFIX='yes')), |
| 121 | ('VLLM_NVFP4_NSYS', dict(H2H_CELLS='ttft-turn2', H2H_PREFIX='on'))]: |
| 122 | with self.subTest(arm=arm, **env): |
| 123 | self.assertEqual(print_launch(arm, **env)[0].returncode, 4) |
| 124 | self.assertEqual(self.ours(H2H_CELLS='ttft-turn2', H2H_PREFIX='on').returncode, 4) |
| 125 | |
| 126 | def test_cell_set_lists(self): |
| 127 | for env in [dict(H2H_CELLS='dra74,ttft-fresh'), dict(H2H_CELLS='ttft-fresh', H2H_TTFT_PROMPTS='t32k'), |
| 128 | dict(H2H_CELLS='ttft-fresh', H2H_TTFT_REPS='1', H2H_TTFT_REP_BASE='2')]: |
| 129 | with self.subTest(**env): |
| 130 | r = print_launch('VLLM_NVFP4', **env)[0] |
| 131 | self.assertEqual(r.returncode, 0, r.stderr) |
| 132 | self.assertEqual(r.stdout.splitlines()[-1], '--no-enable-prefix-caching') |
| 133 | self.assertEqual(self.ours(H2H_CELLS='ttft-fresh,ttft-turn2').returncode, 0) |
| 134 | for arm, env in [('VLLM_FP8', dict(H2H_CELLS='dra74,dra74')), ('VLLM_FP8', dict(H2H_CELLS=',')), |
| 135 | ('VLLM_FP8', dict(H2H_CELLS='ttft-fresh', H2H_TTFT_PROMPTS='t4k')), |
| 136 | ('VLLM_FP8', dict(H2H_CELLS='ttft-fresh', H2H_TTFT_PROMPTS='t2k,t2k')), |
| 137 | ('VLLM_FP8', dict(H2H_CELLS='ttft-fresh', H2H_TTFT_REPS='0')), |
| 138 | ('VLLM_FP8', dict(H2H_CELLS='ttft-fresh', H2H_TTFT_REP_BASE='x')), |
| 139 | ('VLLM_NVFP4_NSYS', dict(H2H_CELLS='nsys-c8,dra74')), |
| 140 | ('VLLM_NVFP4_NSYS', dict(H2H_CELLS='ttft-fresh')), |
| 141 | ('VLLM', dict(H2H_CELLS='ttft-fresh'))]: |
| 142 | with self.subTest(arm=arm, **env): |
| 143 | self.assertEqual(print_launch(arm, **env)[0].returncode, 4) |
| 144 | |
| 145 | |
| 146 | class VllmArgvTests(unittest.TestCase): |
| 147 | def argv(self, prefix): |
| 148 | script = ('declare -A ARM_QUANT ARM_KV ARM_ATTN ARM_MOE ARM_SPEC ARM_PREFIX ARM_PROFILE\n' |
| 149 | 'ARM=VLLM_X VLLM_UTIL=0.50 ARM_PREFIX[VLLM_X]=%s\n' % shlex.quote(prefix) |
| 150 | + piece('vllm_argv() {', 'stop_server() {') + '\nvllm_argv && printf "%s\\n" "${VARGV[@]}"\n') |
| 151 | return subprocess.run(['bash', '-c', script], capture_output=True, text=True, timeout=5) |
| 152 | |
| 153 | def test_prefix_values(self): |
| 154 | self.assertEqual(self.argv('on').stdout.splitlines()[-1], '--enable-prefix-caching') |
| 155 | self.assertEqual(self.argv('').stdout.splitlines(), LEGACY_VARGV) |
| 156 | bad = self.argv('maybe') |
| 157 | self.assertEqual(bad.returncode, 1) |
| 158 | self.assertIn('must be on, off or empty', bad.stderr) |
| 159 | |
| 160 | |
| 161 | class WindowLockTests(unittest.TestCase): |
| 162 | def held(self, *, held_id='w1', env_id='w1', gb10='exclusive', lock_held='1'): |
| 163 | with tempfile.TemporaryDirectory() as tmp: |
| 164 | sw = Path(tmp, 'spark-window') |
| 165 | sw.write_text('#!/bin/sh\n[ "$1" = id ] && echo %s\n' % held_id) |
| 166 | sw.chmod(0o755) |
| 167 | Path(tmp, 'gb10').write_text(gb10 + '\n') |
| 168 | env = dict(os.environ, SPARK_WINDOW_BIN=str(sw), SPARK_WINDOW=env_id, SPARK_WINDOW_DIR=tmp, |
| 169 | AIEN_GB10_LOCK_HELD=lock_held) |
| 170 | script = piece('window_held() {', 'arm_preconditions() {') + '\nwindow_held\n' |
| 171 | return subprocess.run(['bash', '-c', script], env=env, capture_output=True, text=True, timeout=15) |
| 172 | |
| 173 | def test_exclusive_window_is_accepted(self): |
| 174 | self.assertEqual(self.held().returncode, 0) |
| 175 | |
| 176 | def test_negative_controls_refuse(self): |
| 177 | for kw, why in [(dict(held_id='w2'), 'is not SPARK_WINDOW'), (dict(gb10='shared'), 'exclusively'), |
| 178 | (dict(lock_held=''), 'incomplete')]: |
| 179 | with self.subTest(**kw): |
| 180 | r = self.held(**kw) |
| 181 | self.assertEqual(r.returncode, 1) |
| 182 | self.assertIn(why, r.stdout) |
| 183 | |
| 184 | def test_window_mode_never_waits_on_flock(self): |
| 185 | block = piece('if [ "${AIEN_GB10_LOCK_HELD:-}" = 1 ] || [ -n "${SPARK_WINDOW:-}" ]; then', 'GPU_LOCK_HELD=1') |
| 186 | window_branch = block[:block.index('elif')] |
| 187 | self.assertNotIn('flock', window_branch.replace('no flock taken', '')) |
| 188 | self.assertIn('GPU_LOCK_RELEASE=0', window_branch) |
| 189 | self.assertIn('flock -w 900 9', block[block.index('else'):]) |
| 190 | |
| 191 | |
| 192 | class DeadlineAndCellSetTests(unittest.TestCase): |
| 193 | def epochs(self, deadline): |
| 194 | block = piece('LOCK_EPOCH=$(date +%s)', 'echo "lock_epoch') |
| 195 | script = 'date() { echo 1000; }\nDEADLINE=%s\n%s\necho $STOP_AT $WARN_AT $QUIET_AT\n' % (deadline, block) |
| 196 | return subprocess.run(['bash', '-c', script], capture_output=True, text=True, timeout=5).stdout.split() |
| 197 | |
| 198 | def test_epochs(self): |
| 199 | self.assertEqual(self.epochs(''), ['4540', '4300', '4000']) # no deadline: the 60-min hold |
| 200 | self.assertEqual(self.epochs('2140'), ['2080', '1960', '1960']) # slice deadline wins |
| 201 | self.assertEqual(self.epochs('9999'), ['4540', '4300', '4000']) # later deadline never extends |
| 202 | |
| 203 | def cells(self, cellset, arm='VLLM_FP8', fail='', prompts='t2k,t8k,t32k'): |
| 204 | """Run the session's cell-set block with a stub cell(); the real mark_complete decides DONE.""" |
| 205 | block = piece(' EXPECTED_CELLS=0\n for set in', 'else\n if [ -s "$LOGD/listen.txt" ]') |
| 206 | complete = piece('mark_complete() {', 'start_watchdog() {') |
| 207 | with tempfile.TemporaryDirectory() as tmp: |
| 208 | script = ('LOGD=%s PORT=1 ARM=%s CELLSET=%s FAIL=%s TTFT_PROMPTS=%s TTFT_REPS=3 TTFT_REP_BASE=0\n' |
| 209 | 'CELLS_COMPLETED=0 SESSION_RC=1\n' |
| 210 | 'cell() { echo "$*" >> "$LOGD/cells"; [ "$1" = "$FAIL" ] && return 1;' |
| 211 | ' CELLS_COMPLETED=$((CELLS_COMPLETED+1)); }\n' |
| 212 | 'curl() { echo "$@" >> "$LOGD/curl"; }\nsleep() { :; }\nboard() { :; }\n' |
| 213 | 'ts() { echo T; }\n%s\n%s\necho "$EXPECTED_CELLS $SESSION_RC"\n') % ( |
| 214 | shlex.quote(tmp), arm, cellset, fail, prompts, complete, block) |
| 215 | r = subprocess.run(['bash', '-c', script], capture_output=True, text=True, timeout=10) |
| 216 | lines = Path(tmp, 'cells').read_text().splitlines() if Path(tmp, 'cells').exists() else [] |
| 217 | curls = Path(tmp, 'curl').read_text() if Path(tmp, 'curl').exists() else '' |
| 218 | expected, rc = r.stdout.split()[-2:] |
| 219 | done = Path(tmp, 'DONE').exists() |
| 220 | incomplete = Path(tmp, 'INCOMPLETE').read_text() if Path(tmp, 'INCOMPLETE').exists() else '' |
| 221 | return dict(expected=expected, rc=rc, cells=[l.split()[0] for l in lines], lines=lines, curls=curls, |
| 222 | done=done, incomplete=incomplete) |
| 223 | |
| 224 | def test_dra74_set(self): |
| 225 | s = self.cells('dra74') |
| 226 | self.assertEqual(s['expected'], '7') |
| 227 | self.assertEqual(s['cells'], ['decode-c1', 'decode-c4', 'decode-c8', 'decode-c16', |
| 228 | 'prefill-p256', 'prefill-p2k', 'prefill-p8k']) |
| 229 | |
| 230 | def test_complete_session_marks_done(self): |
| 231 | # regression: the session must call mark_complete after its cells, or every run ends INCOMPLETE |
| 232 | s = self.cells('dra74') |
| 233 | self.assertEqual((s['rc'], s['done'], s['incomplete']), ('0', True, '')) |
| 234 | |
| 235 | def test_short_session_is_incomplete(self): |
| 236 | s = self.cells('dra74', fail='prefill-p2k') |
| 237 | self.assertEqual((s['rc'], s['done']), ('1', False)) |
| 238 | self.assertIn('5/7', s['incomplete']) |
| 239 | self.assertNotIn('prefill-p8k', s['cells']) |
| 240 | |
| 241 | def test_full_set_unchanged(self): |
| 242 | s = self.cells('full') |
| 243 | self.assertEqual((s['expected'], len(s['cells']), s['rc']), ('14', 14, '0')) |
| 244 | |
| 245 | def test_nsys_set_brackets_one_cell_with_the_profiler(self): |
| 246 | s = self.cells('nsys-c8') |
| 247 | self.assertEqual((s['expected'], s['cells']), ('1', ['decode-c8'])) |
| 248 | self.assertEqual([l.split()[-1].rsplit('/', 1)[-1] for l in s['curls'].splitlines()], |
| 249 | ['start_profile', 'stop_profile']) |
| 250 | |
| 251 | def test_ttft_fresh_cells(self): |
| 252 | s = self.cells('ttft-fresh') |
| 253 | self.assertEqual((s['expected'], s['rc']), ('3', '0')) |
| 254 | self.assertEqual(s['cells'], ['ttft-fresh-2k', 'ttft-fresh-8k', 'ttft-fresh-32k']) |
| 255 | self.assertEqual(s['lines'][2], 'ttft-fresh-32k 1 1 ttft.jsonl --select t32k --ttft fresh --warmup 1 ' |
| 256 | '--warm-select t2k --reps 3 --rep-base 0') |
| 257 | self.assertEqual(self.cells('ttft-fresh', prompts='t32k')['cells'], ['ttft-fresh-32k']) |
| 258 | |
| 259 | def test_turn2_label_follows_the_arm(self): |
| 260 | self.assertEqual(self.cells('ttft-turn2', arm='OURS')['cells'], ['ttft-turn2-reread']) |
| 261 | s = self.cells('ttft-turn2', arm='VLLM_FP8') |
| 262 | self.assertEqual((s['cells'], s['expected'], s['rc']), (['ttft-turn2-cached'], '1', '0')) |
| 263 | self.assertIn('--select t32k --ttft turn2', s['lines'][0]) |
| 264 | |
| 265 | def test_cell_set_list_sums_and_stops_on_a_short_set(self): |
| 266 | s = self.cells('dra74,ttft-fresh') |
| 267 | self.assertEqual((s['expected'], len(s['cells']), s['rc'], s['done']), ('10', 10, '0', True)) |
| 268 | s = self.cells('dra74,ttft-fresh', fail='decode-c4') |
| 269 | self.assertEqual(s['cells'], ['decode-c1', 'decode-c4']) |
| 270 | self.assertEqual((s['rc'], s['done']), ('1', False)) |
| 271 | s = self.cells('ttft-fresh,ttft-turn2', arm='OURS', fail='ttft-turn2-reread') |
| 272 | self.assertEqual((s['expected'], s['rc']), ('4', '1')) |
| 273 | self.assertIn('3/4', s['incomplete']) |
| 274 | |
| 275 | |
| 276 | if __name__ == '__main__': |
| 277 | unittest.main() |