Explain momentum and Adam. What problem does each solve over vanilla SGD?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Momentum maintains an exponential moving average of gradients and steps along that average: v ← βv + g; w ← w − lr·v (β typically 0.9). In loss landscapes shaped like ravines - steep in some directions, shallow in others - vanilla SGD oscillates across the steep walls while crawling along the valley floor. Momentum cancels the oscillating components (they alternate sign and average out) and accumulates the consistent ones, giving up to a 1/(1−β) effective amplification along stable directions. It also smooths mini-batch noise.
Full worked answer with diagram
Momentum maintains an exponential moving average of gradients and steps along that average: v ← βv + g; w ← w − lr·v (β typically 0.9). In loss landscapes shaped like ravines - steep in some directions, shallow in others - vanilla SGD oscillates across the steep walls while crawling along the valley floor. Momentum cancels the oscillating components (they alternate sign and average out) and accumulates the consistent ones, giving up to a 1/(1−β) effective amplification along stable directions. It also smooths mini-batch noise.
Adam adds a second idea: per-parameter adaptive step sizes. It tracks both the first moment m (like momentum, β₁=0.9) and second moment v - an EMA of squared gradients (β₂=0.999 classically, ~0.95 in LLM practice) - and updates with w ← w − lr · m̂ / (√v̂ + ε). Dividing by √v̂ normalizes each parameter's step by its typical gradient magnitude: parameters with rare/small gradients (embedding rows for rare tokens) get relatively larger steps; parameters with large, noisy gradients get damped. The hats are bias correction - both EMAs are initialized at zero and severely underestimate their targets early in training; without correction, early steps would be badly mis-scaled.
Why this matters for transformers: gradient scale varies enormously across a deep transformer (embeddings vs LayerNorm gains vs attention projections), and a single global LR can't serve them all - SGD is notoriously hard to make work on transformers, while Adam-family optimizers are robust. The flip side: Adam keeps two extra fp32 states per parameter (~8 bytes/param), a major memory cost that motivates 8-bit optimizers and ZeRO-style sharding.
Worth sketching. Drawing the two EMAs as separate branches makes it obvious what bias correction is correcting and why it only matters early.
flowchart LR
A["Mini-batch gradient g"] --> B["m = b1 m + (1 - b1) g<br/>direction memory"]
A --> C["v = b2 v + (1 - b2) g squared<br/>scale memory"]
B --> D["Bias correct both:<br/>they start at zero"]
C --> D
D --> E["step = lr m_hat / (sqrt(v_hat) + eps)"]
E --> F["w = w - step"]
F -->|"next batch"| A
What a good answer covers
- Momentum maintains an exponential moving average of gradients and steps along that average
- In loss landscapes shaped like ravines - steep in some directions, shallow in others - vanilla SGD…
- Momentum cancels the oscillating components (they alternate sign and average out) and accumulates the…
- Adam adds a second idea: per-parameter adaptive step sizes
- It tracks both the first moment m (like momentum, β₁=0.9) and second moment v - an EMA of squared…
Key terms: Momentum · Adam · per-parameter adaptive step sizes · bias correction
Interviewer follow-ups to expect
Why does Adam need bias correction - what happens without it?
Adam adds a second idea: per-parameter adaptive step sizes. It tracks both the first moment m (like momentum, β₁=0.9) and second moment v - an EMA of squared gradients (β₂=0.999 classically, ~0.95 in LLM practice) - and updates with
w ← w − lr · m̂ / (√v̂ + ε). Dividing by √v̂ normalizes each parameter's step by its typical gradient magnitude: parameters with rare/small gradients (embedding rows for rare tokens) get relatively larger steps; parameters with large, noisy gradients get damped. The hats are bias correction - both EMAs are initialized at zero and severely underestimate their targets early in training; without correction, early steps would be badly mis-scaled.Why does SGD+momentum still often beat Adam on convnets?
What's the memory footprint of Adam for a 7B model and how do you reduce it?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep