TL;DR
Adam is a training method that gives every weight its own step size. Its usual weight decay, an L2 penalty added to the gradient, is weaker than intended, because Adam's adaptive scaling quietly shrinks the penalty for weights that have had large gradients. In 2017 Ilya Loshchilov and Frank Hutter proposed AdamW, which subtracts the decay directly from the weights. On image benchmarks this made Adam generalise much better and brought it close to SGD with Momentum.
Builds on: Adam Optimizer, L2 Regularization, Stochastic Gradient Descent · Leads to: AdamW Optimizer, the method this paper introduces
Why it mattered
Language models. Later Transformer training recipes widely use AdamW, so a recipe that sets weight decay for a large model usually means the decoupled form.
Standard libraries. Once the decoupled form was published, deep learning libraries added AdamW as a built-in optimizer. Before that, they offered only L2 regularization under the name "weight decay", which is the naming confusion the paper addresses.
Choosing an optimizer. Before this paper, practitioners often had to choose between Adam, which trained quickly, and SGD with momentum, which generalised better on image tasks. The paper's stated goal was to make Adam competitive enough that people no longer need to switch.
The problem
Weight decay is a penalty that pulls weights towards zero so that the model does not fit noise. The usual way to implement it is an L2 penalty: add to the loss, whose gradient is .
For plain Gradient Descent the two ideas are the same. Shrinking each weight by a fixed fraction and adding the L2 gradient give identical steps, once the L2 strength is scaled by the learning rate. The paper calls this its Proposition 1.
The trouble starts with adaptive methods. Adam divides each weight's update by the square root of its recent squared gradients. If the penalty is added to the gradient, the penalty is divided by that same number. A weight with a long history of large gradients therefore receives only a small share of its penalty. The paper states the consequence directly: weights with large historic gradients are regularized less than they would be under decoupled weight decay.
The experiments show the cost. Adam trailed SGD with momentum, whose L2 penalty behaves as expected, and the authors argue that this gap is caused by the regularizer, not by adaptivity itself.
How it works
The change to Adam is one line, and it is easiest to see on one weight. Here is the pipeline in the order the update runs.
- Take the loss gradient for the current batch. It contains no penalty.
- Update Adam's two running averages of and of , and correct their start-up bias.
- Form the adaptive step: the averaged gradient divided by the root of the averaged squared gradient, times the learning rate.
- Compute the decay term from the current weights. Do not add it to the gradient.
- Subtract the adaptive step and the decay term from the weights together.
flowchart LR
G["Loss gradient (no penalty)"] --> A["Adam averages, bias corrected"]
A --> S["Adaptive step"]
W["Current weights"] --> D["Decay term: lambda times weights"]
S --> U["Subtract both from the weights"]
D --> U
U --> N["New weights"]
Now trace one weight through the pipeline. Take , decay , learning rate , schedule multiplier , and a loss gradient of at the first step, so only the penalty acts.
- The loss gradient is .
- AdamW: the adaptive part is , because both averages are . The decay term is . The update subtracts it: . Check: the weight shrank by , which is percent.
- Adam with L2: the penalised gradient is . The bias-corrected averages are and , so and the adaptive ratio is . The update is . Check: the weight shrank by , which is percent.
- Interpret. The same penalty gave different shrinkage. In the L2 version the penalty was divided by , so its size depended on this weight's gradient history. With a longer history of large gradients the same penalty would have shrunk the weight far less. AdamW's decay never passes through that division.
The plot shows the same point over a range of gradient histories. The flat line is AdamW's decay, which does not depend on the history. The curve is the L2 penalty's relative strength, which falls as the historical gradient scale grows.
- L2 inside Adam
- AdamW
The math
For a loss with batch gradient , Adam with decoupled weight decay (AdamW) updates the weights by the adaptive step and a separate decay term, with the decay strength kept out of the averages.
Write for the base learning rate, for a schedule multiplier (1 for a fixed rate), and for the decay rates of the two averages, and for a small constant. The paper's defaults are , , and . All operations on vectors are element by element.
Step 1 in symbols: the gradient
The gradient is computed from the data loss alone. Nothing in it depends on .
Step 2 in symbols: the averages
Because both start at zero, they are corrected for their start-up bias:
Step 3 in symbols: the adaptive step
Step 4 in symbols: the decoupled decay
The update is
This is the paper's decoupled update. The decay term is not multiplied by . With and a zero loss gradient, each step multiplies the weight by , the same form as ordinary weight decay. That is the sense in which the decay is decoupled: its size is set by and , and the adaptive scaling never touches it.
Step 5 in symbols: the L2 version
With L2 inside Adam, the penalty is added to the gradient before the averages:
The penalty's contribution to the step is now , which is divided by the weight's gradient scale. The paper's Propositions 1 and 2 make this precise. For SGD the two forms are equivalent when the L2 strength is set to . For Adam no single L2 strength reproduces the decoupled update. The reason is that Adam's per-weight scaling is not the same for every weight, so the penalty cannot be matched across weights with one constant.
Results
The main comparison. On image classification benchmarks (CIFAR-10 and a downsampled ImageNet), AdamW generalises better than Adam with L2, and the gain holds across the learning-rate schedules the paper tries.
Hyperparameter landscape. With L2, the good settings for learning rate and weight decay are coupled, so changing one alone hurts. With decoupled decay the good settings are much closer to independent, so the two can be tuned separately. This is the paper's main practical argument: the search is easier.
Long runs. In long training runs AdamW reaches lower test error than Adam with L2. The authors read the gain as a generalisation effect, not only faster convergence.
Warm restarts. Adding warm restarts with cosine annealing (AdamWR) speeds up AdamW, and it narrows the gap to SGD with warm restarts.
Normalized weight decay. The best raw decay value depends on how long the run is and on the batch size. The authors propose a normalized form that scales the decay with those quantities, so one setting carries across runs. They present it as one possible choice, not the only one.
Limits. The experiments are on image classification only, mostly CIFAR-10 and ImageNet32x32 with small residual networks. The authors say their results must be checked on a wider range of tasks, especially ones where regularization matters. The gap to SGD is closed "most of the way", not fully, and the paper does not claim that Adam always beats SGD.
Reading guide
- Abstract and Section 1. The five observations are the paper's claims in order. Needs Adam Optimizer, Stochastic Gradient Descent and Momentum.
- The method section. The core of the paper. Needs L2 Regularization and Gradient Descent. Read the two update rules side by side, then the propositions that compare them.
- The experiments on schedules and hyperparameters. The schedule and hyperparameter plots. Needs Learning Rate. Pay attention to the axes of Figure 2.
- Sections 4.3 to 4.5. Long runs, warm restarts and other uses. Needs Overfitting and Convolutional Neural Network for the generalisation discussion.
- Appendix B. Normalized weight decay and AdamWR. Needs the idea of a learning-rate schedule that decreases on a cosine curve and restarts. Take the square-root rule as an empirical choice, which the authors call one possibility among many.
Check yourself
QuestionRecall: what is the form of weight decay that this paper argues is correct for Adam, and where does the decay enter the update?Show answer
It is decoupled weight decay, the update used by AdamW. The decay term is subtracted from the weights together with the adaptive step, and it is not added to the gradient, so the adaptive averages never see it.
QuestionComputation: a weight equals , the decay is , the schedule multiplier is , the learning rate is , and the loss gradient is zero at every step so far. What is the weight after one step under AdamW, and under Adam with L2 inside? Ignore .Show answer
Under AdamW the decay term is , the adaptive part is zero, so the new weight is . Under Adam with L2 the penalised gradient is . Then , , and the adaptive ratio is . The update is , so the new weight is . AdamW shrank the weight by half, and L2 inside Adam shrank it by one percent.
QuestionWhy: explain why an L2 penalty inside Adam is weaker for weights whose gradients have been large.Show answer
Inside Adam the penalty is part of the gradient, and the adaptive step divides the whole gradient by , the typical size of that weight's past gradients. A large history gives a large , so the penalty's share of the step is small. AdamW subtracts the decay outside that division, so every weight shrinks by the same fraction.
QuestionApplied: a model is trained with AdamW, with decay and a schedule multiplier that falls over training. You want the weights to be shrunk less near the end of training, without changing the learning rate or . Which quantity should you change, and why does changing it leave the adaptive step alone?Show answer
Change the schedule multiplier . In Algorithm 2 the decay per step is , so lowering weakens the decay without touching or . The adaptive step is , so lowering also shrinks the adaptive step. The two terms are scaled together, so the schedule changes the overall pace of the update, while the ratio between decay and adaptive step stays the same. Changing alone would change only the adaptive step, not the decay.