What is an optimizer in deep learning?
An optimizer is the rule that turns gradients into weight updates during training. Plain stochastic gradient descent (SGD) moves each weight a fixed fraction of its gradient. Momentum, RMSProp, and Adam add memory of past gradients to move faster along consistent directions and to give each weight its own effective step size.
The optimizer affects how quickly a model trains, which learning rates it tolerates, and sometimes how well it generalizes. Image classifiers such as ResNets are often trained with SGD plus momentum. Transformers and large language models are almost always trained with Adam or its variant AdamW. Optimizer state also costs memory: Adam stores two extra numbers for every parameter.
Key ideas
- SGD updates each weight by the learning rate times its gradient.
- Momentum averages past gradients, speeding up consistent directions and damping oscillation.
- RMSProp divides each step by a running root-mean-square of that weight's gradients.
- Adam combines momentum with RMSProp-style scaling and corrects the bias of both averages.
- Ill-conditioned losses, steep in some directions and flat in others, are where adaptive methods help most.
- Adam and AdamW are the defaults for transformers; SGD with momentum remains common for vision.
Short takes on this topic
Common questions
What is the difference between Adam and AdamW?
Adam implements weight decay by adding it to the gradient, so the adaptive scaling also shrinks the decay for weights with large gradients. AdamW subtracts the decay from the weights directly, separate from the adaptive step. That makes regularization behave as intended, and AdamW is now the standard choice for training transformers.
What learning rate should I use with Adam?
The paper's default of 0.001 is a reasonable start for small models. Large transformers usually use smaller peak rates, from about 1e-4 to 6e-4, with warmup and decay. Fine-tuning a pretrained model often uses 1e-5 to 5e-5.
What does epsilon do in Adam?
Epsilon, 1e-8 by default, is added to the denominator √v̂ to avoid dividing by zero for weights whose gradients are near zero. It also caps the effective step for those weights. Some models raise it, for example to 1e-6, to make training more stable in low-precision arithmetic.
Is stochastic gradient descent the same as mini-batch gradient descent?
In deep learning the terms are used interchangeably. Strictly, SGD estimates the gradient from one example, and mini-batch gradient descent averages it over a small batch such as 32 or 256 examples. Every modern framework's "SGD" optimizer works on whatever batch it is given.
Related explainers
- Gradient Descent — Optimizing by following the slope downhill
- Learning Rate Scheduling — Step decay, cosine annealing, warmup, and the LR range test
- Backpropagation — How networks learn from their mistakes
- Convexity, Minima & Saddle Points — Why some optimization problems are harder than others
- Hyperparameters — The knobs you tune before training begins
- Epochs & Batching — How data is fed to the model in epochs, batches, and shuffles
References
- Kingma & Ba (2014), "Adam: A Method for Stochastic Optimization"
- Loshchilov & Hutter (2017), "Decoupled Weight Decay Regularization"
- Wilson et al. (2017), "The Marginal Value of Adaptive Gradient Methods in Machine Learning"
- Goodfellow, Bengio & Courville (2016), "Deep Learning", chapter 8: Optimization for Training Deep Models
- Zhang et al., "Dive into Deep Learning", section 12.10: Adam
Last updated