NaNs and Infinities

NaN means "not a number." Infinity means a value exceeded representable finite range.

In training, they are alarms.

Common causes include:

  • division by zero
  • log of zero
  • overflow in exponentials
  • too-large learning rate
  • unstable normalization
  • invalid data values

Once NaN appears, it can spread through tensors quickly. A single non-finite value can contaminate loss, gradients, and parameters.

A practical debugging checklist:

check input values
check loss value
check logits before softmax
check gradient norms
check parameter values
check learning rate
DL-C16-T07-001Exercise: NaN warning

Enter 1 for serious numerical warning, or 2 for harmless normal value: loss becomes NaN.

Compute it first, then check your number.

DL-C16-T07-002Exercise: Log zero

Enter 1 if log(0) is unsafe in ordinary real-valued computation, or 2 if it is always a finite number.

Compute it first, then check your number.