Match GPT-2 versus Llama-2 attention design choices to their differences
GPT-2 to Llama-2: PE moved to RoPE, LayerNorm became RMSNorm, GELU became SwiGLU, 70B added GQA. The softmax(QK^T/sqrt(d_k))V core stayed identical.
Think of two cars from the same family. The 2019 sedan and the 2023 sedan look similar, but the newer one has a smarter steering system, lighter suspension, and a more efficient engine that runs on the same fuel. The seats, the steering wheel, the brakes work the same way. GPT-2 and Llama-2 are like that pair. The core engine, scaled dot-product attention, is unchanged. Around it, every component got swapped for a quieter, faster, or cheaper version: rotary position info instead of added embeddings, simpler normalization, a gated activation, and KV sharing at scale.
Detailed answer & concept explanation~7 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.
60s: name the four changes (PE: learned absolute → RoPE, norm: LayerNorm → RMSNorm, activation: GELU → SwiGLU, KV sharing: MHA → GQA at 70B), state the attention math is identical, mention which Llama-2 sizes use GQA, give the rough motivation per change (long context, parameter efficiency, perplexity-per-FLOP, KV cache memory).
| Component | GPT-2 (2019) | Llama-2 (2023) |
|---|---|---|
| Positional encoding | Learned absolute PE at input | RoPE applied to Q, K inside attention |
| Normalization | LayerNorm (mean + variance, with bias) | RMSNorm (variance only, no bias) |
| FFN activation | GELU | SwiGLU (gated, three weight matrices) |
| KV-head sharing (70B) | MHA (one KV per query head) | GQA (64 query, 8 KV) |
| Attention math core | softmax(QK^T/sqrt(d_k)) V | softmax(QK^T/sqrt(d_k)) V (identical) |
Real products, models, and research that use this idea.
- Llama-2 70B uses GQA with 64 query heads grouped onto 8 KV heads; the 7B and 13B variants keep plain MHA.
- Mistral 7B and Mixtral 8x7B inherited Llama-2's stack: RoPE, RMSNorm, SwiGLU, GQA on the larger variants.
- Qwen 3.5 and DeepSeek V4 retain RoPE plus RMSNorm plus SwiGLU but moved past GQA to MLA (DeepSeek) or extended GQA configurations.
- GPT-2's learned absolute PE became the canonical 'don't do this for long context' example after RoPE-based models started shipping 32k+ contexts.
- Llama 4 Maverick and Gemma 4 continue the Llama-2 architectural lineage: RoPE, RMSNorm, SwiGLU, GQA-style sharing at the larger sizes.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does Llama-2 70B specifically pick GQA with 8 KV heads, not 4 or 16?
QWhy didn't Llama-2 also adopt sliding window attention or some sparse 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.
Assuming Llama-2 changed the attention math itself. The core softmax(QK^T/sqrt(d_k))V is identical to GPT-2; what moved is the surrounding engineering, PE, normalization, FFN, head sharing.
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.