已合并
fix(threshold_grad_v2_d): 对齐接口及比较语义 #9150
fix(threshold_grad_v2_d): 对齐接口及比较语义 #9150
已合并
babeiee创建于 8月25日
babeiee
8月25日

描述

  • 将 ThresholdGradV2D OpDef 的输入输出名称调整为 gradients、features、backprops,并将 threshold 调整为必选属性,与 GEIR 原型保持一致。
  • Kernel 改为直接执行 features > threshold 比较并正向选择 gradients,修正 NaN 等非全序值下由反向比较导致的语义偏差。
  • Golden 同步显式广播及 features > threshold ? gradients : 0 计算语义。
  • 本 PR 仅包含用户指定的 3 个文件。

关联的Issue

[]https://gitcode.com/cann/ops-nn/issues/5107

测试

  • staged pre-commit:全部通过,包括 clang-format、ruff、codespell、OAT。
  • pre-push FAST:JIT build、ophost UT、opkernel UT、Ascend 950 打包全部通过。
  • GitCode 远端 Git hooks:通过。

文档更新

不涉及。

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 babeiee 的贡献)
Bbabeiee
8月25日 创建了 pull request,commit e8f8a1d9
atomgit-bot
atomgit-bot
8月25日 评论:

变更摘要

本 PR 修复 ThresholdGradV2D 算子的接口命名与比较语义:将 OpDef 的输入输出名称对齐为 gradients、features、backprops,并把 threshold 属性由可选改为必选;Kernel 由反向比较(LE)改为直接执行 features > threshold(GT)并正向选择 gradients,避免 NaN 等非全序值下的语义偏差;Golden 同步为显式广播后按 features > threshold ? gradients : 0 计算。

主要改动

  • 对齐 OpDef 接口命名与属性(threshold_grad_v2_d_def.cpp):将输入 gradOutput/self、输出 out 分别重命名为 gradients/features/backprops,并将 threshold 由 OPTIONAL(默认 1.0)改为 REQUIRED 必选属性,与 GEIR 原型保持一致。
  • Kernel 改用正向比较语义(threshold_grad_v2_d_dag.h):将 COMPARE_MODE_LE(3)替换为 COMPARE_MODE_GT(1),并调整 Vec::Select 的输入顺序为 Compare, OpCopyInGradCast, data_zero,直接按 features > threshold 正向选择 gradients,修正反向比较导致的 NaN 等非全序值语义偏差。
  • Golden 同步计算语义(tests/assets/golden.py):改为先用 torch.broadcast_tensors 显式广播,再以 self_t > threshold 生成 mask,通过 torch.where(mask, grad_output, zeros) 实现 features > threshold ? gradients : 0。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月25日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
8月25日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月25日 评论:

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 ✅ 王永光, 唐玮玮 (2/2) ✅ 王永光 (1/1)
activation ✅ 唐玮玮, 王星 (2/2) ✅ 王星 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
CANN-robot
CANN-robot成员
8月25日 评论:

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
8月25日 将zengjuan,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,wangrui_,renruhai,su-yueming,zhajianqing123,tang-lei01,chenqi317,wang-xing001,liubo75,tangweiwei2,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong,wangyongguang设为评审人
CANN-robotCANN-robot成员
8月25日 将kevin_huang1234,wangrui_,renruhai,su-yueming,zhajianqing123,tang-lei01,wang-xing001,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong,wangyongguang设为审查人
babeiee
8月25日 评论:

/ai summary

likedislike
atomgit-bot
atomgit-bot
8月25日 评论:

⚠️ 已有 AI 任务正在处理中,请稍候,无需重复触发。

likedislike
不准确?
Bbabeiee
8月25日 修改了pull request 的描述
babeiee
8月25日 评论:

compile

likedislike
Bbabeiee
8月25日 预合并成功(commit_id: 16f1f65a0b552bfad3425ab52186eae6cb13f233)
CANN-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
8月25日 评论:

流水线任务触发成功
任务链接 [7579baa786ab4ce9939a3b3b8460ae85][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_classify ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_9030_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
UT_Test_report_lcov ⚠️ WARNING >>>>>

[2026-08-25 11:40:56]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
8月25日 评论:

流水线任务触发成功
任务链接 [9c09d69eac9e4aaaaf9d3f88e95115d4][流水线指导]

任务名称状态日志下载链接
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_precommit ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>

[2026-08-25 11:26:41]    CI执行结束

likedislike
CANN-robotCANN-robot成员
8月25日 添加了label:api-check-pass
CANN-robotCANN-robot成员
8月25日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-passed
yuning_chen
yuning_chen成员
8月25日 评论:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!

likedislike
tangweiwei2成员
8月25日 评论:

/lgtm

likedislike
wang-xing001成员
8月27日 评论:

/lgtm
/approve

likedislike
wangyongguang成员
8月27日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月27日 添加了label:lgtmapproved
CANN-robotCANN-robot成员
8月27日 关闭了关联的issue
CANN-robotCANN-robot成员
8月27日 合入了pull request