Mixed-precision arithmetic
Mixed-precision arithmetic is an encyclopedia record, sourced from en.wikipedia.org, last updated 2024-10-18, source revision https://en.wikipedia.org/w/index.php?oldid=1251898104. Mixed-precision arithmetic is a form of floating-point arithmetic that uses numbers with varying widths in a single operation. Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
Mixed-precision arithmetic is a form of floating-point arithmetic that uses numbers with varying widths in a single operation. ==Overview== A common usage of mixed-precision arithmetic is for operating on inaccurate numbers with a small width and expanding them to a larger, more accurate representation. For example, two half-precision or bfloat16 (16-bit) floating-point numbers may be multiplied together to result in a more accurate single-precision (32-bit) float. In this way, mixed-precision arithmetic approximates arbitrary-precision arithmetic, albeit with a low number of possible precisions. Iterative algorithms (like gradient descent) are good candidates for mixed-precision arithmetic. In an iterative algorithm like square root, a coarse integral guess can be made and refined over many iterations until the error in precision makes it such that the smallest addition or subtraction to the guess is still too coarse to be an acceptable answer. When this happens, the precision can be increased to something more precise, which allows for smaller increments to be used for the approximation. Supercomputers such as Summit utilize mixed-precision arithmetic to be more efficient with regards to memory and processing time, as well as power consumption. Loss scaling means multiplying the loss function by a constant factor during training, typically before backpropagation. This is done to prevent the gradients from underflowing to zero when using low-precision data types. If the unscaled loss is \mathcal{L} , the scaled loss is k\mathcal{L} where k is the scaling factor. Since gradient scaling and loss scaling are mathematically equivalent by \frac{\partial(k\mathcal{L})}{\partial\mathbf{w}} = k\frac{\partial\mathcal{L}}{\partial\mathbf{w}} , loss scaling is an implementation of gradient scaling. PyTorch AMP uses exponential backoff to automatically adjust the scale factor for loss scaling. That is, it periodically increase the scale factor. Whenever the gradients contain a NaN (indicating overflow), the weight update is skipped, and the scale factor is decreased. ==References==
Cite this
"Mixed-precision arithmetic". 1729267926. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1251898104 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy