Repository navigation
The dK/dV epilogue is the next item's opening move, and the probe says which of its three parts that was worth (#94) - #102
Merged
Conversation
…s which of its three parts that was worth (#94)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 4 of #94, on kernel B. Phase 0 is posted on the issue; this is what it licensed, and the forensics that licensed it are half the diff.
#100closed with kernel B named as the next increment on the strength of one number it had not decomposed —EPI6 347 ticks an item. So the first thing here is the decomposition, because #98 already has one refuted reading of this kernel on the record ("saturated store port") and a second guess was not worth taking.Phase 0, in four lines
EPIsplitsEWAIT 829 + ETREAD 649 + ESTORE 5 004. The twotcgen05.ldbands — the thing that makes kernel B's epilogue structurally different from kernel A's — are 10% of it. It is 128 KiB of fp32store_rows, at a per-byte rate no worse than kernel A's 64 KiB.FILL4 511 against 1 306, because a kernel-B item opens by TMA-ing 64 KiB of resident K and V plus three staged query tiles while the pass warps sit atscored.wait(0).FILL 4 511 + GAP 1 609 + EPI 6 482of a 46 638-tick item.ISSUE 3 188 / IDLE 23where The HD-wide accumulations are one N=128 band, and the dQ drain is the next item's opening move (#94) #100 read1 564 / 1 642; the sums are 3 211 and 3 206, and every pass-side column reproduces. Kernel B's irreducible issue work isTMA 61 + SMMA 1 013 + 2 × GMMA 182 ≈ 1 440, so the pass has ~1 000 ticks of room before the issue side binds — not the 2 100 anIDLEreading implies.The change
The dK/dV drain is the next item's opening move.
BackwardKvStreamgainsstaged_row/staged_headand adrain, the item's bottom keeps only theaccumulated.waitthat cannot crosspipeline::run's barrier re-arm, and a flush after the persistent loop settles the last item. It isBackwardQStream::drainwith a second band, and the hazard resolves identically: the next item's first gradient MMAs overwrite both accumulators (accumulateisstep != 0) and are issued after the block barrier at the bottom of the pass's first step, by which timetile_x8has retired the drain'stcgen05.ld. The issue warp'sjob.draincall is a predicated no-op — it never stages a row — which is what keeps the out-of-quadrantgroup = 2it would compute from ever addressing anything.And the instrument, which belongs in
mainfor #95's and #100's reason. Kernel B gets theTMA + SMMA + GMMApartition ofISSUEand the per-itemFILL/GAPthat only kernel A had; both kernels getEPIsplit intoEWAIT + ETREAD + ESTORE. Kernel B'sPASSsplit is in the file behindphase_probe::KV_PASS_SPLIT, off, because there it is not free — see the last section.What it buys
The tick budget is the container-independent instrument, so it leads. Kernel B, per item,
main @ f15b471against this PR:EPIFILLDRAINGAPEPIfalls toEWAITexactly, andFILLfalls to nothing: the drain went into the window and the window is gone. The drain itself costs +954 ticks where it landed (5 653 → 6 607) — its stores now contend with the TMA fill they are hiding behind — so the item saves10 993 → 7 795, not the whole 5 653. That is the honest reading of why the shortest shape moves most: the fill window is the same size at every shape and the item it is amortized over is not.Kernel A's columns are unchanged in the same pair of runs (
EPI493/492,DRAIN3 955/3 952, span 28 276/27 827).Clean standalone profiles, §13.9 shape (L=12, B=12, T=2048, D=3072, H=24, HD=128, E=8, K=2), two containers whose full steps agree to 0.4%:
f15b471forward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dot−3.4% on the row against −3.7% on the tick budget at the same shape, which is the agreement that carries this: two instruments, one clock-free.
Same-container A/B, both orders
--baseline-ref f15b471, throttled containers — the full step reads 754–756 ms where the standalone pair above reads 327–329, i.e. 2.3×, the hazard #96 named. The rows are the measurement.f15b471forward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotOrder reversed — this branch retained and profiled first at
6357e36(tree-identical to the head here),f15b471passed as the candidate, so the Δ column is still "what this PR saves":f15b471(candidate)forward.attention.flashbackward.attention.flash_qbackward.attention.flash_kvbackward.attention.flash_dotBoth orders put
flash_kvdown (−0.3985 and −0.6128) and the named rows account for the step delta each way to within the noise on the untouched ones.The throttled A/B under-reports this change relative to both clean instruments (−0.8% and −1.3% on the row against −3.4%), and it is worth saying why rather than picking the number I like: what this PR moves is a store into a TMA fill, and a container 2.3× off its clocks stretches both. The A/B agrees on the sign in both orders; the standalone pair and the tick budget agree on the size.
./run.sh flash-attn flash, [32,1024,24,128] — forward 0.793, backward q 0.617, backward kv 1.039, both 1.655, against #100's post-repin 0.793 / 0.621 / 1.033 / 1.653. That is a cross-container comparison and it reads flat; the probe's own shipped-kernel column, which times the shipped kernel beside the instrumented one, reads backward kv 1.063 → 1.037, 1.307 → 1.273 and 0.354 → 0.329 across the three shapes. Both are cross-container and neither is the instrument the span column is.Gates
--kernel flash-attn --bin flash— green and byte-identical tof15b471: dq 7.299e-4 / 5.203e-4 / 6.458e-4, dk 7.322e-4 / 7.437e-4 / 7.084e-4, dv 2.933e-3 / 2.717e-3 / 2.911e-3, y ≤ 1.469e-3, lse ≤ 9.537e-7 — the digits The backward's register pass splits across two warpgroups over the same TMEM lanes (#94) #98 and The HD-wide accumulations are one N=128 band, and the dQ drain is the next item's opening move (#94) #100 published. Forced correction 100.00% of its 32 eligible visits, 0.00% everywhere else. Byte-identical for a reason: it is the same drain of the same accumulator columns to the same addresses, later.--kernel ops— green.--kernel model— green, 14/14, MoE overfit 2.949803 → 0.000039.KernelBudget: forward 128 / 0, backward q 128 / 0, backward kv 138 → 142 / 0, ratcheted, zero spill, 85 under ptxas'65536/288= 227. The four registers are the staged(row, head)pair and the address arithmetic they feed, live across the item; kernel A paid the same four in The HD-wide accumulations are one N=128 band, and the dQ drain is the next item's opening move (#94) #100 and had them to spare, this kernel's peak liveness isPᵀheld across formingdSᵀand the four land on top of it.What is left in kernel B, and one thing I did not build
With the item-level work banked, kernel B's remaining cost is the visit, and the visit is the pass:
PASS2 974 of a 3 595-tick pass column, against an issue column whose irreducible part is ~1 440.The probe answers what the pass is made of, and the answer costs something to get — kernel B's seven stops a chunk are +8.9% against its shipped self (kernel A's three are +3.4%) and move 1 600 ticks a visit out of
IDLEand intoGMMA. So it ships behindKV_PASS_SPLIT = false, with the one number it was built for on the record:The ~1 000 ticks kernel B's pass carries over kernel A's are arithmetic, not the second
store_tile— the extra swizzled store ofPᵀis worth 131 ticks and the TMEM read is flat. The two passes issue the same operations on the same shapes; the difference is that kernel B's two subtracts aresub_col_assignwhere A's aresub_row_assign, and ferro'scol_map_assignreads its operandSLOTS × VALUEStimes whererow_map_assignhoists it toSLOTS. Filed as ferro-kittens#196 with the measurement and the six-line mirror-image fix, explicitly unverified — it is a hypothesis with a symptom, not an attribution, and it wants a cadence pair before it wants a PR. Not in this branch, and this branch does not depend on it.The other residual is the one this PR could not remove:
ESTOREis still 5 928 ticks an item, now hidden rather than paid, and hiding it is all there is to do with it — a[32, 64]BaseLdtmband'sstore_rowsputs 8 rows × 32 bytes behind each store instruction, which is the layout's own coalescing and not a call-site choice.