Identify the attention-pattern difference between Mistral 7B and Llama-2 7B
Mistral 7B uses sliding-window attention with a 4k window over 32k context; Llama-2 7B uses full causal attention over 4k. Same parameter count, different attention pattern.
Imagine two researchers asked to find connections in a thousand-page book. The first researcher reads page N by glancing at every page before it, a slow read but every page sees every prior page. The second researcher reads page N by glancing only at the last 100 pages, but does this many times in stacked passes; by the final pass, information from page 1 has hopped through enough intermediate pages to reach page N. The first researcher is Llama-2 7B with full attention; the second is Mistral 7B with sliding-window attention.
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.
5m: the full vs sliding-window pattern split, Mistral's 4k window inside 32k context, depth-stacking to grow effective receptive field, what GQA and RoPE do and don't change, and where sliding-window costs you on long-range lookup.
| Property | Llama-2 7B | Mistral 7B |
|---|---|---|
| Attention pattern | Full causal | Sliding window (4096) |
| Context length | 4096 | 32768 |
| KV head structure | MHA (32 query, 32 KV) | GQA (32 query, 8 KV) |
| Positional encoding | RoPE | RoPE |
| Per-token attention cost | O(seq) | O(window) |
| Per-layer receptive field | Full prior context | 4096 nearest tokens |
| Effective receptive field | Same as per-layer | L * window via stacking |
Real products, models, and research that use this idea.
- Mistral 7B's release blog explicitly documents the 4096-token sliding window inside a 32768 total context.
- Llama-2 7B's release paper specifies 4k full causal attention and standard MHA.
- FlashAttention 2 added efficient sliding-window kernels that Mistral 7B inference relies on.
- vLLM and llama.cpp both support sliding-window attention via attention mask flags when serving Mistral models.
- Later Mistral models (Mistral Large 3) moved to a hybrid of sliding-window and full attention layers to get the best of both.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does sliding-window attention interact with the KV cache at long context?
QWhy did Mistral Large 3 move to a hybrid full and sliding-window layer pattern?
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.
Naming MQA, GQA, or RoPE as the headline difference. Mistral 7B and Llama-2 7B differ in attention PATTERN (full vs sliding window), not in head sharing or positional encoding.
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.