How does the Adam optimizer work?
Plain gradient descent moves every weight by the same learning rate times its gradient. Adam, short for adaptive moment estimation, keeps two running averages per weight: the mean of recent gradients (momentum) and the mean of their squares. It divides the first by the root of the second, so weights with large, noisy gradients take smaller steps and weights with small, steady gradients take larger ones. The paper describes it as computationally efficient, light on memory and suited to noisy or sparse gradients (Kingma and Ba, arXiv:1412.6980, submitted 22 December 2014, read 26 November 2026). Adam gives each parameter its own effective step size, so one global learning rate matters less than with plain gradient descent.
What are Adam’s default settings?
In PyTorch, torch.optim.Adam defaults to lr=1e-3, betas=(0.9, 0.999), eps=1e-8 and weight_decay=0 (PyTorch source, adam.py, read 26 November 2026). The two betas set how fast the gradient average and squared-gradient average forget the past; eps avoids division by zero. Most of the time only the learning rate needs tuning. For fine-tuning a large pretrained model, start far lower than 1e-3.
What is the difference between Adam and AdamW?
AdamW keeps the same update but applies weight decay separately from the gradient, which makes regularization behave predictably. PyTorch’s AdamW defaults to weight_decay=1e-2 (PyTorch source, adamw.py, read 26 November 2026, file). If you use weight decay at all, prefer AdamW over Adam.
When should you use Adam instead of SGD?
| Adam / AdamW | SGD with momentum | |
|---|---|---|
| Step size | Adaptive per parameter | One global rate |
| Tuning effort | Lower, defaults often work | Higher, needs a schedule |
| Memory | Two extra values per weight | One extra value per weight |
| Typical use | Transformers, fast first results | Tasks where generalization is checked closely |
Start with AdamW, and switch to SGD only if validation results justify the tuning. Reddi, Kale and Kumar give an explicit simple convex example where Adam does not converge to the optimal solution (arXiv:1904.09237, read 26 November 2026), and Wilson et al. found that solutions from adaptive methods often generalize worse than SGD, even with better training performance (arXiv:1705.08292, read 26 November 2026). See the overfitting entry for checking generalization, and compare on held-out data. Watch the loss function curve and the batch size, which interacts with the best learning rate.