Note: This API will be deprecated in later versions. Use the latest API aclnnMlaPrologV3WeightNz instead.
Interface function: In inference scenarios, this operator performs the preprocessing computation for Multi-Head Latent Attention. The main computation process consists of five paths.
- After multiplying the input with for downsampling and RmsNorm, the first path multiplies the result with and , followed by two upsampling operations to obtain , while the second path multiplies the result with and applies rotary position encoding (ROPE) to obtain .
- The third path multiplies the input with for downsampling and RmsNorm, and then passes the result into the cache to obtain .
- The fourth path multiplies the input with , applies rotary position encoding (ROPE), and then stores the result into another cache to obtain .
- The fifth path processes the output through DynamicQuant to generate quantization parameters.
- The weight parameters
[object Object],[object Object], and[object Object]are required to be provided in NZ format.
Formula:
RmsNorm formula
The calculation formula of the query includes downsampling, RmsNorm, and two upsamplings.
Performs rotary position encoding (ROPE) to the query.
The computation formula of the key, including downsampling and RmsNorm. The computation result is stored in the cache.
Performs rotary position encoding (ROPE) to the key and stores the result in the cache.
Dequant Scale Query Nope calculation formula:
Each operator has calls. First, [object Object] is called to obtain the input parameters and compute the required workspace size based on the process. Then, [object Object] is called to perform computation.
Parameters
[object Object]undefined
Returns
[object Object]: status code. For details, see .The first-phase API performs input parameter validation. The following errors may be returned:
[object Object]undefined
Deterministic computation:
[object Object]defaults to deterministic implementation. Currently, A5 does not fully support the generalization scope of the input parameters and supported scenarios of the MlaProlog API on A2 and A3. The details are as follows:
Shape field description
[object Object]undefined
When transposing is not performed, the dimensions of
[object Object],[object Object], and[object Object]are represented as (k, n).Shape constraints:
- When BS fusion is used for
[object Object], that is , (T, He)- The shape of ropeSin and ropeCos is (T, Dr).
- The shape of cacheIndex is (T).
- The shape of dequantScaleXOptional is (T, 1).
- The shape of queryOut is (T, N, Hckv).
- The shape of queryRopeOut is (T, N, Dr).
- In the int8 full quantization scenario, the shape of dequantScaleQNopeOutOptional is (T, N, 1). In other scenarios, the shape is (1).
- When BS fusion is not used for
[object Object], that is , (B, S, He)- The shape of ropeSin and ropeCos is (B, S, Dr).
- The shape of cacheIndex is (B, S).
- The shape of dequantScaleXOptional is (B*S, 1).
- The shape of queryOut is (B, S, N, Hckv).
- The shape of queryRopeOut is (B, S, N, Dr).
- In the int8 full quantization scenario, the shape of dequantScaleQNopeOutOptional is (B*S, N, 1). In other scenarios, the shape is (1).
- One or more of the B, S, T, and Skv values can be 0. That is, input parameters related to the shape and B, S, T, and Skv values can be empty tensors. Other input parameters do not support empty tensors.
- If the values of B, S, and T are 0,
[object Object]and[object Object]output empty tensors, and[object Object]and[object Object]are not updated. - If the value of Skv is 0,
[object Object],[object Object], and[object Object]are calculated normally, and[object Object]and[object Object]are not updated. That is, an empty tensor is output.
- If the values of B, S, and T are 0,
- When BS fusion is used for
The aclnnMlaPrologV2WeightNz API supports the following scenarios: A2 and A3 support all the following scenarios, and A5 supports only non-quantization scenarios.
[object Object]In different quantization scenarios, the combination of dtype and shape of parameters must meet the following conditions:
[object Object]
The following sample code for A2 and A3 is for reference only. For details, see .
The following is the sample code for A5, which is for reference only.