INT8 Quantization › Worked Example: Quantizing a Small Weight Tensor
Language AI HandbookAll chapters INT8 Quantization › Worked Example: Quantizing a Small Weight TensorOne section · Sections in this chapter6 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To build concrete intuition, let's trace through a complete quantization example with specific numbers. This will make the abstractions tangible and reveal where errors accumulate.
Suppose we have a small weight tensor (one row of a larger matrix):
Step 1: Compute the absmax. We scan the entire vector and find:
Step 2: Compute the scale factor. Dividing by 127 to cover the full INT8 range:
Step 3: Quantize each element. Divide by and round to the nearest integer:
The quantized tensor is: .
Step 4: Reconstruct and compute error. Multiply each integer by :
The maximum error is 0.0037, and the mean absolute error is about 0.0015. Notice that the largest element (1.12) reconstructs perfectly since it was the absmax and maps exactly to 127. The element with value 0.05 (the smallest magnitude) experiences the largest relative error: the rounding from 5.67 to 6 introduces a 5.9% relative error. This pattern is typical: absmax quantization gives best relative precision to large-magnitude values and worst to small ones.
The maximum possible error for any element is , which all our actual errors satisfy. Storing the entire vector requires just 8 bytes (8 integers) plus 4 bytes for the float32 scale factor, totaling 12 bytes instead of the original 32 bytes (8 float32 values). That is 2.67x compression with bounded error.