2026-11-22
Flash Attention, Revisited: The Card Was Fine
10th kernel: flash attention again, this time with a backward, and a correction. Week 3 ran at about 0.5 TFLOPs on a T4, ~25x behind torch, and I blamed the card, because Turing has no cp.async. That was wrong. This version adds a backward in three kernels with no atomics, recomputing the probabilities from Q, K and the saved logsumexp instead of storing them. Output and all three gradients match SDPA to about 5e-4 relative, with essentially no exact zeros.
On a Colab T4 with Triton 3.1.0 and torch 2.5.1, two runs each: the forward does 9.5 TFLOPs at N=512, 1.69x SDPA, and 19.7-20.1 at N=4096, 1.47-1.49x. Forward plus backward beats SDPA at every size, from 1.57x at N=512 down to 1.39x at N=4096. The N=2048 forward came out 39% apart between runs, so I'm not quoting it. An Ampere comparison was single-run and isn't reported.
The catch is that Colab's default today is Triton 3.8.0 with torch 2.14, and on that the identical file does 0.41-0.56 TFLOPs. Week 3's number. Swapping only Triton on the same T4, N=4096: 3.1.0 gives 20.1, 3.2.0 gives 20.3, 3.3.1 fails to compile, 3.4.0 to 3.8.0 give 0.46-0.53. So the slowdown follows the Triton version, somewhere between 3.2.0 and 3.4.0 on sm_75. I never recorded week 3's Triton version, so its result is consistent with this, not proven by it, and why the newer compiler is slow on Turing I haven't established. Copy this kernel into a fresh Colab and you get the slow one.
Next is a fused backward, FlashAttention-2 style, one kernel instead of three: right now dK/dV and dQ each read Q, K and V again.
