QuantizeLinear - version 13#
This page documents version 13 of operator QuantizeLinear. See QuantizeLinear for the latest version (since version 25).
Domain:
ai.onnxSince version: 13
The linear quantization operator. It consumes a high precision tensor, a scale, and a zero point to compute the low precision / quantized tensor. The scale factor and zero point must have same shape, and can be either a scalar for per-tensor / per layer quantization, or a 1-D tensor for per-axis quantization. The quantization formula is y = saturate ((x / y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if it’s uint8, or [-128, 127] if it’s int8. For (x / y_scale), it’s rounding to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details. ‘y_zero_point’ and ‘y’ must have same type.
Inputs
x (T1): N-D full precision Input tensor to be quantized.
y_scale (tensor(float)): Scale for doing quantization to get ‘y’. It can be a scalar, which means per-tensor/layer quantization, or a 1-D Tensor for per-axis quantization.
y_zero_point (T2): Zero point for doing quantization to get ‘y’. Shape must match y_scale. Default is uint8 with zero point of 0 if it’s not specified.
Outputs
y (T2): N-D quantized output tensor. It has same shape as input ‘x’.
Type Constraints
T1: Constrain ‘x’ to float or int32 tensor. Allowed types: tensor(float), tensor(int32).
T2: Constrain ‘y_zero_point’ and ‘y’ to 8-bit integer tensor. Allowed types: tensor(int8), tensor(uint8).
Examples#
test_cc_quantizelinear
Inputs:
x: shape=(6,), dtype=float32
[ 0., 2., 3., 1000., -254., -1000.]
y_scale: shape=(), dtype=float32
2.
Outputs:
y: shape=(6,), dtype=uint8
[ 0, 1, 2, 255, 0, 0]
test_cc_quantizelinear_int8
Inputs:
x: shape=(6,), dtype=float32
[ 0., 2., 3., 1000., -254., -1000.]
y_scale: shape=(), dtype=float32
2.
y_zero_point: shape=(), dtype=int8
-10
Outputs:
y: shape=(6,), dtype=int8
[ -10, -9, -8, 127, -128, -128]
Differences with previous version (10)#
SchemaDiff: QuantizeLinear (domain 'ai.onnx')
old version: 10
new version: 13
breaking: no
Documentation:
line similarity: 0.40 (+4/-2 lines)
--- QuantizeLinear v10
+++ QuantizeLinear v13
@@ -1,4 +1,6 @@
-The linear per-tensor/layer quantization operator. It consumes a high precision tensor, a scale, a zero point to compute the low precision / quantized tensor.
-The quantization formula is y = saturate ((x / y_scale) + y_zero_point). For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8.
+The linear quantization operator. It consumes a high precision tensor, a scale, and a zero point to compute the low precision / quantized tensor.
+The scale factor and zero point must have same shape, and can be either a scalar for per-tensor / per layer quantization, or a 1-D tensor for per-axis quantization.
+The quantization formula is y = saturate ((x / y_scale) + y_zero_point).
+For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8.
For (x / y_scale), it's rounding to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details. 'y_zero_point' and 'y' must have same type.