talira

FlashAttention

Fast, memory-efficient exact attention kernels for training and running transformers on GPUs

open sourceBSD-3-Clausefree

FlashAttention is the official implementation of FlashAttention and FlashAttention-2, fast and memory-efficient exact attention for transformers, from Tri Dao and colleagues' papers. It installs from PyPI as flash-attn for PyTorch on NVIDIA CUDA or AMD ROCm. The repository also carries FlashAttention-3, a beta optimised for Hopper GPUs such as the H100, and FlashAttention-4, written in CuTeDSL for Hopper and Blackwell GPUs and published as flash-attn-4.

Problems it solves

  • speed up transformer training and cut its GPU memory use
  • fit longer sequences into my GPU's memory when training a model
  • use the fastest attention kernels on H100 or Blackwell GPUs

Features

  • FlashAttention and FlashAttention-2 exact attention
  • NVIDIA CUDA and AMD ROCm support
  • FlashAttention-3 beta for Hopper GPUs
  • FlashAttention-4 in CuTeDSL for Hopper and Blackwell

Limitations

  • Linux only; Windows may work from v2.3.2 but isn't well tested1
  • Needs a CUDA or ROCm toolkit and PyTorch 2.2+, and compiling without ninja can take about two hours1

Alternatives

The same job

These do what FlashAttention does.

  1. FlashMLA DeepSeek's optimized Multi-head Latent Attention kernels for LLM inference on NVIDIA GPUs and Ascend NPUs

Compare FlashAttention with the top 3