Description: Fuses
[object Object],[object Object],[object Object], and[object Object]. For details, see the formulas.Compared with the API, this API has the following new features:
- Ascend 950PR/Ascend 950DT:
- The MXFP8, MXFP4, and Pertoken quantization scenarios are added.
- The field types of the weight, weightScale, and weightAssistMatrix parameters are changed to tensorlist. Select a proper API based on the actual situation.
- Ascend 950PR/Ascend 950DT:
Formula:
[object Object]Atlas A3 training products/Atlas A3 inference products[object Object] and [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
[object Object]Definition
- ⋅ indicates matrix multiplication.
- ⊙ indicates element-wise multiplication.
- indicates rounding
[object Object]to the nearest integer.
Input
- : activation matrix (left matrix), where
[object Object]indicates the total number of tokens and[object Object]indicates the feature dimension. - : grouped weight matrix (right matrix), where
[object Object]indicates the number of experts,[object Object]indicates the feature dimension, and[object Object]indicates the output dimension. - : per-channel scale factor for the grouped weight matrix (right matrix), where
[object Object]indicates the number of experts and[object Object]indicates the output dimension. - : per-token scale factor for the activation matrix (left matrix), where
[object Object]indicates the total number of tokens. - : grouped index list of cumsum or count.
- : activation matrix (left matrix), where
Output
- : quantized output matrix.
- : quantization scale factor.
Computation process
- Determine the tokens of the current group based on
[object Object], where .
[object Object]
- Determine the tokens of the current group based on
- Perform the following computation based on the input parameters determined by grouping:
where
- Quantize the output.
- Definition
- ⋅ indicates matrix multiplication.
- ⊙ indicates element-wise multiplication.
- indicates rounding
[object Object]to the nearest integer.
- Input
- : activation matrix (left matrix), where
[object Object]indicates the total number of tokens and[object Object]indicates the feature dimension. - : grouped weight matrix (right matrix), where
[object Object]indicates the number of experts,[object Object]indicates the feature dimension, and[object Object]indicates the output dimension. - : auxiliary matrix used for matrix multiplication. For details about how to generate the auxiliary matrix, see the following description.
- : per-channel scale factor for the grouped weight matrix (right matrix), where
[object Object]indicates the number of experts,[object Object]indicates the number of groups along the K-axis, and[object Object]indicates the output dimension. - : per-token scale factor for the activation matrix (left matrix), where
[object Object]indicates the total number of tokens. - : grouped index list of cumsum or count.
- : activation matrix (left matrix), where
- Output
- : quantized output matrix.
- : quantization scale factor.
- Computation process
- Determine the tokens of the current group based on
[object Object], where .
- The grouping logic is the same as that of A8W8.
- Determine the tokens of the current group based on
- The computation process of generating the auxiliary matrix (weightAssistMatrix) is as follows. (Note that the computation of weightAssistMatrix is generated offline and used as the input, instead of being completed inside the operator.)
For per-channel quantization ( is 2D):
For per-group quantization ( is 3D):
Note:
- Perform the following computation based on the input parameters determined by grouping:
3.1. Convert the left matrix into two components that represent the high and low bits.
3.2. Enable per-channel or per-group quantization during matrix multiplication. Per-channel:
Per-group:
3.3. Restore the matrix multiplication results of the high and low bits into the overall result.
where
- Quantize the output.
Definition
- ⋅ indicates matrix multiplication.
- ⊙ indicates element-wise multiplication.
- indicates rounding
[object Object]to the nearest integer.
Input
- : activation matrix (left matrix), where indicates the total number of tokens and indicates the feature dimension.
- : grouped weight matrix (right matrix), where
[object Object]indicates the number of experts,[object Object]indicates the feature dimension, and[object Object]indicates the output dimension. - : per-channel scale factor for the grouped weight matrix (right matrix), where
[object Object]indicates the number of experts and[object Object]indicates the output dimension. - : per-token scale factor for the activation matrix (left matrix), where
[object Object]indicates the total number of tokens. - : smooth scaling factor, where E is the number of experts, and N is the output dimension.
- : grouped index list of cumsum or count.
Output
- : quantized output matrix.
- : quantization scale factor.
Computation process
- Determine the tokens of the current group based on
[object Object], where .
- The grouping logic is the same as that of A8W8.
- Determine the tokens of the current group based on
- Perform the following computation based on the input parameters determined by grouping:
where
- Quantize the output.
Ascend 950PR/Ascend 950DT:
[object Object]Definition
- ⋅ indicates matrix multiplication.
- ⊙ indicates element-wise multiplication.
Input
- : activation matrix (left matrix), where
[object Object]indicates the total number of tokens and[object Object]indicates the feature dimension. - : grouped weight matrix (right matrix), where
[object Object]indicates the number of experts,[object Object]indicates the feature dimension, and[object Object]indicates the output dimension. - : channel-wise scaling factor of the group weight matrix (right matrix), where E is the number of experts, K is the feature dimension, and N is the output dimension.
- : token-wise scaling factor of the activation matrix (left matrix), where M is the total number of tokens and K is the feature dimension.
- : grouped index list of cumsum or count.
- : activation matrix (left matrix), where
Output
- : quantized output matrix.
- : quantization scaling factor.
Computation process
- Determine the tokens of the current group based on
[object Object], where .
- Determine the tokens of the current group based on
- Perform the following computation based on the input parameters determined by grouping:
, where
- Quantize the output.
: exponent bit of the maximum positive regular number corresponding to the data type.
[object Object]undefined
: number of elements to be quantized each time. Only 32 is supported.
Definition
- ⋅ indicates matrix multiplication.
- ⊙ indicates element-wise multiplication.
Input
- : activation matrix (left matrix), where
[object Object]indicates the total number of tokens and[object Object]indicates the feature dimension. - : grouped weight matrix (right matrix), where
[object Object]indicates the number of experts,[object Object]indicates the feature dimension, and[object Object]indicates the output dimension. - : per-channel scaling factor of the group weight matrix (right matrix), where E is the number of experts, K is the feature dimension, and N is the output dimension.
- : per-token scaling factor of the activation matrix (left matrix), where M is the total number of tokens and K is the feature dimension.
- : grouped index list of cumsum or count.
- : activation matrix (left matrix), where
Output
- : quantized output matrix.
- : quantization scale factor.
Computation process
- Determine the tokens of the current group based on
[object Object], where .
- Determine the tokens of the current group based on
Perform the following computation based on the input parameters determined by grouping:
, where
indicates the quantization factor corresponding to the token.
Quantize the output.
Each operator has calls. First, [object Object] is called to obtain the workspace size required for computation and the executor that contains the operator computation process. Then, [object Object] is called to perform computation.
Parameters
[object Object]- [object Object]Atlas A3 training products/Atlas A3 inference products[object Object] and [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
- In the A4W4 scenario, the weight supports the transposition of NZ inputs. In other scenarios, only non-transposition is supported. INT32 is used for adaptation in the A8W4 and A4W4 scenarios. Actually, one INT32 is interpreted as eight INT4 data. The A8W8 scenario does not support the ND data format.
- The dequantMode parameter is supported. In the A8W4 and A4W4 scenarios, the value can be 0 or 1. In the A8W8 scenario, the value can only be 0.
- The dequantDtype and quantMode parameters are not supported.
- x and weight do not support empty tensors.
- When the weight NZ input is transposed, only the single-tensor mode is supported.
- The weight, weightScale, and weightAssistMatrix support both the single-tensor scenario (the length of the tensor list is 1) and the multi-tensor scenario (the length of the tensor list is greater than 1).
- Ascend 950PR/Ascend 950DT:
- The weight supports only the ND format and can be transposed.
- The dequantMode parameter is supported. In the MX quantization scenario, the value can be 2. In the Pertoken scenario, the value can be 0.
- The dequantDtype parameter is supported. In the MX quantization scenario, the value can be 0. In the Pertoken scenario, the value can be 0, 1, or 27.
- The quantMode parameter is supported. In the MX quantization scenario, the value can be 2. In the Pertoken scenario, the value can be 0.
- Only the same value of dequantMode and quantMode is supported.
- x and xScale support empty tensors with M being 0.
- weight and weightScale support empty tensors with N being 0.
- Currently, weight and weightScale support only the scenario where the length of the tensor list is 1.
- [object Object]Atlas A3 training products/Atlas A3 inference products[object Object] and [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
Returns:
[object Object]: status code. For details, see .The first-phase API implements input parameter validation. The following errors may be thrown:
[object Object]
Deterministic computation:
[object Object]defaults to a deterministic implementation.
[object Object]Atlas A3 training products/Atlas A3 inference products[object Object] and [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
In the A8W8/A8W4/A4W4 quantization scenario, the following restrictions must be met:
Data type requirements
[object Object]The shape constraints must meet the requirements listed in the following table.
[object Object]
In the A8W8 scenario, the length of the N-axis cannot exceed 10240, and the length of the last axis of
[object Object]cannot be greater than or equal to 65536.In the A8W4 scenario, the length of the N-axis cannot exceed 10240, and the length of the last axis of
[object Object]cannot be greater than or equal to 20000.In A4W4 scenarios, the size of the N axis must not exceed 10240, and the size of the last axis of
[object Object]must be less than 20000.In the multi-tensor scenario, that is, when the length of the tensor list is greater than 1, the shapes of weight, weightScale, and weightAssistMatrix need to be flattened based on the E dimension. For example, {(E, K, N)} needs to be changed to {E (K, N)}.
Ascend 950PR/Ascend 950DT:
The first dimension of groupList supports a maximum of 1024 groups.
In the MX quantization scenario, the following constraints must be met:
Data type requirements
[object Object]The shape constraints must meet the requirements listed in the following table.
[object Object]The weightScale transpose attribute must be the same as that of weight.
In the MX quantization scenario, N must be 128-pixel aligned.
In the MXFP4 scenario, K cannot be 2.
In the MXFP4 scenario, K must be an even number. If the output data type is FLOAT4_E2M1, N must be an even number greater than or equal to 4.
In the per-token quantization scenario, the following constraints must be met:
Data type requirements
[object Object]The shape constraints must meet the following requirements:
[object Object]
The following example is for reference only. For details, see .
[object Object]Atlas A3 training products/Atlas A3 inference products[object Object] and [object Object]Atlas A2 training products/Atlas A2 inference products[object Object]:
[object Object]Ascend 950PR/Ascend 950DT:
[object Object]