Paper Breakdowns  /  FlashAttention
Paper 09~7 min readNeurIPS 2022
Paper Breakdown

FlashAttention,
explained.

Everyone knew attention got painfully slow on long inputs, and everyone assumed the problem was too much math. This 2022 paper showed the arithmetic was never the bottleneck — the GPU was spending almost all its time shuffling data between fast and slow memory. Fix the shuffling, and attention gets several times faster while computing the exact same answer.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

The real bottleneck

Self-attention has every token compare itself to every other token, producing an N×N scores matrix. For a sequence of length N, that matrix grows with the square of N — at 8,000 tokens it's 64 million numbers. The standard implementation writes that whole matrix out to memory, reads it back to apply softmax, then reads it a third time to multiply by the values.

The paper's diagnosis: the GPU's arithmetic units were mostly idle, waiting on those reads and writes. Attention was memory-bound, not compute-bound. The field had been optimizing the wrong thing.

02

Fast memory, slow memory

A GPU has two very different kinds of memory. HBM is the big main memory — tens of gigabytes, but relatively slow. SRAM is tiny on-chip memory — only kilobytes to a few megabytes, but roughly an order of magnitude faster.

The GPU memory hierarchy
SRAM~20 MB, ~19 TB/s — tiny but blazing fast. Work here.
HBM~40 GB, ~1.5 TB/s — huge but ~10x slower. Touch as little as possible.

Standard attention parks that giant scores matrix in slow HBM and keeps trudging back to it. FlashAttention's entire strategy is to never put it there in the first place.

03

Tiling and the online softmax

Instead of computing the full matrix at once, FlashAttention breaks the work into tiles — small blocks of queries and keys that fit inside fast SRAM. It loads a block, computes its piece of attention entirely in SRAM, and moves on, never writing the intermediate scores back to HBM.

The tricky part is softmax, which normally needs to see a whole row at once to normalize it. FlashAttention uses an online softmax: it processes blocks one at a time and keeps a running running-total and running-maximum, rescaling previous partial results as new blocks arrive — so it gets the exact normalized answer without ever holding the full row. All the attention operations are fused into a single pass over fast memory.

04

Exact, not approximate

This is what set FlashAttention apart. Earlier attempts to speed up attention approximated it — sparse patterns, low-rank tricks — trading accuracy for speed. FlashAttention changes only the memory schedule. The result is bit-for-bit the same attention; you give up nothing.

Worth knowing

Because it never stores the N×N matrix, FlashAttention's memory grows only linearly with sequence length instead of quadratically. That's the door to long context windows — the reason models could suddenly handle tens of thousands of tokens.

05

The results

FlashAttention delivered large end-to-end speedups — on the order of 2–4x faster attention and meaningful whole-model training speedups — while cutting attention memory from quadratic to linear in sequence length. It made previously impractical context lengths routine.

Writes full N×N matrix?Attention memoryAccuracy
Standard attentionYes — to slow HBMQuadratic in NExact
Sparse / low-rankNoLowerApproximate
FlashAttentionNoLinear in NExact
06

Why it still matters

FlashAttention (and its successors, FlashAttention-2 and -3) became a default building block baked into every major training and inference stack. If you've used a model with a long context window, you've almost certainly used it.

Its deeper lesson is one every systems engineer learns eventually: on modern hardware, data movement is the cost, not arithmetic. The fastest code isn't the one that does the least math — it's the one that moves the least memory. FlashAttention is that principle, applied to the single most important operation in modern AI.

Frequently asked

Quick answers

What is FlashAttention?

An IO-aware algorithm that computes exact attention faster and with far less memory by minimizing data movement between a GPU's slow HBM and fast SRAM — processing attention in tiles with an online softmax.

Why was standard attention slow?

It writes the full N×N scores matrix to slow HBM and reads it back multiple times. The reads and writes — not the math — were the bottleneck; attention was memory-bound.

SRAM vs HBM?

HBM is large but slow main memory; SRAM is tiny but ~10x faster on-chip memory. FlashAttention does as much as possible in SRAM and touches HBM as little as possible.

Is it exact or approximate?

Exact — it computes the identical result as standard attention, just with a smarter memory schedule. No accuracy is lost.

How does it enable long context?

By never storing the full scores matrix, its memory grows linearly (not quadratically) with sequence length, making much longer context windows practical.

FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness · Dao, Fu, Ermon, Rudra, Ré · NeurIPS 2022 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 30 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns