Intuition What this page is for
The parent note gave you the formulas: autoregressive loss, causal attention, parameter counting, scaling laws. This page stress-tests those formulas against every situation you could meet — every sign, every degenerate input, every limiting case, plus a word problem and an exam twist. If you can follow all ten examples below, no GPT-architecture question can surprise you.
Prerequisites we lean on: the parent topic , Transformer architecture , Self-attention and multi-head attention , Scaling laws (Kaplan, Chinchilla) , Cross-entropy loss .
Definition Notation: which logarithm?
Throughout this page log and ln mean the exact same thing — the natural logarithm (base e ≈ 2.718 ). GPT losses are reported in nats (natural-log units), so we never use base 10 or base 2. If you see log V and ln V on different lines, they are identical.
Before working examples, let us list every kind of case the GPT-architecture math can throw at us. Each row is a "cell". Every cell is covered by at least one worked example below.
#
Cell (scenario class)
Degenerate / limiting version
Example
A
Counting attention params (4 d 2 )
tiny d vs GPT-3 d
Ex 1, Ex 2
B
Counting MLP params (8 d 2 ) & full-layer total
when MLP dominates
Ex 2
C
Causal mask correctness
position 1 (sees only itself), last position (sees all)
Ex 3
D
Cross-entropy loss numeric
perfect model (L → 0 ), random model (L → ln V )
Ex 4
E
The d k variance fix
d k = 1 (no effect) vs large d k
Ex 5
F
Scaling-law forecast (sign of Δ L )
scale up (loss falls, Δ L < 0 ) vs scale down (loss rises, Δ L > 0 )
Ex 6, Ex 7
G
Limiting behaviour of the power law
N → ∞ (L → 0 ) and N → 0 (L → ∞ )
Ex 8
H
Real-world word problem
compute budget → predicted loss
Ex 9
I
Exam-style twist (spot the wrong claim)
encoder/fine-tune myth
Ex 10
The three "signs" that matter in this topic are:
the sign inside the mask (0 = allowed to look, − ∞ = forbidden),
the sign of Δ ( log L ) when you scale (negative when you grow, positive when you shrink),
the sign of the exponent in the power law (loss decreases as N grows, so the useful form has N in the denominator).
Worked example Example 1 — Attention params for a
tiny model (cell A, small-d )
A toy GPT layer has model dimension d = 4 . How many parameters live in one causal self-attention block (ignore biases)?
Forecast: Guess first — is it closer to 16, 64, or 256?
Steps:
List the four weight matrices: W Q , W K , W V , W O . Why this step? The parent formula 4 d 2 counts these four ; naming them stops you from forgetting W O (the output projection), the one people always drop.
Each matrix is d × d = 4 × 4 = 16 numbers. Why this step? A projection maps a d -vector to a d -vector, so it is a d × d grid.
Total = 4 × 16 = 64 . Why this step? Four identical matrices, so multiply.
Verify: Plug into 4 d 2 = 4 × 4 2 = 4 × 16 = 64 . ✓ Units: pure count (dimensionless). The middle guess (64) was right — the d 2 term makes even a tiny d jump fast.
Worked example Example 2 — Full layer params, and does MLP dominate? (cells A + B, large-
d )
For GPT-3, d = 12288 , and the MLP inner dimension is 4 d . Compute (a) attention params, (b) MLP params, (c) which dominates, per layer. We ignore all biases and LayerNorm scale/shift parameters (they add only O ( d ) each, negligible against O ( d 2 ) ).
Forecast: Will attention or the MLP hold more weights? Guess the ratio.
Steps:
Attention = 4 d 2 = 4 × 1228 8 2 . Why this step? Same 4 d 2 rule as Ex 1, now at scale.
4 × 1228 8 2 = 603 , 979 , 776 ≈ 6.04 × 1 0 8 .
MLP has two matrices: W 1 of shape ( 4 d ) × d and W 2 of shape d × ( 4 d ) . Each is 4 d 2 , total 8 d 2 . Why this step? The MLP expands to 4 d then projects back — two rectangular matrices, each 4 × d 2 .
8 × 1228 8 2 = 1 , 207 , 959 , 552 ≈ 1.21 × 1 0 9 .
Ratio MLP : Attention = 8 d 2 : 4 d 2 = 2 : 1 . Why this step? The d 2 cancels, leaving a clean constant — the MLP always carries twice the attention's weights, at any scale.
Verify: 8/4 = 2 exactly, independent of d . Full layer = 12 d 2 = 12 × 1228 8 2 ≈ 1.81 × 1 0 9 . Multiply by GPT-3's 96 layers ⇒≈ 1.74 × 1 0 11 (the transformer-block parameters). The gap to the famous 175B is the token + position embedding matrices , which do NOT scale with layer count: the token embedding is V × d = 50257 × 12288 ≈ 6.2 × 1 0 8 , and the learned position embeddings are T m a x × d = 2048 × 12288 ≈ 2.5 × 1 0 7 . Adding these to 1.74 × 1 0 11 recovers ≈ 1.75 × 1 0 11 . ✓
Worked example Example 3 — Mask at position 1 and at the last position (cell C, degenerate ends)
A sequence has T = 4 tokens. Write the mask entries M ij for (a) token i = 1 (the very first), (b) token i = 4 (the last).
Forecast: How many tokens can the first token look at? How many can the last look at?
Steps:
Rule from the parent note: M ij = 0 if j ≤ i (allowed, look at the picture's blue cells), else M ij = − ∞ (forbidden, red cells). Why this step? The mask is added before softmax; − ∞ becomes weight 0 , so "forbidden" literally means "can't attend".
Row i = 1 : M 11 = 0 ; M 12 = M 13 = M 14 = − ∞ . So token 1 attends only to itself . Why this step? The first token has no past — it must predict token 2 from token 1 alone. This is the degenerate "sees only itself" end.
Row i = 4 : M 41 = M 42 = M 43 = M 44 = 0 ; none are − ∞ . Token 4 attends to all four . Why this step? The last token has the full history available — the other degenerate end.
Verify: Count allowed cells row by row: row 1 → 1 cell, row 2 → 2, row 3 → 3, row 4 → 4. Total = 1 + 2 + 3 + 4 = 10 . The formula for a T × T lower-triangular (including diagonal) count is 2 T ( T + 1 ) = 2 4 ⋅ 5 = 10 . ✓ Look at the figure: the blue staircase has exactly 10 cells.
Worked example Example 4 — Loss when the model is perfect vs when it guesses uniformly (cell D, both limits)
Vocabulary size V = 50257 (GPT-2's). Compute the per-token loss L = − log P θ ( x t ∣ x < t ) for: (a) a perfect model that assigns probability 1 to the true token; (b) a random model that spreads probability uniformly, P = 1/ V for every token. (Recall log = ln , natural log.)
Forecast: One answer is 0 . Guess the other — bigger or smaller than 10?
Steps:
Perfect model: P = 1 , so L = − log 1 = 0 . Why this step? This is the lower limit of the loss — you cannot do better than certainty about the truth. See Cross-entropy loss .
Random model: P = 1/ V , so L = − log ( 1/ V ) = log V . Why this step? Uniform ignorance is the natural upper baseline ; any trained model must beat it.
Compute log V = ln 50257 ≈ 10.82 nats. Why this step? GPT uses natural log (nats); this number is the "loss of knowing nothing" and is exactly where training curves start.
Verify: e 10.82 ≈ 50000 ≈ V . ✓ So any real GPT-2 loss (typically ≈ 3 nats) sits between 0 and 10.82 — sane. Units: nats (dimensionless log-probability).
Worked example Example 5 — Variance of the dot product for
d k = 1 vs d k = 64 (cell E)
Query and key entries are independent with mean 0 , variance 1 . The raw score is q ⋅ k = ∑ m = 1 d k q m k m . Find its standard deviation for (a) d k = 1 , (b) d k = 64 , and state what d k -division does in each.
Forecast: For d k = 64 , will the raw scores be roughly ± 1 or roughly ± 8 ?
Steps:
Each product q m k m has mean 0 and variance 1 . Why this step? Let us actually derive it. By independence and zero mean, E [ q m k m ] = E [ q m ] E [ k m ] = 0 ⋅ 0 = 0 . Then Var ( q m k m ) = E [( q m k m ) 2 ] − ( E [ q m k m ] ) 2 = E [ q m 2 ] E [ k m 2 ] − 0 . Since E [ q m 2 ] = Var ( q m ) + E [ q m ] 2 = 1 + 0 = 1 (and likewise for k m ), we get Var ( q m k m ) = 1 ⋅ 1 = 1 . This is the atom we sum. (See Self-attention and multi-head attention .)
Summing d k independent terms adds variances: Var ( q ⋅ k ) = d k , so std = d k . Why this step? Variances (not standard deviations) add for independent sums — the reason the spread grows as d k , matching the parent's claim.
Case d k = 1 : std = 1 = 1 . Dividing by d k = 1 changes nothing — the degenerate case where the fix is invisible. Case d k = 64 : std = 64 = 8 . Dividing by 8 pulls scores back to std 1 . Why this step? Shows the fix does nothing when small and everything when large — softmax of ± 8 logits saturates (one weight ≈ 1 , gradients die); ± 1 logits stay soft.
Verify: After dividing by d k , new variance = d k / ( d k ) 2 = d k / d k = 1 for any d k . ✓ The orange curve in the figure (raw, wide) collapses onto the blue curve (scaled, unit-width) exactly.
N c in the scaling law?
Kaplan's law is L ( N ) ≈ ( N c / N ) α N . Here N is the model's parameter count and α N ≈ 0.076 is the fitted power. The constant N c is a fixed reference scale (measured in parameters) obtained by fitting real training runs: it is the number of parameters at which the extrapolated loss would equal 1 nat. You almost never need its exact value, because in every ratio or difference of losses it cancels — that is the whole practical trick below.
Worked example Example 6 — Scaling
up : GPT-2 → GPT-3 (cell F, negative Δ L )
Kaplan's law: L ( N ) ≈ ( N c / N ) α N with α N = 0.076 . Going N 1 = 1.5 B → N 2 = 175 B , find the change in log-loss Δ ( log L ) = log L 2 − log L 1 . (All logs natural.)
Forecast: Will Δ ( log L ) be positive or negative? By roughly how much?
Steps:
Take logs of the law: log L = α N ( log N c − log N ) = const − α N log N . Why this step? A power law is a straight line in log-log; taking log turns multiplication into subtraction so the constant N c cancels in a difference .
Difference: Δ ( log L ) = − α N ( log N 2 − log N 1 ) = − α N ln ( N 2 / N 1 ) . Why this step? The N c term is identical in both, so it drops — we never need to know it.
Ratio N 2 / N 1 = 175/1.5 ≈ 116.7 ; ln ( 116.7 ) ≈ 4.76 ; Δ = − 0.076 × 4.76 ≈ − 0.36 nats. Why this step? The negative sign confirms scaling up lowers loss — matches the parent's worked Example 3.
Verify: Sign is negative (loss dropped) ✓, magnitude ≈ 0.36 nats — bounded, not infinite, exactly the "capabilities improve but not without limit" message. ✓
Worked example Example 7 — Scaling
down : shrink a model 10× (cell F, positive Δ L )
You must shrink a model by 10 × to fit a phone. Predict Δ ( log L ) .
Forecast: Positive or negative this time?
Steps:
Same formula: Δ ( log L ) = − α N ln ( N 2 / N 1 ) with N 2 / N 1 = 1/10 = 0.1 . Why this step? Reusing one formula for the opposite direction — the only change is the ratio is now < 1 .
ln ( 0.1 ) = − 2.303 , so Δ = − 0.076 × ( − 2.303 ) = + 0.175 nats. Why this step? A negative log times a negative α N -prefactor gives a positive result — shrinking raises loss, as physical intuition demands.
Verify: + 0.175 > 0 ✓ (worse model). And Ex 6's − 0.36 vs this + 0.175 are consistent: growing 117 × helps twice as much (in log-ratio) as shrinking 10 × hurts, because ln 117 ≈ 4.76 vs ln 10 ≈ 2.30 . ✓
Worked example Example 8 — The two limits of the power law (cell G,
N → ∞ and N → 0 )
Analyse L ( N ) = ( N c / N ) 0.076 as (a) N → ∞ and (b) N → 0 + .
Forecast: Does infinite scale give zero loss? Should it?
Steps:
As N → ∞ : N c / N → 0 , and 0 raised to a positive power → 0 , so L → 0 . Why this step? The clean power law predicts zero loss at infinite size — a known over-idealization : real data has irreducible entropy, so Chinchilla adds a floor term L = E + ( A / N ) α . Look at the figure: the naive curve (blue) dives to 0; the realistic curve (orange) flattens at a floor.
As N → 0 + : N c / N → ∞ , and ∞ 0.076 = ∞ , so L → ∞ . Why this step? A model with (almost) no parameters is infinitely bad — the sanity boundary on the other end.
Verify: Both limits monotonic and correctly signed: L strictly decreases as N grows (derivative d N d L < 0 ). Check the sign of the slope: d N d ( N c / N ) 0.076 = − 0.076 N c 0.076 N − 1.076 < 0 for all N > 0 . ✓
Worked example Example 9 — "Given my compute budget, what loss can I expect?" (cell H)
A lab has compute for a model N = 6 B params. A published N 0 = 1 B model reached loss L 0 = 2.20 nats. Using α N = 0.076 , predict the 6B model's loss — no retraining, just the law.
Forecast: Loss below or above 2.20 ? By more or less than 0.2 ?
Steps:
We don't know N c , but ratios kill it: L 0 L = ( N N 0 ) α N . Why this step? Anchoring to a known point ( N 0 , L 0 ) lets us predict a new point without any unknown constant — the practical use of the law.
N N 0 = 6 1 ; raise to 0.076 : ( 1/6 ) 0.076 = e 0.076 l n ( 1/6 ) = e 0.076 × ( − 1.792 ) = e − 0.1362 = 0.8727 . Why this step? The exponent is small, so the multiplicative factor is close to (but below) 1 — big compute gains, modest loss gains, the recurring lesson.
L = 2.20 × 0.8727 = 1.92 nats. Why this step? Convert the fractional factor into the actual predicted loss.
Verify: 1.92 < 2.20 ✓ (bigger model, lower loss), and the drop 0.28 nats is modest despite 6 × compute — matches diminishing returns. Cross-check with the log-difference form of Ex 6: Δ log L = − 0.076 ln 6 = − 0.136 , and e − 0.136 = 0.873 . ✓ Same number.
Worked example Example 10 — Which statement is wrong, and why? (cell I)
An exam gives four claims. Exactly one is false. Find it and correct it.
(i) GPT is decoder-only with causal masking.
(ii) GPT-3's headline result is few-shot in-context learning with frozen weights.
(iii) GPT-2 switched to pre-LN for training stability.
(iv) GPT-3 was fine-tuned separately on every downstream task .
Forecast: Which line smells wrong?
Steps:
Check (i) against the parent's BERT vs GPT (encoder vs decoder) mistake box: GPT keeps only the masked decoder, no encoder, no cross-attention. True. Why this step? Eliminate the classic encoder myth first.
Check (ii): GPT-3's star result is in-context/few-shot with frozen weights — you put examples in the prompt . True. Why this step? This is the emergent-at-scale property, not a bug.
Check (iii): GPT-2 indeed moved LayerNorm to the pre-activation position and added a final LayerNorm, which stabilised its 48-layer depth. True. Why this step? Confirms the one architectural tweak the parent note flagged as genuinely important.
Check (iv): this is the false one. GPT-1 fine-tuned per task, so the claim feels right by association — but GPT-3's whole point is that it needs no per-task fine-tuning. Correction: "GPT-3 requires no per-task fine-tuning; it performs the task from a few examples placed in the prompt, with all weights frozen." Why this step? The trap reuses GPT-1's true behaviour to lie about GPT-3 — exactly the parent note's second mistake box.
Verify: Exactly one false claim identified — (iv) — consistent with the parent note's "GPT-3 was fine-tuned on each task" mistake box. ✓
Recall Quick self-test
First token in a 4-length sequence attends to how many positions? ::: Exactly 1 (only itself).
Ratio of MLP params to attention params per layer? ::: 2 : 1 (8 d 2 vs 4 d 2 ).
Uniform-guess loss for vocab V ? ::: ln V nats (≈ 10.82 for V = 50257 ).
Sign of Δ ( log L ) when you make the model bigger? ::: Negative (loss falls).
What does dividing by d k do to the score variance? ::: Rescales it back to exactly 1 for any d k .
In the scaling law, what does N c mean? ::: A fitted reference parameter-count (where extrapolated loss = 1 nat); it cancels in every ratio.
Mnemonic The matrix in one breath
"Count d 2 , mask the future, log the vocab, and every 10× buys you a little." — parameters grow as d 2 , the mask blocks j > i , random loss is log V (natural log), and scaling gives bounded log-linear gains.