QuantizeLinear - 13 vs 23

Next section compares an older to a newer version of the same operator after both definition are converted into markdown text. Green means an addition to the newer version, red means a deletion. Anything else is unchanged.

Files changed (1) hide show
  1. QuantizeLinear13 → QuantizeLinear23 +56 -16
QuantizeLinear13 → QuantizeLinear23 RENAMED
@@ -1 +1 @@
1
- The linear quantization operator. It consumes a high precision tensor, a scale, and a zero point to compute the low precision / quantized tensor.
1
+ The linear quantization operator consumes a high-precision tensor, a scale, and a zero point to compute the
2
- 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.
2
+ low-precision/quantized tensor. The scale factor and zero point must have the same shape, determining the quantization
3
- The quantization formula is y = saturate ((x / y_scale) + y_zero_point).
3
+ granularity. The quantization formula is y = saturate((x / y_scale) + y_zero_point).
4
+
4
- For saturation, it saturates to [0, 255] if it's uint8, or [-128, 127] if it's int8.
5
+ Saturation is done according to:
6
+ - uint16: [0, 65535]
7
+ - int16: [-32768, 32767]
8
+ - uint8: [0, 255]
9
+ - int8: [-128, 127]
10
+ - uint4: [0, 15]
11
+ - int4: [-8, 7]
12
+
5
- 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.
13
+ For (x / y_scale), it rounds to the nearest even. Refer to https://en.wikipedia.org/wiki/Rounding for details.
14
+
15
+ y_zero_point and y must have the same type. y_zero_point is usually not used for quantization to float8 and 4bit types, but the quantization
16
+ formula remains the same for consistency, and the type of the attribute y_zero_point still determines the quantization type.
17
+ x and y_scale are allowed to have different types. The type of y_scale determines the precision of the division operation between x and
18
+ y_scale, unless the precision attribute is specified.
19
+
20
+ There are three supported quantization granularities, determined by the shape of y_scale.
21
+ In all cases, y_zero_point must have the same shape as y_scale.
22
+ - Per-tensor (per-layer) quantization: y_scale is a scalar.
23
+ - Per-axis quantization: The scale must be a 1-D tensor, with the length of the quantization axis. For an input shape
24
+ (D0, ..., Di, ..., Dn) and axis=i, y_scale is a 1-D tensor of length Di.
25
+ - Blocked quantization: The scale's shape is identical to the input's shape, except for one dimension, in which
26
+ blocking is performed. Given x shape (D0, ..., Di, ..., Dn), axis=i, and block size B: y_scale shape is
27
+ (D0, ..., ceil(Di/B), ..., Dn).
6
28
  ### Attributes
7
29
  * **axis - INT** (default is '1'):
8
- (Optional) The axis of the quantization 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).
30
+ (Optional) The axis of the dequantizing dimension of the input tensor. Used only for per-axis and blocked quantization. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input). When the rank of the input is 1, per-tensor quantization is applied, rendering the axis unnecessary in this scenario.
31
+
32
+ * **block_size - INT** (default is '0'):
33
+
34
+ (Optional) The size of the quantization block (number of times every scale is replicated). Used only for blocked quantization. The block size is a positive integer. Given x shape (D0, ..., Di, ..., Dn), y_scale shape (S0, ... Si, ...Sn) and axis=i, the accepted range is [ceil(Di/Si), ceil(Di/(Si-1))-1]
35
+
36
+ * **output_dtype - INT** (default is '0'):
37
+
38
+ (Optional) The output data type. If not supplied, the output data type is inferred from y_zero_point data type (T3). If neither output_dtype nor y_zero_point are supplied, output data type is uint8. If both output_dtype and y_zero_point are specified, output_dtype must be T3.
39
+
40
+ * **precision - INT** (default is '0'):
41
+
42
+ (Optional) The precision of the division operation between x and y_scale. If not provided, it will be the same as the type of y_scale.
43
+
44
+ * **saturate - INT** (default is '1'):
45
+
46
+ The parameter defines how the conversion behaves if an input value is out of range of the destination type. It only applies for float 8 quantization (float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz). It is true by default. All cases are fully described in two tables inserted in the operator description.
9
47
  ### Inputs
10
48
  Between 2 and 3 inputs.
11
49
  - **x** (heterogeneous) - **T1**:
12
50
  N-D full precision Input tensor to be quantized.
13
- - **y_scale** (heterogeneous) - **tensor(float)**:
51
+ - **y_scale** (heterogeneous) - **T2**:
14
- 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.
52
+ Scale for doing quantization to get y. For per-tensor/layer quantization the scale is a scalar, for per-axis quantization it is a 1-D Tensor and for blocked quantization it has the same shape as the input, except for one dimension in which blocking is performed.
15
- - **y_zero_point** (optional, heterogeneous) - **T2**:
53
+ - **y_zero_point** (optional, heterogeneous) - **T3**:
16
- 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.
54
+ 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.
17
55
  ### Outputs
18
- - **y** (heterogeneous) - **T2**:
56
+ - **y** (heterogeneous) - **T3**:
19
- N-D quantized output tensor. It has same shape as input 'x'.
57
+ N-D quantized output tensor. It has same shape as input x.
20
58
  ### Type Constraints
21
- * **T1** in ( tensor(float), tensor(int32) ):
59
+ * **T1** in ( tensor(bfloat16), tensor(float), tensor(float16), tensor(int32) ):
22
- Constrain 'x' to float or int32 tensor.
60
+ The type of the input 'x'.
23
- * **T2** in ( tensor(int8), tensor(uint8) ):
61
+ * **T2** in ( tensor(bfloat16), tensor(float), tensor(float16), tensor(int32) ):
24
- Constrain 'y_zero_point' and 'y' to 8-bit integer tensor.+ The type of the input 'y_scale'.
62
+ * **T3** in ( tensor(float4e2m1), tensor(float8e4m3fn), tensor(float8e4m3fnuz), tensor(float8e5m2), tensor(float8e5m2fnuz), tensor(int16), tensor(int4), tensor(int8), tensor(uint16), tensor(uint4), tensor(uint8) ):
63
+
64
+ The type of the input y_zero_point and the output y.