Unit 10 · AI research · Lesson 1 of 9
Optimization and math foundations for ML research
Step 1: Learn the ideas
- Convexity, smoothness and the descent lemma
- Conditioning, curvature and why momentum helps
- Stochastic gradients: noise, batch size and the critical batch size
- Adaptive optimizers: Adam, AdamW and decoupled weight decay
- Learning-rate warmup, decay schedules and restarts
- Normalization and initialization as conditioning aids
- Implicit regularization and the sharp-versus-flat minima debate
- Scaling laws and compute-optimal training (awareness)
- Reading training curves: divergence, spikes and plateaus
Why it matters
Many research-engineering failures are optimization failures in disguise. An idea "does not work" because the learning rate was tuned for the baseline only, the warmup was missing, or the comparison stopped before one run had decayed its learning rate. Research interviewers therefore ask you to reason from first principles: why a step size diverges, what batch size does to gradient noise, why AdamW is not Adam with L2. You do not need convergence proofs for deep networks (few exist), but you need the convex intuitions that explain most of what you observe, and you need to know which claims in the literature are empirical regularities rather than theorems.
Core ideas
The quadratic picture. Near a minimum a smooth loss looks like a quadratic with Hessian H. Gradient descent multiplies the error along each eigenvector by (1 − η·λᵢ). It converges only if every factor has magnitude below 1, so η must stay below 2/λ_max, while the flattest direction (λ_min) sets the speed. The condition number κ = λ_max/λ_min is why plain descent crawls along narrow valleys. Momentum accumulates velocity along consistently signed directions and damps oscillation across the valley; on quadratics, well-tuned momentum needs on the order of √κ rather than κ iterations.
Convexity as a lens. For convex, L-smooth functions a step of 1/L guarantees descent and every local minimum is global. Networks are non-convex, yet the same local reasoning explains step-size limits, why normalization layers help (better conditioning), and why a learning rate that is stable early can become unstable when curvature grows during training.
Stochastic gradients. A minibatch gradient is an unbiased estimate whose variance falls roughly as 1/B. Doubling B halves the noise but also halves the number of updates per epoch. Up to a problem-dependent critical batch size, larger batches with proportionally larger learning rates train about as well per example; beyond it, returns diminish. The linear scaling rule with warmup is an empirical recipe for that regime. Noise also acts as a regularizer; the claim that small batches find flatter minima that generalize better is debated, partly because flatness depends on how the network is parameterized.
Adaptive methods. Adam keeps running estimates of each coordinate's first and second gradient moments, with bias correction for the early steps, and divides by the root of the second moment, making steps roughly invariant to gradient scale. An L2 term added to the loss is then rescaled by that denominator, so heavily updated weights are regularized less; AdamW applies decay directly to the weights instead.
Schedules. Warmup is usually explained by unreliable early moment estimates and high initial curvature. Decay (cosine, linear, step, inverse square root) lowers the noise floor late in training, which is why loss often drops sharply when the learning rate falls. Consequence for experiments: compare runs at the end of their own schedules, not at an intermediate step of a longer schedule.
Scaling laws (awareness). Empirical fits show loss falling roughly as a power law in parameters, data and compute over several orders of magnitude. Compute-optimal analyses ask how to split a fixed budget between model size and tokens, and different studies reached different answers partly because of schedule and fitting choices. Treat an exponent as a measurement with uncertainty, valid over the range where it was fitted.
Common misconceptions
- "Adam removes the need to tune the learning rate." It normalizes per-coordinate scale, but the global step size and warmup still dominate stability and final loss.
- "L2 regularization and weight decay are the same thing." They coincide for plain SGD, not for adaptive optimizers, which is the motivation for AdamW.
- "A bigger batch is always faster." Past the critical batch size each extra example adds little; wall-clock gains then come only from better hardware utilization.
- "Non-convex means convex theory is useless." Local quadratic models explain step-size limits, conditioning and the benefits of momentum and normalization remarkably well.
- "The curve plateaued, so training converged." A plateau often reflects the noise floor of the current learning rate; decaying it frequently reveals further progress.
- "Scaling laws predict any model's loss." They are fits for one data distribution, architecture family and recipe; extrapolation is a hypothesis to test.
How to approach it
Rebuild the quadratic picture first: run gradient descent and momentum on an ill-conditioned 2-D quadratic and watch divergence just above 2/λ_max. Then train a small network with SGD and AdamW under two schedules across several seeds while logging gradient norms. At graduate level, interviewers check that you can explain the update rules and learning-rate tradeoffs; at mid and senior level, expect "your run diverged after a few thousand steps, what do you check?" and "how would you compare two optimizers fairly?", which links to experimental controls.
Suggested order
- 1Read the d2l optimization chapter sections on convexity, gradient descent, SGD and minibatch SGD; reproduce step-size divergence on a 2-D quadratic in a notebook.
- 2Read "Why Momentum Really Works" (Distill) and confirm the improvement from momentum numerically by sweeping the condition number of your quadratic.
- 3Read the d2l sections on momentum, Adam and learning-rate scheduling, then the method section of the AdamW paper (listed with the ML training topics) for decoupled decay.
- 4Read "Accurate, Large Minibatch SGD" for the linear scaling rule and warmup, then the definitions and main figures of "An Empirical Model of Large-Batch Training" for the critical batch size.
- 5Read the CS229 main notes section "Implicit regularization effect" for the theoretical view of how the optimizer shapes generalization.
- 6Skim the compute-optimal scaling paper (introduction, the three estimation approaches, limitations) and the earlier Kaplan et al. scaling-law paper; note which conclusions depend on the learning-rate schedule.
- 7Do the optimizer and schedule study project with at least three seeds per configuration and a matched tuning budget.
Step 2: Check off what you can do
Tap each one you can genuinely do or explain. Each earns 10 XP.
Step 3: Go deeper
Dive into Deep LearningStart here
d2l.ai (open-source book)Section: Ch. 12: Optimization Algorithms
Convexity, gradient descent, SGD, momentum, Adam and learning-rate scheduling with runnable code to experiment with.
Open(opens in a new tab)Link responded, 5 Oct 2026Why Momentum Really WorksStart here
DistillVisual, quantitative explanation of conditioning, step-size limits and momentum on quadratics.
Open(opens in a new tab)Link responded, 5 Oct 2026Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour
arXivConcrete recipe and failure points for scaling learning rate with batch size, plus gradual warmup.
Open(opens in a new tab)Link responded, 5 Oct 2026An Empirical Model of Large-Batch Training
arXivQuantitative model of gradient noise and the critical batch size.
Open(opens in a new tab)Link responded, 5 Oct 2026Training Compute-Optimal Large Language Models
arXivAwareness-level reading on compute-optimal allocation and how scaling fits are produced.
Open(opens in a new tab)Link responded, 5 Oct 2026
Step 4: Practice
Implement gradient descent and momentum yourself once on a toy quadratic before using library optimizers. Back every claim (for example "AdamW is more stable here") with at least three seeds and an equal tuning budget per arm, and plot gradient norms next to the loss so you can explain spikes rather than only observe them.
- Optimizer and learning-rate schedule study on a small modelOpen(opens in a new tab)Not attemptedSelf-directed project (Dive into Deep Learning code as a starting point)
Record attempts on each problem’s page (+15 XP, +10 more when solved on your own).
Step 5: Test yourself
Answer each one out loud or on paper before you finish the lesson.
- Question 1Why does the flattest direction set convergence speed while the sharpest sets stability?
- Question 2What happens to gradient noise and to the number of updates when you double the batch size at a fixed number of epochs?
- Question 3Why can a learning rate that is stable early become unstable later in training?
- Question 4What problem does bias correction in Adam fix?
- Question 5Why should two runs be compared at the end of their own learning-rate schedules?
- Question 6What is the critical batch size, informally, and what determines it?
- Question 7Why are sharp-versus-flat minima arguments sensitive to reparameterization?
You’re done when you can
- Derive the 2/λ_max step-size bound for gradient descent on a quadratic without notes.
- Explain in under two minutes why Adam with an L2 penalty differs from AdamW.
- Given a loss curve with a spike and a plateau, name three plausible causes for each and the logs you would check.
- Run an optimizer comparison with at least three seeds per arm and report mean and spread rather than single runs.
- Explain what a compute-optimal scaling fit estimates and one reason it may not transfer to your setting.
Finish the lesson
Unlocks next: Reinforcement learning foundations (optional)


