core30 min studyLesson 15 in Engineering

Training dynamics and optimization failure

Understand step size, stochastic gradients, and adaptive optimizers by investigating when an update fails.

On this page

What you’ll understand

  • Derive a learning-rate stability condition for a quadratic.
  • Explain the tradeoffs of minibatch gradients.
  • Diagnose divergence before changing model capacity.

Training is a dynamical process, not a command that automatically finds the best model. Each update depends on the current parameters, a noisy estimate of sensitivity, numerical precision, and optimizer state. A small quadratic exposes the same basic tension seen in large networks: steps that are too small waste work, while steps that are too large overshoot useful regions and can diverge.

Curvature sets the scale of a safe step

For J(w)=aw2/2J(w)=aw^2/2 with a>0a>0, gradient descent multiplies ww by 1−ηa1-\eta a each step. Convergence requires the magnitude of this factor to be less than one. A factor between zero and one approaches the minimum without crossing it; a negative factor of magnitude below one oscillates while shrinking. At or beyond the stability boundary, loss need not decrease. Even a convex problem can therefore fail because of the update rule.

In many dimensions, different curvature directions have different preferred step sizes. A narrow valley combines steep motion across the valley with slow motion along it, so one global learning rate can be awkward. Feature scaling and preconditioning help this geometry; momentum carries a moving history of gradient directions. The one-dimensional bound is exact only for the stated quadratic. A changing nonconvex neural-network loss requires empirical monitoring and does not inherit a universal safe rate.

wt+1=(1−ηa)wt,∣1−ηa∣<1  ⟺  0<η<2aw_{t+1}=(1-\eta a)w_t,\qquad |1-\eta a|<1\iff 0<\eta<\frac{2}{a}
This stability result assumes a positive-curvature scalar quadratic, exact gradients, fixed learning rate, and exact arithmetic.↔ Scroll wide equations horizontally.

Noise, batch size, and adaptive updates

A minibatch gradient averages gradients for a subset of examples. With suitable independent uniform sampling it estimates the full training gradient without systematic bias, but it has sampling variance. A larger batch can reduce that variance while increasing memory and work per update. It does not automatically make training faster to a target quality. Correlated examples, variable sequence lengths, and nonuniform sampling complicate the relationship between the nominal batch size and the information in an update.

Adam maintains moving averages of gradients and squared gradients, applies bias corrections, and divides a first-moment estimate by a second-moment scale. This adapts coordinate-wise step magnitudes but is not a Hessian inverse or a guarantee of convergence to a global optimum. Decoupled weight decay, as in AdamW, shrinks parameters separately from the adaptive gradient step; simply adding an L2 term to Adam's loss is generally a different update. Record the optimizer definition rather than using these names interchangeably.

gB=1∣B∣∑i∈B∇ℓi(θ),θt+1=θt−ηm^tv^t+ϵg_B=\frac{1}{|B|}\sum_{i\in B}\nabla\ell_i(\theta),\qquad \theta_{t+1}=\theta_t-\eta\frac{\widehat m_t}{\sqrt{\widehat v_t}+\epsilon}
The first expression is a mean minibatch gradient. The second is the usual Adam-style parameter step using bias-corrected moment estimates; weight decay is not included in this displayed update.↔ Scroll wide equations horizontally.

Debug the process using measurable hypotheses

When loss explodes, inspect finite inputs, labels, activations, and gradient norms; reduce the learning rate; and confirm the loss reduction and accumulation scaling. When loss is flat, verify that parameters require gradients, the optimizer owns the intended parameters, and the update actually changes them. Check that masks do not discard every target. Log update norm relative to parameter norm, because a finite gradient can still produce a negligible or destructive step.

Separate optimization success from generalization. A descending training curve says the optimizer is fitting its objective, not that future performance is improving. Use a validation schedule and compare experiments at a common budget such as processed examples or wall-clock time. Warmup and learning-rate decay are design choices with task-dependent effects. Gradient clipping bounds a measured gradient norm but cannot repair invalid labels or prove stability. Change one suspected cause at a time and retain a small reproducible failure case.

Predict divergence before running it

Minimize J(w)=2w² from w=1. Compare learning rates 0.1 and 0.6 using exact gradient descent.

  1. The derivative is 4w, so curvature a=4 and the stability condition is 0<eta<0.5.

  2. At eta=0.1, each step multiplies w by 0.6. The first two values are 0.6 and 0.36; loss falls from 2 to 0.72 to 0.2592.

  3. At eta=0.6, each step multiplies w by −1.4. The first two values are −1.4 and 1.96; loss grows from 2 to 3.92 to 7.6832 despite the gradient always pointing uphill.

The result

Subtracting the gradient is a local direction choice; the step length determines whether that direction actually reduces the objective.

Explore the model

Interactive lab

Interactive lab · optimization

Compare stable and unstable descent

The lab follows gradient descent on f(x)=x²/2 with step size eta and starting value x₀. Compare eta below and above 2 to observe shrinking or diverging iterates. Its curvature is 1, unlike the worked example's curvature 4; it does not simulate Adam or a trained network.

Compare stable and unstable descentGradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Current readings: Position x0: 2; Objective x²/2: 2; Iteration behavior: Stable step. All parameters are adjustable with the labeled controls below.−4−202402.174.356.528.7Parameter xf(x) = x²/2n = 0
ObjectiveDiscrete iterate
Position x0
2
Objective x²/2
2
Iteration behavior
Stable step
n = 0 · t = 0 s

Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA sensible direction can still fail when the update is too large for the stated curvature.

Check your understanding

For J(w)=3w²/2 with a fixed exact-gradient step, which learning rate guarantees convergence from any starting w?

Try it yourself

Two equally sized microbatches have mean gradients 2 and 6 for one parameter. What gradient reproduces the combined-batch mean, and what happens if you add the two means without scaling?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

A combined mean gives equal weight to every example, not a full batch's weight to each microbatch.

Compare with the solution

The correct mean is (2+6)/2=4. Adding the means gives 8 and doubles the gradient scale, equivalent to doubling the learning rate for this step. With unequal microbatch sizes, weight each mean by its example count; averaging means equally would then be wrong.

Take it with you

  • Step size must respect curvature, even for a convex loss.
  • Batch size changes noise, memory, and work rather than guaranteeing speed.
  • Measure update behavior before attributing failure to model capacity.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.