Lesson 2 · Unit 01
Adam and AdamW
A step size per weight, and weight decay done right
What you practise
- A step size per parameter from running averages of the gradient and its square, bias correction on the first steps, weight decay and why AdamW applies it separately
Try a question from this lesson
Pick one
One weight sees gradients around 100, another around 0.001. SGD gives both the same learning rate, 0.01. What goes wrong?
Hint
An SGD step is the learning rate times the gradient. Work it out for each weight.
Correct answer
The first leaps 1.0 a step, the second barely moves
Why
The steps are 1.0 and 0.00001. A rate small enough to tame the first weight freezes the second. Gradients in a deep network differ in scale by orders of magnitude, so one global step size suits almost none of the weights.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Adam: a step size per weight
Adam keeps two running averages for every weight: m, the average gradient, and v, the average squared gradient. The step is m divided by the square root of v.
Dividing by the gradient's typical size cancels its scale. Each weight moves about lr per step, whether its gradients are huge or tiny.
m = 0.9 * m + 0.1 * g
v = 0.999 * v + 0.001 * g * g
w = w - lr * m / (v ** 0.5 + 1e-8)Concept
Weight decay, two ways
Weight decay shrinks every weight a little on each step. It pulls the model toward small weights, which overfit less.
There are two ways to code it. The old way adds decay * w to the gradient. The other shrinks the weight directly, apart from the gradient step. Under plain SGD the two are the same thing. Under Adam they are not.
g = g + decay * w # in the gradient
w = w - lr * decay * w # on the weight10 more exercises in the app
- 3× multiple choice
- 3× type the answer
- 2× true or false
- 1× fill the blanks
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.