- Description: Fuses
[object Object],[object Object],[object Object], and[object Object]. For details, see the formulas. Compared with , this API changes the field type of the[object Object],[object Object], and[object Object]parameters to tensor list. Select an appropriate API as required. - 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 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.
- : 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
- Compute the auxiliary matrix (
[object Object]). (Note that the 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.
- [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]
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]:
[object Object]supports only the INT8 quantization data type.[object Object]only supports the non-transposed mode and supports INT8, INT4, and INT32 data types. In ND format, the shape is {(E, K, N)}. In NZ format, the shape is {(E, N/32, K/16, 16, 32)} for the INT8 data type, {(E, N/64, K/16, 16, 64)} for INT4, and {(E, N/64, K/16, 16, 8)} for INT32.[object Object]supports FLOAT, FLOAT16, and BFLOAT16 data types in the A8W8 scenario, where the shape must be 2D, represented as {(E, N)}. In the A8W4 scenario, it supports the UINT64 data type, and the shape can be 2D or 3D (shape {(E, N)} for per-channel mode and shape {(E, KGroupCount, N)} for per-group mode).- The
[object Object]parameter is supported. The value[object Object]indicates per-token mode for the activation matrix and per-channel mode for the weight matrix. The value[object Object]indicates per-token mode for the activation matrix and per-group mode for the weight matrix. - The
[object Object]parameter is not supported. - The
[object Object]parameter is not supported. - In the A8W8 or A8W4 scenario, the length of the N-axis cannot exceed 10240.
- In the A8W8 scenario, 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 last axis of
[object Object]cannot be greater than or equal to 20000. - The data type of
[object Object]must be INT8, and the shape can be 2D, for example, (M, N/2). - The data type of
[object Object]must be FLOAT, and the shape can be 1D, for example, (M,).
- [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]:
Return
[object Object]status code. For details, see .The first-phase API implements input parameter validation. The following errors may be thrown:
[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 A8W8/A8W4 quantization scenarios, the following constraints must be met:
- Data type requirements
- 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 A8W8/A8W4 quantization scenarios, the following constraints must be met:
Deterministic computation:
[object Object]defaults to a deterministic implementation.
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]