Merged
fix(operator): Make ScatterUpdate update dst inplace and preserve slot symbol #6120
fix(operator): Make ScatterUpdate update dst inplace and preserve slot symbol #6120
Merged
gaoxingwangAdd on Sep 10
gaoxingwang
gaoxingwangCollaborators
Sep 10

fix(operator): Make ScatterUpdate update dst inplace and preserve slot symbol

Sync of #6028 (merged to master) to release branch 9.2.0.

ScatterUpdate returned a new tensor while leaving dst unchanged, which
broke inplace semantics and lost dst ARG symbol in codegen when the
src slot (nameless inplace-view SSA) took over dst registration.

Changes:

  • Change ScatterUpdate dst parameter to a mutable reference and assign result back to dst so the caller-side tensor reflects the update
  • Register input names at param-declaration time via the new TensorSlotManager::MarkInputName (called in RootFunctionBuilder::InitDynFunc and RecordFunc::RecordDynFuncInner), so inputNameList keeps the original ARG symbols before any SetSameSlot migration
  • Keep slot marking and startArgs fill in BuildDynSlotScope unchanged
  • Register pypto.scatter_update in _patch_methods so inplace slot tracking covers it

Related Issues: #3260

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for gaoxingwang's contribution.)
gaoxingwanggaoxingwangCollaborators
Sep 10 Created pull request, commit 17c2f150
gaoxingwanggaoxingwangCollaborators
Sep 10 Associated issue: [Bug-Report|缺陷反馈]: ScatterUpdate整块回写,没有outcast,跨函数消费者与写者无法建立正确依赖,无序导致GLM AttentionFusion概率精度失败
atomgit-bot
atomgit-bot
Sep 10 Comments:

变更摘要

本 PR 将 #6028 同步到 9.2.0 发布分支,修复 ScatterUpdate 的原地语义与槽位符号保留问题:此前 ScatterUpdate 返回新张量而 dst 保持不变,且当 src 槽位(无名的 inplace-view SSA)接管 dst 注册时会在 codegen 中丢失 dst 的 ARG 符号。核心改动包括:将 ScatterUpdate 的 dst 参数改为可变引用并在调用后把结果写回 dst;新增 TensorSlotManager::UpdateInputSlot 并按索引更新输入槽位;在 RootFunctionBuilder::InitDynFunc 参数声明阶段即通过 MarkInput 登记输入名,并在 DyndevFunctionAttribute 中新增 startArgsInputSlotTensorList 持有共享所有权,确保槽位张量在 SetSameSlot 迁移后仍存活;同时在 _patch_methods 中注册 pypto.scatter_update 使原地槽位跟踪覆盖该算子。

主要改动

  • ScatterUpdate 改为原地更新 dst: ScatterUpdate 的 dst 参数由 const Tensor& 改为可变引用 Tensor&(涉及 tilefwk_op.h、scatter_update.cpp 及 Python 绑定 operation.cpp),并在底层算子调用后执行 dst = result; 将结果赋回 dst,使调用侧张量反映更新结果。

  • 新增 UpdateInputSlot 槽位管理接口: 在 TensorSlotManager 中新增 UpdateInputSlot 方法(tensor_slot.h 声明、tensor_slot.cpp 实现),按索引更新 inputSlotList 中的槽位并同步维护 inputSlotDict;RootFunctionBuilder::BuildDynSlotScope 中原先的 MarkInput 调用改为 UpdateInputSlot(idx, *tensor),并相应按索引回填 startArgsInputTensorList 与 startArgsInputSlotTensorList。

  • 参数声明阶段登记输入以保留 ARG 符号: RootFunctionBuilder::InitDynFunc 遍历 irFunc->params_ 时即调用 slotManager->MarkInput(*tensor) 登记输入,并在 DyndevFunctionAttribute 中新增 startArgsInputSlotTensorList(std::vector<std::shared_ptr<Tensor>>),在 SetSameSlot 迁移槽位前持有共享所有权,使 inputNameList 保留原始 ARG 符号。

  • 注册 pypto.scatter_update 到 _patch_methods: 在 python/pypto/pil/ops.py 的 _patch_methods 列表中加入 (pypto, "scatter_update", 0),使原地槽位跟踪覆盖该算子。

  • 更新原地写后读依赖的测试用例: test_scatter_update_keeps_write_after_read_dependency.pypto 中 INDEX_OUTCAST 的结果 SSA 由无名的 %$1@5 变为保留目标符号的 %target_0@5,且 return 语句相应返回 %target_0@5,验证 dst 槽位符号得以保留。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 10 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 10 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 10 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
framework/include/tilefwk ✅ tsungl4, 尹杰 (2/2) ✅ tsungl4 (1/1)
framework/src/interface/function ✅ tsungl4, 尹杰 (2/2) ✅ tsungl4 (1/1)
framework/src/interface/operation ✅ tsungl4, 尹杰 (2/2) ✅ tsungl4 (1/1)
framework/src/interface/tensor ✅ tsungl4, 尹杰 (2/2) ✅ tsungl4 (1/1)
python/pypto/pil ✅ tsungl4, 尹杰 (2/2) ✅ tsungl4 (1/1)
python/src/bindings/operation.cpp ✅ tsungl4, 尹杰 (2/2) ✅ tsungl4 (1/1)
repo-cann/pypto ✅ tsungl4, 尹杰 (2/2) ✅ tsungl4 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
Sep 10 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
gaoxingwang
gaoxingwangCollaborators
Sep 10 Comments:

/compile

likedislike
gaoxingwanggaoxingwangCollaborators
Sep 10 Pre merge succeeded (commit_id: c595800990e16291b28eff00610d3e8c23691e31)
CANN-robot
CANN-robotCollaborators
Sep 10 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 10 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 10 Added label: ci-pipeline-passed
Jie Yin
Jie YinCollaborators
Sep 10 Comments:

/lgtm

likedislike
lidongsheng
lidongshengCollaborators
Sep 10 Comments:

/approve

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