Optimization

Weight Decay & AdamW: Decoupled Regularization

Why shrinking weights is not the same as adding an L2 penalty inside Adam, and how AdamW restores the intended regularization behavior.

status: reviewimportance: importantdifficulty 3/5math: undergraduateread: 13mdemo planned

Concept Structure

Weight Decay & AdamW: Decoupled Regularization

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
1next concepts
2related links

Learning map

Weight Decay & AdamW: Decoupled Regularization
BeforeAdam OptimizerNow3/4 sections readyTryUse the demo notes to predict the mechanism before moving on.NextScaling Laws & Emergent Abilities

Object flow

3/4 sections readyAsk about thisResearch room
ConceptWeight Decay & AdamW: Decoupled RegularizationOptimization
Local snapshot ready
concept:optimization/weight-decay-adamw

Conceptual Bridge

What should feel connected as you move through this page.

Carry inAdam Optimizer

Bring the mental model from Adam Optimizer; this page will reuse it instead of restarting from zero.

Work hereWeight Decay & AdamW: Decoupled Regularization

Why shrinking weights is not the same as adding an L2 penalty inside Adam, and how AdamW restores the intended regularization behavior.

Carry outScaling Laws & Emergent Abilities

The next edge should feel earned: use the demo prediction here before following Scaling Laws & Emergent Abilities.

Test the linkUse the demo notes to predict the mechanism before moving on.Then continue to Scaling Laws & Emergent Abilities
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Regularization often starts with a simple preference: all else equal, prefer smaller weights.

There are two closely related ways to express that idea:

  • add an L2L_2 penalty to the loss,
  • directly shrink parameters a little bit every step.

For plain SGD, those are effectively the same update. That is why many people casually treat "L2 regularization" and "weight decay" as synonyms.

For Adam, they are not the same. Adam rescales coordinates using running estimates of gradient magnitude, so an L2L_2 term added to the gradient gets rescaled too. That means different parameters can experience very different effective regularization strengths.

AdamW fixes this by decoupling weight decay from the adaptive gradient step. First do the Adam update. Then shrink the parameters directly.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let L(θ)L(\theta) be the task loss and λ>0\lambda > 0 the regularization strength.

With an L2L_2 penalty, the regularized objective is

Lreg(θ)=L(θ)+λ2θ22,L_{reg}(\theta) = L(\theta) + \frac{\lambda}{2} \lVert \theta \rVert_2^2,

so the gradient becomes

Lreg(θ)=L(θ)+λθ.\nabla L_{reg}(\theta) = \nabla L(\theta) + \lambda \theta.

For SGD, this leads to

θt+1=θtηL(θt)ηλθt=(1ηλ)θtηL(θt),\theta_{t+1} = \theta_t - \eta \nabla L(\theta_t) - \eta \lambda \theta_t = (1 - \eta \lambda)\theta_t - \eta \nabla L(\theta_t),

which is exactly a weight-decay step.

For Adam, the adaptive preconditioner changes things. AdamW writes the update as

mt=β1mt1+(1β1)gt,m_t = \beta_1 m_{t-1} + (1-\beta_1) g_t, vt=β2vt1+(1β2)gt2,v_t = \beta_2 v_{t-1} + (1-\beta_2) g_t^2, θt+1=θtηm^tv^t+ϵηλθt.\theta_{t+1} = \theta_t - \eta \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon} - \eta \lambda \theta_t.

The key point is that the shrinkage term ηλθt-\eta \lambda \theta_t is not divided by v^t+ϵ\sqrt{\hat v_t} + \epsilon. Regularization stays regularization instead of getting entangled with Adam's coordinatewise scaling.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

theta = np.array([1.0, 1.0])
g = np.array([0.1, 0.1])
vhat = np.array([1e-4, 1.0])  # Adam sees very different curvature/noise
lr = 1e-2
wd = 0.1
eps = 1e-8

adam_with_l2 = theta - lr * ((g + wd * theta) / (np.sqrt(vhat) + eps))
adamw = theta - lr * (g / (np.sqrt(vhat) + eps)) - lr * wd * theta

print("Adam + L2 :", np.round(adam_with_l2, 4))
print("AdamW     :", np.round(adamw, 4))

In the first coordinate, the effective shrinkage under "Adam + L2" becomes much larger because Adam divides by a tiny sqrt(vhat). AdamW avoids that distortion.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

No interactive demo yet for this concept. A useful next step would be a two-coordinate optimizer sandbox showing how Adam + L2 and AdamW diverge when one coordinate has much smaller running variance.

No live visualization is registered for this concept yet.

The page still supports explanatory demo notes above; when a viz.tsx exists, it will render here without changing the route.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Why shrinking weights is not the same as adding an L2 penalty inside Adam, and how AdamW restores the intended regularization behavior.

Demo notes open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Weight Decay & AdamW: Decoupled Regularization should make visible.

Visual Inquiry

Make the image answer a mathematical question

Why shrinking weights is not the same as adding an L2 penalty inside Adam, and how AdamW restores the intended regularization behavior.

3/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Weight Decay & AdamW: Decoupled Regularization easier to reason about before the page gives the answer.

Claim Review

Why shrinking weights is not the same as adding an L2 penalty inside Adam, and how AdamW restores the intended regularization behavior.

StatusSubstantive claim review pending

Source IDs and witness objects are attached for review; they are not proof by themselves.

SourcesNo references

Add source metadata before claiming support.

Witnesses3 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Practice Loop

Try the idea before it explains itself

Why shrinking weights is not the same as adding an L2 penalty inside Adam, and how AdamW restores the intended regularization behavior.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Weight Decay & AdamW: Decoupled Regularization.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptWeight Decay & AdamW: Decoupled RegularizationOptimization

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptOptimization

Weight Decay & AdamW: Decoupled Regularization

Anchored question

What is the smallest example that makes Weight Decay & AdamW: Decoupled Regularization click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:optimization/weight-decay-adamw.

No local draft saved.
Evidence to inspect
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Weight Decay & AdamW: Decoupled Regularization Object key: concept:optimization/weight-decay-adamw Context: Optimization Anchor id: concept/concept-notebook/optimization/weight-decay-adamw Open question: What is the smallest example that makes Weight Decay & AdamW: Decoupled Regularization click without losing the math? Evidence to inspect: - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/optimization/weight-decay-adamw concept:optimization/weight-decay-adamw