Tag

#attention

AI

Flash attention explained: exact attention, 2–4× faster, by moving less memory

At 128K tokens, standard attention's score matrix is 32 GiB for one head in one layer. FlashAttention never writes it to GPU memory: it streams small tiles through on-chip SRAM, keeps a running max and sum for softmax, and recomputes instead of storing. Same exact result, memory linear in sequence length, 2–4× faster. The A100 numbers, FlashAttention-2, -3 and -4, the exponential bottleneck on new GPUs, and where you meet it in PyTorch, vLLM, Ollama and llama.cpp.