SGD with Momentum / Adam Optimizer

Machine Learning
Introduced by
Rumelhart, Hinton & Williams (momentum SGD, 1986); Kingma & Ba (Adam, 2015)
Year
2015
Type
First-order adaptive stochastic optimizer

What does it do?

Stochastic gradient descent (SGD) with momentum and its adaptive successor, Adam, are widely used parameter-update algorithms for training deep learning models.

Momentum SGD was formalised by Polyak (1964) and brought into neural network training by Rumelhart, Hinton, and Williams (1986). Kingma and Ba introduced Adam at ICLR 2015; it combines a running average of gradients with a running average of squared gradients, giving each parameter its own effective step size.

The intuition behind the method

Training a neural network means searching a high-dimensional loss surface for low-loss regions. Plain gradient descent follows the local downhill direction at each step, which can be slow and can zigzag across narrow valleys. Momentum addresses this by accumulating a velocity vector from recent gradients, so steps in consistent directions build up while oscillating components tend to cancel. Adam adds a second running average that tracks how large each parameter's gradients have recently been. Parameters with consistently large gradients receive smaller effective steps, and parameters with small or infrequent gradients receive relatively larger ones. The global learning rate α still has to be chosen, but the per-parameter scaling reduces the need to set separate rates by hand for each layer.

History

The idea of accelerating gradient descent with a momentum term dates to Polyak (1964) in convex optimisation. Rumelhart, Hinton, and Williams (1986) applied momentum to backpropagation training of neural networks. Kingma and Ba (ICLR 2015) introduced Adam, combining momentum with adaptive per-parameter scaling.

When to use it

Adam is a common first choice for training feedforward, convolutional, recurrent, and transformer networks, and other differentiable parametric models, particularly with mini-batch training on large datasets, high-dimensional parameters, or gradients of very different magnitudes across parameters. It is also a reasonable choice when gradients are sparse or the objective is non-stationary, as noted in its original analysis. In some reported image classification experiments, momentum SGD trained from scratch with a carefully designed learning rate schedule has matched or outperformed Adam, although results depend on the task and on how each method is tuned, so it is worth considering when the extra configuration effort is acceptable. Neither method is suitable for objectives that are not differentiable, and both use only first-order gradient information, so they do not exploit curvature. Where a problem is small enough for curvature-aware methods to be practical, those methods may be worth considering instead.

Limitations and considerations

  • The convergence analysis in the original Adam paper is given as a regret bound within the online convex optimisation framework, which does not by itself guarantee convergence for every non-convex deep learning setting. Some studies report that Adam can fail to converge in certain settings, and modified variants have been proposed to address this.
  • Some reported experiments on image classification benchmarks have found that adaptive methods generalise worse than well-tuned SGD with momentum; the size of this effect depends on the task and the training setup.
  • Adam stores two vectors (m and v) the size of the parameter vector. Plain SGD stores none and momentum SGD stores one, so Adam's optimizer state is twice that of momentum SGD.
  • The per-parameter scaling does not remove the need to choose the global learning rate α; a poor choice can still cause instability or very slow progress.
  • Adding L2 regularisation to the gradient in Adam does not behave like weight decay in plain SGD, because the adaptive scaling also rescales the regularisation term, so the effective decay differs between parameters. Decoupled weight decay, which applies the decay directly to the parameters, is a common alternative (as in AdamW).

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Per-parameter adaptive step sizes reduce the need to hand-tune separate learning rates for each layer or parameter group.
  • Memory and per-step computation scale linearly with the number of parameters; the algorithm stores two additional vectors of that size (m and v).
  • Bias correction keeps the early steps correctly scaled, rather than being shrunk by the zero initialisation of the moment estimates.
  • The default settings (α=0.001, β1=0.9, β2=0.999, ε=1e-8) are often a reasonable starting point across many architectures, though they still deserve checking.
  • The per-parameter scaling suits sparse gradients, such as those in embedding layers, where many weights receive zero gradient on a given mini-batch.
  • With a tuned schedule, momentum SGD can be a competitive alternative to Adam in image classification, at the cost of more configuration effort.

Applications

  • Training feedforward, convolutional, and recurrent neural networks on image, text, audio, and tabular data.
  • Fine-tuning pretrained language models, where AdamW with a warmup schedule is a common choice.
  • Training generative models such as GANs, VAEs, and diffusion models, typically with separate optimizer instances for each network component.
  • Optimising neural ordinary differential equations, graph neural networks, and other architectures whose parameters are updated by gradient descent.
  • Hyperparameter and architecture search pipelines that train many models and benefit from Adam's relative insensitivity to hyperparameter choice.

How it works

How it works

1

At each training step, a mini-batch of n examples is drawn from the dataset and the gradient of the loss with respect to the model parameters is computed by backpropagation. Because each gradient is estimated from a subset of the data, it is noisy; this noise is what makes the procedure stochastic, and it keeps each update affordable on large datasets.

Formula
g_t = \nabla_{\theta} \mathcal{L}(\theta_{t-1}; x^{(i:i+n)})
2

Adam keeps an exponentially decaying average of past gradients, the first-moment estimate m_t. The coefficient β1 (default 0.9) sets how strongly earlier gradients persist. This plays the role of the momentum term: it smooths the gradient signal and accumulates progress in directions that keep pointing downhill. Unlike classical momentum, the new gradient is weighted by (1 − β1), so the term is an averaged rather than a summed quantity.

Formula
m_t = \beta_1 m_{t-1} + (1 - \beta_1)\, g_t
3

Adam also keeps an exponentially decaying average of past squared gradients, the second-moment estimate v_t, controlled by β2 (default 0.999). A large v_t for a parameter means its gradients have been large, which reduces that parameter's effective step through the division in the update rule. This per-parameter scaling is the source of Adam's adaptivity.

Formula
v_t = \beta_2 v_{t-1} + (1 - \beta_2)\, g_t^2
4

Because m_t and v_t start at zero, they underestimate their true scale during the first iterations. Dividing by (1 − β^t) corrects this bias, so the estimates have appropriate magnitude from the first update onward and early steps are not artificially small.

Formula
\hat{m}_t = \frac{m_t}{1 - \beta_1^t}, \quad \hat{v}_t = \frac{v_t}{1 - \beta_2^t}
5

The bias-corrected first moment is divided element-wise by the square root of the bias-corrected second moment plus the small constant ε, which guards against division by zero, and the result is scaled by the global learning rate α. Parameters with consistently large gradients take smaller steps, and those with small gradients take larger ones, within the overall scale set by α.

Formula
\theta_t = \theta_{t-1} - \frac{\alpha}{\sqrt{\hat{v}_t} + \varepsilon}\, \hat{m}_t
6

Classical momentum SGD keeps a velocity vector that accumulates the gradient scaled by the learning rate η, decayed by a momentum coefficient μ (commonly 0.9), and subtracts this velocity from the parameters. Compared with plain SGD, the accumulated velocity speeds progress along consistent gradient directions and damps oscillations across the valley. Note that this formula uses v for velocity, whereas in the Adam steps v_t denotes the second-moment estimate, so the two symbols should not be read together.

Formula
v_t = \mu v_{t-1} + \eta \nabla_{\theta} \mathcal{L}(\theta), \quad \theta \leftarrow \theta - v_t

Common pitfalls

  • Adding weight decay to standard Adam through the gradient and assuming it regularises as it would in SGD; AdamW applies decay separately from the adaptive scaling.
  • Keeping the default α=0.001 for fine-tuning pretrained transformers, where much smaller values such as 1e-5 to 5e-5 are typically used.
  • Choosing a large ε, such as 0.1, to stabilise training. ε is added to the square root of the second-moment estimate, so when gradient magnitudes are small a large ε dominates the denominator and reduces the per-parameter adaptivity of the update.
  • Omitting gradient clipping when training recurrent networks or transformers on long sequences, where exploding gradients can still occur.
  • Using a fixed learning rate throughout; warmup followed by a decay schedule is commonly used and often improves final performance, but the benefit depends on the task.

Frequently asked questions

Should I use Adam or SGD with momentum for training a new deep learning model?

Adam is often the simpler starting point because it usually requires less learning rate tuning and tends to converge across a range of architectures. SGD with momentum can reach comparable or slightly better generalisation on some image classification tasks when a learning rate schedule is carefully designed, but it takes more effort to configure. For NLP and transformer models, AdamW is a common choice.

What is the difference between Adam and AdamW?

Standard Adam adds the L2 weight decay term to the gradient before the adaptive scaling, so the effective regularisation strength varies with each parameter's gradient history. AdamW applies weight decay directly to the parameters, separately from the adaptive gradient update. This decoupling is the reason AdamW is often recommended when fine-tuning large pretrained models.

Why does Adam sometimes generalise worse than SGD?

Some reported experiments on image classification benchmarks have found that adaptive methods such as Adam can generalise worse than well-tuned SGD with momentum. The cause is not settled, and the size of the effect depends on the task and the training setup, so the choice should be checked on validation data for the problem at hand.

How should I set the learning rate for Adam?

The default α=0.001 is a common starting point for training from scratch, but it is worth checking with a short learning rate range test. For fine-tuning pretrained transformers, values in the range 1e-5 to 5e-5 are typically used. Many practitioners combine Adam with a warmup phase over the first few percent of training steps, followed by a decay schedule, though the exact settings depend on the task.

Related methods

Sources

  1. Kingma, D. P., & Ba, J. (2015). Adam: A method for stochastic optimization. International Conference on Learning Representations (ICLR 2015). arXiv:1412.6980.

    Open publication reference
  2. Rumelhart, D. E., Hinton, G. E., & Williams, R. J. (1986). Learning representations by back-propagating errors. Nature, 323, 533–536.

    Open DOI reference
  3. Polyak, B. T. (1964). Some methods of speeding up the convergence of iteration methods. USSR Computational Mathematics and Mathematical Physics, 4(5), 1–17.

    Open DOI reference
  4. Goodfellow, I., Bengio, Y., & Courville, A. (2016). Deep Learning (Ch. 8: Optimization for Training Deep Models). MIT Press.

    ISBN: 978-0-262-03561-3