Try each question before opening the answer.
1. In the toy, what are the shapes of Q, of one head's score matrix, and of the logits?
Answer
Q is [3 × 4] (3 tokens × d = 4 numbers). Each head's scores are [3 × 3] (query × key), and there are 2 heads. The logits are [3 × 8] (one row per position, one column per vocabulary word); only the last row is used to pick the next token.
2. Why is the first row of every causal attention matrix [1, 0, 0]?
Answer
Token 0 may only look at itself: the other scores in its row are −∞. A softmax over one finite score gives weight 1 to it and exp(−∞) = 0 to the rest.
3. A real model has dk = 128 and q, k entries with variance 1. What is the typical size (standard deviation) of a raw score, and what happens without the 1/√dk scale?
Answer
The variance of q·k is dk = 128, so the standard deviation is √128 ≈ 11.31. Softmax of numbers that far apart is almost one-hot (step 8's demo gives 0.00, 1.00, 0.00), so the other keys get almost no gradient and training stalls.
4. What goes wrong if we skip the projections and use x̂ itself as Q, K and V?
Answer
After LayerNorm (with γ = 1, as here) every x̂ has the same squared length d = 4, so by Cauchy–Schwarz x̂i·x̂j ≤ x̂i·x̂i: every token scores itself highest. The model also could not separate “what I look for” from “what I contain”, or choose what to pass on.
5. Why does the FFN need the ReLU between W1 and W2?
Answer
Without it, (ĥW1)W2 = ĥ(W1W2): two linear layers collapse into one [4 × 4] matrix, so the 8-wide hidden layer adds nothing a single linear map could not do.
6. During generation, why can K and V be cached, but not Q?
Answer
With a causal mask, a past token never attends to later tokens, so its K and V (in every layer) are fixed once computed, and every later query reads them. A query is only used to produce its own token's output, which is already done, so old queries are never needed again. In short: Q is used once by its own token; K and V are reused by every later token.
7. How many numbers does the toy's KV cache hold after “the cat sat on the” (5 tokens)? How big is the cache of the 7B-class model from step 19 for one 4096-token sequence in FP16?
Answer
Toy: 5 tokens × (4 for K + 4 for V) × 1 layer = 40 numbers (the last state of step 18). 7B-class: 2 × 32 layers × 4096 × 2 bytes = 512 KiB per token, × 4096 tokens = 2.0 GiB.
8. Most GPTs use dff = 4·d. How many parameters would the toy have with dff = 16 instead of 8?
Answer
The FFN goes from 2·4·8 = 64 to 2·4·16 = 128 weights; nothing else changes: 248 − 64 + 128 = 312.
9. LayerNorm the row [1, 2, 3, 6] by hand (γ = 1, β = 0, ignore ε). What would change if you divided by d − 1?
Answer
μ = 12 / 4 = 3; row − μ = [−2, −1, 0, 3]; squares 4 + 1 + 0 + 9 = 14, σ² = 14 / 4 = 3.5, σ = 1.87; result [−1.07, −0.53, 0.00, 1.60]. Dividing by d − 1 = 3 would give σ² = 4.67, a different σ and different outputs; LayerNorm uses d (step 4).
10. At T = 1, sampling draws r = 0.75. Which word is picked? What does greedy pick, and does T matter for greedy?
Answer
The segments, largest first, are “on” [0, 0.70) and then “dog” [0.70, 0.78), so r = 0.75 picks “dog”. Greedy always picks “on”, the largest probability, at every T: dividing all logits by the same T never changes which one is largest.