Advanced Machine Learning

15: Stochastic Gradient Descent

Schedule (you are here )

# date topic description
124-Aug-2026Introduction
226-Aug-2026Foundations of learningDrop/Add
331-Aug-2026PAC learnabilityHW1
402-Sep-2026Linear learning models
507-Sep-2026Labor Day HolidayHoliday
609-Sep-2026Principal Component AnalysisProject ideas
714-Sep-2026Curse of DimensionalityHW2, HW1 due
816-Sep-2026Bayesian Decision Theory
921-Sep-2026Parameter estimation: MLE
1023-Sep-2026Parameter estimation: MAP & NBfinalize teams
1128-Sep-2026Logistic RegressionHW3, HW2 due
1230-Sep-2026Kernel Density Estimation
1305-Oct-2026Support Vector Machines
1407-Oct-2026Matrix Factorization
1512-Oct-2026* MidtermExam, HW3 due
1614-Oct-2026k-means clustering
1719-Oct-2026Invited: Intro to Causal Learning I
# date topic description
1821-Oct-2026Invited: Intro to Causal Learning II
1926-Oct-2026* Mid-point projects checkpointHW4, P
2028-Oct-2026Expectation Maximization
2102-Nov-2026Stochastic Gradient Descent
2204-Nov-2026Automatic Differentiation
2309-Nov-2026Nonlinear embedding approachesHW5, HW4 due
2411-Nov-2026Model comparison & calibration
2516-Nov-2026Convolutional Neural Networks
2618-Nov-2026Word Embedding
2723-Nov-2026Thanksgiving BreakHoliday
2825-Nov-2026Thanksgiving BreakHoliday
2930-Nov-2026* Final ExamExam
3002-Dec-2026Project Final PresentationsHW5 due, P
3107-Dec-2026No classClasses End
3216-Dec-2026Project Reportsdue
3317-Dec-2026Grades due 5 p.m.PAWS

Outline for the lecture

  • Gradient Descent Variants: Batch, Stochastic & Mini-Batch
  • Fluctuations, Sharp Minima & Learning Rate Schedules
  • Pathological Ravines, Momentum & Nesterov Lookahead
  • Adaptive & Spectral Optimizers: AdaGrad, RMSprop, AdamW & Muon
  • Large-Scale Learning Trade-Offs (Bottou & Bousquet)

Connecting the Dots: Why Stochastic Optimization?

1. ERM & Closed-Form Linear / Spectral Models
Linear regression and PCA solve $\nabla \prob{J}{\vth} = \vec{0}$ analytically via $(\bm{X}^T\bm{X})^{-1}$ or SVD in $O(Nd^2 + d^3)$ time.
2. Non-Closed-Form Convex Objectives
Logistic regression and SVMs couple parameters nonlinearly — requiring iterative gradient or QP solvers.
3. Non-Convex Landscapes & Latent Variables
Matrix factorization ($\bm{W}\bm{H}$), K-means, and GMMs introduce curved valleys, saddle points, and local optima.
4. The Big-Data & High-Dimension Wall
When $N \sim 10^8$ and $d \sim 10^9$, full-batch $O(N)$ gradients and $O(d^2)$ Hessians are computationally impossible.
5. Today: Stochastic & Adaptive Optimization
How do noisy $O(1)$ mini-batch gradients, momentum, and adaptive/spectral preconditioners train modern ML?
# date topic
2–4Aug–SepERM, PAC & Linear Models
609-Sep-2026Principal Component Analysis
714-Sep-2026Curse of Dimensionality
9–1021–23 SepParameter Estimation: MLE & MAP
1128-Sep-2026Logistic Regression
1305-Oct-2026Support Vector Machines
1407-Oct-2026Matrix Factorization
1614-Oct-2026k-means clustering
17–1819–21 OctIntro to Causal Learning I & II
2028-Oct-2026Expectation Maximization
2102-Nov-2026Stochastic Gradient Descent
2204-Nov-2026Automatic Differentiation

Gradient Descent Variants

From $O(N)$ full-batch passes to $O(1)$ stochastic and mini-batch updates

Gradient Descent: Steepest Downhill Step

First-order iterative minimization of an objective function $\prob{J}{\vth}$
  • $\prob{J}{\vth}$: Objective / empirical loss function
  • $\vth \in \RR^d$: Parameters of the model
  • $\eta > 0$: Learning rate (step size along the negative gradient)
Update Equation
$\vth_{t+1} = \vth_t - \eta \nabla_{\vth} \prob{J}{\vth_t}$
Gradient Descent

Why Can We Sample the Gradient?

In ERM and MLE, the total objective is an average over $N$ training examples $\{(\vec{x}_i, y_i)\}_{i=1}^N$:
$\displaystyle \prob{J}{\vth} = \frac{1}{N}\sum_{i=1}^N \loss(\vth; \vec{x}_i, y_i) \implies \nabla_{\vth}\prob{J}{\vth} = \frac{1}{N}\sum_{i=1}^N \nabla_{\vth}\loss(\vth; \vec{x}_i, y_i) = \EE_{i \sim \text{Unif}}\!\Big[\nabla_{\vth}\loss(\vth; \vec{x}_i, y_i)\Big]$
  • 1. Linearity of differentiation: The gradient of an average is the average of the per-sample gradients.
  • 2. Unbiased Mini-Batch Estimator: Draw a uniform random subset ${\cal B} \subset \{1,\dots,N\}$ of size $B = |{\cal B}|$:
    $\displaystyle \hat{\vec{g}}_{\cal B}(\vth) \;\def\; \frac{1}{B}\sum_{i \in {\cal B}} \nabla_{\vth}\loss(\vth; \vec{x}_i, y_i) \implies \underbrace{\EE\!\left[\hat{\vec{g}}_{\cal B}(\vth)\right] = \nabla_{\vth}\prob{J}{\vth}}_{\text{unbiased downhill direction!}}, \qquad \underbrace{\text{Cov}\!\left(\hat{\vec{g}}_{\cal B}(\vth)\right) \approx \frac{\bm{\Sigma}_g}{B}}_{\text{variance shrinks as } 1/B}$
  • Key Insight: Step cost scales as $O(B)$, while gradient noise std. dev. shrinks as $1/\sqrt{B}$!

Three Gradient Descent Variants

How many examples $B$ do we use per parameter update?
  • Batch Gradient Descent ($B = N$: entire dataset)
  • Stochastic Gradient Descent ($B = 1$: a single random example)
  • Mini-Batch Gradient Descent ($1 < B \ll N$: a small batch, e.g. $B = 32\text{–}512$)
Unified Update Rule
$\vth_{t+1} = \vth_t - \eta \, {\color{#dc322f} \hat{\vec{g}}_t(\vth_t)}$
The red gradient estimate $\hat{\vec{g}}_t$ is the only difference between the three methods!

Trade-Offs Across the Three Variants

Balancing update accuracy vs. wall-clock time per step
  • Accuracy of each gradient step: Variance scales as $\bm{\Sigma}_g / B$
  • Compute time per update: Evaluations scale as $O(B)$
Method Batch Size $B$ Step Accuracy Step Time Memory Online
Batch $N$ Exact ($\text{Var}=0$) Slow $O(N)$ High
Stochastic $1$ Noisy ($\text{Var}=\bm{\Sigma}_g$) Fast $O(1)$ Low
Mini-Batch $32\text{–}512$ Low Var ($\bm{\Sigma}_g/B$) Fast (GPU GEMM) Moderate

Batch Gradient Descent (B = N)

Compute the exact gradient of $\prob{J}{\vth}$ over the entire dataset
Update Equation
$\displaystyle \vth_{t+1} = \vth_t - \frac{\eta}{N}\sum_{i=1}^N \nabla_{\vth}\loss(\vth_t; \vec{x}_i, y_i)$
We must evaluate gradients for all $N$ examples to perform just one update.

for epoch in range(number_of_epochs):
    gradient = eval_gradient(loss_fun, data, params)  # O(N) full pass
    params = params - eta * gradient
            

Batch Gradient Descent: Pros & Cons

Advantages
  • Deterministic trajectory on the exact empirical risk surface $\prob{J}{\vth}$
  • Guaranteed to converge to the global minimum (if convex) or a local minimum (if non-convex) for suitable $\eta$
Disadvantages
  • Prohibitive $O(N)$ compute cost per step when $N$ is large (redundant gradients across similar examples!)
  • Intractable when the full dataset exceeds RAM / GPU memory
  • Cannot incorporate new streaming data on the fly (no online learning)

Stochastic Gradient Descent (B = 1)

Perform a parameter update for each single training example $(\vec{x}_i, y_i)$
Update Equation
$\vth_{t+1} = \vth_t - \eta \nabla_{\vth} \loss(\vth_t; \vec{x}_i, y_i)$
Evaluates the gradient on a single data sample ($N\times$ faster per update!).

for epoch in range(number_of_epochs):
    np.random.shuffle(data)  # Break ordering bias each epoch!
    for example in data:
        gradient = eval_gradient(loss_fun, example, params)  # O(1) cost
        params = params - eta * gradient
            

Stochastic Gradient Descent: Pros & Cons

Advantages
  • Makes immediate progress from the very first example ($N$ updates per pass through the dataset)
  • Natural fit for online / streaming learning where new samples arrive continuously
Disadvantages
  • High per-step variance $\bm{\Sigma}_g$ causes the objective $\prob{J}{\vth_t}$ to fluctuate heavily
  • Sequential $B=1$ updates underutilize modern SIMD / GPU vector hardware

Mini-Batch Gradient Descent (1 < B ≪ N)

The best of both worlds: low-variance updates + GPU matrix parallelism
$\displaystyle \vth_{t+1} = \vth_t - \frac{\eta}{B}\sum_{j=i}^{i+B-1} \nabla_{\vth}\loss(\vth_t; \vec{x}_j, y_j)$

for epoch in range(number_of_epochs):
    np.random.shuffle(data)
    for batch in batch_iterator(data, batch_size=32):
        gradient = eval_gradient(loss_fun, batch, params)  # GPU GEMM!
        params = params - eta * gradient
            
  • Pros: Shrinks gradient variance by $1/B$ and saturates GPU tensor cores via matrix-matrix multiplies.
  • Con: Adds mini-batch size $B \in \{32, 64, 128, 256, \dots\}$ as a hyperparameter (linear scaling rule: $\eta \propto B$).

Stochastic Fluctuations

How stochastic gradient agitation escapes sharp local traps — and why $\eta_t$ must anneal to settle at $\vth^*$

The Fluctuations of Stochastic Updates

$\displaystyle \textbf{Objective }\text{J}(\vth, \text{Data})\textbf{:}\;\; \underbrace{\text{J}(\vth, \CD)}_{\text{Full Batch (1 fixed surface)}} \neq \underbrace{\text{J}(\vth, {\cal B}_t)}_{\text{Mini-Batch }t\text{ (new surface every step!)}} \neq \underbrace{\text{J}\big(\vth, \{\vec{x}_i, y_i\}\big)}_{\text{Single Sample }i\text{ surface}}$
  • Shifting Surface $\text{J}(\vth, {\cal B}_t)$: Swapping data ${\cal B}_t$ warps the objective itself! SGD never steps uphill — it rolls downhill on $\text{J}(\vth, {\cal B}_t)$ as fragile sharp traps of $\text{J}(\vth, \CD)$ tilt open and vanish.
  • Why This Is Liberating: Why polish a single sample or batch ${\cal B}_t$ (or even $\CD$) to perfection when none of them is the true test risk? One cheap, coarse step per batch is all a proxy surface deserves!
  • The Catch (Moving Target $\vth^*_{{\cal B}_t}$): Inside a wide flat basin, each batch has its own shifted minimum $\vth^*_{{\cal B}_t} \ne \vth^*_{\CD}$, keeping constant-$\eta$ SGD orbiting in an $O(\sqrt{\eta\sigma^2})$ noise ball.
1. Shifting Surface J(θ, Bₜ) Warps Every Step (Sharp Traps Vanish!) Sharp Trap on Fixed J(θ, D) Wide Flat Basin: Moving Minima θ*(Bₜ) Trap vanishes on J(θ, Bₜ) → rolls downhill! 2. 2D Contours: Fixed J(θ, D) vs. Shifting Batch Bowl J(θ, Bₜ) θ*(Bₜ) θ*(D) Noise Ball O(√ησ²) θ₀ Batch GD: fixed J(θ, D) SGD: chases shifting θ*(Bₜ)

Learning Rate Annealing & Robbins–Monro

Why doesn't constant-step SGD stop at the minimum $\vth^*$?
  • At $\vth^*$, the full gradient is zero ($\nabla\prob{J}{\vth^*} = \frac{1}{N}\sum_{i=1}^N \nabla\loss_i(\vth^*) = \vec{0}$), so Batch GD halts automatically.
  • But individual sample gradients $\nabla\loss_i(\vth^*) \ne \vec{0}$ only cancel on average! With fixed $\eta$, SGD bounces perpetually inside a noise ball of radius $O(\sqrt{\eta \sigma^2})$.
  • To converge to $\vth^*$ (Robbins & Monro, 1951), decay $\eta_t$ so that:
    $\displaystyle \underbrace{\sum_{t=1}^{\infty} \eta_t = \infty}_{\text{can reach }\vth^*\text{ from any }\vth_0} \qquad \text{and} \qquad \underbrace{\sum_{t=1}^{\infty} \eta_t^2 < \infty}_{\text{cumulative noise variance }\sum \eta_t^2\sigma^2\text{ stays finite!}}$
  • Schedules in practice: Polynomial $\eta_t = \frac{\eta_0}{1 + \alpha t}$ (satisfies Robbins–Monro), Step Decay, Cosine Annealing $\eta_t = \frac{1}{2}\eta_0\!\left(1 + \cos\frac{t\pi}{T}\right)$.

Batch vs. Mini-Batch vs. Stochastic Gradient Descent

Click 2D contour plot to set $\vec{\theta}_0$ and compare trajectories ($N = 64$).
Step: 0 Batch J: -- Mini-Batch J: -- SGD J: --

Momentum & Nesterov

Overcoming pathological curvature ($\kappa = \lambda_{\max}/\lambda_{\min} \gg 1$), narrow canyons, and oscillations

Four Core Challenges of Vanilla SGD

  • 1. Global Learning Rate Sensitivity: Too small $\eta \implies$ glacial progress; too large $\eta \implies$ divergence.
  • 2. Schedule Tuning: Annealing rates must be hand-tuned to problem geometry and dataset size.
  • 3. Uniform Step Size Across Coordinates: Uses the same scalar $\eta$ for both steep/frequent and flat/rare features.
  • 4. Ravines & Saddle Points: Oscillates wildly across narrow canyons and stalls on flat high-dimensional saddles.
Our Toolkit:   Momentum $\to$ Nesterov (NAG) $\to$ AdaGrad $\to$ RMSprop $\to$ Adadelta $\to$ Adam / AdamW $\to$ Muon

Pathological Curvature: Ravines & Conditioning

Local quadratic canyon $\prob{J}{\vth} = \frac{1}{2}\!\left(\lambda_{\min}\theta_1^2 + \lambda_{\max}\theta_2^2\right)$
  • Condition number $\kappa \def \frac{\lambda_{\max}}{\lambda_{\min}} \gg 1$ (steep walls $\theta_2$, gentle floor $\theta_1$).
  • Light Ball (Vanilla GD, $\gamma=0$): Zero inertia; gradient step $-\eta\nabla\prob{J}{\vth}$ points across the canyon and bounces wall-to-wall!
  • Heavy Ball (Momentum, $\gamma>0$): Physical inertia damps wall oscillations and accelerates down the $\theta_1$ floor (Goh, 2017).
3D Quadratic Ravine: Light Ball (GD) vs. Heavy Ball (Momentum) θ₁ (gentle floor λₘᵢₙ) θ₂ (steep wall λₘₐₓ) Start θ₀ Floor θ* Light Ball (GD, γ=0): Bounces on walls Heavy Ball (Momentum): Rides floor

Heavy-Ball Momentum (Polyak, 1964)

Give the parameter vector physical inertia via a velocity vector $\vec{v}_t$
$\displaystyle \vec{v}_t = \underbrace{\gamma \vec{v}_{t-1}}_{\text{momentum }(\gamma \approx 0.9)} + \underbrace{\eta \nabla_{\vth} \prob{J}{\vth_t}}_{\text{current gradient pull}}, \qquad \vth_{t+1} = \vth_t - \vec{v}_t$
  • 1. Unrolling the recursion: $\vec{v}_t = \eta \sum_{\tau=0}^t \gamma^\tau \nabla_{\vth}\prob{J}{\vth_{t-\tau}}$ is an exponentially weighted sum of past gradients.
  • 2. Across steep canyon walls ($\theta_2$): Alternating signs $(+, -, +, -)$ cancel out, damping zig-zag oscillations!
  • 3. Along the valley floor ($\theta_1$): Steady gradients accumulate to terminal velocity $\frac{\eta}{1 - \gamma}\nabla\prob{J}{\vth}$ ($10\times$ speedup for $\gamma = 0.9$!).

Nesterov Accelerated Gradient: Lookahead Step

$\displaystyle \vec{v}_t = \gamma \vec{v}_{t-1} + \eta \nabla_{\vth} \text{J}\big(\!\underbrace{\vth_t - \gamma \vec{v}_{t-1}}_{\text{lookahead }\tilde{\vth}_t}\!\big)$
$\displaystyle \vth_{t+1} = \vth_t - \vec{v}_t \qquad (\gamma \approx 0.9)$
  • Momentum: Evaluates $\nabla\prob{J}{\vth_t}$ at the old position, then blindly adds $-\gamma\vec{v}_{t-1}$.
  • Nesterov (1983): First steps to the lookahead point $\tilde{\vth}_t = \vth_t - \gamma\vec{v}_{t-1}$, then evaluates $\nabla\prob{J}{\tilde{\vth}_t}$ there to brake before overshooting!
θₜ 1. −η∇J(θₜ) 2. −γvₜ₋₁ (Momentum) θₜ₊₁ (Mom) 1. Lookahead −γvₜ₋₁ θ̃ₜ = θₜ − γvₜ₋₁ 2. −η∇J(θ̃ₜ) (brakes!) θₜ₊₁ (NAG)

Ravines, Condition Number, Momentum & Nesterov Lookahead

Left (1:1 scale): Canyon $\prob{J}{\theta_1,\theta_2} = \frac{1}{2}(\theta_1^2 + \kappa\theta_2^2)$.   Right: Live lookahead vector magnifier.
Step t: 0 GD J: -- Mom J: -- NAG J: --
Presets:
Stability Limit (2/κ): 0.100

Adaptive & Spectral Optimizers

From coordinate-wise second moments (AdaGrad, RMSprop, Adadelta, AdamW) to matrix orthogonalization (Muon)

AdaGrad: Per-Coordinate Adaptive Learning Rates

Duchi, Hazan & Singer (2011): Give rare/flat features large steps and frequent/steep features small steps
$\displaystyle \vec{g}_t = \nabla_{\vth}\prob{J}{\vth_t}, \qquad \underbrace{\vec{v}_t = \vec{v}_{t-1} + \vec{g}_t^2 = \sum_{\tau=1}^t \vec{g}_\tau^2}_{\text{cumulative sum of squared gradients}}, \qquad \vth_{t+1} = \vth_t - \underbrace{\frac{\eta}{\sqrt{\vec{v}_t + \epsilon}}}_{\text{effective }\vec{\eta}_t} \odot \vec{g}_t$
  • Why it works: Coordinates with huge past gradients ($v_{t,j} \gg 1$) have their step size automatically damped; sparse features ($v_{t,j} \approx 0$) keep full step size $\eta$.
  • The Fatal Flaw: Because $\vec{g}_\tau^2 \ge 0$, the sum $\vec{v}_t = \sum_{\tau=1}^t \vec{g}_\tau^2$ grows monotonically without bound ($\vec{v}_t \to \infty$).
  • Eventually $\eta / \sqrt{\vec{v}_t} \to 0$ and learning freezes completely before reaching the optimum!

RMSprop: Stop the Diminishing Learning Rate

Tieleman & Hinton (2012): Replace AdaGrad's unbounded sum with a leaky Exponential Moving Average
$$\begin{aligned} \vec{g}_t &= \nabla_{\vth} \prob{J}{\vth_t}, \qquad \prob{E}{\vec{g}^2}_t = \gamma \prob{E}{\vec{g}^2}_{t-1} + (1 - \gamma)\vec{g}_t^2 \quad (\text{leaky average, }\gamma \approx 0.9) \\ \vth_{t+1} &= \vth_t - \frac{\eta}{\underbrace{\sqrt{\prob{E}{\vec{g}^2}_t + \epsilon}}_{\text{RMS}[\vec{g}]_t}} \odot \vec{g}_t \end{aligned}$$
  • Divides each gradient coordinate by its local Root-Mean-Square $\text{RMS}[\vec{g}]_t$ over the last $\approx \frac{1}{1-\gamma}$ steps.
  • Ancient gradients decay exponentially ($\gamma^\tau \to 0$), so the step size adapts dynamically to current terrain!

A Subtle Flaw: Do the Parameter Units Match?

Zeiler (2012): Check the physical units of $\Delta\vth$ (assuming dimensionless objective $J$):
$$\begin{aligned} \text{1. SGD / Momentum:} \quad & \text{units of } \Delta\vth \propto \text{units of } \vec{g} = \text{units of } \frac{\partial J}{\partial \vth} \propto \color{#dc322f}{\frac{1}{\text{units of }\vth}} \\ \text{2. AdaGrad / RMSprop:} \quad & \text{units of } \Delta\vth \propto \text{units of } \frac{\vec{g}}{\text{RMS}[\vec{g}]} \propto \color{#cb4b16}{1 \quad (\text{dimensionless!})} \end{aligned}$$
$$\text{3. Newton's Method (2nd Order):} \quad \Delta\vth = -\bm{H}^{-1}\vec{g} \propto \frac{\partial J / \partial \vth}{\partial^2 J / \partial \vth^2} \propto \frac{1 / \text{units of }\vth}{1 / (\text{units of }\vth)^2} = \color{#859900}{\text{units of }\vth \; \checkmark}$$
Since $\Big|\frac{\partial^2 J}{\partial \vth^2}\Big|^{-1} \propto \Big|\frac{\Delta\vth}{\vec{g}}\Big|$, we restore the right units by multiplying by $\text{RMS}[\Delta\vth]_{t-1}$!

Adadelta: Matching Units Without Learning Rate η

Replace the arbitrary scalar $\eta$ in RMSprop's numerator with $\text{RMS}[\Delta\vth]_{t-1}$:
$$\begin{aligned} \vec{g}_t &= \nabla_{\vth} \prob{J}{\vth_t}, \qquad \prob{E}{\vec{g}^2}_t = \gamma\prob{E}{\vec{g}^2}_{t-1} + (1-\gamma)\vec{g}_t^2 \\ \Delta\vth_t &= -\frac{\text{RMS}[\Delta\vth]_{t-1}}{\text{RMS}[\vec{g}]_t} \odot \vec{g}_t = -\frac{\sqrt{\prob{E}{\Delta\vth^2}_{t-1} + \epsilon}}{\sqrt{\prob{E}{\vec{g}^2}_t + \epsilon}} \odot \vec{g}_t \\ \prob{E}{\Delta\vth^2}_t &= \gamma\prob{E}{\Delta\vth^2}_{t-1} + (1-\gamma)\Delta\vth_t^2, \qquad \vth_{t+1} = \vth_t + \Delta\vth_t \end{aligned}$$
Result: $\Delta\vth_t$ has the exact units of $\vth$, acts as a diagonal secant approximation, and needs no global $\eta$!

Adam: Adaptive Moment Estimation (2015)

Fuse Momentum (1st moment $\vec{m}_t$) + RMSprop (2nd moment $\vec{v}_t$) + Zero-Init Bias Correction
$$\begin{aligned} \vec{m}_t &= \beta_1 \vec{m}_{t-1} + (1 - \beta_1) \nabla_{\vth} \prob{J}{\vth_t} \qquad &&\text{(1st moment: Momentum EMA, }\beta_1 \simeq 0.9\text{)} \\ \vec{v}_t &= \beta_2 \vec{v}_{t-1} + (1 - \beta_2) \big(\nabla_{\vth} \prob{J}{\vth_t}\big)^2 \qquad &&\text{(2nd moment: RMSprop EMA, }\beta_2 \simeq 0.999\text{)} \\ \hat{\vec{m}}_t &= \frac{\vec{m}_t}{1 - \beta_1^t}, \qquad \hat{\vec{v}}_t = \frac{\vec{v}_t}{1 - \beta_2^t} \qquad &&\text{(Corrects }\vec{m}_0 = \vec{v}_0 = \vec{0}\text{ startup bias!)} \\ \vth_{t+1} &= \vth_t - \frac{\eta}{\sqrt{\hat{\vec{v}}_t} + \epsilon} \odot \hat{\vec{m}}_t \qquad &&(\epsilon \simeq 10^{-8}) \end{aligned}$$
Why divide by $1 - \beta_2^t$? At $t=1$ with $\beta_2=0.999$, $\vec{v}_1 = 0.001\vec{g}_1^2$ underestimates variance by $1000\times$ — without bias correction, the first step $1/\sqrt{\vec{v}_1}$ would be $\approx 31.6\times$ too huge!

The Coordinate-Wise Optimizer Family & AdamW

Notable Extensions
  • AdaMax: $\ell_\infty$-norm second moment $\max(\beta_2\vec{v}_{t-1}, |\vec{g}_t|)$
  • Nadam: Nesterov lookahead inside Adam's $\hat{\vec{m}}_t$
  • AMSGrad: Non-decreasing $\hat{\vec{v}}_t = \max(\hat{\vec{v}}_{t-1}, \vec{v}_t)$
  • QHAdam / AggMo: Multi-damping momentum
  • AdamW (Loshchilov & Hutter, 2019): Decoupled weight decay
Why AdamW Beats Adam + $L_2$
Adding $\frac{\lambda}{2}\|\vth\|^2$ to $J(\vth)$ puts $\lambda\vth_t$ inside $\vec{g}_t$, so Adam divides weight decay by $\sqrt{\hat{\vec{v}}_t}$ — weakening regularization on large-gradient weights!

AdamW decouples decay directly on $\vth_t$:
$\displaystyle \vth_{t+1} = (1 - \eta\lambda)\vth_t - \frac{\eta}{\sqrt{\hat{\vec{v}}_t}+\epsilon}\odot\hat{\vec{m}}_t$
Rule of thumb: Use AdamW if in doubt — unless optimizing 2D hidden matrices, where Muon shines!

The Latest & Greatest: Muon Optimizer

Jordan et al. (2024) / Bernstein & Newhouse: Matrix-Aware Steepest Descent
  • Why Coordinate-Wise Adam Falls Short: Hidden layers are 2D matrices $\bm{W} \in \RR^{m\times n}$. Momentum $\bm{M}_t = \mu\bm{M}_{t-1} + \nabla_{\bm{W}}\prob{J}{\bm{W}_t}$ has skewed singular values ($\sigma_1 \gg \sigma_r$), so a few directions dominate while rare singular directions starve!
  • Muon's Idea (SVD $\bm{M}_t = \bm{U}\bm{\Sigma}\bm{V}^T$): Replace $\bm{M}_t$ with its nearest semi-orthogonal matrix ($\sigma_i \mapsto 1$ for all $i$):
    $\displaystyle \bm{W}_{t+1} = \bm{W}_t - \eta\,\text{Ortho}(\bm{M}_t), \; \text{Ortho}(\bm{M}_t) = \bm{U}\bm{V}^T$
  • Fast GPU Trick (No $O(n^3)$ SVD!): Normalize $\bm{X}_0 = \bm{M}_t / \|\bm{M}_t\|_F$ and run 5 steps of Newton–Schulz in $\text{bf16}$ ($<1\%$ FLOP overhead!):
    $\displaystyle \bm{X}_{k+1} = a\bm{X}_k + b(\bm{X}_k\bm{X}_k^T)\bm{X}_k + c(\bm{X}_k\bm{X}_k^T)^2\bm{X}_k$
5-Step Newton–Schulz Maps All σᵢ ∈ (0, 1] → 1 1.0 0.0 Input Singular Value σᵢ Raw Mₜ (σᵢ) 5-Step Newton–Schulz p⁽⁵⁾(σᵢ) ≈ 1 Raw Momentum Mₜ = UΣVᵀ Muon Ortho(Mₜ) = UVᵀ σ₁ ≫ σ₂ (rare directions starve) ⇒ σ₁ = σ₂ = 1 (all directions move!) Rule: Muon for 2D hidden matrices W + AdamW for 1D embeddings/biases/heads

Adaptive Optimizers: Saddle Points, Valleys & Spectral Steps

Click 2D landscape to place $\vec{\theta}_0$ and race 6 optimizers!
t:0 SGD:-- Mom:-- AdaG:-- RMS:-- Adam:-- Muon:--
Click anywhere on contour plot to relocate $\vec{\theta}_0$!

Large-Scale Learning

Why $O(1)$ stochastic updates beat $O(N)$ batch solvers when data is abundant

The Rise of SGD: Large-Scale Learning

Bottou and Bousquet 2007 Table

Why O(1) SGD Beats O(N) Batch Solvers at Scale

Bottou & Bousquet (2007): Decompose total excess test risk ${\cal E}$ (recall Lectures 2–3!):
$\displaystyle {\cal E} \;=\; \underbrace{\big(\prob{R}{f^*_{\hclass}} - \prob{R}{f^*}\big)}_{{\cal E}_{\text{app}}\text{: Model Capacity}} \;+\; \underbrace{\big(\prob{R}{f_N} - \prob{R}{f^*_{\hclass}}\big)}_{{\cal E}_{\text{est}}\text{: Statistical Noise } \sim O(1/\sqrt{N})} \;+\; \underbrace{\big(\prob{R}{\tilde{f}_N} - \prob{R}{f_N}\big)}_{{\cal E}_{\text{opt}}\text{: Optimization Error } \le \rho}$
  • 1. Don't Over-Optimize Statistical Noise: Since empirical risk $f_N$ already differs from true risk $f^*_{\hclass}$ by ${\cal E}_{\text{est}} \propto 1/\sqrt{N}$, driving optimization tolerance $\rho \ll {\cal E}_{\text{est}}$ (e.g. $\rho = 10^{-12}$) gives zero test-set benefit!
  • 2. Fixed Time Budget $T_{\max}$: Batch GD / 2nd-order methods spend $O(N)$ per step to shrink $\rho$ exponentially ($\log\frac{1}{\rho}$), but can only afford a few steps when $N \sim 10^8$.
  • 3. Why SGD Wins: SGD's per-step cost is $O(1)$ (independent of $N$!) — to reach statistical precision $\rho \propto 1/N$, total time $T(\rho)$ is $O(1/\rho)$ for SGD vs. $O(N\log\frac{1}{\rho})$ for Batch GD!

Take Home Points

  • Unbiased Mini-Batch Gradients: $\hat{\vec{g}}_{\cal B}(\vth)$ is an unbiased estimate of $\nabla\prob{J}{\vth}$ with cost $O(B)$ and variance $\bm{\Sigma}_g / B$, unlocking GPU matrix parallelism.
  • Noise Ball & Robbins–Monro Schedules: Constant-$\eta$ SGD oscillates in an $O(\sqrt{\eta\sigma^2})$ ball around $\vth^*$; annealing $\eta_t$ ($\sum \eta_t = \infty, \sum \eta_t^2 < \infty$) guarantees convergence.
  • Ravines, Momentum & Nesterov Lookahead: Steep canyons ($\kappa = \lambda_{\max}/\lambda_{\min} \gg 1$) make GD zig-zag; Momentum damps oscillations and NAG evaluates $\nabla\prob{J}{\vth_t - \gamma\vec{v}_{t-1}}$ at the lookahead point.
  • Adaptive Preconditioning (AdaGrad $\to$ RMSprop $\to$ AdamW): Normalizing by $\sqrt{\EE[\vec{g}^2]_t} + \epsilon$ with bias correction $(1-\beta^t)$ equalizes per-coordinate step sizes.
  • Muon & Large-Scale Learning: Muon orthogonalizes 2D momentum matrices ($\bm{U}\bm{V}^T$ via 5-step Newton–Schulz) so every singular direction advances equally; at large $N$, $O(1)$ stochastic steps beat $O(N)$ batch methods.