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


Linking Issue Notice
@wangzili121 , 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 .


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.12.0-26.1.0 | ||
| v2.7.1-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| v2.10.0-26.1.0 | ||
| v2.9.0-26.1.0 | ||
| v2.7.1 | ||
| v2.12.0 | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.9.0 | ||
| ci-test | ||
| sync-pr28113--to-v2.9.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


compile


Ascend docs pipeline is running...


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


Ascend docs pipeline is running...


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


变更摘要
该 PR 回退了之前的一个提交("fix: fix aclnn npu_format_cast to respect allow_internal_format=False"),即撤消了使 aclnn npu_format_cast 路径遵从 allow_internal_format=False 配置的修复。回退后,FormatCastKernelNpu.cpp 中移除了此前新增的 13 行相关逻辑代码,test/npu/test_c10d.py 中的测试用例也相应回滚至修复前的状态。
主要改动
-
回退
FormatCastKernelNpu.cpp中 aclnn 格式转换对allow_internal_format的处理逻辑:移除了原修复在MaybeUseAclnnNpuFormatCast或npu_format_cast_impl等函数中新增的、用于在allow_internal_format=False时限制内部格式转换的 13 行代码,当前代码不再对allow_internal_format配置做特殊判断。 -
回滚测试文件
test/npu/test_c10d.py中的相关测试变更:恢复至修复前的测试代码(+9 行,-13 行),撤消了原修复为验证allow_internal_format=False行为而新增或调整的测试用例。 -
整体影响:此次回退意味着 aclnn 路径的
npu_format_cast恢复至不感知allow_internal_format配置的状态,可能影响依赖该配置项控制内部格式行为的场景。


代码审查
I've completed the thorough review of both files. Let me file the closing summary.
审查总结
审查覆盖的文件
| 文件 | 审查结果 |
|---|---|
torch_npu/csrc/aten/common/FormatCastKernelNpu.cpp |
发现 1 个 P1 问题 |
test/npu/test_c10d.py |
无问题(测试变更安全,与回退逻辑一致) |
发现问题统计
- P0: 0
- P1: 1(ACLNN 路径下
allow_internal_format=False不再生效,属于功能回归) - P2: 0
- P3: 0
整体风险评估
高风险回退。本 PR 删除了 MaybeDowngradeInternalFormat 守卫函数,该函数是 ACLNN 格式转换路径中唯一强制执行 allow_internal_format=False 的检查点。由于 ACLNN 路径通过 create_tensor_with_format_and_shape 直接创建张量,完全绕过了 TensorFactories::unsafe_empty_with_format 中的等价检查,因此在 ACLNN 路径(包括 ACLNN-only 设备的所有场景)上,allow_internal_format=False 设置被完全忽略。这可能导致 NPU Graph 捕获失败、精度异常以及不同代码路径间的行为不一致。建议恢复被回退的修复或在其替代位置(如 create_tensor_with_format_and_shape)补充等价检查。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


🟠 High Priority
问题
本 PR 删除了 MaybeDowngradeInternalFormat 函数及其在 MaybeUseAclnnNpuFormatCast 中的调用。该函数是 ACLNN 格式转换路径中唯一 执行 allow_internal_format=False 检查的守卫。
证据链
-
删除的函数 (
MaybeDowngradeInternalFormat) 在allow_internal_format=False时,将内部格式(如 NZ、NC1HWC0 等)降级为基础格式(ND),从而阻止内部格式张量的创建。 -
ACLNN 路径绕过 TensorFactories 的检查:ACLNN 路径通过
format_cast_impl_out_npu_aclnn→create_tensor_with_format_and_shape直接分配存储并设置格式描述符,完全绕过TensorFactories::unsafe_empty_with_format中的CheckForbidInternalFormat()检查(该检查仍在 line 421)。 -
旧 aclop 回退路径仍保留检查:
npu_format_cast_impl→ApplyTensorWithFormat→unsafe_empty_with_format→CheckForbidInternalFormat,但 ACLNN 路径不再受保护。 -
ACLNN-only 设备上彻底失效:在
c10_npu::IsAclnnOnly()的设备上,没有 aclop 回退路径,allow_internal_format=False设置对格式转换完全无效。
影响
建议:恢复 MaybeDowngradeInternalFormat 函数及其在 MaybeUseAclnnNpuFormatCast 中的调用,或者作为替代方案,在 create_tensor_with_format_and_shape 中添加等价的 CheckForbidInternalFormat() 检查,确保 ACLNN 路径与 aclop 路径行为一致。推荐恢复原修复:在 MaybeUseAclnnNpuFormatCast 入口处对 acl_format 调用 MaybeDowngradeInternalFormat。


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | ✅ | >>> |
| UT_X86_Part_02 | ✅ | >>> | |
| UT_ARM_A3_Part_01 | ✅ | >>> | |
| UT_ARM_A3_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


/approve


/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.




【合入来源】
【修改方案】
回退 fix aclnn npu_format_cast to respect allow_internal_format=False,删除 npu_format_cast 的 aclnn 路径中对 allow_internal_format 的处理
【资料变更】
当前PR不涉及,相应资料已在op-plugin仓呈现
【接口变更】
不涉及
【功能验证】
UT通过
【CheckList】