FlashAttention
Attention was always described as a compute problem. FlashAttention's insight is that it is mostly a memory-traffic problem — and that rearranging where the numbers live, without changing a single result, makes it several times faster.
What the textbook implementation wastesThe standard version builds the full matrix of scores between every pair of tokens, writes it to the GPU's main memory, reads it back to apply softmax, writes that, then reads it again to multiply by the values. For a sequence of eight thousand tokens that intermediate matrix is enormous, and the GPU spends most of its time moving it rather than computing with it. Memory bandwidth, not arithmetic, is the ceiling.
Tiling and online softmaxFlashAttention never materialises that matrix. It walks over blocks of queries and keys, loads each tile into the chip's small fast SRAM, and accumulates the output as it goes, carrying a running maximum and sum so the softmax still comes out correct without ever seeing a full row at once. The backward pass recomputes tiles instead of storing them. Memory use drops from quadratic to linear in sequence length, and the output is exact — this is not sparse or approximate attention.
Why it changed what models could beLong context windows are downstream of this kernel. FlashAttention-2 improved how work is partitioned across the GPU and a third version targets newer hardware; the implementation now sits under PyTorch's scaled-dot-product attention, Hugging Face Transformers and vLLM. Most training and serving today runs on it whether or not anyone involved names it.
FlashAttention is an exact attention algorithm that computes the same result as standard attention while never writing the full attention matrix to GPU memory. It processes queries and keys in tiles held in the chip's fast on-chip SRAM, recomputing what it needs in the backward pass. Because attention is limited by memory traffic rather than arithmetic, this cuts both memory use and wall-clock time, making long training sequences affordable with no change to model quality.
Imagine a cook with a tiny counter but a huge pantry. Every trip to the pantry costs time, so the fast way to work is to carry one small batch over and finish everything you can with it before going back. FlashAttention is that discipline applied to the part of a language model that compares every word with every other word. The maths is unchanged — the answer is exactly the same — but the model stops hauling enormous intermediate tables back and forth across the chip's slow memory. The payoff is practical: longer documents fit, training costs less, and answers arrive sooner.