Deep learning
Regularization for neural nets
Weight decay, dropout, augmentation and early stopping keep a net from memorizing. AdamW applies decay outside the adaptive update, which is why it replaced Adam plus L2.
Once a net can overfit one batch, the next job is to generalize. The regularizers that actually get used are boring: weight decay, a little dropout, data augmentation and early stopping. Exotic penalties are rarely the lever.
Concept
Weight decay shrinks weights each step by a factor involving λ. In SGD it matches an L2 penalty on the loss. In Adam, folding L2 into the gradient warps the decay, which is why AdamW exists.
The big idea
- Weight decay: L2 penalty on weights, via AdamW. Primary regularizer for large models.
- Dropout: zero random activations at train time, scale at eval. Less fashionable in modern LLMs (weight decay plus data mix suffice) but still used in many smaller nets.
- Data augmentation: the best regularizer when you can define label-preserving transforms (vision crops/flips, SpecAugment, NLP token noise carefully).
- Early stopping: watch validation loss. Stop when it worsens patiently, not on one noisy step.
- Label smoothing: soft targets instead of one-hot. A mild regularizer for classification.
For linear models the same L1/L2 story is in regularization and penalties. Neural nets mostly use decoupled weight decay plus data.
Walking through why AdamW exists
In vanilla SGD, adding λ/2 ‖θ‖² to the loss is the same as decaying weights each step. In Adam, the adaptive scaling is applied to the whole gradient including the L2 term, so decay is warped per-parameter. AdamW applies decay directly to θ outside the adaptive path:
θ ← θ − η ( m̂ / (√v̂ + ε) + λ θ )When a paper says "AdamW, weight decay 0.1", they mean the decoupled form. Do not substitute Adam + L2 and expect the same result. Use AdamW for almost all modern LLM and transformer training. Typical defaults: β1=0.9, β2=0.95 or 0.999, ε=1e-8, weight decay 0.01–0.1.
Optimizer state memory:
| Optimizer | Extra state beyond weights + grads |
|---|---|
| SGD | 0 |
| SGD + momentum | 1× weights (v) |
| Adam / AdamW | 2× weights (m, v) |
A 7B model in bf16 weights (~14 GB) with AdamW in fp32 moments needs tens of GB more for optimizer state alone, before activations. That is a primary reason for ZeRO/FSDP in distributed training. Details of Adam itself live in momentum and Adam.
Reasonable starting points, not laws:
| Setting | Small MLP / CNN | Transformer LM finetune |
|---|---|---|
| Optimizer | AdamW | AdamW |
| Peak LR | 1e-3 | 5e-5 – 2e-4 |
| Weight decay | 0.01 | 0.01 – 0.1 |
| Dropout | 0.1–0.5 | 0–0.1 |
SGD plus momentum plus a long cosine schedule can match or beat Adam on large vision training at the cost of tuning. If unsure, AdamW.
Add regularization gradually. Do not jump from nothing to heavy dropout plus decay plus aug. See debugging loss curves.
Common mistakes
- Using
Adamplus L2 and calling it AdamW. The decay is not the same. - Heavy dropout on a large LM. Weight decay and data mix usually suffice.
- Early stopping on one noisy val step. Wait for a patient plateau.
Check yourself
- Why does Adam plus an L2 term in the loss not match AdamW? Answer: Adam's adaptive scaling warps the L2 gradient. AdamW decays
θoutside that path. - A 7B model in bf16 is ~14 GB of weights. What extra memory do AdamW fp32 moments need, as a multiple of the weights? Answer: About 2× in fp32, tens of GB, before activations.
Key takeaways
- Weight decay, data and early stopping beat clever tricks.
- AdamW is the default modern optimizer. Remember 2× moment memory.
- Dropout is optional in large LMs. It still helps smaller nets.
- Add regularizers one at a time after you can overfit a batch.
Further learning
Decoupled Weight Decay Regularization (AdamW)L$_2$ regularization and weight decay regularization are equivalent for standard stochastic gradient descent (when rescaled by the learning rate), but as we demonstrate this is \emph{not} the case for adaptive gradien…arXiv.org
Related
Training neural networks well
Optimizers, schedules, initialization, normalization, regularization and a practical recipe for debugging loss curves.
Momentum and Adam
Momentum averages recent gradients to speed up consistent directions. Adam also tracks each parameter's gradient size, which makes it the default for many neural networks.
Regularization with L1, L2 and elastic net
Regularization adds a penalty for large weights. L2 shrinks weights smoothly, L1 drives some to exactly zero, and the penalty strength is tuned on validation data.