FlashAttention is exact attention that skips memory traffic
Attention over N tokens builds an N by N matrix of scores, applies a softmax, and multiplies by the values, once for every head. The usual implementation writes that matrix to the GPU's large, slow memory and reads it back. The paper's claim is that for long sequences this traffic, not the arithmetic, sets the running time: "most operations in Transformers are bottlenecked by memory accesses."
FlashAttention changes where the work happens, not what is computed. It cuts Q, K and V into blocks small enough for the fast on-chip memory, and it updates the softmax block by block. The output is the same softmax(QKᵀ)V, up to floating-point rounding. The paper calls it "an IO-aware exact attention algorithm."
In the backward pass it does not keep the big matrix either. It recomputes the scores from blocks of Q, K and V that are already in fast memory, paying a few extra multiplications to avoid memory reads.
What does it save? Standard attention needs Θ(Nd + N²) accesses to slow memory, where d is the head width. The paper's bound for FlashAttention is Θ(N²d²/M), with M the size of fast memory, for M between d and Nd. It reports about 3 times faster GPT-2 training at sequence length 1K, and 15% faster BERT-large at 512.
If an attention layer is slow at long sequence lengths, check memory traffic before reducing the model.
Dao et al., NeurIPS 2022, §1, §3.1 (Theorem 1) and §3.2 (Theorem 2)