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:
- Quantization scenario (A8W8):
Definition
- ⋅ indicates matrix multiplication.
- ⊙ indicates element-wise multiplication.
- indicates rounding
[object Object]to the nearest integer.
Input
- : input 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 input matrix (left matrix), where
[object Object]indicates the total number of tokens. - : grouped index list of prefix sums.
- : input 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.
- MSD scenario (A8W4):
- Definition
- ⋅ indicates matrix multiplication.
- ⊙ indicates element-wise multiplication.
- indicates rounding
[object Object]to the nearest integer.
- Input
- : input 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 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 input matrix (left matrix), where
[object Object]indicates the total number of tokens. - : grouped index list of prefix sums.
- : input 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
- Compute the auxiliary matrix (
[object Object]). (Note that the bias computation is performed offline and provided as an input, rather than being executed within the operator.)
For per-channel quantization ( is 2D):
For per-group quantization ( is 3D):
Note:
- Compute the auxiliary matrix (
- 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
- Quantization scenario (A8W8):
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.
[object Object][object Object]
Parameters
x (aclTensor*, computation input): left matrix, in the formula, aclTensor on the device. The shape supports 2D. Assuming the shape is [M,K], K must be less than 65536. The data type can be INT8, and the can be ND. are supported.
weight (aclTensor*, computation input): weight matrix, in the formula, aclTensor on the device. The shape supports 5D. The data type can be INT8, INT4, or INT32 (INT32 is used for adaptation. Actually, one INT32 data record is interpreted as eight INT4 data records). The can be FRACTAL_NZ. are supported. Note that this API ignores the weight data format and considers it as the FRACTAL_NZ format.
bias (aclTensor*, computation input): matrix multiplication bias, in the formula. The shape supports 2D. The data type can be INT32. This input is reserved and is not supported currently. You need to pass a null pointer.
offset (aclTensor*, computation input): offset of per-channel asymmetric dequantization, in the formula. The shape supports 2D. The data type is float. This input is reserved and is not supported currently. You need to pass a null pointer.
weightScale (aclTensor*, computation input): quantization factor of the right matrix, in the formula, aclTensor on the device. The shape supports 2D. The length of the first axis must be the same as the first axis of
[object Object]. The length of the last axis must be the same as the last axis of[object Object]restored to the ND format. The data type can be FLOAT, FLOAT16, or BFLOAT16. The can be ND. are supported.xScale (aclTensor*, computation input): quantization factor of the left matrix, in the formula, aclTensor on the device. The shape supports 1D. The length must be the same as the first axis of
[object Object]. The data type can be FLOAT. The can be ND. are supported.groupList (aclTensor*, computation input): number of tokens involved in the computation of each group, in the formula, aclTensor on the device. The shape supports 1D. The length must be the same as the first axis of
[object Object]. The data type can be INT64. The can be ND. are supported. The last value in[object Object]constrains the valid portion of the output data. For details, see the computation process.output (aclTensor*, computation output): quantization result, in the formula, aclTensor on the device. The data type can be INT8, and the shape can be 2D. The can be ND. are supported.
outputScale (aclTensor*, computation output): quantization factor, in the formula, aclTensor on the device. The data type can be FLOAT, and the shape can be 1D. The can be ND. are supported.
outputOffset (aclTensor*, computation output): offset of asymmetric quantization, in the formula, aclTensor on the device. The shape can be 1D, and the data type can be FLOAT. This input is reserved and is not supported currently. You need to pass a null pointer.
workspaceSize (uint64_t*, output parameter): size of the workspace to be allocated on the NPU device.
executor (aclOpExecutor**, computation output): operator executor, containing the operator computation process.
Return
Parameters
- workspace (void*, input parameter): address of the workspace to be allocated on the device.
- workspaceSize (uint64_t, input parameter): workspace size to be allocated on the device, which is obtained by the first-phase API
[object Object]. - executor (aclOpExecutor*, input parameter): operator executor, containing the operator computation process.
- stream (aclrtStream, input parameter): stream for executing the task.
Return
- Deterministic computation:
[object Object]defaults to a deterministic implementation.
- 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.
- 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 .