MlaPreprocessOperation
Applicable Products
Hardware Model |
Supported or Not |
|---|---|
Atlas 350 accelerator card |
x |
√ |
|
√ |
|
x |
|
x |
|
x |
Description
Integrates the entire process of PagedAttention input data processing in the MLA scenario, including rmsnorm, dequantization, matmul, rope, and reshapeAndCache calculations starting from the hidden state input.
Definition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | struct MlaPreprocessParam{ uint32_t wdqDim = 0; uint32_t qRopeDim = 0; uint32_t kRopeDim = 0; float epsilon = 1e-5; int32_t qRotaryCoeff = 2; int32_t kRotaryCoeff = 2; bool transposeWdq = true; bool transposeWuq = true; bool transposeWuk = true; enum CacheMode : uint8_t { KVCACHE = 0, KROPE_CTKV, INT8_NZCACHE, NZCACHE }; CacheMode cacheMode = KVCACHE; enum QuantMode : uint16_t { PER_TENSOR_QUANT_ASYMM = 0, PER_TOKEN_QUANT_SYMM, PER_TOKEN_QUANT_ASYMM, UNQUANT }; QuantMode quantMode = PER_TENSOR_QUANT_ASYMM; enum BackendType : int { BACKEND_TYPE_ATB = 0, BACKEND_TYPE_ACLNN, BACKEND_TYPE_MAX, }; BackendType backendType = BACKEND_TYPE_ATB; uint8_t rsv[34] = {0}; }; |
Parameters
Member |
Type |
Default Value |
Value |
Mandatory or Not |
Description |
|---|---|---|---|---|---|
wdqDim |
uint32_t |
0 |
[0] |
No |
Split dimension size after matmul. |
qRopeDim |
uint32_t |
0 |
[0] |
No |
Dimension size of q passed to RoPE. |
kRopeDim |
uint32_t |
0 |
[0] |
No |
Dimension size of k passed to RoPE. |
epsilon |
float |
1e-5 |
[1e-5] |
No |
It is added to the denominator to prevent division by 0. |
qRotaryCoeff |
int32_t |
2 |
2 |
No |
q rotation coefficient. |
kRotaryCoeff |
int32_t |
2 |
2 |
No |
k rotation coefficient. |
transposeWdq |
bool |
true |
(true) |
No |
Whether to transpose wdq. |
transposeWuq |
bool |
true |
(true) |
No |
Whether to transpose wuq. |
transposeWuk |
bool |
true |
(true) |
No |
Whether to transpose wuk. |
cacheMode |
uint8_t |
0 |
[0,3] |
No |
Cache type. |
quantMode |
uint16_t |
0 |
[0,3] |
No |
RmsNorm quantization type. |
rsv[34] |
uint8_t |
{0} |
[0] |
No |
Reserved parameter. |
Currently, only cacheMode and quantMode takes effect. |
|||||
The user-defined types in the preceding table are described as follows.
cacheMode: type of the input query and kcache. The values are as follows:
- KVCACHE: kcache and q are concatenated and then output.
- KROPE_CTKV: The input and output kvCache is split into krope and ctkv, and q is split into qrope and qnope.
- INT8_NZCACHE: krope and ctkv are converted into the NZ format for output, and ctkv and qnope are quantized into the int8 type through per_head static symmetric quantization.
- NZCACHE: krope and ctkv are converted into the NZ format for output.
quantMode: RmsNorm quantization type. The values are as follows:
- PER_TENSOR_QUANT_ASYMM: per_tensor static asymmetric quantization, which is the default quantization type.
- PER_TOKEN_QUANT_SYMM: per_token dynamic symmetric quantization, which is not implemented.
- PER_TOKEN_QUANT_ASYMM: per_token dynamic asymmetric quantization, which is not implemented.
- UNQUANT: no quantization, floating-point output, which is not implemented.
Input
Module Function |
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|---|
rmsNormQuant_0 |
input |
[tokenNum, hiddenSize] |
float16/bf16 |
ND |
Mandatory. |
gamma0 |
[hiddenSize] |
float16/bf16 |
ND |
Mandatory. The data type is the same as that of input. |
|
beta0 |
[hiddenSize] |
float16/bf16 |
ND |
Mandatory. The data type is the same as that of input. |
|
quantScale0 |
[1] |
float16/bf16 |
ND |
Mandatory. An empty tensor can be passed. This parameter is passed only if quantMode is set to 0. The data type is the same as that of input. |
|
quantOffset0 |
[1] |
int8 |
ND |
Mandatory. An empty tensor can be passed. This parameter is passed only if quantMode is set to 0. |
|
matmul_0 |
wdqkv |
[2112, hiddenSize] |
int8/bf16 |
NZ |
Mandatory. If the data type is the same as that of input and the data type is bf16, rmsNormQuant is disabled. |
deScale0 |
[2112] |
int64/float |
ND |
Mandatory. If the data type of input is float16, the data type of this parameter is int64. If the data type of input is bf16, the data type of this parameter is float. |
|
bias0 |
[2112] |
int32 |
ND |
Mandatory. An empty tensor can be passed. This parameter is not passed when quantMode is set to 1 or 3. |
|
rmsNormQuant_1 |
gamma1 |
[1536] |
float16/bf16 |
ND |
Mandatory. The data type is the same as that of input. |
beta1 |
[1536] |
float16/bf16 |
ND |
Mandatory. The data type is the same as that of input. |
|
quantScale1 |
[1] |
float16/bf16 |
ND |
Mandatory. An empty tensor can be passed. This parameter is passed only if quantMode is set to 0. The data type is the same as that of input. |
|
quantOffset1 |
[1] |
int8 |
ND |
Mandatory. An empty tensor can be passed. This parameter is passed only if quantMode is set to 0. |
|
matmul_1 |
wuq |
[headNum * 192, 1536] |
int8/bf16 |
NZ |
Mandatory. If the data type is the same as that of input and the data type is bf16, rmsNormQuant is disabled. |
deScale1 |
[headNum * 192] |
int64/float |
ND |
Mandatory. If the data type of input is float16, the data type of this parameter is int64. If the data type of input is bf16, the data type of this parameter is float. |
|
bias1 |
[headNum * 192] |
int32 |
ND |
Mandatory. An empty tensor can be passed. This parameter is not passed when quantMode is set to 1 or 3. |
|
rmsNorm |
gamma2 |
[512] |
float16/bf16 |
ND |
Mandatory. The data type is the same as that of input. |
rope |
cos |
[tokenNum,64] |
float16/bf16 |
ND |
Mandatory. The data type is the same as that of input. |
sin |
[tokenNum,64] |
float16/bf16 |
ND |
Mandatory. The data type is the same as that of input. |
|
matmulEin |
wuk |
ND: [headNum, 128, 512] NZ: [headNum, 32, 128, 16] |
float16/bf16 |
ND/NZ |
Mandatory. The data type is the same as that of input. |
reshapeAndCache |
kvCache |
|
float16/bf16/int8 |
ND/NZ |
Mandatory. The data type is the same as that of input.
|
kvCacheRope |
|
float16/bf16 |
ND/NZ |
Mandatory. An empty tensor can be passed.
|
|
slotmapping |
[tokenNum] |
int32 |
ND |
Mandatory. |
|
quant |
ctkvScale |
[1] |
float16/bf16 |
ND |
Mandatory. An empty tensor can be passed. This parameter is passed if cacheMode is set to 2. The data type is the same as that of input. |
qNopeScale |
[headNum] |
float16/bf16 |
ND |
Mandatory. An empty tensor can be passed. This parameter is passed if cacheMode is set to 2. The data type is the same as that of input. |
Output
Optional output tensors cannot be empty.
Module Function |
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|---|
Output data |
qOut0 |
|
float16/bf16/int8 |
ND |
Output tensor. The data type is the same as that of input. If cacheMode is set to 2, the data type is int8. |
kvCacheOut0 |
|
float16/bf16/int8 |
ND/NZ |
Output tensor. The data type is the same as that of input.
|
|
qOut1 |
[tokenNum, headNum, 64] |
float16/bf16 |
ND |
This tensor is output if cacheMode is not set to 0. The data type is the same as that of input. |
|
kvCacheOut1 |
|
float16/bf16 |
ND/NZ |
This tensor is output if cacheMode is not set to 0. The data type is the same as that of input.
|
Restrictions
- tokenNum ≤ 1024
- blockSize ≤ 128 or blockSize = 256
- If cacheMode is set to 2 or 3, blockSize is 128.
- The value range of hiddenSize is [2048,8192], and the value must be 256-aligned.
- If rmsNormQuant is disabled, hiddenSize can only be set to 6144, and cacheMode can only be set to 0 or 1.
- If rmsNormQuant is disabled or hiddenSize is not set to 7168:
- 1 ≤ tokenNum ≤ 256
- Value range of headNum: [16, 32, 64, 128].