Abstract
This paper reveals that the common practice of using $L_2$ regularization as a proxy for weight decay is fundamentally flawed for adaptive gradient methods like Adam. By "decoupling" the weight decay step from the gradient-based update, we introduce AdamW, an optimizer that significantly improves generalization performance and simplifies hyperparameter tuning. Our findings demonstrate that with this modification, Adam can finally match or exceed the performance of Stochastic Gradient Descent (SGD) on major image classification benchmarks.
The Problem: Inequivalence of $L_2$ Regularization and Weight Decay
In deep learning, regularization is essential for model generalization. Two common techniques are $L_2$ regularization (adding a penalty to the loss function based on the square of the weights) and weight decay (directly shrinking weights at each step). While these are mathematically equivalent for standard SGD, they diverge for adaptive optimizers like Adam.
In adaptive methods, $L_2$ regularization is "adapted" alongside the gradients. Because Adam scales updates by the inverse of the moving average of squared gradients, the $L_2$ penalty is effectively divided by that same moving average. This means weights with large historic gradients are regularized less than intended, leading to poor generalization and a frustrating coupling of hyperparameters: changing the learning rate typically requires re-tuning the regularization strength.
Methods: Decoupled Weight Decay
The authors propose Decoupled Weight Decay as a simple yet profound fix. Instead of adding the regularization term to the loss function before calculating gradients, they apply the weight decay directly to the parameters after the gradient-based update step. This leads to two new variants: SGDW and AdamW.
The paper also introduces two complementary techniques:
- Normalized Weight Decay: A method to scale the weight decay factor based on the total number of training steps, making the optimal hyperparameter more stable across different training budgets.
- Warm Restarts (AdamWR): Combining AdamW with a cosine annealing learning rate schedule and periodic "restarts" to improve "anytime" performance—getting better results faster.
Key Insights
Hyperparameter Independence
A major practical takeaway is the decoupling of the learning rate and the weight decay factor. In standard Adam implementations, the "sweet spot" for these hyperparameters is often a narrow diagonal, meaning they are tightly coupled. In AdamW, this region becomes a much broader, more rectangular space, making it significantly easier to find optimal settings.
The Inequivalence Trap
The "aha moment" is realizing that in Adam, $L_2$ regularization is not weight decay. Decoupling ensures every weight decays at the same rate, regardless of its gradient history. Furthermore, while Adam is "adaptive," it still benefits immensely from a global learning rate schedule like cosine annealing. AdamW combined with these schedules can finally match the performance of tuned SGD with momentum.
Key Results
The quantitative improvements are substantial across standard benchmarks like CIFAR-10, CIFAR-100, and ImageNet32x32:
- Generalization: AdamW achieved a 15% relative improvement in test error compared to standard Adam on CIFAR-10.
- Competitive Performance: With decoupled weight decay, AdamW became competitive with state-of-the-art SGD results on image tasks where Adam previously struggled.
- Speedup: Using warm restarts (AdamWR), the researchers achieved top-tier results up to 10x faster than standard training approaches in some scenarios.
Conclusion
By identifying and fixing the flawed implementation of weight decay in adaptive optimizers, this paper provides a more robust and easier-to-tune alternative to standard Adam. AdamW has since become a standard in the deep learning community, particularly for training Transformers and other large-scale models where generalization is paramount.
Summary updated