Skip to content

Decoupled Weight Decay Regularization (AdamW)

optionalextendedfundamentalpaperrubric 8/122019 · ICLR 2019 · ~20 min

Ilya Loshchilov, Frank Hutter

Status

TL;DR. “Weight decay” and “L2 regularisation” are treated as the same thing in many libraries. That is true for SGD, but for Adam it is false. With L2 added to the loss, the decay gradient is divided by Adam’s per-weight scale, so weights with large historical gradients are barely regularised. AdamW applies the decay directly to the weights, separate from the adaptive step. This improves generalisation and makes the learning rate and weight decay easier to tune independently. It is now the default optimizer for transformers and LLM pretraining.

AdamW changes one line of Adam:

θt=θt−1−ηt(α m^tv^t+ϵ+λ θt−1),\theta_{t} = \theta_{t-1} - \eta_t\Big(\alpha\,\frac{\hat m_t}{\sqrt{\hat v_t}+\epsilon} + \lambda\,\theta_{t-1}\Big),

where ηt\eta_t is the schedule multiplier. In Adam with L2, λθ\lambda\theta is instead added to the gradient before mm and vv are computed. The paper proves three statements:

  1. For SGD, decay λ\lambda equals L2 with λ′=λ/α\lambda' = \lambda/\alpha, which is why the best L2 value moves with the learning rate.
  2. For adaptive methods, no L2 coefficient reproduces decoupled decay.
  3. With a fixed preconditioner diag(s)−1\mathrm{diag}(s)^{-1}, decoupled decay equals L2 on θ⊙s\theta\odot\sqrt{s}, so weights with large gradients are regularised more than under plain L2.

Results. On CIFAR-10 and ImageNet32x32, AdamW gives a 15% relative improvement in test error over Adam with L2 at the default learning rate 0.001. It reaches similar training loss with better generalisation and becomes competitive with SGD with momentum. Adding warm restarts (AdamWR) improves anytime performance, with speedups of up to 10× at the first restart.

  • Muon — Moonlight found that adding AdamW-style weight decay was needed for Muon at scale.
  • μP — learning-rate transfer across widths for Adam-family optimizers.
  • CS336 — implements AdamW from scratch and discusses which parameters to decay.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Show that SGD with decoupled weight decay θ ← (1 − λ)θ − α∇f takes the same steps as plain SGD on f + (λ′/2)‖θ‖² with λ′ = λ/α. Then, using the PyTorch convention where each step multiplies weights by (1 − ηλ), compute how much a weight with no gradient shrinks after 100,000 steps at η = 3e-4 and λ = 0.1.

    What a strong answer covers
    • SGD on the regularised loss: θ ← θ − α(∇f + λ′θ) = (1 − αλ′)θ − α∇f; setting αλ′ = λ gives λ′ = λ/α, so the two are identical.
    • The equivalence ties the best L2 coefficient to the learning rate, so changing α means retuning λ′, which is why the two hyperparameters look coupled.
    • Shrink factor (1 − 3e-5)^100000 ≈ exp(−3) ≈ 0.05, so weights the gradient does not support fall to about 5% of their value.
    • The effective decay depends on the product ηλ and the number of steps, so changing the schedule or training length changes the regularisation.
  2. Mechanism

    Explain why adding L2 regularisation to the loss and then running Adam regularises weights with large historical gradients less than weights with small gradients, and how AdamW's decoupled decay changes this. Use Proposition 3 (fixed preconditioner) to say what loss AdamW actually minimises.

    What a strong answer covers
    • With L2 in the loss, the decay term λθ is added to the gradient and then divided by √v; weights with a large gradient history have a large √v, so their decay is shrunk.
    • AdamW applies θ ← θ − ηλθ outside the preconditioner, so every weight decays at the same relative rate.
    • With a fixed preconditioner diag(s)⁻¹, decoupled decay equals L2 on θ ⊙ √s: weights with large s (large gradients) are regularised more than under plain L2.
    • Since Adam's preconditioner changes over time, this equivalence is only approximate, but it shows the two methods optimise different objectives.
  3. Design

    You are pretraining a 1B model with AdamW and want to scale to 8B with twice the steps. Decide which parameters get weight decay, how to set λ when the step count changes, and what you would monitor to tell whether decay is too strong or too weak.

    What a strong answer covers
    • Common practice excludes biases, LayerNorm/RMSNorm gains and often embeddings from decay, because shrinking them is not regularisation in the usual sense.
    • The total decay depends on ηλ times the number of steps; with twice the steps, keep the product of λ and the run length roughly constant (the paper's normalised decay λ = λ_norm √(b/(BT)) is one rule).
    • Monitor weight norms per layer: steadily growing norms suggest decay is too weak; norms collapsing with rising loss suggest it is too strong.
    • Tune λ and the learning rate on a small proxy; AdamW makes the good region in (η, λ) more separable, so the search can be done one axis at a time.

Done with this page?

Status