Quiz: optimisers and learning rates
Before this unit: Day 36: Neural networks.
See also: Day 38: Evaluation and statistics.
Short questions on learning rates, momentum, Adam and schedules. Try each on paper first, then open the answer.
Q1. The loss is 100 times steeper across a valley than along it. Why can plain gradient descent not simply use a large learning rate?
Which direction decides when a step overshoots?
The steep direction limits the learning rate: above 2/\lambda_{\max} every step across the valley overshoots further and training diverges. With that small learning rate the flat direction moves very slowly, about 50 times more steps than the steep one needs.
Q2. Momentum with \beta = 0.9. The gradient has been the same for many steps. How long is each step compared with plain gradient descent?
v \leftarrow 0.9v + g settles where v = 0.9v + g.
v = g/(1 - 0.9) = 10g: ten times as long. If instead the gradient alternates in sign, the velocity stays small: momentum damps the zig-zag.
Q3. One weight has gradients around 1000, another around 0.001. With plain gradient descent, how do their steps compare? With Adam?
Adam divides the average gradient by the root of the average squared gradient.
Plain descent: the first weight moves a million times further. Adam: both move by about \eta per step, because for a steady gradient \hat m/\sqrt{\hat v} \approx \pm 1.
Q4. You change the loss from a mean over the pixels to a sum (a million times larger). Which optimiser needs a new learning rate?
Q3.
Plain gradient descent and momentum: their steps are a million times longer, so \eta must be a million times smaller. Adam’s steps are unchanged.
Q5. Why does Adam divide its running averages by 1 - \beta^t?
What are m and v after the first step, when they started at 0?
They start at 0, so early on they are too small: after one step m = 0.1g and v = 0.001g^2. Their ratio m/\sqrt v = 3.16 would make the first steps three times too long. Dividing by 1 - 0.9^t and 1 - 0.999^t gives \hat m = g, \hat v = g^2 at the first step; the correction fades as t grows.
Q6. Training with mini-batches: the loss falls fast, then stays at a noisy level. What does lowering the learning rate towards the end do, and why?
What makes the weights jiggle around the minimum?
The noisy gradients keep moving the weights around the minimum; the size of the jiggle grows with the learning rate. A decaying schedule (step or cosine) shrinks the steps at the end, so the weights settle closer to the minimum and the loss falls further (on the demo’s noisy bowl from 0.054 to 0.011).
Q7. Why start training with a warm-up, a learning rate that grows from almost 0 over the first steps?
What do Adam’s running averages know at step 3? What can large steps do to a random network?
At the start the weights are random and the gradients large and erratic; Adam’s averages rest on very few gradients. Large first steps can throw the weights into a bad region (dead ReLU units, saturated layers) from which training does not recover. A short warm-up avoids that at almost no cost.
Q8. (math) Plain gradient descent on \mathcal L = \frac12\lambda w^2. For which learning rates does w shrink to 0? For which does it shrink fastest?
One step multiplies w by a constant.
w \leftarrow (1 - \eta\lambda)w. It shrinks to 0 if |1 - \eta\lambda| < 1, i.e. 0 < \eta < 2/\lambda; fastest for \eta = 1/\lambda (one step). For 1/\lambda < \eta < 2/\lambda it overshoots and alternates in sign.