Repository navigation
Conversation
29511f3 to
7782e5c
Compare
|
Note on the shas: both branches were |
|
Correction and the cleaner numbers. Both
Rows sum to −54.14 against a −53.07 step — a 1.1 ms cross-check, where the throttled pairs disagreed by 6–10. Every neighbouring row is flat: These are two separate containers, so they are corroboration and not the §10.1 gate; the gate is the three same-container pairs (both orders), which agree in sign and rows, and the same-shard training smoke (62345 → 73110 tok/s, 27.68% → 32.46% MFU). The residual is 13.14 ms in three rows, and #91 is the one of them that is still a fusion rather than compulsory traffic. |
Q/K/V reach flash as one rotate-and-stage pass and stay staged for the backward (#90)
Phase 2 of #88. Stacked on #89 (
rope-table) — base that first; the diff below is against it.#89 made the rotations cheap. This makes them free: on the tcgen05 path there is no rotation pass at all, no split, and no staging pass either — one kernel reads the projection's fp32
[N,3D]panel and writes the three packed-bf16 head panels flash streams.The kernel
stage_qkv_heads_bf16substitutes forsplit_group3+ tworope_forwardpasses + threestage_attention_heads_bf16launches. Per packed output pair it reads three fp32 couples (Q, K, V at their group strides) and one(cos, sin)couple, rotates Q and K, foldssoftmax_scale · log2(e)into Q, quantizes RNE, and writes three words at the head-major index the existing staging pass already computed. Reads and writes stay the coalesced runs the unfused staging had; the table adds 8 bytes a lane out of a 1 MiB L2-resident buffer.Everything it drops was fp32 storage between two kernels — an fp32 expression stored and reloaded as fp32 is a no-op — so the words it writes are the composition's bit for bit, and
--kernel flash-attnasserts that at zero tolerance at three tile-aligned shapes rather than at a tolerance. The unfused kernels stay as the oracles it is checked against (§11);stage_attention_heads_bf16keeps its own bit-exact CPU mirror and is still what stages dY.The storage change (SPEC §7.1)
acts.q/k/vwere[N,D]fp32 ×3, 10.1 GiB live, and §7.1 already had them flagged as deferred candidates: their only consumer was the staging pass that quantizes them. They are now the staged panels themselves —GpuBlockActs::attentionis anAttentionOperandsenum,Stagedon the tcgen05 contract andWide(the fp32 triple, the split, the two rotation passes) for every shape its oracle kernels serve. That is the documented decision change, written up in §7.1 with the audit's own question applied: q/k/v hold nothing accumulated or compared, RoPE is a pointwise rotation rather than an accumulation, and it now happens before the single rounding instead of between two of them.Two consequences beyond the forward:
FlashAttentionScratchis down to dY — a backward temporary, one buffer for every block — and its correction counts.Nothing else reads the panels (checked); the CPU-parity reference compares model outputs, not attention operands, and needed no change.
Measurement
Same-container A/B against #89's head, §13.9 shape. (Same caveat as #89: these
compare_profilecontainers run the tcgen05 GEMMs 3–6× slower than a clean one — absolute step 810 ms where a standalone profile ofea8e147reads 401.8 ms and the training smoke below reproduces the brief's 62.4k tok/s exactly. Both halves saw it; the row deltas are the claim.)forward.qkv_proj.splitforward.q_ropeforward.k_ropeforward.attention.stage_bf16forward.attention.stage_qkvbackward.attention.stage_bf16Four forward rows totalling 19.72 ms become one 5.04 ms row. The fused pass is cheaper than the staging pass alone was: it reads the same bytes as three coalesced runs out of one buffer instead of three kernels each walking a different one.
Backward staging drops to a quarter — three of its four operands are now panels the forward already wrote.
Rows touched sum to −22.09 against a −28.81 step. The remaining −6.7 is nine GEMM rows each drifting −0.3 to −0.9, all the same direction; I am not claiming them. If it is not drift it is the freed VRAM, and the honest statement is that this change is worth the −22.09 it can account for.
VRAM: 134.8 → 129.4 GiB used, free headroom 43.5 → 49.0 GiB (+12.6%) — the 5.4 GiB the fp32 triples cost.
Gates
--kernel flash-attn— green, including the new zero-tolerance fused-vs-composition staging gate at[1,128,2],[2,256,3],[1,1024,4].--kernel flash-attn --bin flash— green: forced-correction gate (ramped-key reference) passes, and everyKernelBudgetlands exactly on its pin — forward 128/0, backward q 182/0, backward kv 190/0. No rise, nothing to ratchet.--kernel model— green. Note this exercises theWidearm only (its shapes areT=4), which is the same coverage the staging path has always had in that binary; theStagedarm is gated by--kernel flash-attnand by the training smoke.--kernel model --bin train --shard /data/wiki-train-00000.tok --steps 100, same shard, main vs this stack:ea8e147Trajectories are indistinguishable — they differ from step 1 in the fifth decimal, which is the MoE scatter-atomic nondeterminism, and neither run is systematically above the other. The baseline run reproducing the brief's 62.4k tok/s / 27.70% MFU to three digits is also what says the
compare_profilecontainers above, not this pair, are the anomalous ones.--kernel gemm.