What problem does it solve?
Flash Attention reduces the high compute and especially the high memory cost of transformer self-attention so you can train and run long-context models without running out of GPU memory.
Core Features & Use Cases
- 2-4x speedup with exact attention: Uses IO-aware tiling and recomputation to accelerate attention while keeping results aligned with standard attention for typical dtypes.
- Huge memory reduction for long sequences: Avoids materializing the O(N²) attention matrix, enabling much longer contexts on the same hardware.
- Multiple integration paths: Works via PyTorch’s native scaled_dot_product_attention (PyTorch 2.2+), or via the flash-attn library for advanced variants like multi-query, sliding-window, and FlashAttention-3 (H100 FP8).
Use Case: Running a Llama- or Mistral-style model on 4K–32K tokens where standard attention either OOMs or becomes too slow; Flash Attention lets the same workload fit and run faster.
Quick Start
Use the torch.nn.functional.scaled_dot_product_attention path in PyTorch 2.2+ so your model automatically leverages Flash Attention when available.