papers / flashattention2022
Next task →
Research Papers/Efficient inference and systems/FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
Efficient inference and systems · #2 · seminal

FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness

Tri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra, Christopher Re · 2022 · NeurIPS
reproduction difficulty: highSystemsTransformersEfficiency

1. Research problem

Standard attention materializes an N-by-N score matrix in high-bandwidth memory, making memory traffic dominate runtime for long sequences.

2. Motivation

The authors wanted exact attention that respects the GPU memory hierarchy instead of approximating it or slowing training with recomputation.

3. Previous approaches

Sparse and low-rank attention approximations reduced FLOPs but sacrificed quality; exact attention implementations wrote large intermediate matrices to HBM.

4. Core contribution

Introduced an IO-aware tiling algorithm that computes exact attention in SRAM blocks, streams over keys/values with online softmax, and avoids storing the full attention matrix.

5. Mathematical formulation

Online softmax maintains running row maxima and normalization sums while streaming tiles of K and V, so the output is mathematically identical to standard softmax attention.

6. Methodology

Fuse QK^T, softmax, and multiply-by-V into one GPU kernel with tiling and recomputation of attention during backward pass instead of saving it.

7. Architecture

A GPU kernel replacing the attention module; model architecture is unchanged.

8. Experimental setup

BERT and GPT-2 training speed, long-sequence benchmarks, and comparison with approximate attention methods.

9. Datasets

Language modeling and pretraining setups on standard corpora used in BERT/GPT-2 training.

10. Results

Faster training than optimized baselines with much lower memory, enabling longer contexts; exact outputs rather than approximated attention.

11. Limitations

Requires custom CUDA kernels and specific GPU architectures; tiling parameters matter; initially less flexible for arbitrary attention masks.

12. Critical analysis

A systems paper that changed how attention is engineered: it shows IO complexity, not FLOP count, is often the real bottleneck.

13. Implementation tasks

  • 1.Implement a numerically stable online softmax in NumPy and verify it matches standard softmax.
  • 2.Profile memory usage of naive versus tiled attention for growing sequence length.
  • 3.Benchmark a hand-written tiled kernel against a library FlashAttention implementation if a GPU is available.

14. Follow-up work

  • 1.FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning (Dao, 2023)
  • 2.FlashDecoding and PagedAttention-style serving systems

15. Open research questions

  • 1.How should attention kernels adapt to new hardware and variable sequence lengths?
  • 2.Can exact IO-aware methods extend to cross-attention and sparse masks efficiently?
16. Reproduce it. Record the hypothesis, configuration, dataset, metrics and discrepancies in the Experiment Tracker. A reproduction is not complete until you have run the experiments, performed at least one ablation and documented the differences from the reported numbers.