Why is causal attention cheaper than full bidirectional at the same length?
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.
Detailed answer & concept explanation~8 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.
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.
- FlashAttention-2 (Dao 2023): introduced causal-aware tile scheduling; the `is_causal=True` flag activates the upper-triangle skip.
- FlashAttention-3 (Shah et al. 2024): brings the same optimization plus warp-specialization to H100 GPUs.
- Llama 4 Maverick and Mistral Large 2 serving via vLLM with FlashAttention-3: benchmark roughly 2x faster per-token throughput on the attention kernel versus bidirectional at the same length.
- PyTorch's `F.scaled_dot_product_attention(..., is_causal=True)`: dispatches to the causal-aware FlashAttention path when available.
- PagedAttention in vLLM: KV pages for future positions are never allocated, so the kernel does not even iterate over them, a related but distinct optimization.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf causal attention is 2x faster on the attention kernel, why is end to end transformer block throughput only 1.3-1.5x faster instead of 2x?
QHow does sliding-window causal attention (Mistral 7B) change the FlashAttention tile skip pattern?
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.
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.
Same topic, related formats. Practice these next.