Merged
feature: support topK from 1 to 9182 in CSA mode #11919
feature: support topK from 1 to 9182 in CSA mode #11919
Merged
Yuan BinAdd on Sep 14
Yuan Bin
Yuan BinCollaborators
Sep 14

描述

改动原因

为CSA模式添加topK的[1,8192]的泛化,使其支持更广泛的索引数范围。

改动方法

放宽对sparse_flash_mla_meta中cmpTopk的拦截条件,在sparse_flash_mla中增加对cmp_sparse_indices中最后一维的长度检查。在sparse_flash_mla的v0阶段中中使s2进行正常的完整循环和获取循环长度。

关联的Issue

https://gitcode.com/cann/ops-transformer/issues/5261

测试

经过360条白盒泛化测试用例,以及200条泛化前后的性能测试

文档更新

更新了sparse_flash_mla与sparse_flash_mla_meta的README文档与接口文档,更新了topK的合法与拦截的范围。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Yuan Bin's contribution.)
Yuan BinYuan BinCollaborators
Sep 14 Created pull request, commit 6fd53e6a
Yuan BinYuan BinCollaborators
Sep 14 Associated issue: [Requirement|需求建议]:SMLA算子支持topk泛化1~8192
atomgit-bot
atomgit-bot
Sep 14 Comments:

变更摘要

本 PR 为 CSA 模式下的 sparse_flash_mla 算子扩展 topK 的合法取值范围,从原先仅支持固定值扩展为支持 [1, 8192] 的任意索引数。核心思路是放宽 sparse_flash_mla_meta 中对 cmpTopk 的拦截条件、在 sparse_flash_mla 的 tiling 检查中新增对 cmp_sparse_indices 最后一维长度的校验,并调整 CSA 内核在 v0 阶段对压缩块切片(s2)的处理逻辑,使其支持完整的循环与部分末块;同时更新了相关算子的 README 与接口文档。

主要改动

  • 新增 TOPK_LIMIT 常量与 tiling 参数校验: 在 sparse_flash_mla_tiling.h 中新增 TOPK_LIMIT = 8192;在 sparse_flash_mla_tiling.cpp 的 CheckSingleParaCmpSparseIndices 中新增对 cmp_sparse_indices 最后一维(即 topk)的检查,要求在 DAV_2201 架构下取值位于 [1, TOPK_LIMIT],否则返回 GRAPH_FAILED。
  • 放宽 cmp_topk 拦截条件: 在 sparse_flash_mla_metadata_check.h 的 CheckSingleParamSmla 中,将 cmpTopk 的合法性判断由仅允许 0/512/1024(非 Ascend950 场景)放宽为 cmpTopk <= 8192 即可通过校验。
  • 统一 CSA 内核 v0 阶段的 s2 切片逻辑: 在 sparse_flash_mla_csa_kernel.h 的 CalcParams 中删除 HEAD_RATIO_ONE 分支,统一使用 s2Offset 作为 v0S2Start、以 actualSingleProcessSInnerSize 作为 v0S2DealSize,使每个压缩块读取自身对应的切片(含不完整的末块)。
  • 文档更新: 依据 PR 描述,同步更新了 sparse_flash_mla 与 sparse_flash_mla_meta 的 README 和接口文档中 topK 的合法与拦截范围。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 14 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 14 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
*/*/README.md ✅ wangxun21, 蔡雯雯, 杨露, guijianwei (4/2) ✅ 杨露, 蔡雯雯 (2/1)
*/*/docs/acl*.md ✅ 蔡雯雯, 杨露, guijianwei, wangxun21 (4/2) ✅ 蔡雯雯, 杨露 (2/1)
attention ✅ tang-hao-hw-gitcode, guijianwei, wangxun21 (3/2) ✅ tang-hao-hw-gitcode (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

aaaakai, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Sep 14 Set guijianwei,hz36amy_00,coder_linx,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,gitee-duhuiping,claire8090,liudan12,shasha_an,wangzhe123456789,Wei_NaChuan,zhangshuoleiokok,luwei_1104,gitcode-chenjiao,cc-z,kdy18482276080,shen_weiling,Ww7012,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,haijie_699874,fengying555682,zzy__,Julius47,yuhao_,L_Euler,wangxun21,caiwenwen,yanglu-1 as approver
CANN-robotCANN-robotCollaborators
Sep 14 Set guijianwei,hz36amy_00,coder_linx,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,gitee-duhuiping,claire8090,liudan12,shasha_an,wangzhe123456789,Wei_NaChuan,zhangshuoleiokok,luwei_1104,gitcode-chenjiao,cc-z,kdy18482276080,shen_weiling,Ww7012,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,haijie_699874,fengying555682,zzy__,Julius47,yuhao_,L_Euler,wangxun21,caiwenwen,yanglu-1 as approver
Yuan Bin
Yuan BinCollaborators
Sep 14 Comments:

/compile

likedislike
Yuan BinYuan BinCollaborators
Sep 14 Pre merge succeeded (commit_id: 31cb4d7820c0fd308de736c3a789ee95e1269b0a)
CANN-robot
CANN-robotCollaborators
Sep 14 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 14 Added label: ci-pipeline-running
6 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 14 Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
Sep 14 Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robotCollaborators
Sep 14 Added label: cann-cla/yes
caiwenwen
caiwenwenCollaborators
Sep 14 Comments:

/lgtm
/approve

likedislike
Yuan Bin
Yuan BinCollaborators
Sep 14 Comments:

\compile

likedislike
何宇航
何宇航Collaborators
Sep 14 Comments:

compile

likedislike
Yuan BinYuan BinCollaborators
Sep 14 virtual merging failed, update merge request[project_id: 7673863, iid: 11919, target_commit_sha: 5915c386ffc67b05f450c1db2256786a01dfbe43], message: You are not allowed to merge to this ref
Yuan BinYuan BinCollaborators
Sep 14 virtual merging failed, update merge request[project_id: 7673863, iid: 11919, target_commit_sha: 5915c386ffc67b05f450c1db2256786a01dfbe43], message: You are not allowed to merge to this ref
何宇航
何宇航Collaborators
Sep 14 Comments:

compile

likedislike
Yuan BinYuan BinCollaborators
Sep 14 virtual merging failed, update merge request[project_id: 7673863, iid: 11919, target_commit_sha: 5915c386ffc67b05f450c1db2256786a01dfbe43], message: You are not allowed to merge to this ref
Yuan BinYuan BinCollaborators
Sep 14 virtual merging failed, update merge request[project_id: 7673863, iid: 11919, target_commit_sha: 5915c386ffc67b05f450c1db2256786a01dfbe43], message: You are not allowed to merge to this ref
CANN-robot
CANN-robotCollaborators
Sep 14 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robot
CANN-robotCollaborators
Sep 14 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 14 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 14 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 14 Added label: ci-pipeline-failed
CANN-robotCANN-robotCollaborators
Sep 14 Removed label: ci-pipeline-failed
CANN-robotCANN-robotCollaborators
Sep 14 Added label: ci-pipeline-passed
yanglu-1
yanglu-1Collaborators
Sep 14 Comments:

/lgtm
/approve

likedislike
guijianwei
guijianweiCollaborators
Sep 14 Comments:

/lgtm

likedislike
wangxun21
wangxun21Collaborators
Sep 14 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 14 Added label: lgtm
tang-hao-hw-gitcode
tang-hao-hw-gitcodeCollaborators
Sep 14 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 14 Added label: approved
CANN-robotCANN-robotCollaborators
Sep 14 Merged pull request