Drag each answer to line up with its matching prompt
Sliding window
Each token attends to W nearby tokens, local context only. Used in Mistral 7B (window=4096).
Dilated attention
Tokens grouped into blocks; intra block dense + cross-block sparse. Used in some GPT-3 ablations.
Global + local (BigBird style)
Skip-N pattern, attend to every Nth token over medium range. Used in Longformer.
Block sparse
Most tokens attend locally; a few designated 'global' tokens see and are seen by everyone, enabling long range info flow.
Sparse attention patterns differ in which slice of the n × n grid they compute: diagonal band, strided band, band plus VIP tokens, or block structured.
Picture a huge grid asking, for each word, which other words it should look at. The standard kernel fills the whole grid. Sparse attention keeps most of the grid blank to save effort, and different designs pick different shapes to keep. A narrow band along the diagonal lets each word peek at nearby neighbors only, like reading with a small window. A strided band skips some neighbors but reaches further. A band plus a few full rows treats a handful of words as VIP guests everyone gets to talk to. Chunked patterns slice the sequence into groups and only check inside each group plus a few cross-links. Same idea everywhere, different geometry.
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.
Sparse attention is a family of structured masks on the n × n score matrix. The structure is chosen so the kernel computes only a subset of the entries, dropping the asymptotic cost while keeping enough connectivity for the model to remain expressive at sequence lengths dense attention cannot afford.
The four families split by the geometry of the mask. A diagonal band gives sliding window. A strided band gives dilated. A band plus a few full rows and columns gives the global plus local pattern. Chunks with sparse cross-chunk links give block sparse. The sections below walk each family along with its canonical exemplar architecture, distinguish sparse exact patterns from kernel approximations, then place the whole family inside the modern long context stack.
Sliding window: the diagonal band
Sliding window attention lets each query see W keys around it, producing a banded mask. Per-layer compute is O(n · W), linear in n, and the kernel is hardware-friendly because the band aligns with contiguous memory access.
Information propagates L · W tokens across L stacked layers; with Mistral 7B's W = 4096 and 32 layers, the theoretical reach is 131k positions. The catch is fidelity: information squeezes through intermediate tokens' residual streams at each hop, so distant relationships are weakly represented even when reach in principle is sufficient.
Mistral 7B with W = 4096 is the canonical modern decoder example, and the pattern continues in Mistral Large 3. Longformer uses sliding window as the local component of its heads, alongside dilated and global heads.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Pattern | Geometry | Single layer reach | Exemplar |
|---|---|---|---|
| Sliding window | Diagonal band, width W | W tokens | Mistral 7B (W=4096) |
| Dilated | Strided band | W × stride | Longformer dilated heads |
| Global + local | Band + a few full rows/cols | Effectively n (via globals) | BigBird, Longformer |
| Block sparse | Dense blocks + sparse cross-block | n via cross-block pattern | Sparse Transformer, GPT-3 ablations |
Real products, models, and research that use this idea.
- Mistral Large 3 and the wider Mistral lineage continue to use sliding window attention (W around 4096) as a structural choice through 2026.
- Longformer combines sliding window local plus dilated heads plus global tokens for documents up to 4096 tokens.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does BigBird need global tokens in addition to sliding window?
Pure sliding window attention can only propagate information across L × W tokens in L layers. For a 4096-token document with W=512 and L=12 layers, that's 6144, covered. For longer or more globally interactive tasks, you need a shortcut. Global tokens provide that: any local token reaches any other in 2 hops through a global one, regardless of distance.
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.
Conflating 'sparse attention' with 'efficient attention', sparse attention is one family (approximate, fewer pairs computed); FlashAttention is exact (same pairs, different I/O). They're different layers of the stack.
60 second bullets to scan on the way to the call.
Geometry of each pattern: band, strided band, band with globals, blocks
Exemplar architectures: Mistral sliding window, Longformer, BigBird, Sparse Transformer
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.