Dao-AILab/flash-attention
Fast and memory-efficient exact attention
What it solves
FlashAttention optimizes the attention mechanism in transformer models to be faster and more memory-efficient. It addresses the high memory and computational overhead associated with the standard attention operation, specifically by reducing the number of times data is moved between different types of GPU memory (IO-awareness).
How it works
It implements a specialized version of scaled dot product attention that minimizes memory access. The project provides multiple versions (FlashAttention, FlashAttention-2, 3, and 4) optimized for different GPU architectures, including NVIDIA (Ampere, Ada, Hopper, Blackwell) and AMD (ROCm). It supports advanced features like causal masking, sliding window local attention, and multi-query/grouped-query attention (MQA/GQA).
Who it’s for
It is designed for machine learning engineers and researchers who are training or deploying large language models (LLMs) and need to maximize GPU throughput and reduce memory consumption during the attention phase.
Highlights
- Multi-GPU Architecture Support: Optimized kernels for NVIDIA Hopper (H100) and Blackwell (B200) GPUs, as well as AMD ROCm-compatible GPUs.
- Memory Efficiency: Reduces IO overhead to speed up both forward and backward passes.
- Inference Optimization: Includes specialized functions for incremental decoding with KV cache support.
- Flexible Attention Patterns: Supports causal masking, ALiBi slopes, and sliding window attention.
Related
- Project
- Project
- Project
- Dispatch
- Project