Decoupled Weight Decay Regularization
Ilya Loshchilov, Frank Hutter
Read the Paper on arXivAdam (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 , , , .
Click any topic to jump in
Exponential moving average of gradients damps oscillations and averages noise across iterations.
Adds per-parameter adaptive learning rates via second moment of gradients.
Equivalent in SGD, but Adam's adaptive scaling couples regularization to gradient history, under-regularizing frequent parameters.
Decouples weight decay from the gradient update, restoring uniform regularization across all parameters.
AdamW is the default for Transformers; hyperparameters tune independently.
Before understanding Adam, we need to understand vanilla SGD's limitations and how momentum — the exponential moving average of gradients that forms Adam's 'first moment' — addresses them by accumulating directional information across iterations.
Vanilla stochastic gradient descent (SGD) computes the gradient on a mini-batch and takes a step . This has fundamental limitations that become severe for deep networks with millions of parameters:
Oscillation in ravines: Most loss landscapes are highly elongated — the Hessian eigenvalue ratio (condition number) can exceed for deep networks. The gradient points along the steepest descent direction, which in a ravine is nearly perpendicular to the optimal path. This causes violent zigzagging: each step overshoots along the narrow dimension while making little progress along the long dimension. For a 2D quadratic with eigenvalues and , the gradient-to-optimal-direction angle is — nearly orthogonal.
No memory of past gradients: Each step uses only the current mini-batch gradient, which is a noisy estimate of the true gradient (mini-batch variance for batch size ). With batch size 32 on a dataset of 50K samples, each gradient estimate sees only 0.064% of the data. The optimizer has no mechanism to average out this noise across iterations.
Sensitive to learning rate: The optimal learning rate is where are Hessian eigenvalues. For a poorly conditioned loss (), this gives — too small for fast convergence along the flat directions. Any larger causes divergence along the steep direction; any smaller causes extremely slow progress.
Equal treatment of all parameters: A single global learning rate is applied to all parameters. But different layers, different weight matrices, and different dimensions of the same tensor may have vastly different gradient magnitudes. In a Transformer, embedding gradients might be smaller than attention logit gradients — a single learning rate cannot be optimal for both.
Stochastic noise amplification: Mini-batch gradients have variance that doesn't decrease with more training iterations (unlike full-batch gradient descent). SGD's trajectory looks like a random walk near the minimum, unable to converge to the exact optimum without learning rate annealing.
Momentum (Polyak, 1964; widely adopted via Sutskever et al., 2013) adds a "velocity" vector that accumulates an exponential moving average of past gradients. This is the foundation of Adam's first moment estimate :
where is the current gradient, is the momentum coefficient, and . Unrolling the recursion, is a weighted sum of all past gradients: — recent gradients are weighted more heavily (exponential decay with half-life steps).
Why this solves SGD's problems:
Oscillation damping: In a ravine, gradients oscillate between positive and negative along the narrow dimension. The momentum average cancels these oscillations: after a few steps. Along the consistent long-axis direction, gradients accumulate: at steady state with . The effective step size along consistent directions is amplified by .
Noise averaging: The exponential moving average acts as a low-pass filter on the stochastic gradient signal. With , the effective average is over the last gradients, reducing variance by roughly compared to raw SGD. This is equivalent to using a larger batch size — for free.
Escape from saddle points and flat regions: In flat regions where , accumulated velocity from previous non-zero gradients carries the parameters forward — like a ball rolling through a valley floor. Without momentum, the optimizer would stall in flat regions indefinitely.
Standard hyperparameter: is the near-universal default, meaning velocity is a weighted average of the last ~10 gradient steps. Nesterov momentum (, evaluating the gradient at a "lookahead" position) gives a small additional improvement by incorporating curvature information, and is the default in PyTorch's SGD(nesterov=True).
Limitation that motivates Adam: Momentum gives the same effective learning rate to all parameters — it addresses the oscillation and noise problems but not the per-parameter scale problem. Parameters with consistently large gradients and parameters with small sparse gradients both use . This is where adaptive methods (RMSProp, Adam) enter the picture.
Momentum accumulates past gradients as exponential moving average
Damps oscillations in ravines, accelerates in consistent directions
Standard retains 90% of previous velocity
Foundation for Adam optimizer (first moment estimate)
Basic gradient descent: step proportional to gradient
Velocity accumulates gradients; β controls momentum strength
Momentum turns the optimizer into a low-pass filter on the stochastic gradient signal. The EMA attenuates high-frequency oscillations (noise, ravine zig-zag) while amplifying low-frequency consistent directions by . With , this is a free boost in effective batch size along descent-consistent directions.