Merged
fix(pass): Fix reshape and assemble logic error #7040
niulinkaiAdd on Oct 20
fix(pass): Fix reshape and assemble logic error #7040
Merged
niulinkaiAdd on Oct 20
niulinkai
niulinkaiCollaborators
Oct 20

变更摘要
本 PR 修复了 pass 阶段中 reshape 与 assemble 相关逻辑的错误。核心改动集中在 RemoveRedundantAssemble::HanldeForSingleAssemble:原先只要 consumers.size() == 1 中的消费者为 OP_ASSEMBLE 就会删除该节点并折叠,现改为仅针对 COPY_OUT -> ASSEMBLE -> RESHAPE -> OUTCAST 这一特定模式进行折叠,并新增了在多个 COPY_IN 消费者场景下对输入进行重连(rewire)的逻辑,以保留 ReplaceTensor 刷新后的绝对 COPY_IN 属性。同时在 RemoveUnalignedReshape 中补充了对空消费者(无消费者)张量的处理,避免进入 COPY_IN 插桩路径。两处配套单测验证了新逻辑。

主要改动

收窄 RemoveRedundantAssemble 的折叠条件:HanldeForSingleAssemble 新增 reshapeToOutcast 与 rewireCopyIns 判定,仅当输出唯一消费者为 OP_RESHAPE 且节点类型为 NodeType::OUTCAST,同时输入输出 magic 相同、生产者全为 COPY_OUT、消费者仅含自身与 COPY_IN 时才执行折叠,避免误删并行的 ASSEMBLE。
新增 COPY_IN 消费者重连逻辑:在 rewireCopyIns 为真时备份消费者集合,对非自身的 COPY_IN 消费者调用 ReplaceInput(output, input),保留由 ReplaceTensor 刷新后的绝对 COPY_IN 属性;同时将 MoveTokenDependencyBeforeRemoveOp、SetAsDeleted、HandleCopyOutToAssemble 等调用对象由原消费者 *cons 统一改为当前 op。
空消费者张量的处理:RemoveUnalignedReshape::HandleNoCopyInConsumer 在完成 UB 检查后,若 output->GetConsumers() 为空则直接 return,不再走插入 COPY_IN 的路径;checkNonCopyInConsumerExists 也将 hasNoCopyInConsumer 初始化为 consumers.empty()。
新增单元测试:test_pre_graph.cpp 增加 KeepParallelAssemblesWithSiblingCopyIn,验证在存在并行 ASSEMBLE 与 COPY_IN 时保留结果并核对 COPY_IN 的绝对偏移属性;test_remove_unaligned_reshape_op.cpp 增加 TestTerminalDynamicReshapeSkipsPairedConversion,验证终端动态 reshape 场景下跳过配对转换。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for niulinkai's contribution.)
niulinkainiulinkaiCollaborators
Oct 20 Created pull request, commit 9c3d5de5
atomgit-bot
atomgit-bot
Oct 20 Comments:

变更摘要

本 PR 修复了 pass 阶段中 reshape 与 assemble 相关逻辑的错误。核心改动集中在 RemoveRedundantAssemble::HanldeForSingleAssemble:原先只要 consumers.size() == 1 中的消费者为 OP_ASSEMBLE 就会删除该节点并折叠,现改为仅针对 COPY_OUT -> ASSEMBLE -> RESHAPE -> OUTCAST 这一特定模式进行折叠,并新增了在多个 COPY_IN 消费者场景下对输入进行重连(rewire)的逻辑,以保留 ReplaceTensor 刷新后的绝对 COPY_IN 属性。同时在 RemoveUnalignedReshape 中补充了对空消费者(无消费者)张量的处理,避免进入 COPY_IN 插桩路径。两处配套单测验证了新逻辑。

主要改动

  • 收窄 RemoveRedundantAssemble 的折叠条件:HanldeForSingleAssemble 新增 reshapeToOutcast 与 rewireCopyIns 判定,仅当输出唯一消费者为 OP_RESHAPE 且节点类型为 NodeType::OUTCAST,同时输入输出 magic 相同、生产者全为 COPY_OUT、消费者仅含自身与 COPY_IN 时才执行折叠,避免误删并行的 ASSEMBLE。
  • 新增 COPY_IN 消费者重连逻辑:在 rewireCopyIns 为真时备份消费者集合,对非自身的 COPY_IN 消费者调用 ReplaceInput(output, input),保留由 ReplaceTensor 刷新后的绝对 COPY_IN 属性;同时将 MoveTokenDependencyBeforeRemoveOp、SetAsDeleted、HandleCopyOutToAssemble 等调用对象由原消费者 *cons 统一改为当前 op。
  • 空消费者张量的处理:RemoveUnalignedReshape::HandleNoCopyInConsumer 在完成 UB 检查后,若 output->GetConsumers() 为空则直接 return,不再走插入 COPY_IN 的路径;checkNonCopyInConsumerExists 也将 hasNoCopyInConsumer 初始化为 consumers.empty()。
  • 新增单元测试:test_pre_graph.cpp 增加 KeepParallelAssemblesWithSiblingCopyIn,验证在存在并行 ASSEMBLE 与 COPY_IN 时保留结果并核对 COPY_IN 的绝对偏移属性;test_remove_unaligned_reshape_op.cpp 增加 TestTerminalDynamicReshapeSkipsPairedConversion,验证终端动态 reshape 场景下跳过配对转换。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Oct 20 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Oct 20 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 20 Comments:

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robotCollaborators
Oct 20 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
9.2.0 ✅ Andy-lb, zhangyuebing (2/2) ✅ Andy-lb (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Oct 20 Set xinweiliu,cam_bxh,dai-zhentao,TianXL,lululu40888,shi-dingkun,gguuaanngg,codehjp423,jiangtao_rts,gitcode-chenjiao,hanxiaolong,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,gcw_kUomxQ2l,Andy-lb,WenboCodes as approver
8 event messages are collapsed here。 See more
niulinkainiulinkaiCollaborators
Oct 21 Associated issue: [Bug-Report|缺陷反馈]:engram算子开发过程中,使用Q3版本出现精度问题
niulinkai
niulinkaiCollaborators
Oct 21 Comments:

compile

likedislike
niulinkainiulinkaiCollaborators
Oct 21 Pre merge succeeded (commit_id: b4cd4e3e50622a526c449a308eed9c24a7487df1)
CANN-robot
CANN-robotCollaborators
Oct 21 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 21 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 21 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 21 Added label: ci-pipeline-passed
niulinkai
niulinkaiCollaborators
Oct 29 Comments:

compile

likedislike
niulinkainiulinkaiCollaborators
Oct 29 Pre merge succeeded (commit_id: 2e9df2bffddb98c7695a7922151ae387528fa50d)
CANN-robot
CANN-robotCollaborators
Oct 29 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 29 Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
Oct 29 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 29 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 29 Added label: ci-pipeline-passed
Andy-lb
Andy-lbCollaborators
Oct 29 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Oct 29 Added label: approved
zhangyuebing
zhangyuebingCollaborators
Oct 29 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Oct 29 Added label: lgtm
CANN-robotCANN-robotCollaborators
Oct 29 Merged pull request