已合并
新增ut 测试 #5394
L1919_snow创建于 7月6日
新增ut 测试 #5394
已合并
L1919_snow创建于 7月6日
L1919_snow成员
7月6日

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

  • 需求
  • 问题单
  • issue/工单
  • 重构优化
  • 资料更新

【修改方案】

新增测试脚本

【资料变更】

“不涉及”

【接口变更】

“不涉及”

【功能验证】

image.png

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

  • 代码注释完备,正确记录错误日志
  • 代码实现进行了返回值、空指针等校验
  • PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
  • PR持续集成流水线(CI)执行通过,代码检查无异常
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 L1919_snow 的贡献)
LL1919_snow成员
7月6日 创建了 pull request,commit 40e743e6
atomgit-bot
atomgit-bot
7月6日 评论:

变更摘要

本次 PR 主要为 NPU 算子新增单元测试,覆盖 NpuDropPathnpu_renorm_backward 两个功能模块。测试均基于 torch_npu 运行在 NPU 设备上,验证前向传播、反向传播的正确性,以及与 PyTorch 原生自动微分结果的一致性。变更不涉及任何业务代码修改,仅新增 2 个测试文件。

主要改动

  • 新增 NpuDropPath 单元测试: 在 test/test_base_ops/test_drop_path.py 中新增 TestNpuDropPath 测试类,覆盖基础前向传播、drop_prob=0 时输出与输入一致、反向传播 autograd 流程、以及训练/评估模式下丢弃行为的差异验证。
  • 新增 npu_renorm_backward 单元测试: 在 test/test_base_ops/test_npu_renorm_backward.py 中新增 TestNPURenormBackward 测试类,验证自定义反向算子 torch_npu.npu_renorm_backward 的基础调用,并与 PyTorch 原生 torch.renorm 自动微分结果进行精度对比。
  • 多维度参数覆盖: npu_renorm_backward 测试涵盖多种 p 值(0.5、1、1.5、2、3)、不同 dim(含负数)、不同 maxnorm、3D/4D 张量、float16/bfloat16 低精度、全零输入及大张量等边界场景,确保算子实现的鲁棒性。
likedislike
atomgit-bot
atomgit-bot
7月6日 评论:

代码审查

审查总结

审查覆盖的文件:

  • test/test_base_ops/test_drop_path.py — 发现 1 个问题(P2)
  • test/test_base_ops/test_npu_renorm_backward.py — 未发现问题

按优先级统计:

优先级 数量
P0 0
P1 0
P2 1
P3 0

整体风险评估:

此 PR 新增两个 NPU 算子单元测试文件,共 227 行代码。test_npu_renorm_backward.py 覆盖了多种 p 值、维度、maxnorm 值、不同精度(float16/bfloat16)、边界情况(零张量、负 dim、大张量),测试逻辑完整且正确。test_drop_path.py 存在一处测试质量问题:test_train_eval_mode 对训练模式的 dropout 行为未做断言,导致该测试在 NpuDropPath 训练模式存在 bug 时仍会通过,降低了测试的回归保护价值。整体风险较低,建议修复 test_train_eval_mode 中的缺失断言后再合入。

类型 数量
🔴 阻塞 0
🟡 建议 2

💬 仅评论

likedislike
ascend-robotascend-robot成员
7月6日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
7月6日 评论:

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


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/op-plugin liangsongwei, culechan (2/2) liangsongwei (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
ascend-robotascend-robot成员
7月6日 添加了label:needs-issue
ascend-robot
ascend-robot成员
7月6日 评论:

Linking Issue Notice

@l1919_snow , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .

likedislike
L1919_snow成员
7月6日 评论:

compile

likedislike
ascend-robotascend-robot成员
7月6日 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
7月6日 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
7月6日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
7月6日 评论:

ascend docs pipeline is running...

likedislike
ascend-robot
ascend-robot成员
7月6日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
7月6日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
7月6日 添加了label:docs-ci-pipeline-success
ascend-robot
ascend-robot成员
7月6日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
7月6日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
7月6日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
7月6日 评论:
流水线 PR-pipeline_op-plugin#2478 [ commitID:7300ce13 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_master_ARM >>>
Build_v2_7_1_ARM >>>
Build_v2_9_0_ARM >>>
Build_v2_10_0_ARM >>>
Build_v2_11_0_ARM >>>
Build_v2_12_0_ARM >>>
Build_master_x86 >>>
Build_v2_7_1_x86 >>>
Build_v2_9_0_x86 >>>
Build_v2_10_0_x86 >>>
Build_v2_11_0_x86 >>>
Build_v2_12_0_x86 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck >>>
CodeCheck_pre-commit >>>
开源片段检查 SCA >>>
开发者测试 UT_master_ARM_01 >>>
UT_v2_7_1_ARM >>>
UT_v2_9_0_ARM >>>
UT_v2_10_0_ARM >>>
UT_v2_11_0_ARM >>>
UT_v2_12_0_ARM >>>
流水线 PR-pipeline_op-plugin >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
atomgit-bot
atomgit-bot7月6日进行代码检视1
test/test_base_ops/test_drop_path.py
@@ -0,0 +44,4 @@
44+ drop_path.eval()
45+ eval_output = drop_path(x)
46+ self.assertTrue(torch.allclose(eval_output, x))
47+ print(f"训练模式是否有丢弃: {has_zero_train.item()}")
atomgit-bot
atomgit-bot7月6日评论:

🟡 Medium Priority

test_drop_path.pytest_train_eval_mode 方法中(第 41-47 行),has_zero_train = (train_output == 0).any() 计算了训练模式下输出中是否存在被丢弃(置零)的元素,但该变量仅在 print 中使用,从未通过 assertTrue 或其他断言进行验证。测试仅对 eval 模式的输出做了断言(第 46 行),而对训练模式的丢弃行为没有任何断言。这意味着如果训练模式存在 bug 导致完全不丢弃(与 eval 模式行为一致),该测试仍会通过,无法起到验证训练模式正确性的作用。

建议:对 has_zero_train 增加断言,例如 self.assertTrue(has_zero_train.item(), "训练模式下应有丢弃行为");或使用更严格的检查(如确认丢弃比例在合理范围内)。同时移除 print 语句或用日志替代。

likedislike
atomgit-bot
atomgit-bot7月6日进行代码检视1
test/test_base_ops/test_drop_path.py
@@ -0,0 +44,4 @@
44+ drop_path.eval()
45+ eval_output = drop_path(x)
46+ self.assertTrue(torch.allclose(eval_output, x))
47+ print(f"训练模式是否有丢弃: {has_zero_train.item()}")
atomgit-bot
atomgit-bot7月6日评论:

🟡 Medium Priority

test_train_eval_mode (line 35-47) 声称测试"训练模式 vs 评估模式",但仅对评估模式做了断言 (self.assertTrue(torch.allclose(eval_output, x))),训练模式下的 has_zero_train 仅被 print 输出,未做任何断言。若 NpuDropPath 在训练模式下存在 bug(例如即使 drop_prob=0.5 也从不丢弃),该测试仍会通过,无法起到回归保护作用。

对于一个形状为 (68, 5) = 340 元素的张量,drop_prob=0.5 时没有任何元素被丢弃的概率为 (0.5)^340 ≈ 10⁻¹⁰²,实际不可能发生。因此可以安全地添加断言,例如 self.assertTrue(has_zero_train.item(), "training mode should drop elements")self.assertFalse(torch.allclose(train_output, x))

建议:在 test_train_eval_mode 中对训练模式的行为添加断言。推荐方案:检查 has_zero_train 为 True(训练模式下应有元素被置零),或检查 train_outputx 不 allclose(标准 DropPath 在训练时会对保留值做 scale,因此不可能与输入完全一致)。同时移除或保留 print 语句均可,但断言是必须的。

likedislike
LL1919_snow成员
7月7日 修改了pull request 的描述
此处折叠了5条事件消息 查看更多
LL1919_snow成员
7月7日 解决了最后一个问题
梁松伟
梁松伟成员
7月7日 评论:

/approve

likedislike
ascend-robotascend-robot成员
7月7日 添加了label:approved
culechan
culechan成员
7月7日 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
7月7日 添加了label:lgtm
LL1919_snow成员
7月7日 关联了issue:[Bug]: Tensor.renorm 反正实现问题修改
ascend-robotascend-robot成员
7月7日 删除了label:needs-issue
ascend-robotascend-robot成员
7月7日 合入了pull request
ascend-robot
ascend-robot成员
7月7日 评论:

Pull Request 已合并或已关闭。

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

likedislike