Reproduce “FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness” on OpenResearch
Turn your favorite coding agents into research agents that review literature, develop hypotheses, and run experiments.
Universal app for Apple silicon and Intel. Requires macOS 11 or later.
About this paper
Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, Christopher Ré
FlashAttention computes exact self-attention by processing blocks in GPU SRAM, using online softmax, kernel fusion, and recomputation rather than storing the full attention matrix in HBM. It retains quadratic arithmetic and linear additional memory. On 8 A100 GPUs, a 4K GPT-2 small run reported perplexity 17.5 and 3.6 days, versus 18.2 and 4.7 days at 1K with Megatron-LM; both context and implementation differ.
Key insights
- Modern GPUs are frequently memory-bound rather than compute-bound; optimizing data movement (IO) between memory levels is critical for real-world performance gains.
- The softmax normalization factors for attention can be updated incrementally, allowing attention computation to be broken into smaller blocks and processed efficiently within fast on-chip memory (SRAM).
- Storing only essential information and recomputing intermediate attention values during the backward pass reduces memory consumption from quadratic to linear while maintaining speed due to on-chip processing.
Summary by alphaXiv.
Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.