AdamW and Decoupled Weight Decay
The most popular deep learning optimizer had a subtle bug for years: its built-in weight decay silently got tangled up with its adaptive learning rate, and untangling the two into what is now called AdamW measurably improved training.
Prerequisites: RMSProp and AdaGrad, Regularization as a Prior
Weight decay is a simple, old idea: at every update, shrink every weight slightly toward zero, which discourages the model from relying on any single weight too heavily and tends to improve generalization. For plain gradient descent, adding weight decay is equivalent to adding an penalty to the loss — they amount to the same update. Adam, the most widely used optimizer in deep learning, also lets you add weight decay this way. The surprising finding is that for Adam, doing it the "add to the loss" way is subtly wrong, and fixing it — decoupling weight decay from the gradient-based update entirely — is what AdamW does.
The analogy: rent that scales with your income versus rent that doesn't
Imagine a landlord who charges rent proportional to how volatile your recent income has been — a bigger discount in a slow month, a bigger charge in a busy one. That is what happens if you fold weight decay into the loss and let Adam's adaptive step-size machinery process it: Adam divides every gradient, including the "shrink toward zero" signal from the decay term, by each parameter's own adaptive scale. So a parameter that has been getting large, noisy gradients has its decay diluted, while a parameter with small gradients gets decayed relatively harder — a coupling nobody asked for. AdamW instead charges flat rent, in a fixed amount, decoupled from how your income has been behaving: the decay is applied as its own separate, plain shrinkage step, untouched by Adam's adaptive scaling.
The mechanics
Ordinary "-regularized Adam" adds the decay to the gradient before Adam's adaptive scaling touches it:
Here is the decay strength, the current weight, and are Adam's momentum and adaptive-variance estimates — the decay term gets folded into and then divided by along with everything else, so its effective strength varies parameter by parameter.
AdamW instead keeps the decay completely separate from that division:
In words: take Adam's usual adaptively-scaled step, and then, as a fully separate operation, shrink the weight by a fixed fraction — the same fractional shrinkage for every parameter, regardless of that parameter's gradient history.
Worked example 1: the coupling effect
Two weights, both currently at value , with decay and learning rate . Weight A has a large adaptive scale (noisy gradients); weight B has a small one, (quiet gradients). Under -in-the-loss Adam, the decay contribution to the gradient is for both, but it then gets divided: A's effective decay push is , B's is — a tenfold difference in how hard the two weights are actually decayed, purely because of unrelated gradient noise.
Worked example 2: AdamW's flat decay
Same two weights under AdamW: the decay step is for both A and B, regardless of their adaptive scales — every weight gets shrunk by the same of its value this step. That predictable, uniform shrinkage is what makes weight decay behave the way it is supposed to: a knob for overall model complexity, not one whose effect depends unpredictably on each parameter's recent gradient noise.
What this means in practice
AdamW is now the default optimizer for training transformers and most modern deep networks precisely because of this fix — Loshchilov and Hutter showed it closes a measurable generalization gap that plain "Adam with regularization" left on the table, at no extra computational cost. If a training recipe specifies "Adam" with a weight decay hyperparameter, check whether the actual implementation is coupled or decoupled — most modern deep learning frameworks now default to AdamW under the hood, but older or custom code may not.
Adam's adaptive per-parameter scaling silently distorts an penalty folded into the loss; AdamW decouples weight decay into its own flat, fixed-fraction shrinkage step so every parameter gets decayed by the same proportion regardless of its gradient history.
Practice
- Two weights have adaptive scales and . Under -in-loss Adam with , what is each weight's effective decay push?
- Under AdamW with , , , what is the flat decay applied?
- Why does plain SGD not have this coupling problem in the first place?
People often assume "Adam with weight decay set to a nonzero value" and "AdamW" are the same thing. They are not: the first folds decay into the gradient and lets Adam's adaptive division distort it; the second applies decay as a separate, undistorted step. Swapping one implementation for the other with the same value can change training outcomes meaningfully, so treat them as different optimizers, not interchangeable spellings of the same idea.
Related concepts
Practice in interviews
Further reading
- Loshchilov & Hutter, Decoupled Weight Decay Regularization (2019)
- Kingma & Ba, Adam: A Method for Stochastic Optimization (2015)