Explain sliding-window attention and hybrid local/global stacks. What do you gain and what do you give up?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Sliding-window attention restricts each token to the last w tokens instead of the whole prefix. Time goes from O(n^2) to O(n*w), and more importantly the KV cache for those layers is capped at w entries rather than growing with n. Mistral 7B popularised it with a 4096 window; Gemma 2 and 3 interleave it with full-attention layers.
Full worked answer with diagram
Sliding-window attention restricts each token to the last w tokens instead of the whole prefix. Time goes from O(n^2) to O(n*w), and more importantly the KV cache for those layers is capped at w entries rather than growing with n. Mistral 7B popularised it with a 4096 window; Gemma 2 and 3 interleave it with full-attention layers.
The point candidates usually miss: a stack of windowed layers is not as myopic as it sounds, because the receptive field compounds with depth exactly like a CNN. With window w and L layers, information can in principle travel ~L*w positions. But propagation through many hops is lossy and diffuse, and any single-hop exact retrieval, quoting a string sitting further than w back, simply cannot happen in a local layer.
Hence the modern pattern: hybrid stacks. Interleave mostly local layers with occasional full-attention layers, for example Gemma 3's 5:1 local-to-global ratio with 1024-token windows. The global layers do exact long-range retrieval; local layers do the cheap bulk of the work. Published ablations show minimal perplexity cost, and the KV savings at 128k are large because only 1 layer in 6 has a cache that scales with n.
What you give up and what to watch:
- Effective retrieval context is governed by the global layers, not by the advertised window. The ratio is a real quality knob, not free.
- The remaining full-attention layers become the memory bottleneck, which is why teams stack further tricks on exactly those layers: cross-layer KV sharing, MLA, cache quantization.
- Prefix caching and cache reuse get fiddlier when layers have heterogeneous cache semantics.
- Mask bugs in local layers are silent at short context and only surface at long context, so your test suite needs long cases or you will ship it.
Compared to a learned sparse pattern, sliding windows hard-code the assumption that relevance is local. That is a good prior for prose and a poor one for code with distant definitions, which is part of why learned sparsity has moved from research into shipped models: DeepSeek-V3.2's sparse attention uses a lightweight indexer to score prior positions and lets each query attend only to the top-scoring ones.
Worth sketching. Drawing the 5:1 block shows exactly which layers still carry a cache that grows with context.
flowchart LR
IN["tokens"] --> L1["local layer, window 1024<br/>cache capped at w"]
L1 --> L2["five local layers in a row"]
L2 --> G["one full-attention layer<br/>cache grows with n"]
G --> OUT["repeat the block"]
L2 --> RF["receptive field compounds to ~ L x w,<br/>but multi-hop propagation is lossy"]
G --> EX["exact long-range retrieval<br/>can only happen here"]
What a good answer covers
- Sliding-window attention restricts each token to the last w tokens instead of the whole prefix
- Time goes from O(n^2) to O(nw), and more importantly the KV cache for those layers is capped at w…
- Mistral 7B popularised it with a 4096 window; Gemma 2 and 3 interleave it with full-attention layers
- With window w and L layers, information can in principle travel ~Lw positions
- But propagation through many hops is lossy and diffuse, and any single-hop exact retrieval, quoting a…
In the glossary: Attention · KV cache · MLA · Quantization · Prefix caching
Interviewer follow-ups to expect
How would you choose the local-to-global ratio for a code model versus a chat model?
What does sliding-window attention do to prefix caching in a multi-turn agent?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep