Merged
fix:apply_came_part4中图原型与算子原型参数名不一致 #13551
陈思Add on 18 days ago
fix:apply_came_part4中图原型与算子原型参数名不一致 #13551
Merged
陈思Add on 18 days ago
陈思
陈思Collaborators
18 days ago

描述

修复 ApplyCamePart4 的 OpDef、GE 原型和二进制配置之间的参数声明不一致,并补全参考实现的数值异常检查。

  • 将 OpDef 及 ascend350/ascend950 二进制配置的输入输出名称统一为 GE 原型中的 param/r/c。
  • 调整两个平台二进制配置的输入顺序:sum_u_r/sum_u_c/sum_u_rc 对应 index 7/8/9,可选输入 sum_r 对应 index 10,global_shape 对应 index 11;同步 kernel 入口注释。
  • Torch 对照实现按 GE 输入名显式绑定参数,使用 Torch 张量运算;CPU golden 和输入定制函数支持省略 sum_r、global_shape。
  • CPU golden 与 Torch 对照实现对 denom <= 0、非有限 denom、非正或非有限归一化 rc、非有限 param 输出抛出 ValueError,避免 NaN/Inf 进入精度比较。有效输入按 kernel 的倒数乘法路径计算,param 更新使用舍入后的 r_out/c_out。

关联的Issue

关联 Issue:#8118

https://gitcode.com/cann/ops-nn/issues/8118

测试

  • 对本次 5 个变更文件运行仓库 pre-commit,所有适用检查通过,包括 clang-format、ruff check/format、JSON、codespell、OAT。
  • Torch CPU 共 30 组定向场景验证通过:FP32/FP16/BF16 常规更新、可选输入省略、低精度舍入路径,以及零/负/非有限 denom、两项抵消、rc 为零或负值时的显式报错。
  • 静态核对 OpDef、GE 原型和两平台所有二进制配置的输入名称及顺序,通过;git diff --check 通过。
  • 未进行 NPU 上板验证。

文档更新

更新 kernel 入口参数顺序注释及 golden 的数值域说明。

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 陈思's contribution.)
陈思陈思Collaborators
18 days ago Created pull request, commit b6d8b043
atomgit-bot
atomgit-bot
18 days ago Comments:

变更摘要

本 PR 修复 optim/apply_came_part4 算子中图原型与算子原型的参数名不一致问题:将算子原型定义中的输入/输出名称(param_in/r_in/c_in、param_out/r_out/c_out)统一改为与图原型一致的 param/r/c,并同步更新 ascend350、ascend950 两个平台的 binary 配置以及测试侧 golden 实现中的参数绑定方式。

主要改动

  • 算子原型 I/O 名称统一:apply_came_part4_def.cpp 中 Input 由 param_in、r_in、c_in 改为 param、r、c,Output 由 param_out、r_out、c_out 改为 param、r、c,数据类型、格式与 REQUIRED 约束保持不变。
  • binary 配置输入名称同步:config/ascend350/apply_came_part4_binary.json 与 config/ascend950/apply_came_part4_binary.json 中 fp32/float16/bf16 三个 bin 的 inputs 和 outputs 名称同步改为 param、r、c,与算子原型保持一致。
  • 可选输入 sum_r 在输入列表中的位置调整:两份 binary 配置中将可选输入 sum_r 从 index 7 移到末尾 index 10,sum_u_r、sum_u_c、sum_u_rc 的索引相应前移为 7、8、9,global_shape 保持 index 11。
  • golden 计算接口改为按 GE 输入名显式接收参数:tests/assets/golden.py 中 _ApplyCamePart4Compose.__init__ 不再保存 kwargs,__call__ 改为以 param、m、r、c、weight_decay、lr、beta3、sum_u_r、sum_u_c、sum_u_rc、sum_r、global_shape 等具名参数接收输入,并删除了不再使用的 _to_numpy_for_golden。
  • golden 数值流程明确化:__call__ 内统一转为 float32 计算,r/c 输出先按低精度舍入得到,再参与 rc 与 param_out 的更新计算,最终返回 [param_out, r_out, c_out] 三个结果。

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

likedislike
Incorrect?
atomgit-bot
atomgit-bot
18 days ago Comments:

代码审查

✅ 未发现问题


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

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
18 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
18 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
*/*/op_host/*_def.cpp ✅ 汤磊, 陈琦, 汤平川 (3/2) ✅ 汤磊 (1/1)
optim ✅ 汤平川, 陈琦 (2/2) ✅ 汤平川 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
63 messages are collapsed here。 See more
wangyongguang
wangyongguangCollaborators
16 days ago Comments:

✅ LGTM - apply_came_part4 输入顺序修复 (sum_r index 调整)

接口变更:

  • sum_r: index 7 → 10 (optional 参数后移)
  • sum_u_r/sum_u_c/sum_u_rc: index 8/9/10 → 7/8/9 (前移)
  • 输入/输出命名简化:param_in → param, r_in → r, param_out → param

golden.py 修复:

  • 新增 denom 有效性检查 (finite + > 0)
  • 拒绝 NaN/Inf/负数传递给精度比较器
  • _checked_param_update() 新增验证

影响:调用方需按新 index 传参 (sum_r 从第 8 个参数移到第 11 个)

推荐批准。

/approve

likedislike
fanzhaoyun001fanzhaoyun001
16 days ago Resolved final issue
CANN-robotCANN-robotCollaborators
16 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
16 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
16 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike