Skip to content
StackDecode
AI & ML Atlas
Neural NetworksoptimiserInteractive simulation

AdamW Optimisation

Adam with weight decay applied correctly, separate from the gradient.

The idea

In Adam, adding L2 regularisation to the loss gets rescaled by the adaptive denominator and so is not true weight decay. AdamW shrinks the weights directly (θ ← θ − η·λ·θ) in the update, independent of the adaptive step. It regularises better and is the standard for training transformers.

θ ← θ − η (m̂/(√v̂ + ε) + λθ)

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

  • current weights
  • minimum
  • last update

Start somewhere on the bowl. Rings are lines of equal loss; the minimum is at the centre.

step:
0
loss:
3.4617
1/61

Loss landscape seen from above: a long narrow valley. Final loss 0.0003.

Step by step

  1. 1Compute the Adam update from the gradient.
  2. 2Subtract the adaptive step from the weights.
  3. 3Also shrink the weights by η·λ·θ (decoupled decay).
  4. 4Repeat each step.

Where it is used

Training large language models and vision transformers.

Watch out for

The decay strength λ must be tuned and usually excludes biases and norm parameters.

Related