Skip to content

AI Glossary · Concepts

What is FlashAttention?

FlashAttention

FlashAttention is an optimized way to compute a transformer's attention that's far more memory-efficient, by avoiding writing the huge intermediate attention matrix to memory. It makes longer context windows and faster training practical without changing the model's results.

· Updated · Chain of Thought

Model Architecture

  • 2 sources

Standard attention compares every token with every other token, so time and memory grow with the square of the sequence length. That is the bottleneck that makes long contexts expensive in a transformer. Tri Dao and colleagues at Stanford showed in 2022 that a large part of the cost is not the arithmetic but moving data between the GPU’s large, slow high-bandwidth memory (HBM) and its small, fast on-chip SRAM (Dao et al., FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness). FlashAttention computes attention in tiles that fit in SRAM, so it never writes the full attention matrix out to HBM.

It is exact: the output is the same attention result, not an approximation. The paper reports a 15% end-to-end training speedup on BERT-large (sequence length 512) against the MLPerf 1.1 record, a 3x speedup on GPT-2 at sequence length 1K, and memory that grows linearly rather than quadratically with sequence length, which made longer contexts practical to train. FlashAttention-2, the following year, reorganized how work is split across the GPU and reported about a 2x speedup over the original, reaching 50 to 73% of the A100’s theoretical maximum throughput (Dao, FlashAttention-2).

You rarely call FlashAttention directly. It ships inside training frameworks and inference servers, and its effect shows up as cheaper long-context training and inference rather than as a feature. It matters for decisions you do make: how much a longer context window costs, and why kernel-level work on specific hardware can move price and speed as much as a model change. It does not change what attention does, so it is not an alternative architecture; state-space models and mixture of experts change the model itself. The model architecture topic collects the episodes on that layer, and why is it hard to move off NVIDIA? covers why hardware-specific kernels matter.

Sources

Go deeper