Skip to content

AdamW takes weight decay out of the gradient

For plain SGD, adding an L2 penalty λ/2·‖θ‖² to the loss and shrinking the weights by a factor each step are the same update. Many libraries therefore treat "weight decay" and "L2 regularization" as one setting. The paper shows this is "not the case for adaptive gradient algorithms, such as Adam."

In Adam with an L2 term, the penalty's gradient λθ is added to the loss gradient before Adam computes its moving averages. Adam then divides the whole thing by the square root of its running second moment. A weight with a history of large gradients receives a small share of the decay, and a weight with small gradients a large one.

AdamW leaves the penalty out of the gradient. It takes the usual Adam step and subtracts λθ from the weights in the same update, scaled by the schedule multiplier ηₜ, not folded into the gradient (Algorithm 2). Every weight decays at the same relative rate, whatever its gradient history.

Why bother? The authors report that this decoupling makes the best learning rate and the best weight decay less dependent on each other, so the two are easier to tune. The paper also reports about 15% relative improvement in test error over Adam on CIFAR-10 and ImageNet32x32 (§4.4).

When a training recipe says "weight decay 0.1," check whether the optimizer is Adam with an L2 term or AdamW. They are different updates.

Loshchilov and Hutter, ICLR 2019, §2, Algorithm 2, and §4