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.
★☆☆☆☆ 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. Adam combines…
2. With consistent gradients, each parameter moves about…
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.
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. Adam's first bias-corrected step is…
2. Default β₂ is…
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.
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. Transformers often lower β₂ to…
2. Adam's optimiser state per parameter is…
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. Adam's step for gradients with mean μ and variance σ² is about…
2. Adam's convergence failure on convex problems was shown by…
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
D. P. Kingma, J. Ba (2015). “Adam: a method for stochastic optimization.” Proc. ICLR.
S. J. Reddi, S. Kale, S. Kumar (2018). “On the convergence of Adam and beyond.” Proc. ICLR.
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.
I. Loshchilov, F. Hutter (2019). “Decoupled weight decay regularization.” Proc. ICLR.
Without bias correction and with β₂ near 1, early steps are inflated, which speeds early progress but causes larger loss spikes.
Practice
Show:
Level 0
Problem 1Level 0
New w after Adam’s first step with w = 1, g = −3, η = 0.1?
w + 0.1 = 1.1.
Problem 2Level 0
m after one step from 0 with g = −3, β₁ = 0.9?
0.1 × (−3) = −0.3.
Problem 3Level 0
v after one step from 0 with g = −3, β₂ = 0.999?
0.001 × 9 = 0.009.
Level 1
Problem 4Level 1
Uncorrected-step inflation at t = 1 with default β’s?
0.1/√0.001 ≈ 3.162.
Problem 5Level 1
Bias-correction factor 1 − β₁ for t = 1?
0.1.
Problem 6Level 1
Steps until β₁ᵗ ≤ 0.01 for β₁ = 0.9?
⌈ln 0.01/ln 0.9⌉ = 44.
Problem 7Level 1
Steps until β₂ᵗ ≤ 0.01 for β₂ = 0.999?
4603.
Level 2
Problem 8Level 2
Peak uncorrected-step inflation with default β’s?
≈ 6.57, at t = 12.
Problem 9Level 2
Ideal step per unit η for μ = 0.1, σ = 1 (μ/√(μ² + σ²))?
≈ 0.0995.
Problem 10Level 2
Largest spike without correction at η = 0.003, β₂ = 0.999, in exercise 2?
0.042.
Problem 11Level 2
Largest spike with correction at η = 0.003, β₂ = 0.999?
0.0016.
Problem 12Level 2
Largest spike without correction at η = 0.03, β₂ = 0.999?
0.446.
Problem 13Level 2
Loss at step 50 without correction at η = 0.003, β₂ = 0.999?
0.022.
Level 3
Problem 14Level 3
Show that Adam’s first corrected step is η·sign(g).
At t = 1, m = (1 − β₁)g and v = (1 − β₂)g². Then m̂ = g and v̂ = g², so m̂/√v̂ = g/|g| = sign(g), ignoring ε. The step is η·sign(g). ∎
Problem 15Level 3
Derive the uncorrected inflation factor and explain its peak.
Under a constant gradient g, uncorrected m = (1 − β₁ᵗ)g and v = (1 − β₂ᵗ)g², so the step is η(1 − β₁ᵗ)/√(1 − β₂ᵗ), while the corrected step is η. The ratio is (1 − β₁ᵗ)/√(1 − β₂ᵗ). The numerator rises to 1 within about 40 steps; the denominator stays small for thousands of steps (1 − 0.999ᵗ ≈ 0.001t early on). The ratio first rises (numerator growing faster) and then falls as √(0.001t) grows, peaking around t = 12 at about 6.6, and approaching 1 only after several thousand steps. ∎
Problem 16Level 3
Explain why correction hardly mattered with β₂ = 0.9 in exercise 2.
With β₂ = 0.9, the second moment’s bias factor 1 − 0.9ᵗ reaches 0.99 by t = 44, the same time scale as the first moment’s. The inflation factor (1 − 0.9ᵗ)/√(1 − 0.9ᵗ) = √(1 − 0.9ᵗ) is at most 1, so uncorrected steps are never larger than corrected ones, only slightly smaller for a few dozen steps. With β₂ = 0.999 the two moments warm up on very different time scales, which creates the large inflation. ∎
Problem 17Level 3
Advise on Adam settings for fine-tuning a vision transformer on a small aerial dataset in mixed precision.
Use AdamW (decoupled weight decay) with a small learning rate (around 10⁻⁵ to 10⁻⁴ for fine-tuning), a linear warm-up over the first few hundred steps, and cosine decay. Lower β₂ to about 0.98–0.99 for stability with small batches, and raise ε to about 10⁻⁶ so that tiny v̂ values in low precision do not produce huge steps. Keep bias correction on. Monitor loss spikes: exercise 2 shows that immature second-moment estimates cause them. ∎
Level 4
Problem 18Level 4
Largest spike without correction at η = 0.01, β₂ = 0.999?
0.123.
Problem 19Level 4
Loss at step 50 with correction at η = 0.003, β₂ = 0.999?
0.398.
Problem 20Level 4
Largest spike with correction at η = 0.03, β₂ = 0.999?
0.064.
Coding practice
🐍 Code 1 (Level 1): Adam step
Moments, bias correction, step.
🐍 Code 2 (Level 0): bias-correction factor
1 − βᵗ.
🐍 Code 3 (Level 1): uncorrected inflation
(1 − β₁ᵗ)/√(1 − β₂ᵗ).
🐍 Code 4 (Level 0): averaging window
1/(1 − β).
🐍 Code 5 (Level 1): bias warm-up length
Smallest t with βᵗ ≤ tol.
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
Adam: topic test
10 questions, drawn at random from a bank of 21. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.