Analysis (docs/experiments/verify-tail-and-gaps.md, CUPTI windows CP.1 / CL.2 / CY.1 against VANL): R6 is the single-stream control (2035 gaps, 211 us) against VANL (1194, 119 us); with the side streams LEL has 1124 / 123.7 us, residual +0.006 ms. R7 has no gap. R8 (+86.5 us at LEL's T mix) is the hyper-connection chain 31.2, the head matmul at T >= 3 38.4 and the greedy pick 18.0. The switch batches the 6 T launches of the tail (mtp_full_native_write plus the five lm_head_mix kernels a row) into 6: new sealed sm120_head_chain.cu/.ptx (final write, head norm, pre-final mix with the row as grid.y, compiled with the --use_fast_math flags of the originals), the existing multi-column bf16 gemv, mtp_full_down_silu over the contiguous rows. Bitwise by construction (same bodies, same per-column fma chain). Flag in GrConfig::head_chain_batch like U5a; HEAD_MIX_MULTI untouched. Model-free probe tools/decode-sm120/sm120_probe_head_chain.cpp (built, not run), report script scripts/e2e/codex/speed/verify_tail_report.py, 15 unit tests (288 original_verify tests pass). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
16 KiB
Verify graph: the tail after the last layer and the idle gaps (ledger rows R6, R7, R8; switch HEAD_CHAIN_BATCH)
Branch claude/tail-fusion. Analysis first (CUPTI windows, read-only on rnr5090), then one opt-in switch,
LELEKA_SM120_HEAD_CHAIN_BATCH (default off). Nothing was run on a GPU: every claim below is either read from the
CUPTI traces (marked with the window) or from code, and the expected section delta is arithmetic, not a measurement.
0. Answer first
| ledger row | what the windows show | verdict |
|---|---|---|
| R6 idle inside the verify graph, 2052 against 1193 gaps, +0.094 ms | The numbers are the verify graph only, counted as union gaps (no kernel of the graph runs), and they reproduce exactly: control CL.2 (one stream) 2035 gaps / 211.0 us, VANL 1194 / 119.3 us. With the side streams of the profile set (CP.1, CY.1) LEL has 1124 / 123.7 us and 1070 / 118.4 us, i.e. +5.8 us a graph at LEL's own T mix (+2.3 .. +13.1 us at equal T). Every gap is 0.10-0.11 us in both. The loss of R6 was the single stream; the side-stream switches (V1, V3a, V3b, V4a) removed it. |
closed by the side streams; residual +0.006 ms, nothing to build |
| R7 first doorbell after graph start, +0.015 ms | 21-23 kernels precede the first doorbell in both; LEL 95.6 / 105.6 / 112.5 / 121.9 / 137.4 / 149.5 us at T 1..6, VANL 93.3 / 98.6 / 114.7 / 125.8 / - / 135.3 us. | no gap to remove (-3.9 .. +14.2 us, mixed signs) |
R8 tail after the last add_hits, +0.090 ms |
At LEL's T mix the tail is 86.5 us longer than VANL's (table in 3.3): hyper-connection chain of the head 31.2 us, language-model head matmul at T >= 3 38.4 us, greedy pick + finite scan 18.0 us, one extra VANL kernel -1.0 us. | the chain is a launch-count loss and is removed bitwise by the switch; matmul and pick are not launch fusion (3.4) |
| the 2052 / 1193 "per round" | not per round: per verify graph. The non-verify graphs of a round are separate: LEL 4.23 graphs, 426 kernels, 409 union gaps, 43.5 us idle; VANL 3.48 graphs, 148 kernels, 108 gaps, 11.6 us (CP.1 and VANL windows; draft graph 113 kernels against 53, 2.2 a round). That is the draft/commit side (rows O1, O9), not the tail. |
out of scope here |
1. Data and method
- LEL:
/data/leleka-e2e/spd-gap/runs/verify-ffn-d1-d2-d3-cupti-windows/CP.1/win-r29.lct(profile set: side mixer / QSA / shared expert, fused QSA prelude; no COMBINE_VEC4, no D1/D2/D3, so the tail is the literal one). 785 verify graphs, T 1..8 (28 / 206 / 253 / 40 / 231 / 22 / 4 / 1). Control for R6:verify-new-switches-cupti-windows/CL.2/win-r29.lct(833 graphs, one stream) andCY.1(profile set + new switches, 894 graphs). - VANL:
/data/leleka-e2e/spd-gap/runs/cupti/VANL/win-r29.lct, 893 verify graphs (T 1 / 2 / 3 / 4 / 6 = 127 / 94 / 92 / 569 / 11; no T = 5, its row below is the mean of T = 4 and 6, marked). - Script
scripts/e2e/codex/speed/verify_tail_report.py(extract, thencompare; stdlib, readslct.py). Verify graph = at least 900 kernels per correlation id, first and last two dropped; T = grid of the CPU-row copy kernel / 10; tail = every kernel that starts at or after the end of the lastadd_hits; the head matmul is the longest kernel of the tail. Every number is a p50 per T unless it says weighted. "Weighted" = the per-T difference summed over LEL's own T mix (780 graphs), the only mix both sides can be compared at.
2. The idle gaps (R6, R7)
Union gaps and idle time inside one verify graph (p50 per T):
| T | LEL CP.1 gaps / idle us |
VANL gaps / idle us | difference idle us |
|---|---|---|---|
| 1 | 1135 / 124.8 | 1203 / 122.0 | +2.8 |
| 2 | 1069 / 118.2 | 1167 / 115.9 | +2.3 |
| 3 | 1095 / 120.3 | 1166 / 115.7 | +4.6 |
| 4 | 1156 / 126.6 | 1200 / 119.8 | +6.7 |
| 5 | 1175 / 128.9 | - (mean of T 4, 6: 119.2) | +9.7 (interpolated) |
| 6 | 1194 / 131.6 | 1198 / 118.6 | +13.1 |
| all graphs (mean) | 1124 / 123.7 | 1194 / 119.3 | weighted +5.8 |
control CL.2, one stream |
2035 / 211.0 | R6's LEL column |
The R6 cell (0.213 against 0.119 ms) is the single-stream control against VANL. The profile windows have three streams in
the verify graph for LEL (CP.1, CY.1), like VANL, and the gap time of a graph is then the time the critical path waits
for a dependent launch: about 0.10 us per serial edge. What is left (+0.006 ms weighted) grows with T, i.e. with the number
of serial edges of the per-token head chain below; it is not a separate loss.
First doorbell (R7), kernels before it and its start from the graph start, p50: LEL 23 kernels and 95.6 / 105.6 / 112.5 / 121.9 / 137.4 / 149.5 us at T 1..6; VANL 21-23 kernels and 93.3 / 98.6 / 114.7 / 125.8 / - / 135.3 us. The difference is inside the T-dependent embedding and mixer work of the first layer, with mixed signs: nothing to fuse.
3. The tail (R8)
3.1 Kernel sequence after the last add_hits (T = 3, p50 duration us, gap before us)
LEL (22 launches, 415.6 us) and VANL (10 launches, 352.9 us):
| LEL | dur | gap | VANL | dur | gap |
|---|---|---|---|---|---|
mtp_full_combine |
1.44 | 0.48 | combine (vec4) | 1.12 | 0.48 |
mtp_full_native_write x 3 |
0.83 / 0.77 / 0.74 | 0.10 | post (all rows) |
0.90 | 0.10 |
mtp_full_gr_norm, mmvf256, down_silu, mmvf160, pre_final x 3 |
17.5 + 13.3 + 13.3 | 0.10 each | hyper-connection split, down, up (three GrMulti kernels, one multi-token read) |
2.69 + 10.11 + 7.94 | 0.10 |
head_quant |
0.86 | 0.10 | quantize | 0.86 | 0.10 |
an extra kernel (Q81Block const*, int*, int*, float*) |
0.96 | 0.10 | |||
head_n14_t3_large |
338.5 | 0.10 | head matmul F::Block |
319.9 | 0.10 |
chain_sampler_greedy_kernel (grid T, 1024 threads) |
25.9 | -0.10 | sampler_greedy_cluster_kernel (grid 8 x T) + logits_nonfinite |
4.5 + 2.8 | -0.10 |
Launches in the tail by T: LEL 10 / 16 / 22 / 28 / 34 / 40 at T 1..6 (6 T + 4), VANL 9 / 10 / 10 / 10 / - / 10. Gaps inside the tail are 0.10 us per launch: 1.3 .. 4.1 us in LEL, 1.1 .. 1.3 us in VANL. At T = 1 the hyper-connection chain and the matmul are the same (20.5 against 21.8 us, 310.2 against 310.5); the tail differs there only by the pick (24.5 against 6.8 us).
3.2 Why the LEL head chain is per token
plan_head_mix (original_verify_window_gr/plan_hc_read.rs) launches the native lm_head_mix once per row: mtp_full_gr_norm,
bf16_gemv (down, mtp_full_mmvf256), mtp_full_down_silu, bf16_gemv (up, mtp_full_mmvf160), mtp_full_pre_final, and
the last layer's plan_final_write adds one mtp_full_native_write a row: 6 T launches, each 0.7 .. 7 us and latency
bound. VANL does one multi-token hyper-connection read (output_hc_* read as three launches), which is what
LELEKA_SM120_HEAD_MIX_MULTI ports; that switch changes the summation order and is not bitwise (25 of 2057 rows moved), so
it stays off. The loss is therefore the launch count of a per-token chain, not the arithmetic.
3.3 Where the 86.5 us go (LEL minus VANL, p50 per T, weighted at LEL's T mix; compare output)
| section | T1 | T2 | T3 | T4 | T5 (VANL mean of 4, 6) | T6 | weighted |
|---|---|---|---|---|---|---|---|
| tail total | +16.2 | +23.4 | +62.7 | +88.8 | +162.0 | +246.2 | 86.5 |
hyper-connection chain (last add_hits to the head quantize) |
-1.3 | +12.7 | +26.6 | +38.9 | +52.2 | +64.8 | 31.2 |
head matmul (head_n14_tN_large against VANL's kernel) |
-0.3 | -6.6 | +18.6 | +32.5 | +93.8 | +165.8 | 38.4 |
| greedy pick + finite scan | +17.7 | +18.2 | +18.6 | +18.3 | +17.3 | +16.2 | 18.0 |
| the extra VANL kernel before the matmul | 0 | -0.9 | -1.0 | -1.0 | -1.2 | -1.3 | -1.0 |
| head quantize | +0.1 | 0 | 0 | 0 | 0 | 0 | 0 |
The sum of the sections reproduces R8's +0.090 ms (86.5 us). LEL's weighted tail is 453.9 us, VANL's at that mix 367.3 us.
3.4 What can be removed, and how
| part | weighted | bitwise route | done here |
|---|---|---|---|
hyper-connection chain, 6 T launches |
31.2 us | yes: same per-row kernels, row as blockIdx.y; the multi-column gemv has the same per-column fma chain |
yes, the switch |
greedy pick: chain_sampler_greedy_kernel is one block of 1024 threads a token (25 us, 1 MB read at ~40 GB/s); VANL splits a token over 8 blocks (4.2-6.6 us) |
up to 20 us (25.3 -> ~5 plus a merge) | yes: argmax with lowest-index ties is independent of the split, NaN never wins (s > bv), penalties are not used in the verify graph (Address(0) history). Needs a small scratch for the partials in OriginalNativeHeadRows (native_head, outside this scope) |
no |
head matmul at T >= 3: LEL uses the "exact" multi-column layout (1 row a block, 4 warps; multi_exact, Original mode17), so 248,320 blocks; VANL 15,520 .. 62,080 blocks |
38.4 us | the existing _upstream kernels are NOT bitwise (the cross-warp reduction groups the sums differently). The sealed head_n14_tN_small kernels (4 rows a block, the per-row program unchanged by the source comment of native_head_native.cu) are the cheap experiment: a dispatch change in native_head/dispatch.rs for kind 14, T >= 3; unmeasured |
no |
| 2.8 us finite scan | in the 18.0 | LELEKA_SM120_ACCEPT_ON_DEVICE already puts it in the graph (off; no sign in CA.1) |
no |
4. The switch LELEKA_SM120_HEAD_CHAIN_BATCH
Resolved in original_verify_window_sm120.rs (Sm120Switches::head_chain_batch, DEFAULT_ON_HEAD_CHAIN_BATCH = false, below
12.x never taken), carried to the planners in GrConfig::head_chain_batch (like U5a's down_fused; decided in
prepare before the assets load, so a requested switch whose PTX is not sealed fails the recording by name).
- Final residual write.
plan_final_writeof a group with >= 2 rows is ONE launch ofleleka_verify_final_write_rows(grid[40, rows]), in place, instead ofmtp_full_native_writea row. - Head mix.
plan_head_mixwith >= 2 rows is FIVE launches, whatever T:leleka_verify_head_norm_rows(grid[4, T], 1024 threads) -> sealedbf16_f32_mmvf_multi_kernel<256, 4|8>(down) -> existingmtp_full_down_siluover the T x 320 contiguouslofloats -> sealedbf16_f32_mmvf_multi_kernel<160, 4|8>(up) ->leleka_verify_head_pre_final_rows(grid[10, T]). - One row keeps the literal launches. With
HEAD_MIX_MULTIalso on, the planner takesplan_head_mix_multiand only the residual write is batched.head_quant, the head matmul and the pick are unchanged. - Launches a graph:
6 T->6(one group; with two groups the writes are 2):-(6 T - 6), 12 / 18 / 24 / 30 at T = 3 / 4 / 5 / 6, about 15 at the mean T = 3.6 of the replay.
Why it is bitwise. The three new kernels are the bodies of mtp_full_native_write, mtp_full_gr_norm and
mtp_full_pre_final with blockIdx.y as the row and the per-row bases added as arguments; no instruction order changes. They
are compiled with --fmad=true --use_fast_math, the flags the two originals were resealed with (extra-seal-plan group
reseal-fastmath), so expf, rsqrtf and the divisions lower to the same approximate PTX. The unit test
the_batched_kernels_use_the_arithmetic_of_the_kernels_they_batch compares the float instruction sequence of each new entry with
the sealed original: identical for the write (7 instructions) and the norm (64), per loop iteration for the pre-final mix (the
originals' loop is unrolled differently, the iteration mul.ftz, ex2.approx.ftz, add.ftz, rcp.approx.ftz, mul.rn.ftz, add.rn.ftz, selp is the same). The gemv is the existing multi-column kernel: acc[k] = fma(w1, x1, fma(w0, x0, acc[k])) over the same
pairs, the same shared-memory reset and the same warp tree as the single-column kernel, for each column k < T. The silu is
element-wise on contiguous slots. All of these are the facts the model-free probe checks on the GPU (section 6).
Not touched. The arithmetic of the head's hyper-connection read (the thing HEAD_MIX_MULTI changed), head_quant, the matmul,
the argmax, executor_prefill*, the profile JSONs, original_verify_window_gpu_plan*.
Files
New: crates/cuda-driver/src/sm120_head_chain.{cu,ptx} (nvcc 13.2.86 in WSL: --ptx -O3 -arch=sm_120 -std=c++17 --fmad=true --use_fast_math, sha256 6c9f80f9617d90ed637164621093aaa31ed67892fbcb03491f6eb076fb405ea8),
original_verify_window_gr/head_chain.rs (asset, resolve, the two plans), original_verify_window_gr/tests/head_chain_launches.rs,
original_verify_window_planner/tests/head_chain_batch.rs, tools/decode-sm120/sm120_probe_head_chain.cpp +
build_head_chain.sh, scripts/e2e/codex/speed/verify_tail_report.py. Edited (a few lines each): original_verify_window_sm120.rs (switch, own
block), original_verify_window_gr.rs (field, module), .../gr/assets.rs, .../gr/plan_hc_read.rs (two dispatch lines),
.../ops/all_window_assets.rs (resolve + asset), scripts/gpu-bringup/extra-seal-plan.json, ptx-sm86/MANIFEST.json ("not built
for sm_86 by design").
5. Expected section delta (arithmetic, not a claim)
Per extra row the literal chain pays (p50 of CP.1): write 0.8 + norm 1.9 + down gemv 3.7 + silu 0.7 + up gemv 5.8 + pre-final
1.2 = 14.1 us of kernels and 6 x 0.10 us of gaps = 14.7 us. The batched chain pays for the first row what T = 1 pays (20.5 us
from the last add_hits to the head quantize) plus the wider kernels. Upper bound of the saving of the section "hyper-connection
chain" is therefore 14.7 x (T - 1) = 14.7 / 29.4 / 44.1 / 58.8 / 73.5 us at T 2..6, 35 us weighted at LEL's T mix (mean T - 1 =
2.39); the lower bound is what the wider kernels give back (the up gemv has T x 10,240 block-rows of work and is throughput
bound, so not all of its 5.8 us per row disappears). My expectation is 0.02 .. 0.035 ms a graph, which would close 22 .. 39 % of
R8's 0.090 ms. VANL parity for this section would be 31.2 us weighted. The matmul (38.4) and pick (18.0) stay.
6. What the orchestrator should look at
- Probe (model-free, on the GPU; built in WSL, not run):
tools/decode-sm120/build_head_chain.sh [OUTDIR]thenOUTDIR/sm120_probe_head_chain OUTDIR/ptx. It runs the literal six kernels a row against the batched launches for T = 1..8, three seeds (small, large, special values: -0.0, denormals, inf, nan), the write also for groups starting at row 1..7; every byte of R, xn, lo, gated and mixed is compared (buffers start as 0xCD, so a stray write shows). Expected:SUMMARY failures=0. - Identity: set only
LELEKA_SM120_HEAD_CHAIN_BATCH=1(alone, then with the profile set) and run the teacher-forced top-16 + draft trace job: rows must be bit-identical, A/A first. - CUPTI window, per T within one variant (the tail section of
verify_tail_report.py): launches in the tail 6 T + 4 -> 10 (one group); kernelsmtp_full_native_write,mtp_full_gr_norm,mtp_full_mmvf256,mtp_full_down_silu,mtp_full_mmvf160,mtp_full_pre_finaldrop to 0 (they stay elsewhere:mmvf256/down_siluin the PLE and projection paths), andleleka_verify_final_write_rows1,leleka_verify_head_norm_rows1,leleka_verify_head_pre_final_rows1,bf16_f32_mmvf_multi_kernel<256, 4|8>+1,bf16_f32_mmvf_multi_kernel<160, 4|8>+1 come. The section to compare is "lastadd_hitsend to the start ofhead_quant" (hcin the report): 35.7 / 50.4 / 65.8 / 81.3 / 96.1 us at T 2..6 inCP.1, 20.5 at T 1. Note the window of the control and of the variant must be separate sessions with their own T mix: compare per T. - The engine log prints
leleka-serve head chain batch: ononce when the switch resolved.
7. Not finished / next
- Greedy pick (18.0 us weighted, bitwise, needs a scratch buffer in
OriginalNativeHeadRows) and the head matmul at T >= 3 (38.4 us, first experiment: the_small4-rows-a-block kernels of kind 14) are the larger remaining parts of R8 and are not launch-count fusion; both are outside the files of this step. - The probe and the identity run need the GPU; the PTX is built (nvcc 13.2.86 in WSL) and byte-pinned.
- Ledger rows to update after the orchestrator's windows: R6 (closed by side streams, residual +0.006 ms), R7 (no gap), R8 (this decomposition; the switch as the fix for the 31.2 us part).