AdamW

Also known as: Adam with decoupled weight decay

On this page 7

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.

PropertyAdam with L2 penaltyAdamW
Where decay entersAdded to the gradientApplied directly to the weights
Effect of adaptive scalingDecay is rescaled per parameterDecay is not rescaled
Regularization strengthUneven across parametersUniform relative shrinkage
Coupling with learning rateStrong and hard to separateWeaker, easier to tune
Typical generalizationOften worse than tuned SGDComparable or better
L2 penalty in Adam versus decoupled decay in AdamW

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.

  1. Compute the gradient of the loss for the current mini-batch.
  2. Update the first moment with coefficient beta1 and the second moment with beta2.
  3. Apply bias correction, which matters most in the first few hundred steps.
  4. Take the adaptive gradient step scaled by the learning rate.
  5. 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.

HyperparameterTypical rangeWhat it controls
Learning rate1e-5 to 1e-3Size of the adaptive step
Weight decay0.01 to 0.1Fraction of each weight removed per step, scaled by the learning rate
beta10.9Memory of the momentum average
beta20.95 to 0.999Memory of the squared-gradient average
epsilon1e-8 to 1e-6Numerical stability of the denominator
AdamW hyperparameters

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.

OptimizerState per parameterStrengthWeakness
SGD with momentumOne bufferStrong generalization in visionSensitive to learning rate
AdamTwo buffersFast, adaptive convergenceCoupled L2 regularization
AdamWTwo buffersAdaptive steps with clean decayHigher memory than SGD
AdafactorFactored second momentLow memory for huge modelsLess stable without tuning
LionOne bufferLower memory, sign-based updateNeeds smaller learning rates
AdamW and related optimizers

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.