3.2.5 · D3Training Deep Networks

Worked examples — Adam and AdamW optimizers

2,415 words11 min readBack to topic

This page is the worked-examples companion to Adam and AdamW optimizers. The parent note derived the formulas; here we use them on every kind of input the algorithm can meet — the first step, later steps, zero gradients, huge gradients, sign flips, decay, and a couple of exam traps. By the end you should never hit a case you haven't seen.

Everything below leans on four moving parts you already met in the parent note. Let's re-anchor them in one place so no symbol is unexplained.

Think of as a compass: it mostly reports which way to move, and its length hovers near 1 rather than tracking how big the gradient is. Keep that picture — most surprises below come from it.


The scenario matrix

Every situation Adam can face falls into one of these cells. The examples that follow are tagged with the cell they cover.

Cell What's special about the input Covered by
A. First step , EMAs still empty Example 1
B. Positive vs negative gradient sign of Example 1 (+), Example 2 (−)
C. Steady state, constant , gradient stable Example 3
D. Huge vs tiny gradient, same direction magnitude extremes Example 4
E. Zero / degenerate gradient , or suddenly vanishes Example 5
F. Sign flip / oscillating gradient changes sign each step Example 6
G. AdamW vs Adam+L2 decay , decoupled vs coupled Example 7
H. Early-step instability without bias correction small, correction on/off Example 8
I. Word problem (real training) choosing in practice Example 9
J. Exam twist dominating, effective-LR cap Example 10

Prerequisites worth a glance if any line feels unfamiliar: Exponential Moving Average, Momentum and Nesterov Acceleration, RMSProp, Stochastic Gradient Descent, Weight Decay and L2 Regularization, Bias-Variance in Gradient Estimation.


Worked examples


Recall

Recall Cover the answers — one line each

First-step size regardless of |g| ::: (compass length 1), as long as . Steady-state step on constant g ::: , independent of . What an oscillating plus/minus gradient does to the step ::: drives so the step (Adam refuses to ping-pong). Momentary zero gradient at step 1000 (m about 0.36, sqrt vhat about 0.4, eta 0.01) ::: step — momentum carries it through. AdamW decay for a weight at theta=1, eta=1, lambda=0.01 ::: (uniform); Adam+L2 gives (gradient-dependent), e.g. vs . Bias-correction size at t=1 on the v path ::: a step change (). When does epsilon actually change the step ::: when ; then it shrinks the compass below length 1, keeping the step .