L2 regularization adds 2λ∥θ∥22 to the loss, turning the update into θ←θ−η(∇L+λθ); under plain SGD this is exactly equivalent to weight decay θ←(1−ηλ)θ−η∇L. With Adam, however, the gradient term is normalized by v^+ϵ, which divides λθ by the same factor, so the effective decay varies wildly with gradient magnitude — L2 and weight decay are no longer equivalent. AdamW decouples them by applying weight decay directly to the parameters: θ←θ−ηλθ−ηv^+ϵm^.
💡Use Cases
the standard generalization tool for deep networks under Adam/AdamW training, especially LLM pretraining and finetuning; interviews ask for the SGD equivalence derivation, why it breaks under Adam, and AdamW's improvement.
⚡Key Problems Solved
constrains the parameter norm to prevent overfitting. AdamW (Loshchilov & Hutter 2019) fixes the mis-scaled weight decay under Adam: the decay coefficient is constant and independent of gradient magnitude, improving generalization (the paper reports roughly 2% lower test error) and robustness to learning-rate / weight-decay hyperparameters; LLM pretraining (e.g. LLaMA) standardly uses AdamW with weight decay around 0.01–0.1 (an order of magnitude above naive L2's 5e-4).
🎯5 High-Frequency Exam Points
1
Derive the equivalence of L2 regularization and weight decay under plain SGD: write both updates θ←θ−η(∇L+λθ) and θ←(1−ηλ)θ−η∇L and state the equivalence condition.
2
Why are L2 and weight decay inequivalent under Adam? What happens when λθ is divided by v^+ϵ?
3
Write the decoupled AdamW update θ←θ−ηλθ−ηv^+ϵm^ and explain why it generalizes better than Adam + L2.
4
Hyperparameter scale: what is typical for AdamW weight decay (0.01–0.1)? How does it relate to L2's common 5e-4?
5
Does weight decay drive weights all the way to zero? Why does it mostly constrain the norm rather than zero out parameters?