Pull Request已成功合入, 合并人@CANN-robot
(感谢 babeiee 的贡献)变更摘要
本 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。


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
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


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


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


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


/lgtm


/lgtm
/approve


/approve


描述
gradients、features、backprops,并将threshold调整为必选属性,与 GEIR 原型保持一致。features > threshold比较并正向选择 gradients,修正 NaN 等非全序值下由反向比较导致的语义偏差。features > threshold ? gradients : 0计算语义。关联的Issue
[]https://gitcode.com/cann/ops-nn/issues/5107
测试
文档更新
不涉及。
类型标签
AI/Agent生成声明