Cooking AGI
Bilingual ML / LLM notes: 285 notes in 11 topics, each built around an example you can work, run and revisit.
Continue reading
Start here
Browse by topic
Example 01
One training step, by hand
Inputs 1 and 2, targets 2 and 4, starting at weight = 1. Drag the line or the point on the curve to see the errors change, then take one step down the gradient.
prediction = weight × inputweight = 1
| Input | Target | Prediction | Squared error |
|---|---|---|---|
| 1 | 2 | 1 | 1 |
| 2 | 4 | 2 | 4 |
loss = mean of the squared errors(1 + 4) / 2 = 2.5
gradient = mean of 2 × (prediction − target) × input(−2 − 8) / 2 = −5
new weight = old weight − learning rate × gradient
Learning rate 0.11 − 0.1 × (−5) = 1.5, loss 2.5 → 0.625. Loss went down: the weight fits the training data better.
Learning rate 11 − 1 × (−5) = 6, loss 2.5 → 40. The step is too large: it overshoots, and loss goes up.
The same model, another way:Optimizers: one step of SGD and of Adam →Training loop: this step in PyTorch →
Saved
Recently updated
- Prefix caching in hybrid models
- KV cache & inferencenow with a visual lab, and the same step in code