KatInterview

Mini-Batch SGD versus Adam: Update Rules and Trade-offs

Machine LearningModel answer
MediumModel answerMachine Learningoptimizationsgdadam

Last updated

Derive the parameter update rules for mini-batch SGD (with and without momentum) and Adam, explain bias correction, and compare the two on speed, tuning, memory and generalization.

You are training a neural network with mini-batch gradients and must justify your choice of optimizer to a teammate.

Write up a comparison of stochastic gradient descent and Adam. Your answer should:

  1. Show how plain mini-batch SGD updates parameters, and how adding momentum changes that rule.
  2. Derive Adam's update. Define every symbol: the learning rate, the two moment decay coefficients, the numerical stabilizer and the time step.
  3. Explain why Adam applies bias correction, and what goes wrong in the first few steps without it.
  4. Compare the optimizers on convergence behavior, hyperparameter tuning effort, memory footprint and generalization.
  5. Keep the comparison fair: contrast Adam with momentum SGD as well as with plain SGD, and avoid claiming that either optimizer is always better.

Before answering, say which clarifying questions you would ask. For example: is the goal fast early progress or best final validation quality? Is weight decay implemented as an L2 term in the gradient or as decoupled decay? Are gradients sparse or very different in scale across parameters?

Hints

Hint 1

Start with the plain rule theta <- theta - lr * g, where g is the mini-batch gradient, then add a velocity term to get momentum SGD.

Hint 2

Adam keeps two exponential moving averages: one of the gradient (first moment) and one of the squared gradient (second moment). Both start at zero, so ask what their values look like at step 1 when the decay coefficients are close to 1.

Hint 3

For the comparison, think about per-parameter step sizes, extra optimizer state per parameter, sensitivity to learning rate, and how L2 regularization interacts with the adaptive denominator.