Description: Performs per-token symmetric/asymmetric dynamic quantization on the input tensor. In the MOE scenario, smoothScalesOptional for each expert is different and is distinguished by the input groupIndexOptional.
Formula:
Symmetric quantization:
When smoothScalesOptional is not provided:
When smoothScalesOptional is provided:
Asymmetric quantization:
When smoothScalesOptional is not provided:
When smoothScalesOptional is provided:
Where row_max denotes computing the maximum value for each row, and row_min denotes computing the minimum value for each row. When the output yOut is of the INT8 type, scale_opt is 255.0 and offset_opt is 127.0. When the output yOut is of the INT4 or INT32 type, scale_opt is 15.0 and offset_opt is 7.0.
Each operator has calls. First, aclnnDynamicQuantV2GetWorkspaceSize is called to obtain the workspace size required for computation and the executor that contains the operator computation flow. Then, aclnnDynamicQuantV2 is called to perform computation.
Parameters
[object Object][object Object]Atlas A2 training products/Atlas A2 inference products[object Object] and [object Object]Atlas A3 training products/Atlas A3 inference products[object Object]:
The data type of the output parameter
[object Object]can only be INT4, INT8, or INT32.[object Object]Atlas inference products[object Object] and [object Object]Atlas training products[object Object]:
- Only FLOAT16 is supported for the input parameter
[object Object]. - The input parameters
[object Object]and[object Object]are reserved and are not involved in the calculation in the current version. - The input parameter
[object Object]must be set to 2. - Only INT8 is supported for the output parameter
[object Object].
- Only FLOAT16 is supported for the input parameter
Returns
[object Object]: status code. For details, see .The first-phase API implements input parameter verification. The following errors may be thrown.
[object Object]
- [object Object]Atlas A2 training products/Atlas A2 inference products[object Object], [object Object]Atlas A3 training products/Atlas A3 inference products[object Object], and Ascend 950 PR/Ascend 950 DT:
- When the data type of yOut is INT4, the last dimensions of x and yOut must be divisible by 2.
- When the data type of yOut is INT32, the last dimension of x must be divisible by 8.
- [object Object]Atlas inference products[object Object] and [object Object]Atlas training products[object Object]: The last dimension of the input x must be exactly divisible by 32. Currently, only symmetric quantization is supported, and the BFLOAT16 data type is not supported.
- Deterministic computation:
- aclnnDynamicQuantV2 defaults to a deterministic implementation.
The following example is for reference only. For details, see .