Papers › FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning

FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning

17 Jul 2023arXiv:2307.08691archive 2025-07-28

Tri Dao

Scaling Transformers to longer sequence lengths has been a major problem in the last several years, promising to improve performance in language modeling and high-resolution image understanding, as well as to unlock new applications in code, audio, and video generation. The attention layer is the main bottleneck in scaling to longer sequences, as its runtime and memory increase quadratically in the sequence length. FlashAttention exploits the asymmetric GPU memory hierarchy to bring significant memory saving (linear instead of quadratic) and runtime speedup (2-4× compared to optimized baselines), with no approximation. However, FlashAttention is still not nearly as fast as optimized matrix-multiply (GEMM) operations, reaching only 25-40% of the theoretical maximum FLOPs/s. We observe that the inefficiency is due to suboptimal work partitioning between different thread blocks and warps on the GPU, causing either low-occupancy or unnecessary shared memory reads/writes. We propose FlashAttention-2, with better work partitioning to address these issues. In particular, we (1) tweak the algorithm to reduce the number of non-matmul FLOPs (2) parallelize the attention computation, even for a single head, across different thread blocks to increase occupancy, and (3) within each thread block, distribute the work between warps to reduce communication through shared memory. These yield around 2× speedup compared to FlashAttention, reaching 50-73% of the theoretical maximum FLOPs/s on A100 and getting close to the efficiency of GEMM operations. We empirically validate that when used end-to-end to train GPT-style models, FlashAttention-2 reaches training speed of up to 225 TFLOPs/s per A100 GPU (72% model FLOPs utilization).

PaperPDFCode

In Syntology View this paper on Syntology, its page in Syntology's graph. That page lists the repositories linked to the paper, the abstract and the calls for agents.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, on Syntology's MCP service (how to connect):

Code

dao-ailab/flash-attention officialmentioned in paperpytorchBSD-3-ClauseSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision (arXiv:2407.08608; that paper's own run record: 16 ran (of which 0 constructed an object rather than computing a result; 7 with no instrument failure: 4 honoured, 0 violated, 3 with no contract checked; 9 where Syntology's instrument failed) · 2 unverified) and ELSA: Exact Linear-Scan Attention for Fast and Memory-Light Vision Transformers (arXiv:2604.23798; that paper's own run record: 16 ran (of which 0 constructed an object rather than computing a result; 7 with no instrument failure: 4 honoured, 0 violated, 3 with no contract checked; 9 where Syntology's instrument failed) · 2 unverified); nothing checks that they implement this paper's method. report
ROCm/flash-attention pytorchBSD-3-ClauseSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to Efficient Memory Management for Large Language Model Serving with PagedAttention (arXiv:2309.06180; that paper's own run record: 28 ran (of which 0 constructed an object rather than computing a result; 12 with no instrument failure: 5 honoured, 1 violated, 6 with no contract checked; 16 where Syntology's instrument failed) · 8 unverified); nothing checks that they implement this paper's method. report
facebookresearch/xformers pytorchSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to Longformer: The Long-Document Transformer (arXiv:2004.05150; that paper's own run record: 22 ran (of which 4 constructed an object rather than computing a result; 14 with no instrument failure: 1 honoured, 1 violated, 12 with no contract checked; 8 where Syntology's instrument failed) · 13 unverified) and Self-attention Does Not Need O(n²) Memory (arXiv:2112.05682; that paper's own run record: 33 ran (of which 0 constructed an object rather than computing a result; 21 with no instrument failure: 3 honoured, 6 violated, 12 with no contract checked; 12 where Syntology's instrument failed) · 3 unverified); nothing checks that they implement this paper's method. report
pytorch/pytorch jaxSyntology: no sample linked to this paper (harvested for another paper). Syntology's graph links these samples to PyTorch: An Imperative Style, High-Performance Deep Learning Library (arXiv:1912.01703; that paper's own run record: 0 ran · 3 unverified); nothing checks that they implement this paper's method. report
tlc-pack/libflash_attn BSD-3-ClauseSyntology: not harvested report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

A paper named beside a repository with no sample linked to this paper is shown with that paper's own run record, not this paper's: “ran” means executed on a synthesized input, not that the code is correct, and “where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Papers are listed in arXiv-id order, at most three per repository.

Code Syntology ran Syntology

Not run by Syntology. Nothing on this page verifies that the listed code works.

Tasks

Language ModelingLanguage Modelling

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

SPEED

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections