AI Research Scientist · Scaling Laws & Stability
Numerical precision and mixed-precision failure modes
Numerical precision and mixed-precision failure modes
fp16 overflow
fp16 uses only 5 exponent bits, capping representable magnitude near . When a gradient or activation’s magnitude exceeds that ceiling in a forward or backward pass, the value clips to infinity or NaN instead of a large finite number.- 1Scale the loss by 1024 before backward().WhyChain rule scales every gradient by the same factor.
- 2Gradients now sit near .WhyThat falls inside fp16’s representable range.
- 3Unscale gradients by dividing by 1024 before the optimizer step.WhyRestores true magnitude for the fp32 update.
- Rangenarrow ceiling near causes overflow to inf or NaN.
- Underflowgradients below the minimum normal round silently to zero.
- Rangematches fp32’s full exponent span, so clipping rarely occurs.
- Precisiononly 7 mantissa bits, so stored values round more coarsely.
Recall check from the same lesson
If an fp16 run instead shows gradient norms silently plateauing near zero rather than NaN losses, scaling the loss upward before backward() would help because it shifts those small gradients into fp16's representable range, and then dividing the gradients back down by the same factor before the optimizer step restores their true magnitude.
Review the explanation
Answer: True. This is exactly the underflow remedy: scaling the loss multiplies every gradient by the same factor via the chain rule, lifting values that would otherwise round to zero into fp16's representable exponent band. Dividing by that same factor before the optimizer step removes the artificial inflation so the update reflects the true gradient magnitude in fp32 master weights.
Sources
One sitting · 20–30 minutes
A focused session on your AI Research Scientist interview
LearnBench starts from what you already know — skip what you have, master what you’re missing.
Start now