FlashAttention's Memory Breakthrough for Transformers

FlashAttention revolutionized Transformer efficiency by treating attention as an I/O problem, using tiling and recomputation to keep computations in fast on-chip SRAM. This avoids storing large intermediate matrices in slower HBM, reducing memory usage from quadratic to linear with sequence length and enabling contexts up to 64K tokens.

The top 3

  1. FlashAttention's Top Speedup: Up to 9x Faster than Standard Attention: FlashAttention-2 can be up to 9 times faster than standard PyTorch attention implementations, and FlashAttention-3 further boosts performance to 740 TFLOPs/s (FP16) on H100 GPUs, significantly accelerating Transformer training and inference.
  2. Memory Breakthrough: Quadratic to Linear Scaling and 40x Savings: FlashAttention reduces memory complexity from quadratic O(N²) to linear O(N) with sequence length and can achieve up to 40x memory savings for `scaled_dot_product_attention` with small head dimensions, enabling much longer context windows.
  3. The "IO-Aware" Secret: Tiling, Recomputation, and Kernel Fusion: FlashAttention's breakthrough lies in its "IO-aware" design, which employs tiling to process attention in small SRAM blocks, strategic recomputation to avoid storing large intermediate matrices, and kernel fusion, all to minimize slow High Bandwidth Memory (HBM) access.

Sources

Open the full topic