Why can FlashAttention be faster with the same formula?

Distinguish FLOPs, memory IO and intermediate storage.

Content revision 4 · 2026-10-24

S03 · Revision 1 · 2026-10-21

  1. HBM: Q / K / V
  2. SRAM: tiles + online softmax
  3. HBM: outputs and statistics
FieldToFit redraw: IO-path redraw; box sizes do not represent capacities.

The bottleneck

Naive attention may materialize and repeatedly read/write T×T scores and probabilities in HBM. FlashAttention tiles the operation and performs local work in on-chip SRAM, avoiding full intermediate matrices in device memory.

The mechanism

Online softmax maintains each row’s maximum m, normalization sum l and weighted output. Each new tile rescales previous accumulators to the updated maximum and merges its contribution. Backward can recompute intermediates, trading compute for IO. The mathematical attention is unchanged, not necessarily bitwise floating-point results.

m′ = max(m, max(S_tile)); l′ = e^(m−m′)l + Σe^(S_tile−m′)

Examples and evidence

The sketch moves Q/K/V tiles from HBM into SRAM, writing required outputs and statistics. Avoiding full T² intermediate storage does not eliminate T² dense interactions. Report sequence length, head dimension, precision and hardware when measuring gains.

New constraints

On-chip capacity, thread layout and kernel support define applicability. Small sequences or special masks may gain less. FlashAttention optimizes execution; it does not replace long-context evaluation or KV allocation management.

Primary sources

Manual browser reading records and interactive calculators are available with JavaScript.

Keep exploring

I04 · Why is a long context not reliable long-term memory?

S04 · How does PagedAttention reduce KV allocation waste?

All 18 questions