Exercises
Practice target construction, leakage detection, shapes, parameter counting, entropy, update order, gradient clipping, train-validation diagnosis, checkpoint state, and end-to-end failure audits.
Use vocabulary IDs <bos>=0, A=1, B=2, C=3, D=4, X=5,
Y=6, and <eos>=7. The model has , , , two
blocks, two heads, , and tied input-output weights.
Q1. Construct an aligned example
For sequence <bos> A B D <eos>, write the input-ID row and target-ID row.
Answer it first, then check.
Hint
Solution
[0,1,2,4]; target [1,2,4,7].Q2. Identify target leakage
A training row uses input [0,1,2,3,7] and calculates loss only for target 7
at its final input position. Which judgment is correct?
Select one choice, then check.
Hint
Solution
<eos>, the final input position
should contain C, not <eos>.Q3. Audit batch and loss shapes
For and , give the shapes of input IDs, logits, flattened logits, and flattened targets.
Answer it first, then check.
Hint
Solution
Q4. Recover the parameter ledger
The token table has 32 entries, positions 16, each block 156, and final LayerNorm 8. Calculate the total for two blocks with tied readout.
Compute it first, then check your number.
Hint
Solution
Q5. Calculate irreducible loss
After <bos>, the target entropy is . The ambiguous C/D
context contributes another per sequence on average. There are four
target positions. Calculate the population loss floor in nats per token.
Compute it first, then check your number.
Hint
Solution
Q6. Repair a training step
The following order is wrong: forward, backward, optimizer step, clip gradients, clear gradients. Choose the corrected order.
Select one choice, then check.
Hint
Solution
Q7. Interpret clipping evidence
Before clipping, the global gradient norm is 3.0. After clipping at threshold 1.0, it is 1.0. What does this observation establish?
Select one choice, then check.
Hint
Solution
Q8. Distinguish two failure patterns
Run A stays near 2.05 on both training and validation. Run B falls to 0.02 on training but rises to 3.0 on validation. Match each run to the first broad diagnosis.
Select one choice, then check.
Hint
Solution
Q9. Choose checkpoint contents
Which record is sufficient for an exact next AdamW update in the same environment?
Select one choice, then check.
Hint
Solution
Q10. Diagnose a suspicious run
A model reports correct shapes and finite loss. Its initial loss is 0.03, its tied parameter count is 400, and changing input position 3 changes logits row 0. Identify the three independent failures or suspicions.
Select one choice, then check.