Merged
修复dliklg算子初始化越界 #15406
修复dliklg算子初始化越界 #15406
Merged
llwy0320Add on 4 days ago
llwy0320Collaborators
4 days ago

描述

修复dliklg算子初始化越界

关联的Issue

#6847

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for llwy0320's contribution.)
Lllwy0320Collaborators
4 days ago Created pull request, commit 299c28b2
atomgit-bot
atomgit-bot
4 days ago Comments:

变更摘要

本 PR 针对 attention/dense_lightning_indexer_kl_loss_grad/op_kernel/arch35/dense_lightning_indexer_kl_loss_grad_kernel_base.h 中向量核按 vBlockIdx 批量清零输出缓冲的逻辑做了边界收窄。原先 softmaxOutGm、dWeightGm、dqGm、dkGm、bmm3Res 五块输出的尺寸、偏移计算与 InitOutput 调用对所有 block 无条件执行;改动后为每一类输出加上 vBlockIdx < 对应 PreBlockTotal 的前置判断,仅由仍落在该缓冲分块范围内的 block 完成清零,避免越界 block 参与初始化。

主要改动

  • 按分块总数收窄清零范围: 新增 if (vBlockIdx < softmaxOutPreBlockTotal)、if (vBlockIdx < weightPreBlockTotal)、if (vBlockIdx < qPreBlockTotal)、if (vBlockIdx < kPreBlockTotal) 四个条件分支,把各输出缓冲的初始化限定在自身分块内。
  • softmaxOutGm 与 dWeightGm 初始化移入条件分支: softmaxOutPreBlock/weightPreBlock 的 init*Size、*Offset 计算与对应 InitOutput<float> 调用由原先的无条件执行改为按索引判断后执行。
  • dqGm、dkGm 初始化分别加守卫: 梯度输出 dqGm、dkGm 的尺寸(尾块与常规块区分)和偏移计算及 InitOutput<OUT_T> 调用改为各自独立的条件分支。
  • bmm3Res 与 dkGm 共用 k 分块条件: InitOutput<T>(bmm3Res[dkOffset], initdkSize, 0) 与 dkGm 的初始化一起被放入 vBlockIdx < kPreBlockTotal 分支,两者复用同一 dkOffset 与 initdkSize。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
4 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
4 days ago 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
attention ✅ Julius47, coder_linx (2/2) ✅ Julius47 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Set guijianwei,hz36amy_00,yangziqi_007,coder_linx,cheng_zhiwei,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,huang-wei-chen,liudan12,shasha_an,wangzhe123456789,Wei_NaChuan,zhangshuoleiokok,luwei_1104,cc-z,kdy18482276080,xuchengyang,shen_weiling,gaoxiang618,songjionghui,lining_210,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,haijie_699874,zzy__,Julius47,yuhao_,L_Euler,wangxun21 as approver
CANN-robotCANN-robotCollaborators
4 days ago Set guijianwei,hz36amy_00,yangziqi_007,coder_linx,cheng_zhiwei,juyangokok,monologue815,xuanyuandy,crystalhu,yu-xinjie62,huangwei791,jiang-lirui,yang-binrong,Allan_Yu,huang-wei-chen,liudan12,shasha_an,wangzhe123456789,Wei_NaChuan,zhangshuoleiokok,luwei_1104,cc-z,kdy18482276080,xuchengyang,shen_weiling,gaoxiang618,songjionghui,lining_210,wenxin_fight,miaofangzheng,mabing1118,tang-hao-hw-gitcode,haijie_699874,zzy__,Julius47,yuhao_,L_Euler,wangxun21 as approver
Lllwy0320Collaborators
4 days ago Change title to "修复dliklg算子初始化越界", originally titled "fix dliklg".
Lllwy0320Collaborators
4 days ago Modify description of pull request
llwy0320Collaborators
4 days ago Comments:

compile

likedislike
Lllwy0320Collaborators
4 days ago Pre merge succeeded (commit_id: d1efe447e40772016c36cef650834ccb374eb03e)
CANN-robot
CANN-robotCollaborators
4 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
4 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
4 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
4 days ago Added label: ci-pipeline-passed
johan_leeCollaborators4 days agoStart code review1
attention/dense_lightning_indexer_kl_loss_grad/op_kernel/arch35/dense_lightning_indexer_kl_loss_grad_kernel_base.h
@@ -729,0 +730,4 @@
730+ dqOffset = (uint64_t)vBlockIdx * qPreBlockFactor;
731+ InitOutput<OUT_T>(dqGm[dqOffset], initdqSize, 0);
732+ }
733+ if (vBlockIdx < kPreBlockTotal) {
johan_lee4 days agoComments:

【review】
问题分类:可测
位置:attention/dense_lightning_indexer_kl_loss_grad/op_kernel/arch35/dense_lightning_indexer_kl_loss_grad_kernel_base.h:733,代码:if (vBlockIdx < kPreBlockTotal) {
问题:这次用每个缓冲区自己的 PreBlockTotal 限制初始化写入。触发场景是 kernel 实际启动的向量块数大于某个缓冲区的 PreBlockTotal,或者尾块只剩 PreBlockTail 个元素。现有算子测试只有 Host InferShape 和 Tiling,后者验证 tiling key、数据与 workspace,不执行这段 InitOutput,因此移除该边界条件后现有断言仍能通过。
可能导致的结果:初始化越界或最后一个有效块漏清零都无法由现有测试识别,设备侧的越界写或梯度污染可能在后续修改中回归。
建议的修改方法:增加一个实际执行 kernel 的回归用例,选用能让 K 梯度的 PreBlockTotal 小于实际向量块数且有非整尾块的形状。用设备内存越界检测或缓冲区哨兵验证额外块不写入,并验证最后一个有效块只处理 PreBlockTail。

likedislike
Jjohan_leeCollaborators
4 days ago Resolved final issue
llwy0320Collaborators
3 days ago Comments:

compile

likedislike
Lllwy0320Collaborators
3 days ago Pre merge succeeded (commit_id: 0934ad7a7f28d28ea0f6c6dee4ba52b5325debbe)
CANN-robot
CANN-robotCollaborators
3 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
3 days ago Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
3 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
3 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
3 days ago Added label: ci-pipeline-passed
林竹
林竹Collaborators
3 days ago Comments:

/lgtm

likedislike
Julius47Collaborators
3 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
3 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
3 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
3 days ago Merged pull request