Where does FlashAttention deliver the biggest serving speedup?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
FlashAttention's biggest win is long-context prefill, where avoiding HBM materialization of the n×n score matrix saves quadratic memory traffic.
Imagine grading every pair of students in a class by comparing their answers. The slow way writes every comparison into a giant grid on paper first, then adds up each row. With a big class that grid is enormous, and shuffling it on and off your desk is the real time sink. FlashAttention skips the giant grid. It walks through students in small groups, keeps a running tally on a sticky note, and never writes the full grid down. The answer is identical, but you barely touch the desk drawer. The bigger the class, the more drawer trips you save. A long prompt is a big class processed all at once, so that is exactly where skipping the grid helps most.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: attention is memory bound, naive kernel materializes the n×n matrix, tiling plus online softmax in SRAM, exact not approximate, prefill is the big win and decode is not.
| Aspect | Naive attention | FlashAttention |
|---|---|---|
| n×n score matrix in HBM | Materialized, read and written multiple times | Never materialized; tiled in SRAM |
| HBM traffic vs sequence length | Quadratic in n | Roughly linear in n |
| Numerical result | Exact | Exact, identical output |
| Biggest speedup regime | Baseline | Long-context prefill |
| Batch-1 decode benefit | Baseline | Small; no quadratic term to remove |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Claiming FlashAttention is an approximation or that it speeds up batch-1 decode most. It is exact, and its quadratic saving is largest during long-context prefill, not single-row decode.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.