What is Mixed precision?

Using different numeric precisions for different parts of a computation, such as multiplying in FP16 and accumulating in FP32, to balance speed and accuracy.

Field: GPU Programming

Japanese name: 混合精度

The idea

Higher numeric precision reduces error but costs more memory and computation. FP16 (half precision) is 16 bits, half the size of FP32 (single precision). For the same number of values, both the memory used and the data moved are halved. In exchange it holds fewer digits, so errors appear more easily. Mixed precision computes the error-tolerant parts in low precision and the error-sensitive parts in high precision.

Why accumulation uses higher precision

The fraction field of FP16 is 10 bits, which gives 11 bits of precision counting the leading 1. Since 2 to the 11th power is 2048, values from 2048 to 4096 can be represented only in steps of 2. Adding 1 to 2048 gives 2049, which cannot be represented, and under the standard rounding rule the result stays 2048. When many products are summed, as in a matrix product, small values stop being added to a total that has grown large, and error builds up. The multiplications are therefore done in low precision and only the running total is kept in FP32. NVIDIA tensor cores have instructions that multiply FP16 matrices and accumulate into FP32.

Use in deep learning training

In neural network training, a known method keeps a master copy of the weights in FP32 and uses FP16 for the forward and backward computations. This keeps in high precision the step where small updates are added into the weights. In FP16, very small gradients can become 0. To prevent this, the loss is multiplied by a scale factor before the backward computation, and the gradients are divided by the same factor before the weights are updated. Frameworks such as PyTorch provide features that do this automatically.

Try it: questions about Mixed precision

In mixed-precision AI training, why are master weights kept in FP32 while most computation is done in FP16 or bfloat16?

  1. AWhen small updates are added to weights, a low-precision format would lose them to absorption
  2. BFP32 computes faster than FP16, so all weight calculations are left to FP32
  3. CFP16 and bfloat16 values are not allowed to be stored in memory
Show answer and explanation

Answer: A. When small updates are added to weights, a low-precision format would lose them to absorption

Training repeatedly adds very small amounts, learning rate × gradient, to the weights. FP16 and bfloat16 have short significands, so if an update is too small relative to the weight, the rounded sum equals the old weight and the update vanishes (absorption). Weights are therefore kept in FP32 so updates accumulate correctly, while lower-precision copies are used for the forward and backward passes. On hardware that supports it, lower precision computes faster, and low-precision values can be stored in memory.

In GPU mixed-precision computation, why are multiplications often done in a low precision such as FP16 while accumulation is done in FP32?

  1. AMultiplication cannot be done in FP32
  2. BSumming many products in low precision accumulates rounding error and loses small values, so accumulation alone uses higher precision
  3. CAddition cannot be done in FP16
Show answer and explanation

Answer: B. Summing many products in low precision accumulates rounding error and loses small values, so accumulation alone uses higher precision

FP16 has only a 10-bit significand, so adding a small product to a large running sum can round the product away. A matrix product sums thousands of products, so such errors accumulate and skew the result. So the input values being multiplied are kept in low precision to cut memory use and arithmetic cost, while the sum of the products (the accumulation) is done in FP32. Most tensor cores perform this kind of multiply-accumulate in a single instruction.

FAQ

Does lowering precision make the results worse?

Mixed precision is the technique for keeping that effect small. Computations where error accumulates, such as summation and weight updates, are done in FP32. This is what distinguishes it from running everything in low precision.

What changes if BF16 is used instead of FP16?

The range of representable values widens. BF16 has the same 8-bit exponent as FP32, so small gradients are less likely to become 0 and loss scaling is usually unnecessary. In exchange, its fraction field is 7 bits, coarser than the 10 bits of FP16.

Books on GPU Programming Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary