Exercises — GPT family architecture evolution
Every symbol used below is defined right where it first appears, so you never need to jump back to the parent to follow a step.
Level 1 — Recognition
These check that you can name the right fact. No arithmetic.
L1.1
GPT is built from the 2017 Transformer, which had two towers: an encoder (reads the whole input at once) and a decoder (generates output one token at a time). Which tower did GPT keep, and which single mechanism inside it makes GPT "autoregressive"?
Recall Solution
GPT keeps only the decoder, and drops the encoder entirely (so there is no cross-attention). The mechanism that makes it autoregressive is the causal mask: a rule that forbids each token from looking at any token to its right (the future). "Autoregressive" simply means predict the next item using only the items before it — the mask is what enforces "only before it".
L1.2
Match each model to its defining first contribution: (a) GPT-1 (b) GPT-2 (c) GPT-3 (d) GPT-3.5 / InstructGPT
- In-context / few-shot learning emerges from scale
- Generative pretraining + supervised fine-tuning
- RLHF (alignment), not an architecture change
- Zero-shot task transfer; moved LayerNorm to pre-LN
Recall Solution
- (a) → 2: GPT-1 introduced generative pretraining then supervised fine-tuning per task.
- (b) → 4: GPT-2 showed zero-shot transfer and switched to pre-LN (LayerNorm placed before each sublayer).
- (c) → 1: GPT-3's headline was few-shot in-context learning emerging purely from scale.
- (d) → 3: GPT-3.5 / InstructGPT added RLHF, an alignment change on the same backbone. See RLHF and InstructGPT.
L1.3
"Pre-LN" vs "Post-LN". In one sentence each, say where the LayerNorm sits and why GPT-2 switched.
Recall Solution
LayerNorm (LN) rescales a vector so its entries have mean 0 and variance 1 — it stabilizes the numbers flowing through the network.
- Post-LN (GPT-1): LN is applied after adding the sublayer output back into the residual stream.
- Pre-LN (GPT-2+): LN is applied before the sublayer, so the residual "highway" stays un-normalized. Switch reason: the un-normalized highway lets gradients flow cleanly through 48–96 stacked layers without exploding or vanishing.
Level 2 — Application
Now plug numbers into the formulas the parent built.
L2.1 — Cross-entropy of a single prediction
The training loss for next-token prediction is the negative log-likelihood where is the probability the model assigns to the correct next token. (Recall from the notation note: , base , so the unit is the nat.) If the model gives the true token probability , what is the loss? What if it were a perfect ?
Recall Solution
Loss at : nats. Loss at : nats. Reading it: loss means the model was certain and correct. The lower the probability it puts on the truth, the bigger the penalty — and it blows up toward as . This is exactly the Cross-entropy loss penalizing confident wrong-ness.
The figure below plots this loss curve against the probability the model assigns to the true token. Follow the yellow curve: it is flat and near 0 on the right (confident and correct, blue dot at ) and rockets upward on the left (the pink dot at sits at loss , and the curve keeps climbing toward as ). The steep left tail is the visual meaning of "confident wrongness is punished hard".

L2.2 — Attention parameter count
One attention layer with model dimension (the length of each token's vector) has four square weight matrices , each of size . A matrix of shape has numbers. How many attention parameters per layer? Evaluate for GPT-3 ().
Recall Solution
Four matrices parameters. For : . So just the attention projections of one layer already hold ~0.6 billion parameters. Because it grows as , doubling width quadruples this cost — that quadratic is why 175B is reached so quickly.
L2.3 — The scaling
An attention score is a dot product between a query vector and a key vector , each of length . If each entry is independent with mean 0 and variance 1, the variance of the sum equals . With , what is the standard deviation of the raw score, and what does dividing by do to it?
Recall Solution
Variance , so standard deviation . After dividing by : new variance , standard deviation . Why we do this: softmax turns scores into probabilities. If scores swing by or more, softmax saturates (one weight , the rest ) and its gradient nearly vanishes. Rescaling to variance 1 keeps softmax in its responsive region so learning continues.
Level 3 — Analysis
Explain why, not just what.
L3.1 — Why strictly upper-triangular mask?
The causal mask adds to forbidden score positions so that after softmax those attention weights become exactly 0. Write the exact rule for (token attending to token ), and explain what breaks if we allowed .
Recall Solution
Rule: if (token may attend to itself and everything before it), and if (the future is blocked). The blocked region is the strict upper triangle (). If we allowed token to see token , then while predicting token the model could peek at the very answer it is supposed to guess. Training loss would collapse toward 0 by copying, and no real language ability would be learned. The strictness (, not ) is essential.
The figure below draws the mask as a grid: rows are query positions (the token doing the predicting), columns are key positions (the token being looked at). Blue cells (value ) are allowed — they form a lower-triangular staircase where . Pink cells (value ) are blocked — they form the strict upper triangle , the "future" a token must never peek at. Reading any row left to right shows exactly how far into the past that token may attend.

L3.2 — Why a power law, not an exponential?
The Kaplan scaling law says test loss falls as where is the parameter count and a constant. Why does plotting against reveal whether the relationship is a power law?
Recall Solution
Take (natural log) of both sides: . This is a straight line in the variables with slope . A power law is the function whose log-log graph is a straight line. An exponential would instead be straight on a semi-log plot ( vs plain ). Empirically, GPT losses fall on a line only in log-log — so the data say "power law". Physically: every time you multiply by 10, loss drops by the same fraction, not the same amount.
L3.3 — Why do residual connections enable 96 layers?
A residual layer computes , where is the input and is the sublayer (attention or MLP). Using the chain rule idea, explain why this lets gradients survive through many stacked layers.
Recall Solution
The gradient of the output with respect to the input has the form , where is the identity (the "" term). Even if is tiny, the keeps the total near 1, so multiplying such factors across 96 layers does not drive the gradient to 0. Without the residual, each layer contributes a factor ; multiplying 96 small numbers gives a vanishingly small product — the classic vanishing-gradient failure. The identity "highway" is what makes very deep stacks trainable.
Level 4 — Synthesis
Combine multiple pieces.
L4.1 — Forecast a scale jump with the scaling law
GPT-2 has parameters; GPT-3 has . Using and the power law , estimate the change in log-loss (in nats) from GPT-2 to GPT-3, and interpret the sign and size.
Recall Solution
Ratio . Since (natural log), moving from to changes it by Interpretation: the sign is negative — loss improves (drops). The size ~0.36 nats is meaningful but bounded: a 117× scale-up did not send loss to 0. That finite return is exactly what motivated the search for compute-optimal scaling (Chinchilla), where data is scaled alongside parameters.
L4.2 — Full attention block param budget for one GPT-3 layer
Combine L2.2 with the MLP. The position-wise MLP is where is a nonlinearity, maps and maps . Ignoring biases, count total parameters (attention + MLP) in one GPT-3 layer with , and state which part dominates.
Recall Solution
Attention: . MLP: has params, has params, total . Per layer: . With : parameters per layer. The MLP dominates ( vs ) — it holds two-thirds of a layer's weights. This is why sparse alternatives like Mixture-of-Experts target the MLP for efficiency.
L4.3 — Architecture change vs training/alignment change
Sort these five GPT milestones into exactly two categories — "architecture change" (the wiring/layers change) vs "training/alignment change" (weights are learned/adjusted, wiring unchanged): (a) pre-LN, (b) RLHF, (c) causal masking, (d) few-shot in-context learning, (e) Mixture-of-Experts. For any tricky item, justify which bucket it belongs in.
Recall Solution
Architecture change: (a) pre-LN (moves a layer's LayerNorm), (c) causal masking (the core attention wiring), (e) Mixture-of-Experts (replaces the dense MLP with routed experts — Mixture-of-Experts). Training/alignment change: (b) RLHF (fine-tunes the same backbone with human feedback — RLHF and InstructGPT), (d) few-shot in-context learning. Justify the tricky one (d): in-context learning is not a wiring change and not a weight update at all — it happens at inference with frozen weights. It is placed under training/alignment change here because, of the two allowed buckets, it belongs on the "how the model is used/produced" side rather than the "how the model is wired" side. The deeper truth to remember: it is an emergent behaviour of a large trained model, but it definitively does not alter the architecture.
Level 5 — Mastery
Design-level reasoning.
L5.1 — Why does scale alone eventually stop helping (and what fixes it)?
Using the power law and the idea of finite data, argue why simply growing forever gives diminishing returns, and name the principle that rebalances the recipe.
Recall Solution
The power law with tiny means each 10× in parameters shaves only ~ nats — a shrinking absolute payoff as approaches its irreducible floor (the entropy of language itself, which no model can beat). Worse, a giant trained on too little data underfits: parameters have nothing new to learn from. The fix is compute-optimal scaling — the Chinchilla finding that and should grow together (roughly in proportion), not alone. See Scaling laws (Kaplan, Chinchilla). So mastery-level answer: scale works, but only balanced scale of parameters and tokens, bounded by the irreducible entropy floor.
L5.2 — Design check: why not just remove the mask to "give the model more context"?
A student proposes dropping the causal mask so every token can attend to the whole sentence, arguing that seeing all positions gives strictly more information and can only help. State precisely why removing the mask is fatal for a generative (left-to-right) model, both at training time and at generation time, and name the model family that legitimately uses unmasked (bidirectional) attention and how its objective differs.
Recall Solution
Removing the mask makes attention bidirectional: while predicting token , the model can attend to token (and beyond) directly.
- At training time: the target token becomes visible as an input, so the model "cheats" by copying rather than predicting. The loss collapses toward 0 without any genuine language learning.
- At generation time: those future tokens do not exist yet (you are producing them one at a time), so any skill that relied on seeing them is useless — the model was trained on information it will never have at inference. The family that does use bidirectional (unmasked) attention is BERT (encoder-only). But BERT is trained on a masked-token filling objective (hide random words, predict them from both sides) — not left-to-right generation — so bidirectionality is legitimate there. See BERT vs GPT (encoder vs decoder). Conclusion: for a generative left-to-right model the causal mask is not optional overhead — it is what keeps the training objective honest and matched to how the model is actually used.
L5.3 — Synthesis forecast + budget
Suppose a lab plans a model 10× larger than GPT-3 in parameters (so ). (i) Estimate the log-loss improvement over GPT-3 using . (ii) Estimate attention-projection params per layer if they also double the width to .
Recall Solution
(i) nats. A modest, predictable gain — again bounded, reinforcing the diminishing-returns lesson. (ii) Attention projections per layer. Doubling quadruples the per-layer attention cost (from ~ to ~), the same scaling from L2.2 — showing why width is far more expensive than depth.
Recall Feynman recap
Every exercise here poked at one of four load-bearing ideas: (1) GPT is a decoder-only next-word guesser, (2) the causal mask keeps the guessing honest, (3) residuals + pre-LN let the stack go deep, and (4) scaling laws let you predict — but only bounded — improvements. Master those four and the whole GPT timeline is just "same skeleton, bigger, plus a couple of honest tweaks".