Part IX — Deep Learning Regularization, Normalization & Training Dynamics · Chapter 7

Weight decay vs. L2 regularization

Hook

Two textbooks tell you "L2 regularization" and "weight decay" are the same thing. With plain SGD, they're right. Plug either one into Adam, and they quietly stop agreeing.

Intuition

Two weights, w1w_1 and w2w_2, start identical. The only difference is their optimizer history: w1w_1 has barely been updated (small accumulated squared gradient vv), w2w_2 has been updated constantly (large vv). Watch what the same λ\lambda does to each under the two decay schemes.

Formalize

L2 regularization is usually implemented by adding λw\lambda w to the gradient before the optimizer's update rule divides by v+ϵ\sqrt{v}+\epsilon. Weight decay (as in AdamW) skips that division entirely:

ΔwL2=ηλwv+ϵΔwdecoupled=ηλw\Delta w_{\text{L2}} = \frac{\eta\,\lambda\,w}{\sqrt{v}+\epsilon} \qquad \Delta w_{\text{decoupled}} = \eta\,\lambda\,w
  • η\eta — the learning rate.
  • λ\lambda — the regularization strength.
  • ww — the current weight value.
  • vv — Adam's accumulated squared-gradient history for this parameter.
  • ϵ\epsilon — a tiny constant that keeps the division well-defined.
  1. Plain SGD: v is effectively 1 for every parameter

    SGD has no per-parameter adaptive scaling, so both formulas reduce to the same thing: Δw=ηλw\Delta w = \eta\lambda w. There's no distinction to make — this is why the two terms got used interchangeably for years.

  2. Adam: v varies wildly per parameter

    A parameter with a small vv (rarely updated) gets divided by a small number, so ΔwL2\Delta w_{\text{L2}} comes out close to ηλw\eta\lambda w — full-strength regularization. A parameter with a large vv (frequently updated) gets divided by a large number, so its coupled decay shrinks toward zero no matter how large λ\lambda is.

  3. Decoupled decay never looks at v

    Δwdecoupled=ηλw\Delta w_{\text{decoupled}} = \eta\lambda w doesn't reference vv at all — every parameter decays by the same fraction of itself, exactly matching the original intent of "shrink every weight a little."

Play

Push λ\lambda up. The two coupled bars (L2-in-Adam) spread apart — w1w_1's decay grows fast, w2w_2's barely moves. The two decoupled bars stay stacked on top of each other the entire time, because decoupled decay was never looking at each parameter's gradient history in the first place.

Worked example
  1. Same λ = 0.5, two parameters

    With η=0.1\eta=0.1:

    • w1w_1 has v=0.01v=0.01 (so v=0.1\sqrt{v}=0.1): coupled decay is 0.1×0.5×1/0.1=0.5\approx 0.1\times0.5\times1 / 0.1 = 0.5 — half the weight, in one step.
    • w2w_2 has v=4v=4 (so v=2\sqrt{v}=2): coupled decay is 0.1×0.5×1/2=0.0250.1\times0.5\times1/2=0.025 — twenty times smaller, for the identical λ\lambda.
  2. Decoupled decay doesn't care

    At that same λ=0.5\lambda=0.5, decoupled decay gives both parameters exactly 0.1×0.5×1=0.050.1\times0.5\times1=0.05 — a fixed 5% shrink, independent of how often either parameter has been updated.

  3. Why this matters in practice

    Rarely-updated parameters (think: embeddings for infrequent tokens) get crushed by coupled L2 long before frequently-updated ones feel any pull — an accident of optimizer bookkeeping, not a deliberate regularization choice. Decoupled decay applies the same regularization strength everywhere, which is why AdamW dropped coupled L2 in favor of it.

Checkpoint

Raise λ until coupled L2 would shrink w₁ by at least 50% in a single step, while decoupled decay on that same w₁ stays under 10%.

Move the λ slider to try it
Summary
ΔwL2=ηλwv+ϵΔwdecoupled=ηλw\Delta w_{\text{L2}} = \frac{\eta\,\lambda\,w}{\sqrt{v}+\epsilon} \qquad \Delta w_{\text{decoupled}} = \eta\,\lambda\,w

"Weight decay" and "L2 regularization" are the same formula only when there's no adaptive per-parameter scaling to interact with. The moment you add one — Adam, RMSProp, anything that divides by an accumulated gradient statistic — coupling the two lets the optimizer's own bookkeeping decide how much regularization each parameter actually receives. Decoupling them, as AdamW does, restores λ\lambda to meaning what it says. The next few chapters look at other places training goes wrong not because the math is broken, but because a hyperparameter interacts with something it was never designed to interact with — starting with the learning rate itself.