Instability diagnosis: localize the first broken quantity
Separate data, target, weighting, numerical, optimizer, and sampling failures through fixed-batch probes and controlled interventions.
On this page
The question for today
What you’ll understand
- Use target-scale baselines and exact probes before changing hyperparameters.
- Apply gradient clipping only after the intended gradient scale is established.
- Separate training divergence from sampling-configuration and autoencoder failures.
An exploding loss, a skipped optimizer step, and a poor sample grid are different symptoms. Diffusion adds several interfaces where a small mismatch can survive shape checking: data scale, noise coefficients, prediction type, timestep weights, and sampler interpretation. Find the first quantity that becomes inconsistent or nonfinite, then change one cause at a time instead of treating every failure as an excessive learning rate.
A fixed batch can expose a target or scale mismatch
Save clean inputs, encoded latents if used, timesteps, Gaussian draws, condition masks, coefficients, targets, and reference outputs. Recompute a forward and loss in a wide dtype and compare with the intended mixed-precision path. Check data ranges, channel order, latent scaling, coefficient broadcasting, and whether the scheduler expects epsilon or velocity. Verify the target uses the intended noise realization. A training variant that perturbs the noisy input while retaining another target is a separate declared objective, not an accidental implementation detail to ignore.
For ordinary unweighted per-coordinate noise MSE with standard Gaussian targets, a zero predictor has expected loss one at every timestep. That is a useful scale baseline under exactly those assumptions. A score target, summed feature reduction, noise offset, changed normalization, or timestep weight changes the number. One sampled batch can exceed the expectation without a defect. Inspect loss by timestep and data slice, and preserve both raw and weighted values so an objective change is not mistaken for numerical divergence.
Inspect finite gradients before relying on clipping
Trace activations, loss terms, unscaled gradients, parameter updates, optimizer moments, and skipped-step counters. Mixed-precision loss scaling changes gradient magnitude until it is undone; clip the intended unscaled gradients according to the framework's supported procedure. PyTorch 2.14 documents the ordering needed for AMP and clipping. A nonfinite gradient is not repaired by ordinary norm clipping, and repeated skipped updates can leave training stalled while logging continues. Compare a small full-precision run to isolate arithmetic range problems from a wrong target or unstable objective.
Clipping limits a finite gradient norm under the chosen rule, but does not prove that the direction is useful or that the learning rate is appropriate. Optimizers with moments or preconditioning do not turn the clipped gradient into a simple learning-rate-times-gradient update in general. Record actual update norms and effective batch reduction. If instability correlates with rare timestep weights, condition groups, or malformed examples, diagnose that association before lowering every learning rate or replacing the entire schedule.
Separate learning failures from evaluation-pipeline failures
Check autoencoder reconstruction, target conversion, scheduler configuration, timestep range, conditioning representation, guidance convention, and EMA restoration before interpreting generated artifacts. A model trained for one parameterization can look broken under a sampler reading its output as another. Use fixed examples and a tiny overfit diagnostic to verify that the implementation can fit a controlled task, while retaining a separate held-out evaluation for generalization. Restore a known checkpoint and vary one suspected setting with the same random inputs to test a causal hypothesis.
The optimization lab gives an exact quadratic stability contrast. Reset, set η=0.50 and x₀=1, predict x₂=0.25, then Step twice. Separately Reset, set η=2.50 and x₀=1, predict x₁=−1.5 and x₂=2.25, then Step twice. Each Step advances one iteration. These reachable values remain visible, and the model has no diffusion loss, neural network, AMP, or optimizer moments. Use it to distinguish a demonstrated unstable recurrence from an unsupported claim that the same scalar threshold governs every diffusion optimizer.
Work it through
A finite clipping calculation has a limited conclusion
After removing any loss scale, a finite gradient is [3,4]. Use global norm threshold two and a plain SGD update with learning rate 0.1, without momentum or weight decay.
The gradient norm is sqrt(3²+4²)=5, so the clipping multiplier is 2/5=0.4.
The clipped gradient is [1.2,1.6] with norm two.
Plain SGD changes the parameter by [−0.12,−0.16], whose norm is 0.2. A different optimizer or a nonfinite input gradient would require another analysis.
The stated rule limits this finite gradient and gives a calculable SGD step. It does not establish correct targets, useful directions, or stable long-run training.
The living notebook
Explore the model
Interactive lab · optimization
Diagnose an exact recurrence before generalizing its threshold
Reset, set η=0.50 and x₀=1, predict x₂=0.25, then Step twice. Separately Reset, set η=2.50 and x₀=1, predict x₁=−1.5 and x₂=2.25, then Step twice. The lab uses x_n=(1−η)ⁿx₀ for one quadratic, not diffusion, AMP, or an adaptive optimizer.
- Position x0
- 2
- Objective x²/2
- 2
- Iteration behavior
- Stable step
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 stability claim needs the actual recurrence or measured controlled experiment.
Pause & reason
Check your understanding
Your turn
Try it yourself
A zero noise predictor sees one four-coordinate target epsilon=[1,−1,2,0]. Compute per-coordinate MSE. Does a result above one alone prove the standard-noise generator is incorrect?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Sum squared coordinates and divide by four; distinguish a realization from an expectation.
Compare with the solution
The sum is 1+1+4+0=6, so MSE is 6/4=1.5. The expected baseline is one over standard Gaussian draws, not an exact value for every realization. Repeated controlled statistical checks and target inspection are needed before diagnosing a generator defect.
Keep the idea
Take it with you
- Trace the first inconsistent or nonfinite quantity with fixed inputs.
- Objective scale and gradient scale require explicit normalization.
- Sampling, EMA, conditioning, and autoencoder mismatches can mimic learning failure.
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.