文件最后提交记录最后更新时间
【update】block_sparse_attention/fused_infer_attention_score等算子资料修改 Co-authored-by: wjc<wangjincheng14@huawei.com> # message auto-generated for no-merge-commit merge: !4071 merge personal/wjc/doc_updates into master 【update】block_sparse_attention/fused_infer_attention_score等算子资料修改 Created-by: Anthony0331 Commit-by: wjc Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 本次PR对block_sparse_attention、fused_infer_attention_score等算子的API文档进行了集中修正和优化。主要解决了文档中普遍存在的拼写错误、参数名不一致、术语不准确、约束条件描述模糊或过时、以及部分格式和示例代码错误等问题。这些修改旨在提升整个算子接口文档集的准确性、一致性和可读性,确保开发者能够正确理解和使用相关功能。 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> 关联Issue [#1825](https://gitcode.com/cann/ops-transformer/issues/1825) ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> 更新了以下文件: attention/block_sparse_attention/docs/aclnnBlockSparseAttention.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScore.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV2.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV3.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV4.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV5.md attention/incre_flash_attention/docs/aclnnIncreFlashAttention.md attention/incre_flash_attention/docs/aclnnIncreFlashAttentionV2.md attention/incre_flash_attention/docs/aclnnIncreFlashAttentionV3.md attention/incre_flash_attention/docs/aclnnIncreFlashAttentionV4.md attention/nsa_compress_attention_infer/docs/aclnnNsaCompressAttentionInfer.md attention/nsa_compress_attention_infer/examples/test_aclnn_nsa_compress_attention_infer.cpp attention/nsa_compress_with_cache/docs/aclnnNsaCompressWithCache.md attention/nsa_selected_attention_infer/docs/aclnnNsaSelectedAttentionInfer.md attention/nsa_selected_attention_infer/examples/test_aclnn_nsa_selected_attention_infer.cpp attention/prompt_flash_attention/docs/aclnnPromptFlashAttention.md attention/prompt_flash_attention/docs/aclnnPromptFlashAttentionV2.md attention/prompt_flash_attention/docs/aclnnPromptFlashAttentionV3.md ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [x] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!40711 个月前
【update】block_sparse_attention/fused_infer_attention_score等算子资料修改 Co-authored-by: wjc<wangjincheng14@huawei.com> # message auto-generated for no-merge-commit merge: !4071 merge personal/wjc/doc_updates into master 【update】block_sparse_attention/fused_infer_attention_score等算子资料修改 Created-by: Anthony0331 Commit-by: wjc Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 本次PR对block_sparse_attention、fused_infer_attention_score等算子的API文档进行了集中修正和优化。主要解决了文档中普遍存在的拼写错误、参数名不一致、术语不准确、约束条件描述模糊或过时、以及部分格式和示例代码错误等问题。这些修改旨在提升整个算子接口文档集的准确性、一致性和可读性,确保开发者能够正确理解和使用相关功能。 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> 关联Issue [#1825](https://gitcode.com/cann/ops-transformer/issues/1825) ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> 更新了以下文件: attention/block_sparse_attention/docs/aclnnBlockSparseAttention.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScore.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV2.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV3.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV4.md attention/fused_infer_attention_score/docs/aclnnFusedInferAttentionScoreV5.md attention/incre_flash_attention/docs/aclnnIncreFlashAttention.md attention/incre_flash_attention/docs/aclnnIncreFlashAttentionV2.md attention/incre_flash_attention/docs/aclnnIncreFlashAttentionV3.md attention/incre_flash_attention/docs/aclnnIncreFlashAttentionV4.md attention/nsa_compress_attention_infer/docs/aclnnNsaCompressAttentionInfer.md attention/nsa_compress_attention_infer/examples/test_aclnn_nsa_compress_attention_infer.cpp attention/nsa_compress_with_cache/docs/aclnnNsaCompressWithCache.md attention/nsa_selected_attention_infer/docs/aclnnNsaSelectedAttentionInfer.md attention/nsa_selected_attention_infer/examples/test_aclnn_nsa_selected_attention_infer.cpp attention/prompt_flash_attention/docs/aclnnPromptFlashAttention.md attention/prompt_flash_attention/docs/aclnnPromptFlashAttentionV2.md attention/prompt_flash_attention/docs/aclnnPromptFlashAttentionV3.md ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [x] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!40711 个月前
修改版权头 Co-authored-by: yayahello<zhaopenglei@hisilicon.com> # message auto-generated for no-merge-commit merge: !3171 merge master into master 修改版权头 Created-by: yayahello Commit-by: yayahello Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 版权声明不标准,修改为标准头 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #000--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> 关联Issue [#1100](https://gitcode.com/cann/ops-transformer/issues/1100) ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [x] ❓ 其他,请描述: See merge request: cann/ops-transformer!31712 个月前
common目录整改 Co-authored-by: hello_simida<wangyi206@huawei.com> # message auto-generated for no-merge-commit merge: !4870 merge feature/common_dir_fix_v2 into master common目录整改 Created-by: hello_simida Commit-by: hello_simida Merged-by: cann-robot Description: ## 描述 本次修改对 common/ 目录进行整理,分为两个阶段: - **Phase 1**: 将 common/include/kernel/ 重命名为 common/include/op_kernel/ - **Phase 2**: 将 common/include/tiling_base/common/src/tiling_base/ 合并到 common/include/op_host/common/src/op_host/ 相应的 CMake 配置和所有 #include 路径引用已同步更新。 影响范围: - 351 个文件修改(include 路径更新) - 8 个文件重命名(tiling_base → op_host) - 2 个 CMakeLists.txt 修改 + 多个 tests 目录 CMakeLists.txt 更新 ## 关联的Issue Closes #2246 ## 测试 - 编译验证通过:bash build.sh --pkg --soc=ascend910b --ops=all_gather_matmul_v2 -j16 - 编译产物成功生成 .run 包 ## 文档更新 无 ## 类型标签 - [x] ♻️ 重构 - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!487026 天前
add kirin9030 ops Co-authored-by: zengjuan<zengjuan2@huawei.com> # message auto-generated for no-merge-commit merge: !1118 merge master into master add kirin9030 ops Created-by: zengjuan Commit-by: zengjuan Merged-by: cann-robot Description: ## 描述 add kirin9030 ops: attention/nsa_compress_with_cache attention/nsa_selected_attention_infer attention/ring_attention_update ffn/ffn ffn/swin_attention_ffn ffn/swin_transformer_ln_qkv ffn/swin_transformer_ln_qkv_quant gmm/grouped_matmul gmm/grouped_matmul_swiglu_quant moe/moe_compute_expert_tokens moe/moe_finalize_routing moe/moe_finalize_routing_v2 moe/moe_re_routing moe/moe_token_unpermute moe/moe_token_unpermute_with_ep moe/moe_token_unpermute_with_routing_map posembedding/apply_rotary_pos_emb posembedding/dequant_rope_quant_kvcache posembedding/interleave_rope posembedding/kv_rms_norm_rope_cache posembedding/rope_quant_kvcache posembedding/rope_with_sin_cos_cache posembedding/rotary_position_embedding ## 关联的Issue https://gitcode.com/cann/ops-transformer/issues/671 ## 测试 蓝区门禁、黄区门禁、算子二级冒烟 ## 文档更新 无 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-transformer!11183 个月前
fix: skip failing operator UT builds by commenting out error test CMakeLists.txt Co-authored-by: huang-chuhong<huangchuhong1@h-partners.com> # message auto-generated for no-merge-commit merge: !5823 merge fix/ut-build-skip-failing-ops into master fix: skip failing operator UT builds by commenting out error test CMakeLists.txt Created-by: huang-chuhong Commit-by: huang-chuhong Merged-by: cann-robot Description: ## 描述 部分算子 UT 在 ascend910b 平台上编译失败,导致整体 UT 构建阻塞。本 PR 通过注释失败算子的 tests CMakeLists.txt 代码部分(保留版权头),使 op_host/op_api UT 构建能顺利通过。 ## 改动 - build.sh: 在 set_ut_mode() 中新增逻辑,当 UT_TEST_ALL=TRUE 且 ENABLE_BUILT_CUSTOM!=TRUE 时自动拆分为 OP_HOST_UT + OP_API_UT + OP_GRAPH_UT,关闭 OP_KERNEL_UT - 注释以下算子的 tests CMakeLists.txt(保留版权头): - ffn/ffn, attention/fused_floyd_attention_grad, attention/lightning_indexer_grad, attention/nsa_compress_attention, attention/nsa_compress_attention_infer, attention/nsa_compress_with_cache, attention/nsa_selected_attention, attention/nsa_selected_attention_infer, gmm/quant_grouped_matmul_dequant, mc2/matmul_all_reduce, mhc/mhc_pre_sinkhorn, mhc/mhc_sinkhorn, moe/moe_gating_top_k_softmax_v2, posembedding/norm_rope_concat ## 关联的Issue https://gitcode.com/cann/ops-transformer/issues/2622 https://gitcode.com/cann/ops-transformer/issues/2594 ## 测试 - bash build.sh -u: 1198 tests, 1197 passed, 1 skipped - bash build.sh -u --ophost: 2904 tests, all passed - bash build.sh -u --opapi: 1198 tests, 1197 passed, 1 skipped ## 类型标签 - [x] 🧪 测试 - [x] 📦 构建/CI See merge request: cann/ops-transformer!582310 天前
匹配最新cann版本,上线新版本attention/ffn/moe/posembedding算子 Co-authored-by: huangchuhong<huangchuhong1@h-partners.com> # message auto-generated for no-merge-commit merge: !538 merge master into master 匹配最新cann版本,上线新版本attention/ffn/moe/posembedding算子 Created-by: huang-chuhong Commit-by: huangchuhong Merged-by: cann-robot Description: ## 描述 transformer 同步算子最新开发,涉及attention/ffn/moe/posembedding ## 关联的Issue https://gitcode.com/cann/ops-transformer/issues/315 ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-transformer!5385 个月前
doc Tools工具扫描问题修改 Co-authored-by: gitee-yanglulu<yanglulul@h-partners.com> # message auto-generated for no-merge-commit merge: !3432 merge master into master doc Tools工具扫描问题修改 Created-by: gitee-yanglulu Commit-by: gitee-yanglulu Merged-by: cann-robot Description: doc Tools工具扫描问题修改 See merge request: cann/ops-transformer!34322 个月前
README.md

NsaSelectedAttentionInfer

产品支持情况

产品 是否支持
Ascend 950PR/Ascend 950DT ×
Atlas A3 训练系列产品/Atlas A3 推理系列产品
Atlas A2 训练系列产品/Atlas A2 推理系列产品
Atlas 200I/500 A2 推理产品 ×
Atlas 推理系列产品 ×
Atlas 训练系列产品 ×
Kirin X90 处理器系列产品
Kirin 9030 处理器系列产品

功能说明

  • 算子功能:Native Sparse Attention推理过程中,Selected Attention的计算。

  • 计算公式:

    self-attention(自注意力)利用输入样本自身的关系构建了一种注意力模型。其原理是假设有一个长度为nn的输入样本序列xxxx的每个元素都是一个dd维向量,可以将每个dd维向量看作一个token embedding,将这样一条序列经过3个权重矩阵变换得到3个维度为n∗dn*d的矩阵。

    Selected Attention的计算由topk索引取数与attention计算融合而成,外加paged attention取kvCache。首先,通过topkIndicestopkIndices索引从keykey中取出keytopkkey_{topk},从valuevalue中取出valuetopkvalue_{topk},计算self_attention公式如下:

    Attention(query,key,value)=Softmax(query⋅keytopkTd)valuetopkAttention(query,key,value)=Softmax(\frac{query · key_{topk}^T}{\sqrt{d}})value_{topk}

    其中queryquerykeytopkTkey_{topk}^T乘积代表输入xx的注意力,为避免该值变得过大,通常除以dd的开根号进行缩放,并对每行进行softmax归一化,与valuetopkvalue_{topk}相乘后得到一个n∗dn*d的矩阵。

参数说明

参数名 输入/输出/属性 描述 数据类型 数据格式
query 输入 公式中的输入query。 FLOAT16、BFLOAT16 ND
key 输入 公式中的输入key。 FLOAT16、BFLOAT16 ND
value 输入 公式中的输入value。 FLOAT16、BFLOAT16 ND
topkIndices 输入 公式里的topK索引。 INT32 ND
output 输出 公式中attention的输出。 FLOAT16、BFLOAT16 ND
  • Kirin X90/Kirin 9030 处理器系列产品: 不支持BFLOAT16。

约束说明

  • 参数query中的N和numHeads值相等,key、value的N和numKeyValueHeads值相等,并且numHeads是numKeyValueHeads的倍数关系。
  • 参数query中的D和key的D(H/numKeyValueHeads)值相等,value的D(H/numKeyValueHeads)和output的D值相等。
  • query,key,value输入,功能使用限制如下:
    • 支持B轴小于等于3072。
    • 支持key/value的N轴小于等于256。
    • 支持query的N轴与key/value的N轴(H/D)的比值(即GQA中的group大小)小于等于16。
    • 支持query与Key的D轴等于192。
    • 支持value的D轴等于128。
    • 支持Key与Value的blockSize等于64或128。
    • 普通场景下仅支持query的S轴等于1。
    • 多token推理场景下,仅支持query的S轴最大等于4,并且此时要求每个batch单独的actualQSeqLen <= actualSelKvSeqLen。
    • 仅支持paged attention。
    • 仅支持selectBlockSize取值为16的整数倍,最大支持到128。
    • selectBlockCount上限满足selectBlockCount * selectBlockSize <= MaxKvSeqlen,MaxKvSeqlen = Max(actualSelKvSeqLenOptional)。

调用说明

调用方式 样例代码 说明
aclnn接口 test_aclnn_nsa_selected_attention_infer 通过aclnnNsaSelectedAttentionInfer接口方式调用NsaCompressAttentionInfer算子。