What does FlashAttention actually do, and how is it different from PagedAttention?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
They solve different problems at different layers, and you use them together rather than choosing between them.
Full worked answer with diagram
They solve different problems at different layers, and you use them together rather than choosing between them.
FlashAttention is a kernel. It is an exact, IO-aware implementation of attention. Instead of materialising the full n x n score matrix in HBM, it tiles Q, K and V into on-chip SRAM and computes the softmax in a streaming pass, keeping a running max and running sum. Extra memory drops from O(n^2) to O(n), and HBM reads and writes fall by a large constant factor because the score matrix never leaves SRAM (the FLOPs are still quadratic), which is what makes long contexts tractable. It is exact, not an approximation: outputs match naive attention up to floating point. It wins most on prefill and long context, where the score matrix is large. Decode has a query length of 1, so there is almost no parallelism along the query axis, which is why decode-oriented variants split along the KV length and combine partial softmaxes afterwards.
PagedAttention is memory management. Store the KV cache in fixed-size blocks (16 tokens is the common default) indexed through a per-sequence block table, so a sequence's KV does not need to be contiguous. That kills the fragmentation you get from pre-allocating max-length buffers, so the same HBM supports a much larger batch, and prefix sharing becomes a block-table pointer instead of a copy. The attention kernel then has to gather KV through the block table.
So: FlashAttention makes the attention computation cheap in memory traffic; PagedAttention makes the KV cache cheap in memory capacity. A modern server runs FlashAttention-style kernels over a paged KV layout, and picking an "attention backend" is picking which such kernel you get.
Red flag phrasing: "we use PagedAttention instead of FlashAttention." Also worth saying: neither one changes output quality.
Worth sketching. Two boxes stacked as layers kill the "one instead of the other" misconception in a single stroke.
flowchart TD
A["Attention for one step"] --> K["Kernel layer: FlashAttention tiles<br/>Q, K, V through SRAM"]
K -->|"extra memory drops from O(n squared) to O(n)"| R["Exact output, no approximation"]
K --> B["Gathers KV through a block table"]
B --> M["Memory layer: PagedAttention,<br/>fixed 16-token blocks"]
M --> POOL["Shared pool: no fragmentation,<br/>prefix sharing by pointer"]
What a good answer covers
- They solve different problems at different layers, and you use them together rather than choosing…
- It is an exact, IO-aware implementation of attention
- Instead of materialising the full n x n score matrix in HBM, it tiles Q, K and V into on-chip SRAM and…
- Extra memory drops from O(n^2) to O(n), and HBM reads and writes fall by a large constant factor because…
- It is exact, not an approximation: outputs match naive attention up to floating point
Key terms: FlashAttention is a kernel · PagedAttention is memory management
In the glossary: FlashAttention · HBM · Prefill · Decode · PagedAttention · KV cache
Interviewer follow-ups to expect
Why does decode need a differently shaped kernel than prefill?
What does changing the attention backend actually change for you operationally?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep