FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, Christopher Ré
NeurIPS 2022 · arXiv 2205.14135 · Read the paper ↗
Exact attention computed tile by tile, so the full score matrix never touches slow memory.
5 steps · 0 solved
Start: Stable softmax →- 1Stable softmaxSubtract the max before exponentiating.LLM sampling: turn logits into probabilities without overflowing
- 2Online softmaxUpdate the max and sum one block at a time.Online softmax, the trick inside FlashAttention
- 3Why tiling helpsCount memory traffic for naive and tiled matmul.Count global memory loads for naive vs tiled matmul
- 4Tiled attention forwardPut it together for causal attention.FlashAttention-style tiled causal attention forward (Dao et al., 2022)
- 5Tiled backwarddK and dV block by block from the saved log-sum-exp.Compute dK and dV tile by tile from the saved log-sum-exp
More transformers and llms papers
- Attention Is All You Need 2017
- LoRA: Low-Rank Adaptation of Large Language Models 2021
- RoFormer: Enhanced Transformer with Rotary Position Embedding 2021
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model 2023
- Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity 2021
- Fast Inference from Transformers via Speculative Decoding 2022
- LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale 2022