已合并
fix(op-plugin): align native_batch_norm infer save tensors with meta/CUDA shapes. #4972
Margaret_wangrui创建于 5月18日
fix(op-plugin): align native_batch_norm infer save tensors with meta/CUDA shapes. #4972
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Margaret_wangrui 的贡献)5月18日 创建了 pull request,commit 5b3d054c
ascend-robot
5月18日 评论:
5月18日 评论:
ascend-robot
5月18日 评论:
5月18日 评论:
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 | ✅ htchu, sunyu-xuan (2/2) | ✅ htchu (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Margaret_wangrui, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月18日 添加了label:ascend-cla/yes
5月18日 修改了pull request 的描述
此处折叠了100条消息 查看更多
sunyu-xuan
5月21日 评论:
5月21日 评论:
/lgtm


5月21日 添加了label:approvedlgtm
ascend-robot
5月21日 评论:
5月21日 评论:
Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: htchu.
Reviewers who wrote a comment of /lgtm are: htchu, sunyu-xuan.


5月21日 合入了pull request
【合入来源】
说明: 修复推理模式下
native_batch_norm的save_mean/save_invstd与 PyTorch meta、CUDA 输出形状不一致(原 NPU 为[0],应为[num_features])。【修改方案】
op_plugin/config/op_plugin_functions.yaml:调整native_batch_norm推理 infer 配置中out1、out2(对应save_mean、save_invstd)的尺寸表达式,由「训练时用input.size(1)、推理时用{0}」改为 恒为input.size(1)(即num_features),与 ATen / meta 侧对推理分支输出形状的约定一致。op_plugin/ops/aclops/BatchNormKernelNpu.cpp:在 推理(training=False)分支中,将save_mean、save_invstd的分配由at::empty({0}, ...)改为at::empty({dim_c}, ...)。底层 BN Infer 仍不填充有效统计值,仅保证 张量形状与 meta、CUDA 对齐;补充注释说明设计意图。test/test_base_ops/test_native_batch_norm.py:新增TestNativeBatchNormInferSaveShapes,校验 NPU 上save_mean、save_invstd为(C,),并与同配置的 CPU、metanative_batch_norm输出形状一致;顺带整理无关 import。交互关系简述: PyTorch 调用链 → op-plugin 注册的
native_batch_normNPU 实现 → ACL 算子执行;本次变更集中在 算子出口张量分配 与 YAML infer 元数据,不涉及 CANN 接口版本升级。【资料变更】
不涉及。
【接口变更】
不涉及
【功能验证】
测试场景: 推理
native_batch_norm(training=False)时,save_mean、save_invstd的形状须为(num_features,),并与 CPU、meta 一致。测试方法: 运行
test/test_base_ops/test_native_batch_norm.py(需 NPU 可用);其中TestNativeBatchNormInferSaveShapes为本次新增 UT;回归TestNativeBatchNormLegit。UT 看护: 已新增
TestNativeBatchNormInferSaveShapes。【CheckList】