FlashAttention
FlashAttention is an IO-aware exact attention algorithm that reduces GPU memory bandwidth pressure by reordering the order of computation. It does not change the mathematical result, yet it makes attention several times faster in practice and cuts memory usage from quadratic to linear, and it has become the default component in nearly all large-model training and inference stacks today.
Core Principles
The root of the problem lies not in compute but in memory access. A GPU has two kinds of storage: on-chip memory that is extremely small but very fast, and high-bandwidth memory that is very large but limited in bandwidth. The speed gap between them is often more than an order of magnitude. Naive attention must write the full attention matrix, whose size is the square of the sequence length, out to HBM, read it back for normalization and weighted summation, and then read it again during backpropagation; these repeated read-write rounds become the real bottleneck, while the matrix multiply units themselves sit idle waiting, so compute utilization is driven very low.
FlashAttention's approach is tiled computation: it splits queries, keys and values into blocks, loads them into on-chip memory block by block, and completes scoring, masking, normalization and weighted summation inside the chip, without ever materializing the full attention matrix in HBM. To remain strictly exact under tiling, it uses online normalization, maintaining the running maximum and scaling factor as it accumulates and applying a final correction, so that the tiled intermediate results are fully equivalent to the whole computation.
At the same time it pairs this with recomputation: instead of keeping intermediate matrices for backpropagation, it recomputes the forward fragments on demand, trading a small amount of extra compute for a large amount of memory. The overall effect is linearized memory usage, markedly higher speed, and a result that is mathematically equivalent exact attention rather than a sparse or low-rank approximation.
The method was proposed by Tri Dao and others. The early version established the tiling and recomputation framework; the second version optimized thread-block partitioning and parallelism, reduced the overhead of non-matrix operations and improved efficiency under causal masking, bringing real throughput close to the theoretical limit; the third version targets a new generation of hardware, using asynchronous copies, tensor memory acceleration and low-precision features to squeeze out further throughput and push more computation onto hardware units. The common thread across the three generations has always been to keep data as close as possible to the compute units.
Key Points
First, it is exact, which is the fundamental dividing line between it and sparse or linear attention: it does not sacrifice quality, it only optimizes execution. Second, the gain comes from improved memory access: the longer the sequence and the better the head dimension fits the hardware, the more pronounced the gain; on very short sequences the gain is limited.
Third, it depends heavily on hardware and kernels: different generations and different precisions require dedicated implementations, and whether a kernel fits the hardware directly determines success. Fourth, it is a low-level acceleration rather than an architectural change, and can be layered onto most models as a plug-in replacement, which is exactly why it spread so fast. Fifth, it multiplies with structural optimizations such as grouped-query attention; one manages the cache, the other manages memory access.
Common Misconceptions
Many people assume FlashAttention is an approximate attention that loses precision; this is the biggest misunderstanding. Others believe it solves every long-context problem, when in fact it only lowers the constants and the memory usage: the complexity is still quadratic, and very long sequences still require sparsification, position extrapolation and cache optimization.
Application Scenarios
Large-model pretraining, long-context fine-tuning, high-resolution multimodal attention, inference acceleration, video temporal modeling, long-document question answering, and acceleration of the attention layers in diffusion models.