A finite number line #

A floating-point number allocates bits to a sign, an exponent and a significand. The exponent permits magnitudes spanning many orders, while the significand controls the spacing of representable numbers near each magnitude. Fixed-point or integer quantization can use a scale and an offset to associate integer codes with approximate real values. A smaller representation can double the number of weights that fit in the same memory even if a particular operation still uses a wider accumulator.

Consider an illustrative signed code with a scale of 0.1 and zero offset. A weight of 0.34 rounds to the code 3 and decodes to 0.3. Choosing a finer scale reduces this rounding error near zero while shrinking the range covered by a fixed set of codes. Values outside the range must be clipped or handled separately. The useful scale depends on the values the layer actually encounters.

Section sources [1] [2]

Why training often uses mixed precision #

Training repeatedly adds small updates to larger weights. If the stored spacing near a weight exceeds the proposed update, rounding can leave the stored weight unchanged. Very small gradients can also underflow before they influence the update. Micikevicius and colleagues studied a combination of half-precision computation, accumulation in higher precision, a higher-precision copy of weights, and scaling the loss where needed.

Multiplying a loss by a scale multiplies its gradients. Dividing the resulting gradients by that factor before the update restores their intended scale, subject to rounding. Too much scaling can cause overflow. Following the training loss and checking for finite gradients gives more information than the nominal number of bits printed on a chip specification.

Section sources [1]

Quantization for inference #

An inference system no longer needs an optimizer’s state, but each layer must produce activations suitable for the next. Jacob and colleagues developed a scheme for integer-only inference that accounts for activation ranges and quantization during training. For large language models, Dettmers and colleagues identified outlying features that made straightforward eight-bit matrix multiplication less accurate. Their method treated these features at higher precision while computing most contributions in eight bits.

Section sources [2] [3]

Interpreting a compression result #

A fourfold reduction in stored weight bytes does not guarantee fourfold lower latency. Loading scales, unpacking codes, processing activations and writing output all take time. Compare the same prompts at the same batch size, and include both accuracy and latency distributions. An average score can conceal a failure concentrated in a narrow kind of input. Whether lower precision expands practical access to an AI system depends on what limited the original deployment.

Section sources [2] [3]

Moving a difficult numerical range #

Imagine one input channel with an activation of 120 and a corresponding weight of 0.025. Their contribution to a dot product is 3. Dividing every activation in that channel by 10 and multiplying its corresponding weights by 10 preserves that contribution in exact arithmetic. The two numbers in the example become 12 and 0.25. After quantization the rounding errors can differ substantially because the range each part must cover has changed.

Guangxuan Xiao and colleagues used this identity in SmoothQuant. They estimated activation ranges from calibration examples and chose channel scales that shared the numerical burden between activations and weights. This let them use eight-bit representations for both in the matrix multiplications they studied. A practical check is to try inputs outside the calibration sample. An infrequent large activation can still force clipping or expose an accuracy loss that an average over familiar prompts would conceal.

Section sources [4]

Sources

  1. Paulius Micikevicius and colleagues · Mixed Precision Training (2017 preprint) arxiv.org
  2. Benoit Jacob and colleagues · Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference (2018) arxiv.org
  3. Tim Dettmers and colleagues · LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale (2022) arxiv.org
  4. Guangxuan Xiao and colleagues · SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models (2023) proceedings.mlr.press