What does this symmetric INT8 quantization snippet print, and which statement about using an asymmetric (zero-point) scheme for ReLU outputs is correct?
import numpy as np
x = np.array([-0.62, 0.013, 0.733, 2.54], dtype=np.float32)
scale = np.abs(x).max() / 127 # symmetric INT8
q = np.clip(np.round(x / scale), -127, 127).astype(np.int8)
x_hat = q.astype(np.float32) * scale # dequantize
print(q.tolist())
print(round(float(x_hat[2]), 3))Show the answer and explanation
Correct answer: A, [-31, 1, 37, 127] and 0.74. ReLU outputs are never negative, so a zero-point lets all 256 codes cover [0, max] and gives a step about half as large as the symmetric one.
Explanation Quantization
Symmetric quantization maps [−max|x|, +max|x|] onto the integers −127…127 with zero at code 0: scale = max|x| / 127, q = round(x / scale), x̂ = q × scale.
Here scale = 2.54 / 127 = 0.02:
| x | x / scale | q | x̂ | error |
|---|---|---|---|---|
| −0.62 | −31.0 | −31 | −0.62 | 0 |
| 0.013 | 0.65 | 1 | 0.02 | 0.007 (54% relative) |
| 0.733 | 36.65 | 37 | 0.74 | 0.007 |
| 2.54 | 127.0 | 127 | 2.54 | 0 |
np.round runs before the cast, so 36.65 becomes 37, not 36. The maximum rounding error is scale / 2 = 0.01, and small values lose the most relative precision.
Asymmetric quantization adds a zero-point z: q = round(x / scale) + z, with scale = (max − min) / 255 for UINT8. It pays off when the range is lopsided. ReLU outputs in [0, 6]:
- symmetric: scale = 6 / 127 ≈ 0.047, and the 127 negative codes are never used
- asymmetric: scale = 6 / 255 ≈ 0.024, about half the step, so half the rounding error
Why the distractors fail: symmetric schemes represent zero exactly (code 0); ReLU outputs have no negative values to protect; and a zero-point aligns the grid with the min–max range, not with the mean.
Interview tip: the common recipe is symmetric per-channel for weights (centred near zero) and asymmetric or calibrated per-tensor for activations, whose ranges are often one-sided.