Description: Fuses
[object Object],[object Object],[object Object], and[object Object]. For details, see the formulas. This API is the weightNZ specialization version of . The difference between this API and aclnnGroupedMatmulSwigluQuantV2 is that the weight parameter is forcibly regarded as the FRACTAL_NZ format in this scenario.Formulas:
[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.
Inputs
- : activation matrix (left matrix), where indicates the total number of tokens and indicates the feature dimension.
- : grouped weight matrix (right matrix), where indicates the number of routed experts, indicates the feature dimension, and 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.
Outputs
- : quantized output matrix.
- : quantization scale factor.
Calculation 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.
- Inputs
- : activation matrix (left matrix), where indicates the total number of tokens and indicates the feature dimension.
- : grouped weight matrix (right matrix), where indicates the number of routed experts, indicates the feature dimension, and indicates the output dimension.
- : auxiliary matrix for matrix multiplication (the computation process for generating the auxiliary matrix is described below).
- : 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.
- Outputs
- : quantized output matrix.
- : quantization scale factor.
- Calculation 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.
Inputs
- : activation matrix (left matrix), where indicates the total number of tokens and indicates the feature dimension.
- : grouped weight matrix (right matrix), where indicates the number of routed experts, indicates the feature dimension, and 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.
Outputs
- : quantized output matrix.
- : quantization scale factor.
Calculation 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.
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 flow. Then, [object Object] is called to perform computation.
Parameters
[object Object]- [object Object]Atlas A3 training series products/Atlas A3 inference series products[object Object] and [object Object]Atlas A2 training series products/Atlas A2 inference series products[object Object]:
- [object Object]The weight is forcibly regarded as the FRACTAL_NZ format.[object Object]
- The weight supports transposition in the A4W4 scenario, and supports only non-transposition in other scenarios. INT32 is used for adaptation in the A8W4 and A4W4 scenarios. In practice, one INT32 is interpreted as eight INT4 data. The ND data format is not supported in the A8W8 scenario.
- 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 is transposed in the NZ format, only the single-tensor mode is supported.
- weight, weightScale, and weightAssistMatrix support both single-tensor scenarios (the length of the tensor list is 1) and multi-tensor scenarios (the length of the tensor list is greater than 1).
- [object Object]Atlas A3 training series products/Atlas A3 inference series products[object Object] and [object Object]Atlas A2 training series products/Atlas A2 inference series products[object Object]:
Returns:
[object Object]: status code. For details, see .The first-phase API implements input parameter validation. The following error codes may be returned.
[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 A8W8 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 65536.In A8W4 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 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 according to the dimension of E. For example, {(E, K, N)} needs to be changed to {E (K, N)}.
- In the A8W8/A8W4/A4W4 quantization scenario, the following restrictions must be met:
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]