Foundations

Optimizers: SGD to Momentum to Adam to AdamW

Optimizers transform gradients into updates using velocity, adaptive scaling, and explicit weight decay.

Updated

1

Concept

Backpropagation produces gradients; an optimizer turns them into parameter updates. The optimizer adds state and policy to the local signal. Its behavior depends on learning rate, schedule, batch construction, clipping, precision, and regularization. Comparing names without matching those conditions is rarely informative.

Plain minibatch SGD updates θt=θt1ηgt\theta_t=\theta_{t-1}-\eta g_t. It has little state and a clear interpretation. Gradient noise can help exploration, but narrow curved valleys cause oscillation. Tuning a single global learning rate is difficult when useful scales differ across parameters.

Momentum maintains velocity, commonly an exponential moving average of gradients. Persistent directions accumulate speed, while alternating components partly cancel. This can move quickly along a shallow valley and reduce wall-to-wall bouncing. Different libraries use slightly different equations or Nesterov variants, so hyperparameters are not perfectly portable by label alone.

Adam estimates a first moment mtm_t and second raw moment vtv_t for each parameter coordinate. Roughly, the update divides the bias-corrected first moment by the square root of the bias-corrected second moment plus a small ϵ\epsilon. Recent gradient direction drives the step; recent squared magnitude normalizes it. Bias correction matters early because moving averages initialized at zero are otherwise biased toward zero.

Adaptive scaling is useful for sparse or uneven gradients, and Adam became common in Transformer training. It is not automatically stable under every setting. The meaning and placement of epsilon, precision of optimizer state, gradient clipping, and beta values matter. Optimizer state also consumes memory: Adam normally stores two moment tensors in addition to parameters and gradients.

Regularization creates a subtle distinction. For ordinary SGD, adding an L2 penalty to the objective can be equivalent to shrinking weights during updates under standard conditions. In Adam, the penalty gradient is passed through coordinate-wise adaptive scaling, so it no longer acts as uniform shrinkage. AdamW decouples weight decay: first compute the adaptive gradient update, then apply explicit parameter decay. This makes the decay behavior match its intended definition more directly.

Not every parameter should necessarily decay. Biases and normalization scale parameters are often placed in no-decay groups, depending on architecture and evidence. Parameter grouping is part of the optimizer configuration and a frequent source of silent bugs. Log which names enter each group and fail on unexpected omissions or duplicates.

Schedules matter as much as the optimizer. Warmup avoids large effective updates before activations and moment estimates settle. Decay reduces step size later for convergence. A fair experiment reports optimizer equations or implementation, learning-rate curve, batch size, clipping, decay groups, total tokens, and seeds. SGD, Momentum, Adam, and AdamW are update rules with different inductive biases—not a chronological ladder where the newest name wins every task.

Optimizer checkpoints must include step counters and moment buffers, not only model weights. Resuming Adam with empty moments changes the update rule even when parameters match exactly. Likewise, stepping the schedule once per batch versus once per epoch can produce a radically different learning-rate curve. A reproducible run records those boundaries and verifies the first resumed update against an uninterrupted reference.

2

Explain it like I am five

Four cyclists descend a winding track. Plain SGD steers only from the current slope. Momentum carries velocity, smoothing alternating turns. Adam keeps separate gauges for recent direction and squared magnitude on every control, taking smaller steps where gradients are consistently large. AdamW also applies a deliberate shrinkage to weights as a separate maintenance rule. No bicycle wins every track; schedule, surface, and tuning determine the race.

3

Teach it back

Compare SGD, Momentum, Adam, and AdamW, especially the difference between L2 added to an adaptive gradient and decoupled weight decay.

Minimum: 80 characters and 15 words. Your text stays only in this browser.

Saved only on this device.

Show a model answer

SGD steps along the negative minibatch gradient. Momentum maintains an exponential velocity to smooth noise and accelerate persistent directions. Adam tracks first and second gradient moments, bias-corrects them, and scales each coordinate adaptively. With adaptive scaling, adding L2 to the gradient also gets coordinate-scaled and is not equivalent to multiplicative shrinkage. AdamW decouples weight decay from the gradient update, applying the regularizer directly and making its meaning clearer.

4

Check your understanding

1. What does momentum accumulate?
Answer and explanation

An exponentially weighted history of gradients or updates — Velocity dampens oscillation and reinforces directions that persist.

2. What is AdamW's defining change relative to naive Adam plus L2?
Answer and explanation

Weight decay is decoupled from the adaptive gradient — Decoupling avoids adaptive preconditioning changing the form of parameter shrinkage.

Complete the teach-back and answer the quiz correctly to finish this lesson.

Sources

  1. Diederik P. Kingma and Jimmy Ba (2014). Adam: A Method for Stochastic Optimization.
  2. Ilya Loshchilov and Frank Hutter (2017). Decoupled Weight Decay Regularization.