AdamW, short for Adam with decoupled weight decay, is a gradient-based optimizer that applies weight decay directly to the parameters instead of adding an L2 penalty to the gradient that Adam then rescales. Training of transformers, vision models and most large language models in artificial intelligence relies on AdamW as the default optimizer, because it combines Adam’s fast, adaptive steps with predictable regularization.
Ilya Loshchilov and Frank Hutter proposed the method in their paper on decoupled weight decay, showing that L2 regularization and weight decay are not equivalent for adaptive optimizers. The fix is small in code but changes how well models generalize and how hyperparameters interact.
Why Adam needed decoupled weight decay
In plain stochastic gradient descent, adding an L2 penalty to the loss and applying weight decay produce the same update, up to a rescaling of the coefficient. In Adam, the gradient is divided by a running estimate of its per-parameter magnitude, so the L2 term is divided too. Parameters with large historical gradients therefore receive much weaker regularization than parameters with small gradients.
This coupling makes regularization uneven and hard to tune. AdamW removes the penalty from the gradient and subtracts a fraction of each weight in a separate step, so every parameter decays at the same relative rate regardless of its gradient history.
The table contrasts the two ways of regularizing an adaptive optimizer.
| Property | Adam with L2 penalty | AdamW |
|---|---|---|
| Where decay enters | Added to the gradient | Applied directly to the weights |
| Effect of adaptive scaling | Decay is rescaled per parameter | Decay is not rescaled |
| Regularization strength | Uneven across parameters | Uniform relative shrinkage |
| Coupling with learning rate | Strong and hard to separate | Weaker, easier to tune |
| Typical generalization | Often worse than tuned SGD | Comparable or better |
How the AdamW update works
AdamW keeps Adam’s two exponential moving averages: the first moment m (a momentum term) and the second moment v (the average squared gradient). After bias correction, the adaptive step is lr * m_hat / (sqrt(v_hat) + eps). The decoupled decay then subtracts lr * wd * w from each weight, where wd is the weight decay coefficient.
- Compute the gradient of the loss for the current mini-batch.
- Update the first moment with coefficient
beta1and the second moment withbeta2. - Apply bias correction, which matters most in the first few hundred steps.
- Take the adaptive gradient step scaled by the learning rate.
- Shrink every decayed weight by
lr * wd, independent of the gradient.
In common implementations such as PyTorch, the decay term is multiplied by the learning rate, so a learning rate schedule also scales the decay. The original paper described a separate schedule multiplier; practitioners should check which convention their framework uses before copying hyperparameters between codebases.
Key hyperparameters and typical values
AdamW has five main hyperparameters. The learning rate and weight decay usually need tuning, while the moment coefficients are often left near their defaults, except in large-scale language model pretraining.
| Hyperparameter | Typical range | What it controls |
|---|---|---|
| Learning rate | 1e-5 to 1e-3 | Size of the adaptive step |
| Weight decay | 0.01 to 0.1 | Fraction of each weight removed per step, scaled by the learning rate |
| beta1 | 0.9 | Memory of the momentum average |
| beta2 | 0.95 to 0.999 | Memory of the squared-gradient average |
| epsilon | 1e-8 to 1e-6 | Numerical stability of the denominator |
Large language models often use beta2 of 0.95 rather than 0.999, because a shorter memory reacts faster to sudden gradient changes and reduces loss spikes. Fine-tuning runs typically use smaller learning rates and weight decay around 0.01 to 0.1, combined with learning rate warmup and a cosine or linear decay schedule.
A widespread practice is to exclude biases and normalization parameters from weight decay. Shrinking LayerNorm gains or bias terms toward zero rarely helps generalization and can destabilize training, so parameter groups with zero decay are standard in transformer code.
AdamW compared with other optimizers
AdamW is one of several optimizers used in deep learning, and each trades memory, speed and tuning effort differently. The comparison below summarizes the most common neighbors.
| Optimizer | State per parameter | Strength | Weakness |
|---|---|---|---|
| SGD with momentum | One buffer | Strong generalization in vision | Sensitive to learning rate |
| Adam | Two buffers | Fast, adaptive convergence | Coupled L2 regularization |
| AdamW | Two buffers | Adaptive steps with clean decay | Higher memory than SGD |
| Adafactor | Factored second moment | Low memory for huge models | Less stable without tuning |
| Lion | One buffer | Lower memory, sign-based update | Needs smaller learning rates |
The memory cost matters at scale: with 32-bit optimizer states, AdamW stores two extra values per parameter, which for a 7-billion-parameter model adds roughly 56 GB of optimizer state. Techniques such as 8-bit optimizers and sharded states reduce this burden.
Common mistakes when using AdamW
Most problems with AdamW come from hyperparameter conventions rather than the algorithm itself. Mixing up Adam and AdamW settings is a frequent source of silent underperformance.
- Reusing Adam’s L2 coefficient as AdamW weight decay; values like 1e-4 are often far too small in AdamW.
- Decaying normalization weights, which can harm stability without any regularization benefit.
- Ignoring the learning rate coupling, so changing the learning rate also changes the effective decay.
- Skipping warmup, which can cause early divergence because the second-moment estimate starts near zero.
- Setting epsilon too small in mixed precision, which can cause overflow or unstable denominators.
Stripped to the essentials
Training a model means nudging millions of numbers a little at a time. AdamW is a set of rules for those nudges. It decides how big each nudge should be for each number.
It also adds a gentle pull toward zero on every number. This keeps the model from relying too much on any single value. Older Adam mixed this pull into its other rules, so it worked unevenly. AdamW keeps the two jobs separate and predictable.
Where it is applied
A machine learning team fine-tunes a 1-billion-parameter language model to answer customer support questions. Its first run uses Adam with an L2 coefficient of 1e-4, and the model overfits after two epochs, with validation loss rising while training loss keeps falling.
The team switches to AdamW with a learning rate of 2e-5, weight decay of 0.05, beta2 of 0.98 and 500 warmup steps. Bias and LayerNorm parameters are placed in a group with zero weight decay. The rest of the setup, including data and batch size, stays the same.
Validation loss now keeps improving through the third epoch, and human reviewers rate answers as more accurate. The team records the AdamW settings as its default fine-tuning recipe, documenting that the decay is multiplied by the learning rate in its framework.