Answers · The mathematics underneath
Why does Adam need bias correction at the start of training?
In shortAdam needs bias correction because its two running averages start at zero, and without correction the early steps are several times larger than the learning rate asks for.
Adam needs bias correction because both running averages start at zero, so at early steps they are too small. Correcting each by its exact shortfall makes the first update equal to the learning rate; without correction the update is not cautious but several times too large.
The two averages are not symmetric. The gradient average with looks back about ten steps. The squared-gradient average with looks back about a thousand. At step one the first is at a tenth of its final size and the second is at a thousandth. The numerator therefore warms up quickly and the denominator warms up slowly, and that mismatch is why the uncorrected ratio overshoots rather than undershoots.
The exact shortfall
Expand the recursion for the gradient average. After steps the weights on the observed gradients are , and they sum to rather than to one. The missing weight was spent on the zero with which the average started. The same calculation applies to the squared-gradient average with . That is why the correction divides by rather than adding a constant.
At with and , take a gradient that is the same at every step for the calculation. Then and . The square root is , so the uncorrected ratio is . The corrected quantities are and , so their ratio is one. The corrected first step is , approximately .
Why both being small does not cancel
The natural guess is that if and are both short, the ratio is roughly right. It is not, because the two averages are short by different factors. The uncorrected update is inflated relative to the corrected one by . At that factor is , not one. At the uncorrected ratio is .
The gap gets worse before it gets better. At the uncorrected ratio is . By the squared-gradient average has warmed up and the uncorrected ratio is . A learning rate tuned for corrected Adam can therefore be exceeded by a large factor in the first few dozen steps. A ramped learning rate does a similar job, but bias correction does it exactly for a zero initialisation.
Correcting only one average is worse than correcting neither in one direction and not enough in the other. If only is corrected at , the update is , still far too large. If only is corrected, the update is , too small. Both factors are needed because the ratio contains both.
The correction is exact for the zero start. If the gradients were stationary, would be an unbiased estimate of and an unbiased estimate of . If the distribution changes, both corrected and uncorrected quantities estimate different things, but the initialisation bias is still removed. The of about only stops a coordinate with no history from dividing by zero; it is not what fixes the bias.
What it does not fix
Bias correction repairs the start, not the diagonal approximation. If a valley runs at forty-five degrees to both coordinates, both coordinates have gradients of the same typical size, so the adaptive denominators are equal and the method behaves like plain momentum. Only a full matrix preconditioner would notice that curvature. Weight decay placed inside the loss has a related problem: its gradient is divided by , so the decay applied to a parameter is scaled by that parameter's gradient history. Applying the decay directly to the parameters is the difference between AdamW and Adam.
Worth keeping
- At step one with the usual settings, uncorrected Adam takes a step about 3.16 times the learning rate; by step ten the factor is about 6.53.
- Bias correction divides each average by one minus beta to the power t, which is the exact factor by which a zero-started geometric average is short.
- It fixes the initialisation, not the diagonal limitation: a valley at forty-five degrees still looks like plain momentum.
Where this goes next
This question is one step of The Mathematics of Gradient Descent, a course that works through its subject from the beginning. The page that teaches this part of it is A Step Size Per Coordinate, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- Why is the negative gradient the direction of steepest descent?A unit step goes downhill fastest when it points directly opposite the gradient, because the dot product with the gradient is then as negative as it can be.
- How does momentum stop the steps from cancelling each other out?Momentum keeps a running total of past gradients, so directions that keep agreeing build up while directions that keep flipping sign cancel out.
- Why does computing the gradient cost about the same no matter how many parameters the network has?Because one backward sweep shares intermediate derivatives across all parameters, so the whole gradient costs a few forward passes in total rather than one per parameter.
- Why does gradient descent still work when each step uses only one minibatch's gradient?A minibatch gradient is wrong at every step but correct on average, so the errors cancel over many steps while the true downhill pull keeps adding up.
- What is the difference between variance and standard deviation?They measure the same spread: variance is the average squared distance from the mean, standard deviation is its square root, so you report the standard deviation and calculate with the variance.
- How do you make a vague claim precise enough to tell whether it's true?Fix what is being talked about, what is asserted, which cases are covered and the cut-off, then name an observation that would prove it false.