Skip to content

Adam and Other Optimizers

Improved versions of gradient descent. Momentum keeps the ball rolling; Adam also gives each weight its own step size based on how large its gradients have been.

Also optimizers · momentum · RMSProp · AdamW · SGD with momentum · adaptive learning rate

Fig. / How it works
SAME STEPS: ADAM (●) SETTLES, PLAIN GD (○) ZIGZAGS
Role · kind
TrainingTechnique
Level
Intermediate

Kingma and Ba, 2014

Plain gradient descent takes the same careful step every time. Momentum is like a ball that builds up speed downhill. Adam is a hiker who takes longer strides on gentle, consistent slopes and shorter ones on bumpy terrain.

Where it fits

+All relationships as a list

See it on the full map

Try it

Roll downhill: gradient descent, momentum and Adam
Loading interactive widget…
TakeawaySame landscape, same starting point, different update rules. The learning rate decides whether you crawl, glide or fly off the map.

How it works

Plain gradient descent uses one learning rate for every weight and reacts only to the current gradient. Two ideas fix its main weaknesses:

  • Momentum: keep a running average of recent gradients and step along it. Zig-zags across a narrow valley cancel out, while consistent downhill directions build up speed.
  • Adaptive step sizes (RMSProp): keep a running average of each weight’s squared gradients and divide by its square root. Weights with large, noisy gradients take smaller steps; weights with tiny gradients take bigger ones.

Adam (2014) combines both, with a small correction for the first few steps when the averages are still near zero. In practice it trains most networks well with its default settings, which is why it became the default. AdamW fixes how weight decay (regularization) interacts with the adaptive steps and is the standard for Transformers.

The 3D widget lets you race plain gradient descent, momentum and Adam on the same landscape.

The math

With gradient gtg_t, decay rates β1,β2\beta_1, \beta_2 and learning rate η\eta:

mt=β1mt−1+(1−β1)gt,vt=β2vt−1+(1−β2)gt2m_t = \beta_1 m_{t-1} + (1-\beta_1) g_t, \quad v_t = \beta_2 v_{t-1} + (1-\beta_2) g_t^2θt=θt−1−ηm^tv^t+ϵ,m^t=mt1−β1t, v^t=vt1−β2t\theta_t = \theta_{t-1} - \eta \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}, \quad \hat m_t = \frac{m_t}{1-\beta_1^t}, \ \hat v_t = \frac{v_t}{1-\beta_2^t}

Everyday use cases

  • Case 01

    Training language models

    Large language models are typically trained with AdamW.

  • Case 02

    A sensible default

    For a new neural network, Adam with its usual settings is a reliable first choice.

Strengths, weaknesses and when to use it

Strengths

  • Works well with little tuning across many problems.
  • Handles parameters whose gradients differ wildly in scale.

Weaknesses

  • Stores two extra numbers per parameter, which costs memory in huge models.
  • Plain SGD with momentum sometimes generalizes slightly better in vision.

When to use itAs the default optimizer for neural networks; AdamW for Transformers.

Compare with

Check yourself

  1. Q01

    What does Adam adapt for each parameter?

    Show answer

    A: Its step size

  2. Q02

    Why does momentum help in a long, narrow valley?

    Show answer

    A: It averages out the zig-zag across the valley and builds speed along it

Go deeper

Learn first