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.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
The fact that causal attention is faster than bidirectional at the same sequence length surprises people. The matrices are the same size; the softmax is the same operation; the value matmul has the same dimensions. The savings live in one place: FlashAttention's tile scheduler skips entire blocks of the score matrix that the causal mask would zero out anyway. This is a hardware-aware optimization that naive implementations miss entirely and that FlashAttention has made the production default since 2023.
This deep dive walks the tile scheduling mechanism in detail, quantifies the speedup, contrasts FlashAttention with naive masked attention, surveys the related optimizations (sliding window, PagedAttention, GQA), and ends with the end to end implications for transformer serving in 2026.
FlashAttention's tile-based processing
Standard attention materializes the full score matrix in high-bandwidth memory:
- Compute
S = Q K^Tof shape(T, T). - Apply mask if causal.
- Apply softmax row-wise.
- Compute
O = A V.
For T = 16,384, the score matrix alone is 2 GB at FP32 (1 GB at FP16). HBM bandwidth becomes the bottleneck.
FlashAttention's insight
Process the score matrix in tiles that fit in SRAM (on-chip cache). For a tile size ts of 64-128, divide both Q and K, V into row blocks of ts. For each output row block, iterate over all key column blocks, computing the partial softmax + value contribution online without materializing the full row.
The key algorithmic trick is the online softmax: maintain a running max and running sum so the partial softmax over each tile composes correctly into the full-row softmax. This is what enables tile by tile processing without losing softmax correctness.
What this gives you
Memory: peak SRAM usage is O(ts^2) instead of O(T^2). For ts = 128 and T = 16,384, that is 16K vs 268M entries, a 16,000x reduction.
Time: the matmul total FLOPs are unchanged, but HBM traffic drops dramatically. Attention becomes compute-bound instead of memory-bound, which on modern GPUs means it actually runs faster.
What changes with the causal mask
The causal mask blocks all entries S[i, j] where j > i. FlashAttention's tile scheduler can inspect tile coordinates and decide which tiles to skip entirely. This is where the causal speedup lives.
FlashAttention is the algorithm. Causal-aware tile skipping is the special case that makes causal attention fast.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| 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.
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?
The transformer block also contains the FFN, which is unchanged between causal and bidirectional and is typically 2-3x more compute than attention. So the attention 2x speedup amortizes against a fixed FFN cost. The end to end speedup is bounded by Amdahl's law on the attention/FFN ratio.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases 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.
60 second bullets to scan on the way to the call.
FlashAttention's tile-based processing of the score matrix
Three tile categories: below, straddling, above the diagonal
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.