Sliding-window attention can't see beyond the window. Describe the trick that recovers older context.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Sliding-window attention (used in Mistral, Longformer, etc.) restricts each token to attending only to the previous W tokens. Naively this seems to throw away anything older than W positions back. Describe the architectural property that lets information from older tokens still reach the current position, and explain how the effective receptive field scales.
Layer stacking. Each layer adds W tokens of reach; after L layers the effective receptive field is roughly W * L. Mistral-7B's 4k window over 32 layers gives ~131k token reach.
Picture a line of telephone-game players where each player can only whisper to the four people immediately in front of them. A message from the back of the line cannot reach the front in one hop, but as the line passes the message forward four people at a time, it eventually arrives at the front. The total distance the message can travel is four people per hop times however many hops there are. Sliding-window attention works the same way: each layer is one hop, the window size is how many tokens you can reach per hop, and the depth of the transformer is how many hops the message gets.
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.
Explain that per-layer window W combines with depth L through the residual stream to give a receptive field of roughly W * L, run the Mistral 7B numbers (4096 * 32 = 131k), note the bandwidth-bottleneck caveat, and contrast with full attention and hybrid long-context architectures.
| Attention pattern | Per-layer cost | Per-layer reach | Effective receptive field |
|---|---|---|---|
| Full attention | O(T^2 * d_k) | T (everything) | T, direct in one hop |
| Sliding window | O(W * T * d_k) | W tokens back | ≈ W * L via depth-hops |
| SSM / Mamba | O(T * d_state) | Recurrent, all of history compressed | Bounded by d_state bandwidth |
| Hybrid (sliding + periodic full) | Mostly O(W * T) + sparse O(T^2) | W per layer, plus full-attention layers | ≈ W * L with one-hop long edges at full-attn layers |
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.
Assuming sliding-window models cannot see past W tokens. The per-layer window is W; the cross-layer receptive field is L * W via stacking.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.