How does FlashAttention compute exact attention without materializing the full N by N attention matrix in high-bandwidth memory?
Last updated
Tiling: blocks of Q, K and V are loaded into fast on-chip SRAM, and each score tile is computed, used and discarded, so the N×N matrix never sits in HBM (off-chip GPU memory).
Online softmax keeps a running max, normalizer and unnormalized output per row, rescaling them as each new block arrives. The result is exact up to rounding.
All steps are fused in one kernel: FLOPs stay O(N²d) but extra memory drops to O(N) and HBM traffic falls sharply, which gives the speedup.