I knew the symmetric case cold, but adding the zero point tripped me up at first.
Explain the affine quantization formula and how to compute scale and zero point from the min/max of the FP32 tensor. Then demonstrate the full conversion process: quantize FP32 to Int8 using the formula, and dequantize back to FP32 to verify. Emphasize the role of zero point in preserving the representation of zero and handling asymmetric ranges.
Pro tip: Mention that zero point must be an integer within the Int8 range and that clamping is necessary to avoid overflow. Also, note that for symmetric quantization, zero point is 0, but asymmetric (with zero point) is better for tensors with skewed distributions.
Given an FP32 tensor, compute its min and max values. Determine the scale and zero point using the formulas: scale = (max - min) / (q_max - q_min), zero_point = round(q_min - min / scale), where q_min and q_max are the quantized range limits (e.g., -128 and 127 for int8).
Ensure the computed zero point falls within the valid quantized range by clamping it to [q_min, q_max]. This prevents overflow and maintains representability.
For each element x in the FP32 tensor, compute the quantized value: q = clamp(round(x / scale) + zero_point, q_min, q_max). This maps the FP32 values to the Int8 range.
To recover an approximation of the original FP32 value, compute: x_approx = (q - zero_point) * scale. This step is used to verify the quantization error.
Explain that zero point allows asymmetric quantization, which better preserves the distribution of values, especially when the FP32 range is not symmetric around zero. Mention that this is crucial for activations in neural networks.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by deriving the affine quantization formula that maps the real range [min, max] to the full int8 range [-128, 127]. Then compute scale as (max - min) / 255 and zero point as round(-128 - min / scale), clamping to [-128, 127]. Finally, present the quantize and dequantize functions and explain that the mapping is correct because it preserves the affine relationship and uses the entire int8 range even when the distribution is asymmetric.
Pro tip: Mention that zero point must be an integer and that clamping is necessary to handle edge cases, and note that this approach is standard in frameworks like TensorFlow Lite and PyTorch.
State that quantization maps real values to integers via q = round(r / scale) + zero_point, and dequantization via r = (q - zero_point) * scale.
Given min and max, set scale = (max - min) / (q_max - q_min) where q_min = -128 and q_max = 127. Then zero_point = round(q_min - min / scale), clamped to [q_min, q_max].
Provide the functions: quantize(r) = clamp(round(r / scale) + zero_point, -128, 127) and dequantize(q) = (q - zero_point) * scale.
Show that the mapping is affine and bijective on the range, and that it uses the full int8 range because min maps to -128 and max maps to 127 (up to rounding).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.