-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_gdn_packed_component.py
More file actions
2592 lines (2345 loc) · 115 KB
/
Copy pathtest_gdn_packed_component.py
File metadata and controls
2592 lines (2345 loc) · 115 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Fail-closed tests for the packed-vs-rollback serving component.
The metric schema comes from ``vllm/benchmarks/serve.py:563-748,1188-1284``
at vLLM ``702f481``. The AB/BA/AB and every-axis acceptance contract is the
local G3 gate in ``.agents/specs/gdn-packed-decode.md``.
"""
from __future__ import annotations
import json
import pathlib
import shutil
import shlex
import statistics
import subprocess
import tempfile
import unittest
from unittest import mock
import tools.bench.gdn_packed_component as gdn_component
from tools.bench.gdn_packed_component import (
ARMS,
CONCURRENCIES,
LEG_ORDER,
REPETITIONS,
WARMUP_LABEL,
build_component_plan,
finalize_evidence,
summarize_component_records,
summarize_evidence,
verify_finalized_evidence,
)
from tools.bench.online_gate import (
FLASHINFER_VERSION,
MODEL_REVISIONS,
OnlineRun,
PANDAS_VERSION,
POINTS,
TRACE_CLEAN_FIXED_ENV,
TRACE_REQUIRED_ENV,
TRACE_SYSTEM_PATH,
VLLM_ORACLE_VERSION,
build_client_command,
)
from tools.bench.serve_low_common import (
HarnessError,
SGLANG_COMMIT,
VLLM_COMMIT,
sha256_file,
)
from tests.tools.test_online_gate_client import (
write_cache_drop_report,
write_profile_log,
)
SOURCE_SHA = "c" * 40
SOURCE_ROOT = pathlib.Path(__file__).resolve().parents[2]
# Text anchors bounding the diagnostic-c16 flow inside the driver script.
DIAG_BEGIN = "# >>> diagnostic-c16 flow"
DIAG_END = "# <<< diagnostic-c16 flow"
def _isolated_environment(
*, arm: str, fixture: pathlib.Path, native: pathlib.Path, home: pathlib.Path
) -> list[str]:
values = {
"HOME": str(home),
"PYTHONPATH": str(SOURCE_ROOT),
"PATH": TRACE_SYSTEM_PATH,
**TRACE_CLEAN_FIXED_ENV,
**TRACE_REQUIRED_ENV,
"VT_FP4_AUTOTUNE_CACHE_PATH": str(native),
"VT_FP4_AUTOTUNE_VERBOSE": "1",
"VT_FP4_FLASHINFER_CACHE_PATH": str(fixture),
"VT_GDN_PACKED_DECODE": "1" if arm == "packed" else "0",
}
return [f"{name}={value}" for name, value in values.items()]
def _clean_environment(*, home: pathlib.Path) -> list[str]:
values = {
"HOME": str(home),
"PYTHONPATH": str(SOURCE_ROOT),
"PATH": TRACE_SYSTEM_PATH,
**TRACE_CLEAN_FIXED_ENV,
}
return [f"{name}={value}" for name, value in values.items()]
def _write_model_gate_log(
path: pathlib.Path,
*,
fixture: pathlib.Path,
native: pathlib.Path,
snapshot: pathlib.Path,
) -> None:
write_profile_log(
path,
fixture=fixture,
native_target=native,
server_pid=99,
)
with path.open("a", encoding="utf-8") as output:
output.write(
"/source/tests/parity/test_qwen27_paged_engine.cpp:150: MESSAGE: "
"qwen27_paged_engine: loading full 27B via FromModelDir("
f"{snapshot}) — dense W4A4 fp4-resident loader + engine stack...\n"
"qwen27_paged_engine M0-EXIT: produced 16/16 tokens; "
'continuation="fixture"\n'
"qwen27_paged_engine: full production stream 16/16 token-exact "
"vs vLLM\n"
"[doctest] test cases: 1 | 1 passed | 0 failed | 0 skipped\n"
"[doctest] assertions: 235 | 235 passed | 0 failed |\n"
"[doctest] Status: SUCCESS!\n"
)
def _thermal_snapshot(
*,
sw_thermal_us: int = 0,
hw_thermal_us: int = 0,
hw_power_braking_us: int = 0,
hw_thermal_active: bool = False,
) -> str:
return (
"==============NVSMI LOG==============\n"
"GPU 00000000:01:00.0\n"
" Clocks Event Reasons\n"
" SW Power Cap : Not Active\n"
" HW Slowdown : Not Active\n"
" HW Thermal Slowdown : "
+ ("Active" if hw_thermal_active else "Not Active")
+ "\n"
" HW Power Brake Slowdown : Not Active\n"
" SW Thermal Slowdown : Not Active\n"
" Temperature\n"
" GPU Current Temp : 45 C\n"
" GPU Power Readings\n"
" Average Power Draw : 100.00 W\n"
" Instantaneous Power Draw : 105.00 W\n"
" Clocks Event Reasons Counters\n"
" SW Power Capping : 0 us\n"
" Sync Boost : 0 us\n"
f" SW Thermal Slowdown : {sw_thermal_us} us\n"
f" HW Thermal Slowdown : {hw_thermal_us} us\n"
f" HW Power Braking : {hw_power_braking_us} us\n"
)
def _record(*, concurrency: int, packed_better: bool, repetition: int) -> dict:
requests = {2: 6, 16: 96}[concurrency]
duration = 10.0 if packed_better else 12.0
latency = 8.0 if packed_better else 10.0
record = {
"completed": requests,
"duration": duration,
"errors": [""] * requests,
"failed": 0,
"generated_texts": [f"text-{repetition}-{index}" for index in range(requests)],
"input_lens": [1024] * requests,
"itls": [[latency / 1000.0] * 127 for _ in range(requests)],
"max_concurrency": concurrency,
"max_concurrent_requests": concurrency,
"num_prompts": requests,
"output_lens": [128] * requests,
"output_throughput": requests * 128 / duration,
"request_throughput": requests / duration,
"start_times": [float(index // concurrency) * 1.5 for index in range(requests)],
"total_input_tokens": requests * 1024,
"total_output_tokens": requests * 128,
"total_token_throughput": requests * (1024 + 128) / duration,
"ttfts": [latency / 1000.0] * requests,
}
for metric in ("ttft", "tpot", "itl"):
for stat in ("mean", "median", "p90", "p99"):
record[f"{stat}_{metric}_ms"] = latency
for stat in ("mean", "median", "p90", "p99"):
record[f"{stat}_e2el_ms"] = latency * 128
return record
def _set_latency(record: dict, latency_ms: float) -> None:
requests = record["completed"]
record["ttfts"] = [latency_ms / 1000.0] * requests
record["itls"] = [[latency_ms / 1000.0] * 127 for _ in range(requests)]
for metric in ("ttft", "tpot", "itl"):
for stat in ("mean", "median", "p90", "p99"):
record[f"{stat}_{metric}_ms"] = latency_ms
for stat in ("mean", "median", "p90", "p99"):
record[f"{stat}_e2el_ms"] = latency_ms * 128
def _apply_ttft_ms(record: dict, ttfts_ms: list[float]) -> None:
"""Replace the TTFT samples and re-derive every reported timing field.
Only the raw ``ttfts`` array changes; the ITL/output arrays and duration
stay fixed, so throughput, TPOT and ITL are untouched and — because decode
dominates E2EL — essentially only the TTFT distribution (including its
p90/p99 tail) moves. Reassigning every ``LOWER_AXES`` field from the
detailed recomputation keeps the record self-consistent with the harness'
exact ``_run_metrics`` recomputation check.
"""
if len(ttfts_ms) != record["completed"]:
raise AssertionError("ttft sample count must equal the request count")
record["ttfts"] = [value / 1000.0 for value in ttfts_ms]
metrics = gdn_component._recompute_timing_metrics(record)
for axis in gdn_component.LOWER_AXES:
record[axis] = metrics[axis]
# c2 mode-conditional TTFT fixtures (CLAIM-GDN-BA-ROUNDING-1). A c2 leg has six
# requests at closed-loop concurrency 2. The real c2 decode (~13.7 s) dwarfs the
# ~0.4 s ttft mode gap, so E2EL is effectively flat and the arrival-mode mixture
# is the only moving distribution. This helper mirrors that with a CONSTANT total
# latency L (decode = L - ttft per request), which keeps E2EL exactly flat, and
# start_times honour concurrency 2 (each pair starts when the previous pair ends).
_C2_MODE_LATENCY_MS = 14000.0
_C2_MODE_LATENCY_S = 14.0
_C2_MODE_DURATION_S = 42.0
def _apply_c2_ttft_modes(record: dict, ttfts_ms: list[float]) -> None:
"""Set a c2 leg's six per-request TTFTs (ms) at a constant total latency.
Decode is ``_C2_MODE_LATENCY_MS - ttft`` per request, so E2EL is flat and only
the TTFT distribution (its fast/slow arrival-mode mixture) moves. This is the
fixture the mode-conditional c2 gate is calibrated against.
"""
if len(ttfts_ms) != 6:
raise AssertionError("a c2 leg has six requests")
record["duration"] = _C2_MODE_DURATION_S
record["request_throughput"] = 6 / _C2_MODE_DURATION_S
record["output_throughput"] = 6 * 128 / _C2_MODE_DURATION_S
record["total_token_throughput"] = 6 * (1024 + 128) / _C2_MODE_DURATION_S
record["start_times"] = [float(index // 2) * _C2_MODE_LATENCY_S for index in range(6)]
record["ttfts"] = [value / 1000.0 for value in ttfts_ms]
record["itls"] = [
[(_C2_MODE_LATENCY_MS - value) / 127 / 1000.0] * 127 for value in ttfts_ms
]
metrics = gdn_component._recompute_timing_metrics(record)
for axis in gdn_component.LOWER_AXES:
record[axis] = metrics[axis]
# Mode split at 675 ms: fast (prefill-immediate) ~600 ms, slow (prefill-queued)
# ~700 ms; both straddle the fixed threshold. Fixtures span the FIVE timed reps
# (30 pooled c2 TTFT samples per arm) under CLAIM-GDN-BA-ROUNDING-1.
# (a) mixture flip: IDENTICAL per-mode values, but packed pools to 10 fast/20 slow
# while rollback pools to 25 fast/5 slow. The pooled mean/median flip below
# the retired 0.5% band, yet the per-mode ratios are exactly 1.0.
_C2_MODE_FLIP_PACKED = {
rep: [600.0, 600.0, 700.0, 700.0, 700.0, 700.0] for rep in REPETITIONS # 2 fast/4 slow -> 10/20
}
_C2_MODE_FLIP_ROLLBACK = {
rep: [600.0, 600.0, 600.0, 600.0, 600.0, 700.0] for rep in REPETITIONS # 5 fast/1 slow -> 25/5
}
# (b) genuine slow-mode regression: fast modes equal, packed slow-mode mean 5%
# worse (735 vs 700). Counts equal (15 fast / 15 slow both arms).
_C2_MODE_SLOW_REGRESS_PACKED = {rep: [600.0, 600.0, 600.0, 735.0, 735.0, 735.0] for rep in REPETITIONS}
_C2_MODE_SLOW_REGRESS_ROLLBACK = {rep: [600.0, 600.0, 600.0, 700.0, 700.0, 700.0] for rep in REPETITIONS}
# (d) lottery extreme: packed draws only 2 slow samples (28 fast); rollback keeps
# 10 slow. The slow-mode comparison is SKIPPED, never failed.
_C2_MODE_LOTTERY_PACKED = {
1: [600.0, 600.0, 600.0, 600.0, 600.0, 600.0],
2: [600.0, 600.0, 600.0, 600.0, 600.0, 600.0],
3: [600.0, 600.0, 600.0, 600.0, 600.0, 600.0],
4: [600.0, 600.0, 600.0, 600.0, 600.0, 600.0],
5: [600.0, 600.0, 600.0, 600.0, 700.0, 700.0], # -> 28 fast / 2 slow
}
_C2_MODE_LOTTERY_ROLLBACK = {
rep: [600.0, 600.0, 600.0, 600.0, 700.0, 700.0] for rep in REPETITIONS # -> 20 fast / 10 slow
}
# Both arms at parity per mode (used to prove the full 40-axis gate: both modes
# gated + c16 packed-better).
_C2_MODE_PARITY = {rep: [600.0, 600.0, 600.0, 700.0, 700.0, 700.0] for rep in REPETITIONS}
# --- c2 TTFT phase-lottery fixtures (ms) -------------------------------------
# Bimodal per-request TTFTs from the upstream-mirrored prefill co-schedule
# arrival lottery: a 1024-token prefill runs alone (~fast) or co-schedules
# (~slow, ~2x). Magnitudes are small vs the ~1 s fixture decode so E2EL stays
# stable (<4%) while the c2 TTFT-family per-rep aggregates swing far past 4%.
# Reps flip between a 3/3 mix and an all-slow 6/0 rep. Packed sits uniformly
# below rollback per request so the arm comparison and per-rep pairing stay clean.
_C2_TTFT_BIMODAL_PACKED = {
1: [5.0, 5.0, 5.0, 10.0, 10.0, 10.0], # 3/3 mix, mean 7.5
2: [5.0, 5.0, 5.0, 10.0, 10.0, 10.0], # 3/3 mix, mean 7.5
3: [10.0, 10.0, 10.0, 10.0, 10.0, 10.0], # 6/0 slow, mean 10.0
4: [5.0, 5.0, 5.0, 10.0, 10.0, 10.0], # 3/3 mix, mean 7.5
5: [5.0, 5.0, 5.0, 10.0, 10.0, 10.0], # 3/3 mix, mean 7.5
}
_C2_TTFT_BIMODAL_ROLLBACK = {
1: [11.0, 11.0, 11.0, 22.0, 22.0, 22.0], # 3/3 mix, mean 16.5
2: [22.0, 22.0, 22.0, 22.0, 22.0, 22.0], # 6/0 slow, mean 22.0
3: [11.0, 11.0, 11.0, 22.0, 22.0, 22.0], # 3/3 mix, mean 16.5
4: [11.0, 11.0, 11.0, 22.0, 22.0, 22.0], # 3/3 mix, mean 16.5
5: [11.0, 11.0, 11.0, 22.0, 22.0, 22.0], # 3/3 mix, mean 16.5
}
# A per-rep flip: rollback r1 dips below packed r1 (arrival phasing). Both arms
# pool to the SAME 30-sample TTFT distribution (15x10 + 15x20 ms — the honest
# at-parity expectation, since packed decode does not move TTFT), so the pooled
# arm comparison ties (packed <= rollback holds) while the per-rep mixture flips.
# All rep aggregates stay within 50% of the shared pool.
_C2_TTFT_FLIP_PACKED = {
1: [10.0, 20.0, 20.0, 20.0, 20.0, 20.0], # 1 fast/5 slow, mean 18.33 (> rollback r1)
2: [10.0, 10.0, 10.0, 10.0, 20.0, 20.0], # 4 fast/2 slow, mean 13.33
3: [10.0, 10.0, 10.0, 10.0, 20.0, 20.0], # 4 fast/2 slow, mean 13.33
4: [10.0, 10.0, 10.0, 20.0, 20.0, 20.0], # 3 fast/3 slow, mean 15.0
5: [10.0, 10.0, 10.0, 20.0, 20.0, 20.0], # 3 fast/3 slow, mean 15.0 -> 15/15
}
_C2_TTFT_FLIP_ROLLBACK = {
1: [10.0, 10.0, 10.0, 10.0, 10.0, 20.0], # 5 fast/1 slow, mean 11.67 (< packed r1)
2: [10.0, 10.0, 20.0, 20.0, 20.0, 20.0], # 2 fast/4 slow, mean 16.67
3: [10.0, 10.0, 20.0, 20.0, 20.0, 20.0], # 2 fast/4 slow, mean 16.67
4: [10.0, 10.0, 10.0, 20.0, 20.0, 20.0], # 3 fast/3 slow, mean 15.0
5: [10.0, 10.0, 10.0, 20.0, 20.0, 20.0], # 3 fast/3 slow, mean 15.0 -> 15/15
}
# c16 TTFT tail fixtures (96 requests): 94 at 20 ms fix mean/median/p90; the two
# tail requests set p99 = ~0.95*low + 0.05*high. These prove the 15% tail rule
# still governs c16 TTFT tails (c16 is NEVER pooled). Five reps.
_C16_TTFT_TAIL_WITHIN_15PCT = {
1: (58.0, 88.0), 2: (52.0, 82.0), 3: (50.0, 80.0), 4: (51.0, 81.0), 5: (53.0, 83.0),
}
_C16_TTFT_TAIL_BEYOND_15PCT = {
1: (62.0, 92.0), 2: (52.0, 82.0), 3: (50.0, 80.0), 4: (50.0, 80.0), 5: (52.0, 82.0),
}
def _c16_tail_ttft(low: float, high: float) -> list[float]:
return [20.0] * 94 + [low, high]
# --- packed-vs-rollback ACCEPTANCE noise-band fixtures (ms) -------------------
# These drive the G3 acceptance band (contract.acceptance): an axis FAILS only
# when the packed deficit exceeds run noise (0.5% non-tail/memory, 15% tail).
# A c16 packed-vs-rollback TTFT tail-ONLY deficit (96 samples, never pooled):
# both arms share the 94x20 ms bulk AND the same tail sum (a+b=80), so the
# mean/median/p90 ratios are exactly 1.0 and only p99 (0.95*ordered[94] +
# 0.05*ordered[95]) moves. rollback p99 = 0.95*30 + 0.05*50 = 31.0.
_C16_TAIL_ROLLBACK_TTFT = [20.0] * 94 + [30.0, 50.0] # p99 = 31.0
_C16_TAIL_PACKED_TTFT_WITHIN = [20.0] * 94 + [34.70, 45.30] # p99 35.235 -> ratio 0.88
_C16_TAIL_PACKED_TTFT_BEYOND = [20.0] * 94 + [38.75, 41.25] # p99 38.875 -> ratio 0.80
def _uniform_records(*, deficit: float) -> dict[tuple[int, str, int], dict]:
"""Records where packed is uniformly ``deficit`` worse than rollback.
Every timing axis is uniform per request (mean=median=p90=p99), identical
across the repetitions, so each axis is perfectly stable and the
packed/rollback normalized ratio is exactly ``1 - deficit`` on every axis
(throughput, request rate, and every mean/median/p90/p99 latency).
"""
result: dict[tuple[int, str, int], dict] = {}
worse = 1.0 / (1.0 - deficit)
for concurrency in CONCURRENCIES:
requests = {2: 6, 16: 96}[concurrency]
for arm in ARMS:
duration = 10.0 * (worse if arm == "packed" else 1.0)
latency = 8.0 * (worse if arm == "packed" else 1.0)
for repetition in REPETITIONS:
record = _record(
concurrency=concurrency,
packed_better=True,
repetition=repetition,
)
record["duration"] = duration
record["request_throughput"] = requests / duration
record["output_throughput"] = requests * 128 / duration
record["total_token_throughput"] = requests * (1024 + 128) / duration
_set_latency(record, latency)
result[(concurrency, arm, repetition)] = record
return result
def _uniform_memory(*, deficit: float) -> dict[tuple[int, str, int], dict]:
"""Memory where packed is uniformly ``deficit`` worse than rollback."""
result: dict[tuple[int, str, int], dict] = {}
worse = 1.0 / (1.0 - deficit)
for concurrency in CONCURRENCIES:
for arm in ARMS:
base = 100.0 * (worse if arm == "packed" else 1.0)
for repetition in REPETITIONS:
result[(concurrency, arm, repetition)] = {
"peak_gpu_memory_mib": base,
"peak_pss_kib": base * 1024,
"peak_rss_kib": base * 2048,
"peak_mem_available_drop_kib": base * 4096,
"returned": True,
}
return result
def _records(*, packed_better: bool) -> dict[tuple[int, str, int], dict]:
result = {}
for concurrency in CONCURRENCIES:
for arm in ARMS:
for repetition in REPETITIONS:
result[(concurrency, arm, repetition)] = _record(
concurrency=concurrency,
packed_better=(arm == "packed") == packed_better,
repetition=repetition,
)
return result
def _memory(*, packed_better: bool) -> dict[tuple[int, str, int], dict]:
result = {}
for concurrency in CONCURRENCIES:
for arm in ARMS:
for repetition in REPETITIONS:
preferred = (arm == "packed") == packed_better
base = 100.0 if preferred else 120.0
result[(concurrency, arm, repetition)] = {
"peak_gpu_memory_mib": base,
"peak_pss_kib": base * 1024,
"peak_rss_kib": base * 2048,
"peak_mem_available_drop_kib": base * 4096,
"returned": True,
}
return result
def _set_timing_leg(record: dict, *, duration: float, latency_ms: float) -> None:
"""Overwrite one leg's duration/throughput and flat per-request latency.
Throughput scales with ``duration`` and every timed-latency axis is set to
``latency_ms`` (mean=median=p90=p99), keeping the record self-consistent with
the harness' exact ``_run_metrics`` recomputation check. Used by the paired
majority-consistency fixtures to perturb specific rep-pairs by ~1-2%.
"""
requests = record["completed"]
record["duration"] = duration
record["request_throughput"] = requests / duration
record["output_throughput"] = requests * 128 / duration
record["total_token_throughput"] = requests * (1024 + 128) / duration
_set_latency(record, latency_ms)
def _prime_c16_paired(records: dict) -> None:
"""Reset both c16 arms to a common near-identical baseline for paired tests.
Every c16 leg is set to duration 10.0 / latency 8.0 ms so the two arms sit on
top of each other; a paired fixture then perturbs specific packed reps by
~1-2% to exercise the majority-consistency gate. c2 is left as the clean
packed-better base and its TTFT-family stays excluded from the paired set.
"""
for arm in ARMS:
for repetition in REPETITIONS:
_set_timing_leg(records[(16, arm, repetition)], duration=10.0, latency_ms=8.0)
def _write_fixture_corpus(root: pathlib.Path, *, tokenizer: pathlib.Path) -> None:
corpus_root = root / "corpus" / "27"
corpus_root.mkdir(parents=True)
source_files = []
source_partitions = [("warmup", 1)] + [
(f"c{concurrency}-r{repetition}", 192)
for repetition in REPETITIONS
for concurrency, _ in POINTS
]
for partition, requests in source_partitions:
filename = "warmup.jsonl" if partition == "warmup" else f"{partition}.jsonl"
path = corpus_root / filename
path.write_text(
"".join(
json.dumps({"index": index, "partition": partition}) + "\n"
for index in range(requests)
),
encoding="utf-8",
)
source_files.append(
{
"file": filename,
"partition": partition,
"requests": requests,
"sha256": sha256_file(path),
}
)
source_manifest = corpus_root / "manifest.json"
source_manifest.write_text(
json.dumps(
{
"common_prefix_limit": 32,
"files": source_files,
"format": "sglang-custom-conversations-jsonl-v1",
"model_key": "27",
"output_len": 128,
"requests_per_partition": 192,
"seed": 0,
"sglang_commit": SGLANG_COMMIT,
"target_input_len": 1024,
"tokenizer_revision": MODEL_REVISIONS["27"],
"tokenizer_sha256": sha256_file(tokenizer),
"total_prompts": 192 * len(POINTS) * len(gdn_component.REPETITIONS) + 1,
"warmup_requests": 1,
}
),
encoding="utf-8",
)
vllm_root = corpus_root / "vllm"
vllm_root.mkdir()
vllm_files = []
source_by_name = {item["file"]: item for item in source_files}
for repetition in REPETITIONS:
for concurrency, requests in POINTS:
filename = f"c{concurrency}-r{repetition}.jsonl"
path = vllm_root / filename
path.write_text(
"".join(
json.dumps({"prompt": f"{filename}-{index}"}) + "\n"
for index in range(requests)
),
encoding="utf-8",
)
vllm_files.append(
{
"concurrency": concurrency,
"file": filename,
"repetition": repetition,
"requests": requests,
"sha256": sha256_file(path),
"source_sha256": source_by_name[filename]["sha256"],
}
)
vllm_manifest = vllm_root / "manifest.json"
vllm_manifest.write_text(
json.dumps(
{
"files": vllm_files,
"format": "vllm-custom-jsonl-v1",
"input_len": 1024,
"model_key": "27",
"output_len": 128,
"source_manifest_sha256": sha256_file(source_manifest),
"tokenizer_revision": MODEL_REVISIONS["27"],
"total_prompts": sum(requests for _, requests in POINTS)
* len(gdn_component.REPETITIONS),
"vllm_commit": VLLM_COMMIT,
}
),
encoding="utf-8",
)
gdn_component.COMPONENT_SOURCE_CORPUS_MANIFEST_SHA256 = sha256_file(
source_manifest
)
gdn_component.COMPONENT_VLLM_CORPUS_MANIFEST_SHA256 = sha256_file(
vllm_manifest
)
def _write_complete_evidence(root: pathlib.Path, *, packed_better: bool = True) -> None:
(root / "component-plan.json").write_text(
json.dumps(build_component_plan(SOURCE_SHA)), encoding="utf-8"
)
build = root / "build"
artifact = build / "examples" / "server"
artifact.parent.mkdir(parents=True)
artifact.write_text(
"immutable MatmulNvfp4Cutlass [VT_FP4_CACHE] prepared\n",
encoding="utf-8",
)
model_gate_binary = build / "tests" / "test_qwen27_paged_engine"
model_gate_binary.parent.mkdir(parents=True)
model_gate_binary.write_text("immutable model gate\n", encoding="utf-8")
model_gate_binary.chmod(0o755)
snapshot = root / MODEL_REVISIONS["27"]
snapshot.mkdir()
model_config = snapshot / "config.json"
model_config.write_text("{}\n", encoding="utf-8")
tokenizer = snapshot / "tokenizer.json"
tokenizer.write_text("{}\n", encoding="utf-8")
_write_fixture_corpus(root, tokenizer=tokenizer)
weight = snapshot / "model-00001-of-00001.safetensors"
weight.write_text("weight\n", encoding="utf-8")
generation_config = snapshot / "generation_config.json"
generation_config.write_text("{}\n", encoding="utf-8")
client = root / "oracle" / "bin" / "vllm"
client.parent.mkdir(parents=True)
client.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
client.chmod(0o755)
ninja = root / "oracle" / "bin" / "ninja"
ninja.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
ninja.chmod(0o755)
cutlass = root / "oracle" / "cutlass"
(cutlass / "include").mkdir(parents=True)
(cutlass / "tools" / "util" / "include").mkdir(parents=True)
(cutlass / "include" / "cutlass.h").write_text("fixture\n", encoding="utf-8")
(cutlass / "tools" / "util" / "include" / "util.h").write_text(
"fixture\n", encoding="utf-8"
)
cutlass_record = gdn_component._fingerprint_tree(cutlass)
oracle_artifacts = {}
for name in sorted(gdn_component._ORACLE_ARTIFACT_NAMES):
if name == "client":
path = client
elif name == "ninja":
path = ninja
else:
path = root / "oracle" / "artifacts" / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(f"{name}\n", encoding="utf-8")
oracle_artifacts[name] = {
"path": str(path),
"sha256": sha256_file(path),
}
execution_dir = root / "execution"
execution_dir.mkdir(parents=True)
oracle_manifest = execution_dir / "27-oracle.json"
oracle_manifest.write_text(
json.dumps(
{
"artifacts": oracle_artifacts,
"bench_dependencies": {
"flashinfer": FLASHINFER_VERSION,
"pandas": PANDAS_VERSION,
},
"client_contract_source_commit": VLLM_COMMIT,
"cutlass_source_tree": cutlass_record,
"generated_utc": "2026-07-14T00:00:00+00:00",
"oracle_version": VLLM_ORACLE_VERSION,
"runtime_version": VLLM_ORACLE_VERSION,
}
),
encoding="utf-8",
)
configure_log = root / "configure.log"
configure_log.write_text(
"CUDA compiler identification is NVIDIA 13.0.88\n"
f"CUTLASS found at {cutlass}\n"
"enabling sm120a NVFP4 cutlass GEMM\n",
encoding="utf-8",
)
build_command = execution_dir / "27-build-command.txt"
build_command.write_text(
shlex.join(
[
"cmake",
"--build",
str(build),
"--target",
"server",
"test_qwen27_paged_engine",
"--parallel",
str(len(gdn_component.os.sched_getaffinity(0))),
]
)
+ "\n",
encoding="utf-8",
)
build_log = execution_dir / "27-build.log"
build_log.write_text("build passed\n", encoding="utf-8")
cmake_cache = build / "CMakeCache.txt"
compile_commands = build / "compile_commands.json"
compile_tokens = [
str(gdn_component.DGX_CUDA_COMPILER),
"-DVLLM_CPP_FLASH_ATTN",
"-DVLLM_CPP_TRITON=1",
"-DVLLM_CPP_TRITON_CHUNKO_BF16=1",
"-DVT_CUTLASS_NVFP4=1",
"--generate-code=arch=compute_121a,code=[compute_121a,sm_121a]",
f"-I{cutlass / 'include'}",
f"-I{cutlass / 'tools' / 'util' / 'include'}",
"-c",
str(SOURCE_ROOT / "src/vt/cuda/cuda_matmul_nvfp4_cutlass.cu"),
]
compile_commands.write_text(
json.dumps(
[
{
"arguments": compile_tokens,
"directory": str(build),
"file": str(
SOURCE_ROOT / "src/vt/cuda/cuda_matmul_nvfp4_cutlass.cu"
),
}
]
),
encoding="utf-8",
)
cmake_cache.write_text(
"\n".join(
[
"CMAKE_BUILD_TYPE:STRING=RelWithDebInfo",
f"CMAKE_CUDA_COMPILER:FILEPATH={gdn_component.DGX_CUDA_COMPILER}",
"CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON",
f"CMAKE_MAKE_PROGRAM:FILEPATH={ninja}",
"VLLM_CPP_BENCH_PROFILE_CONTROL:BOOL=OFF",
"VLLM_CPP_BUILD_TESTS:BOOL=ON",
"VLLM_CPP_CUDA:BOOL=ON",
"VLLM_CPP_CUDA_ARCHITECTURES:STRING=121a",
"VLLM_CPP_FLASH_ATTN:BOOL=ON",
"VLLM_CPP_SERVER:BOOL=ON",
"VLLM_CPP_TRITON:BOOL=ON",
"VLLM_CPP_TRITON_REGEN:BOOL=OFF",
f"VLLM_CPP_CUTLASS_DIR:PATH={cutlass}",
f"CMAKE_HOME_DIRECTORY:INTERNAL={SOURCE_ROOT}",
]
)
+ "\n",
encoding="utf-8",
)
artifacts = {
"build_command": build_command,
"build_log": build_log,
"client": client,
"cmake_cache": cmake_cache,
"compile_commands": compile_commands,
"configure_log": configure_log,
"cuda_compiler": gdn_component.DGX_CUDA_COMPILER,
"model_config": model_config,
"oracle_manifest": oracle_manifest,
"server": artifact,
"snapshot:generation_config.json": generation_config,
"tokenizer": tokenizer,
"weight:model-00001-of-00001.safetensors": weight,
}
artifacts.update(
{
f"oracle:{name}": pathlib.Path(record["path"])
for name, record in oracle_artifacts.items()
}
)
artifact_records = {
name: {"path": str(path), "sha256": sha256_file(path)}
for name, path in artifacts.items()
}
native = root / "native-plan-must-not-exist.json"
execution = {
"artifacts": artifact_records,
"bench_dependencies": {
"flashinfer": FLASHINFER_VERSION,
"pandas": PANDAS_VERSION,
},
"build_contract": {
"build_type": "RelWithDebInfo",
"compile_command_sha256": gdn_component._sha256_canonical(
compile_tokens
),
"cuda_compiler": str(gdn_component.DGX_CUDA_COMPILER),
"cuda_compiler_sha256": sha256_file(gdn_component.DGX_CUDA_COMPILER),
"cuda_compiler_version": "13.0.88",
"cutlass_source_tree": cutlass_record,
"native_plan_target": str(native),
"native_plan_target_absent": True,
"profile_control": False,
"schema_version": gdn_component.BUILD_CONTRACT_SCHEMA_VERSION,
"sm_architecture": "121a",
"target_compile_definitions": [
"VLLM_CPP_FLASH_ATTN",
"VLLM_CPP_TRITON=1",
"VLLM_CPP_TRITON_CHUNKO_BF16=1",
"VT_CUTLASS_NVFP4=1",
],
"triton_aot": True,
},
"cache_drop_roots": [
str(snapshot.absolute()),
str((root / "corpus" / "27").absolute()),
str(artifact.absolute()),
str(client.absolute()),
],
"generated_utc": "2026-07-14T00:00:00+00:00",
"host": {"kernel": "fixture", "machine": "fixture", "node": "fixture"},
"max_num_batched_tokens": 2048,
"max_num_seqs": 32,
"model_key": "27",
"model_revision": MODEL_REVISIONS["27"],
"num_blocks": 4736,
"port": 8001,
"snapshot_files": ["generation_config.json"],
"vllm_cpp_sha": SOURCE_SHA,
"vllm_oracle_version": VLLM_ORACLE_VERSION,
"vllm_source_sha": VLLM_COMMIT,
"weight_files": ["model-00001-of-00001.safetensors"],
}
execution_path = root / "execution" / "27-component.json"
execution_path.write_text(json.dumps(execution), encoding="utf-8")
fixture = (
SOURCE_ROOT
/ "tests/fixtures/nvfp4_flashinfer_v025_gb10/autotune_configs.json"
)
for arm in ARMS:
log = root / "model-gates" / f"{arm}.log"
log.parent.mkdir(parents=True, exist_ok=True)
_write_model_gate_log(
log,
fixture=fixture,
native=native,
snapshot=snapshot,
)
command = [
"/usr/bin/env",
"-i",
*_isolated_environment(
arm=arm,
fixture=fixture,
native=native,
home=root,
),
str(model_gate_binary),
]
(root / "model-gates" / f"{arm}-command.txt").write_text(
shlex.join(command) + "\n", encoding="utf-8"
)
gate = {
"log": str(log),
"log_sha256": sha256_file(log),
"model_key": "27",
"passed": True,
"test_name": "test_qwen27_paged_engine",
"vllm_cpp_sha": SOURCE_SHA,
}
(root / "model-gates" / f"{arm}.json").write_text(
json.dumps(gate), encoding="utf-8"
)
raw_records = _records(packed_better=packed_better)
memory_records = _memory(packed_better=packed_better)
run_lines = ["corpus_validated", "gpu_lock_acquired path=/tmp/gpu"]
for arm in ARMS:
run_lines.append(f"model_gate_complete arm={arm}")
run_lines.append("model_gates_validated")
# One discarded cold-start warmup pair, run first before the timed series.
warmup_base = root / "warmup" / "27"
warmup_base.mkdir(parents=True, exist_ok=True)
for arm in ARMS:
(warmup_base / f"{arm}-logs").mkdir(parents=True, exist_ok=True)
server_log = warmup_base / f"{arm}-logs" / "server.log"
server_log.write_text("HTTP worker pool 36 fixed\n", encoding="utf-8")
run_lines.append(
f"warmup_leg_begin arm={arm} label={gdn_component.WARMUP_LABEL}"
)
(warmup_base / f"w0-{arm}.json").write_text(
json.dumps(
{
"arm": arm,
"label": gdn_component.WARMUP_LABEL,
"discarded": True,
"server_log": str(server_log),
}
),
encoding="utf-8",
)
run_lines.append(
f"warmup_leg_end arm={arm} label={gdn_component.WARMUP_LABEL}"
)
for concurrency in CONCURRENCIES:
for order in LEG_ORDER:
arm, repetition_text = order.rsplit("-r", 1)
repetition = int(repetition_text)
key = (concurrency, arm, repetition)
tag = f"gdn-{arm}"
raw = (
root
/ "raw"
/ "27"
/ "ours"
/ f"c{concurrency}-r{repetition}-{tag}.json"
)
raw.parent.mkdir(parents=True, exist_ok=True)
raw.write_text(json.dumps(raw_records[key]), encoding="utf-8")
base = root / "memory" / "27" / f"c{concurrency}" / arm
base.mkdir(parents=True, exist_ok=True)
memory = memory_records[key]
samples = [
{
"alive": True,
"gpu_memory_mib": memory["peak_gpu_memory_mib"],
"mem_available_kib": 1000000,
"peak_mem_available_drop_kib": memory[
"peak_mem_available_drop_kib"
],
"peak_pss_kib": memory["peak_pss_kib"],
"peak_rss_kib": memory["peak_rss_kib"],
"pids": [10],
"pss_kib": memory["peak_pss_kib"],
"rss_kib": memory["peak_rss_kib"],
},
{
"alive": False,
"gpu_memory_mib": 0,
"mem_available_kib": 1000000,
"peak_mem_available_drop_kib": memory[
"peak_mem_available_drop_kib"
],
"peak_pss_kib": memory["peak_pss_kib"],
"peak_rss_kib": memory["peak_rss_kib"],
"pids": [],
"pss_kib": 0,
"rss_kib": 0,
},
]
(base / f"r{repetition}.samples.jsonl").write_text(
"".join(json.dumps(row) + "\n" for row in samples),
encoding="utf-8",
)
(base / f"r{repetition}.summary.json").write_text(
json.dumps(
{
"peak_mem_available_drop_kib": memory[
"peak_mem_available_drop_kib"
],
"peak_pss_kib": memory["peak_pss_kib"],
"peak_rss_kib": memory["peak_rss_kib"],
"samples": len(samples),
}
),
encoding="utf-8",
)
cache = root / "cache-drop" / "27" / f"c{concurrency}" / arm
cache.mkdir(parents=True, exist_ok=True)
before_cache = cache / f"r{repetition}-before.json"
after_cache = cache / f"r{repetition}-after.json"
write_cache_drop_report(before_cache)
write_cache_drop_report(after_cache)
for cache_report in (before_cache, after_cache):
cache_record = json.loads(cache_report.read_text())
cache_record["roots"] = execution["cache_drop_roots"]
cache_report.write_text(json.dumps(cache_record), encoding="utf-8")
returned = root / "memory-return" / "27" / f"c{concurrency}" / arm
returned.mkdir(parents=True, exist_ok=True)
(returned / f"r{repetition}.json").write_text(
json.dumps(
{
"cache_drops": {
"after": {
"path": str(after_cache),
"sha256": sha256_file(after_cache),
},
"before": {
"path": str(before_cache),
"sha256": sha256_file(before_cache),
},
},
"gpu_idle": True,
"baseline_mem_available_kib": 1000000,
"drop_caches_succeeded": True,
"final_mem_available_kib": 1000000,
"mem_available_within_tolerance": True,
"returned": True,
"tolerance_kib": 1048576,
}
),
encoding="utf-8",
)
logs = root / "logs" / "27" / f"c{concurrency}" / arm
logs.mkdir(parents=True, exist_ok=True)
write_profile_log(
logs / f"r{repetition}-server.log",
fixture=fixture,
native_target=native,
server_pid=100 + repetition,
)
command = [
"/usr/bin/env",
"-i",
*_isolated_environment(
arm=arm,
fixture=fixture,
native=native,
home=root,
),
str(artifact),
"--model",
str(snapshot),
"--port",
"8001",
"--num-blocks",
"4736",
"--max-num-seqs",
"32",
"--max-num-batched-tokens",
"2048",
"--no-enable-prefix-caching",
"--served-model-name",
"gate",
]
(logs / f"r{repetition}-server-command.txt").write_text(
shlex.join(command) + "\n", encoding="utf-8"
)
client_log = (
root
/ "logs"
/ "27"
/ "ours"
/ f"c{concurrency}-r{repetition}-{tag}.log"