Autocast: Low Precision Range, Calculator Selection and Gradient Scale

Autocast selects the appropriate computational accuracy by sub- and context; The parameters store, optimizer state and conclusion may also use higher accuracy.

• 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

  • Distinguishing the range of float16 from bfloat16
  • Track the order of scaling and restoring the gradient

Suggested first

  • Python Basic Syntax:
  • Thick shape with Index

Combining accuracy is not a uniform half-precision of all the sheets

Autocast selects the appropriate computational accuracy by sub- and context; The parameters store, optimizer state and conclusion may also use higher accuracy. The manual integration of models and all inputs into low accuracy does not amount to the use of the same mix accuracy formula. Determining stability requires a combination of numerical ranges and effective accuracy, rather than simply comparing the bytes per element.

The maximum limited value of float16 is approximately 65504. If an intermediate value exceeds this range, conversion or operation may become inexorable; The index range for bfloat16 is closer to float32, but the end number is shorter and not all numbers are therefore more accurate. A model for pre-training at bfloat16 cannot be assumed to operate in float16 without verification.

The gradient scale multiplied the loss by a larger factor, so that certain small gradients did not spill too early in the low accuracy chain. For example, the theoretical gradient of 10-8 is very small, multiplied by 1048576, approximately 0.01048576, which is easier to retain; The scale is to be restored before the update. It cannot repair the spillovers that have already occurred in the front, nor can it make the wrong labels or illegal reclassifications right.

The gradient crop should apply a threshold to the actual scale after unscale. The same threshold corresponds to another update if first cropped by a magnified gradient. The multi-microbatch accumulation also needs to be fully updated at the boundary, and the scalable state should not be arbitrarily updated for each small batch, so that the accumulated gradient mixes different scales.

Errors can be calculated by fixing input recovery with a higher degree of accuracy, determining where the first non-limited value comes from, and judging whether it is data, arithmetical or an accuracy range. Only scaler was seen skipping a step and the check should not be deleted immediately; Skipping is a protection mechanism, and the reason for its persistence needs to be identified. Performance comparisons also maintain the same targets and valid sample numbers.

The calculation of autocast depends on the device and version, and cannot extrapolate the internal accuracy of the entire section from a loaded dtype. The explicit conversion input is also not equal to the value of having the algorithms perform according to the mix precision policy. The range above is a numerical description, not a test of hardware behaviour. The specific autocast support sub, default dtype and GradScaler configuration should be based on the target version and the device.

Does the larger index range mean that all small differences are more precise?

No, the index range is different in dimension from the end, and bfloat16 may still be a rougher indication of the adjacent values.

The forward is NaN. Can you fix a simple gradient scale?

No, scaling mainly deals with some gradients spilling; Illegal or overflow calculations should be located first.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. PyTorch — Performance Tuning Guide
  2. PyTorch — Automatic Mixed Precision recipe

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.