# DequantizeLinear#

## DequantizeLinear - 13#

Version

• domain: main

• since_version: 13

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 13.

Summary

The linear dequantization operator. It consumes a quantized tensor, a scale, and a zero point to compute the full precision tensor. The dequantization formula is y = (x - x_zero_point) * x_scale. ‘x_scale’ and ‘x_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. ‘x_zero_point’ and ‘x’ must have same type. ‘x’ and ‘y’ must have same shape. In the case of dequantizing int32, there’s no zero point (zero point is supposed to be 0).

Attributes

• axis: (Optional) The axis of the dequantizing dimension of the input tensor. Ignored for per-tensor quantization. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input). Default value is 1.

Inputs

Between 2 and 3 inputs.

• x (heterogeneous) - T: N-D quantized input tensor to be de-quantized.

• x_scale (heterogeneous) - tensor(float): Scale for input ‘x’. It can be a scalar, which means a per- tensor/layer dequantization, or a 1-D tensor for per-axis dequantization.

• x_zero_point (optional, heterogeneous) - T: Zero point for input ‘x’. Shape must match x_scale. It’s optional. Zero point is 0 when it’s not specified.

Outputs

• y (heterogeneous) - tensor(float): N-D full precision output tensor. It has same shape as input ‘x’.

Type Constraints

• T in ( tensor(int32), tensor(int8), tensor(uint8) ): Constrain ‘x_zero_point’ and ‘x’ to 8-bit/32-bit integer tensor.

Examples

default

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

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",
)

Differences

 0 0 The linear dequantization operator. It consumes a quantized tensor, a scale, a zero point to compute the full precision tensor. The linear dequantization operator. It consumes a quantized tensor, a scale, and a zero point to compute the full precision tensor. 1 1 The dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' are both scalars. The dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' must have same shape, and can be either a scalar 2 for per-tensor / per layer quantization, or a 1-D tensor for per-axis quantization. 2 3 'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32, 'x_zero_point' and 'x' must have same type. 'x' and 'y' must have same shape. In the case of dequantizing int32, 3 4 there's no zero point (zero point is supposed to be 0). there's no zero point (zero point is supposed to be 0). 4 5 6 **Attributes** 7 8 * **axis**: 9 (Optional) The axis of the dequantizing dimension of the input 10 tensor. Ignored for per-tensor quantization. Negative value means 11 counting dimensions from the back. Accepted range is [-r, r-1] where 12 r = rank(input). Default value is 1. 13 5 14 **Inputs** **Inputs** 6 15 7 16 Between 2 and 3 inputs. Between 2 and 3 inputs. 8 17 9 18 * **x** (heterogeneous) - **T**: * **x** (heterogeneous) - **T**: 10 19 N-D quantized input tensor to be de-quantized. N-D quantized input tensor to be de-quantized. 11 20 * **x_scale** (heterogeneous) - **tensor(float)**: * **x_scale** (heterogeneous) - **tensor(float)**: 12 21 Scale for input 'x'. It's a scalar, which means a per-tensor/layer Scale for input 'x'. It can be a scalar, which means a per- 13 22 quantization. tensor/layer dequantization, or a 1-D tensor for per-axis 23 dequantization. 14 24 * **x_zero_point** (optional, heterogeneous) - **T**: * **x_zero_point** (optional, heterogeneous) - **T**: 15 25 Zero point for input 'x'. It's a scalar, which means a per- Zero point for input 'x'. Shape must match x_scale. It's optional. 16 tensor/layer quantization. It's optional. 0 is the default value 17 26 when it's not specified. Zero point is 0 when it's not specified. 18 27 19 28 **Outputs** **Outputs** 20 29 21 30 * **y** (heterogeneous) - **tensor(float)**: * **y** (heterogeneous) - **tensor(float)**: 22 31 N-D full precision output tensor. It has same shape as input 'x'. N-D full precision output tensor. It has same shape as input 'x'. 23 32 24 33 **Type Constraints** **Type Constraints** 25 34 26 35 * **T** in ( * **T** in ( 27 36 tensor(int32), tensor(int32), 28 37 tensor(int8), tensor(int8), 29 38 tensor(uint8) tensor(uint8) 30 39 ): ): 31 40 Constrain 'x_zero_point' and 'x' to 8-bit/32-bit integer tensor. Constrain 'x_zero_point' and 'x' to 8-bit/32-bit integer tensor.

## DequantizeLinear - 10#

Version

• domain: main

• since_version: 10

• function: False

• support_level: SupportType.COMMON

• shape inference: True

This version of the operator has been available since version 10.

Summary

The linear dequantization operator. It consumes a quantized tensor, a scale, a zero point to compute the full precision tensor. The dequantization formula is y = (x - x_zero_point) * x_scale. ‘x_scale’ and ‘x_zero_point’ are both scalars. ‘x_zero_point’ and ‘x’ must have same type. ‘x’ and ‘y’ must have same shape. In the case of dequantizing int32, there’s no zero point (zero point is supposed to be 0).

Inputs

Between 2 and 3 inputs.

• x (heterogeneous) - T: N-D quantized input tensor to be de-quantized.

• x_scale (heterogeneous) - tensor(float): Scale for input ‘x’. It’s a scalar, which means a per-tensor/layer quantization.

• x_zero_point (optional, heterogeneous) - T: Zero point for input ‘x’. It’s a scalar, which means a per- tensor/layer quantization. It’s optional. 0 is the default value when it’s not specified.

Outputs

• y (heterogeneous) - tensor(float): N-D full precision output tensor. It has same shape as input ‘x’.

Type Constraints

• T in ( tensor(int32), tensor(int8), tensor(uint8) ): Constrain ‘x_zero_point’ and ‘x’ to 8-bit/32-bit integer tensor.