Updated 24 October 2026. Worked numerical and organisational scenarios are fictional teaching examples; technical claims refer to cited primary sources.
Contents
- The direct answer: AdamW has two different forces
- Choose a useful reading route
- Why training needs an optimiser at all
- The variables behind a conventional AdamW update
- Adam and AdamW are not merely two spellings
- Follow the gradient without confusing it with the loss value
- What the two moving moments remember
- Why the first updates need bias correction
- Fully solved first AdamW step
- Fully solved second step when the new gradient is zero
- Why adding an L2 penalty is not the same calculation
- Some parameters should be decayed differently
- A decay-only thought experiment with checked arithmetic
- Learning-rate schedules change both the adaptive step and decay
- Gradient accumulation is not a licence to step more often
- Mixed precision, clipping and numerical stability
- What a complete training checkpoint must preserve
- A failure map: unusual loss curves and what to check
- What to log so another person can verify the update
- How to compare AdamW settings without fooling yourself
- Changed-context transfer: sparse gradients and excluded parameters
- A learner’s pathway from algebra to research engineering
- What AdamW does not solve
- FAQ: Is AdamW just Adam plus an L2 penalty?
- FAQ: Does a zero gradient mean no weight change?
- FAQ: Should every parameter get the same decay?
- FAQ: Can I compare runs with the same epoch count?
- FAQ: How do I know whether weight decay helped?
- Primary sources and connected study pathways
The direct answer: AdamW has two different forces
AdamW is an optimisation algorithm used to update the numerical parameters of many machine-learning models. Its central insight is that the adaptive update calculated from the loss gradient and the shrinkage called weight decay should be applied as distinct operations. Adam computes running estimates of gradients and squared gradients, corrects their initial bias and scales a step for each parameter. AdamW then also moves eligible weights toward zero by a decay factor that is not mixed into those gradient statistics. This prevents the regularisation signal from being distorted by Adam’s adaptive denominator.
If you remember one equation, remember a simplified update for one parameter: new weight = old weight × (1 − learning rate × decay coefficient) − learning rate × corrected first moment ÷ (square root of corrected second moment + epsilon). The two subtractions serve different purposes. The first is proportional to the current weight; the second follows the estimated loss gradient. This is a teaching form for a conventional AdamW step, not a claim that every optimiser configuration or framework uses identical extra options.
This chapter is for students, researchers and builders who want to diagnose a training run rather than copy a mysterious library setting. We will calculate two steps completely, check a decay-only thought experiment, explain why L2 penalties behave differently under Adam, and discuss realistic limits. The numerical models and project cases are fictional illustrations. Start with How AI Works for the general model pipeline; this guide owns the narrower mechanism of parameter updates and weight decay.
Choose a useful reading route
A beginner can read the next five sections to understand gradients, running averages, decoupled decay and the first-step arithmetic. A machine-learning practitioner should also read the discussions of parameter groups, gradient accumulation, learning-rate schedules, mixed precision and checkpoint restoration. A reviewer deciding whether a benchmark is credible should pay particular attention to held-out validation, controlled comparisons and the limits of optimiser-based generalisation claims.
You do not need advanced calculus to follow the worked scalar case, although calculus explains where gradients come from. The case deliberately uses round starting numbers rather than the hyperparameters of any particular production model. That keeps the arithmetic independently checkable. It also avoids suggesting that one set of optimiser values is universally suitable for language models, classifiers, scientific predictors or tiny school datasets.
The core professional distinction is between an optimisation mechanism and a validated outcome. A correct AdamW implementation is necessary for a training setup that specifies AdamW, but it cannot rescue flawed data, leakage, inappropriate targets or unfair evaluation. Treat the optimiser as one accountable layer inside a larger experiment.
Why training needs an optimiser at all
A model’s parameters are numbers that influence its predictions. Training evaluates a loss function that expresses a selected form of prediction error, calculates how the loss changes with respect to the parameters, and asks an optimiser to choose the next values. For a single weight, a positive gradient means increasing that weight locally increases the loss, so a basic gradient-descent step subtracts a quantity proportional to the gradient. A negative gradient moves the weight in the opposite direction.
But gradients are not constant, and different parameters can have very different magnitudes and histories. One layer may receive sporadic signals while another gets large correlated updates. A global learning rate alone may make some directions move rapidly and others slowly. Adam addresses this by maintaining per-parameter estimates of first and second gradient moments. The first captures an exponentially weighted direction; the second tracks the magnitude of squared gradients and helps normalise step size.
This adaptation is useful, but it changes what happens if a conventional L2 penalty is simply added to the loss. Its gradient then enters the same adaptive machinery as every data-driven gradient. The effect of shrinking a weight becomes entangled with the history of past gradients. AdamW was designed to separate the shrinkage operation from that adaptive calculation, not to remove the need for carefully chosen data and learning objectives.
The variables behind a conventional AdamW update
Let theta denote the parameter to update, g the current gradient of the training loss with respect to that parameter, alpha the learning rate, lambda the decoupled weight-decay coefficient, beta1 the first-moment memory factor, beta2 the second-moment memory factor, and epsilon a small denominator stabiliser. The moment states begin at zero for a fresh optimiser. The step counter begins at zero and advances only when the optimiser performs an update.
At step t, the first moment becomes beta1 times the previous moment plus (1 − beta1) times the current gradient. The second becomes beta2 times its previous value plus (1 − beta2) times the square of the current gradient. These are exponentially weighted moving statistics rather than simple averages over all previous examples. Values of beta1 and beta2 near one preserve more history. They do not say whether the current gradient is accurate or unbiased.
Since both moments begin at zero, early estimates are biased toward zero. Adam divides the first by (1 − beta1 raised to t) and the second by (1 − beta2 raised to t). The corrected first moment is then divided by the square root of the corrected second moment plus epsilon. The decay path, by contrast, scales the parameter directly by (1 − alpha × lambda). Dimensions matter: the product alpha × lambda is the per-step proportional shrinkage in this common formulation.
Adam and AdamW are not merely two spellings
The original Adam idea is adaptive moment estimation. In a common legacy way of adding L2 regularisation, the gradient entering Adam is altered by adding a term proportional to theta. That addition changes the first- and second-moment histories. A parameter with a large historic gradient scale can experience a different effective penalty from one with a small historic scale, because the penalty passes through an adaptive denominator.
AdamW instead calculates the gradient moments from the selected training loss and performs the weight-shrinkage step separately. The decoupled decay does not itself accumulate inside the moment or variance statistics. This distinction was analysed by Ilya Loshchilov and Frank Hutter in their paper Decoupled Weight Decay Regularization, published at ICLR 2019. The authors examined why L2 regularisation and weight decay, closely connected under standard gradient descent with appropriate coefficient scaling, are not generally equivalent under adaptive methods.
The practical implication is not that AdamW always trains better than every alternative. It means that a declared AdamW configuration has a clearer separation between the adaptive loss-driven step and the proportional decay. Whether the resulting model generalises well is an empirical question that depends on task, data, architecture, schedule, decay groups and validation procedure.
Follow the gradient without confusing it with the loss value
Suppose a fictional scalar model currently has parameter theta = 2 and the loss gradient at that parameter for one chosen batch is g = 0.2. The gradient is not the loss itself. A loss of 0.2 and a gradient of 0.2 are different quantities even when their numerical values happen to match. The gradient describes local sensitivity to a change in theta, while the loss summarises the model’s error under the selected objective.
A gradient may be influenced by class imbalance, scaling, outliers, label errors and the current batch. An adaptive optimiser does not verify that the underlying target represents the real problem. If a model predicts student readiness using information that will not be available when the prediction is needed, AdamW may minimise training loss beautifully while building an unusable model. The site’s data leakage guide addresses this separate evaluation error.
Gradients also belong to a specific computational state: model weights, batch, random-number generator, data transformation and training mode. Reusing a gradient after secretly changing that state may invalidate a worked calculation. In production debugging, record which optimiser update consumed which accumulated gradient, and distinguish microbatch backward passes from completed optimiser steps.
What the two moving moments remember
The first moment smooths the direction of successive gradients. When many recent gradients agree in sign, it tends to carry that direction forward. The second moment smooths the squares of gradients, which are non-negative, and describes recent squared magnitude. A larger corrected second moment generally reduces the adaptive step for a fixed corrected first moment. It does not make the update inherently more trustworthy, because the history may include errors or unstable data.
The two memory coefficients control different effects. A beta1 of 0.9, for example, retains 90% of the previous first moment before adding 10% of the new gradient. A beta2 of 0.99 retains 99% of the previous second moment before adding 1% of the new squared gradient. The moments react on different timescales. That is one reason their numerical values should not be swapped carelessly.
An operational consequence is that restoring only the model weights after an interruption does not restore the optimiser’s state. If the moments and step counter are forgotten, subsequent updates follow a different trajectory even when the next data batch matches. For a reproducible continuation, preserve the required model state, optimiser state and scheduler state, along with the data position and random seeds when those are relevant.
Why the first updates need bias correction
If a moving average starts at zero, its earliest values are pulled toward zero simply because it has not seen much history. With beta1 = 0.9, a first observed gradient of 0.2 produces m1 = 0.9 × 0 + 0.1 × 0.2 = 0.02. Without correction, one might falsely read 0.02 as the typical gradient magnitude. Dividing by 1 − 0.9 = 0.1 gives corrected m1 = 0.2, matching the observed first gradient.
With beta2 = 0.99, the first squared-gradient estimate is v1 = 0.99 × 0 + 0.01 × 0.2² = 0.0004. Dividing by 1 − 0.99 = 0.01 gives corrected v1 = 0.04. Its square root is 0.2. These corrections are determined by the update count t, not the number of words, records or backward passes processed since the previous step.
A common implementation bug is incrementing the optimiser step counter for each microbatch while actually updating weights only after several microbatches. That would use the wrong powers in the correction factors if the optimiser’s internal steps were managed incorrectly. Keep the concepts separate: backward computation accumulates gradients; optimiser stepping updates parameters and moments. A correct framework generally manages this when its supported API is used as intended.
Fully solved first AdamW step
Let our fictional initial parameter be theta0 = 2, loss gradient g1 = 0.2, learning rate alpha = 0.1, decay coefficient lambda = 0.05, beta1 = 0.9, beta2 = 0.99 and epsilon = 0.00000001. The learning rate is deliberately much larger than common production defaults to make the teaching arithmetic transparent; it is not a recommended setting for an actual large model.
Starting from m0 = v0 = 0, the first moment is m1 = 0.9 × 0 + 0.1 × 0.2 = 0.02. The second is v1 = 0.99 × 0 + 0.01 × 0.04 = 0.0004. Bias correction gives mhat1 = 0.02 ÷ 0.1 = 0.2 and vhat1 = 0.0004 ÷ 0.01 = 0.04. The adaptive gradient contribution is alpha × mhat1 ÷ (sqrt(vhat1) + epsilon) = 0.1 × 0.2 ÷ 0.20000001, approximately 0.099999995.
The separate decay contribution is alpha × lambda × theta0 = 0.1 × 0.05 × 2 = 0.01. Thus theta1 = 2 − 0.01 − approximately 0.099999995 = approximately 1.890000005, usually rounded to 1.89 for display. Notice that the decay is 0.5% of the original weight in this step, while the gradient-driven move is about 0.1. An implementation returning a vastly different value needs investigation of gradient sign, beta corrections, epsilon placement, learning rate or decay policy before any training claim is accepted.
Fully solved second step when the new gradient is zero
Now let the next loss gradient be g2 = 0 while retaining the same settings. The moment states do not instantly become zero because they contain history. The first moment becomes m2 = 0.9 × 0.02 + 0.1 × 0 = 0.018. The second becomes v2 = 0.99 × 0.0004 + 0.01 × 0 = 0.000396. The corrected first moment is 0.018 ÷ (1 − 0.9²) = 0.018 ÷ 0.19 = approximately 0.0947368421.
The corrected second moment is 0.000396 ÷ (1 − 0.99²) = 0.000396 ÷ 0.0199 = approximately 0.0198994975. Its square root is approximately 0.141065579. The adaptive move is therefore 0.1 × 0.0947368421 ÷ (0.141065579 + 0.00000001), approximately 0.06715801. Decay on the prior parameter is 0.1 × 0.05 × 1.89 = 0.00945.
The new parameter is approximately 1.89 − 0.06715801 − 0.00945 = 1.81339199. The key lesson is that a zero current gradient does not imply zero AdamW parameter movement when first-moment history persists. It also does not mean every model parameter is always decayed: a parameter excluded from the decay group would omit the 0.00945 term. If no gradient tensor is supplied at all, some frameworks skip the entire parameter update, which is a different case from an explicitly present gradient of zero.
Why adding an L2 penalty is not the same calculation
Consider a regularised loss L(theta) + lambda × theta² ÷ 2. Its gradient contains the ordinary loss gradient plus lambda × theta. For theta = 2 and lambda = 0.05, that additional L2 term is 0.1. If the ordinary gradient is 0.2, the modified gradient entering an ordinary adaptive update would be 0.3. Adam then builds moments and normalises using that combined quantity. In AdamW, the loss-gradient moments are built from 0.2, and the direct proportional decay is performed outside those moments.
In the first scalar step, the adaptive update produced by either 0.2 or 0.3 under a zero-state Adam calculation with negligible epsilon can happen to have magnitude approximately 0.1, because the moment numerator and square-root denominator scale together. That coincidence does not make the methods equivalent across subsequent steps, parameter dimensions or changing histories. AdamW also applies a separate 0.01 shrinkage in the example, which an ordinary Adam loss-only step would not replicate by default.
Under standard gradient descent without adaptive moments, an L2 penalty and weight decay can be algebraically related after appropriate coefficient scaling. The important qualifier is the algorithm and coefficient convention. It is inaccurate to announce a universal identity independent of learning rate and optimiser. The original AdamW paper establishes precisely why the adaptive case breaks the simple correspondence.
Some parameters should be decayed differently
Deep networks can contain matrices of learned weights, biases, normalisation parameters, embeddings and other components. Many training configurations use parameter groups, for example one group with a selected decay coefficient and another with zero decay. Whether a particular parameter should be excluded is an empirical and architectural design choice, not an immutable law. Common recipes often exclude biases and some normalisation parameters; the correct grouping must match the model and its training objective.
A reliable grouping implementation enumerates every trainable parameter exactly once, verifies that no parameter appears in both groups and checks that no expected parameter was omitted. It should make the chosen weight-decay settings inspectable. If the system silently leaves a newly added layer outside all groups, a training run may differ from the published configuration. If a parameter is duplicated between groups, a framework may reject the configuration or cause unexpected behaviour.
Do not treat grouping as decoration added after training. Two runs with identical model weights, data and nominal learning rate can follow different optimisation trajectories when their parameter groups differ. Keep a stable grouping policy with code review, version control and checkpoint metadata. When comparing experiments, disclose which parameters received decay and whether the groups were the same.
A decay-only thought experiment with checked arithmetic
It is useful to isolate the proportional shrinkage from the adaptive gradient contribution. Suppose a parameter starts at 2 and hypothetically receives 100 AdamW steps with zero adaptive contribution but a decay factor of 1 − 0.01 × 0.1 = 0.999 on every step. This is an algebraic thought experiment, not a claim about how a particular framework handles missing gradients or moment history. Under the stated condition, theta100 = 2 × 0.999^100, approximately 1.8095843.
The retained fraction is 0.999^100, approximately 0.9047921, or 90.47921%. The total shrinkage is therefore approximately 9.52079% over those one hundred steps. It would be wrong to multiply 0.1% by 100 and claim exactly 10% decline, because later updates shrink an already smaller weight. Multiplicative decay compounds over steps.
The number of effective optimiser steps matters. If another run performs only fifty parameter updates because it uses a larger gradient-accumulation interval, applying the same alpha and lambda on every completed step yields 0.999^50, a different retention factor. Matching epoch counts or the number of seen training examples is not enough to guarantee the same cumulative decay schedule. The experiment should report actual optimiser update counts.
Learning-rate schedules change both the adaptive step and decay
In a common AdamW implementation, the learning rate multiplies both the adaptive update and the decoupled decay contribution. Consequently a schedule that warms up and then reduces the learning rate also changes how much shrinkage happens at each optimiser step. The total decay retention under the decay-only approximation is a product of factors (1 − alpha_t × lambda) over the actual steps. A simple constant-rate power formula cannot reproduce a changing schedule.
Consider two runs with the same hundred data passes. One makes one optimiser update per pass; another accumulates gradients over several passes before each update. A scheduler stepping per optimiser update sees a different index sequence from one stepping per epoch. If the experiment claims both had the same cosine schedule, reviewers should ask what the scheduler’s unit actually was. The related learning-rate schedule guide works through warmup, cosine decay and correct resumption.
A practical logging policy records the learning rate and weight decay applied by each group at every completed optimiser step. When training is resumed, restore the scheduler as well as the optimiser. Otherwise the update count and decay exposure can silently change even when the model eventually reports a plausible validation score.
Gradient accumulation is not a licence to step more often
Gradient accumulation means combining gradients from several microbatches before one optimiser update. It is useful when the desired effective batch size cannot fit in accelerator memory at once. For instance, four microbatches of eight independent examples yield 32 example contributions before a step, assuming the gradients have been scaled to represent the intended average and no additional special weighting applies. The optimiser still performs one update, not four.
A common error is to call the optimiser’s step after every microbatch while claiming to have accumulated four microbatches. That changes moment histories, bias corrections, decay applications and scheduler progression. Another error is to sum four already averaged microbatch losses without dividing by four when the intended objective is an equal-weight average; the resulting gradient can be four times too large. Unequal microbatch sizes complicate the weighting and require accounting by examples or tokens as appropriate.
See gradient accumulation and correct optimiser steps for the full accounting. The AdamW-specific principle is that moment updates and proportional decay follow actual optimiser steps. When comparing configurations, preserve that unit of measurement and do not infer it from the number of forward passes.
Mixed precision, clipping and numerical stability
Training systems may compute parts of the forward and backward passes in reduced precision to improve throughput or memory use. This changes the numerical environment in which gradients are produced and checked. A dynamic loss scaler, for example, can increase a loss scale to preserve small gradients and skip a parameter update when an overflow is detected. A skipped optimiser step must be handled consistently by the optimiser and scheduler; otherwise the logged step count no longer matches the actual parameter updates.
Gradient clipping is a separate control. It limits gradients before they enter an optimiser update, often by using a global norm threshold. It does not replace weight decay or guarantee that the resulting model is stable. Under loss scaling, clipping an unscaled gradient is materially different from clipping the scaled value. The related gradient clipping guide explains the safe ordering.
Epsilon prevents division by zero in the adaptive denominator, but it also influences very small-gradient behaviour. For an actual implementation, use the documented epsilon convention of the chosen framework and version rather than assuming every library places epsilon in exactly the same expression. The goal is controlled numerical behaviour, not the myth that one tiny constant makes all training failures disappear.
What a complete training checkpoint must preserve
A checkpoint that stores only model parameter values may be adequate for inference but incomplete for exact training continuation. AdamW has first-moment states, second-moment states and update counters. Training may also have a learning-rate scheduler, precision scaler, sampler position, random-number-generator state and data-pipeline state. If a run resumes without them, its future trajectory may differ from the uninterrupted run even if the first evaluation looks similar.
A dependable checkpoint contract names the versions and parameter groups, stores the optimiser state using the framework’s supported serialization path, and validates that the tensors map to the intended model parameters. Reordering parameters carelessly can create serious errors when a checkpoint is loaded. Some frameworks provide additional features to manage named parameters or adapt restoration, but the developer remains responsible for confirming semantic correspondence.
Test a tiny uninterrupted run against a deliberately interrupted and resumed run. Control randomness where practical, compare numerical tolerances and record the first step at which states diverge. Exact bitwise identity may not be achievable on every hardware and backend combination, but the target tolerance and sources of nondeterminism should be declared. A successful checkpoint file write does not by itself demonstrate a valid optimiser resumption.
A failure map: unusual loss curves and what to check
If training loss becomes non-finite, check the inputs, labels, gradients, precision settings, learning rate and denominator behaviour before blaming decay. If parameters collapse rapidly toward zero, examine the product alpha × lambda, the number of steps, parameter groups and whether decay was accidentally applied multiple times per intended update. If the validation score worsens while training loss falls, consider overfitting, distribution shift and leakage rather than assuming AdamW is mathematically broken.
If two supposedly identical runs diverge immediately, compare seeds, data order, initial weights, device kernels, optimiser states and the exact grouping of parameters. If divergence begins after resumption, inspect the restored step counters and scheduler positions. If one layer never changes, determine whether its parameter is frozen, missing from optimiser groups, receiving no gradient, or subject to an accidental stop-gradient boundary. A zero gradient tensor and an absent gradient are not necessarily treated identically by a framework.
A good debugging table separates observed symptom, plausible mechanisms, direct measurements and safe repair. Merely changing the optimiser because an experiment underperforms can hide the true defect and spoil comparability. Preserve the failing configuration long enough to reproduce the problem on a small batch or synthetic fixture. Fix the correct layer and rerun the intended checks.
What to log so another person can verify the update
The minimal useful optimiser record includes algorithm name and library version, learning-rate schedule, beta values, epsilon, decay coefficient per group, parameter-group membership policy, effective batch definition, gradient clipping policy and completed update count. For an investigation, log bounded statistics such as gradient norm, parameter norm, update norm, proportion of zero or missing gradients and non-finite detection counts. Avoid exposing raw private training examples in logs merely to prove that an optimiser ran.
Aggregate statistics can be misleading without denominators. If a training job reports 400 gradient-clipping events, ask whether that means 400 optimiser steps out of 500 or 400 individual tensor operations within 50 steps. The rates are 80% and eight clips per step respectively, and they are not interchangeable. The logging schema should make its measurement unit explicit and permit comparisons across runs with different accumulation policies.
Whenever a model is intended for consequential use, optimisation logs belong beside evidence about the task itself: data suitability, subgroup performance where relevant, validation selection, known failures and deployment monitoring. AdamW proves how a parameter was updated under an algorithm, not whether using the resulting predictor is safe, fair or appropriate.
How to compare AdamW settings without fooling yourself
A fair comparison holds the evaluation protocol stable while varying a chosen factor. If you want to test weight-decay values, do not also change the model architecture, training split, label cleaning rule and early-stopping criterion without documenting the changes. Use grouped or time-aware validation when records are dependent or future information could leak. Tune on an appropriate validation set, then reserve an untouched test set for the final estimate when the study design permits.
Optimiser hyperparameters interact. A decay coefficient that works with one learning-rate schedule or number of updates may work differently with another. Keep a budget ledger that records how many models were tried, how the settings were chosen and whether results are noisy across seeds. Choosing the single lucky run from dozens and reporting it as typical performance is selection bias. The early stopping guide explains why validation patience and saved best checkpoints must be handled consistently.
Training stability is not identical to model quality. A method can converge to low training error while generalising poorly, or appear noisy during training while ultimately performing acceptably on held-out cases. Use application-relevant metrics and error analysis rather than reading all conclusions from a smooth loss graph. A clear experiment answers a reader’s concrete question: what changed, what remained comparable and how uncertain is the result?
Changed-context transfer: sparse gradients and excluded parameters
Imagine a fictional model with two scalar parameters. Weight A is 2.0 and belongs to a group with alpha = 0.01 and lambda = 0.1. Weight B is 2.0 and belongs to a group with no decay. For a simplified decay-only step with zero adaptive contribution, A becomes 2 × (1 − 0.01 × 0.1) = 2 × 0.999 = 1.998. B remains 2.0. That difference is intentional because the parameters have different group policies, not because the optimiser randomly preferred A.
Now suppose A’s gradient tensor is absent rather than explicitly zero, perhaps because the parameter was not used in the current computation. Depending on the framework, the optimiser may skip that parameter’s update entirely, including its decay. The correct answer can then differ from 1.998. A team comparing an always-present zero gradient against a missing gradient must inspect the actual documented implementation rather than assuming mathematical notation covers both situations.
Transfer the logic to an embedding model in which only some entries are touched by each batch. A blanket rule saying every vector always decays by the same amount per wall-clock interval may not describe actual sparse optimiser behaviour. Identify which parameters were updated, which groups allow decay and which library path supports sparse gradients. The mechanism transfers because it distinguishes a conceptual equation from the particular software pathway that applies it.
A learner’s pathway from algebra to research engineering
For a secondary-school learner, the AdamW equation combines ideas already familiar from algebra: multiplication, subtraction, powers and square roots. The calculation becomes easier when the variables are labelled and evaluated in order. A student can verify that 0.9 × 0.02 = 0.018 without knowing a programming language. The new concept is that a computer repeats these operations across large collections of parameters according to gradients extracted from data.
For a junior developer, the next step is to implement the scalar arithmetic in a small numerical notebook and compare it with a supported optimiser using the same settings. Check the first moment, second moment and step count before interpreting a whole-network training curve. Then change only one assumption, such as the decay group or the accumulated batch count, and predict how the result should differ before executing it.
For a researcher, the important transfer is into experimental discipline: keep comparable data splits, name the exact algorithmic variant, preserve the optimiser state, verify library behaviour and report uncertainty across relevant trials. This is the larger principle behind education that transfers into life: understanding a rule includes knowing when its assumptions stop holding.
What AdamW does not solve
AdamW cannot make a biased dataset representative, reconstruct missing labels, remove training-serving skew, repair a wrong loss function or confer causal validity on an observational prediction. It can improve the update path for a stated optimisation problem, but the stated problem can still be unsuitable. It also cannot promise that larger decay always yields better generalisation. Too much decay can underfit, and the right setting depends on architecture, training duration, task and other regularisation choices.
Many practical implementations offer options beyond the basic algorithm, such as alternate backends, fused execution, capturable operation, maximum rather than minimum objectives and variants of second-moment handling. These should be interpreted using the current documentation of the actual library. The simple scalar example is not a substitute for examining these options. Some optimisers use different update rules and should not be silently called AdamW.
Finally, performance claims need appropriate evidence. The original AdamW paper offered empirical findings for its studied tasks and settings; it did not prove AdamW dominates every future architecture or domain. Distinguish published evidence from the fictional arithmetic here. Treat this guide as an explanation of mechanisms and evaluation discipline, not as a prediction that any particular production model will succeed.
FAQ: Is AdamW just Adam plus an L2 penalty?
No. In AdamW, the decoupled weight-decay operation is separated from the adaptive gradient-moment calculation. Adding an L2 penalty to a loss sends its gradient through Adam’s moment estimates and scaling, which is not generally equivalent. For standard nonadaptive gradient descent, the two formulations can be related by a coefficient conversion, but that special relationship should not be exported unchanged to Adam.
FAQ: Does a zero gradient mean no weight change?
Not necessarily. Existing first-moment history can produce an adaptive update when the current gradient is zero, and a nonzero decay coefficient can shrink eligible parameters on a step. An entirely absent gradient tensor may be treated differently from a present zero tensor by the implementation. The exact behaviour should be checked against the framework, especially when frozen parameters or sparse updates are involved.
FAQ: Should every parameter get the same decay?
No. A training configuration may use groups with different decay coefficients or omit decay for selected parameter types. The policy should be explicit, tested and appropriate to the architecture. Do not assume that a borrowed recipe is universally optimal, and verify each trainable parameter belongs to its intended group exactly once.
FAQ: Can I compare runs with the same epoch count?
Epoch count alone is not sufficient. Effective batch size, accumulation interval, number of optimiser updates, scheduler stepping, skipped updates and the decay schedule all affect the trajectory. Compare completed optimiser steps and data exposure, and disclose differences rather than treating a shared epoch label as proof of equivalence.
FAQ: How do I know whether weight decay helped?
Evaluate on properly held-out data using a prespecified or clearly documented comparison, ideally across relevant random seeds and uncertainty estimates. Keep the model, data and evaluation rules as comparable as possible. Training loss falling faster is not the same as improved generalisation, and choosing a lucky single run is not strong evidence.
Primary sources and connected study pathways
The primary technical sources are Loshchilov and Hutter, Decoupled Weight Decay Regularization, ICLR 2019, for the algorithm’s motivation and distinction from L2 regularisation, and PyTorch’s maintained AdamW reference, for its documented formulas, state and parameter-group interface. The NIST AI RMF Playbook is a governance resource about trustworthy deployment; it is not an optimiser specification.
If you are building a complete learning route, read batch normalisation and evaluation mode for another train-versus-evaluate boundary, activation checkpointing for the memory-versus-recomputation trade-off, and probability calibration for why optimising a model does not ensure trustworthy probabilities. The broader How X Works hub connects these technical mechanisms to other domains.
The lasting habit is to distinguish what each layer actually guarantees. AdamW defines a method for changing weights. Validated data, correct arithmetic, reproducible experiment records and meaningful held-out tests establish whether those changes helped solve the real problem.