Merged
docs: 修正算子接口文档中的表述问题 #15771
docs: 修正算子接口文档中的表述问题 #15771
Merged
周云飞Add on 17 days ago
Total: 100 files changed+232-242
@@ -29,7 +29,7 @@
29 29 
30## 功能说明30## 功能说明
31 31 
32-- ​算子功能​:aclnnBlockSparseAttention稀疏注意力反向计算,支持灵活的块级稀疏模式,通过BlockSparseMask指定每个Q块选择的KV块,实现高效的稀疏注意力计算。32+- ​算子功能​:计算块稀疏注意力的反向传播,支持灵活的块级稀疏模式,通过BlockSparseMask指定每个Q块选择的KV块。
33- ​计算公式​:33- ​计算公式​:
34 34 
35 稀疏块大小为 $blockShapeX×blockShapeY$,其中blockShapeX表示Q方向的稀疏粒度,blockShapeY表示KV方向的稀疏粒度。两个方向的粒度相互独立,可以配置为不同值。35 稀疏块大小为 $blockShapeX×blockShapeY$,其中blockShapeX表示Q方向的稀疏粒度,blockShapeY表示KV方向的稀疏粒度。两个方向的粒度相互独立,可以配置为不同值。
@@ -31,7 +31,7 @@
31 31 
32## Function32## Function
33 33 
34-- Description: aclnnBlockSparseAttention performs backward computation for sparse attention. It supports flexible block-level sparsity patterns and uses BlockSparseMask to specify the KV blocks selected for each Q block, enabling efficient sparse attention computation.34+- Description: Computes the backward pass of block-sparse attention. It supports flexible block-level sparsity patterns and uses BlockSparseMask to specify the KV blocks selected for each Q block.
35- Formula:35- Formula:
36 36 
37 The sparse block size is $blockShapeX×blockShapeY$, where blockShapeX indicates the sparse granularity in the Q direction and blockShapeY indicates the sparse granularity in the KV direction. The granularities of the two directions are independent of each other and can be set to different values.37 The sparse block size is $blockShapeX×blockShapeY$, where blockShapeX indicates the sparse granularity in the Q direction and blockShapeY indicates the sparse granularity in the KV direction. The granularities of the two directions are independent of each other and can be set to different values.
@@ -486,7 +486,7 @@ aclnnStatus aclnnDenseLightningIndexerGradKLLoss(
486 - 确定性计算:486 - 确定性计算:
487 aclnnDenseLightningIndexerGradKLLoss默认非确定性实现,支持通过aclrtCtxSetSysParamOpt开启确定性。487 aclnnDenseLightningIndexerGradKLLoss默认非确定性实现,支持通过aclrtCtxSetSysParamOpt开启确定性。
488 - 入参为空的场景处理:488 - 入参为空的场景处理:
489- - query或key或query_index或key_index或weight为空Tensor:当前不支持,会报错。489+ - query或key或queryIndex或keyIndex或weights为空Tensor:当前不支持,会报错。
490 490 
491 <table style="undefined;table-layout: fixed; width: 942px"><colgroup>491 <table style="undefined;table-layout: fixed; width: 942px"><colgroup>
492 <col style="width: 100px">492 <col style="width: 100px">
@@ -488,7 +488,7 @@ aclnnStatus aclnnDenseLightningIndexerGradKLLoss(
488 - Deterministic computation:488 - Deterministic computation:
489 aclnnDenseLightningIndexerGradKLLoss defaults to a non-deterministic implementation, and supports enabling deterministic computation through alcrtCtxSetSysParamOpt.489 aclnnDenseLightningIndexerGradKLLoss defaults to a non-deterministic implementation, and supports enabling deterministic computation through alcrtCtxSetSysParamOpt.
490 - Handling of empty input parameters:490 - Handling of empty input parameters:
491- - If query, key, query_index, key_index, or weight is an empty tensor: currently not supported, and an error is reported.491+ - If query, key, queryIndex, keyIndex, or weights is an empty tensor: currently not supported, and an error is reported.
492 492 
493 <table style="undefined;table-layout: fixed; width: 942px"><colgroup>493 <table style="undefined;table-layout: fixed; width: 942px"><colgroup>
494 <col style="width: 100px">494 <col style="width: 100px">
@@ -23,10 +23,10 @@
23 23 
24## 功能说明24## 功能说明
25 25 
26-* 接口功能:训练场景下,使用FlashAttention算法实现self-attention(自注意力)的计算。对标竞品适配gpt-oss模型支持sink功能。**跟[aclnnFlashAttentionVarLenScoreV3](./aclnnFlashAttentionVarLenScoreV3.md)接口的区别是:增加`sinkInOptional`可选输入,保留了[aclnnFlashAttentionVarLenScoreV4](./aclnnFlashAttentionVarLenScoreV4.md)的`softmaxOutLayout`可选输入。**26+* 接口功能:训练场景下,使用FlashAttention算法实现self-attention(自注意力)的计算。支持gpt-oss模型的sink功能。**跟[aclnnFlashAttentionVarLenScoreV3](./aclnnFlashAttentionVarLenScoreV3.md)接口的区别是:增加`sinkOptional`可选输入,保留了[aclnnFlashAttentionVarLenScoreV4](./aclnnFlashAttentionVarLenScoreV4.md)的`softmaxOutLayout`可选输入。**
27 27 
28 <!-- npu="950" id7 -->28 <!-- npu="950" id7 -->
29- - <term>Ascend 950PR&950DT系列产品</term>:暂不支持sinkInOptional与softmaxOutLayout参数。29+ - <term>Ascend 950PR&950DT系列产品</term>:暂不支持sinkOptional与softmaxOutLayout参数。
30 30 
31 <!-- end id7 -->31 <!-- end id7 -->
32 32 
@@ -25,10 +25,10 @@
25 25 
26## Function26## Function
27 27 
28-- Description: In training scenarios, the FlashAttention algorithm is used to implement self-attention computation. It is adapted to competitor gptoss models and supports the sink function. **The difference from the [aclnnFlashAttentionVarLenScoreV3](./aclnnFlashAttentionVarLenScoreV3_en.md) API is: the `sinkInOptional` optional input is added, while the `softmaxOutLayout` optional input from [aclnnFlashAttentionVarLenScoreV4](./aclnnFlashAttentionVarLenScoreV4_en.md) is retained.**28+- Description: In training scenarios, the FlashAttention algorithm is used to implement self-attention computation. It supports the sink function for gpt-oss models. **The difference from the [aclnnFlashAttentionVarLenScoreV3](./aclnnFlashAttentionVarLenScoreV3_en.md) API is: the `sinkOptional` optional input is added, while the `softmaxOutLayout` optional input from [aclnnFlashAttentionVarLenScoreV4](./aclnnFlashAttentionVarLenScoreV4_en.md) is retained.**
29 29 
30 <!-- npu="950" id7 -->30 <!-- npu="950" id7 -->
31- - <term>Ascend 950PR&950DT products</term>: The sinkInOptional and softmaxOutLayout parameters are not supported.31+ - <term>Ascend 950PR&950DT products</term>: The sinkOptional and softmaxOutLayout parameters are not supported.
32 32 
33 <!-- end id7 -->33 <!-- end id7 -->
34 34 
@@ -33,13 +33,13 @@
33 已知注意力的正向计算公式为(pseType=1时,与[aclnnFlashAttentionScoreGrad](./aclnnFlashAttentionScoreGrad.md)计算公式相同,pseType=其他取值公式如下):33 已知注意力的正向计算公式为(pseType=1时,与[aclnnFlashAttentionScoreGrad](./aclnnFlashAttentionScoreGrad.md)计算公式相同,pseType=其他取值公式如下):
34 34 
35 $$35 $$
36- Y=Dropout(Softmax(Mask(\frac{QK^T}{\sqrt{d}}+pse),atten\_mask),keep\_prob)V36+ Y=Dropout(Softmax(Mask(\frac{QK^T}{\sqrt{d}}+pse,atten\_mask)),keep\_prob)V
37 $$37 $$
38 38 
39 为方便表达,以变量$S$和$P$表示计算公式:39 为方便表达,以变量$S$和$P$表示计算公式:
40 40 
41 $$41 $$
42- S=Mask(\frac{QK^T}{\sqrt{d}}+pse),atten\_mask42+ S=Mask(\frac{QK^T}{\sqrt{d}}+pse,atten\_mask)
43 $$43 $$
44 44 
45 $$45 $$
@@ -35,13 +35,13 @@
35 The known attention forward computation formula is (when pseType = 1, it is the same as the formula of [aclnnFlashAttentionScoreGrad](./aclnnFlashAttentionScoreGrad_en.md); when pseType takes other values, the formula is as follows):35 The known attention forward computation formula is (when pseType = 1, it is the same as the formula of [aclnnFlashAttentionScoreGrad](./aclnnFlashAttentionScoreGrad_en.md); when pseType takes other values, the formula is as follows):
36 36 
37 $$37 $$
38- Y=Dropout(Softmax(Mask(\frac{QK^T}{\sqrt{d}}+pse),atten\_mask),keep\_prob)V38+ Y=Dropout(Softmax(Mask(\frac{QK^T}{\sqrt{d}}+pse,atten\_mask)),keep\_prob)V
39 $$39 $$
40 40 
41 For ease of expression, variables $S$ and $P$ are used to represent the formulas:41 For ease of expression, variables $S$ and $P$ are used to represent the formulas:
42 42 
43 $$43 $$
44- S=Mask(\frac{QK^T}{\sqrt{d}}+pse),atten\_mask44+ S=Mask(\frac{QK^T}{\sqrt{d}}+pse,atten\_mask)
45 $$45 $$
46 46 
47 $$47 $$
@@ -52,15 +52,15 @@ $$
52则注意力的反向计算公式为:52则注意力的反向计算公式为:
53 53 
54$$54$$
55-V=P^TdY55+dV=P^TdY
56$$56$$
57 57 
58$$58$$
59-Q=\frac{((dS)*K)}{\sqrt{d}}59+dQ=\frac{((dS)*K)}{\sqrt{d}}
60$$60$$
61 61 
62$$62$$
63-K=\frac{((dS)^T*Q)}{\sqrt{d}}63+dK=\frac{((dS)^T*Q)}{\sqrt{d}}
64$$64$$
65 65 
66其中增加**sink**之后计算逻辑见下,主要修改相关softmax_max和softmax_sum逻辑计算部分66其中增加**sink**之后计算逻辑见下,主要修改相关softmax_max和softmax_sum逻辑计算部分
@@ -54,15 +54,15 @@ $$
54The backward propagation formula for attention is:54The backward propagation formula for attention is:
55 55 
56$$56$$
57-V=P^TdY57+dV=P^TdY
58$$58$$
59 59 
60$$60$$
61-Q=\frac{((dS)*K)}{\sqrt{d}}61+dQ=\frac{((dS)*K)}{\sqrt{d}}
62$$62$$
63 63 
64$$64$$
65-K=\frac{((dS)^T*Q)}{\sqrt{d}}65+dK=\frac{((dS)^T*Q)}{\sqrt{d}}
66$$66$$
67 67 
68The computation logic after adding **sink** is as follows, mainly modifying the relevant softmax_max and softmax_sum logic computation parts.68The computation logic after adding **sink** is as follows, mainly modifying the relevant softmax_max and softmax_sum logic computation parts.
@@ -296,9 +296,9 @@ cann_ops_transformer.flash_attn(
296 <td>296 <td>
297 <ul>297 <ul>
298 <li>tensor_type支持bfloat16和float16</li>298 <li>tensor_type支持bfloat16和float16</li>
299- <li>BNSD -> (B, N_Q, S_Q, D)</li>299+ <li>BNSD -> (B, Q_N, Q_S, D)</li>
300- <li>BSND -> (B, S_Q, N_Q, D)</li>300+ <li>BSND -> (B, Q_S, Q_N, D)</li>
301- <li>TND -> (T_Q, N_Q, D)</li>301+ <li>TND -> (Q_T, Q_N, D)</li>
302 </ul>302 </ul>
303 </td>303 </td>
304 <td rowspan="4">304 <td rowspan="4">
@@ -332,9 +332,9 @@ cann_ops_transformer.flash_attn(
332 <td rowspan="2">332 <td rowspan="2">
333 <ul>333 <ul>
334 <li>tensor_type支持bfloat16和float16</li>334 <li>tensor_type支持bfloat16和float16</li>
335- <li>BNSD -> (B, N_KV, S_KV, D)</li>335+ <li>BNSD -> (B, KV_N, KV_S, D)</li>
336- <li>BSND -> (B, S_KV, N_KV, D)</li>336+ <li>BSND -> (B, KV_S, KV_N, D)</li>
337- <li>TND -> (T_KV, N_KV, D)</li>337+ <li>TND -> (KV_T, KV_N, D)</li>
338 <li>PA_BBND -> (num_blocks, block_size, KV_N, D)</li>338 <li>PA_BBND -> (num_blocks, block_size, KV_N, D)</li>
339 <li>PA_BNBD -> (num_blocks, KV_N, block_size, D)</li>339 <li>PA_BNBD -> (num_blocks, KV_N, block_size, D)</li>
340 <li>PA_NZ -> (num_blocks, KV_N, D//16, block_size, 16)</li>340 <li>PA_NZ -> (num_blocks, KV_N, D//16, block_size, 16)</li>
@@ -297,9 +297,9 @@ In the documentation constraints, the meanings of common fields are as follows:
297 <td>q</td>297 <td>q</td>
298 <td> <ul>298 <td> <ul>
299 <li>tensor_type supports bfloat16 and float16.</li>299 <li>tensor_type supports bfloat16 and float16.</li>
300- <li>BNSD -> (B, N_Q, S_Q, D)</li>300+ <li>BNSD -> (B, Q_N, Q_S, D)</li>
301- <li>BSND -> (B, S_Q, N_Q, D)</li>301+ <li>BSND -> (B, Q_S, Q_N, D)</li>
302- <li>TND -> (T_Q, N_Q, D)</li>302+ <li>TND -> (Q_T, Q_N, D)</li>
303 </ul>303 </ul>
304 </td>304 </td>
305 <td rowspan="4"> Must exist305 <td rowspan="4"> Must exist
@@ -329,9 +329,9 @@ In the documentation constraints, the meanings of common fields are as follows:
329 <td>k</td>329 <td>k</td>
330 <td rowspan="2"> <ul>330 <td rowspan="2"> <ul>
331 <li>tensor_type supports bfloat16 and float16.</li>331 <li>tensor_type supports bfloat16 and float16.</li>
332- <li>BNSD -> (B, N_KV, S_KV, D)</li>332+ <li>BNSD -> (B, KV_N, KV_S, D)</li>
333- <li>BSND -> (B, S_KV, N_KV, D)</li>333+ <li>BSND -> (B, KV_S, KV_N, D)</li>
334- <li>TND -> (T_KV, N_KV, D)</li>334+ <li>TND -> (KV_T, KV_N, D)</li>
335 <li>PA_BBND -> (num_blocks, block_size, KV_N, D)</li>335 <li>PA_BBND -> (num_blocks, block_size, KV_N, D)</li>
336 <li>PA_BNBD -> (num_blocks, KV_N, block_size, D)</li>336 <li>PA_BNBD -> (num_blocks, KV_N, block_size, D)</li>
337 <li>PA_NZ -> (num_blocks, KV_N, D//16, block_size, 16)</li>337 <li>PA_NZ -> (num_blocks, KV_N, D//16, block_size, 16)</li>
@@ -357,7 +357,7 @@ aclnnStatus aclnnFusedCausalConv1d(
357 <tr>357 <tr>
358 <td>convStates(aclTensor*)</td>358 <td>convStates(aclTensor*)</td>
359 <td>输入/输出</td>359 <td>输入/输出</td>
360- <td>计算公式中的cacheState,代表缓存状态张量,存储各序列的历史token数据,各序列计算完成后原地更新。</td>360+ <td>计算公式中的cachedState,代表缓存状态张量,存储各序列的历史token数据,各序列计算完成后原地更新。</td>
361 <td><ul><li>不支持空tensor。</li><li>shape为[..., stateLen, dim],第0维的大小不固定。</li><li>stateLen == K-1+m,prefill场景下m=0,decode、PD混部场景下m=[0,7]。</li><li>m表示投机个数,映射numAcceptedTokens参数的值。</li><li>支持dim0和dim1非连续且stride大于等于1</li></ul></td>361 <td><ul><li>不支持空tensor。</li><li>shape为[..., stateLen, dim],第0维的大小不固定。</li><li>stateLen == K-1+m,prefill场景下m=0,decode、PD混部场景下m=[0,7]。</li><li>m表示投机个数,映射numAcceptedTokens参数的值。</li><li>支持dim0和dim1非连续且stride大于等于1</li></ul></td>
362 <td>数据类型与x一致</td>362 <td>数据类型与x一致</td>
363 <td>ND</td>363 <td>ND</td>
@@ -359,7 +359,7 @@ aclnnStatus aclnnFusedCausalConv1d(
359 <tr>359 <tr>
360 <td>convStates(aclTensor*)</td>360 <td>convStates(aclTensor*)</td>
361 <td>Input/Output</td>361 <td>Input/Output</td>
362- <td>cacheState in the Formula. It represents the cache state tensor, stores historical token data of each sequence, and is updated in place after each sequence is computed.</td>362+ <td>cachedState in the formula. It represents the cache state tensor, stores historical token data of each sequence, and is updated in place after each sequence is computed.</td>
363 <td><ul><li>Empty tensors are not supported.</li><li>The shape is [..., stateLen, dim], and the size of dimension 0 is not fixed.</li><li>stateLen == K-1+m, where m=0 in the prefill use case and m=[0,7] in the decode and PD mixed deployment use cases.</li><li>m indicates the count of speculative tokens, which maps to the value of the numAcceptedTokens parameter.</li><li>Non-contiguous dim0 and dim1 with stride greater than or equal to 1 are supported.</li></ul></td>363 <td><ul><li>Empty tensors are not supported.</li><li>The shape is [..., stateLen, dim], and the size of dimension 0 is not fixed.</li><li>stateLen == K-1+m, where m=0 in the prefill use case and m=[0,7] in the decode and PD mixed deployment use cases.</li><li>m indicates the count of speculative tokens, which maps to the value of the numAcceptedTokens parameter.</li><li>Non-contiguous dim0 and dim1 with stride greater than or equal to 1 are supported.</li></ul></td>
364 <td>Data type consistent with that of x</td>364 <td>Data type consistent with that of x</td>
365 <td>ND</td>365 <td>ND</td>
@@ -1190,7 +1190,7 @@ aclnnStatus aclnnFusedInferAttentionScoreV2(
1190 - keyAntiquantMode和valueAntiquantMode需要保持一致1190 - keyAntiquantMode和valueAntiquantMode需要保持一致
1191 - keyAntiquantScale和valueAntiquantScale要么都为空,要么都不为空;keyAntiquantOffset和valueAntiquantOffset要么都为空,要么都不为空1191 - keyAntiquantScale和valueAntiquantScale要么都为空,要么都不为空;keyAntiquantOffset和valueAntiquantOffset要么都为空,要么都不为空
1192 - KeyAntiquantScale和valueAntiquantScale都不为空时,其shape需要保持一致;keyAntiquantOffset和valueAntiquantOffset都不为空时,其shape需要保持一致1192 - KeyAntiquantScale和valueAntiquantScale都不为空时,其shape需要保持一致;keyAntiquantOffset和valueAntiquantOffset都不为空时,其shape需要保持一致
1193- - 仅支持per-token和per-channel模式,per-token模式下要求两个参数的shape均为\(B, S\),数据类型固定为FLOAT32;per-channel模式下要求两个参数的shape为(N, D\),(N, 1, D\)或(H\),数据类型固定为BF16。1193+ - 仅支持per-token和per-channel模式,per-token模式下要求两个参数的shape均为\(B, S\),数据类型固定为FLOAT32;per-channel模式下要求两个参数的shape为\(N, D\),\(N, 1, D\)或\(H\),数据类型固定为BF16。
1194 - 当伪量化参数和KV分离量化参数同时传入时,以KV分离量化参数为准。1194 - 当伪量化参数和KV分离量化参数同时传入时,以KV分离量化参数为准。
1195 - keyAntiquantScale与valueAntiquantScale非空场景,要求query的s小于等于16。1195 - keyAntiquantScale与valueAntiquantScale非空场景,要求query的s小于等于16。
1196 - keyAntiquantScale与valueAntiquantScale非空场景,要求query的dtype为BFLOAT16,key、value的dtype为INT8,输出的dtype为BFLOAT16。1196 - keyAntiquantScale与valueAntiquantScale非空场景,要求query的dtype为BFLOAT16,key、value的dtype为INT8,输出的dtype为BFLOAT16。
@@ -1669,7 +1669,7 @@ BFLOAT16和INT8不区分高精度和高性能,行无效修正对FLOAT16、BFLO
1669 <td>shape为五维时,各维度约束为:[blockNum, N, D/16, blockSize, 16]</td>1669 <td>shape为五维时,各维度约束为:[blockNum, N, D/16, blockSize, 16]</td>
1670 </tr>1670 </tr>
1671 <tr>1671 <tr>
1672- <td>attention</td>1672+ <td>attentionOut</td>
1673 <td>dtype与query一致</td>1673 <td>dtype与query一致</td>
1674 <td>-</td>1674 <td>-</td>
1675 </tr>1675 </tr>
@@ -1706,7 +1706,7 @@ BFLOAT16和INT8不区分高精度和高性能,行无效修正对FLOAT16、BFLO
1706 <td>shape为五维时,各维度约束为[blockNum, N, D/32, blockSize, 32]</td>1706 <td>shape为五维时,各维度约束为[blockNum, N, D/32, blockSize, 32]</td>
1707 </tr>1707 </tr>
1708 <tr>1708 <tr>
1709- <td>attention</td>1709+ <td>attentionOut</td>
1710 <td>BFLOAT16</td>1710 <td>BFLOAT16</td>
1711 <td>-</td>1711 <td>-</td>
1712 </tr>1712 </tr>
@@ -1727,12 +1727,12 @@ BFLOAT16和INT8不区分高精度和高性能,行无效修正对FLOAT16、BFLO
1727 </tr>1727 </tr>
1728 <tr>1728 <tr>
1729 <td>keyAntiquantScaleOptional</td>1729 <td>keyAntiquantScaleOptional</td>
1730- <td>FLOAT32;需与dequantScaleQueryOptional, valueAntiquantScaleOptional同时存在,不支持传入keyAntiquantOffsetOptional和valueAntiquantOffsetOptional;仅支持pertensor模式</td>1730+ <td>FLOAT32;需与dequantScaleQueryOptional, valueAntiquantScaleOptional同时存在,不支持传入keyAntiquantOffsetOptional和valueAntiquantOffsetOptional;仅支持per-tensor模式</td>
1731 <td>shape为(1)</td>1731 <td>shape为(1)</td>
1732 </tr>1732 </tr>
1733 <tr>1733 <tr>
1734 <td>valueAntiquantScaleOptional</td>1734 <td>valueAntiquantScaleOptional</td>
1735- <td>FLOAT32;需与dequantScaleQueryOptional, keyAntiquantScaleOptional同时存在,不支持传入keyAntiquantOffsetOptional和valueAntiquantOffsetOptional;仅支持pertensor模式</td>1735+ <td>FLOAT32;需与dequantScaleQueryOptional, keyAntiquantScaleOptional同时存在,不支持传入keyAntiquantOffsetOptional和valueAntiquantOffsetOptional;仅支持per-tensor模式</td>
1736 <td>shape为(1)</td>1736 <td>shape为(1)</td>
1737 </tr>1737 </tr>
1738 <tr>1738 <tr>
@@ -1668,7 +1668,7 @@ If the operator can determine that invalid rows exist, the invalid row calculati
1668 <td>When the shape is five-dimensional, the constraints on each dimension are <code>[blockNum, N, D/16, blockSize, 16]</code>.</td>1668 <td>When the shape is five-dimensional, the constraints on each dimension are <code>[blockNum, N, D/16, blockSize, 16]</code>.</td>
1669 </tr>1669 </tr>
1670 <tr>1670 <tr>
1671- <td>attention</td>1671+ <td>attentionOut</td>
1672 <td>The data type is the same as that of <code>query</code>.</td>1672 <td>The data type is the same as that of <code>query</code>.</td>
1673 <td>-</td>1673 <td>-</td>
1674 </tr>1674 </tr>
@@ -1705,7 +1705,7 @@ If the operator can determine that invalid rows exist, the invalid row calculati
1705 <td>When the shape is five-dimensional, the constraints on each dimension are <code>[blockNum, N, D/32, blockSize, 32]</code>.</td>1705 <td>When the shape is five-dimensional, the constraints on each dimension are <code>[blockNum, N, D/32, blockSize, 32]</code>.</td>
1706 </tr>1706 </tr>
1707 <tr>1707 <tr>
1708- <td>attention</td>1708+ <td>attentionOut</td>
1709 <td>BFLOAT16</td>1709 <td>BFLOAT16</td>
1710 <td>-</td>1710 <td>-</td>
1711 </tr>1711 </tr>
@@ -1726,12 +1726,12 @@ If the operator can determine that invalid rows exist, the invalid row calculati
1726 </tr>1726 </tr>
1727 <tr>1727 <tr>
1728 <td>keyAntiquantScaleOptional</td>1728 <td>keyAntiquantScaleOptional</td>
1729- <td>FLOAT32. This parameter must coexist with dequantScaleQueryOptional and valueAntiquantScaleOptional. keyAntiquantOffsetOptional and valueAntiquantOffsetOptional cannot be passed. Only the pertensor mode is supported.</td>1729+ <td>FLOAT32. This parameter must coexist with dequantScaleQueryOptional and valueAntiquantScaleOptional. keyAntiquantOffsetOptional and valueAntiquantOffsetOptional cannot be passed. Only the per-tensor mode is supported.</td>
1730 <td>shape is (1)</td>1730 <td>shape is (1)</td>
1731 </tr>1731 </tr>
1732 <tr>1732 <tr>
1733 <td>valueAntiquantScaleOptional</td>1733 <td>valueAntiquantScaleOptional</td>
1734- <td>FLOAT32. This parameter must coexist with dequantScaleQueryOptional and keyAntiquantScaleOptional. keyAntiquantOffsetOptional and valueAntiquantOffsetOptional cannot be passed. Only the pertensor mode is supported.</td>1734+ <td>FLOAT32. This parameter must coexist with dequantScaleQueryOptional and keyAntiquantScaleOptional. keyAntiquantOffsetOptional and valueAntiquantOffsetOptional cannot be passed. Only the per-tensor mode is supported.</td>
1735 <td>shape is (1)</td>1735 <td>shape is (1)</td>
1736 </tr>1736 </tr>
1737 <tr>1737 <tr>
@@ -466,7 +466,7 @@ aclnnStatus aclnnFusedInferAttentionScoreV5(
466 <li>使用时,shape必须与valueAntiquantScaleOptional保持一致。</li>466 <li>使用时,shape必须与valueAntiquantScaleOptional保持一致。</li>
467 <li>不使用该功能时可传入nullptr。</li>467 <li>不使用该功能时可传入nullptr。</li>
468 <li>部分场景支持非连续tensor,具体见<a href="#约束说明">约束说明</a>。</li>468 <li>部分场景支持非连续tensor,具体见<a href="#约束说明">约束说明</a>。</li>
469- <li>支持per-tensor,per-channel,per-token,per-tensor叠加per-head,per-token叠加per-head,per-token叠加使用page attention模式管理scale/offset、per-token叠加per head并使用page attention模式管理scale/offset。</li>469+ <li>支持per-tensor、per-channel、per-token、per-tensor叠加per-head、per-token叠加per-head、per-token叠加使用PagedAttention模式管理scale/offset、per-token叠加per-head并使用PagedAttention模式管理scale/offset。</li>
470 <li>综合约束请见<a href="#约束说明">约束说明</a>。</li>470 <li>综合约束请见<a href="#约束说明">约束说明</a>。</li>
471 </ul>471 </ul>
472 </td>472 </td>
@@ -775,7 +775,7 @@ aclnnStatus aclnnFusedInferAttentionScoreV5(
775 <tr>775 <tr>
776 <td>blockSize</td>776 <td>blockSize</td>
777 <td>输入</td>777 <td>输入</td>
778- <td>PageAttention中KV存储每个block中最大的token个数。</td>778+ <td>PagedAttention中KV存储每个block中最大的token个数。</td>
779 <td>不传时按照0处理。</td>779 <td>不传时按照0处理。</td>
780 <td>INT64</td>780 <td>INT64</td>
781 <td>-</td>781 <td>-</td>
@@ -450,7 +450,7 @@ aclnnStatus aclnnFusedInferAttentionScoreV5(
450 <li>When used, the shape must keep consistent with valueAntiquantScaleOptional.</li>450 <li>When used, the shape must keep consistent with valueAntiquantScaleOptional.</li>
451 <li>Pass in nullptr when this function is not used.</li>451 <li>Pass in nullptr when this function is not used.</li>
452 <li>Supports non-contiguous tensors in partial scenarios. For details, see <a href="#constraints">Constraints</a>.</li>452 <li>Supports non-contiguous tensors in partial scenarios. For details, see <a href="#constraints">Constraints</a>.</li>
453- <li>Supports per-tensor, per-channel, per-token, per-tensor stacked with per-head, per-token stacked with per-head, per-token stacked with page attention mode for scale/offset management, and per-token stacked with per-head and page attention mode for scale/offset management.</li>453+ <li>Supports per-tensor, per-channel, per-token, per-tensor stacked with per-head, per-token stacked with per-head, per-token stacked with PagedAttention mode for scale/offset management, and per-token stacked with per-head and PagedAttention mode for scale/offset management.</li>
454 <li>For comprehensive constraints, see <a href="#constraints">Constraints</a>.</li>454 <li>For comprehensive constraints, see <a href="#constraints">Constraints</a>.</li>
455 </ul>455 </ul>
456 </td>456 </td>
@@ -740,7 +740,7 @@ aclnnStatus aclnnFusedInferAttentionScoreV5(
740 <tr>740 <tr>
741 <td>blockSize</td>741 <td>blockSize</td>
742 <td>Input</td>742 <td>Input</td>
743- <td>Maximum number of tokens in each block of KV storage in PageAttention.</td>743+ <td>Maximum number of tokens in each block of KV storage in PagedAttention.</td>
744 <td>Processed as 0 if not passed in.</td>744 <td>Processed as 0 if not passed in.</td>
745 <td>INT64</td>745 <td>INT64</td>
746 <td>-</td>746 <td>-</td>
@@ -317,7 +317,7 @@ cann_ops_transformer.generic_block_sparse_attention(
317| | win_left | ATTR(OPTIONAL) | int |317| | win_left | ATTR(OPTIONAL) | int |
318| | win_right | ATTR(OPTIONAL) | int |318| | win_right | ATTR(OPTIONAL) | int |
319| | attn_mask | INPUT(OPTIONAL) | Tensor |319| | attn_mask | INPUT(OPTIONAL) | Tensor |
320-| SeqLens参数组 | cu_seqlens_q | INPUT(OPTIONAL) | Tensor |320+| SeqLengths参数组 | cu_seqlens_q | INPUT(OPTIONAL) | Tensor |
321| | cu_seqlens_kv | INPUT(OPTIONAL) | Tensor |321| | cu_seqlens_kv | INPUT(OPTIONAL) | Tensor |
322| | seqused_q | INPUT(OPTIONAL) | Tensor |322| | seqused_q | INPUT(OPTIONAL) | Tensor |
323| | seqused_kv | INPUT(OPTIONAL) | Tensor |323| | seqused_kv | INPUT(OPTIONAL) | Tensor |
@@ -255,7 +255,7 @@ cann_ops_transformer.generic_block_sparse_attention(
255| | win_left | ATTR(OPTIONAL) | int |255| | win_left | ATTR(OPTIONAL) | int |
256| | win_right | ATTR(OPTIONAL) | int |256| | win_right | ATTR(OPTIONAL) | int |
257| | attn_mask | INPUT(OPTIONAL) | Tensor |257| | attn_mask | INPUT(OPTIONAL) | Tensor |
258-| SeqLens Parameter Group | cu_seqlens_q | INPUT(OPTIONAL) | Tensor |258+| SeqLengths Parameter Group | cu_seqlens_q | INPUT(OPTIONAL) | Tensor |
259| | cu_seqlens_kv | INPUT(OPTIONAL) | Tensor |259| | cu_seqlens_kv | INPUT(OPTIONAL) | Tensor |
260| | seqused_q | INPUT(OPTIONAL) | Tensor |260| | seqused_q | INPUT(OPTIONAL) | Tensor |
261| | seqused_kv | INPUT(OPTIONAL) | Tensor |261| | seqused_kv | INPUT(OPTIONAL) | Tensor |
@@ -341,7 +341,7 @@ cann_ops_transformer.generic_block_sparse_attention_grad(
341| T1 | 输入q所有batch序列长度的累加和 |341| T1 | 输入q所有batch序列长度的累加和 |
342| T2 | 输入kv所有batch序列长度的累加和 |342| T2 | 输入kv所有batch序列长度的累加和 |
343| D | `layout_sparse_pattern=1`固定128;`layout_sparse_pattern=0`时`1<=D<=256` |343| D | `layout_sparse_pattern=1`固定128;`layout_sparse_pattern=0`时`1<=D<=256` |
344-| J | $\lceil max\_kv\_seqlen / blockShapeY \rceil$,KV块数 |344+| J | $\lceil max\_seqlen\_kv / blockShapeY \rceil$,KV块数 |
345| maxS1 | `layout_sparse_pattern=1`时为`sparse_block_idx`最后一维容量,须≥`max_seqlen_q` |345| maxS1 | `layout_sparse_pattern=1`时为`sparse_block_idx`最后一维容量,须≥`max_seqlen_q` |
346 346 
347### 参数组约束347### 参数组约束
@@ -312,7 +312,7 @@ In data constraints, common fields are defined as follows:
312| T1 | Cumulative sum of sequence lengths of all batches in input q. |312| T1 | Cumulative sum of sequence lengths of all batches in input q. |
313| T2 | Cumulative sum of sequence lengths of all batches in input kv. |313| T2 | Cumulative sum of sequence lengths of all batches in input kv. |
314| D | headdim, currently fixed to 128. |314| D | headdim, currently fixed to 128. |
315-| J | $\lceil max\_kv\_seqlen / blockShapeY \rceil$, number of KV blocks. |315+| J | $\lceil max\_seqlen\_kv / blockShapeY \rceil$, number of KV blocks. |
316| maxS1 | Capacity of the last dimension of `sparse_block_idx`, must be ≥ `max_seqlen_q`. |316| maxS1 | Capacity of the last dimension of `sparse_block_idx`, must be ≥ `max_seqlen_q`. |
317 317 
318### Parameter Group Constraints318### Parameter Group Constraints
@@ -581,7 +581,7 @@ int main()
581 int64_t headNum = 64;581 int64_t headNum = 64;
582 int64_t sparseMode = 3;582 int64_t sparseMode = 3;
583 char layoutStr[] = "BSND";583 char layoutStr[] = "BSND";
584- bool deteminstic = true;584+ bool deterministic = true;
585 int64_t preToken = 65536;585 int64_t preToken = 65536;
586 int64_t nextToken = 65536;586 int64_t nextToken = 65536;
587 587 
@@ -672,7 +672,7 @@ int main()
672 672 
673 // 调用aclnnLightningIndexerGrad第一段接口673 // 调用aclnnLightningIndexerGrad第一段接口
674 ret = aclnnLightningIndexerGradGetWorkspaceSize(q, k, dy, sparseIndices, weights, nullptr, nullptr, headNum,674 ret = aclnnLightningIndexerGradGetWorkspaceSize(q, k, dy, sparseIndices, weights, nullptr, nullptr, headNum,
675- layoutStr, sparseMode, preToken, nextToken, deteminstic, dQuery,675+ layoutStr, sparseMode, preToken, nextToken, deterministic, dQuery,
676 dKey, dWeights, &workspaceSize, &executor);676 dKey, dWeights, &workspaceSize, &executor);
677 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnLightningIndexerGradGetWorkspaceSize failed. ERROR: %d\n", ret);677 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnLightningIndexerGradGetWorkspaceSize failed. ERROR: %d\n", ret);
678 FreeResource(q, k, dy, sparseIndices, weights, dQuery, dKey, dWeights, qDeviceAddr, kDeviceAddr,678 FreeResource(q, k, dy, sparseIndices, weights, dQuery, dKey, dWeights, qDeviceAddr, kDeviceAddr,
@@ -583,7 +583,7 @@ int main()
583 int64_t headNum = 64;583 int64_t headNum = 64;
584 int64_t sparseMode = 3;584 int64_t sparseMode = 3;
585 char layoutStr[] = "BSND";585 char layoutStr[] = "BSND";
586- bool deteminstic = true;586+ bool deterministic = true;
587 int64_t preToken = 65536;587 int64_t preToken = 65536;
588 int64_t nextToken = 65536;588 int64_t nextToken = 65536;
589 589 
@@ -674,7 +674,7 @@ int main()
674 674 
675 // Call the first-phase API of aclnnLightningIndexerGrad.675 // Call the first-phase API of aclnnLightningIndexerGrad.
676 ret = aclnnLightningIndexerGradGetWorkspaceSize(q, k, dy, sparseIndices, weights, nullptr, nullptr, headNum,676 ret = aclnnLightningIndexerGradGetWorkspaceSize(q, k, dy, sparseIndices, weights, nullptr, nullptr, headNum,
677- layoutStr, sparseMode, preToken, nextToken, deteminstic, dQuery,677+ layoutStr, sparseMode, preToken, nextToken, deterministic, dQuery,
678 dKey, dWeights, &workspaceSize, &executor);678 dKey, dWeights, &workspaceSize, &executor);
679 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnLightningIndexerGradGetWorkspaceSize failed. ERROR: %d\n", ret);679 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnLightningIndexerGradGetWorkspaceSize failed. ERROR: %d\n", ret);
680 FreeResource(q, k, dy, sparseIndices, weights, dQuery, dKey, dWeights, qDeviceAddr, kDeviceAddr,680 FreeResource(q, k, dy, sparseIndices, weights, dQuery, dKey, dWeights, qDeviceAddr, kDeviceAddr,
@@ -135,7 +135,7 @@ cann_ops_transformer.lightning_indexer(
135| seqused_q | Tensor | 可选 | 不同batch中q的真实使用长度。数据格式为ND。 shape为(b,)。 | int32 | 1 |135| seqused_q | Tensor | 可选 | 不同batch中q的真实使用长度。数据格式为ND。 shape为(b,)。 | int32 | 1 |
136| seqused_k | Tensor | 可选 | 不同batch中k的真实使用长度。数据格式为ND。 shape为(b,)。 | int32 | 1 |136| seqused_k | Tensor | 可选 | 不同batch中k的真实使用长度。数据格式为ND。 shape为(b,)。 | int32 | 1 |
137| cmp_residual_k | Tensor | 可选 | 表示k压缩前token数量除以cmp_ratio的余数。需要在mask_mode等于3、cmp_ratio不等于1的场景下使用。数据格式为ND。 shape为(b,)。 | int32 | 1 |137| cmp_residual_k | Tensor | 可选 | 表示k压缩前token数量除以cmp_ratio的余数。需要在mask_mode等于3、cmp_ratio不等于1的场景下使用。数据格式为ND。 shape为(b,)。 | int32 | 1 |
138-| block_table | Tensor | 可选 | 表示PageAttention中KV存储使用的block映射表。不支持空tensor。数据格式为ND。 shape为(b, k_s_max/block_size)。 | int32 | 2 |138+| block_table | Tensor | 可选 | 表示PagedAttention中KV存储使用的block映射表。不支持空tensor。数据格式为ND。 shape为(b, k_s_max/block_size)。 | int32 | 2 |
139| output_idx_offset | Tensor | 可选 | 表示topK结果输出索引所需要加上的偏移。值必须大于等于0,加上偏移后topK index不能超过int32最大值。数据格式为ND。 支持的shape为:layout_q为BSND时shape为(b,q_s,k_n);layout_q为TND时shape为(q_t,k_n)。 | int32 | 2-3 |139| output_idx_offset | Tensor | 可选 | 表示topK结果输出索引所需要加上的偏移。值必须大于等于0,加上偏移后topK index不能超过int32最大值。数据格式为ND。 支持的shape为:layout_q为BSND时shape为(b,q_s,k_n);layout_q为TND时shape为(q_t,k_n)。 | int32 | 2-3 |
140| metadata | Tensor | 可选 | 由lightning_indexer_metadata得到的分核信息,包含使用核数、分块大小以及每个核处理数据的起始点等内容。不支持空tensor。数据格式为ND。 shape为(2048,)。 | int32 | 1 |140| metadata | Tensor | 可选 | 由lightning_indexer_metadata得到的分核信息,包含使用核数、分块大小以及每个核处理数据的起始点等内容。不支持空tensor。数据格式为ND。 shape为(2048,)。 | int32 | 1 |
141| max_seqlen_q | int | 可选 | q的最大序列长度。-1表示任意可能长度,默认值为-1。 | int64 | - |141| max_seqlen_q | int | 可选 | q的最大序列长度。-1表示任意可能长度,默认值为-1。 | int64 | - |
@@ -131,7 +131,7 @@ cann_ops_transformer.lightning_indexer(
131| seqused_q | Tensor | Optional | Actual used length of q in different batches. Data format: ND. | int32 | (b,) |131| seqused_q | Tensor | Optional | Actual used length of q in different batches. Data format: ND. | int32 | (b,) |
132| seqused_k | Tensor | Optional | Actual used length of k in different batches. Data format: ND. | int32 | (b,) |132| seqused_k | Tensor | Optional | Actual used length of k in different batches. Data format: ND. | int32 | (b,) |
133| cmp_residual_k | Tensor | Optional | Remainder of dividing the number of k tokens before compression by cmp_ratio. Required when mask_mode is 3 and cmp_ratio is not 1. Data format: ND. | int32 | (b,) |133| cmp_residual_k | Tensor | Optional | Remainder of dividing the number of k tokens before compression by cmp_ratio. Required when mask_mode is 3 and cmp_ratio is not 1. Data format: ND. | int32 | (b,) |
134-| block_table | Tensor | Optional | Block mapping table used for KV storage in PageAttention. Empty tensors are not supported. Data format: ND. | int32 | (b, k_s_max/block_size) |134+| block_table | Tensor | Optional | Block mapping table used for KV storage in PagedAttention. Empty tensors are not supported. Data format: ND. | int32 | (b, k_s_max/block_size) |
135| output_idx_offset | Tensor | Optional | Offset to add to the output indices of the topK result. The value must be greater than or equal to 0, and the topK index plus the offset must not exceed the maximum value of int32. Data format: ND. | int32 | (b,q_s,k_n) when layout_q is BSND; (q_t,k_n) when layout_q is TND |135| output_idx_offset | Tensor | Optional | Offset to add to the output indices of the topK result. The value must be greater than or equal to 0, and the topK index plus the offset must not exceed the maximum value of int32. Data format: ND. | int32 | (b,q_s,k_n) when layout_q is BSND; (q_t,k_n) when layout_q is TND |
136| metadata | Tensor | Optional | Core splitting information obtained from lightning_indexer_metadata, including the number of used cores, block size, and the start point of the data processed by each core. Empty tensors are not supported. Data format: ND. | int32 | (1024,) |136| metadata | Tensor | Optional | Core splitting information obtained from lightning_indexer_metadata, including the number of used cores, block size, and the start point of the data processed by each core. Empty tensors are not supported. Data format: ND. | int32 | (1024,) |
137| max_seqlen_q | int | Optional | Maximum sequence length of q. -1 indicates any possible length. Default value: -1. | int64 | - |137| max_seqlen_q | int | Optional | Maximum sequence length of q. -1 indicates any possible length. Default value: -1. | int64 | - |
@@ -268,7 +268,7 @@ aclnnStatus aclnnMixedQuantSparseFlashMla(
268 <tr>268 <tr>
269 <td>oriBlockTableOptional(aclTensor*)</td>269 <td>oriBlockTableOptional(aclTensor*)</td>
270 <td>输入</td>270 <td>输入</td>
271- <td>PageAttention中oriKvCache存储使用的block映射表。</td>271+ <td>PagedAttention中oriKvCache存储使用的block映射表。</td>
272 <td>layoutKvOptional为PA_BBND时必须传入。第二维长度不小于所有batch中最大的S2对应的block数量。</td>272 <td>layoutKvOptional为PA_BBND时必须传入。第二维长度不小于所有batch中最大的S2对应的block数量。</td>
273 <td>INT32</td>273 <td>INT32</td>
274 <td>ND</td>274 <td>ND</td>
@@ -278,7 +278,7 @@ aclnnStatus aclnnMixedQuantSparseFlashMla(
278 <tr>278 <tr>
279 <td>cmpBlockTableOptional(aclTensor*)</td>279 <td>cmpBlockTableOptional(aclTensor*)</td>
280 <td>输入</td>280 <td>输入</td>
281- <td>PageAttention中cmpKvCache存储使用的block映射表。</td>281+ <td>PagedAttention中cmpKvCache存储使用的block映射表。</td>
282 <td>cmpKvOptional传入且layoutKvOptional为PA_BBND时必须传入。</td>282 <td>cmpKvOptional传入且layoutKvOptional为PA_BBND时必须传入。</td>
283 <td>INT32</td>283 <td>INT32</td>
284 <td>ND</td>284 <td>ND</td>
@@ -253,7 +253,7 @@ aclnnStatus aclnnMixedQuantSparseFlashMla(
253 <tr>253 <tr>
254 <td>oriBlockTableOptional (aclTensor*)</td>254 <td>oriBlockTableOptional (aclTensor*)</td>
255 <td>Input</td>255 <td>Input</td>
256- <td>Block mapping table used for oriKvCache storage in PageAttention.</td>256+ <td>Block mapping table used for oriKvCache storage in PagedAttention.</td>
257 <td>Must be passed in when layoutKv is PA_BBND. The length of the second dimension must be greater than or equal to the number of blocks corresponding to the maximum S2 among all batches.</td>257 <td>Must be passed in when layoutKv is PA_BBND. The length of the second dimension must be greater than or equal to the number of blocks corresponding to the maximum S2 among all batches.</td>
258 <td>INT32</td>258 <td>INT32</td>
259 <td>ND</td>259 <td>ND</td>
@@ -263,7 +263,7 @@ aclnnStatus aclnnMixedQuantSparseFlashMla(
263 <tr>263 <tr>
264 <td>cmpBlockTableOptional (aclTensor*)</td>264 <td>cmpBlockTableOptional (aclTensor*)</td>
265 <td>Input</td>265 <td>Input</td>
266- <td>Block mapping table used for cmpKvCache storage in PageAttention.</td>266+ <td>Block mapping table used for cmpKvCache storage in PagedAttention.</td>
267 <td>Must be passed in when cmpKv is passed and layoutKv is PA_BBND.</td>267 <td>Must be passed in when cmpKv is passed and layoutKv is PA_BBND.</td>
268 <td>INT32</td>268 <td>INT32</td>
269 <td>ND</td>269 <td>ND</td>
@@ -205,8 +205,8 @@ cann_ops_transformer.mixed_quant_sparse_flash_mla(
205| cmp_kv | tensor | 可选 | 压缩KV。quant_mode=1/2时使用fp8_e4m3;quant_mode=3时必须传入uint8 TQ4数据、kv_d=258。 | fp8_e4m3、uint8 | ND | <ul><li>(b, cmp_kv_s, kv_n, kv_d)</li><li>(cmp_kv_t, kv_n, kv_d)</li><li>(cmp_kv_block_nums, cmp_kv_block_size, kv_n, kv_d)</li></ul>205| cmp_kv | tensor | 可选 | 压缩KV。quant_mode=1/2时使用fp8_e4m3;quant_mode=3时必须传入uint8 TQ4数据、kv_d=258。 | fp8_e4m3、uint8 | ND | <ul><li>(b, cmp_kv_s, kv_n, kv_d)</li><li>(cmp_kv_t, kv_n, kv_d)</li><li>(cmp_kv_block_nums, cmp_kv_block_size, kv_n, kv_d)</li></ul>
206| ori_sparse_indices | tensor | 可选 | 表示原始KV topK索引,无效位置填-1 | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>206| ori_sparse_indices | tensor | 可选 | 表示原始KV topK索引,无效位置填-1 | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>
207| cmp_sparse_indices | tensor | 可选 | 表示压缩KV topK索引,无效位置填-1;quant_mode=3时必须传入且cmp_kv_k仅支持512或1024。 | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>207| cmp_sparse_indices | tensor | 可选 | 表示压缩KV topK索引,无效位置填-1;quant_mode=3时必须传入且cmp_kv_k仅支持512或1024。 | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>
208-| ori_block_table | tensor | 可选 | 表示PageAttention场景下ori_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>208+| ori_block_table | tensor | 可选 | 表示PagedAttention场景下ori_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>
209-| cmp_block_table | tensor | 可选 | 表示PageAttention场景下cmp_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>209+| cmp_block_table | tensor | 可选 | 表示PagedAttention场景下cmp_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>
210| cu_seqlens_q | tensor | 可选 | 表示处理输入q变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>210| cu_seqlens_q | tensor | 可选 | 表示处理输入q变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>
211| cu_seqlens_ori_kv | tensor | 可选 | 表示处理输入ori_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>211| cu_seqlens_ori_kv | tensor | 可选 | 表示处理输入ori_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>
212| cu_seqlens_cmp_kv | tensor | 可选 | 表示处理输入cmp_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>212| cu_seqlens_cmp_kv | tensor | 可选 | 表示处理输入cmp_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>
@@ -193,8 +193,8 @@ cann_ops_transformer.mixed_quant_sparse_flash_mla(
193| cmp_kv | tensor | Optional | Represents the compressed quantized KV input. Key and Value share the same data. | fp8_e4m3 | ND | <ul><li>(b, cmp_kv_s, kv_n, kv_d)</li><li>(cmp_kv_t, kv_n, kv_d)</li><li>(cmp_kv_block_nums, cmp_kv_block_size, kv_n, kv_d)</li></ul>193| cmp_kv | tensor | Optional | Represents the compressed quantized KV input. Key and Value share the same data. | fp8_e4m3 | ND | <ul><li>(b, cmp_kv_s, kv_n, kv_d)</li><li>(cmp_kv_t, kv_n, kv_d)</li><li>(cmp_kv_block_nums, cmp_kv_block_size, kv_n, kv_d)</li></ul>
194| ori_sparse_indices | tensor | Optional | Represents the topK indices of the original KV. -1 is filled at invalid positions. | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>194| ori_sparse_indices | tensor | Optional | Represents the topK indices of the original KV. -1 is filled at invalid positions. | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>
195| cmp_sparse_indices | tensor | Optional | Represents the topK indices of the compressed KV. -1 is filled at invalid positions. | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>195| cmp_sparse_indices | tensor | Optional | Represents the topK indices of the compressed KV. -1 is filled at invalid positions. | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>
196-| ori_block_table | tensor | Optional | Represents the block mapping table used by ori_kv in the PageAttention use case. | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>196+| ori_block_table | tensor | Optional | Represents the block mapping table used by ori_kv in the PagedAttention use case. | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>
197-| cmp_block_table | tensor | Optional | Represents the block mapping table used by cmp_kv in the PageAttention use case. | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>197+| cmp_block_table | tensor | Optional | Represents the block mapping table used by cmp_kv in the PagedAttention use case. | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>
198| cu_seqlens_q | tensor | Optional | Represents the cumulative sequence lengths for processing the variable-length sequences of input q. | int32 | ND | <ul><li>(b+1,)</li></ul>198| cu_seqlens_q | tensor | Optional | Represents the cumulative sequence lengths for processing the variable-length sequences of input q. | int32 | ND | <ul><li>(b+1,)</li></ul>
199| cu_seqlens_ori_kv | tensor | Optional | Represents the cumulative sequence lengths for processing the variable-length sequences of input ori_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>199| cu_seqlens_ori_kv | tensor | Optional | Represents the cumulative sequence lengths for processing the variable-length sequences of input ori_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>
200| cu_seqlens_cmp_kv | tensor | Optional | Represents the cumulative sequence lengths for processing the variable-length sequences of input cmp_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>200| cu_seqlens_cmp_kv | tensor | Optional | Represents the cumulative sequence lengths for processing the variable-length sequences of input cmp_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>
@@ -25,15 +25,15 @@
25 25 
26- **功能更新**:(相对于aclnnMlaPrologV2weightNz的差异)26- **功能更新**:(相对于aclnnMlaPrologV2weightNz的差异)
27 - 新增Query与Key的尺度矫正因子,分别对应qcQrScale($\alpha_q$)与kcScale($\alpha_{kv}$)。27 - 新增Query与Key的尺度矫正因子,分别对应qcQrScale($\alpha_q$)与kcScale($\alpha_{kv}$)。
28- - 新增可选输入参数(例如actualSeqLenOptional、kNopeClipAlphaOptional、queryNormFlag、weightQuantMode、kvCacheQuantMode、queryQuantMode、ckvkrRepoMode、quantScaleRepoMode、tileSize、queryNormOutOptional和dequantScaleQNormOptional等),将cache_mode由必选改为可选。28+ - 新增参数(例如actualSeqLenOptional、kNopeClipAlphaOptional、weightQuantMode、kvCacheQuantMode、queryQuantMode、ckvkrRepoMode、quantScaleRepoMode和tileSize等),新增可选输出queryNormOutOptional和dequantScaleQNormOutOptional。
29 - 调整cacheIndex参数的名称与位置,对应当前的cacheIndexOptional。29 - 调整cacheIndex参数的名称与位置,对应当前的cacheIndexOptional。
30- **接口功能**:推理场景,Multi-Head Latent Attention前处理的计算。主要计算过程分为七路:30- **接口功能**:推理场景,Multi-Head Latent Attention前处理的计算。主要计算过程分为七路:
31 - 首先对输入$x$乘以$W^{DQ}$进行下采样和RmsNorm后分为两路,第一路乘以$W^{UQ}$和$W^{UK}$经过两次上采样后,再乘以Query尺度矫正因子$\alpha_q$得到$q^N$;第二路乘以$W^{QR}$后经过旋转位置编码(ROPE)得到$q^R$。31 - 首先对输入$x$乘以$W^{DQ}$进行下采样和RmsNorm后分为两路,第一路乘以$W^{UQ}$和$W^{UK}$经过两次上采样后,再乘以Query尺度矫正因子$\alpha_q$得到$q^N$;第二路乘以$W^{QR}$后经过旋转位置编码(ROPE)得到$q^R$。
32 - 第三路是输入$x$乘以$W^{DKV}$进行下采样和RmsNorm后,乘以Key尺度矫正因子$\alpha_{kv}$传入Cache中得到$k^C$;32 - 第三路是输入$x$乘以$W^{DKV}$进行下采样和RmsNorm后,乘以Key尺度矫正因子$\alpha_{kv}$传入Cache中得到$k^C$;
33 - 第四路是输入$x$乘以$W^{KR}$后经过旋转位置编码传入另一个Cache中得到$k^R$;33 - 第四路是输入$x$乘以$W^{KR}$后经过旋转位置编码传入另一个Cache中得到$k^R$;
34 - 第五路是输出$q^N$经过DynamicQuant后得到的量化参数。34 - 第五路是输出$q^N$经过DynamicQuant后得到的量化参数。
35- - 第六路是queryNormFlag=true时,输入$x$乘以$W^{DQ}$进行下采样和RmsNorm后得到压缩结果$c^Q$,作为queryNormOutOptional输出。35+ - 第六路是queryNormOutOptional非空且非量化场景(weightQuantMode=0)下,输入$x$乘以$W^{DQ}$进行下采样和RmsNorm后得到压缩结果$c^Q$,作为queryNormOutOptional输出。
36- - 第七路是queryNormFlag=true且量化场景(weightQuantMode≠0)下,对$c^Q$做DynamicQuant,最终得到量化后的queryNormOutOptional和对应量化参数dequantScaleQNormOutOptional。36+ - 第七路是queryNormOutOptional非空且量化场景(weightQuantMode≠0)下,对$c^Q$做DynamicQuant,最终得到量化后的queryNormOutOptional和对应量化参数dequantScaleQNormOutOptional。
37 - 权重参数WeightDq、WeightUqQr和WeightDkvKr需要以NZ格式传入。37 - 权重参数WeightDq、WeightUqQr和WeightDkvKr需要以NZ格式传入。
38 38 
39- **计算公式**:39- **计算公式**:
@@ -96,7 +96,7 @@
96 q^{N} = {\mathrm{round}(q^{N} / \mathrm{dequantScaleQNope})}96 q^{N} = {\mathrm{round}(q^{N} / \mathrm{dequantScaleQNope})}
97 $$97 $$
98 98 
99- Query Norm及Dequant Scale Query Norm计算公式(queryNormFlag=true时输出)99+ Query Norm及Dequant Scale Query Norm计算公式(queryNormOutOptional非空时输出)
100 100 
101 非量化场景(weightQuantMode=0):101 非量化场景(weightQuantMode=0):
102 102 
@@ -565,16 +565,6 @@ aclnnStatus aclnnMlaPrologV3WeightNz(
565 <td>-</td>565 <td>-</td>
566 <td>-</td>566 <td>-</td>
567 </tr>567 </tr>
568- <tr>
569- <td>queryNormFlag</td>
570- <td>输入</td>
571- <td>表示是否输出queryNormOutOptional、dequantScaleQNormOutOptional。</td>
572- <td>false表示不输出,true表示输出,默认值为false</td>
573- <td>BOOL</td>
574- <td>-</td>
575- <td>-</td>
576- <td>-</td>
577- </tr>
578 <tr>568 <tr>
579 <td>weightQuantMode</td>569 <td>weightQuantMode</td>
580 <td>输入</td>570 <td>输入</td>
@@ -714,7 +704,7 @@ aclnnStatus aclnnMlaPrologV3WeightNz(
714 <td>queryNormOutOptional</td>704 <td>queryNormOutOptional</td>
715 <td>输出</td>705 <td>输出</td>
716 <td>公式中tokenX做rmsNorm后的输出tensor(对应<i>c<sup><i>Q</i></sup></i>)。</td>706 <td>公式中tokenX做rmsNorm后的输出tensor(对应<i>c<sup><i>Q</i></sup></i>)。</td>
717- <td>queryNormFlag=true时输出</td>707+ <td>可选输出,不需要时传入nullptr。</td>
718 <td>BFLOAT16、INT8、FLOAT8_E4M3FN、HIFLOAT8</td>708 <td>BFLOAT16、INT8、FLOAT8_E4M3FN、HIFLOAT8</td>
719 <td>ND</td>709 <td>ND</td>
720 <td>710 <td>
@@ -729,7 +719,7 @@ aclnnStatus aclnnMlaPrologV3WeightNz(
729 <td>dequantScaleQNormOutOptional</td>719 <td>dequantScaleQNormOutOptional</td>
730 <td>输出</td>720 <td>输出</td>
731 <td>queryNormOutOptional的反量化参数。</td>721 <td>queryNormOutOptional的反量化参数。</td>
732- <td>queryNormFlag=true,weightQuantMode=1/2/3/4/5时输出,weightQuantMode=0时为nullptr</td>722+ <td>queryNormOutOptional非空且weightQuantMode不为0时必须传入,其他场景必须为nullptr。</td>
733 <td>FLOAT、FLOAT8_E8M0</td>723 <td>FLOAT、FLOAT8_E8M0</td>
734 <td>ND</td>724 <td>ND</td>
735 <td>725 <td>
@@ -18,15 +18,15 @@
18 18 
19- **Function updates**: (differences from aclnnMlaPrologV2weightNz)19- **Function updates**: (differences from aclnnMlaPrologV2weightNz)
20 - Added scale correction factors for Query and Key, corresponding to qcQrScale ($\alpha_q$) and kcScale ($\alpha_{kv}$), respectively.20 - Added scale correction factors for Query and Key, corresponding to qcQrScale ($\alpha_q$) and kcScale ($\alpha_{kv}$), respectively.
21- - Added optional input parameters (for example, actualSeqLenOptional, kNopeClipAlphaOptional, queryNormFlag, weightQuantMode, kvCacheQuantMode, queryQuantMode, ckvkrRepoMode, quantScaleRepoMode, tileSize, queryNormOutOptional, and dequantScaleQNormOptional). Changed cache_mode from mandatory to optional.21+ - Added parameters such as actualSeqLenOptional, kNopeClipAlphaOptional, weightQuantMode, kvCacheQuantMode, queryQuantMode, ckvkrRepoMode, quantScaleRepoMode, and tileSize, as well as optional outputs queryNormOutOptional and dequantScaleQNormOutOptional.
22 - Adjusted the name and position of the cacheIndex parameter, corresponding to the current cacheIndexOptional.22 - Adjusted the name and position of the cacheIndex parameter, corresponding to the current cacheIndexOptional.
23- **Description**: Inference use case. Computes the preprocessing of Multi-Head Latent Attention. The main computation process consists of seven branches:23- **Description**: Inference use case. Computes the preprocessing of Multi-Head Latent Attention. The main computation process consists of seven branches:
24 - First, the input $x$ is multiplied by $W^{DQ}$, downsampled, and normalized with RmsNorm. The result is then split into two branches. In the first branch, it is multiplied by $W^{UQ}$ and $W^{UK}$, upsampled twice, and then multiplied by the Query scale correction factor $\alpha_q$ to obtain $q^N$. In the second branch, it is multiplied by $W^{QR}$ and then goes through rotary position encoding (ROPE) to obtain $q^R$.24 - First, the input $x$ is multiplied by $W^{DQ}$, downsampled, and normalized with RmsNorm. The result is then split into two branches. In the first branch, it is multiplied by $W^{UQ}$ and $W^{UK}$, upsampled twice, and then multiplied by the Query scale correction factor $\alpha_q$ to obtain $q^N$. In the second branch, it is multiplied by $W^{QR}$ and then goes through rotary position encoding (ROPE) to obtain $q^R$.
25 - The third branch: the input $x$ is multiplied by $W^{DKV}$, downsampled, and normalized with RmsNorm. The result is then multiplied by the Key scale correction factor $\alpha_{kv}$ and written into the Cache to obtain $k^C$.25 - The third branch: the input $x$ is multiplied by $W^{DKV}$, downsampled, and normalized with RmsNorm. The result is then multiplied by the Key scale correction factor $\alpha_{kv}$ and written into the Cache to obtain $k^C$.
26 - The fourth path: the input $x$ is multiplied by $W^{KR}$, then undergoes rotary position encoding and is passed into another Cache to obtain $k^R$;26 - The fourth path: the input $x$ is multiplied by $W^{KR}$, then undergoes rotary position encoding and is passed into another Cache to obtain $k^R$;
27 - The fifth path: the quantization parameter obtained after the output $q^N$ undergoes DynamicQuant.27 - The fifth path: the quantization parameter obtained after the output $q^N$ undergoes DynamicQuant.
28- - The sixth branch: when queryNormFlag=true, the input $x$ is multiplied by $W^{DQ}$, downsampled, and normalized with RmsNorm to obtain the compressed result $c^Q$, which is output as queryNormOutOptional.28+ - The sixth branch: when queryNormOutOptional is non-null and weightQuantMode is 0, the input $x$ is multiplied by $W^{DQ}$, downsampled, and normalized with RmsNorm to obtain the compressed result $c^Q$, which is output as queryNormOutOptional.
29- - The seventh branch: when queryNormFlag=true and in the quantization scenario (weightQuantMode≠0), DynamicQuant is performed on $c^Q$ to obtain the quantized queryNormOutOptional and the corresponding quantization parameter dequantScaleQNormOutOptional.29+ - The seventh branch: when queryNormOutOptional is non-null and in the quantization scenario (weightQuantMode≠0), DynamicQuant is performed on $c^Q$ to obtain the quantized queryNormOutOptional and the corresponding quantization parameter dequantScaleQNormOutOptional.
30 - The weight parameters WeightDq, WeightUqQr, and WeightDkvKr must be passed in NZ format.30 - The weight parameters WeightDq, WeightUqQr, and WeightDkvKr must be passed in NZ format.
31 31 
32- **Formula**:32- **Formula**:
@@ -89,7 +89,7 @@
89 q^{N} = {\mathrm{round}(q^{N} / \mathrm{dequantScaleQNope})}89 q^{N} = {\mathrm{round}(q^{N} / \mathrm{dequantScaleQNope})}
90 $$90 $$
91 91 
92- Query Norm and Dequant Scale Query Norm Formula (output when queryNormFlag=true)92+ Query Norm and Dequant Scale Query Norm Formula (output when queryNormOutOptional is non-null)
93 93 
94 Non-quantized field (weightQuantMode=0):94 Non-quantized field (weightQuantMode=0):
95 95 
@@ -541,16 +541,6 @@ aclnnStatus aclnnMlaPrologV3WeightNz(
541 <td>-</td>541 <td>-</td>
542 <td>-</td>542 <td>-</td>
543 </tr>543 </tr>
544- <tr>
545- <td>queryNormFlag</td>
546- <td>Input</td>
547- <td>Indicates whether to output queryNormOutOptional and dequantScaleQNormOutOptional.</td>
548- <td>false indicates no output, true indicates output, default value is false</td>
549- <td>BOOL</td>
550- <td>-</td>
551- <td>-</td>
552- <td>-</td>
553- </tr>
554 <tr>544 <tr>
555 <td>weightQuantMode</td>545 <td>weightQuantMode</td>
556 <td>Input</td>546 <td>Input</td>
@@ -686,7 +676,7 @@ aclnnStatus aclnnMlaPrologV3WeightNz(
686 <td>queryNormOutOptional</td>676 <td>queryNormOutOptional</td>
687 <td>Output</td>677 <td>Output</td>
688 <td>Output tensor of tokenX after rmsNorm in the formula (corresponding to <i>c<sup><i>Q</i></sup></i>).</td>678 <td>Output tensor of tokenX after rmsNorm in the formula (corresponding to <i>c<sup><i>Q</i></sup></i>).</td>
689- <td>Output when queryNormFlag=true</td>679+ <td>Optional output. Pass nullptr when this output is not needed.</td>
690 <td>BFLOAT16, INT8, FLOAT8_E4M3FN, HIFLOAT8</td>680 <td>BFLOAT16, INT8, FLOAT8_E4M3FN, HIFLOAT8</td>
691 <td>ND</td>681 <td>ND</td>
692 <td> <ul>682 <td> <ul>
@@ -700,7 +690,7 @@ aclnnStatus aclnnMlaPrologV3WeightNz(
700 <td>dequantScaleQNormOutOptional</td>690 <td>dequantScaleQNormOutOptional</td>
701 <td>Output</td>691 <td>Output</td>
702 <td>Dequantization parameter of queryNormOutOptional.</td>692 <td>Dequantization parameter of queryNormOutOptional.</td>
703- <td>Output when queryNormFlag=true and weightQuantMode=1/2/3/4/5; nullptr when weightQuantMode=0</td>693+ <td>Required when queryNormOutOptional is non-null and weightQuantMode is nonzero; must be nullptr otherwise.</td>
704 <td>FLOAT, FLOAT8_E8M0</td>694 <td>FLOAT, FLOAT8_E8M0</td>
705 <td>ND</td>695 <td>ND</td>
706 <td> <ul>696 <td> <ul>
@@ -117,7 +117,7 @@
117 117 
118 此时queryNorm为BFLOAT16类型,dequantScaleQNorm不输出(为nullptr)。118 此时queryNorm为BFLOAT16类型,dequantScaleQNorm不输出(为nullptr)。
119 119 
120- 量化场景(weightQuantMode=1/2/4/5,per-token动态量化),smoothScaleCq可选传入,未传入时视为1:120+ 量化场景(weightQuantMode=1/2/4/5,per-token动态量化),smoothScalesCq可选传入,未传入时视为1:
121 121 
122 $$122 $$
123 \tilde{c}^Q = c^Q \cdot smoothScale123 \tilde{c}^Q = c^Q \cdot smoothScale
@@ -119,7 +119,7 @@
119 119 
120 In this case, queryNorm is of the BFLOAT16 type, and dequantScaleQNorm is not output (nullptr).120 In this case, queryNorm is of the BFLOAT16 type, and dequantScaleQNorm is not output (nullptr).
121 121 
122- Quantization scenario (weightQuantMode=1/2/4/5, per-token dynamic quantization). smoothScaleCq is optional. If not passed in, it is treated as 1:122+ Quantization scenario (weightQuantMode=1/2/4/5, per-token dynamic quantization). smoothScalesCq is optional. If not passed in, it is treated as 1:
123 123 
124 $$124 $$
125 \tilde{c}^Q = c^Q \cdot smoothScale125 \tilde{c}^Q = c^Q \cdot smoothScale
@@ -571,7 +571,7 @@ int main()
571 int64_t headNum = 16;571 int64_t headNum = 16;
572 int64_t selectedBlockSize = 64;572 int64_t selectedBlockSize = 64;
573 int64_t selectedBlockCount = 16;573 int64_t selectedBlockCount = 16;
574- int64_t sparseMod = 2;574+ int64_t sparseMode = 2;
575 char layOut[] = "TND";575 char layOut[] = "TND";
576 576 
577 void *qDeviceAddr = nullptr;577 void *qDeviceAddr = nullptr;
@@ -660,7 +660,7 @@ int main()
660 // 调用aclnnNsaSelectedAttention第一段接口660 // 调用aclnnNsaSelectedAttention第一段接口
661 ret = aclnnNsaSelectedAttentionGetWorkspaceSize(661 ret = aclnnNsaSelectedAttentionGetWorkspaceSize(
662 q, k, v, topKIndices, attenMaskOptional, actualSeqQLenOptional, actualSeqKvLenOptional, scaleValue, headNum,662 q, k, v, topKIndices, attenMaskOptional, actualSeqQLenOptional, actualSeqKvLenOptional, scaleValue, headNum,
663- layOut, sparseMod, selectedBlockSize, selectedBlockCount, softmaxMax, softmaxSum, attentionOut, &workspaceSize, &executor);663+ layOut, sparseMode, selectedBlockSize, selectedBlockCount, softmaxMax, softmaxSum, attentionOut, &workspaceSize, &executor);
664 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNsaSelectedAttentionGetWorkspaceSize failed. ERROR: %d\n", ret);664 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNsaSelectedAttentionGetWorkspaceSize failed. ERROR: %d\n", ret);
665 FreeResource(q, k, v, attentionOut, softmaxMax, softmaxSum, qDeviceAddr, kDeviceAddr, vDeviceAddr,665 FreeResource(q, k, v, attentionOut, softmaxMax, softmaxSum, qDeviceAddr, kDeviceAddr, vDeviceAddr,
666 attentionOutDeviceAddr, softmaxMaxDeviceAddr, softmaxSumDeviceAddr, workspaceSize, workspaceAddr,666 attentionOutDeviceAddr, softmaxMaxDeviceAddr, softmaxSumDeviceAddr, workspaceSize, workspaceAddr,
@@ -572,7 +572,7 @@ int main()
572 int64_t headNum = 16;572 int64_t headNum = 16;
573 int64_t selectedBlockSize = 64;573 int64_t selectedBlockSize = 64;
574 int64_t selectedBlockCount = 16;574 int64_t selectedBlockCount = 16;
575- int64_t sparseMod = 2;575+ int64_t sparseMode = 2;
576 char layOut[] = "TND";576 char layOut[] = "TND";
577 577 
578 void *qDeviceAddr = nullptr;578 void *qDeviceAddr = nullptr;
@@ -661,7 +661,7 @@ int main()
661 // Call the first-phase API of aclnnNsaSelectedAttention.661 // Call the first-phase API of aclnnNsaSelectedAttention.
662 ret = aclnnNsaSelectedAttentionGetWorkspaceSize(662 ret = aclnnNsaSelectedAttentionGetWorkspaceSize(
663 q, k, v, topKIndices, attenMaskOptional, actualSeqQLenOptional, actualSeqKvLenOptional, scaleValue, headNum,663 q, k, v, topKIndices, attenMaskOptional, actualSeqQLenOptional, actualSeqKvLenOptional, scaleValue, headNum,
664- layOut, sparseMod, selectedBlockSize, selectedBlockCount, softmaxMax, softmaxSum, attentionOut, &workspaceSize, &executor);664+ layOut, sparseMode, selectedBlockSize, selectedBlockCount, softmaxMax, softmaxSum, attentionOut, &workspaceSize, &executor);
665 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNsaSelectedAttentionGetWorkspaceSize failed. ERROR: %d\n", ret);665 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNsaSelectedAttentionGetWorkspaceSize failed. ERROR: %d\n", ret);
666 FreeResource(q, k, v, attentionOut, softmaxMax, softmaxSum, qDeviceAddr, kDeviceAddr, vDeviceAddr,666 FreeResource(q, k, v, attentionOut, softmaxMax, softmaxSum, qDeviceAddr, kDeviceAddr, vDeviceAddr,
667 attentionOutDeviceAddr, softmaxMaxDeviceAddr, softmaxSumDeviceAddr, workspaceSize, workspaceAddr,667 attentionOutDeviceAddr, softmaxMaxDeviceAddr, softmaxSumDeviceAddr, workspaceSize, workspaceAddr,
@@ -340,7 +340,7 @@ aclnnStatus aclnnNsaSelectedAttentionInfer(
340 <td>输出</td>340 <td>输出</td>
341 <td>公式中attention的输出。</td>341 <td>公式中attention的输出。</td>
342 <td>342 <td>
343- 预留参数,暂未使用。343+ 用于接收attention计算结果。
344 </td>344 </td>
345 <td>FLOAT16、BFLOAT16</td>345 <td>FLOAT16、BFLOAT16</td>
346 <td>ND</td>346 <td>ND</td>
@@ -313,7 +313,7 @@ aclnnStatus aclnnNsaSelectedAttentionInfer(
313 <td style="white-space: nowrap;">output</td>313 <td style="white-space: nowrap;">output</td>
314 <td>Output</td>314 <td>Output</td>
315 <td>Attention output in the formula.</td>315 <td>Attention output in the formula.</td>
316- <td> Reserved parameter, not used yet.316+ <td> Receives the attention computation result.
317 </td>317 </td>
318 <td>FLOAT16, BFLOAT16</td>318 <td>FLOAT16, BFLOAT16</td>
319 <td>ND</td>319 <td>ND</td>
@@ -414,7 +414,7 @@ cann_ops_transformer.quant_flash_attn_grad(
414 <td>Tensor</td>414 <td>Tensor</td>
415 </tr>415 </tr>
416 <tr>416 <tr>
417- <td rowspan="6">SeqLens参数组</td>417+ <td rowspan="6">SeqLengths参数组</td>
418 <td>cu_seqlens_q</td>418 <td>cu_seqlens_q</td>
419 <td>INPUT(OPTIONAL)</td>419 <td>INPUT(OPTIONAL)</td>
420 <td>Tensor</td>420 <td>Tensor</td>
@@ -415,7 +415,7 @@ In the Python API, `mask_mode` supports passing the `IntEnum` enumeration or the
415 <td>Tensor</td>415 <td>Tensor</td>
416 </tr>416 </tr>
417 <tr>417 <tr>
418- <td rowspan="6">SeqLens parameter group</td>418+ <td rowspan="6">SeqLengths parameter group</td>
419 <td>cu_seqlens_q</td>419 <td>cu_seqlens_q</td>
420 <td>INPUT(OPTIONAL)</td>420 <td>INPUT(OPTIONAL)</td>
421 <td>Tensor</td>421 <td>Tensor</td>
@@ -194,8 +194,8 @@ cann_ops_transformer.quant_sparse_flash_mla(
194| cmp_kv_descale | tensor | 可选 | cmp_kv对应的量化参数 | float32 | ND | <ul><li>[1]</li></ul>194| cmp_kv_descale | tensor | 可选 | cmp_kv对应的量化参数 | float32 | ND | <ul><li>[1]</li></ul>
195| ori_sparse_indices | tensor | 可选 | 表示原始KV topK索引,无效位置填-1 | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>195| ori_sparse_indices | tensor | 可选 | 表示原始KV topK索引,无效位置填-1 | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>
196| cmp_sparse_indices | tensor | 可选 | 表示压缩KV topK索引,无效位置填-1 | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>196| cmp_sparse_indices | tensor | 可选 | 表示压缩KV topK索引,无效位置填-1 | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>
197-| ori_block_table | tensor | 可选 | 表示PageAttention场景下ori_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>197+| ori_block_table | tensor | 可选 | 表示PagedAttention场景下ori_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>
198-| cmp_block_table | tensor | 可选 | 表示PageAttention场景下cmp_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>198+| cmp_block_table | tensor | 可选 | 表示PagedAttention场景下cmp_kv使用的block映射表 | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>
199| cu_seqlens_q | tensor | 可选 | 表示处理输入q变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>199| cu_seqlens_q | tensor | 可选 | 表示处理输入q变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>
200| cu_seqlens_ori_kv | tensor | 可选 | 表示处理输入ori_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>200| cu_seqlens_ori_kv | tensor | 可选 | 表示处理输入ori_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>
201| cu_seqlens_cmp_kv | tensor | 可选 | 表示处理输入cmp_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>201| cu_seqlens_cmp_kv | tensor | 可选 | 表示处理输入cmp_kv变长序列的累积序列长度 | int32 | ND | <ul><li>(b+1,)</li></ul>
@@ -196,8 +196,8 @@ cann_ops_transformer.quant_sparse_flash_mla(
196| cmp_kv_descale | tensor | Optional | Quantization parameter corresponding to cmp_kv. | float32 | ND | <ul><li>[1]</li></ul>196| cmp_kv_descale | tensor | Optional | Quantization parameter corresponding to cmp_kv. | float32 | ND | <ul><li>[1]</li></ul>
197| ori_sparse_indices | tensor | Optional | TopK indices of the original KV. Invalid positions are filled with -1. | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>197| ori_sparse_indices | tensor | Optional | TopK indices of the original KV. Invalid positions are filled with -1. | int32 | ND | <ul><li>(q_t, kv_n, ori_kv_k)</li><li>(b, q_s, kv_n, ori_kv_k)</li></ul>
198| cmp_sparse_indices | tensor | Optional | TopK indices of the compressed KV. Invalid positions are filled with -1. | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>198| cmp_sparse_indices | tensor | Optional | TopK indices of the compressed KV. Invalid positions are filled with -1. | int32 | ND | <ul><li>(q_t, kv_n, cmp_kv_k)</li><li>(b, q_s, kv_n, cmp_kv_k)</li></ul>
199-| ori_block_table | tensor | Optional | Block mapping table used by ori_kv in PageAttention use cases. | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>199+| ori_block_table | tensor | Optional | Block mapping table used by ori_kv in PagedAttention use cases. | int32 | ND | <ul><li>(b, ceil(ori_kv_s_max/ori_kv_block_size))</li></ul>
200-| cmp_block_table | tensor | Optional | Block mapping table used by cmp_kv in PageAttention use cases. | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>200+| cmp_block_table | tensor | Optional | Block mapping table used by cmp_kv in PagedAttention use cases. | int32 | ND | <ul><li>(b, ceil(cmp_kv_s_max/cmp_kv_block_size))</li></ul>
201| cu_seqlens_q | tensor | Optional | Cumulative sequence lengths for variable-length sequences of input q. | int32 | ND | <ul><li>(b+1,)</li></ul>201| cu_seqlens_q | tensor | Optional | Cumulative sequence lengths for variable-length sequences of input q. | int32 | ND | <ul><li>(b+1,)</li></ul>
202| cu_seqlens_ori_kv | tensor | Optional | Cumulative sequence lengths for variable-length sequences of input ori_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>202| cu_seqlens_ori_kv | tensor | Optional | Cumulative sequence lengths for variable-length sequences of input ori_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>
203| cu_seqlens_cmp_kv | tensor | Optional | Cumulative sequence lengths for variable-length sequences of input cmp_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>203| cu_seqlens_cmp_kv | tensor | Optional | Cumulative sequence lengths for variable-length sequences of input cmp_kv. | int32 | ND | <ul><li>(b+1,)</li></ul>
@@ -65,6 +65,7 @@
65 其中,$S_{t-1},S_t \in R^{V_{dim}\times K_{dim}}$,$q_t,k_t\in R^{K_{dim}}$,$v_t,o_t\in R^{V_{dim}}$。$d_t$ 沿状态矩阵的 K 维广播。多个 value head 可以共享同一个 query/key head,要求 $H_v$ 能被 $H_k$ 整除。65 其中,$S_{t-1},S_t \in R^{V_{dim}\times K_{dim}}$,$q_t,k_t\in R^{K_{dim}}$,$v_t,o_t\in R^{V_{dim}}$。$d_t$ 沿状态矩阵的 K 维广播。多个 value head 可以共享同一个 query/key head,要求 $H_v$ 能被 $H_k$ 整除。
66 66 
67- 符号说明67- 符号说明
68+ 
68 | 符号 | 含义 |69 | 符号 | 含义 |
69 | ----------- | ---------------------------------------------------------------------------------- |70 | ----------- | ---------------------------------------------------------------------------------- |
70 | B | Batch Size,输入样本批量大小 |71 | B | Batch Size,输入样本批量大小 |
@@ -286,7 +287,7 @@ aclnnStatus aclnnRecurrentKda(
286 <td>outputFinalState(bool)</td>287 <td>outputFinalState(bool)</td>
287 <td>输入</td>288 <td>输入</td>
288 <td>是否输出有效最终状态。</td>289 <td>是否输出有效最终状态。</td>
289- <td>为 true 时 finalState 返回有效最终状态;是否原位更新由 inplaceFinalState 决定。</td>290+ <td>为 true 时 finalState 返回有效最终状态;是否原地更新由 inplaceFinalState 决定。</td>
290 <td>BOOL</td>291 <td>BOOL</td>
291 <td>-</td>292 <td>-</td>
292 <td>-</td>293 <td>-</td>
@@ -65,6 +65,7 @@
65 其中,$S_{t-1},S_t \in R^{V_{dim}\times K_{dim}}$,$q_t,k_t\in R^{K_{dim}}$,$v_t,o_t\in R^{V_{dim}}$。$d_t$ 沿状态矩阵的 K 维广播。多个 value head 可以共享同一个 query/key head,要求 $H_v$ 能被 $H_k$ 整除。65 其中,$S_{t-1},S_t \in R^{V_{dim}\times K_{dim}}$,$q_t,k_t\in R^{K_{dim}}$,$v_t,o_t\in R^{V_{dim}}$。$d_t$ 沿状态矩阵的 K 维广播。多个 value head 可以共享同一个 query/key head,要求 $H_v$ 能被 $H_k$ 整除。
66 66 
67- 符号说明67- 符号说明
68+ 
68 | 符号 | 含义 |69 | 符号 | 含义 |
69 | ----------- | ---------------------------------------------------------------------------------- |70 | ----------- | ---------------------------------------------------------------------------------- |
70 | B | Batch Size,输入样本批量大小 |71 | B | Batch Size,输入样本批量大小 |
@@ -23,16 +23,16 @@
23 23 
24## 功能说明24## 功能说明
25 25 
26-- **接口功能**:根据topkIndices对key和value选取大小为selectedBlockSize的数据重排,接着进行训练场景下计算注意力的反向输出。26+- **接口功能**:根据sparseIndices从key和value中选取大小为sparseBlockSize的数据块并重排,计算训练场景下注意力的反向传播结果。
27 27 
28-- **计算公式**:根据传入的topkIndices对keyIn和value选取数量为selectedBlockCount个大小为selectedBlockSize的数据重排,公式如下:28+- **计算公式**:根据传入的sparseIndices从key和value中选取大小为sparseBlockSize的数据块并重排。K为sparseIndices的最后一维大小,按第i个有效索引选取数据块的公式如下:
29 29 
30 $$30 $$
31- selectedKey\text{ }=\text{ }Gather \left( key,topkIndices \left[ i \left] \left) ,\text{ }0\text{ } < =i < \text{ }selectBlockCount\right. \right. \right. \right.31+ selectedKey_i = \operatorname{Gather}(key, sparseIndices[i]), \quad 0 \le i < K
32 $$32 $$
33 33 
34 $$34 $$
35- selectedValue\text{ }=\text{ }Gather \left( value,topkIndices \left[ i \left] \left) ,\text{ }0\text{ } < =i < \text{ }selectBlockCount\right. \right. \right. \right.35+ selectedValue_i = \operatorname{Gather}(value, sparseIndices[i]), \quad 0 \le i < K
36 $$36 $$
37 37 
38 KV merge场景下,若value为空指针,则上述公式中的value按key处理,selectedValue等价于selectedKey。该场景的反向输出不单独返回dValue,dKeyOut表示合并后的梯度:38 KV merge场景下,若value为空指针,则上述公式中的value按key处理,selectedValue等价于selectedKey。该场景的反向输出不单独返回dValue,dKeyOut表示合并后的梯度:
@@ -25,16 +25,16 @@
25 25 
26## Function26## Function
27 27 
28-- **Description**: Rearranges data of size selectedBlockSize selected from key and value based on topkIndices, and then computes the backward output of attention in training scenarios.28+- **Description**: Selects and rearranges data blocks of size sparseBlockSize from key and value based on sparseIndices, then computes the attention backward results for training.
29 29 
30-- **Formula**: Rearranges data of selectedBlockCount blocks, each of size selectedBlockSize, selected from keyIn and value based on the input topkIndices. The formula is as follows:30+- **Formula**: Selects and rearranges data blocks of size sparseBlockSize from key and value based on sparseIndices. K is the size of the last dimension of sparseIndices. The following formulas show how a data block is selected using the i-th valid index:
31 31 
32 $$32 $$
33- selectedKey\text{ }=\text{ }Gather \left( key,topkIndices \left[ i \left] \left) ,\text{ }0\text{ } < =i < \text{ }selectBlockCount\right. \right. \right. \right.33+ selectedKey_i = \operatorname{Gather}(key, sparseIndices[i]), \quad 0 \le i < K
34 $$34 $$
35 35 
36 $$36 $$
37- selectedValue\text{ }=\text{ }Gather \left( value,topkIndices \left[ i \left] \left) ,\text{ }0\text{ } < =i < \text{ }selectBlockCount\right. \right. \right. \right.37+ selectedValue_i = \operatorname{Gather}(value, sparseIndices[i]), \quad 0 \le i < K
38 $$38 $$
39 39 
40 In the KV merge use case, if value is a null pointer, value in the preceding formulas is treated as key, and selectedValue is equivalent to selectedKey. The backward output in this use case does not return dValue separately; dKeyOut indicates the merged gradient:40 In the KV merge use case, if value is a null pointer, value in the preceding formulas is treated as key, and selectedValue is equivalent to selectedKey. The backward output in this use case does not return dValue separately; dKeyOut indicates the merged gradient:
@@ -186,8 +186,8 @@ cann_ops_transformer.sparse_flash_mla(
186| cmp_kv | Tensor | 可选 | 压缩kv输入,Key和Value共享同一份数据。 | bfloat16/float16 | ND | `BSND`:(b, cmp_kv_s, kv_n, d)<br>`TND`:(cmp_kv_t, kv_n, d)<br>`PA_BBND`:(cmp_kv_block_nums, cmp_kv_block_size, kv_n, d) |186| cmp_kv | Tensor | 可选 | 压缩kv输入,Key和Value共享同一份数据。 | bfloat16/float16 | ND | `BSND`:(b, cmp_kv_s, kv_n, d)<br>`TND`:(cmp_kv_t, kv_n, d)<br>`PA_BBND`:(cmp_kv_block_nums, cmp_kv_block_size, kv_n, d) |
187| ori_sparse_indices | Tensor | 可选 | 原始kv稀疏索引,无效位置填-1。 | int32 | ND | `BSND`:(b, q_s, kv_n, ori_kv_k)<br>`TND`:(q_t, kv_n, ori_kv_k) |187| ori_sparse_indices | Tensor | 可选 | 原始kv稀疏索引,无效位置填-1。 | int32 | ND | `BSND`:(b, q_s, kv_n, ori_kv_k)<br>`TND`:(q_t, kv_n, ori_kv_k) |
188| cmp_sparse_indices | Tensor | 可选 | 压缩kv的TopK索引,无效位置填-1;仅CSA场景传入。 | int32 | ND | `BSND`:(b, q_s, kv_n, cmp_kv_k)<br>`TND`:(q_t, kv_n, cmp_kv_k) |188| cmp_sparse_indices | Tensor | 可选 | 压缩kv的TopK索引,无效位置填-1;仅CSA场景传入。 | int32 | ND | `BSND`:(b, q_s, kv_n, cmp_kv_k)<br>`TND`:(q_t, kv_n, cmp_kv_k) |
189-| ori_block_table | Tensor | 可选 | PageAttention场景下`ori_kv`使用的Block映射表。 | int32 | ND | (b, max_num_blocks_per_seq) |189+| ori_block_table | Tensor | 可选 | PagedAttention场景下`ori_kv`使用的Block映射表。 | int32 | ND | (b, max_num_blocks_per_seq) |
190-| cmp_block_table | Tensor | 可选 | PageAttention场景下`cmp_kv`使用的Block映射表。 | int32 | ND | (b, max_num_blocks_per_seq) |190+| cmp_block_table | Tensor | 可选 | PagedAttention场景下`cmp_kv`使用的Block映射表。 | int32 | ND | (b, max_num_blocks_per_seq) |
191| cu_seqlens_q | Tensor | 可选 | TND场景下`q`各Batch有效token数的累积和。 | int32 | ND | (b+1,) |191| cu_seqlens_q | Tensor | 可选 | TND场景下`q`各Batch有效token数的累积和。 | int32 | ND | (b+1,) |
192| cu_seqlens_ori_kv | Tensor | 可选 | TND场景下`ori_kv`各Batch有效token数的累积和。 | int32 | ND | (b+1,) |192| cu_seqlens_ori_kv | Tensor | 可选 | TND场景下`ori_kv`各Batch有效token数的累积和。 | int32 | ND | (b+1,) |
193| cu_seqlens_cmp_kv | Tensor | 可选 | TND场景下`cmp_kv`各Batch有效token数的累积和。 | int32 | ND | (b+1,) |193| cu_seqlens_cmp_kv | Tensor | 可选 | TND场景下`cmp_kv`各Batch有效token数的累积和。 | int32 | ND | (b+1,) |
@@ -370,7 +370,7 @@ layout匹配关系表:
370#### PagedAttention参数组370#### PagedAttention参数组
371 371 
372- `layout_kv="PA_BBND"`时,必须传入`seqused_ori_kv`和`ori_block_table`;传入`cmp_kv`时,还必须传入`cmp_block_table`。372- `layout_kv="PA_BBND"`时,必须传入`seqused_ori_kv`和`ori_block_table`;传入`cmp_kv`时,还必须传入`cmp_block_table`。
373-- PageAttention的`block_size`取值必须大于0。对于<term>Atlas A2系列产品</term>和<term>Atlas A3系列产品</term>,取非16的倍数或大于1024时拦截;对于<term>Ascend 950PR&950DT系列产品</term>,取小于等于0时拦截。373+- PagedAttention的`block_size`取值必须大于0。对于<term>Atlas A2系列产品</term>和<term>Atlas A3系列产品</term>,取非16的倍数或大于1024时拦截;对于<term>Ascend 950PR&950DT系列产品</term>,取小于等于0时拦截。
374- topk_value_mode=2时 `ori_block_table`、`cmp_block_table`均可不传。374- topk_value_mode=2时 `ori_block_table`、`cmp_block_table`均可不传。
375 375 
376| 参数 | 单参数校验 | 存在性拦截 | 一致性拦截 | 特性交叉拦截 |376| 参数 | 单参数校验 | 存在性拦截 | 一致性拦截 | 特性交叉拦截 |
@@ -188,8 +188,8 @@ cann_ops_transformer.sparse_flash_mla(
188| cmp_kv | Tensor | Optional | Compressed KV input. Key and Value share the same data. | bfloat16/float16 | ND | `BSND`: (b, cmp_kv_s, kv_n, d)<br>`TND`: (cmp_kv_t, kv_n, d)<br>`PA_BBND`: (cmp_kv_block_nums, cmp_kv_block_size, kv_n, d) |188| cmp_kv | Tensor | Optional | Compressed KV input. Key and Value share the same data. | bfloat16/float16 | ND | `BSND`: (b, cmp_kv_s, kv_n, d)<br>`TND`: (cmp_kv_t, kv_n, d)<br>`PA_BBND`: (cmp_kv_block_nums, cmp_kv_block_size, kv_n, d) |
189| ori_sparse_indices | Tensor | Optional | Original KV sparse index. Reserved field. | int32 | ND | `TND`: (q_t, kv_n, ori_kv_k) `BSND`: (b, q_s, kv_n, ori_kv_k) |189| ori_sparse_indices | Tensor | Optional | Original KV sparse index. Reserved field. | int32 | ND | `TND`: (q_t, kv_n, ori_kv_k) `BSND`: (b, q_s, kv_n, ori_kv_k) |
190| cmp_sparse_indices | Tensor | Optional | TopK indices of the compressed KV. Invalid positions are filled with -1. Passed in only for CSA use cases. | int32 | ND | `BSND`: (b, q_s, kv_n, cmp_kv_k)<br>`TND`: (q_t, kv_n, cmp_kv_k) |190| cmp_sparse_indices | Tensor | Optional | TopK indices of the compressed KV. Invalid positions are filled with -1. Passed in only for CSA use cases. | int32 | ND | `BSND`: (b, q_s, kv_n, cmp_kv_k)<br>`TND`: (q_t, kv_n, cmp_kv_k) |
191-| ori_block_table | Tensor | Optional | Block mapping table used by `ori_kv` in PageAttention use cases. | int32 | ND | (b, max_num_blocks_per_seq) |191+| ori_block_table | Tensor | Optional | Block mapping table used by `ori_kv` in PagedAttention use cases. | int32 | ND | (b, max_num_blocks_per_seq) |
192-| cmp_block_table | Tensor | Optional | Block mapping table used by `cmp_kv` in PageAttention use cases. | int32 | ND | (b, max_num_blocks_per_seq) |192+| cmp_block_table | Tensor | Optional | Block mapping table used by `cmp_kv` in PagedAttention use cases. | int32 | ND | (b, max_num_blocks_per_seq) |
193| cu_seqlens_q | Tensor | Optional | Cumulative sum of the number of effective tokens in each batch of `q` in TND use cases. | int32 | ND | (b+1,) |193| cu_seqlens_q | Tensor | Optional | Cumulative sum of the number of effective tokens in each batch of `q` in TND use cases. | int32 | ND | (b+1,) |
194| cu_seqlens_ori_kv | Tensor | Optional | Cumulative sum of the number of effective tokens in each batch of `ori_kv` in TND use cases. | int32 | ND | (b+1,) |194| cu_seqlens_ori_kv | Tensor | Optional | Cumulative sum of the number of effective tokens in each batch of `ori_kv` in TND use cases. | int32 | ND | (b+1,) |
195| cu_seqlens_cmp_kv | Tensor | Optional | Cumulative sum of the number of effective tokens in each batch of `cmp_kv` in TND use cases. | int32 | ND | (b+1,) |195| cu_seqlens_cmp_kv | Tensor | Optional | Cumulative sum of the number of effective tokens in each batch of `cmp_kv` in TND use cases. | int32 | ND | (b+1,) |
@@ -372,7 +372,7 @@ Layout matching relationship table:
372#### Paged Attention Parameter Group372#### Paged Attention Parameter Group
373 373 
374- When `layout_kv="PA_BBND"`, `seqused_ori_kv` and `ori_block_table` must be passed in; when `cmp_kv` is passed in, `cmp_block_table` must also be passed in.374- When `layout_kv="PA_BBND"`, `seqused_ori_kv` and `ori_block_table` must be passed in; when `cmp_kv` is passed in, `cmp_block_table` must also be passed in.
375-- The `block_size` of PageAttention must be greater than 0. For <term>Atlas A2 products</term> and <term>Atlas A3 products</term>, an error is reported when the value is not a multiple of 16 or is greater than 1024; for <term>Ascend 950PR&950DT products</term>, an error is reported when the value is less than or equal to 0.375+- The `block_size` of PagedAttention must be greater than 0. For <term>Atlas A2 products</term> and <term>Atlas A3 products</term>, an error is reported when the value is not a multiple of 16 or is greater than 1024; for <term>Ascend 950PR&950DT products</term>, an error is reported when the value is less than or equal to 0.
376- When topk_value_mode=2, `ori_block_table` and `cmp_block_table` can be omitted.376- When topk_value_mode=2, `ori_block_table` and `cmp_block_table` can be omitted.
377 377 
378| Parameter | Single-Parameter Check | Existence Check | Consistency Check | Feature Cross-Check |378| Parameter | Single-Parameter Check | Existence Check | Consistency Check | Feature Cross-Check |
@@ -168,7 +168,7 @@ aclnnStatus aclnnSparseFlashMlaGrad(
168 <td>输入</td>168 <td>输入</td>
169 <td>attention结构的输入Q。</td>169 <td>attention结构的输入Q。</td>
170 <td>170 <td>
171- query、oriKvOptional、cmpKvOptional、dOut、outOptional、lse、oriSparseIndicesOptional、cmpSparseIndicesOptional的Shape维度保持一致。171+ query、oriKvOptional、cmpKvOptional、dOut、out、lse、oriSparseIndicesOptional、cmpSparseIndicesOptional的Shape维度保持一致。
172 </td>172 </td>
173 <td>BFLOAT16、FLOAT16</td>173 <td>BFLOAT16、FLOAT16</td>
174 <td>ND</td>174 <td>ND</td>
@@ -159,7 +159,7 @@ aclnnStatus aclnnSparseFlashMlaGrad(
159 <td>query (aclTensor*)</td>159 <td>query (aclTensor*)</td>
160 <td>Input</td>160 <td>Input</td>
161 <td>Input Q of the attention structure.</td>161 <td>Input Q of the attention structure.</td>
162- <td> The shape dimensions of query, oriKvOptional, cmpKvOptional, dOut, outOptional, lse, oriSparseIndicesOptional, and cmpSparseIndicesOptional must be consistent.162+ <td> The shape dimensions of query, oriKvOptional, cmpKvOptional, dOut, out, lse, oriSparseIndicesOptional, and cmpSparseIndicesOptional must be consistent.
163 </td>163 </td>
164 <td>BFLOAT16, FLOAT16</td>164 <td>BFLOAT16, FLOAT16</td>
165 <td>ND</td>165 <td>ND</td>
@@ -16,7 +16,7 @@
16- 算子功能:SparseLightningIndexer(candidate consumer)在16- 算子功能:SparseLightningIndexer(candidate consumer)在
17 LightningIndexerV2 的加权 ReLU 打分 + TopK 框架上,**消费上游 source 算子输出的候选块索引**17 LightningIndexerV2 的加权 ReLU 打分 + TopK 框架上,**消费上游 source 算子输出的候选块索引**
18 (`candidate_block_indices`),对每个 query 行做**无 leak 候选内 TopK**:18 (`candidate_block_indices`),对每个 query 行做**无 leak 候选内 TopK**:
19- 可达且命中介候选块的位置以真实分数参与排序,其余位置(不可达 / 可达但不在候选内)一律无效不入选;19+ 可达且命中候选块的位置以真实分数参与排序,其余位置(不可达 / 可达但不在候选内)一律无效不入选;
20 **非候选块索引一律不进入 topk 输出**,候选内有效数不足 topk 时剩余槽位填 -1。20 **非候选块索引一律不进入 topk 输出**,候选内有效数不足 topk 时剩余槽位填 -1。
21 与 `lightning_indexer`(source 模式,`candidate_topk_blocks != -1`)21 与 `lightning_indexer`(source 模式,`candidate_topk_blocks != -1`)
22 配对使用,构成候选块两级 TopK 的 consumer 侧。22 配对使用,构成候选块两级 TopK 的 consumer 侧。
@@ -15,7 +15,7 @@ English | [简体中文](./README.md)
15 15 
16## Description16## Description
17 17 
18-- Operator function: On the weighted ReLU scoring + TopK framework of LightningIndexerV2, SparseLightningIndexer (candidate consumer) **consumes the candidate block indexes output by the upstream source operator** (`candidate_block_indices`) and performs **leak-free TopK within candidates** for each query row. Reachable positions that hit candidate blocks participate in sorting with real scores, and all other positions (unreachable / reachable but not in candidates) are invalid and are not selected. **Non-candidate block indexes never enter the topk output**, and when the number of valid entries within candidates is less than topk, the remaining slots are filled with -1. This operator is used in pair with `lightning_indexer` (source mode, `candidate_topk_blocks != -1`) to form the consumer side of the two-level TopK over candidate blocks.18+- Operator function: SparseLightningIndexer (candidate consumer) uses the weighted ReLU scoring and TopK framework of LightningIndexerV2. It **consumes the candidate block indices produced by the upstream source operator** (`candidate_block_indices`) and performs **leak-free TopK within candidate blocks** for each query row. Reachable positions covered by candidate blocks are ranked using their actual scores. All other positions, including unreachable positions and reachable positions outside candidate blocks, are invalid and are not selected. **Indices outside candidate blocks never appear in the topk output**, and when the number of valid entries within candidates is less than topk, the remaining slots are filled with -1. This operator is used together with `lightning_indexer` (source mode, `candidate_topk_blocks != -1`) to form the consumer side of the two-level TopK over candidate blocks.
19 19 
20- Calculation formula (for each batch b and query row i, with N2=1):20- Calculation formula (for each batch b and query row i, with N2=1):
21 21 
@@ -29,7 +29,7 @@
29 29 
30- **输入输出支持以下数据场景**:30- **输入输出支持以下数据场景**:
31 31 
32- ```32+ ```text
33 k_cache: [total_blocks, kv_block_size, H_kv, 128] 或 [total_blocks, H_kv, kv_block_size, 128]33 k_cache: [total_blocks, kv_block_size, H_kv, 128] 或 [total_blocks, H_kv, kv_block_size, 128]
34 v_cache: [total_blocks, kv_block_size, H_kv, 128] 或 [total_blocks, H_kv, kv_block_size, 128]34 v_cache: [total_blocks, kv_block_size, H_kv, 128] 或 [total_blocks, H_kv, kv_block_size, 128]
35 kv_indices: [batch, max_kv_blocks]35 kv_indices: [batch, max_kv_blocks]
@@ -31,7 +31,7 @@
31 31 
32- **The inputs and outputs support the following data use cases**:32- **The inputs and outputs support the following data use cases**:
33 33 
34- ```34+ ```text
35 k_cache: [total_blocks, kv_block_size, H_kv, 128] or [total_blocks, H_kv, kv_block_size, 128]35 k_cache: [total_blocks, kv_block_size, H_kv, 128] or [total_blocks, H_kv, kv_block_size, 128]
36 v_cache: [total_blocks, kv_block_size, H_kv, 128] or [total_blocks, H_kv, kv_block_size, 128]36 v_cache: [total_blocks, kv_block_size, H_kv, 128] or [total_blocks, H_kv, kv_block_size, 128]
37 kv_indices: [batch, max_kv_blocks]37 kv_indices: [batch, max_kv_blocks]
@@ -192,7 +192,7 @@
192|[aclnnMoeTokenUnpermuteGrad](../../moe/moe_token_unpermute_grad/docs/aclnnMoeTokenUnpermuteGrad.md)|[aclnnMoeTokenUnpermute](../../moe/moe_token_unpermute/docs/aclnnMoeTokenUnpermute.md)的反向传播。|默认确定性实现|默认确定性实现|默认确定性实现|192|[aclnnMoeTokenUnpermuteGrad](../../moe/moe_token_unpermute_grad/docs/aclnnMoeTokenUnpermuteGrad.md)|[aclnnMoeTokenUnpermute](../../moe/moe_token_unpermute/docs/aclnnMoeTokenUnpermute.md)的反向传播。|默认确定性实现|默认确定性实现|默认确定性实现|
193|[aclnnMoeTokenUnpermuteWithEp](../../moe/moe_token_unpermute_with_ep/docs/aclnnMoeTokenUnpermuteWithEp.md)|根据sortedIndices存储的下标位置,去获取permutedTokens中的输入数据与probs相乘,并进行合并累加。|默认确定性实现|默认确定性实现|默认确定性实现|193|[aclnnMoeTokenUnpermuteWithEp](../../moe/moe_token_unpermute_with_ep/docs/aclnnMoeTokenUnpermuteWithEp.md)|根据sortedIndices存储的下标位置,去获取permutedTokens中的输入数据与probs相乘,并进行合并累加。|默认确定性实现|默认确定性实现|默认确定性实现|
194|[aclnnMoeTokenUnpermuteWithEpGrad](../../moe/moe_token_unpermute_with_ep_grad/docs/aclnnMoeTokenUnpermuteWithEpGrad.md)|[aclnnMoeTokenUnpermuteWithEp](../../moe/moe_token_unpermute_with_ep/docs/aclnnMoeTokenUnpermuteWithEp.md)的反向传播。|默认确定性实现|默认确定性实现|默认确定性实现|194|[aclnnMoeTokenUnpermuteWithEpGrad](../../moe/moe_token_unpermute_with_ep_grad/docs/aclnnMoeTokenUnpermuteWithEpGrad.md)|[aclnnMoeTokenUnpermuteWithEp](../../moe/moe_token_unpermute_with_ep/docs/aclnnMoeTokenUnpermuteWithEp.md)的反向传播。|默认确定性实现|默认确定性实现|默认确定性实现|
195-|[aclnnMoeTokenUnpermuteWithRoutingMap](../../moe/moe_token_unpermute_with_routing_map/docs/aclnnMoeTokenUnpermuteWithRoutingMap.md)|对经过aclnnMoeTokenUpermuteWithRoutingMap处理的permutedTokens,累加回原unpermutedTokens。|默认确定性实现|默认确定性实现|默认确定性实现|195+|[aclnnMoeTokenUnpermuteWithRoutingMap](../../moe/moe_token_unpermute_with_routing_map/docs/aclnnMoeTokenUnpermuteWithRoutingMap.md)|对经过aclnnMoeTokenPermuteWithRoutingMap处理的permutedTokens,累加回原unpermutedTokens。|默认确定性实现|默认确定性实现|默认确定性实现|
196|[aclnnMoeTokenUnpermuteWithRoutingMapGrad](../../moe/moe_token_unpermute_with_routing_map_grad/docs/aclnnMoeTokenUnpermuteWithRoutingMapGrad.md)|[aclnnMoeTokenUnpermuteWithRoutingMap](../../moe/moe_token_unpermute_with_routing_map/docs/aclnnMoeTokenUnpermuteWithRoutingMap.md)的反向传播。|默认非确定性实现,支持配置开启|默认非确定性实现,支持配置开启|默认非确定性实现,支持配置开启|196|[aclnnMoeTokenUnpermuteWithRoutingMapGrad](../../moe/moe_token_unpermute_with_routing_map_grad/docs/aclnnMoeTokenUnpermuteWithRoutingMapGrad.md)|[aclnnMoeTokenUnpermuteWithRoutingMap](../../moe/moe_token_unpermute_with_routing_map/docs/aclnnMoeTokenUnpermuteWithRoutingMap.md)的反向传播。|默认非确定性实现,支持配置开启|默认非确定性实现,支持配置开启|默认非确定性实现,支持配置开启|
197|[aclnnMoeUpdateExpert](../../mc2/moe_update_expert/docs/aclnnMoeUpdateExpert.md)|本API支持负载均衡和专家剪枝功能。经过映射后的专家表和Mask可传入MoE层进行数据分发和处理。|-|默认确定性实现|默认确定性实现|197|[aclnnMoeUpdateExpert](../../mc2/moe_update_expert/docs/aclnnMoeUpdateExpert.md)|本API支持负载均衡和专家剪枝功能。经过映射后的专家表和Mask可传入MoE层进行数据分发和处理。|-|默认确定性实现|默认确定性实现|
198|[aclnnMsaIndexScore](../../attention/msa_index_score/docs/aclnnMsaIndexScore.md)|计算 MSA Index Branch 的 block score,对每个 query token 与 KV sparse block 做 matmul+maxpool 得到重要性分数。|默认确定性实现|默认确定性实现|默认确定性实现|198|[aclnnMsaIndexScore](../../attention/msa_index_score/docs/aclnnMsaIndexScore.md)|计算 MSA Index Branch 的 block score,对每个 query token 与 KV sparse block 做 matmul+maxpool 得到重要性分数。|默认确定性实现|默认确定性实现|默认确定性实现|
@@ -29,7 +29,7 @@
29 29 
30 1. 接收AttentionToFFN算子发送的数据。该数据以ScheduleContext结构体内存排布方式存储。其具体定义参见[调用示例](#调用示例)。该结构体包含CommonArea,ControlArea,AttentionArea,FfnArea域。本接口涉及CommonArea(用于存储配置信息,如session_num,micro_batch_num,micro_batch_size,selected_expert_num),ControlArea(用于上层控制进程是否退出),FfnArea域(负责管理本算子计算过程中所需的输入及输出缓冲区,其中token_info_buf字段用来存储该算子的输入信息)。30 1. 接收AttentionToFFN算子发送的数据。该数据以ScheduleContext结构体内存排布方式存储。其具体定义参见[调用示例](#调用示例)。该结构体包含CommonArea,ControlArea,AttentionArea,FfnArea域。本接口涉及CommonArea(用于存储配置信息,如session_num,micro_batch_num,micro_batch_size,selected_expert_num),ControlArea(用于上层控制进程是否退出),FfnArea域(负责管理本算子计算过程中所需的输入及输出缓冲区,其中token_info_buf字段用来存储该算子的输入信息)。
31 31 
32- 2. 扫描token_info_buf存储的信息,当通信数据准备就绪时,本算子开始进行数据整理。整理如下图所示,将layer id, session id,micro batch id,expert ids分别写入layer_id_buf,session_id_buf,micro_batch_id_buf,expert_ids_buf的device内存上。32+ 2. 扫描token_info_buf存储的信息,当通信数据准备就绪时,本算子开始进行数据整理。整理如下图所示,将layer id, session id,micro batch id,expert ids分别写入layer_ids_buf,session_ids_buf,micro_batch_ids_buf,expert_ids_buf的device内存上。
33 33 
34 ```mermaid34 ```mermaid
35 graph TB35 graph TB
@@ -31,7 +31,7 @@
31 31 
32 1. Receive the data sent from the AttentionToFFN operator. The data is stored in the memory layout of the ScheduleContext structure. For details, see [Example](#example). The structure contains the CommonArea, ControlArea, AttentionArea, and FfnArea domains. This API involves CommonArea (stores configuration information such as session_num, micro_batch_num, micro_batch_size, and selected_expert_num), ControlArea (used by the upper layer to control whether the process exits), and the FfnArea domain (manages the input and output buffers required for computation of this operator, where the token_info_buf field stores the input information of this operator).32 1. Receive the data sent from the AttentionToFFN operator. The data is stored in the memory layout of the ScheduleContext structure. For details, see [Example](#example). The structure contains the CommonArea, ControlArea, AttentionArea, and FfnArea domains. This API involves CommonArea (stores configuration information such as session_num, micro_batch_num, micro_batch_size, and selected_expert_num), ControlArea (used by the upper layer to control whether the process exits), and the FfnArea domain (manages the input and output buffers required for computation of this operator, where the token_info_buf field stores the input information of this operator).
33 33 
34- 2. Scans the information stored in token_info_buf. When the communication data is ready, this operator starts data reorganization. The reorganization is shown in the following figure: layer id, session id, micro batch id, and expert ids are written to the device memory of layer_id_buf, session_id_buf, micro_batch_id_buf, and expert_ids_buf, respectively.34+ 2. Scans the information stored in token_info_buf. When the communication data is ready, this operator starts data reorganization. The reorganization is shown in the following figure: layer id, session id, micro batch id, and expert ids are written to the device memory of layer_ids_buf, session_ids_buf, micro_batch_ids_buf, and expert_ids_buf, respectively.
35 35 
36 ```mermaid36 ```mermaid
37 graph TB37 graph TB
@@ -493,7 +493,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRouting(
493 int64_t batch = 8;493 int64_t batch = 8;
494 int64_t bsdp = 1;494 int64_t bsdp = 1;
495 int64_t dtype = 0;495 int64_t dtype = 0;
496- float shareInputWeight = 1.0;496+ float sharedInputWeight = 1.0;
497 int64_t sharedInputOffset = 0;497 int64_t sharedInputOffset = 0;
498 bool transposeX = false;498 bool transposeX = false;
499 bool transposeW = false;499 bool transposeW = false;
@@ -602,7 +602,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRouting(
602 602 
603 // 调用aclnnGroupedMatmulFinalizeRouting第一段接口603 // 调用aclnnGroupedMatmulFinalizeRouting第一段接口
604 workspaceSize = 0;604 workspaceSize = 0;
605- ret = aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize(x, w, scale, bias, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);605+ ret = aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize(x, w, scale, bias, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);
606 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize failed. ERROR: %d\n", ret);606 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize failed. ERROR: %d\n", ret);
607 return ret);607 return ret);
608 // 根据第一段接口计算出的workspaceSize申请device内存608 // 根据第一段接口计算出的workspaceSize申请device内存
@@ -526,7 +526,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV2(
526 int64_t batch = 8;526 int64_t batch = 8;
527 int64_t bsdp = 1;527 int64_t bsdp = 1;
528 int64_t dtype = 0;528 int64_t dtype = 0;
529- float shareInputWeight = 1.0;529+ float sharedInputWeight = 1.0;
530 int64_t sharedInputOffset = 0;530 int64_t sharedInputOffset = 0;
531 bool transposeX = false;531 bool transposeX = false;
532 bool transposeW = false;532 bool transposeW = false;
@@ -646,7 +646,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV2(
646 646 
647 // 调用aclnnGroupedMatmulFinalizeRoutingV2第一段接口647 // 调用aclnnGroupedMatmulFinalizeRoutingV2第一段接口
648 workspaceSize = 0;648 workspaceSize = 0;
649- ret = aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize(x, w, scale, bias, offset, antiquantScaleOptional, antiquantOffsetOptional, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);649+ ret = aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize(x, w, scale, bias, offset, antiquantScaleOptional, antiquantOffsetOptional, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);
650 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize failed. ERROR: %d\n", ret);650 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize failed. ERROR: %d\n", ret);
651 return ret);651 return ret);
652 // 根据第一段接口计算出的workspaceSize申请device内存652 // 根据第一段接口计算出的workspaceSize申请device内存
@@ -526,7 +526,7 @@ The following sample code is for reference only. For details about the compilati
526 int64_t batch = 8;526 int64_t batch = 8;
527 int64_t bsdp = 1;527 int64_t bsdp = 1;
528 int64_t dtype = 0;528 int64_t dtype = 0;
529- float shareInputWeight = 1.0;529+ float sharedInputWeight = 1.0;
530 int64_t sharedInputOffset = 0;530 int64_t sharedInputOffset = 0;
531 bool transposeX = false;531 bool transposeX = false;
532 bool transposeW = false;532 bool transposeW = false;
@@ -646,7 +646,7 @@ The following sample code is for reference only. For details about the compilati
646 646 
647 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingV2647 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingV2
648 workspaceSize = 0;648 workspaceSize = 0;
649- ret = aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize(x, w, scale, bias, offset, antiquantScaleOptional, antiquantOffsetOptional, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);649+ ret = aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize(x, w, scale, bias, offset, antiquantScaleOptional, antiquantOffsetOptional, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);
650 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize failed. ERROR: %d\n", ret);650 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV2GetWorkspaceSize failed. ERROR: %d\n", ret);
651 return ret);651 return ret);
652 // Allocate device memory based on the workspaceSize computed by the first-phase API652 // Allocate device memory based on the workspaceSize computed by the first-phase API
@@ -380,7 +380,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV3(
380 - x1、x2、scaleOptional、pertokenScaleOptional、groupListOptional、logitOptional、rowIndexOptional是必选参数,biasOptional,sharedInputOptional是可选参数。目前暂不支持offsetOptional参数。380 - x1、x2、scaleOptional、pertokenScaleOptional、groupListOptional、logitOptional、rowIndexOptional是必选参数,biasOptional,sharedInputOptional是可选参数。目前暂不支持offsetOptional参数。
381 - 当groupListType为0时,groupListOptional须为非负单调非递减数列(累积和),且最后一个值不大于x1中tensor的第一维;当groupListType为1时,groupListOptional须为非负数组(各组大小),且数值的总和不大于x1中tensor的第一维。381 - 当groupListType为0时,groupListOptional须为非负单调非递减数列(累积和),且最后一个值不大于x1中tensor的第一维;当groupListType为1时,groupListOptional须为非负数组(各组大小),且数值的总和不大于x1中tensor的第一维。
382 - out的第一维batch、sharedInputOffset必须大于等于0,且小于等于m。382 - out的第一维batch、sharedInputOffset必须大于等于0,且小于等于m。
383- - 当sharedInputOptional不为空时,其第一维长度为shareInputLen。sharedInputOffset、shareInputLen以及两者之和均需小于等于out的第一维batch。383+ - 当sharedInputOptional不为空时,其第一维长度为sharedInputLen。sharedInputOffset、sharedInputLen以及两者之和均需小于等于out的第一维batch。
384 - x1支持M为0,x2支持N为0;其他空Tensor场景不支持。384 - x1支持M为0,x2支持N为0;其他空Tensor场景不支持。
385 385 
386 <!-- end id10 -->386 <!-- end id10 -->
@@ -642,7 +642,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV3(
642 int64_t batch = 1;642 int64_t batch = 1;
643 int64_t bsdp = 1;643 int64_t bsdp = 1;
644 int64_t dtype = 0;644 int64_t dtype = 0;
645- float shareInputWeight = 1.0;645+ float sharedInputWeight = 1.0;
646 int64_t sharedInputOffset = 0;646 int64_t sharedInputOffset = 0;
647 bool transposeX = false;647 bool transposeX = false;
648 bool transposeW = false;648 bool transposeW = false;
@@ -763,7 +763,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV3(
763 763 
764 // 调用aclnnGroupedMatmulFinalizeRoutingV3第一段接口764 // 调用aclnnGroupedMatmulFinalizeRoutingV3第一段接口
765 workspaceSize = 0;765 workspaceSize = 0;
766- ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, offset, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);766+ ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, offset, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);
767 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);767 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);
768 return ret);768 return ret);
769 // 根据第一段接口计算出的workspaceSize申请device内存769 // 根据第一段接口计算出的workspaceSize申请device内存
@@ -952,7 +952,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV3(
952 int64_t batch = 8;952 int64_t batch = 8;
953 int64_t bsdp = 1;953 int64_t bsdp = 1;
954 int64_t dtype = 0;954 int64_t dtype = 0;
955- float shareInputWeight = 1.0;955+ float sharedInputWeight = 1.0;
956 int64_t sharedInputOffset = 0;956 int64_t sharedInputOffset = 0;
957 bool transposeX = false;957 bool transposeX = false;
958 bool transposeW = false;958 bool transposeW = false;
@@ -1080,7 +1080,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV3(
1080 void *workspaceAddr = nullptr;1080 void *workspaceAddr = nullptr;
1081 1081 
1082 // 调用aclnnGroupedMatmulFinalizeRoutingV3第一段接口1082 // 调用aclnnGroupedMatmulFinalizeRoutingV3第一段接口
1083- ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize, &executor);1083+ ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize, &executor);
1084 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);1084 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);
1085 return ret);1085 return ret);
1086 // 根据第一段接口计算出的workspaceSize申请device内存1086 // 根据第一段接口计算出的workspaceSize申请device内存
@@ -385,7 +385,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingV3(
385 - x1, x2, scaleOptional, pertokenScaleOptional, groupListOptional, logitOptional, and rowIndexOptional are mandatory parameters; biasOptional and sharedInputOptional are optional parameters. The offsetOptional parameter is currently not supported.385 - x1, x2, scaleOptional, pertokenScaleOptional, groupListOptional, logitOptional, and rowIndexOptional are mandatory parameters; biasOptional and sharedInputOptional are optional parameters. The offsetOptional parameter is currently not supported.
386 - When groupListType is 0, groupListOptional must be a non-negative, monotonically non-decreasing sequence (cumulative sum), and the last value must not be greater than the first dimension of the tensor in x1; when groupListType is 1, groupListOptional must be a non-negative array (size of each group), and the sum of the values must not be greater than the first dimension of the tensor in x1.386 - When groupListType is 0, groupListOptional must be a non-negative, monotonically non-decreasing sequence (cumulative sum), and the last value must not be greater than the first dimension of the tensor in x1; when groupListType is 1, groupListOptional must be a non-negative array (size of each group), and the sum of the values must not be greater than the first dimension of the tensor in x1.
387 - batch (the first dimension of out) and sharedInputOffset must be greater than or equal to 0 and less than or equal to m.387 - batch (the first dimension of out) and sharedInputOffset must be greater than or equal to 0 and less than or equal to m.
388- - When sharedInputOptional is not empty, the length of its first dimension is shareInputLen. sharedInputOffset, shareInputLen, and their sum must be less than or equal to batch, the first dimension of out.388+ - When sharedInputOptional is not empty, the length of its first dimension is sharedInputLen. sharedInputOffset, sharedInputLen, and their sum must be less than or equal to batch, the first dimension of out.
389 - x1 supports M being 0, and x2 supports N being 0. Other empty tensor use cases are not supported.389 - x1 supports M being 0, and x2 supports N being 0. Other empty tensor use cases are not supported.
390 390 
391 <!-- end id10 -->391 <!-- end id10 -->
@@ -647,7 +647,7 @@ The following is sample code for reference only. For details about how to compil
647 int64_t batch = 1;647 int64_t batch = 1;
648 int64_t bsdp = 1;648 int64_t bsdp = 1;
649 int64_t dtype = 0;649 int64_t dtype = 0;
650- float shareInputWeight = 1.0;650+ float sharedInputWeight = 1.0;
651 int64_t sharedInputOffset = 0;651 int64_t sharedInputOffset = 0;
652 bool transposeX = false;652 bool transposeX = false;
653 bool transposeW = false;653 bool transposeW = false;
@@ -768,7 +768,7 @@ The following is sample code for reference only. For details about how to compil
768 768 
769 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingV3.769 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingV3.
770 workspaceSize = 0;770 workspaceSize = 0;
771- ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, offset, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);771+ ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, offset, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);
772 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);772 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);
773 return ret);773 return ret);
774 // Allocate device memory based on the workspaceSize calculated by the first-phase API.774 // Allocate device memory based on the workspaceSize calculated by the first-phase API.
@@ -957,7 +957,7 @@ The following is sample code for reference only. For details about how to compil
957 int64_t batch = 8;957 int64_t batch = 8;
958 int64_t bsdp = 1;958 int64_t bsdp = 1;
959 int64_t dtype = 0;959 int64_t dtype = 0;
960- float shareInputWeight = 1.0;960+ float sharedInputWeight = 1.0;
961 int64_t sharedInputOffset = 0;961 int64_t sharedInputOffset = 0;
962 bool transposeX = false;962 bool transposeX = false;
963 bool transposeW = false;963 bool transposeW = false;
@@ -1085,7 +1085,7 @@ The following is sample code for reference only. For details about how to compil
1085 void *workspaceAddr = nullptr;1085 void *workspaceAddr = nullptr;
1086 1086 
1087 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingV3.1087 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingV3.
1088- ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize, &executor);1088+ ret = aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize(x, w, scale, bias, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize, &executor);
1089 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);1089 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingV3GetWorkspaceSize failed. ERROR: %d\n", ret);
1090 return ret);1090 return ret);
1091 // Allocate device memory based on the workspaceSize calculated by the first-phase API.1091 // Allocate device memory based on the workspaceSize calculated by the first-phase API.
@@ -343,7 +343,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
343 - x1、x2、scale、groupList、logit、rowIndex是必选参数,pertokenScaleOptional、sharedInput、bias是可选参数。MxA8W4场景下pertokenScaleOptional为必选参数。目前暂不支持offsetOptional参数,必须为nullptr。343 - x1、x2、scale、groupList、logit、rowIndex是必选参数,pertokenScaleOptional、sharedInput、bias是可选参数。MxA8W4场景下pertokenScaleOptional为必选参数。目前暂不支持offsetOptional参数,必须为nullptr。
344 - 当groupListType为0时,groupList须为非负单调非递减数列(累积和),且最后一个值不大于x1中tensor的第一维;当groupListType为1时,groupList须为非负数组(各组大小),且数值的总和不大于x1中tensor的第一维。344 - 当groupListType为0时,groupList须为非负单调非递减数列(累积和),且最后一个值不大于x1中tensor的第一维;当groupListType为1时,groupList须为非负数组(各组大小),且数值的总和不大于x1中tensor的第一维。
345 - out的第一维batch、sharedInputOffset必须大于等于0,且小于等于m。345 - out的第一维batch、sharedInputOffset必须大于等于0,且小于等于m。
346- - 当sharedInput不为空时,其第一维长度为shareInputLen。sharedInputOffset、shareInputLen以及两者之和均需小于等于out的第一维batch。346+ - 当sharedInput不为空时,其第一维长度为sharedInputLen。sharedInputOffset、sharedInputLen以及两者之和均需小于等于out的第一维batch。
347 - x1支持M为0,x2支持N为0;其他空Tensor场景不支持。347 - x1支持M为0,x2支持N为0;其他空Tensor场景不支持。
348 348 
349 <!-- end id10 -->349 <!-- end id10 -->
@@ -640,7 +640,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
640 int64_t batch = 24;640 int64_t batch = 24;
641 int64_t bsdp = 8;641 int64_t bsdp = 8;
642 int64_t dtype = 0;642 int64_t dtype = 0;
643- float shareInputWeight = 1.0;643+ float sharedInputWeight = 1.0;
644 int64_t sharedInputOffset = 0;644 int64_t sharedInputOffset = 0;
645 bool transposeX = false;645 bool transposeX = false;
646 bool transposeW = false;646 bool transposeW = false;
@@ -763,7 +763,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
763 763 
764 // 调用aclnnGroupedMatmulFinalizeRoutingWeightNzV2第一段接口764 // 调用aclnnGroupedMatmulFinalizeRoutingWeightNzV2第一段接口
765 workspaceSize = 0;765 workspaceSize = 0;
766- ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);766+ ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);
767 767 
768 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);768 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);
769 return ret);769 return ret);
@@ -963,7 +963,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
963 int64_t batch = 24;963 int64_t batch = 24;
964 int64_t bsdp = 8;964 int64_t bsdp = 8;
965 int64_t dtype = 0;965 int64_t dtype = 0;
966- float shareInputWeight = 1.0;966+ float sharedInputWeight = 1.0;
967 int64_t sharedInputOffset = 0;967 int64_t sharedInputOffset = 0;
968 bool transposeX = false;968 bool transposeX = false;
969 bool transposeW = false;969 bool transposeW = false;
@@ -1050,7 +1050,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
1050 // 调用aclnnGroupedMatmulFinalizeRoutingWeightNzV2第一段接口1050 // 调用aclnnGroupedMatmulFinalizeRoutingWeightNzV2第一段接口
1051 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(1051 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(
1052 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,1052 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,
1053- shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,1053+ sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,
1054 &executor);1054 &executor);
1055 CHECK_FREE_RET(ret == ACL_SUCCESS,1055 CHECK_FREE_RET(ret == ACL_SUCCESS,
1056 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);1056 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);
@@ -1313,7 +1313,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
1313 int64_t batch = 24;1313 int64_t batch = 24;
1314 int64_t bsdp = 8;1314 int64_t bsdp = 8;
1315 int64_t dtype = 0;1315 int64_t dtype = 0;
1316- float shareInputWeight = 1.0;1316+ float sharedInputWeight = 1.0;
1317 int64_t sharedInputOffset = 0;1317 int64_t sharedInputOffset = 0;
1318 bool transposeX = false;1318 bool transposeX = false;
1319 bool transposeW = true;1319 bool transposeW = true;
@@ -1416,7 +1416,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
1416 1416 
1417 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(1417 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(
1418 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,1418 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,
1419- shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,1419+ sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,
1420 &executor);1420 &executor);
1421 CHECK_RET(ret == ACL_SUCCESS,1421 CHECK_RET(ret == ACL_SUCCESS,
1422 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);1422 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);
@@ -343,7 +343,7 @@ aclnnStatus aclnnGroupedMatmulFinalizeRoutingWeightNzV2(
343 - x1, x2, scale, groupList, logit, and rowIndex are required parameters; pertokenScaleOptional, sharedInput, and bias are optional parameters. In the MxA8W4 use case, pertokenScaleOptional is a required parameter. Currently, the offsetOptional parameter is not supported and must be nullptr.343 - x1, x2, scale, groupList, logit, and rowIndex are required parameters; pertokenScaleOptional, sharedInput, and bias are optional parameters. In the MxA8W4 use case, pertokenScaleOptional is a required parameter. Currently, the offsetOptional parameter is not supported and must be nullptr.
344 - When groupListType is 0, groupList must be a non-negative monotonically non-decreasing sequence (cumulative sum), and the last value must not be greater than the first dimension of the tensor in x1; when groupListType is 1, groupList must be a non-negative array (size of each group), and the sum of the values must not be greater than the first dimension of the tensor in x1.344 - When groupListType is 0, groupList must be a non-negative monotonically non-decreasing sequence (cumulative sum), and the last value must not be greater than the first dimension of the tensor in x1; when groupListType is 1, groupList must be a non-negative array (size of each group), and the sum of the values must not be greater than the first dimension of the tensor in x1.
345 - The first dimension batch of out and sharedInputOffset must be greater than or equal to 0 and less than or equal to m.345 - The first dimension batch of out and sharedInputOffset must be greater than or equal to 0 and less than or equal to m.
346- - When sharedInput is not empty, its first dimension is shareInputLen. sharedInputOffset, shareInputLen, and their sum must be less than or equal to the first dimension batch of out.346+ - When sharedInput is not empty, its first dimension is sharedInputLen. sharedInputOffset, sharedInputLen, and their sum must be less than or equal to the first dimension batch of out.
347 - x1 supports M = 0 and x2 supports N = 0; other empty tensor use cases are not supported.347 - x1 supports M = 0 and x2 supports N = 0; other empty tensor use cases are not supported.
348 348 
349 <!-- end id10 -->349 <!-- end id10 -->
@@ -628,7 +628,7 @@ The following sample code is for reference only. For details about compilation a
628 int64_t batch = 24;628 int64_t batch = 24;
629 int64_t bsdp = 8;629 int64_t bsdp = 8;
630 int64_t dtype = 0;630 int64_t dtype = 0;
631- float shareInputWeight = 1.0;631+ float sharedInputWeight = 1.0;
632 int64_t sharedInputOffset = 0;632 int64_t sharedInputOffset = 0;
633 bool transposeX = false;633 bool transposeX = false;
634 bool transposeW = false;634 bool transposeW = false;
@@ -751,7 +751,7 @@ The following sample code is for reference only. For details about compilation a
751 751 
752 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingWeightNzV2.752 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingWeightNzV2.
753 workspaceSize = 0;753 workspaceSize = 0;
754- ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);754+ ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, tuningConfig, out, &workspaceSize, &executor);
755 755 
756 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);756 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);
757 return ret);757 return ret);
@@ -951,7 +951,7 @@ The following sample code is for reference only. For details about compilation a
951 int64_t batch = 24;951 int64_t batch = 24;
952 int64_t bsdp = 8;952 int64_t bsdp = 8;
953 int64_t dtype = 0;953 int64_t dtype = 0;
954- float shareInputWeight = 1.0;954+ float sharedInputWeight = 1.0;
955 int64_t sharedInputOffset = 0;955 int64_t sharedInputOffset = 0;
956 bool transposeX = false;956 bool transposeX = false;
957 bool transposeW = false;957 bool transposeW = false;
@@ -1038,7 +1038,7 @@ The following sample code is for reference only. For details about compilation a
1038 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingWeightNzV2.1038 // Call the first-phase API of aclnnGroupedMatmulFinalizeRoutingWeightNzV2.
1039 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(1039 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(
1040 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,1040 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,
1041- shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,1041+ sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,
1042 &executor);1042 &executor);
1043 CHECK_FREE_RET(ret == ACL_SUCCESS,1043 CHECK_FREE_RET(ret == ACL_SUCCESS,
1044 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);1044 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);
@@ -1300,7 +1300,7 @@ The following sample code is for reference only. For details about compilation a
1300 int64_t batch = 24;1300 int64_t batch = 24;
1301 int64_t bsdp = 8;1301 int64_t bsdp = 8;
1302 int64_t dtype = 0;1302 int64_t dtype = 0;
1303- float shareInputWeight = 1.0;1303+ float sharedInputWeight = 1.0;
1304 int64_t sharedInputOffset = 0;1304 int64_t sharedInputOffset = 0;
1305 bool transposeX = false;1305 bool transposeX = false;
1306 bool transposeW = true;1306 bool transposeW = true;
@@ -1403,7 +1403,7 @@ The following sample code is for reference only. For details about compilation a
1403 1403 
1404 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(1404 ret = aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize(
1405 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,1405 x, w, scale, nullptr, nullptr, nullptr, nullptr, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype,
1406- shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,1406+ sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, nullptr, out, &workspaceSize,
1407 &executor);1407 &executor);
1408 CHECK_RET(ret == ACL_SUCCESS,1408 CHECK_RET(ret == ACL_SUCCESS,
1409 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);1409 LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingWeightNzV2GetWorkspaceSize failed. ERROR: %d\n", ret);
@@ -493,7 +493,7 @@ The following sample code is for reference only. For details about compilation a
493 int64_t batch = 8;493 int64_t batch = 8;
494 int64_t bsdp = 1;494 int64_t bsdp = 1;
495 int64_t dtype = 0;495 int64_t dtype = 0;
496- float shareInputWeight = 1.0;496+ float sharedInputWeight = 1.0;
497 int64_t sharedInputOffset = 0;497 int64_t sharedInputOffset = 0;
498 bool transposeX = false;498 bool transposeX = false;
499 bool transposeW = false;499 bool transposeW = false;
@@ -602,7 +602,7 @@ The following sample code is for reference only. For details about compilation a
602 602 
603 // Call the first-phase API of aclnnGroupedMatmulFinalizeRouting.603 // Call the first-phase API of aclnnGroupedMatmulFinalizeRouting.
604 workspaceSize = 0;604 workspaceSize = 0;
605- ret = aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize(x, w, scale, bias, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, shareInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);605+ ret = aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize(x, w, scale, bias, pertokenScale, groupList, sharedInput, logit, rowIndex, dtype, sharedInputWeight, sharedInputOffset, transposeX, transposeW, groupListType, out, &workspaceSize, &executor);
606 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize failed. ERROR: %d\n", ret);606 CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnGroupedMatmulFinalizeRoutingGetWorkspaceSize failed. ERROR: %d\n", ret);
607 return ret);607 return ret);
608 // Allocate device memory based on the workspaceSize calculated by the first-phase API.608 // Allocate device memory based on the workspaceSize calculated by the first-phase API.
@@ -23,7 +23,7 @@
23 23 
24## 功能说明24## 功能说明
25 25 
26-- 接口功能:融合GroupedMatmul 、dquant、swiglu和quant,详细解释见计算公式。26+- 接口功能:融合GroupedMatmul 、dequant、swiglu和quant,详细解释见计算公式。
27 27 
28- 计算公式:28- 计算公式:
29 29 
@@ -23,7 +23,7 @@
23 23 
24## 功能说明24## 功能说明
25 25 
26-- 接口功能:融合GroupedMatmul、dquant、swiglu和quant,详细解释见计算公式,[aclnnGroupedMatmulSwigluQuant](./aclnnGroupedMatmulSwigluQuant.md)接口的weightNZ特化版本。26+- 接口功能:融合GroupedMatmul、dequant、swiglu和quant,详细解释见计算公式,[aclnnGroupedMatmulSwigluQuant](./aclnnGroupedMatmulSwigluQuant.md)接口的weightNZ特化版本。
27 27 
28- 计算公式:28- 计算公式:
29 29 
@@ -25,7 +25,7 @@
25 25 
26## Function26## Function
27 27 
28-- Description: Fuses GroupedMatmul, dquant, swiglu, and quant. For details, see the formula. This is a weightNZ-specific version of the [aclnnGroupedMatmulSwigluQuant](./aclnnGroupedMatmulSwigluQuant_en.md) API.28+- Description: Fuses GroupedMatmul, dequant, swiglu, and quant. For details, see the formula. This is a weightNZ-specific version of the [aclnnGroupedMatmulSwigluQuant](./aclnnGroupedMatmulSwigluQuant_en.md) API.
29 29 
30- Formula:30- Formula:
31 31 
@@ -25,7 +25,7 @@
25 25 
26## Function26## Function
27 27 
28-- Description: Fuses GroupedMatmul, dquant, swiglu, and quant. For details, see Formula.28+- Description: Fuses GroupedMatmul, dequant, swiglu, and quant. For details, see Formula.
29 29 
30- Formula:30- Formula:
31 31 
@@ -274,7 +274,7 @@
274 274 
275 * $X∈\mathbb{Z_8}^{M \times K}$:激活矩阵(左矩阵),M是总token数,K是特征维度。275 * $X∈\mathbb{Z_8}^{M \times K}$:激活矩阵(左矩阵),M是总token数,K是特征维度。
276 * $W∈\mathbb{Z_8}^{E \times K \times N}$:分组权重矩阵(右矩阵),E是专家个数,K是特征维度,N是输出维度。276 * $W∈\mathbb{Z_8}^{E \times K \times N}$:分组权重矩阵(右矩阵),E是专家个数,K是特征维度,N是输出维度。
277- * $w\_scale∈\mathbb{R}^{E \times N}$:分组权重矩阵(右矩阵)的逐通道缩放因子,E是专家个数,K是特征维度, N是输出维度。277+ * $w\_scale∈\mathbb{R}^{E \times N}$:分组权重矩阵(右矩阵)的逐通道缩放因子,E是专家个数,N是输出维度。
278 * $x\_scale∈\mathbb{R}^{M}$:激活矩阵(左矩阵)的逐token缩放因子,M是总token数,K是特征维度。278 * $x\_scale∈\mathbb{R}^{M}$:激活矩阵(左矩阵)的逐token缩放因子,M是总token数,K是特征维度。
279 * $grouplist∈\mathbb{N}^{E}$:cumsum或count的分组索引列表。279 * $grouplist∈\mathbb{N}^{E}$:cumsum或count的分组索引列表。
280 - **输出**:280 - **输出**:
@@ -276,7 +276,7 @@
276 276 
277 - $X∈\mathbb{Z_8}^{M \times K}$: activation matrix (left matrix), where M is the total number of tokens and K is the feature dimension.277 - $X∈\mathbb{Z_8}^{M \times K}$: activation matrix (left matrix), where M is the total number of tokens and K is the feature dimension.
278 - $W∈\mathbb{Z_8}^{E \times K \times N}$: grouped weight matrix (right matrix), where E is the number of experts, K is the feature dimension, and N is the output dimension.278 - $W∈\mathbb{Z_8}^{E \times K \times N}$: grouped weight matrix (right matrix), where E is the number of experts, K is the feature dimension, and N is the output dimension.
279- - $w\_scale∈\mathbb{R}^{E \times N}$: per-channel scaling factor of the grouped weight matrix (right matrix), E is the number of experts, K is the feature dimension, N is the output dimension.279+ - $w\_scale∈\mathbb{R}^{E \times N}$: per-channel scaling factor of the grouped weight matrix (right matrix), E is the number of experts, N is the output dimension.
280 - $x\_scale∈\mathbb{R}^{M}$: per-token scaling factor of the activation matrix (left matrix), M is the total number of tokens, K is the feature dimension.280 - $x\_scale∈\mathbb{R}^{M}$: per-token scaling factor of the activation matrix (left matrix), M is the total number of tokens, K is the feature dimension.
281 - $grouplist∈\mathbb{N}^{E}$: group index list of cumsum or count.281 - $grouplist∈\mathbb{N}^{E}$: group index list of cumsum or count.
282 - **Output**:282 - **Output**:
@@ -29,7 +29,7 @@
29- **Formula**:29- **Formula**:
30 30 
31 $$31 $$
32- ataOut = AllToAllV(expandX)\\32+ dataOut = AllToAllV(expandX)\\
33 $$33 $$
34 34 
35 Data is returned along the same path used by the MoeDistributeDispatchSetup and MoeDistributeDispatchTeardown operators to collect data. This operator only sends communication status and communication data, and exits immediately after the data is sent without waiting for communication completion. Communication status confirmation and data post-processing are completed by aclnnMoeDistributeCombineTeardown.35 Data is returned along the same path used by the MoeDistributeDispatchSetup and MoeDistributeDispatchTeardown operators to collect data. This operator only sends communication status and communication data, and exits immediately after the data is sent without waiting for communication completion. Communication status confirmation and data post-processing are completed by aclnnMoeDistributeCombineTeardown.
@@ -29,8 +29,8 @@
29- **Formula**:29- **Formula**:
30 30 
31 $$31 $$
32- ataOut = AllToAllV(expandX)\\32+ dataOut = AllToAllV(expandX)\\
33- xOut = Sum(expertScales * ataOut + expertScales * sharedExpertX)33+ xOut = Sum(expertScales * dataOut + expertScales * sharedExpertX)
34 $$34 $$
35 35 
36 Data collected by the MoeDistributeDispatchSetup and MoeDistributeDispatchTeardown operators is returned along the original path. This operator only performs communication status confirmation and data sorting. It confirms the communication status of the data sent by the aclnnMoeDistributeCombineSetup API and performs a weighted sum based on the expert scale weights.36 Data collected by the MoeDistributeDispatchSetup and MoeDistributeDispatchTeardown operators is returned along the original path. This operator only performs communication status confirmation and data sorting. It confirms the communication status of the data sent by the aclnnMoeDistributeCombineSetup API and performs a weighted sum based on the expert scale weights.
@@ -330,7 +330,7 @@ aclnnStatus aclnnMoeDistributeCombineV2(
330 <td>sharedExpertRankNum</td>330 <td>sharedExpertRankNum</td>
331 <td>输入</td>331 <td>输入</td>
332 <td>共享专家卡数量。(一个共享专家可复制部署到多个卡上)</td>332 <td>共享专家卡数量。(一个共享专家可复制部署到多个卡上)</td>
333- <td>数据类型需与expandX保持一致。</td>333+ <td>-</td>
334 <td>INT64</td>334 <td>INT64</td>
335 <td>-</td>335 <td>-</td>
336 <td>-</td>336 <td>-</td>
@@ -332,7 +332,7 @@ aclnnStatus aclnnMoeDistributeCombineV2(
332 <td>sharedExpertRankNum</td>332 <td>sharedExpertRankNum</td>
333 <td>Input</td>333 <td>Input</td>
334 <td>Number of devices for shared experts. (One shared expert can be copied and deployed to multiple devices)</td>334 <td>Number of devices for shared experts. (One shared expert can be copied and deployed to multiple devices)</td>
335- <td>The data type must be the same as that of expandX.</td>335+ <td>-</td>
336 <td>INT64</td>336 <td>INT64</td>
337 <td>-</td>337 <td>-</td>
338 <td>-</td>338 <td>-</td>
@@ -27,8 +27,8 @@
27- 计算公式:27- 计算公式:
28 28 
29 $$29 $$
30- ataOut = AllToAllV(expandX)\\30+ dataOut = AllToAllV(expandX)\\
31- xOut = Sum(expertScales * ataOut) + sharedExpertX31+ xOut = Sum(expertScales * dataOut) + sharedExpertX
32 $$32 $$
33 33 
34 `expertScales`为空Tensor时,路由专家结果直接求和;若传入`sharedExpertXOptional`,仍直接累加,不乘路由权重。34 `expertScales`为空Tensor时,路由专家结果直接求和;若传入`sharedExpertXOptional`,仍直接累加,不乘路由权重。
@@ -29,8 +29,8 @@
29- Formula:29- Formula:
30 30 
31 $$31 $$
32- ataOut = AllToAllV(expandX)\\32+ dataOut = AllToAllV(expandX)\\
33- xOut = Sum(expertScales * ataOut + expertScales * sharedExpertX)33+ xOut = Sum(expertScales * dataOut) + sharedExpertX
34 $$34 $$
35 35 
36 When `expertScales` is an empty tensor, weight multiplication is skipped and the expert outputs are summed directly.36 When `expertScales` is an empty tensor, weight multiplication is skipped and the expert outputs are summed directly.
@@ -630,9 +630,9 @@ aclnnStatus aclnnMoeDistributeDispatchSetupTeardownCalcOutputSize(
630 <td>-</td>630 <td>-</td>
631 </tr>631 </tr>
632 <tr>632 <tr>
633- <td>assisInfoForCombineOutSize</td>633+ <td>assistInfoForCombineOutSize</td>
634 <td>Output</td>634 <td>Output</td>
635- <td>Memory size of assisInfoForCombineOut of the aclnnMoeDistributeDispatchSetup API.</td>635+ <td>Memory size of assistInfoForCombineOut of the aclnnMoeDistributeDispatchSetup API.</td>
636 <td>-</td>636 <td>-</td>
637 <td>INT64</td>637 <td>INT64</td>
638 <td>-</td>638 <td>-</td>
@@ -43,7 +43,7 @@
43 43 
44 其中的Reduce计算是将来自不同rank的数据进行reduce计算。44 其中的Reduce计算是将来自不同rank的数据进行reduce计算。
45 45 
46- - 情形1:如果x数据类型为float8_e4m3fn、float8_e5m2、int8和hifloat8,入参scale为float32且shape维度与x相同,则先进行reduce_scatter通信,然后进行pertoken-pergroup反量化,得到bfloat16、float16或者float32数据类型的输出。46+ - 情形1:如果x数据类型为float8_e4m3fn、float8_e5m2、int8和hifloat8,入参scales为float32且维数与x相同,则先进行reduce_scatter通信,然后进行pertoken-pergroup反量化,得到bfloat16、float16或者float32数据类型的输出。
47 47 
48 - 情形2:如果x数据类型为float8_e4m3fn、float8_e5m2,入参scales为float8_e8m0,则先进行reduce_scatter通信,然后进行MX反量化,得到bfloat16、float16或者float32数据类型的输出。48 - 情形2:如果x数据类型为float8_e4m3fn、float8_e5m2,入参scales为float8_e8m0,则先进行reduce_scatter通信,然后进行MX反量化,得到bfloat16、float16或者float32数据类型的输出。
49 49 
@@ -45,7 +45,7 @@
45 45 
46 The Reduce computation here performs a reduce operation on data from different ranks.46 The Reduce computation here performs a reduce operation on data from different ranks.
47 47 
48- - Case 1: If x is of the float8_e4m3fn, float8_e5m2, int8, or hifloat8 data type and the input parameter scale is float32, reduce_scatter communication is performed first, followed by pertoken-pergroup dequantization. The output is of the bfloat16, float16, or float32 data type.48+ - Case 1: If x is of the float8_e4m3fn, float8_e5m2, int8, or hifloat8 data type and the input parameter scales is float32 and has the same number of dimensions as x, reduce_scatter communication is performed first, followed by pertoken-pergroup dequantization. The output is of the bfloat16, float16, or float32 data type.
49 49 
50 - Case 2: If x is of the float8_e4m3fn or float8_e5m2 data type and the input parameter scales is float8_e8m0, reduce_scatter communication is performed first, followed by MX dequantization. The output is of the bfloat16, float16, or float32 data type.50 - Case 2: If x is of the float8_e4m3fn or float8_e5m2 data type and the input parameter scales is float8_e8m0, reduce_scatter communication is performed first, followed by MX dequantization. The output is of the bfloat16, float16, or float32 data type.
51 51 
@@ -23,7 +23,7 @@
23 23 
24## 功能说明24## 功能说明
25 25 
26-- 接口功能:mhc_post基于一系列计算对MHC(Manifold-Constrained Hyper-Connection)架构中上一层输出$h_{t}^{out}$进行Post Mapping,对上一层的输入$x_j$进行Res Mapping,然后对二者进行残差连接,得到下一层的输入$x_{l+1}$。该算子实现前述过程的反向功能。26+- 接口功能:mhc_post基于一系列计算对MHC(Manifold-Constrained Hyper-Connection)架构中上一层输出$h_{t}^{out}$进行Post Mapping,对上一层的输入$x_l$进行Res Mapping,然后对二者进行残差连接,得到下一层的输入$x_{l+1}$。该算子实现前述过程的反向功能。
27 27 
28- 计算公式:28- 计算公式:
29 29 
@@ -208,7 +208,7 @@ aclnnStatus aclnnMhcPostBackward(
208 <tr>208 <tr>
209 <td>gradHPost</td>209 <td>gradHPost</td>
210 <td>输出</td>210 <td>输出</td>
211- <td>网络中MHC层的输入数据h_post的梯度</td>211+ <td>网络中MHC层的输入数据hPost的梯度</td>
212 <td>-</td>212 <td>-</td>
213 <td>数据类型与hPost一致</td>213 <td>数据类型与hPost一致</td>
214 <td>ND</td>214 <td>ND</td>
@@ -25,7 +25,7 @@
25 25 
26## Function26## Function
27 27 
28-- Description: mhc_post performs Post Mapping on the previous layer output $h_{t}^{out}$ in the MHC (Manifold-Constrained Hyper-Connection) architecture through a series of computations, performs ResMapping on the previous layer input $x_j$, and then performs residual connection on the two to obtain the next layer input $x_{l+1}$. This operator implements the backward function of the preceding process.28+- Description: mhc_post performs Post Mapping on the previous layer output $h_{t}^{out}$ in the MHC (Manifold-Constrained Hyper-Connection) architecture through a series of computations, performs ResMapping on the previous layer input $x_l$, and then performs residual connection on the two to obtain the next layer input $x_{l+1}$. This operator implements the backward function of the preceding process.
29 29 
30- Formula:30- Formula:
31 31 
@@ -205,7 +205,7 @@ aclnnStatus aclnnMhcPostBackward(
205 <tr>205 <tr>
206 <td>gradHPost</td>206 <td>gradHPost</td>
207 <td>Output</td>207 <td>Output</td>
208- <td>Gradient of the MHC layer input data h_post in the network.</td>208+ <td>Gradient of the MHC layer input data hPost in the network.</td>
209 <td>-</td>209 <td>-</td>
210 <td>Data type consistent with hPost</td>210 <td>Data type consistent with hPost</td>
211 <td>ND</td>211 <td>ND</td>
@@ -23,7 +23,7 @@
23 23 
24## 功能说明24## 功能说明
25 25 
26-- 接口功能:MhcPreBackward是MhcPre的反向算子,MhcPre算子基于一系列计算得到mHC(Manifold-Constrained Hyper-Connections)架构中的$H^{res}$和$H^{post}$投影矩阵以及Atten或MLP层的输入矩阵$h^{in}$。26+- 接口功能:MhcPreBackward是MhcPre的反向算子,MhcPre算子基于一系列计算得到mHC(Manifold-Constrained Hyper-Connections)架构中的$H^{res}$和$H^{post}$投影矩阵以及Attention或MLP层的输入矩阵$h^{in}$。
27 27 
28- 计算公式:28- 计算公式:
29 29 
@@ -25,7 +25,7 @@
25 25 
26## Function26## Function
27 27 
28-- Description: MhcPreBackward is the backward operator of MhcPre. The MhcPre operator obtains the $H^{res}$ and $H^{post}$ projection matrices and the Atten or MLP layer input matrix $h^{in}$ in the mHC (Manifold-Constrained Hyper-Connections) architecture through a series of computations.28+- Description: MhcPreBackward is the backward operator of MhcPre. The MhcPre operator obtains the $H^{res}$ and $H^{post}$ projection matrices and the Attention or MLP layer input matrix $h^{in}$ in the mHC (Manifold-Constrained Hyper-Connections) architecture through a series of computations.
29 29 
30- Formula:30- Formula:
31 31 
@@ -278,7 +278,7 @@ aclnnStatus aclnnMhcPreBackward(
278 <tr>278 <tr>
279 <td>gradHIn (aclTensor*)</td>279 <td>gradHIn (aclTensor*)</td>
280 <td>Input</td>280 <td>Input</td>
281- <td>hIn serves as the layer input of the Atten/MLP layers. Outputs the corresponding gradient of the forward output hIn.</td>281+ <td>hIn serves as the layer input of the Attention/MLP layers. Outputs the corresponding gradient of the forward output hIn.</td>
282 <td><ul><li>Empty tensors are not supported.</li><li>shape is (B, S, D) or (T, D). Where B keeps consistent with the B of `x`; S keeps consistent with the S of `x`; T=B*S; D keeps consistent with the D of `x`.</li></ul></td>282 <td><ul><li>Empty tensors are not supported.</li><li>shape is (B, S, D) or (T, D). Where B keeps consistent with the B of `x`; S keeps consistent with the S of `x`; T=B*S; D keeps consistent with the D of `x`.</li></ul></td>
283 <td>BFLOAT16, FLOAT16</td>283 <td>BFLOAT16, FLOAT16</td>
284 <td>ND</td>284 <td>ND</td>
@@ -39,7 +39,7 @@ $$
39\end{aligned}39\end{aligned}
40$$40$$
41 41 
42-第$i$次迭代($i = 1, 2, \dots, \mathbf({num\_iters}-1)$):42+第$i$次迭代($i = 1, 2, \dots, \mathbf{num\_iters}-1$):
43 43 
44$$44$$
45\begin{aligned}45\begin{aligned}
@@ -41,7 +41,7 @@ $$
41\end{aligned}41\end{aligned}
42$$42$$
43 43 
44-Iteration $i$ ($i = 1, 2, \dots, \mathbf({num\_iters}-1)$):44+Iteration $i$ ($i = 1, 2, \dots, \mathbf{num\_iters}-1$):
45 45 
46$$46$$
47\begin{aligned}47\begin{aligned}
@@ -389,7 +389,7 @@ int main() {
389 // 创建bias aclTensor389 // 创建bias aclTensor
390 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);390 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);
391 CHECK_RET(ret == ACL_SUCCESS, return ret);391 CHECK_RET(ret == ACL_SUCCESS, return ret);
392- // 创建scale aclTensor392+ // 创建scales aclTensor
393 ret = CreateAclTensor(scalesHostData, scalesShape, &scalesDeviceAddr, aclDataType::ACL_FLOAT, &scales);393 ret = CreateAclTensor(scalesHostData, scalesShape, &scalesDeviceAddr, aclDataType::ACL_FLOAT, &scales);
394 CHECK_RET(ret == ACL_SUCCESS, return ret);394 CHECK_RET(ret == ACL_SUCCESS, return ret);
395 395 
@@ -391,7 +391,7 @@ int main() {
391 // Create bias aclTensor.391 // Create bias aclTensor.
392 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);392 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);
393 CHECK_RET(ret == ACL_SUCCESS, return ret);393 CHECK_RET(ret == ACL_SUCCESS, return ret);
394- // Create scale aclTensor.394+ // Create scales aclTensor.
395 ret = CreateAclTensor(scalesHostData, scalesShape, &scalesDeviceAddr, aclDataType::ACL_FLOAT, &scales);395 ret = CreateAclTensor(scalesHostData, scalesShape, &scalesDeviceAddr, aclDataType::ACL_FLOAT, &scales);
396 CHECK_RET(ret == ACL_SUCCESS, return ret);396 CHECK_RET(ret == ACL_SUCCESS, return ret);
397 397 
@@ -78,7 +78,7 @@
78每个算子分为[两段式接口](../../../docs/zh/context/two_phase_api.md),必须先调用“aclnnMoeFusedTopkGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnMoeFusedTopk”接口执行计算。78每个算子分为[两段式接口](../../../docs/zh/context/two_phase_api.md),必须先调用“aclnnMoeFusedTopkGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnMoeFusedTopk”接口执行计算。
79 79 
80```Cpp80```Cpp
81-aclnnMoeFusedTopkGetWorkspaceSize(81+aclnnStatus aclnnMoeFusedTopkGetWorkspaceSize(
82 const aclTensor* x,82 const aclTensor* x,
83 const aclTensor* addNum,83 const aclTensor* addNum,
84 const aclTensor* mappingNum,84 const aclTensor* mappingNum,
@@ -71,7 +71,7 @@
71Each operator uses a [two-phase API](../../../docs/en/context/two_phase_api.md). You must first call the "aclnnMoeFusedTopkGetWorkspaceSize" API to obtain the workspace size required for computation and the executor that contains the operator computation process, and then call the "aclnnMoeFusedTopk" API to perform the computation.71Each operator uses a [two-phase API](../../../docs/en/context/two_phase_api.md). You must first call the "aclnnMoeFusedTopkGetWorkspaceSize" API to obtain the workspace size required for computation and the executor that contains the operator computation process, and then call the "aclnnMoeFusedTopk" API to perform the computation.
72 72 
73```Cpp73```Cpp
74-aclnnMoeFusedTopkGetWorkspaceSize(74+aclnnStatus aclnnMoeFusedTopkGetWorkspaceSize(
75 const aclTensor* x,75 const aclTensor* x,
76 const aclTensor* addNum,76 const aclTensor* addNum,
77 const aclTensor* mappingNum,77 const aclTensor* mappingNum,
@@ -556,7 +556,7 @@ int main() {
556 // 创建bias aclTensor556 // 创建bias aclTensor
557 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);557 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);
558 CHECK_RET(ret == ACL_SUCCESS, return ret);558 CHECK_RET(ret == ACL_SUCCESS, return ret);
559- // 创建expertForSourceRow aclTensor559+ // 创建out aclTensor
560 ret = CreateAclTensor(outHostData, outShape, &outAddr, aclDataType::ACL_FLOAT, &out);560 ret = CreateAclTensor(outHostData, outShape, &outAddr, aclDataType::ACL_FLOAT, &out);
561 CHECK_RET(ret == ACL_SUCCESS, return ret);561 CHECK_RET(ret == ACL_SUCCESS, return ret);
562 // 创建expertIdOut aclTensor562 // 创建expertIdOut aclTensor
@@ -555,7 +555,7 @@ int main() {
555 // Create the expandedPermutedRows aclTensor.555 // Create the expandedPermutedRows aclTensor.
556 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);556 ret = CreateAclTensor(biasHostData, biasShape, &biasAddr, aclDataType::ACL_FLOAT, &bias);
557 CHECK_RET(ret == ACL_SUCCESS, return ret);557 CHECK_RET(ret == ACL_SUCCESS, return ret);
558- // Create the expertForSourceRow aclTensor.558+ // Create the out aclTensor.
559 ret = CreateAclTensor(outHostData, outShape, &outAddr, aclDataType::ACL_FLOAT, &out);559 ret = CreateAclTensor(outHostData, outShape, &outAddr, aclDataType::ACL_FLOAT, &out);
560 CHECK_RET(ret == ACL_SUCCESS, return ret);560 CHECK_RET(ret == ACL_SUCCESS, return ret);
561 // Create the expandedSrcToDstRow aclTensor.561 // Create the expandedSrcToDstRow aclTensor.
@@ -169,7 +169,7 @@ aclnnStatus aclnnApplyRotaryPosEmbGrad(
169 <tr>169 <tr>
170 <td>queryOptional</td>170 <td>queryOptional</td>
171 <td>可选输入</td>171 <td>可选输入</td>
172- <td>正向计算输入query,空指针时不计算gradCosOutOptional和gradSinOutOptional。</td>172+ <td>正向计算输入query,空指针时不计算gradCosOut和gradSinOut。</td>
173 <td>与gradQueryEmbed的数据类型和维度一致,必须与keyOptional同时传入或同时不传入。</td>173 <td>与gradQueryEmbed的数据类型和维度一致,必须与keyOptional同时传入或同时不传入。</td>
174 <td>BFLOAT16、FLOAT16、FLOAT32</td>174 <td>BFLOAT16、FLOAT16、FLOAT32</td>
175 <td>ND</td>175 <td>ND</td>
@@ -179,7 +179,7 @@ aclnnStatus aclnnApplyRotaryPosEmbGrad(
179 <tr>179 <tr>
180 <td>keyOptional</td>180 <td>keyOptional</td>
181 <td>可选输入</td>181 <td>可选输入</td>
182- <td>正向计算输入key,空指针时不计算gradCosOutOptional和gradSinOutOptional。</td>182+ <td>正向计算输入key,空指针时不计算gradCosOut和gradSinOut。</td>
183 <td>与gradQueryEmbed的数据类型和维度一致,必须与queryOptional同时传入或同时不传入。</td>183 <td>与gradQueryEmbed的数据类型和维度一致,必须与queryOptional同时传入或同时不传入。</td>
184 <td>BFLOAT16、FLOAT16、FLOAT32</td>184 <td>BFLOAT16、FLOAT16、FLOAT32</td>
185 <td>ND</td>185 <td>ND</td>
@@ -357,7 +357,7 @@ aclnnStatus aclnnApplyRotaryPosEmbGrad(
357 - `gradQueryEmbed`、`gradQueryOut`的shape必须相同,`gradKeyEmbed`、`gradKeyOut`的shape必须相同。357 - `gradQueryEmbed`、`gradQueryOut`的shape必须相同,`gradKeyEmbed`、`gradKeyOut`的shape必须相同。
358 - 对于任意`layout`,`gradQueryEmbed`和`gradKeyEmbed`除N维度外其它维度必须相同。358 - 对于任意`layout`,`gradQueryEmbed`和`gradKeyEmbed`除N维度外其它维度必须相同。
359 - `cos`、`sin`的N维度必须等于1;`layout`为1(BSND)或2(SBND)时,`cos`、`sin`的B维度可以等于1,也可以和`gradQueryEmbed`的B维度一致;`layout`为4(TND)时,`cos`、`sin`的T维度必须和`gradQueryEmbed`的T维度一致;除N(及BSND、SBND布局下可选广播的B)维度外,其余维度需与`gradQueryEmbed`一致。359 - `cos`、`sin`的N维度必须等于1;`layout`为1(BSND)或2(SBND)时,`cos`、`sin`的B维度可以等于1,也可以和`gradQueryEmbed`的B维度一致;`layout`为4(TND)时,`cos`、`sin`的T维度必须和`gradQueryEmbed`的T维度一致;除N(及BSND、SBND布局下可选广播的B)维度外,其余维度需与`gradQueryEmbed`一致。
360- - `cos`、`sin`、`gradCosOutOptional`、`gradSinOutOptional`的shape必须相同。360+ - `cos`、`sin`、`gradCosOut`、`gradSinOut`的shape必须相同。
361 - `query`维度需与`gradQueryEmbed`一致,`key`维度需与`gradKeyEmbed`一致,且`query`和`key`必须同时传入或同时不传入。361 - `query`维度需与`gradQueryEmbed`一致,`key`维度需与`gradKeyEmbed`一致,且`query`和`key`必须同时传入或同时不传入。
362 - `rotaryModeOptional`仅支持"half"。362 - `rotaryModeOptional`仅支持"half"。
363 - `layout`仅支持{1, 2, 4},对应{BSND, SBND, TND}。363 - `layout`仅支持{1, 2, 4},对应{BSND, SBND, TND}。
@@ -171,7 +171,7 @@ aclnnStatus aclnnApplyRotaryPosEmbGrad(
171 <tr>171 <tr>
172 <td>queryOptional</td>172 <td>queryOptional</td>
173 <td>Optional input</td>173 <td>Optional input</td>
174- <td>Query of the forward computation. If the pointer is null, gradCosOutOptional and gradSinOutOptional are not computed.</td>174+ <td>Query of the forward computation. If the pointer is null, gradCosOut and gradSinOut are not computed.</td>
175 <td>Must be consistent with gradQueryEmbed in data type and dimensions, and must be passed in together with keyOptional or not passed in.</td>175 <td>Must be consistent with gradQueryEmbed in data type and dimensions, and must be passed in together with keyOptional or not passed in.</td>
176 <td>BFLOAT16, FLOAT16, FLOAT32</td>176 <td>BFLOAT16, FLOAT16, FLOAT32</td>
177 <td>ND</td>177 <td>ND</td>
@@ -181,7 +181,7 @@ aclnnStatus aclnnApplyRotaryPosEmbGrad(
181 <tr>181 <tr>
182 <td>keyOptional</td>182 <td>keyOptional</td>
183 <td>Optional input</td>183 <td>Optional input</td>
184- <td>Forward computation input key. If it is a null pointer, gradCosOutOptional and gradSinOutOptional are not computed.</td>184+ <td>Forward computation input key. If it is a null pointer, gradCosOut and gradSinOut are not computed.</td>
185 <td>The data type and dimensions must be the same as those of gradQueryEmbed. Must be passed in together with queryOptional or omitted together.</td>185 <td>The data type and dimensions must be the same as those of gradQueryEmbed. Must be passed in together with queryOptional or omitted together.</td>
186 <td>BFLOAT16, FLOAT16, FLOAT32</td>186 <td>BFLOAT16, FLOAT16, FLOAT32</td>
187 <td>ND</td>187 <td>ND</td>
@@ -359,7 +359,7 @@ aclnnStatus aclnnApplyRotaryPosEmbGrad(
359 - The shape of `gradQueryEmbed` and `gradQueryOut` must be the same, and the shape of `gradKeyEmbed` and `gradKeyOut` must be the same.359 - The shape of `gradQueryEmbed` and `gradQueryOut` must be the same, and the shape of `gradKeyEmbed` and `gradKeyOut` must be the same.
360 - For any `layout`, all dimensions except N must be the same between `gradQueryEmbed` and `gradKeyEmbed`.360 - For any `layout`, all dimensions except N must be the same between `gradQueryEmbed` and `gradKeyEmbed`.
361 - The N dimension of `cos` and `sin` must be equal to 1. If `layout` is 1 (BSND) or 2 (SBND), the B dimension of `cos` and `sin` can be 1 or consistent with the B dimension of `gradQueryEmbed`. If `layout` is 4 (TND), the T dimension of `cos` and `sin` must be consistent with the T dimension of `gradQueryEmbed`. All dimensions except N (and the optionally broadcast B dimension under BSND and SBND layouts) must be consistent with those of `gradQueryEmbed`.361 - The N dimension of `cos` and `sin` must be equal to 1. If `layout` is 1 (BSND) or 2 (SBND), the B dimension of `cos` and `sin` can be 1 or consistent with the B dimension of `gradQueryEmbed`. If `layout` is 4 (TND), the T dimension of `cos` and `sin` must be consistent with the T dimension of `gradQueryEmbed`. All dimensions except N (and the optionally broadcast B dimension under BSND and SBND layouts) must be consistent with those of `gradQueryEmbed`.
362- - The shapes of `cos`, `sin`, `gradCosOutOptional`, and `gradSinOutOptional` must be the same.362+ - The shapes of `cos`, `sin`, `gradCosOut`, and `gradSinOut` must be the same.
363 - The dimensions of `query` must be consistent with `gradQueryEmbed`, and the dimensions of `key` must be consistent with `gradKeyEmbed`. `query` and `key` must be both passed in or both omitted.363 - The dimensions of `query` must be consistent with `gradQueryEmbed`, and the dimensions of `key` must be consistent with `gradKeyEmbed`. `query` and `key` must be both passed in or both omitted.
364 - `rotaryModeOptional` only supports "half".364 - `rotaryModeOptional` only supports "half".
365 - `layout` only supports {1, 2, 4}, corresponding to {BSND, SBND, TND}.365 - `layout` only supports {1, 2, 4}, corresponding to {BSND, SBND, TND}.
@@ -19,20 +19,22 @@
19 - 旋转位置编码(Rope)支持Interleave和Half类型。19 - 旋转位置编码(Rope)支持Interleave和Half类型。
20 - 特征拼接(Concat)支持在sequence维度上进行拼接,拼接有顺序区别。20 - 特征拼接(Concat)支持在sequence维度上进行拼接,拼接有顺序区别。
21 21 
22-- 计算公式(以Query(视频)和EncoderQuery(文本)为例):22+- 计算公式(以Query(视频)和EncoderQuery(文本)为例,`concatOrder=0`):
23 23 
24 $$24 $$
25 hiddenState_q = \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\25 hiddenState_q = \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\
26- hiddenState_{eq} = \text{Norm}(encoderQuery, normEncoderQueryWeight, normEncoderQueryBias, eps) \\26+ hiddenState_{eq} = \text{Norm}(encoderQuery, normAddedQueryWeight, normAddedQueryBias, eps) \\
27 concatenatedHiddenState = \text{Concat}(hiddenState_q, hiddenState_{eq}) \\27 concatenatedHiddenState = \text{Concat}(hiddenState_q, hiddenState_{eq}) \\
28 transposedHiddenState = \text{Transpose}(concatenatedHiddenState, (0, 2, 1, 3)) \\28 transposedHiddenState = \text{Transpose}(concatenatedHiddenState, (0, 2, 1, 3)) \\
29- hiddenState = \text{RoPE}(concatenatedHiddenState, ropeSin, ropeCos)29+ hiddenState = \text{RoPE}(transposedHiddenState, ropeSin, ropeCos)
30 $$30 $$
31 31 
32+ 当`ropeType`为`NONE`时,RoPE不做变换;其他模式下,RoPE仅作用于拼接后序列的前`seqRope`个位置,其余位置不变。
33+ 
32- 说明:34- 说明:
33 35 
34- 1. 输入输出布局如下:输入`query`的shape为`(B, S, N, D)`,输出`hiddenState`的shape为`(B, N, S, D)`,其中36+ 1. 输入输出布局如下:输入`query`的shape为`(B, S_q, N, D)`,`encoderQuery`的shape为`(B, S_eq, N, D)`,输出`hiddenState`的shape为`(B, N, S_q + S_eq, D)`,其中
35- B为batch,S为sequenceLen,N为headNum,D为headDim。37+ `B`为批次大小,`S_q`和`S_eq`分别为`query`和`encoderQuery`的序列长度,`N`为注意力头数,`D`为头维度。
36 2. Norm有五种模式(`normType`):`NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`,其中:38 2. Norm有五种模式(`normType`):`NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`,其中:
37 当`normType = NONE`时:39 当`normType = NONE`时:
38 40 
@@ -43,8 +45,8 @@
43 当`normType = LAYER_NORM`时45 当`normType = LAYER_NORM`时
44 46 
45 $$47 $$
46- queryMean_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}query_{b,s,n} \\48+ queryMean_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}query_{b,s,n,i} \\
47- queryVar_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}(query-queryMean_{b,s,n})^2 \\49+ queryVar_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i}-queryMean_{b,s,n})^2 \\
48 queryRstd_{b,s,n}= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\50 queryRstd_{b,s,n}= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\
49 hiddenState_q = (query-queryMean)*queryRstd$$51 hiddenState_q = (query-queryMean)*queryRstd$$
50 当`normType = LAYER_NORM_AFFINE`时,在上面的基础上52 当`normType = LAYER_NORM_AFFINE`时,在上面的基础上
@@ -56,7 +58,7 @@
56 当`normType = RMS_NORM`时:58 当`normType = RMS_NORM`时:
57 59 
58 $$60 $$
59- queryMs = \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n})^2 \\61+ queryMs = \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i})^2 \\
60 queryRms = \frac{1}{\sqrt{queryMs+\epsilon}} \\62 queryRms = \frac{1}{\sqrt{queryMs+\epsilon}} \\
61 hiddenState_q = query * queryRms63 hiddenState_q = query * queryRms
62 $$64 $$
@@ -21,20 +21,22 @@ English | [简体中文](./README.md)
21 - Rotary position encoding (Rope) supports the Interleave and Half types.21 - Rotary position encoding (Rope) supports the Interleave and Half types.
22 - Feature concatenation (Concat) supports concatenation along the sequence dimension, and the concatenation order matters.22 - Feature concatenation (Concat) supports concatenation along the sequence dimension, and the concatenation order matters.
23 23 
24-- Computation formula (taking Query (video) and EncoderQuery (text) as an example):24+- Computation formula (taking Query (video) and EncoderQuery (text) as an example, with `concatOrder=0`):
25 25 
26 $$26 $$
27 hiddenState_q = \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\27 hiddenState_q = \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\
28- hiddenState_{eq} = \text{Norm}(encoderQuery, normEncoderQueryWeight, normEncoderQueryBias, eps) \\28+ hiddenState_{eq} = \text{Norm}(encoderQuery, normAddedQueryWeight, normAddedQueryBias, eps) \\
29 concatenatedHiddenState = \text{Concat}(hiddenState_q, hiddenState_{eq}) \\29 concatenatedHiddenState = \text{Concat}(hiddenState_q, hiddenState_{eq}) \\
30 transposedHiddenState = \text{Transpose}(concatenatedHiddenState, (0, 2, 1, 3)) \\30 transposedHiddenState = \text{Transpose}(concatenatedHiddenState, (0, 2, 1, 3)) \\
31- hiddenState = \text{RoPE}(concatenatedHiddenState, ropeSin, ropeCos)31+ hiddenState = \text{RoPE}(transposedHiddenState, ropeSin, ropeCos)
32 $$32 $$
33 33 
34+ When `ropeType` is `NONE`, RoPE does not transform the input. Otherwise, RoPE applies only to the first `seqRope` positions of the concatenated sequence. The remaining positions are unchanged.
35+ 
34- Notes:36- Notes:
35 37 
36- 1. The input and output layouts are as follows: the shape of the input `query` is `(B, S, N, D)`, and the shape of the output `hiddenState` is `(B, N, S, D)`, where38+ 1. The input `query` has shape `(B, S_q, N, D)`, `encoderQuery` has shape `(B, S_eq, N, D)`, and the output `hiddenState` has shape `(B, N, S_q + S_eq, D)`, where
37- B is batch, S is sequenceLen, N is headNum, and D is headDim.39+ `B` is the batch size, `S_q` and `S_eq` are the sequence lengths of `query` and `encoderQuery`, respectively, `N` is the number of attention heads, and `D` is the head dimension.
38 2. Norm has five modes (`normType`): `NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`, where:40 2. Norm has five modes (`normType`): `NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`, where:
39 When `normType = NONE`:41 When `normType = NONE`:
40 42 
@@ -45,8 +47,8 @@ English | [简体中文](./README.md)
45 When `normType = LAYER_NORM`47 When `normType = LAYER_NORM`
46 48 
47 $$49 $$
48- queryMean_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}query_{b,s,n} \\50+ queryMean_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}query_{b,s,n,i} \\
49- queryVar_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}(query-queryMean_{b,s,n})^2 \\51+ queryVar_{b,s,n} = \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i}-queryMean_{b,s,n})^2 \\
50 queryRstd_{b,s,n}= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\52 queryRstd_{b,s,n}= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\
51 hiddenState_q = (query-queryMean)*queryRstd$$53 hiddenState_q = (query-queryMean)*queryRstd$$
52 When `normType = LAYER_NORM_AFFINE`, based on the preceding formulas:54 When `normType = LAYER_NORM_AFFINE`, based on the preceding formulas:
@@ -58,7 +60,7 @@ English | [简体中文](./README.md)
58 When `normType = RMS_NORM`:60 When `normType = RMS_NORM`:
59 61 
60 $$62 $$
61- queryMs = \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n})^2 \\63+ queryMs = \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i})^2 \\
62 queryRms = \frac{1}{\sqrt{queryMs+\epsilon}} \\64 queryRms = \frac{1}{\sqrt{queryMs+\epsilon}} \\
63 hiddenState_q = query * queryRms65 hiddenState_q = query * queryRms
64 $$66 $$
@@ -31,21 +31,23 @@
31 - 旋转位置编码(Rope)支持Interleave和Half类型。31 - 旋转位置编码(Rope)支持Interleave和Half类型。
32 - 特征拼接(Concat)支持在sequence维度上进行拼接,拼接有顺序区别。32 - 特征拼接(Concat)支持在sequence维度上进行拼接,拼接有顺序区别。
33 33 
34-- 计算公式(以Query(视频)和EncoderQuery(文本)为例):34+- 计算公式(以Query(视频)和EncoderQuery(文本)为例,`concatOrder=0`):
35 35 
36 $$36 $$
37 \begin{aligned}37 \begin{aligned}
38 hiddenState_q &= \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\38 hiddenState_q &= \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\
39- hiddenState_{eq} &= \text{Norm}(encoderQuery, normEncoderQueryWeight, normEncoderQueryBias, eps) \\39+ hiddenState_{eq} &= \text{Norm}(encoderQuery, normAddedQueryWeight, normAddedQueryBias, eps) \\
40- concatedHiddenState &= \text{Concat}(hiddenState_q, hiddenState_{eq}) \\40+ concatenatedHiddenState &= \text{Concat}(hiddenState_q, hiddenState_{eq}) \\
41- transposedHiddenState &= \text{Transpose}(concatedHiddenState, (0, 2, 1, 3)) \\41+ transposedHiddenState &= \text{Transpose}(concatenatedHiddenState, (0, 2, 1, 3)) \\
42- hiddenState &= \text{RoPE}(concatedHiddenState, ropeSin, ropeCos)42+ hiddenState &= \text{RoPE}(transposedHiddenState, ropeSin, ropeCos)
43 \end{aligned}43 \end{aligned}
44 $$44 $$
45 45 
46+ 当`ropeType`为`NONE`时,RoPE不做变换;其他模式下,RoPE仅作用于拼接后序列的前`seqRope`个位置,其余位置不变。
47+ 
46- 说明:48- 说明:
47- 1. 输入输出布局如下:输入`query`的shape为`(B, S, N, D)`,输出`hiddenState`的shape为`(B, N, S, D)`,其中49+ 1. 输入输出布局如下:输入`query`的shape为`(B, S_q, N, D)`,`encoderQuery`的shape为`(B, S_eq, N, D)`,输出`hiddenState`的shape为`(B, N, S_q + S_eq, D)`,其中
48- B为batch,S为sequenceLen,N为headNum,D为headDim。50+ `B`为批次大小,`S_q`和`S_eq`分别为`query`和`encoderQuery`的序列长度,`N`为注意力头数,`D`为头维度。
49 2. Norm有五种模式(`normType`):`NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`,其中:51 2. Norm有五种模式(`normType`):`NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`,其中:
50 当`normType = NONE`时:52 当`normType = NONE`时:
51 $$53 $$
@@ -56,8 +58,8 @@
56 58 
57 $$59 $$
58 \begin{aligned}60 \begin{aligned}
59- queryMean_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D-1}query_{b,s,n} \\61+ queryMean_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D-1}query_{b,s,n,i} \\
60- queryVar_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D-1}(query-queryMean_{b,s,n})^2 \\62+ queryVar_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i}-queryMean_{b,s,n})^2 \\
61 queryRstd_{b,s,n} &= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\63 queryRstd_{b,s,n} &= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\
62 hiddenState_q &= (query-queryMean)*queryRstd64 hiddenState_q &= (query-queryMean)*queryRstd
63 \end{aligned}65 \end{aligned}
@@ -73,7 +75,7 @@
73 75 
74 $$76 $$
75 \begin{aligned}77 \begin{aligned}
76- queryMs &= \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n})^2 \\78+ queryMs &= \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i})^2 \\
77 queryRms &= \frac{1}{\sqrt{queryMs+\epsilon}} \\79 queryRms &= \frac{1}{\sqrt{queryMs+\epsilon}} \\
78 hiddenState_q &= query * queryRms80 hiddenState_q &= query * queryRms
79 \end{aligned}81 \end{aligned}
@@ -33,21 +33,23 @@ Disclaimer: This document is licensed under the [Creative Commons License versio
33 - Rotary position encoding (Rope) supports Interleave and Half types.33 - Rotary position encoding (Rope) supports Interleave and Half types.
34 - Feature concatenation (Concat) supports concatenation along the sequence dimension, with order distinction.34 - Feature concatenation (Concat) supports concatenation along the sequence dimension, with order distinction.
35 35 
36-- Formula (using Query (video) and EncoderQuery (text) as an example):36+- Formula (using Query (video) and EncoderQuery (text) as an example, with `concatOrder=0`):
37 37 
38 $$38 $$
39 \begin{aligned}39 \begin{aligned}
40 hiddenState_q &= \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\40 hiddenState_q &= \text{Norm}(query, normQueryWeight, normQueryBias, eps) \\
41- hiddenState_{eq} &= \text{Norm}(encoderQuery, normEncoderQueryWeight, normEncoderQueryBias, eps) \\41+ hiddenState_{eq} &= \text{Norm}(encoderQuery, normAddedQueryWeight, normAddedQueryBias, eps) \\
42- concatedHiddenState &= \text{Concat}(hiddenState_q, hiddenState_{eq}) \\42+ concatenatedHiddenState &= \text{Concat}(hiddenState_q, hiddenState_{eq}) \\
43- transposedHiddenState &= \text{Transpose}(concatedHiddenState, (0, 2, 1, 3)) \\43+ transposedHiddenState &= \text{Transpose}(concatenatedHiddenState, (0, 2, 1, 3)) \\
44- hiddenState &= \text{RoPE}(concatedHiddenState, ropeSin, ropeCos)44+ hiddenState &= \text{RoPE}(transposedHiddenState, ropeSin, ropeCos)
45 \end{aligned}45 \end{aligned}
46 $$46 $$
47 47 
48+ When `ropeType` is `NONE`, RoPE does not transform the input. Otherwise, RoPE applies only to the first `seqRope` positions of the concatenated sequence. The remaining positions are unchanged.
49+ 
48- Description:50- Description:
49- 1. The input and output layout is as follows: the shape of input `query` is `(B, S, N, D)`, and the shape of output `hiddenState` is `(B, N, S, D)`, where51+ 1. The input `query` has shape `(B, S_q, N, D)`, `encoderQuery` has shape `(B, S_eq, N, D)`, and the output `hiddenState` has shape `(B, N, S_q + S_eq, D)`, where
50- B is batch, S is sequenceLen, N is headNum, and D is headDim.52+ `B` is the batch size, `S_q` and `S_eq` are the sequence lengths of `query` and `encoderQuery`, respectively, `N` is the number of attention heads, and `D` is the head dimension.
51 2. Norm has five modes (`normType`): `NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`, where:53 2. Norm has five modes (`normType`): `NONE(0), LAYER_NORM(1), LAYER_NORM_AFFINE(2), RMS_NORM(3), RMS_NORM_AFFINE(4)`, where:
52 When `normType = NONE`:54 When `normType = NONE`:
53 $$55 $$
@@ -58,8 +60,8 @@ Disclaimer: This document is licensed under the [Creative Commons License versio
58 60 
59 $$61 $$
60 \begin{aligned}62 \begin{aligned}
61- queryMean_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D}query_{b,s,n} \\63+ queryMean_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D-1}query_{b,s,n,i} \\
62- queryVar_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D}(query-queryMean_{b,s,n})^2 \\64+ queryVar_{b,s,n} &= \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i}-queryMean_{b,s,n})^2 \\
63 queryRstd_{b,s,n} &= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\65 queryRstd_{b,s,n} &= \frac{1}{\sqrt{queryVar_{b,s,n}+\epsilon}} \\
64 hiddenState_q &= (query-queryMean)*queryRstd66 hiddenState_q &= (query-queryMean)*queryRstd
65 \end{aligned}67 \end{aligned}
@@ -75,7 +77,7 @@ Disclaimer: This document is licensed under the [Creative Commons License versio
75 77 
76 $$78 $$
77 \begin{aligned}79 \begin{aligned}
78- queryMs &= \frac{1}{D}\sum_{i=0}^{D}(query_{b,s,n})^2 \\80+ queryMs &= \frac{1}{D}\sum_{i=0}^{D-1}(query_{b,s,n,i})^2 \\
79 queryRms &= \frac{1}{\sqrt{queryMs+\epsilon}} \\81 queryRms &= \frac{1}{\sqrt{queryMs+\epsilon}} \\
80 hiddenState_q &= query * queryRms82 hiddenState_q &= query * queryRms
81 \end{aligned}83 \end{aligned}
@@ -488,7 +488,7 @@ aclnnStatus aclnnQkvRmsNormRopeCache(
488 488 
489- 输入shape限制:489- 输入shape限制:
490 * B<sub>qkv</sub>为输入qkv的batch_size,S<sub>qkv</sub>为输入qkv的sequence length,大小由qkvSize决定。490 * B<sub>qkv</sub>为输入qkv的batch_size,S<sub>qkv</sub>为输入qkv的sequence length,大小由qkvSize决定。
491- * N<sub>qkv</sub>为输入qkv的head number。D<sub>qkv</sub>为输入qkv的head dim,目前仅支持128。D<sub>q</sub>、D<sub>k</sub>和D<sub>k</sub>分别为q、k、v的head dim,要求D<sub>qkv</sub> = D<sub>q</sub> = D<sub>k</sub> = D<sub>v</sub>,D<sub>qkv</sub>需要满足(D<sub>qkv</sub>*qkv数据类型占字节数)可以被32整除。491+ * N<sub>qkv</sub>为输入qkv的head number。D<sub>qkv</sub>为输入qkv的head dim,目前仅支持128。D<sub>q</sub>、D<sub>k</sub>和D<sub>v</sub>分别为q、k、v的head dim,要求D<sub>qkv</sub> = D<sub>q</sub> = D<sub>k</sub> = D<sub>v</sub>,D<sub>qkv</sub>需要满足(D<sub>qkv</sub>*qkv数据类型占字节数)可以被32整除。
492 * 根据rope规则,D<sub>k</sub>和D<sub>q</sub>为偶数。若cacheMode为PA_NZ场景下,D<sub>k</sub>、D<sub>q</sub>需32 Byte对齐;BlockSize需32 Byte对齐。492 * 根据rope规则,D<sub>k</sub>和D<sub>q</sub>为偶数。若cacheMode为PA_NZ场景下,D<sub>k</sub>、D<sub>q</sub>需32 Byte对齐;BlockSize需32 Byte对齐。
493 * 关于上述32B对齐的情形,对齐值由cache的数据类型决定。以BlockSize为例,若cache的数据类型为int8,则需要满足BlockSize % 32 = 0;若cache的数据类型为float16,则需要满足BlockSize % 16 = 0;若kCache与vCache参数的dtype不一致,BlockSize需同时满足BlockSize % 32 = 0和BlockSize % 16 = 0。493 * 关于上述32B对齐的情形,对齐值由cache的数据类型决定。以BlockSize为例,若cache的数据类型为int8,则需要满足BlockSize % 32 = 0;若cache的数据类型为float16,则需要满足BlockSize % 16 = 0;若kCache与vCache参数的dtype不一致,BlockSize需同时满足BlockSize % 32 = 0和BlockSize % 16 = 0。
494 * BlockNum为写入cache的内存块数,大小由用户输入场景决定,要求BlockNum >= Ceil(S<sub>qkv</sub> / BlockSize) * B<sub>qkv</sub>。494 * BlockNum为写入cache的内存块数,大小由用户输入场景决定,要求BlockNum >= Ceil(S<sub>qkv</sub> / BlockSize) * B<sub>qkv</sub>。