AdamW vs Adam
Decoupled Weight Decay Regularization
Ilya Loshchilov, Frank Hutter
5
Concepts
6
Formulas
5
Demos
Paper Overview
Adam (Kingma & Ba, 2015) is the most widely used optimizer in deep learning, combining momentum (exponential moving average of gradients, ) with adaptive per-parameter learning rates via RMSProp (exponential moving average of squared gradients, ). With bias correction to counteract zero-initialization, Adam automatically scales each parameter's step size inversely proportional to the root-mean-square of its historical gradients — large-gradient parameters get smaller steps, sparse-gradient parameters get larger steps.
However, a subtle implementation detail created a widespread bug across deep learning frameworks: treating weight decay as L2 regularization (adding to the gradient before the adaptive update). In SGD, L2 regularization and weight decay are mathematically equivalent. But in Adam, the L2 gradient term gets divided by alongside the task gradient — meaning the effective regularization strength varies inversely with gradient magnitude. Parameters with large, frequent gradients (large ) are under-regularized, while sparse parameters are over-regularized. This is exactly backwards from what we want.
AdamW (Loshchilov & Hutter, 2019) fixes this by decoupling weight decay from the gradient-based update. Instead of adding to the gradient (which then passes through Adam's adaptive scaling), AdamW applies weight decay as a separate multiplicative step: before the gradient update, where is the learning rate and is the weight decay coefficient. This ensures every parameter shrinks by the same fraction per step, regardless of its gradient history.
This seemingly small change leads to significantly better generalization, especially for Transformers. On CIFAR-10 with a ResNet, Loshchilov & Hutter showed that AdamW achieves the same test accuracy as SGD with momentum — closing a gap that had previously been attributed to Adam being a "worse optimizer." AdamW is now the default optimizer in PyTorch (torch.optim.AdamW), Hugging Face Transformers, and is used to train BERT, GPT-2/3/4, ViT, LLaMA, Stable Diffusion, and virtually all modern architectures. Typical hyperparameters: to , to , , , .
Chapter Roadmap
Click any topic to jump in
SGD + Momentum
Exponential moving average of gradients damps oscillations and averages noise across iterations.
Adam
Adds per-parameter adaptive learning rates via second moment of gradients.
L2 vs Weight Decay
Equivalent in SGD, but Adam's adaptive scaling couples regularization to gradient history, under-regularizing frequent parameters.
AdamW
Decouples weight decay from the gradient update, restoring uniform regularization across all parameters.
When to Use
AdamW is the default for Transformers; hyperparameters tune independently.
Concept by concept
5 sections, in reading order.