NaN with Inf: first error found

When the loss occurred in NaN, the activation, division or index in the front might have been false.

• Step by stepCollate in 2 self-measured2 First-hand sources
Start Body
Learning objectives and first steps2 objectives 2 first fixes

Try to do it after reading

  • Error distinguishing overflow from defined domain
  • Check the earliest anomalies with a layer-by-layer limited value

Suggested first

  • Target function to oversee learning
  • Basic training and validation cycle

The last NaN is not usually the reason

When the loss occurred in NaN, the activation, division or index in the front might have been false. NaN is transmitted along the calculation and the final position indicates only that it is observed and cannot directly locate the source. The limited value should be checked from the input point of entry, the forward direction should be identified on a layer basis, loss and reverse should be confirmed and the first abnormal mass should be found.

The two common situations are different: log(0) produces negative results, while 0/0 is not defined, resulting in NaN; The big index exp(1000) will spill over within the usual floating point range. They need different repairs. A very small constant added to the harmonization of all results may not only be ineffective, but may also alter the target or mask data errors.

softmax may spill if exp(1000) and exp(999) are directly calculated; Minus calculation of exp(0) and exp(−1) with a probability of approximately [0.731059,0.268941]. Equalization does not change the probability because the common index factor is offset by the molecular denominator. Value stability is derived from an equivalent deformation, not a reduction in mathematical accuracy.

Reduce complexity before it's back to complexity when it's wrong

Sets a failed batch and model status, closes random enhancements, checks input ranges and missing codes, and then uses higher accuracy or closes mixing accuracy. In the event of an anomaly occurring only in reverse, check for zero, extreme gradients and custom subconductors; A limited front line does not guarantee a limited number of partial guides.

The unusual records should maintain a stable sample number, a volume of shape, dtype, a minimum maximum value and a first error step. Direct printing of complete sensitive samples is unnecessary and may also reveal data; Aggregation diagnosis and synthesis are usually more suitable for sharing. Do not skip failed batches to claim that training quality has been validated.

Gradient tailoring can only handle a limited size of a gradient and cannot turn undefined operations into the correct number of guides. The loss shrunk to mitigate some of the low accuracy gradient problems, and also to solve the problem of the definitional field errors such as negative number opening squares. The choice of repair is made by distinguishing between data problems, mathematical problems and floating point ranges.

This section uses the general floating point numerical principle and the diagnostic boundary of PyTorch2. Probability is reviewed by standard index algorithms. The restoration will require re-validation of the original failed batch and adjacent boundary samples.

Why would softmax lose the maximum value when the exp is overflowed?

(a) All molecular denominators are multiplied by one positive factor and the probability is constant; The index parameters have changed to positive and facilitate the control of the range.

Can you prove training repairs by replacing NaN with zero?

Can't. It hides only observations and must locate the cause of the first loss and verify that the target and gradient still meet the definition.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — Automatic Mixed Precision recipe
  2. PyTorch — Numerical accuracy

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.