Walk through what FlashAttention does differently from standard attention, and what changes between v1, v2, and v3.
Walk through the FlashAttention algorithm: what does it change vs standard attention, why does that change matter for GPU performance, and what evolves between v1, v2, and v3?
FlashAttention keeps the n×n matrix out of HBM by tiling Q/K/V into SRAM and using online softmax. v1 introduced tiling, v2 added sequence dim parallelism, v3 went Hopper async + FP8. Same math, 2-4x faster.
Standard attention is like solving a huge crossword by repeatedly carrying the whole grid back and forth between your desk and a shelf across the room. FlashAttention does it section by section at your desk and never brings the whole grid out, so you get exactly the same answers without wasting time on the walking. The desk space is small but the trip to the shelf is the slow part, and the section by section trick avoids it almost entirely. Each new version (v2, v3) is a smarter way of organizing the same trick to fit the latest desks (GPUs).
Detailed answer & concept explanation~6 min readEverything 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. 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.
Walk the HBM-bandwidth problem, the tiling and online softmax mechanics, the forward/backward asymmetry (save m,l + recompute on backward), then trace v1 to v2 (seq dim parallelism, fewer non-matmul FLOPs) and v2 to v3 (TMA, warpgroup MMA, FP8 on Hopper). Emphasize math equivalence throughout.
| Aspect | Standard attention | FlashAttention v1 | FlashAttention-v2 | FlashAttention v3 |
|---|---|---|---|---|
| Year | 2017 | 2022 | 2023 | 2024 |
| Materializes n×n in HBM? | Yes | No | No | No |
| Memory complexity | O(n²) | O(n) | O(n) | O(n) |
| Parallelism | Batch × heads | Batch × heads | Batch × heads × seq | Batch × heads × seq + async |
| Target hardware | Any | Ampere+ | Ampere+ | Hopper (H100) |
| Precision | FP16/BF16 | FP16/BF16 | FP16/BF16 | FP16/BF16/FP8 |
Real products, models, and research that use this idea.
- PyTorch's torch.nn.functional.scaled_dot_product_attention dispatches to FlashAttention-v2 kernels on supported GPUs by default.
- vLLM and TensorRT-LLM both use FlashAttention style kernels in their decode path, often combined with PagedAttention for KV cache.
- Training a 7B model at 32k context on A100s is only practical with FlashAttention, naive attention would OOM on the activation memory.
- H100 deployments at major labs use FlashAttention-v3 with FP8 for substantial training speedup.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the backward pass avoid storing the n×n attention matrix?
QWhat was the specific SM-utilization problem v2 fixed?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating FlashAttention as an approximation, or attributing the speedup to a faster matmul kernel rather than to eliminating HBM round trips.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.