Match GPT-2 versus Llama-2 attention design choices to their differences
Drag each answer to line up with its matching prompt
Positional encoding
Both use the same scaled dot product attention, softmax(QK^T / sqrt(d_k)) V
Normalization layer
GPT-2 uses GELU vs Llama-2 uses SwiGLU
KV-head sharing (70B scale)
GPT-2 learned absolute PE added at input vs Llama-2 RoPE applied inside attention
Activation in FFN block
GPT-2 plain multi-head attention vs Llama-2 70B grouped query attention (8 KV heads)
Attention math core
GPT-2 uses LayerNorm (mean + variance) vs Llama-2 uses RMSNorm (variance only, no bias)
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.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
GPT-2 (2019) and Llama-2 (2023) are decoder-only transformers with the same overall shape: alternating attention and FFN blocks, residual stream, learned token embeddings, standard scaled dot-product attention. The four-year gap between them was filled with engineering work, and Llama-2 swapped four specific components for empirically-better versions while keeping the architectural core unchanged.
The pattern matters because it tells you what kind of progress was happening: not a new attention mechanism, not a fundamental rethink, but careful incremental swaps each justified by an ablation study. This deep dive walks each of the four changes, explains why each one was the right move at the time, names where each component sits in the modern stack, and ends with the components Llama-2 itself retained that the next generation (MoE, MLA) now abandons.
Positional encoding: learned absolute → RoPE
GPT-2's PE is a learned (max_len, d_model) table added to token embeddings at the input. Each position 0 through max_len gets its own learned vector. The position information enters once at the input layer and the model has to propagate it through every transformer block.
Where the design breaks
Two failure modes: at training-time max_len you have no PE vector for positions beyond it (hard cap on context length), and even within the window the absolute formulation does not naturally encode the (m - n) shifts that attention scores want.
What RoPE does
RoPE rotates Q and K vectors by position-dependent angles before the attention dot product. The rotation angle at position m is:
Applied to even-odd pairs of the Q and K dimensions, the rotation has the property that q_m · k_n factors through (m - n), giving the attention dot product a built-in relative-position property without a learnable table.
Why this matters
No learnable PE parameters. No hard cap on context (rotations are well-defined at any m). Direct relative-position dependence in the dot product. Long-context extension techniques (RoPE base scaling, NTK-aware, YaRN, LongRoPE) all build on this foundation; a learned absolute PE has no analogous extension story.
Every modern open-weight LLM (Llama 4 Maverick, Qwen 3.5, Mistral Large 3, DeepSeek V4) inherits RoPE. The learned-absolute design did not survive the long-context era.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| 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.
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?
Meta's GQA ablations swept group sizes and found 8 KV heads landed in the sweet spot: 8x KV cache reduction relative to 64 (the largest possible saving), with negligible quality loss versus MHA. Smaller (4 KV) gave more savings but the perplexity hit started showing; larger (16 KV) saved less without quality benefit. The decision is empirical, anchored to specific ablation numbers, not derived from theory.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases 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.
60 second bullets to scan on the way to the call.
The four components that changed between GPT-2 and Llama-2
Why RoPE replaced learned absolute PE
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.