Merged
fix(bce_with_logits_bwd): 空 self 不再跳过 shape 校验 #13156
sunhao_hwAdd on 23 days ago
fix(bce_with_logits_bwd): 空 self 不再跳过 shape 校验 #13156
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for sunhao_hw's contribution.)23 days ago Associated issue: [Bug-Report|缺陷反馈]: aclnnBinaryCrossEntropyWithLogitsBackward 空 self 跳过 shape 校验,非法入参返回 0 且不写输出
23 days ago Associated issue: [Bug-Report|缺陷反馈]: aclnnBinaryCrossEntropyWithLogitsBackward 空 self 跳过 shape 校验,非法入参返回 0 且不写输出
atomgit-bot
23 days ago Comments:
23 days ago Comments:
变更摘要
本 PR 修复 aclnnBinaryCrossEntropyWithLogitsBackward 在 self 为空张量时绕过参数校验的问题。此前 CheckShape 对空 self 直接返回成功,使 self 与 target、out 的 shape 一致性检查以及 gradOutput、weight、posWeight 的 broadcast 校验被跳过,非法入参因此返回成功而非 161002。改动后空张量的 0 尺寸维度仍参与 shape 与 broadcast 校验,类型提升校验也提前到空张量短路之前,同时在 UT 中新增空 shape 非法入参用例。
主要改动
CheckShape移除空张量提前返回:删除self->IsEmpty()时直接返回true的分支,使self为空时仍执行与target、out的 shape 一致性检查及后续 broadcast 校验。CheckParams前置CheckPromoteType:在返回成功前新增第 7 步 dtype 提升校验并映射为ACLNN_ERR_PARAM_INVALID,避免空self短路导致跳过类型提升校验。- 新增 UT 用例
case_empty_shape_invalid:在test_aclnn_binary_cross_entropy_with_logits_backward.cpp中覆盖三种非法入参,分别是outshape 不一致、targetshape 不一致、gradOutput无法 broadcast 到空self,均断言返回ACLNN_ERR_PARAM_INVALID。 - 保持合法空张量的原有行为:shape 合法的空
self仍在计算侧短路返回、不发起 kernel,仅校验收紧,合法场景行为不变。
🧩 本次 Review 已使用自定义 Skill:


Incorrect?
atomgit-bot
23 days ago Comments:
23 days ago Comments:


Incorrect?
23 days ago Added label: cann-cla/yes
41 messages are collapsed here。 See more
CANN-robot
20 days ago Comments:
20 days ago Comments:
The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: 杨阳


20 days ago Added label: lgtmapproved
20 days ago Closed associated issue
20 days ago Merged pull request
CANN-robot
20 days ago Comments:
20 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
aclnnBinaryCrossEntropyWithLogitsBackward 在 self 为空张量时,CheckShape 直接返回成功,跳过 self 与 target、out 的 shape 一致性以及 gradOutput、weight、posWeight 的 broadcast 校验;GetWorkspaceSize 随后短路返回 ACLNN_SUCCESS,第二段不写 out。非法 shape 因此返回 0,而不是资料要求的 161002。
修改 loss/sigmoid_cross_entropy_with_logits_grad_v2/op_api/aclnn_binary_cross_entropy_with_logits_backward.cpp:
并在 tests/ut/op_host/test_aclnn_binary_cross_entropy_with_logits_backward.cpp 增加 case_empty_shape_invalid,覆盖 out、target shape 不一致以及 gradOutput 不能 broadcast 到空 self 的三种入参。
按检视意见,将 aclnn 资料中 self 的维度约束由 1-8 改为 0-8。
关联的Issue
关联Issue #7133(Close #7133)
https://gitcode.com/cann/ops-nn/issues/7133
测试
在 CANN 9.2.0、Atlas A2(910B3)上用修改后的 op_api 覆盖原库复现:
文档更新
更新了 loss/sigmoid_cross_entropy_with_logits_grad_v2/docs/aclnnBinaryCrossEntropyWithLogitsBackward.md 与 aclnnBinaryCrossEntropyWithLogitsBackward_en.md,self 的维度(shape)由 1-8 改为 0-8。
类型标签
AI/Agent生成声明