Skip to content
Tech Interview Prep
Technical interview guideNew

Gradient Descent and Optimizers

How gradient descent minimises a loss by stepping against its gradient, and how learning rate, batch size, momentum, adaptive methods and schedules change how that descent behaves in practice. Built for ML engineers who must explain and compare optimizers in interviews.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v2
Editorial status
Reviewed

Scope: Current to PyTorch 2.x (torch.optim defaults: Adam lr 1e-3, betas (0.9, 0.999), eps 1e-8, weight_decay 0; AdamW weight_decay 0.01) and TensorFlow 2.x / Keras 3 optimizers. Convergence statements assume smooth losses unless stated; learning-rate limits quoted for quadratic losses with curvature lambda..

Overview

Curated: · Written: · Reviewed:

Gradient Descent and Optimizers

In one line

Gradient descent minimises a loss by stepping against its gradient, θ ← θ − η·g. Reach for it whenever you train a differentiable model. The interview question is almost always which knob (learning rate, batch size, momentum, adaptive scaling or schedule) changes the step, and in what way.

Key definitions

  • Learning rate (η): scales the step. It alone decides whether the run converges or diverges.
  • Curvature (λ) and Hessian eigenvalues: second-order slope along each direction. The largest one sets the stability bound.
  • Mini-batch gradient: the average gradient over a batch, a noisy estimate of the full gradient.
  • Saddle point: zero gradient, with Hessian eigenvalues of both signs.
  • Condition number (κ = λmax / λmin): sets how many steps plain gradient descent needs.
  • Bias correction: divides Adam's moment estimates by 1 − β^t so early steps are not pulled toward zero.

Formulas and complexity

wnew=wold−ηdLdww_{new} = w_{old} - \eta \frac{dL}{dw} 0<η<2λmax0 < \eta < \frac{2}{\lambda_{max}} effective step along a steady gradient≈ηg1−β\text{effective step along a steady gradient} \approx \frac{\eta g}{1-\beta}

For a quadratic with curvature a, one step multiplies w by (1 − ηa), so you need |1 − ηa| < 1. Show the arithmetic when you quote the bound. Per step, a batch of N examples costs O(N·d) for d parameters. Backpropagation costs a small constant multiple of the forward pass.

How it works

  • The loss gives a slope at the current weights. The update moves against that slope.
  • Momentum adds a velocity, v ← β·v + g, so consistent components accumulate and oscillating ones cancel.
  • Adaptive methods divide each parameter's step by a running measure of its gradient magnitude.
  • A schedule changes η as a function of step count. Warmup ramps it up first, then decay lowers it.
Mini-batch Gradient g Momentum or adaptive scaling Step size from eta and schedule Update theta

When to use and when not to

ChoiceUse whenAvoid when
Plain SGD with momentumVision models from scratch on long schedules; memory mattersYou need fast early progress with little tuning
AdamFast early progress; less learning-rate sensitivityMemory is tight (two extra buffers per parameter)
AdamWYou want weight decay to mean what it saysDecay is not wanted at all
Large batchCompute-bound hardware with spare throughputStep count is the bottleneck or generalisation drops
Warmup then decayTransformers, large batches, Adam's early momentsThe run is tiny and short

Traps interviewers probe

  1. Blaming the learning rate for everything. Badly scaled inputs also raise κ. Fix: standardise features, then compute 2/λmax before changing η.
  2. Thinking Adam's step scales with the gradient. On the first step bias correction makes the update about η whatever g is. Fix: say the step is roughly η·m̂/√v̂, and that the ratio is what sets its size.
  3. Folding L2 into the loss under Adam. The penalty gets divided by the second-moment term, so it weakens for parameters with large gradients. Fix: use AdamW, which applies θ ← θ − η·λ·θ separately.
  4. Calling every stall a local minimum. Usually it is a plateau or a saddle. Fix: check the gradient norm and the Hessian sign pattern before deciding.
  5. Confusing AdaGrad with RMSProp. AdaGrad sums squared gradients, so its rate only decays. RMSProp uses a moving average, so the rate does not decay to zero. Fix: name the denominator's behaviour.

Interview tips

Open by stating the update rule and naming which of the two quantities you are changing: the gradient estimate g or the step size η. Keep the answer to the question asked.

Expect these follow-ups: why a loss jumps tenfold in one step, why Adam needs less tuning, why AdamW differs from L2, how batch size should scale η, and when to clip by global norm.

A 30-second outline: the rule θ − η·g. The stability bound η < 2/λmax, so a larger curvature needs a smaller step. The knob you would change first, with the signal that tells you. The fix, such as warmup for large batches or AdamW for decay. Finish by naming one thing you would monitor: loss, gradient norm or update-to-weight ratio.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.