Weight Quantization Basics › Worked Example: Computing Scale and Zero-Point
Language AI HandbookAll chapters Weight Quantization Basics › Worked Example: Computing Scale and Zero-PointOne section · Sections in this chapter6 / 12 ↓
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
Let us work through a concrete numerical example to make the formulas tangible. We will quantize a small tensor using both symmetric and asymmetric approaches, computing every intermediate value by hand.
Suppose we have the following weight tensor (7 values for clarity):
We want to represent this using 4-bit signed integers, which range from to (giving , ). This tiny tensor will show the mechanics clearly.
Step 1: Find the range.
Step 2a: Compute the symmetric scale.
The symmetric approach uses the maximum absolute value:
Step 2b: Compute the asymmetric scale and zero-point.
Step 3: Quantize each value.
For symmetric ():
| Error | ||||
|---|---|---|---|---|
| -0.8 | -6.22 | -6 | -0.771 | 0.029 |
| -0.4 | -3.11 | -3 | -0.386 | 0.014 |
| -0.1 | -0.78 | -1 | -0.129 | 0.029 |
| 0.0 | 0.00 | 0 | 0.000 | 0.000 |
| 0.2 | 1.56 | 2 | 0.257 | 0.057 |
| 0.5 | 3.89 | 4 | 0.514 | 0.014 |
| 0.9 | 7.00 | 7 | 0.900 | 0.000 |
The maximum error occurs at 0.2, which maps to integer 2 but dequantizes to 0.257, an error of 0.057. This error arises because the symmetric scale is set by the extreme value of 0.9, which coarsens the step size throughout the tensor.
For asymmetric (, ):
| Error | ||||
|---|---|---|---|---|
| -0.8 | -7.06 + (-1) = -8.06 | -8 | -0.793 | 0.007 |
| -0.4 | -3.53 + (-1) = -4.53 | -5 | -0.453 | 0.053 |
| -0.1 | -0.88 + (-1) = -1.88 | -2 | -0.113 | 0.013 |
| 0.0 | 0.00 + (-1) = -1.00 | -1 | 0.000 | 0.000 |
| 0.2 | 1.77 + (-1) = 0.77 | 1 | 0.227 | 0.027 |
| 0.5 | 4.41 + (-1) = 3.41 | 3 | 0.453 | 0.047 |
| 0.9 | 7.94 + (-1) = 6.94 | 7 | 0.793 | 0.107 |
The dequantization here uses .
The key insight from this comparison is not that one scheme is uniformly better. The symmetric scheme perfectly represents 0.9 (the anchor of its scale) with zero error, while asymmetric cannot. The asymmetric scheme better represents -0.8 (small error) but assigns its maximum error to 0.9. The average error depends on the full distribution, and asymmetric generally wins when the distribution is not centered at zero. For this tensor, which has a slightly positive skew, asymmetric quantization gives smaller average error for most values.
Step 4: Verify dequantization.
For symmetric, dequantization is . For asymmetric, dequantization is .
At (asymmetric): . Compare to the original : error of 0.007. The asymmetric mapping distributes its integer range more efficiently across the actual value range, which is why its error for typical values is smaller.