§ Gradients · Interactive Graduate Primer
Tensor by Tensor · expanded

Optimizers

Learn how changing several inputs changes one output. Begin with partial derivatives, then explore gradient descent, backpropagation, and optimizers. The later sections include proofs and deeper mathematical detail.
A first reading path

Start with sections 2–4, then section 7. Return to the directional-derivative proof after you understand a gradient-descent update. An optimizer is a rule for updating the model’s adjustable numbers.

For L(a, b) = a² + 2b², the gradient at (1, 2) is [2, 8]. The first entry measures change along a while b stays fixed. The second measures change along b while a stays fixed. With step size 0.1, subtract [0.2, 0.8] to reach (0.8, 1.2). The loss falls from 9 to 3.52.

Check: why subtract the gradient?

The gradient points toward the steepest local increase under the usual Euclidean length measure. Subtracting it moves toward a local decrease when the step is small enough. A large step can still overshoot and increase the loss.

12. Modern Optimisers

Introduction

Two optimizers can receive the same current gradient yet take different steps because they remember different history. SGD uses the present value, while momentum, RMSProp, and AdamW track running first or second moments.

Learning goal

Compare major gradient optimizers by their stored state, update behavior, assumptions, and appropriate diagnostic questions.

Before you start

Gradient descent, learning rates, moving averages, squared values, and parameter updates.

Lesson plan

  1. Start from plain SGD and identify what information one update uses.
  2. Add first-moment and second-moment histories to understand momentum and adaptive scaling.
  3. Compare AdamW and newer methods without treating any optimizer as universally best.

Optimizers change how gradients become parameter steps. They do not replace the gradient calculation. Compare methods under the same initialization, batches, and evaluation rule so a changed result has one plausible cause.

OptimiserUpdateNotes
SGD$\theta\leftarrow\theta-\eta g$Baseline.
SGD + momentum$v\leftarrow\mu v-\eta g;\;\theta\leftarrow\theta+v$Damps oscillation.
NesterovEvaluate $g$ at $\theta+\mu v$.Look-ahead momentum.
AdaGrad$\theta\leftarrow\theta - \frac{\eta}{\sqrt{G+\varepsilon}}g,\; G\mathrel{+}=g^2$Per-parameter rate, decays.
RMSPropEMA of $g^2$.Non-stationary AdaGrad.
AdamMomentum + RMSProp + bias correction.Default for most DL.
AdamWDecoupled weight decay.LLM pre-training standard.
LAMB / LARSLayer-wise scaling.Large-batch distributed.
ShampooPrecondition by $H^{-1/(2d)}$.Approx 2nd-order at scale.
MuonPolar decomposition of update.Recent SOTA for LLMs.
Warning · Decoupled weight decay matters

In Adam, naive $L_2$ regularisation couples into the adaptive learning rate and is not equivalent to AdamW. Use AdamW for real weight decay.