What commonly causes the loss to become NaN during training?

Quick Overview

Asks what typically makes a training loss turn into NaN and how to track down the cause. Tests your grasp of floating-point behavior in deep learning training and whether you can debug a diverging run methodically.

What commonly causes the loss to become NaN during training?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

What commonly causes the loss to become `NaN` during training? Assume a neural network trained with a gradient-based optimizer, possibly in mixed precision. Explain the causes and how you would find which one you are facing. ```hint Where the first bad number appears A non-finite value has to appear somewhere first: in the data, in one operation of the forward or backward pass, or in the size of an update. Think about what turns a finite number into inf, and what turns inf into NaN. ``` ### What a Strong Answer Covers - How a finite value turns into NaN as it moves through training. - Causes that come from the optimization setup. - Numerically unsafe operations and their stable replacements. - Reduced-precision limits and how mixed-precision training guards against them. - Data causes, and a concrete procedure for localizing the first non-finite value. ### Follow-up Questions - How does dynamic loss scaling work in mixed-precision training, and what does it do when it sees an inf gradient? - Why does bfloat16 training rarely need loss scaling while FP16 training does? - The loss stays finite for hours while the weights slowly grow, and then it turns NaN. How would you investigate? - How would you make a long training job recover automatically from an occasional NaN step?

Overview: Asks what typically makes a training loss turn into NaN and how to track down the cause. Tests your grasp of floating-point behavior in deep learning training and whether you can debug a diverging run methodically.

General logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

What commonly causes the loss to become NaN during training?

Assume a neural network trained with a gradient-based optimizer, possibly in mixed precision. Explain the causes and how you would find which one you are facing.

What a Strong Answer Covers Guidance

  • How a finite value turns into NaN as it moves through training.
  • Causes that come from the optimization setup.
  • Numerically unsafe operations and their stable replacements.
  • Reduced-precision limits and how mixed-precision training guards against them.
  • Data causes, and a concrete procedure for localizing the first non-finite value.

Follow-up Questions Guidance

  • How does dynamic loss scaling work in mixed-precision training, and what does it do when it sees an inf gradient?
  • Why does bfloat16 training rarely need loss scaling while FP16 training does?
  • The loss stays finite for hours while the weights slowly grow, and then it turns NaN. How would you investigate?
  • How would you make a long training job recover automatically from an occasional NaN step?