← Back to LLMs Mind Map
中文·English
⚡ LLMsID: flashattention

FlashAttention

🎯Core Definition
FlashAttention is an IO-aware exact attention implementation: it tiles QKTQ K^T into SRAM, uses online softmax with running max mim_i and normalization factor lil_i (recursively rescaled when merging blocks: mnew=max(m,mlocal)m_{new} = max(m, m_{local})), never writes the O(n2)O(n^2) attention matrix back to HBM in the forward pass, and recomputes rather than stores in the backward pass; the motivation is the ~10-20x bandwidth gap between HBM and SRAM (A100: 40GB HBM vs ~108KB SRAM).
💡Use Cases
the de-facto attention implementation for LLM training and inference (PyTorch SDPA, NVIDIA FA2/FA3, DeepSeek/Meta stacks); gains grow with sequence length, and long-context training essentially requires it.
⚡Key Problems Solved
standard implementations shuttle the attention matrix between HBM and SRAM repeatedly, making IO the bottleneck; tiling + recomputation cuts HBM traffic from O(n2d)O(n^2 d) to O(n2d2M)O(\frac{n^2 d^2}{M}) (MM = SRAM size), giving 2-4x speedup and O(n)O(n) memory instead of O(n2)O(n^2), with results bit-identical to standard softmax (not an approximation).
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of FlashAttention.
Use Cases
In production engineering, what are the primary use cases for FlashAttention and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Why is attention memory-bound? The bandwidth/capacity gap between HBM and SRAM?
2
How does online softmax merge block statistics (recursive formulas for running max m and normalizer l)?
3
Why recompute in the backward pass instead of storing? Memory from O(n2)O(n^2) to what?
4
What did FlashAttention-2 improve over v1 (dropping intermediate matrices, fewer non-matmul ops, ~2x)?
5
Why is FlashAttention exact? Essential difference from sparse/low-rank attention?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "FlashAttention"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice ➔
← Previous CardPre-LN & RMSNormNext Card →Supervised Fine-Tuning (SFT)

🔗 More LLMs Knowledge Cards

Agent & Tool CallingAlignment Tax & Preference DataScaled Dot-Product AttentionAttention Variants MHA/MQA/GQA