Training changes a model's parameters so that its next-token probabilities fit the examples in a corpus. A falling loss is useful evidence only after the corpus, target shift, causal mask, parameter set, and update order are known to be correct.
This chapter trains the 368-parameter decoder from Chapter 6. Its architecture does not change:
| Quantity | Value |
|---|---|
| vocabulary size | 8 |
| context length | 4 |
| model width | 4 |
| decoder blocks | 2 |
| attention heads | 2 |
| MLP width | 8 |
| tied learned entries | 368 |
The fixed forward contract remains
What changes is the experiment around it. Token sequences become aligned input and target batches. PyTorch records the forward computation, calculates a gradient for each registered parameter, and AdamW uses those gradients and its stored state to update the model.
The corpus is deliberately small:
<bos> A B C <eos>
<bos> A B D <eos>
<bos> X Y X <eos>
<bos> Y X Y <eos>
This is not a small sample of natural language. It is a controlled grammar for testing whether the implementation learns intended conditional probabilities. Some contexts have more than one valid next token, so the best possible population loss is not zero.
The executable experiment runs on CPU in a local Python environment. The browser-Python editor used for lighter examples does not include PyTorch. The chapter explains each framework operation and supplies exact checks rather than asking you to trust a framework call.