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. Llama-2 swapped four specific components for empirically better versions while keeping the architectural core unchanged.
The pattern matters because it shows what kind of progress was happening. It was not a new attention mechanism or a fundamental rethink. It was careful incremental swaps, each justified by an ablation study.
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
There are two failure modes. First, you have no PE vector for positions beyond training-time max_len (hard cap on context length). Second, 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:
The rotation acts on even-odd pairs of the Q and K dimensions. It has the property that q_m · k_n factors through (m - n). This gives the attention dot product a built-in relative-position property without a learnable table.
Benefits
RoPE has no learnable PE parameters and no hard cap on context (rotations are well-defined at any m). The dot product depends directly on relative position. 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, and GQA with 8 KV heads.
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 Llama 2 ablations compared MHA, MQA, and GQA with 8 KV heads: GQA-8 stayed close to MHA quality, while MQA (1 KV head, the largest possible saving at 64x) lost more. 8 KV heads give an 8x KV cache reduction relative to 64. The GQA paper swept the number of groups and found that 8 groups add little decode cost over MQA. The decision is empirical, anchored to 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.