United StatesDao-AILab/flash-attention
Fast and memory-efficient exact attention
⚡ Exact attention, built for the memory hierarchy
Speed up attention without approximating it.
FlashAttention is the official implementation of FlashAttention and FlashAttention-2 from Tri Dao et al. Built around IO-awareness, it tiles Q, K, and V to compute exact attention on-chip instead of materializing the full N×N attention matrix in slow memory. Alongside it, there is a beta FlashAttention-3 for Hopper GPUs and FlashAttention-4 written in CuTeDSL for Hopper and Blackwell GPUs.
✨ Highlights
- IO-aware exact attention: computes attention blockwise to cut HBM reads/writes while keeping the exact attention result.
- Multiple generations: FlashAttention-2 adds better parallelism and work partitioning. FlashAttention-3 (beta) targets H100/H800 with FP16/BF16 forward/backward and FP8 forward. FlashAttention-4 targets Hopper and Blackwell via CuTeDSL.
- Broad hardware coverage: supports NVIDIA CUDA 12+ on Ampere, Ada, Hopper, Blackwell (Turing via a separate repo), and AMD ROCm 6+ via the Composable Kernel backend or Triton backend.
- Rich attention features: covers causal masking, variable sequence lengths, MQA/GQA, dropout, rotary embeddings, ALiBi, paged attention, arbitrary Q/KV lengths, and head dimensions up to 256 (with backend-dependent support).
- Flexible install paths: install
flash-attnvia pip with--no-build-isolation, build from source, use thehopper/beta build for FlashAttention-3, orpip install flash-attn-4(withcu13extra on CUDA 13).
💡 Why it matters
By reordering attention to match GPU memory hierarchy instead of changing the math, FlashAttention makes long-context exact attention feasible where naive implementations run out of memory or bandwidth. It drops into transformer stacks with minimal API changes while letting users pick the generation and backend that fits their hardware.
It's best used in training or inference where sequence length is the bottleneck and exact attention is required.
#Attention #CUDA #ROCm #IOAware #TiniX