Pull Request已成功合入, 合并人@CANN-robot
(感谢 Chao-Wu 的贡献)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 |
|---|---|---|
| norm | ✅ 刘杰, 任如海 (2/2) | ✅ 刘杰 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
huangxiaochencha, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [828f99cdabce44feb57facc11de38045][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-06-23 20:46:36] CI执行结束


流水线任务触发成功
任务链接 [ba203279df1e4495b95c30075dc20f72][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
| SCA | ✅ SUCCESS | >>>>> |
[2026-06-23 20:41:22] CI执行结束


/lgtm
/approve


变更摘要
本 PR 针对 SyncBatchNormGatherStatsFused 算子进行除法精度修复,主要解决该算子在计算全局均值、方差、running_mean、running_var 及 invstd 时因除法精度不足导致的计算误差问题。修复方式是在所有涉及除法运算的核函数中,将 Div 调用统一显式指定高精度除法配置 DivAlgo::PRECISION_0ULP_FTZ_FALSE(0 ULP 误差),替换原先可能使用的默认低精度除法算法。同时清理了一个不再需要的测试 tiling 定义文件。
主要改动
-
统一引入高精度除法配置: 在
sync_batch_norm_gather_stats_fused_common.h、sync_batch_norm_gather_stats_fused_first_axis_common.h、sync_batch_norm_gather_stats_fused_first_axis_workspace.h、sync_batch_norm_gather_stats_fused_workspace.h四个核函数类中,均添加了static constexpr DivConfig divConfig = {DivAlgo::PRECISION_0ULP_FTZ_FALSE}成员常量,确保所有除法操作使用最高精度算法。 -
Div调用模板化以启用高精度: 在sync_batch_norm_gather_stats_fused_common.h的ComputeGlobalMean/ComputeGlobalVar、sync_batch_norm_gather_stats_fused_first_axis_common.inl的ComputeGlobalMean/ComputeGlobalVar、以及sync_batch_norm_gather_stats_fused_workspace.h的ComputeGlobalInvstdWithRunningVar等函数中,将原有Div调用统一改为Div<float, divConfig>形式,显式使用高精度除法配置。 -
运行态计算路径精度修复: 在
sync_batch_norm_gather_stats_fused_compute.h的SyncBatchNormGatherStatsFusedRunningCompute::compute中,已有的divConfig确保三处Div调用(buffer3_、buffer4_相关计算)均使用高精度配置,与其余路径保持一致。 -
删除冗余测试文件: 移除了
sync_batch_norm_gather_stats_fused_tiling_def.h(-166 行),该文件为测试用的 tiling 定义头文件,不再需要。


代码审查
审查总结
审查结果统计
| 优先级 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 1 |
| P3 | 1 |
整体风险评估:低风险
该 PR 的核心变更是将所有 Div(...) 调用替换为 Div<float, divConfig>(...),其中 divConfig = {DivAlgo::PRECISION_0ULP_FTZ_FALSE},以提升除法运算精度(0 ULP 误差,不冲刷次正规数)。变更范围涵盖 5 个 kernel 类和 1 个 .inl 文件,所有 Div 调用点均已一致替换,无遗漏。
各文件审查结果
| 文件 | 审查结论 |
|---|---|
sync_batch_norm_gather_stats_fused_common.h |
无代码缺陷;5 处 Div 调用已正确替换,divConfig 成员声明正确 |
sync_batch_norm_gather_stats_fused_compute.h |
无代码缺陷;3 处 Div 调用已正确替换,divConfig 成员声明正确 |
sync_batch_norm_gather_stats_fused_first_axis_common.h |
无代码缺陷;函数声明重排仅为格式调整,无功能影响;divConfig 声明正确 |
sync_batch_norm_gather_stats_fused_first_axis_common.inl |
无代码缺陷;2 处 Div 调用已正确替换 |
sync_batch_norm_gather_stats_fused_first_axis_workspace.h |
无代码缺陷;2 处 Div 调用已正确替换,divConfig 声明正确 |
sync_batch_norm_gather_stats_fused_workspace.h |
无代码缺陷;5 处 Div 调用已正确替换,divConfig 声明正确 |
tests/ut/op_kernel/CMakeLists.txt(已删除) |
P2:移除了 kernel 级 UT 测试基础设施 |
tests/ut/op_kernel/sync_batch_norm_gather_stats_fused_tiling_def.h(已删除) |
P2:同上,配套的测试数据结构文件 |
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


🔵 Low Priority
PR 描述为"除法精度修复",但未添加任何用于验证精度改进或防止回归的测试用例。该算子涉及 5 个不同变体(common、compute、workspace、first_axis_common、first_axis_workspace),共计替换了约 17 处 Div 调用。精度修复是关键变更,缺乏对应的回归测试会增加未来重构或 SDK 升级时精度回退的风险。
建议:添加针对该精度修复的回归测试用例,验证 PRECISION_0ULP_FTZ_FALSE 除法模式下的数值精度符合预期。


描述
SyncBatchNormGatherStatsFused算子除法精度修复
关联的Issue
https://gitcode.com/cann/ops-nn/issues/3510
测试
文档更新
类型标签