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 − β^tso early steps are not pulled toward zero.
Formulas and complexity
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.
When to use and when not to
| Choice | Use when | Avoid when |
|---|---|---|
| Plain SGD with momentum | Vision models from scratch on long schedules; memory matters | You need fast early progress with little tuning |
| Adam | Fast early progress; less learning-rate sensitivity | Memory is tight (two extra buffers per parameter) |
| AdamW | You want weight decay to mean what it says | Decay is not wanted at all |
| Large batch | Compute-bound hardware with spare throughput | Step count is the bottleneck or generalisation drops |
| Warmup then decay | Transformers, large batches, Adam's early moments | The run is tiny and short |
Traps interviewers probe
- Blaming the learning rate for everything. Badly scaled inputs also raise κ. Fix: standardise features, then compute 2/λmax before changing η.
- 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.
- 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. - 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.
- 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.