AdamW › The AdamW Formulation

Michael BrenndoerferApril 20, 20253 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 69AdamW › The AdamW Formulation
Reading section 5 of 15 · The AdamW Formulation · 3 minSection 5 of 15 · 3 min

Book contents

Section 5 of 15 · 3 min read

AdamW › The AdamW FormulationOne section · Sections in this chapter5 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

AdamW fixes the problem by applying weight decay directly to the parameters, separate from the gradient update. The regularization term never enters the moment estimates. The moments track only the gradient signal from the loss, and the weight decay operates independently as a direct multiplicative shrinkage of the parameters.

The standard Adam update with L2 regularization computes:

θt+1=θt−αv^t+ϵm^t\theta_{t+1} = \theta_t - \frac{\alpha}{\sqrt{\hat{v}_t} + \epsilon} \hat{m}_t

where the moments mtm_t and vtv_t are computed from the regularized gradient gt+λθtg_t + \lambda \theta_t.

The AdamW update decouples these components:

θt+1=θt−α(m^tv^t+ϵ+λθt)\theta_{t+1} = \theta_t - \alpha \left( \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon} + \lambda \theta_t \right)

where:

  • m^t\hat{m}_t: bias-corrected first moment, computed from the original gradient gtg_t only
  • v^t\hat{v}_t: bias-corrected second moment, computed from the original gradient gtg_t only
  • λ\lambda: the weight decay coefficient
  • α\alpha: the learning rate

The weight decay term αλθt\alpha \lambda \theta_t is added outside the adaptive scaling. Every parameter is shrunk by the same multiplicative factor αλ\alpha \lambda at each step, regardless of its gradient history. The adaptive learning rates only affect the gradient-based update; they have no influence on how strongly weight decay pulls each parameter toward zero.

Written out as the complete set of equations, AdamW performs these steps at each training iteration:

gt=∇θL(θt−1)mt=β1mt−1+(1−β1)gtvt=β2vt−1+(1−β2)gt2m^t=mt1−β1tv^t=vt1−β2tθt=θt−1−α(m^tv^t+ϵ+λθt−1)\begin{aligned} g_t &= \nabla_{\theta} L(\theta_{t-1}) \\ m_t &= \beta_1 m_{t-1} + (1 - \beta_1) g_t \\ v_t &= \beta_2 v_{t-1} + (1 - \beta_2) g_t^2 \\ \hat{m}_t &= \frac{m_t}{1 - \beta_1^t} \\ \hat{v}_t &= \frac{v_t}{1 - \beta_2^t} \\ \theta_t &= \theta_{t-1} - \alpha \left(\frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon} + \lambda \theta_{t-1} \right) \end{aligned}

where:

  • gtg_t: gradient of the training loss, with no regularization term mixed in
  • mtm_t: first moment estimate, an exponential moving average of gradients
  • vtv_t: second moment estimate, an exponential moving average of squared gradients
  • m^t\hat{m}_t: bias-corrected first moment, compensating for the zero initialization of m0m_0
  • v^t\hat{v}_t: bias-corrected second moment, compensating for the zero initialization of v0v_0
  • β1\beta_1: first moment decay rate, typically 0.9
  • β2\beta_2: second moment decay rate, typically 0.999
  • ϵ\epsilon: numerical stability constant, typically 1e-8
  • λ\lambda: weight decay coefficient
  • α\alpha: learning rate

The critical difference from Adam with L2 regularization is in the last equation. The weight decay applies uniformly: the same αλθt−1\alpha \lambda \theta_{t-1} term acts on every parameter with the same effective coefficient, while the gradient update m^t/(v^t+ϵ)\hat{m}_t / (\sqrt{\hat{v}_t} + \epsilon) handles the adaptive per-parameter scaling independently.

The Geometric Interpretation

Another way to think about the difference is geometric. Adam with L2 regularization is trying to minimize a particular objective function, namely the regularized loss L~(θ)\tilde{L}(\theta), but using a preconditioned gradient descent step where the preconditioner is the adaptive scaling 1/v^t1/\sqrt{\hat{v}_t}. The preconditioning changes the effective geometry of the optimization landscape, and the L2 ball that L2 regularization defines in the original parameter space gets distorted by the preconditioner.

AdamW is doing something subtly different: it separates the geometry-distorting adaptive step for the loss gradient from the direct parameter shrinkage for weight decay. The adaptive step handles the optimization of the loss; the weight decay handles the regularization constraint. These two objectives are kept separate rather than being mixed into a single gradient computation.

This is also why AdamW has a cleaner connection to the original weight decay formulation from SGD literature. In the SGD with momentum world, weight decay was a direct multiplicative shrinkage applied to parameters. AdamW restores this interpretation in the adaptive optimizer setting, where Adam's adaptive scaling makes it impossible to achieve uniform weight decay through gradient modification alone.