Repository navigation
Description
Split out of #88, which left it as the last unfused traversal in the attention data path.
backward.qkv_proj.join (now join_group3_rope, #89) reads dQ/dK/dV fp32, un-rotates Q and K, and writes the fp32 [N, 3D] panel. qkv_proj.backward_into then quantizes that panel to bf16 twice — once for the weight GEMM and once for the input GEMM (#79 flagged backward.qkv_proj.weight_gemm as containing two quantizes).
By §7.1's question, the backward scratch.qkv is pure storage: one writer (the join), and both readers quantize it. Nothing accumulates in it and nothing compares it. Same argument that carried the four expert panels in #59 and q/k/v in #90.
Route: join_group3_rope writes packed bf16 directly, in whatever layout the two qkv GEMM operands want, and the two quantize launches are deleted. The win lands in backward.qkv_proj.weight_gemm (16.97 ms at the §13.9 shape on a clean container) and backward.qkv_proj.input_gemm (11.03 ms) rather than in the join row, plus the join's own write traffic halves.
Two things to check before committing to it:
- Whether the two GEMMs want the same layout. The weight GEMM consumes qkv as the K-major operand of an accumulate-transposed product and the input GEMM as a store product; if they want different TMA layouts, the join writes one of them and the other keeps a quantize, which halves the win.
LinearScratch/Bf16LinearScratchis where that is decided, and it is shared with o_proj and the lm-head — the same coupling that made §7.1 deferattention_normalized. - Rounding count. Today the join writes fp32 and each consumer rounds once from that fp32. Writing bf16 in the join means one rounding instead of two independent ones — strictly fewer, not more, so this is the good direction, but it is a §7.1 entry either way.
Estimated at ~80 lines plus the §7.1 row. Gates as #90's: --kernel ops (bit-exact vs the composition), --kernel model, --kernel gemm if any operand descriptor moves, and a same-container A/B naming the two backward.qkv_proj.*_gemm rows.
Activity
Merge pull request #93 from feitreim/qkv-join-packed