Description: Fuses
[object Object],[object Object],[object Object], and[object Object]. For details, see the formulas. This API is the weightNZ specialization version of .Formulas:
[object Object]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. - : Group index list of cumsum.
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 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. - : 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. - : Group index list of cumsum.
- 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 performed offline and is not 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.
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]Return
[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.
A8W8 scenario (A: activation matrix (left matrix); W: weight matrix (right matrix); 8: INT8)
- The length of the last axis of
[object Object]cannot be greater than or equal to 65536.
- The length of the last axis of
- The length of the N-axis cannot exceed 10240.
A8W4 scenario (A: activation matrix (left matrix); W: weight matrix (right matrix); 4: INT4)
- The length of the last axis of
[object Object]cannot be greater than or equal to 20000.
- The length of the last axis of
- The length of the N-axis cannot exceed 10240.
The following example is for reference only. For details, see .