Optimisation

Gradient descent, SGD, momentum and Adam; epochs, batches and steps; learning rate and batch size trade-offs; vanishing and exploding gradients; normalisation.

Gradient Descent
▶ lab

θ ← θ − η∇L. One update rule, one number that decides whether it crawls, converges or explodes. The learning rate is the single most important hyperparameter in deep learning.

Q · The loss curve is flat, or it jumps to NaN after a few hundred steps. Before touching the architecture or the data, what does the update rule itself predict about this behaviour?
Optimisers: SGD, Momentum, Adam
▶ lab

Three ways to decide what multiplies the gradient. None is universally best: Adam converges fast and sometimes generalises worse; SGD with momentum is still the default in much of vision; the choice interacts with the learning rate and with weight decay.

Q · A colleague says "just use Adam". Another says the vision team's models are all SGD with momentum and they generalise better. Who is right, and what would it take to know for this model?
Epoch, Batch, Step

An epoch is one pass over the data. A batch is the subset used for one gradient estimate. A step is one parameter update. "We trained for ten epochs" says nothing until you know the batch size.

Q · Two runs both "trained for ten epochs" and one is far better than the other. What is the unit of training actually being counted, and why is an epoch not it?
Batch Size and Learning Rate
▶ lab

Batch size trades memory, throughput and gradient noise against each other, and it moves the right learning rate with it. Larger batches want larger rates — up to a point — and small batches regularise for free.

Q · A bigger GPU arrived and the batch size was raised to fill it. Throughput doubled and the model got worse. What did the batch size change besides speed?
Vanishing and Exploding Gradients
▶ lab

Backpropagation multiplies one Jacobian per layer. A chain of factors below one shrinks the gradient to nothing by the early layers; a chain above one blows it up. Depth is hard to optimise for this reason, and every remedy attacks the product.

Q · The deep model trains worse than the shallow one it was supposed to improve on, and the early layers barely change. What is happening to the gradient on its way back?
Normalisation Layers

Batch norm normalises each feature over the batch; layer norm normalises each example over its features. The difference decides whether the layer behaves the same at training and inference — and batch norm does not, which makes it a train/serve skew source with a name.

Q · The model evaluated well in the training framework and behaves differently in the serving container, with identical weights. Which layer in the network has a different definition at inference time?
Initialisation and Convergence
▶ lab

Where the weights start decides whether training can begin; the warm-up and decay decide how it ends. A loss curve that plateaus, diverges or oscillates is a report on those choices, and a seed is not a reproducibility strategy.

Q · Two runs with the same config and different seeds ended far apart, and a third never left its starting loss. What did the initial weights and the schedule decide, and how much of the outcome is noise?