Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
FlashAttention skips entire blocks above the causal diagonal because they would softmax to zero, roughly half the work compared to bidirectional, where every block must be computed.
Picture filling out a square grid of homework problems. Bidirectional attention is doing every single problem in the grid. Causal attention has a rule: any problem above the diagonal is just zero, do not write anything. A clever student skips those squares entirely instead of writing zero in each one. FlashAttention is that clever student, it inspects the grid tile by tile, sees which tiles are entirely above the diagonal, and skips them without doing the math. Since roughly half the grid is above the diagonal, the clever student does half the work for the same result.
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.
FlashAttention processes the score matrix in tiles and skips tiles entirely above the causal diagonal. Roughly half the tiles fall above, giving ~2x kernel speedup over bidirectional at the same length. Q, K, V shapes are identical; the savings are in tile scheduling, not matrix shape.
| Aspect | Bidirectional | Causal (with FlashAttention) |
|---|---|---|
| Q, K, V shapes | (T, d_model) | (T, d_model) |
| Score matrix tiles computed | All (T/ts)^2 | Roughly half (lower triangle + diagonal) |
| Softmax | Row-wise on full row | Row-wise on causal prefix |
| Relative kernel cost | 1x baseline | ~0.5x |
| Skip mechanism | None | FlashAttention tile scheduler |
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.
Believing causal attention is cheaper because the matrices are smaller. The Q, K, V shapes are identical; the savings come from skipping blocked-out blocks of the score matrix.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.