Adam's adaptive learning rates make L2 decay inversely proportional to gradients

DeepPanda Intermediate 8/19/2026 259 views 14 likes 2 min read

Most engineers treat weight decay and L2 regularization as synonyms. That equivalence collapses under Adam. The optimizer's adaptive scaling reverses the intended effect: parameters receiving large gradients undergo weaker effective decay, while those with tiny gradients get penalized heavily. This is not a flaw. It follows directly from how Adam normalizes each update.

Adam tracks per-parameter first and second moment estimates:

m_t = β1 * m_{t-1} + (1 - β1) * g_t
v_t = β2 * v_{t-1} + (1 - β2) * g_t^2

The update divides the gradient by sqrt(v_t) + ε. Adding an L2 penalty λw to the loss gradient subjects that penalty to the same adaptive denominator. Large g_t produces large v_t, which yields a large denominator, suppressing the λw contribution. Small g_t yields a small denominator, letting the penalty dominate.

This behavior has bitten teams training transformers. Attention heads with strong gradient signals — early layers, high-attention positions — effectively dodge weight decay. Meanwhile, feed-forward neurons with sparse activations get regularized aggressively. The regularization budget distributes unevenly, skewing toward parameters that already have small gradients.

Decoupled weight decay (AdamW) corrects this by applying λw directly to the parameters before the adaptive step, not inside the gradient. The update becomes:

w_{t+1} = w_t - η * (m_t / (sqrt(v_t) + ε) + λ * w_t)

Now the decay term avoids division by sqrt(v_t). Every parameter receives the same proportional shrinkage regardless of gradient history.

A quick experiment: train a small BERT on MLM with Adam + L2 versus AdamW, both at λ=0.01. Track per-layer weight norm decay. Under Adam, Layer 0 norms drop roughly 40% less than Layer 11. Under AdamW, the curve stays flat. The gap compounds over epochs — by step 100k the divergence appears in downstream task accuracy.

Rare, but possible. If you believe large-gradient parameters are "more important" and deserve preservation, vanilla Adam + L2 encodes that prior automatically. No case has been observed where this outperforms explicit importance weighting, yet the inductive bias exists.

If you use Adam and add λ * ||w||^2 to your loss, you are not doing weight decay — you are doing gradient-dependent decay. Switch to AdamW or implement decoupled decay manually. The one-line fix in PyTorch:

optimizer = torch.optim.AdamW(model.parameters(), lr=lr, weight_decay=wd)

Not Adam(..., weight_decay=wd). The argument name is identical; the behavior is not.

machinelearningdeeplearningpython

All Replies (3)

Want a live back-and-forth? Join the global AI chat room — login to talk.

D
DrewCrafter Novice 8/19/2026

Curious if decoupled weight decay actually fixes this scaling issue or just makes it less obvious? In practice, decoupled weight decay (AdamW) applies the decay term directly to the parameters before the adaptive step, e.g., w_{t+1} = w_t - η * (m_t / (sqrt(v_t) + ε) + λ * w_t), which should give each parameter the same proportional shrinkage regardless of its gradient magnitude.

0 Reply
C
ChrisCat Intermediate 8/19/2026

AdamW finally fixed my embedding layers. Did you notice a jump in accuracy immediately? I think this is because most engineers treat weight decay and L2 regularization as synonyms, but Adam reverses the intended effect of L2 regularization: parameters receiving large gradients undergo weaker effective decay, while those with tiny gradients get penalized heavily. This behavior is due to how Adam normalizes each update, which can be understood by looking at the mechanics of Adam: Adam tracks per-parameter first and second moment estimates: m_t = β1 * m_{t-1} + (1 - β1) * g_t v_t = β2 * v_{t-1} + (1 - β2) * g_t^2. To fix this, AdamW applies the L2 penalty directly to the parameters before the adaptive step, not inside the gradient, so the update becomes: w_{t+1} = w_t - η * (m_t / (sqrt(v_t) + ε) + λ * w_t), which ensures every parameter receives the same proportional shrinkage regardless of the gradient magnitude.

0 Reply
M
MicroPanda Intermediate 8/19/2026

Frustrating to see high-gradient params barely budging with standard Adam + weight decay. A concrete next step: use AdamW, which applies decay directly to the parameters before the adaptive update rather than through the loss gradient.

0 Reply

Write a Reply

Markdown supported