3.3 Optimizers
1. Learn
Section titled “1. Learn”- Understanding Deep Learning (Prince)chapter 6 Fitting models: §6.2 SGD, §6.3 Momentum, §6.4 Adam, §6.5 hyperparameters (pp. 83–91)
2. Bridge
Section titled “2. Bridge”SGD’s noise is a feature and a cost. A mini-batch gradient is an unbiased but noisy estimate of the full gradient. The noise lets SGD wander out of poor regions and costs almost nothing per step, but with a fixed step size the loss stalls at a noise floor whose height grows with the step (UDL §6.2). Shrinking the step later lowers the floor. That is the first reason for schedules.
Momentum keeps a running velocity and steps along it. In a ravine, the steep components flip sign each step and cancel, while the gentle slope along the valley floor adds up, so progress along the valley speeds up by up to . UDL writes instead: the same method with the learning rate scaled by . Nesterov momentum evaluates the correction one step ahead; the formula in the task is PyTorch’s rearrangement of that look-ahead (UDL §6.3; Goh 2017).
Adam keeps two running averages: of the gradient and of its square. It divides each coordinate’s step by (doing only that, with no , is RMSProp), so every parameter moves at a similar pace whatever its gradient’s scale, and the first step is about in every coordinate. Both averages start at zero, which biases them towards zero early on, and the bias correction below removes that (Kingma and Ba 2015; UDL §6.4).
AdamW fixes weight decay. Adding to the gradient sends it through Adam’s per-coordinate scaling, so weights with large gradients are barely regularised. Decoupled decay shrinks the weights directly, , outside and (Loshchilov and Hutter 2019). Most modern transformers are trained with AdamW, linear warmup and cosine decay (Loshchilov and Hutter 2017; Goyal et al. 2017).
3. Explore
Section titled “3. Explore”Implement the optimizers as classes that update a dictionary of NumPy arrays in place, the way PyTorch’s optimizers do. The tests check the first two steps against hand calculations, Adam’s scale invariance, and that AdamW’s decay never touches the gradient.
stubs/m3_3_optimizers.pyLoading starter file…
Prefer your own editor? Edit exercises/stubs/m3_3_optimizers.py and run mlc check 3.3. The tests are identical; import the results on the progress page.
Locally: mlc check 3.3.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.