Foundations to Frontier
Tests
E. Deep Learning › E3 Optimizers (one page each)

Adam

Adam combines momentum (a moving average of gradients, the first moment) with RMSProp (a moving average of squared gradients, the second moment), and corrects both for starting at zero. Each parameter moves by roughly the learning rate times the ratio of its averaged gradient to its gradient RMS: about lr when gradients are consistent, less when they are noisy. It is the default optimiser for transformers and much of deep learning. This page covers the update, bias correction, the default hyperparameters, the effective step and its signal-to-noise behaviour, and known weaknesses. In the exercises you check the corrected first step and the size of the uncorrected inflation, then ablate bias correction while training a network and find that without it, at β₂ = 0.999, the largest loss spike grew 7 to 26 times.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Momentum plus per-parameter scaling

Adam keeps two running averages for every parameter: one of its recent gradients (which way it has been pushed, like momentum) and one of its recent squared gradients (how hard it typically gets pushed, like RMSProp). The step is the first divided by the square root of the second. When a parameter is pushed consistently in one direction it moves at about the learning rate; when its gradients are noisy and cancel, it moves less. A small correction fixes both averages for starting at zero.

Optimizer lab: Adam versus plain gradient descent
Adam: final loss 1.8e-5 (target reached at step 55) · gradient descent: final loss 2.2e-9 (step 22)
Orange: the chosen optimizer; grey dashed: plain gradient descent with the same learning rate. Darker shading means higher loss. On the ill-conditioned bowl, raise κ and watch gradient descent zig-zag across the narrow direction; on the saddle it stalls near the flat start; on the plateau its gradients are tiny. Adaptive methods rescale each direction; momentum methods build speed along consistent directions. The target is 1% of the starting loss (for the saddle, a loss below −0.2; its minima are at −0.25).
Why engineers care

Adam is the default optimiser for transformers, diffusion models and most new architectures, and a safe first choice for perception and control networks. Its behaviour depends on β₁, β₂, ε and the learning rate in ways that matter for stability, especially at the start of training and with mixed precision. Knowing what each part does turns tuning from trial and error into reasoning.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Adam combines…
  2. 2. With consistent gradients, each parameter moves about…
  3. 3. Bias correction compensates for…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Moments: m ← β₁m + (1 − β₁)g and v ← β₂v + (1 − β₂)g², with defaults β₁ = 0.9 and β₂ = 0.999.
  • Bias correction: m̂ = m/(1 − β₁ᵗ) and v̂ = v/(1 − β₂ᵗ).
  • Step: w ← w − η·m̂/(√v̂ + ε), with ε = 10⁻⁸ and a typical η of 10⁻³ to 10⁻⁴.
  • First step: m̂ = g and v̂ = g², so the step is exactly η·sign(g). With w = 1, g = −3 and η = 0.1, w becomes 1.1.
  • Without correction: the step ratio (1 − β₁ᵗ)/√(1 − β₂ᵗ) is 3.16 at t = 1 and peaks at about 6.6 at t = 12, before settling toward 1 over thousands of steps.
  • Warm-up of the averages: β₁ᵗ ≤ 0.01 needs t ≥ 44, but β₂ᵗ ≤ 0.01 needs t ≥ 4603. The second moment’s bias lasts far longer.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Adam's first bias-corrected step is…
  2. 2. Default β₂ is…
  3. 3. Without correction, how much larger is the first step (defaults)?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Adam in code

Exercise 1.

  • The corrected first step is exactly η·sign(g).
  • Without correction the step ratio is 3.16 at t = 1 and peaks at 6.6 at t = 12.
  • With noisy gradients (mean 0.1, standard deviation 1), Adam’s steps shrank to about 2 × 10⁻⁴, a fifth of η, because the averaged gradient is small next to the gradient’s RMS: Adam slows down where gradients are mostly noise.

Practice.

  • The defaults (β₁ = 0.9, β₂ = 0.999, ε = 10⁻⁸) are a good start. Transformers often use β₂ = 0.95–0.98 for stability, and larger ε (10⁻⁶) in low precision.
  • Use AdamW (E3-8) rather than adding L2 to the loss when regularising.
  • Learning-rate warm-up is standard for large models, partly because early Adam steps (with an immature v̂) can be erratic.
  • Adam stores two extra numbers per parameter, which triples optimiser memory compared with plain SGD. Adafactor (E3-13) reduces this.
torch.optim.Adam(params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8)
🐍 Exercise 1: Adam's step and its correction
Implement Adam with optional bias correction, compute the uncorrected step inflation over time, and measure Adam's step size under noisy gradients.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Transformers often lower β₂ to…
  2. 2. Adam's optimiser state per parameter is…
  3. 3. With mostly-noise gradients Adam's steps…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Signal-to-noise view. For stationary gradients with mean μ and variance σ² per coordinate, m̂ ≈ μ and v̂ ≈ μ² + σ², so the step is about η·μ/√(μ² + σ²). That is η when the signal dominates, and smaller when the noise dominates. Adam therefore acts like an automatic annealing per coordinate, and is invariant to rescaling each coordinate’s gradient.

Trust-region intuition. The step is bounded: |Δw| ≲ η in the common case, so η is roughly the maximum distance any parameter moves per step, a scale-free knob that makes learning-rate choice easier than for SGD.

Weaknesses.

  • Convergence: with β₂ fixed, Adam can fail to converge even on convex problems (Reddi et al., 2018). AMSGrad (E3-9) fixes the theory.
  • Generalisation: on some vision tasks Adam generalises worse than tuned SGD with momentum (Wilson et al., 2017), partly due to coupled L2 regularisation, which AdamW fixes.
  • Early instability: v̂ estimated from few samples is noisy; RAdam (E3-11) and warm-up address this.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Adam's step for gradients with mean μ and variance σ² is about…
  2. 2. Adam's convergence failure on convex problems was shown by…
  3. 3. Adam's per-step movement per parameter is roughly bounded by…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Does bias correction matter?

History.

  • D. Kingma and J. Ba (2014, published 2015) introduced Adam; it became one of the most cited papers in machine learning.
  • A. Wilson et al. (2017) questioned adaptive methods’ generalisation.
  • S. Reddi, S. Kale and S. Kumar (2018) gave convergence counterexamples and AMSGrad.
  • I. Loshchilov and F. Hutter (2019) introduced AdamW.

Exercise 2. A 2–64–64–3 tanh network on spirals (600 points), full batch, 300 Adam steps at three learning rates and β₂ = 0.9 or 0.999, with and without bias correction. “Largest spike” is the biggest single-step increase in training loss.

η β₂ bias correction loss at step 50 final loss largest spike
0.003 0.999 yes 0.398 0.008 0.0016
0.003 0.999 no 0.022 0.002 0.042
0.01 0.999 yes 0.060 0.001 0.020
0.01 0.999 no 0.003 0.001 0.123
0.03 0.999 yes 0.007 0.001 0.064
0.03 0.999 no 0.004 0.001 0.446
0.01 0.9 yes 0.028 0.000 0.022
0.01 0.9 no 0.056 0.000 0.018

(The remaining β₂ = 0.9 runs behaved the same way: the correction hardly mattered.)

  • Every run fitted the data by 300 steps. On this task bias correction did not change the end result.
  • Without correction at β₂ = 0.999, training was spikier. The largest loss spike was 7 to 26 times bigger, because the uncorrected v stays too small for hundreds of steps and inflates the steps (by up to 6.6 times around step 12).
  • The same inflation made uncorrected runs faster early, because it acts as a larger learning rate. Its benefit is speed and its cost is stability, much like raising η.
  • With β₂ = 0.9 the correction hardly mattered, because v warms up in a few dozen steps.
🐍 Exercise 2 (research): does bias correction matter?
Train a small network on spirals with Adam at three learning rates and β₂ = 0.9 or 0.999, with and without bias correction; compare early loss, final loss and the largest loss spike.

Adam in AI, robotics and aerospace

  • Transformers and foundation models for perception, language and planning are trained with Adam or AdamW.
  • Reinforcement learning for control (PPO, SAC) uses Adam almost universally.
  • Physics-informed and scientific ML often starts with Adam before switching to L-BFGS for final refinement.

References

  1. D. P. Kingma, J. Ba (2015). “Adam: a method for stochastic optimization.” Proc. ICLR.
  2. S. J. Reddi, S. Kale, S. Kumar (2018). “On the convergence of Adam and beyond.” Proc. ICLR.
  3. A. C. Wilson, R. Roelofs, M. Stern, N. Srebro, B. Recht (2017). “The marginal value of adaptive gradient methods in machine learning.” Advances in NeurIPS 30.
  4. I. Loshchilov, F. Hutter (2019). “Decoupled weight decay regularization.” Proc. ICLR.