# Weight decay

> Canonical: https://skillalmanac.com/glossary/weight-decay | Verification status: pending | Index status: not offered to search engines

Weight decay is a training technique that shrinks a model's weights toward zero as it learns, discouraging overly large weights. For plain stochastic gradient descent it matches L2 regularization, but the two differ for adaptive optimizers such as Adam.

Also called: L2 regularization, L2 regularisation, weight decay Adam.

## In plain language

Weight decay is a gentle pull that keeps a model's internal numbers, called weights, from growing too large while it trains. Imagine a student told to keep every answer simple so they do not memorise quirks of the practice exam. The pull is meant to help the model do well on new data, but it is a setting someone has to choose: too little has no effect and too much stops the model learning. It is a training-time choice, so it does not matter when you only use a finished model. The name is confusing because 'weight decay' and 'L2 regularization' are sometimes used as if they were the same thing, and with some optimizers they are not.

## Technical definition

Google's ML glossary defines L2 regularization as a type of regularization that penalizes weights in proportion to the sum of the squares of the weights. Loshchilov and Hutter (arXiv 1711.05101) state that L2 regularization and weight decay are equivalent for standard SGD when weight decay is rescaled by the learning rate, but not for adaptive gradient algorithms such as Adam, and propose decoupling weight decay from the loss-based gradient step. PyTorch's AdamW documentation describes a weight_decay coefficient where decay does not accumulate in the momentum or variance estimates, and refers to that paper.

## How it shows up when you use agents

You meet weight decay in training code, not in everyday agent use. If you ask [Claude Code](/tools/claude-code) or Cursor to write a fine-tuning or training script, it will often include an optimizer line with a weight_decay value. That number came from the agent's defaults or examples, not from tests on your data.

What breaks when it is misunderstood: you copy a value without knowing what it does, or you switch from SGD to Adam and assume the same setting keeps its meaning. According to the AdamW paper, L2 regularization and weight decay differ under Adam, which is why AdamW exists. The safer habit is to read the optimizer's documentation, change one setting at a time, and compare runs on a held-out validation set.

Next action: ask the agent which optimizer it chose, whether the decay is decoupled, and why it picked that value. See [Regularization](/glossary/regularization), [Overfitting](/glossary/overfitting) and [Learning rate](/glossary/learning-rate).

## Common confusions

- **Weight decay versus L2 regularization.** The same for plain SGD when decay is scaled by the learning rate, not the same for Adam, according to Loshchilov and Hutter.
- **Adam versus AdamW.** AdamW applies the decay separately from the loss-based update. PyTorch documents it as the variant where decay does not accumulate in the momentum or variance.
- **Training setting versus model property.** Weight decay is chosen during training and is not a feature of a model you only use.
- **Myth.** That more decay improves results. Too much can leave a model that fits the training data poorly.

## Worked examples in this catalogue

### [llm-eval-test-sets](https://skillalmanac.com/skills/skill-almanac/llm-eval-test-sets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill builds and validates an eval dataset for any LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.

Why it exercises the concept: Weight decay is judged by performance on held-out data, which needs a clean test set. The catalogue has no training skills, so this is a contrast case that does not tune weight decay.

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill checks train, validation and test files for duplicates, shared groups, time and label leakage and prints JSON.

Why it exercises the concept: Comparing weight-decay settings on a leaky split would give misleading results. The skill checks the split and does not set any training option.

### [Asking a coding agent to explain a training script](https://skillalmanac.com/tools/claude-code)

```
claude
```

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Claude Code starts an interactive session in your project, where you can ask it to read a training script and point out where the optimizer and its weight_decay setting are configured.

Why it exercises the concept: Weight decay usually shows up as one argument to an optimizer in code. The agent can locate it. Illustrative only, and the agent's explanation should be checked against the PyTorch docs.

## Related terms

- [Regularization](https://skillalmanac.com/glossary/regularization.md)
- [Overfitting](https://skillalmanac.com/glossary/overfitting.md)
- [Learning rate](https://skillalmanac.com/glossary/learning-rate.md)
- [Stochastic gradient descent (SGD)](https://skillalmanac.com/glossary/stochastic-gradient-descent.md)
- [Loss function](https://skillalmanac.com/glossary/loss-function.md)
- [Gradient descent](https://skillalmanac.com/glossary/gradient-descent.md)

## Sources

- [Decoupled Weight Decay Regularization — Loshchilov and Hutter](https://arxiv.org/abs/1711.05101), arXiv (accessed 2026-11-24)
- [Machine Learning Glossary — L2 regularization](https://developers.google.com/machine-learning/glossary#l2-regularization), Google for Developers (accessed 2026-11-24)
- [torch.optim.AdamW](https://docs.pytorch.org/docs/2.15/generated/torch.optim.AdamW.html), PyTorch (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above. Independent source and example-target verification is pending. [Glossary index](https://skillalmanac.com/glossary.md).
