Explain effective context for Mistral's 4096 sliding window over a 16k input
Mistral 7B uses sliding window attention with a window of 4096 tokens. The model is fed a 16k-token input. What does the phrase 'effective context' mean for this configuration, and why is it larger than 4096?
Per-layer reach is 4096; cross-layer receptive field is L * 4096. For Mistral 7B (32 layers) that is 131k tokens, larger than the 16k input, so every position can influence the last token.
Picture a row of librarians, each only able to read books from the four shelves in front of them. The librarian at the far right cannot directly read books from the far left of the room. But if the librarian at position 5 writes a one-page summary of what she sees, and the librarian at position 9 reads that summary as part of her own shelf range, the signal hops forward. Stack enough librarians in a line and the rightmost one can hear about books from the very left of the room, even though no single librarian ever saw more than four shelves at once.
Detailed answer & concept explanation~6 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.
Distinguish per-layer window W from cross-layer receptive field W * L, compute Mistral 7B's 131k bound, explain how the residual stream carries depth-hops, contrast cost with full attention, and flag the theoretical-vs-effective gap that motivates hybrid architectures.
Real products, models, and research that use this idea.
- Mistral 7B and Mixtral: W = 4096 across 32 layers; theoretical receptive field ≈ 131k tokens over 8k pretraining context.
- Longformer (Beltagy et al. 2020): pioneered sliding-window with W = 512 plus global tokens for document-scale tasks.
- Gemini 3.1 Pro: hybrid stack interleaving sliding-window with periodic full-attention layers for million-token contexts.
- Jamba (AI21 2024): alternates Mamba SSM layers with sliding-window attention for long-context efficiency.
- Llama 3 and Llama 4 deliberately avoid sliding-window in favor of full attention with longer pretraining contexts, trading compute for one-hop routing.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does Mistral 7B's effective long-context performance degrade past ~20-30k tokens despite the theoretical 131k receptive field?
QHow does Mistral's sliding-window interact with its rolling KV cache, and what changes for serving compared to full attention?
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.
Treating 4096 as the model's maximum context. That is the per-layer window; the receptive field across 32 layers is 131k tokens.
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.