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: 13mprediction probe

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

Commit a prediction against the code witness.

2prerequisites
1next concepts
2related links

Learner Contract

What this page should let you do.

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

This Optimization concept is the current object: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | code witness expected | prediction probe

Explain the mechanism, trace the main notation, and answer the prediction probe against the code witness.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Test the linkUse the prediction probe to commit to the mechanism before moving on.Then continue to Scaling Laws & Emergent Abilities

Claim/source review status

Claim review not recorded

No structured claim checks yet; source metadata is not enough to establish support.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims0/0 reviewed
Sources0 cited
Codeattached
Demoplanned
Reviewednot recorded
Updatedpage 2026-06-29

Object flow

4/4 sections readyAsk about thisResearch room
ConceptWeight Decay & AdamW: Decoupled RegularizationOptimization
Local snapshot ready
concept:optimization/weight-decay-adamw
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 the authored prediction probe to test the mechanism without a live widget.

Section prompt

Prediction check: the first coordinate has vhat=1e-4, so Adam's denominator is tiny there. Before running the code, predict which method shrinks coordinate 1 more aggressively, then change vhat[0] and watch the coupling disappear for AdamW.

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.

4/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.

Source Grounding

Canonical references for the mechanism on this page.

Source gapNo canonical references are listed yet.

Add source metadata before treating this page as source-grounded.

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