Weight Decay vs L2 Regularization
Why weight decay and L2 regularization give the same update rule under plain SGD but diverge once you use an adaptive optimizer like Adam — the distinction AdamW was built to fix.
L2 regularization adds a penalty to the loss function, so the optimizer is minimizing loss plus a term that punishes large weights. Weight decay is a direct update rule: at every step, shrink each weight by a fixed fraction, , before applying the gradient step. Under plain stochastic gradient descent these turn out to be exactly equivalent, because the gradient of the L2 penalty term added to the loss gradient produces precisely that same shrinkage.
The equivalence breaks under Adam and similar adaptive optimizers, which rescale each parameter's update by a running estimate of that parameter's gradient magnitude:
If you implement "regularization" as an L2 penalty added to the loss (as most deep learning frameworks did by default for years), the penalty's gradient gets divided by along with everything else — so parameters with large historical gradients get less shrinkage than intended, and parameters with small gradients get more, an unintended and parameter-dependent side effect nobody asked for. Applying weight decay as a direct multiplicative shrink instead (, applied separately from the adaptive gradient step) avoids this entirely — that's the whole idea behind AdamW.
Worked example. Suppose , , and a parameter's adaptive denominator . L2-as-penalty shrinks the weight by (10x amplified by the small denominator). Decoupled weight decay shrinks it by regardless of — the intended, denominator-independent amount.
L2 regularization and weight decay are the same thing under plain SGD, but under Adam the L2-as-penalty version gets warped by the adaptive per-parameter learning rate, while true (decoupled) weight decay shrinks every weight by the same intended fraction — the fix AdamW implements.
Practice in interviews
Further reading
- Loshchilov and Hutter (2019), Decoupled Weight Decay Regularization