Skip to content

V is read where its GEMM left it, because a descriptor transposes and an epilogue rounds (#107 A8) - #118

Merged
feitreim merged 2 commits into
mainfrom
a8-elide-v-panel
Aug 6, 2026
Merged

feitreim merged 2 commits into
mainfrom
a8-elide-v-panel

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

Closes #107's A8, the last unimplemented inventory item with real traffic.

What the inventory got wrong

A8 was priced at 6.75 GiB/step and marked HARD, on the reading that flash
would need a TMA descriptor over the fp32 row-major [N, 3, D] qkv panel, which
it cannot have: tcgen05 takes bf16 operands and nothing widens on the way in.
That is right about the fp32 panel and wrong about the obstacle. The
descriptor was never the obstacle.

stage_qkv_heads_bf16 did exactly three things to V's third of the panel: read
it fp32, round it to bf16, and transpose token against head. Nothing rotated it
(RoPE is Q and K only), nothing scaled it, nothing accumulated it. The GEMM's
packed epilogue already rounds, and a TMA descriptor already transposes —
Tcgen05Gemm::store and GlobalLayout::strided both shipped before the issue
was filed. So the question was never "can a descriptor address V inside an fp32
panel" but "can V's group have its own bf16 destination", and it can.

Not #88's declined half either: #88 rejected fusing RoPE into the epilogue (its
tile mapping is MN-major and a rotation crosses column pairs inside a tile).
Nothing is fused into the epilogue here — V's group gets its own GEMM and the
epilogue is the one already in the tree.

The change

The qkv projection runs as two GEMMs over the one transposed weight operand,
read through descriptors over its two row bands (TransposedBands, mapping the
same bytes transposed_tma maps whole — two descriptors, no storage):

  • Q and K's groups → the fp32 [N, 2D] panel stage_qk_heads_bf16 still needs,
  • V's group → packed bf16, straight into the saved panel flash reads.

Flash addresses head h of that row-major panel as a column band through
create_flash_row_major_tma_map: a rank-3 strided GlobalLayout over
[HD, B*T, H] at element strides [1, H*HD, HD]. (batch, token) collapses
into the row coordinate because batch * T + token is the panel's row index,
so the kernels change by their coordinates alone — row = batch * T + token,
plane = head, where a staged panel takes row = token,
plane = batch * H + head. No new tile-library call, no relayout, no kernel
work, and the driver accepts the descriptor's non-monotonic strides (head stride
256 B inside a 6144 B row stride) — checked on device, not assumed.

Per block V's whole fp32 round trip goes: the wide store, the staging read and
the staging write, against one bf16 store added back. 8 · N · D bytes a block
— 9 GiB/step at B=16, 18 GiB/step at B=32. VRAM is unchanged (same [N, D]
packed panel, different writer). Launches +12.

Parity — exact, tolerances untouched

Splitting the output's N leaves each output tile's K walk alone, so V's fp32
accumulator is the unsplit GEMM's to the bit and the packed epilogue's RNE lands
exactly where f32_to_bf16_rne did in the staging pass.

  • --kernel flash-attn: the fused-staging exact gate is now Q/K against
    split_group2 + two rope passes + two staging launches — still exact, every
    word
    . And every tcgen05 forward/backward parity shape now feeds V through
    the row-major descriptor while its CPU reference still indexes head-major, so
    the descriptor's relayout is itself under an exact-layout check at each shape.
    All green.
  • --kernel flash-attn flash: green, ptxas budget gate passes. Forward
    128 regs / 0 spill (pinned 128), backward q 128 / 0, backward kv
    138 / 0 (under the pinned 142). Forward residency unchanged at
    2 CTA/SM, 114836 B shared.
  • --kernel model: all 14 checks green.

Measurement — small, and smaller than the bytes

compare_profile, same container, B=32. The attributable rows:

row main this Δ
forward.qkv_proj.gemm 59.085 39.727
forward.qkv_proj.gemm_v — 19.725 +0.367
forward.attention.stage_qkv → stage_qk 5.030 3.965 −1.065
forward.attention.flash 27.386 27.407 +0.021
backward.attention.flash_q / flash_kv 28.175 / 50.525 28.110 / 49.925 −0.065 / −0.599
full step 720.283 715.033 −5.25

Two things to read off this. Flash pays nothing for the strided descriptor —
all three flash rows are flat or better, which is the load-bearing result.
And the qkv GEMM is not store-bound at this shape: halving a third of its
output cost it nothing measurable and the split's extra wave gave 0.37 ms back,
so only the staging third of the 18 GiB converts. Directly attributable:
−0.70 ms of a 720 ms step. The remaining −4.6 ms of that full-step delta is
spread across untouched expert-GEMM rows and is container drift, not this change.

train_ab, 30 steps, arms alternating, two containers:

container 1 (2 rounds)   baseline 92183.8   candidate 92499.5   1.0034
container 2 (4 rounds)   baseline 91928.7   candidate 92304.4   1.0041
pooled (6 rounds each)   baseline 92013.7   candidate 92369.4   1.0039

+0.39%, candidate ahead in 5 of 6 paired rounds. That is at the edge of what
this harness resolves (spreads 0.24–0.98%), and it is the size the arithmetic
allows once the GEMM's share is known not to convert. #107's own caveat holds:
this is a many-small-wins area and A8 is one of the small ones now that A1/A2
have taken the large one. The value here is as much that the descriptor question
is settled — a strided view into a projection panel is a working flash operand —
as the 0.4%.

… an epilogue rounds (#107 A8)

`stage_qkv_heads_bf16` did three things to V's third of the projection
panel: read it fp32, round it to bf16, and transpose token against head.
Nothing rotated it, nothing scaled it, nothing accumulated it — the
staging pass existed for V only to change its dtype and its layout.

The GEMM's packed epilogue already rounds, and a TMA descriptor already
transposes. So the qkv projection runs as two GEMMs over the one
transposed weight operand, read through descriptors over its two row
bands: Q and K into the fp32 panel the rotate-and-stage pass still needs,
and V's group's packed bf16 straight into the saved panel flash reads.
Flash addresses head `h` of that row-major panel as a column band —
`row = batch * T + token`, `plane = head`, where a staged panel takes
`row = token`, `plane = batch * H + head` — which is one strided
`GlobalLayout` and no kernel work at all.

Splitting the output's N leaves each output tile's K walk alone, so V's
fp32 accumulator is the unsplit GEMM's to the bit and the epilogue's
rounding lands exactly where `f32_to_bf16_rne` did. What disappears per
block is V's whole fp32 round trip: the wide store, the staging read and
the staging write.

The flash harness gates it: the fused staging gate is now Q/K against
`split_group2` + two rope passes + two staging launches, still exact,
and every tcgen05 forward/backward parity shape now feeds V through the
row-major descriptor rather than a staged panel — so the descriptor's
relayout is checked against a head-major CPU reference at every shape.
@feitreim

feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main after #120 (no conflicts; #120's touches are modal_app.py,
bin/profile.rs and the GEMM epilogue, none of which this branch edits).

The model parity harness never reaches the staged path — its shapes are T = 4,
so tcgen05_attention_eligible is false and every check runs the fp32 oracle
arm. The staged path only exists at the training shape, so the end-to-end
numeric check for it is the loss curve. On the rebased branch, 40 steps at B=32:

step=1  loss=11.124607     step=20 loss=8.362467
step=5  loss=10.063386     step=25 loss=8.196915
step=10 loss=8.917294      step=30 loss=8.000682
step=15 loss=8.389352      step=40 loss=7.888780

Normal descent, no NaN, no plateau — V arrives correct at the real shape, which
is what the parity harness cannot say for itself here.

@feitreim
feitreim merged commit a47aa22 into main Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inductor fusion inventory: what torch.compile fuses on our model, mapped to the trainer

1 participant