FlashAttention

FlashAttention is an algorithm that computes the attention step in transformer models exactly but much faster and with far less memory, by keeping the work in a GPU's small on-chip memory instead of repeatedly moving data to and from its main memory.

Attention is the step in a transformer where every token is compared with every other token. A standard implementation builds a full table of scores, one row and one column per token, writes it to the GPU's high-bandwidth memory (HBM), applies a softmax and reads it back again. The table grows with the square of the sequence length, so long inputs eat memory, and much of the running time goes on moving data rather than on arithmetic. In the FlashAttention paper's illustration, the GPU's on-chip SRAM moves data at about 19 TB/s but holds only around 20 MB, while HBM holds 40 GB but runs at about 1.5 TB/s.

Tri Dao and colleagues at Stanford University and the University at Buffalo published FlashAttention in May 2022. Their idea was to make attention aware of that memory hierarchy. FlashAttention splits the inputs into blocks small enough to fit in SRAM, works through them in passes and builds up the softmax result incrementally, a technique called tiling. All the steps are fused into a single GPU kernel, and the full score table is never written to HBM. For training, it stores a small normalisation factor and recomputes attention on the chip during the backward pass instead of reading a stored table. That means more arithmetic but far less memory traffic, so the net result is faster, and memory use grows only linearly with sequence length. The output is exact: the same answer as standard attention, not an approximation.

The original paper reported a 15% end-to-end training speed-up on BERT-large over the MLPerf 1.1 record, a threefold speed-up on GPT-2 with 1,000-token sequences, and the first transformers to do better than chance on the Path-X and Path-256 tasks, with sequences of 16,000 and 64,000 tokens. FlashAttention-2, released by Dao in July 2023, roughly doubled the speed again and reached 50 to 73% of the theoretical peak on Nvidia A100 GPUs. FlashAttention-3, from July 2024, targets Nvidia's H100 and reports up to 740 TFLOPs/s in 16-bit precision, about 75% utilisation, and close to 1.2 PFLOPs/s with 8-bit FP8. As of December 2026 the project's repository also offers FlashAttention-4 for Nvidia Hopper and Blackwell GPUs.

FlashAttention matters because it made long sequences cheaper to train and run without changing the model. Most developers use it without calling it directly: PyTorch's built-in attention function lists FlashAttention-2 among its fused implementations, and Hugging Face's Transformers library can switch a model to FlashAttention-2 or FlashAttention-3 with a single setting. It is also a useful lesson for reading AI news. It did not change the maths of attention, and the amount of computation still grows with the square of the sequence length. The gain came from organising memory traffic around how GPUs actually work.

Common questions

Is FlashAttention an approximation of attention?

No. FlashAttention computes exactly the same result as standard attention. It changes the order in which the work is done and where the intermediate values are kept, not the maths. The original paper also described a block-sparse variant that is approximate, but the main algorithm is exact.

What is the difference between FlashAttention, FlashAttention-2 and FlashAttention-3?

FlashAttention (2022) introduced the tiling approach. FlashAttention-2 (2023) divided the work across the GPU more efficiently and was about twice as fast. FlashAttention-3 (2024) was tuned for Nvidia's H100 Hopper chips, using their asynchronous features and FP8 low-precision arithmetic to go faster again.

Does FlashAttention work on every GPU?

No. As of December 2026 its repository lists FlashAttention-2 for Nvidia Ampere, Ada and Hopper GPUs such as the A100, RTX 4090 and H100, with AMD support through ROCm. FlashAttention-3 is built for Hopper GPUs such as the H100, and FlashAttention-4 targets Hopper and Blackwell.

Does FlashAttention make attention linear in sequence length?

Its memory use grows linearly with sequence length, but its computation still grows with the square of the length, as standard attention does. It actually performs extra arithmetic by recomputing values, and wins because it moves far less data to and from the GPU's main memory.

Finding more

Search for "FlashAttention IO-aware attention", "FlashAttention-3 Hopper" or "fused attention kernel" to follow the work. The papers on arXiv and the project's GitHub repository are the primary sources for what each version does and which hardware it supports. Framework documentation from PyTorch and Hugging Face shows how it is switched on in practice. Treat speed-up figures as specific to the GPU, sequence length and precision they were measured with.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.