INT8 Quantization Simulator
Simulate INT8 quantization and dequantization of model weights.
INT8 quantization maps float32 values to [-128, 127]:
- Find scale: scale = max(|weights|) / 127
- Quantize: q = round(weights / scale), clamped to [-128, 127]
- Dequantize: weights_approx = q * scale
Compute the quantization error (MSE between original and dequantized).
Input: Space-separated float weights
Output:
- Line 1: Dequantized weights, rounded to 4 decimal places
- Line 2: Scale factor, rounded to 6 decimal places
- Line 3: MSE error, rounded to 6 decimal places
Example
1.0 -0.5 0.3 -0.8
0.9921 -0.4961 0.2953 -0.7953 0.007874 0.000013
- First, we find the scale factor:
- Then, we quantize the weights: , which results in , , ,
- Next, we dequantize the weights: , resulting in (after rounding), (after rounding), (after rounding), (after rounding)
- Finally, we calculate the MSE error between the original and dequantized weights: , which equals after calculation and rounding
Constraints
- Clamp quantized values to [-128, 127]
- Use round() for rounding to nearest integer
- Round outputs as specified