A teammate multiplies a recommender's training loss by 100 so the dashboard shows larger numbers. For one weight the gradient has been steady at g = 0.004 per step. Compare plain SGD (lr = 0.01, no momentum) with Adam (lr = 10⁻³, default β and ε = 10⁻⁸) in steady state. How does each optimizer's step for this weight change, and what does that imply?
Show the answer and explanation
Correct answer: C, SGD: 4×10⁻⁵ becomes 4×10⁻³; Adam: stays about 10⁻³, because m̂ and √v̂ both scale by 100 and cancel. Adam's old lr therefore carries over, while SGD needs its lr divided by 100 to train as before.
Explanation Optimizers
Adam's update is Δθ = −η · m̂ / (√v̂ + ε), with m̂ the running mean gradient and v̂ the running mean squared gradient. Scaling the loss by c scales every gradient by c, so m̂ → c·m̂ and √v̂ → c·√v̂: the ratio is unchanged, apart from ε, which matters only when √v̂ is about as small as ε.
| Before (g = 0.004) | After (g = 0.4) | |
|---|---|---|
| SGD, η = 0.01 | 0.01 · 0.004 = 4×10⁻⁵ | 4×10⁻³ (100×) |
| Adam, η = 10⁻³, steady g | η · 0.004 / (0.004 + ε) ≈ 10⁻³ | η · 0.4 / (0.4 + ε) ≈ 10⁻³ (unchanged) |
Practical consequences:
- Reusing a learning rate. With SGD, a loss rescale (including switching
reductionfrom mean to sum at a fixed batch size) changes the effective learning rate by the same factor. With Adam the old lr carries over. - Loss weighting. Adam only cancels a global scale per parameter. In L₁ + λ·L₂, the shared backbone sees a mixture of both gradients, so λ still changes the direction and balance of its updates. Only parameters touched by a single term (such as one head) become insensitive to that term's scale.
- Gradient clipping thresholds and ε are not scale-invariant, so after a large rescale they behave differently.
Why the distractors fail: v̂ averages squared gradients, so it grows by 100² and its root by 100, not 10. Adam's step does not grow with the gradient, unlike SGD's. And scale invariance does not extend to relative loss weights on shared parameters.
Interview tip: "With Adam the learning rate sets the step size in parameter units, roughly independent of loss scale; with SGD the step is learning rate × gradient."