Difficulty: Hard Tags: Inference, Quantization, Numerical Computing
A serving team compresses activations using symmetric int8 quantization. A faulty kernel clips after dequantization instead of before rounding, which changes values near the representable limits. Implement the exact quantize-dequantize pipeline specified here.
Given scale s > 0, quantize each value by:
q_i = clip(round(x_i / s), -127, 127)
x_hat_i = s * q_i
Rounding is round-to-nearest, ties away from zero. The value -128 is
intentionally excluded (symmetric quantization uses only [-127, 127]).
values (list of floats), scale (float).
(quantized, dequantized): integers and floats (6 decimal places).
1 <= n <= 10^5, 10^-6 <= s <= 10^3, |x_i| <= 10^9.Input
values = [-100, -0.75, -0.25, 0.25, 100], scale = 0.5
Output
quantized = [-127, -2, -1, 1, 127]
dequantized = [-63.500000, -1.000000, -0.500000, 0.500000, 63.500000]
Explanation: Values are divided by 0.5, rounded with ties away from
zero, clipped to [-127, 127], then multiplied by the scale.
No results yet
Run your code to check it against the examples, or submit to run every test.