com.microsoft - DequantizeLinear#
DequantizeLinear - 1#
Version
domain: com.microsoft
since_version: 1
function:
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 1 of domain com.microsoft.
Summary
Attributes
axis - INT : The axis along which same quantization parameters are applied. It’s optional.If it’s not specified, it means per-tensor quantization and input ‘x_scale’ and ‘x_zero_point’ must be scalars.If it’s specified, it means per ‘axis’ quantization and input ‘x_scale’ and ‘x_zero_point’ must be 1-D tensors.
Inputs
x (heterogeneous) - T1:
x_scale (heterogeneous) - T2:
x_zero_point (heterogeneous) - T1:
Outputs
y (heterogeneous) - T2:
Type Constraints
T1 in ( tensor(int8), tensor(uint8) ): Constrain ‘x’ and ‘x_zero_point’ to 8-bit integer tensors.
T2 in ( tensor(float), tensor(float16) ): Constrain ‘y’, ‘x_scale’ to float tensors.
Examples
default
import numpy as np
import onnx
node = onnx.helper.make_node(
"DequantizeLinear",
inputs=["x", "x_scale", "x_zero_point"],
outputs=["y"],
)
# scalar zero point and scale
x = np.array([0, 3, 128, 255]).astype(np.uint8)
x_scale = np.float32(2)
x_zero_point = np.uint8(128)
y = np.array([-256, -250, 0, 254], dtype=np.float32)
expect(
node,
inputs=[x, x_scale, x_zero_point],
outputs=[y],
name="test_dequantizelinear",
)
_axis
import numpy as np
import onnx
node = onnx.helper.make_node(
"DequantizeLinear",
inputs=["x", "x_scale", "x_zero_point"],
outputs=["y"],
)
# 1-D tensor zero point and scale of size equal to axis 1 of the input tensor
x = np.array(
[
[
[[3, 89], [34, 200], [74, 59]],
[[5, 24], [24, 87], [32, 13]],
[[245, 99], [4, 142], [121, 102]],
],
],
dtype=np.uint8,
)
x_scale = np.array([2, 4, 5], dtype=np.float32)
x_zero_point = np.array([84, 24, 196], dtype=np.uint8)
y = (
x.astype(np.float32) - x_zero_point.reshape(1, 3, 1, 1).astype(np.float32)
) * x_scale.reshape(1, 3, 1, 1)
expect(
node,
inputs=[x, x_scale, x_zero_point],
outputs=[y],
name="test_dequantizelinear_axis",
)
_e4m3fn
import numpy as np
import onnx
node = onnx.helper.make_node(
"DequantizeLinear",
inputs=["x", "x_scale"],
outputs=["y"],
)
# scalar zero point and scale
x = make_tensor("x", TensorProto.FLOAT8E4M3FN, [5], [0, 0.5, 1, 448, 104])
x_scale = np.float32(2)
y = np.array([0.0, 1.0, 2.0, 896.0, 208.0], dtype=np.float32)
expect(
node,
inputs=[x, x_scale],
outputs=[y],
name="test_dequantizelinear_e4m3fn",
)
_e5m2
import numpy as np
import onnx
node = onnx.helper.make_node(
"DequantizeLinear",
inputs=["x", "x_scale"],
outputs=["y"],
)
# scalar zero point and scale
x = make_tensor("x", TensorProto.FLOAT8E5M2, [5], [0, 0.5, 1, 49152, 96])
x_scale = np.float32(2)
y = np.array([0.0, 1.0, 2.0, 98304.0, 192.0], dtype=np.float32)
expect(
node,
inputs=[x, x_scale],
outputs=[y],
name="test_dequantizelinear_e5m2",
)