Merged
Support 16-Aligned Block Granularity in BlockSparseAttentionGrad #10188
Support 16-Aligned Block Granularity in BlockSparseAttentionGrad #10188
Merged
DaiHuina1Add on Aug 17
DaiHuina1
DaiHuina1Collaborators
Aug 17

描述

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for DaiHuina1's contribution.)
DaiHuina1DaiHuina1Collaborators
Aug 17 Created pull request, commit eba28532
atomgit-bot
atomgit-bot
Aug 17 Comments:

变更摘要

该 PR 主要对 BlockSparseAttentionGrad 算子在 arch35 平台上的 Block 粒度支持进行扩展:将 Block Shape 的合法性约束从「必须是 64 的倍数」放宽为「必须是 16 的倍数」,并相应调整了 Tiling 计算逻辑,使算子能够支持 16、32、48 等更小的非 64 对齐块粒度。同时修复了 cube_op.h 中 L1 缓冲偏移量计算错误以及 madParams.m 的处理,并新增了泛化测试脚本与 Tiling 单元测试用例,覆盖 16/32/48/64 及非对称块、序列尾部、GQA 等场景。

主要改动

  • Block Shape 校验放宽为 16 对齐:在 block_sparse_attention_grad_tiling_arch35.cpp 和 aclnn_block_sparse_attention_grad.cpp 中,将 blockShapeX_、blockShapeY_ 及 blockShapeOptional 的约束由「64 的倍数」改为「16 的倍数」,并同步更新错误提示信息。
  • Tiling 计算逻辑调整以支持小粒度 Block:block_sparse_attention_grad_tiling_arch35.cpp 中重写了 baseM 与 singleM 的计算,当 blockShapeX_ 小于等于 32 时使用 blockShapeX_ * 2,当 blockShapeX_ 或 blockShapeY_ 小于 128 时 singleM 直接取 blockShapeX_,从而支持 16/32/48 等块大小。
  • 修复 L1 偏移与 MMA 参数:cube_op.h 中 value_l1_tensor_ping_ 和 value_l1_tensor_pong_ 的偏移累加由 base_m 改为 base_n,并将 madParams.m 由条件表达式改为直接使用 mProcessAlign。
  • 新增泛化测试脚本:新增 test_bsa_generalization.py,通过复用参考脚本并做文本替换来生成覆盖 block16/32/48/64、非对称块、尾部序列、BNSD/BSND 布局及 GQA 的用例,支持 --dry-run 校验和独立子进程执行。
  • 重构并扩充 Tiling 单元测试:test_block_sparse_attention_grad_tiling.cpp 抽取 RunArch35BnsdTilingCase 辅助函数,新增 block64 回归、block16 尾部、非对称 block16x32 以及拒绝非 16 倍数输入的测试用例。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 17 Added label: cann-cla/no
CANN-robot
CANN-robotCollaborators
Aug 17 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 ✅ 蔡雯雯, hz36amy_00 (2/2) ✅ 蔡雯雯 (1/1)
*/*/docs/acl*.md ✅ 蔡雯雯, hz36amy_00 (2/2) ✅ 蔡雯雯 (1/1)
attention ✅ yuhao_, hz36amy_00 (2/2) ✅ yuhao_ (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Aug 17 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,gitcode-chenjiao,cc-z,shen_weiling,Ww7012,zhouwenfang,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,haijie_699874,wuyao51511,zzy__,yuhao_,L_Euler,caiwenwen as approver
CANN-robotCANN-robotCollaborators
Aug 17 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,gitcode-chenjiao,cc-z,shen_weiling,Ww7012,zhouwenfang,gaoxiang618,songjionghui,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,haijie_699874,wuyao51511,zzy__,yuhao_,L_Euler,caiwenwen as approver
huang-wei-chen
huang-wei-chenCollaboratorsAug 18Start code review2
attention/block_sparse_attention_grad/op_host/op_api/aclnn_block_sparse_attention_grad.cpp
Outdated
@@ -97,2 +97,4 @@
9797 }
9898 
99+ constexpr int64_t BLOCK_ALIGNMENT = 16;
100+ if (data[0] % BLOCK_ALIGNMENT != 0 || data[1] % BLOCK_ALIGNMENT != 0) {
huang-wei-chen
huang-wei-chenAug 18Comments:

问题 :当前校验会影响arch22路径,改后会新增 blockShape 对齐要求,非对齐会被拦截。
建议 :增加arch35判断条件,以免影响arch22原本路径。

likedislike
System
System MessageSystem
Aug 31 Comments:

changed this line on 2528aad6 view diff detail

likedislike
DaiHuina1DaiHuina1Collaborators
Aug 31 Pre merge succeeded (commit_id: e1fb82a56557d86b8d64fe37e926a19dba138cd4)
13 event messages are collapsed here。 See more
DaiHuina1DaiHuina1Collaborators
Aug 31 Resolved final issue
DaiHuina1
DaiHuina1Collaborators
Aug 31 Comments:

/compile

likedislike
DaiHuina1DaiHuina1Collaborators
Aug 31 Pre merge succeeded (commit_id: 96593d69a0d0bcbf901c8e5e516d5d1361a70842)
CANN-robotCANN-robotCollaborators
Aug 31 Added label: ci-pipeline-running
DaiHuina1DaiHuina1Collaborators
Aug 31 Pre merge succeeded (commit_id: 3c64835b2b2402f6175fe881ba4fcb7f642c7672)
DaiHuina1DaiHuina1Collaborators
Aug 31 Force-pushed 1 commits:02a6e93e-Support 16-Aligned Block Granularity in BlockSparseAttentionGrad
DaiHuina1DaiHuina1Collaborators
Aug 31 Pre merge succeeded (commit_id: ba421efe5e70275ee6c7ae29badb59651a5e6615)
DaiHuina1
DaiHuina1Collaborators
Aug 31 Comments:

/compile

likedislike
CANN-robotCANN-robotCollaborators
Aug 31 Removed label: cann-cla/yes
7 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 31 Added label: ci-pipeline-passed
yf_zhou
yf_zhouCollaborators
Sep 1 Comments:

/lgtm

likedislike
xuchengyang
xuchengyangCollaboratorsSep 1Start code review1
attention/block_sparse_attention_grad/op_host/arch35/block_sparse_attention_grad_tiling_arch35.cpp
@@ -254,3 +254,2 @@
254254 uint32_t singleM = AlignTo(2048, baseM);
255- uint32_t block_num_x = q_seq_len_ / blockShapeX_;
256- uint32_t block_num_y = kv_seq_len_ / blockShapeY_;
255+ // Keep all Q tiles for the current KV block/head on one cube core when
xuchengyang
xuchengyangSep 1Comments:

无效注释,可以删除

likedislike
yuhao_
yuhao_Collaborators
Sep 1 Comments:

/approve

likedislike
DaiHuina1DaiHuina1Collaborators
Sep 1 Resolved final issue
DaiHuina1
DaiHuina1Collaborators
Sep 1 Comments:

/check-pr

likedislike
CANN-robot
CANN-robotCollaborators
Sep 1 Comments:

The following labels are not ready.

lgtm: Please wait for reviewers to review the code.

approved: Please wait for committers to review the code.

likedislike
DaiHuina1
DaiHuina1Collaborators
Sep 1 Comments:

/check-pr

likedislike
CANN-robot
CANN-robotCollaborators
Sep 1 Comments:

The following labels are not ready.

lgtm: Please wait for reviewers to review the code.

approved: Please wait for committers to review the code.

likedislike
caiwenwen
caiwenwenCollaborators
Sep 1 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 1 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 1 Merged pull request