Course contentsShow
← Machine Learning and Deep Learning
Lesson 2779 of 3,53860. Distributed Training: Model Parallelism and Mixed PrecisionFree lesson

Debugging Mixed Precision Issues

Learn to diagnose NaN losses, overflow errors, and convergence problems specific to reduced precision.

Debugging Mixed Precision Issues

What you'll learn: How to identify and fix the most common failures that occur when training neural networks in reduced precision.

The Core Challenge

Mixed precision training accelerates your models and reduces memory consumption, but it introduces numerical instability risks that don't exist in full FP32 training. The three most common problems are NaN losses (Not-a-Number), overflow errors, and convergence failures—all stemming from the limited range and precision of FP16 or BF16 formats.

Think of reduced precision like trying to measure ocean depths with a tape measure designed for carpentry: some values are too large (overflow), others too small (underflow), and precision errors accumulate unexpectedly.

Diagnosing Common Issues

NaN Losses

When loss becomes NaN, your training stops progressing. This typically happens when:

  • Gradients overflow: Values exceed FP16's max (~65,504)
  • Division by zero or log(0) operations in your loss function
  • Exponential explosion in activations (common in attention mechanisms)

Debug strategy: Check gradient norms before optimizer steps, verify loss scaling is active, and inspect layer outputs for extreme values.

Overflow Errors

Unlike NaNs, overflows may be silent—values just clip to infinity. Monitor activation statistics and gradient magnitudes across layers.

Convergence Problems

Your model trains but performs worse than FP32. This often means:

  • Loss scaling is too aggressive or conservative
  • Accumulated precision errors in batch normalization or layer norm statistics
  • Weight updates too small to register in FP16

Debug strategy: Compare layer-wise gradient distributions between FP32 and mixed precision runs. Use gradient clipping and ensure your loss scaler adjusts dynamically.

Key Takeaway: Most mixed precision bugs trace to insufficient loss scaling (causing underflow) or numerical operations that produce extreme values; always monitor gradient norms, use dynamic scaling, and validate critical layers match FP32 behavior during debugging.