Bring the mental model from Adam Optimizer; this page will reuse it instead of restarting from zero.
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.
Concept Structure
Weight Decay & AdamW: Decoupled Regularization
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learning map
Weight Decay & AdamW: Decoupled RegularizationConceptual Bridge
What should feel connected as you move through this page.
Why shrinking weights is not the same as adding an L2 penalty inside Adam, and how AdamW restores the intended regularization behavior.
The next edge should feel earned: use the demo prediction here before following Scaling Laws & Emergent Abilities.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
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 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 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
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let be the task loss and the regularization strength.
With an penalty, the regularized objective is
so the gradient becomes
For SGD, this leads to
which is exactly a weight-decay step.
For Adam, the adaptive preconditioner changes things. AdamW writes the update as
The key point is that the shrinkage term is not divided by . Regularization stays regularization instead of getting entangled with Adam's coordinatewise scaling.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
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
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
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.
Start with the picture, metaphor, or geometric mechanism.
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.
Which visible object should carry the first intuition?
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.
Source IDs and witness objects are attached for review; they are not proof by themselves.
Add source metadata before claiming support.
Use equation, code, and demo objects to check whether the source support is operational.
Source support candidates
No structured source note is attached yet.
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.
Before touching the demo, predict one visible change that should happen in Weight Decay & AdamW: Decoupled Regularization.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
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.Open the draft below to save one note and next action in this browser.
Weight Decay & AdamW: Decoupled Regularization
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
This draft stays locally in this browser for concept:optimization/weight-decay-adamw.
- 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
- 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
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.
concept/concept-notebook/optimization/weight-decay-adamw
concept:optimization/weight-decay-adamw