Choosing the parameter update
A gradient gives a direction, not a complete update rule. The optimizer adds history and scaling. Decay, clipping, and scheduling must have explicit conventions so the intended update is the one applied.
#Section 11Gradient descent and optimizers
A gradient describes a local direction for improvement. The optimizer decides how far to move and how previous batches influence that move.
Gradient descent subtracts a positive step size times the current gradient. Stochastic gradient descent, or SGD, uses a sampled batch’s gradient rather than the whole corpus’s gradient. The learning rate is that step-size multiplier. "Stochastic" refers to the data estimate, not to adding an arbitrary random direction to the update.
Gradient descent moves against the current gradient, scaled by the learning rate. The local improvement prediction becomes less reliable for a large move.
Momentum and adaptive learning rates
Momentum retains a running direction, giving consistent gradients more influence than isolated noise. Implementations use different buffer conventions, so match the declared recurrence.
An adaptive learning rate scales updates separately for different parameter coordinates using gradient history. It does not mean the optimizer knows each coordinate's ideal rate or that no global schedule is needed. Large typical squared gradients can reduce one coordinate's normalized update, while another with smaller typical gradients can receive a different scaling.
Adam's first and second moments
Adam tracks an exponential average of gradients and an average of squared gradients. The first moment is the average of the gradient value. The second raw moment is the average of its square, not a centered variance. Because both buffers begin at zero, their early values are biased toward zero; bias correction compensates for that initialization under the averaging model.
Each Adam buffer blends prior history with a new gradient contribution. One tracks direction and the other squared magnitude, separately for each parameter coordinate.
Correct the buffers' initial zero bias, then scale the averaged gradient by its squared-gradient history. Optimizer epsilon guards the denominator and is separate from normalization epsilon.
Kingma and Ba introduced Adam in 2014. Its adaptive normalization is useful in many training settings, but it is not a general convergence guarantee and it does not replace experiment-specific tuning. AdamW applies weight decay separately from that normalization, which Section 12 now makes precise. Adam variants and SGD are alternatives whose quality and memory cost depend on the workload. Adam, AdamW.
| Property | SGD | Momentum SGD | AdamW |
|---|---|---|---|
| History buffers | None | Direction buffer | First and second moments |
| Coordinate normalization | None | None | Squared-gradient history |
| Global learning rate | Required | Required | Required |
| Decay policy | Declared explicitly | Declared explicitly | Decoupled |
| Extra named state per scalar | 0 | 1 buffer | 2 buffers |
| Main pitfall | Noisy or oversized moves | Convention mismatch | State reset or wrong decay |
#Section 12Weight decay
Two parameter settings may fit a training sample similarly, while one uses much larger values. Penalizing or shrinking weights can change which solution optimization prefers. It can also limit parameter growth. This is a modeling choice, not a theorem that smaller weights always give better language-model quality.
Regularization changes the learning procedure to encourage selected properties of the solution. L2 regularization adds a penalty proportional to squared weight values to the loss. Weight decay shrinks weights during the update. Their equivalence depends on the optimizer and coefficient convention.
An L2 penalty adds a weight-dependent term to the gradient. Plain SGD can express it as shrinkage, but Adam also routes it through adaptive history.
Adam processes that combined gradient through its moment estimates and coordinatewise denominator. The penalty then changes the gradient statistics themselves. Decoupled weight decay instead shrinks the parameter separately from Adam's moment-based correction:
AdamW shrinks weights separately, so its moments describe data gradients rather than data plus a penalty. The effective shrinkage depends on the learning-rate schedule and executed updates.
Which parameters receive decay
A common dense-model policy decays matrix weights and excludes normalization gains and bias vectors. Norm gains control channel scaling, and pushing them toward zero is a different intervention from shrinking a projection matrix. Biases set offsets. Excluding these parameters is a convention to test, not a universal mathematical requirement. Embeddings and a tied head require one consistent shared policy, as Part II explained.
Deduplicate tied parameters before assigning decay groups. Two names can refer to one learned object.
PyTorch's AdamW documentation specifies the decoupled update and optimizer-state loading behavior.
#Section 13Gradient clipping
A batch can produce a correction much larger than the recent ones. Applying it directly may destabilize training before the next loss is even measured. Clipping caps the raw gradient magnitude presented to the optimizer; it does not identify the cause of the spike.
The earlier stabilization overview introduces clipping. A global gradient norm is the Euclidean length of all selected parameter gradients treated as one concatenated vector. Global norm clipping multiplies every selected gradient by one common scale if that length exceeds a positive threshold .
Read this as: square and sum all gradient entries , take the square root to get norm , then scale each entry by the smaller of one and threshold divided by . If , no scaling is needed. Implementations may add a tiny numerical stabilizer to the denominator.
[3, 4] to [0.6, 0.8] at threshold 1. Direction is preserved; the illustration does not claim to bound Adam's eventual parameter-update norm.Clip the combined gradient after accumulation and any unscaling. Clipping each contribution first can change their sum. In sharded training, include all relevant shards in the global norm.
Clipping nonfinite values is not a repair: a NaN norm cannot define a meaningful scale. Reject the step or investigate the numerical failure. Log the pre-clipping norm and clipping frequency, because frequent clipping may reveal an unsuitable learning rate, data issue or other instability. The PyTorch norm-clipping contract defines the combined norm and returns its value before clipping. Pascanu and colleagues discussed norm clipping for recurrent-network instability in their 2012 work.
#Section 14Learning-rate scheduling
An aggressive first update acts on uncalibrated representations and moment estimates. A tiny fixed rate may be stable early but spend the whole budget making slow progress. A learning-rate schedule declares how the step multiplier changes as the run advances; it cannot guarantee stability, but it makes that choice explicit.
The earlier warmup and decay overview gives the motivation. Warmup raises the rate from a small initial value to a chosen peak learning rate over an initial interval. Cosine decay lowers it along a half-cosine curve to a minimum learning rate. These are schedule components; cosine decay need not include warm restarts just because the SGDR paper studied them.
Warmup reaches the chosen peak, then cosine decay moves toward the minimum. Define boundaries and behavior after the end; otherwise a cosine can accidentally rise again.
Which step does the scheduler count?
A microbatch is not an optimizer update when accumulation is active. Finch-24's illustrative accumulation processes four microbatches per update, so 1,000 updates consume 4,000 microbatches and 64,000 supervised tokens with the fixed example sizes. Advancing the schedule after every microbatch would run it four times faster in update units. Variable-size batches make a token-based schedule an alternative; state which counter the policy uses.
The displayed table is a mathematical curve indexed by completed updates. A concrete loop must choose whether the next update uses or . In Part VI we set the first executed update's rate with , then increment the completed-update counter only when an optimizer update actually occurs. This avoids a first update at exactly zero while preserving a declared boundary convention. A stateful PyTorch scheduler needs its own documented call order; do not stack it with a manually set rate unless that is intentional.
Linear decay, constant-rate plateaus and schedules with later cooldown are alternatives. A comparison that stops a model before its planned decay endpoint is a comparison of partially completed optimization plans. The SGDR paper provides the historical cosine schedule; the appropriate schedule for a new corpus remains an experimental choice.