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


变更摘要
本 PR 回退了之前的一个功能特性:移除了对 Ascend950 SoC 的自动检测逻辑,以及基于 SoC 版本自动设置 TORCH_NPU_USE_COMPATIBLE_IMPL 环境变量默认值的机制。同时删除了对应的单元测试文件。
主要改动
- 移除
_is_ascend950()函数: 从torch_npu/__init__.py中删除了通过libascendcl.so的aclrtGetSocName接口检测 SoC 是否以 "Ascend950" 开头的完整函数实现(共约 12 行代码) - 移除
TORCH_NPU_USE_COMPATIBLE_IMPL自动赋值逻辑: 删除了在 C++ 初始化前根据_is_ascend950()返回值自动设置环境变量默认值的代码块(当环境变量未被预设置时,Ascend950 设为"1",否则为"0") - 删除测试文件: 整个
test/test_compatible_impl_soc_detect.py文件被删除(42 行),该文件包含 4 个测试用例,分别验证_is_ascend950()返回值类型、与 C++GetSocVersion()的一致性、默认值与 SoC 匹配、以及用户预设值的保留行为


代码审查
审查总结
本次 PR 对 2 个文件进行了变更:
| 文件 | 审查结果 |
|---|---|
torch_npu/__init__.py |
发现问题 — 删除了 _is_ascend950() 函数及其相关的 TORCH_NPU_USE_COMPATIBLE_IMPL 默认值设定逻辑(共 -19 行),但未同步清理调用方 |
test/test_compatible_impl_soc_detect.py |
无问题 — 该测试文件随所测功能一并删除,清理干净,且未被其他文件引用 |
按严重程度统计
| 严重程度 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 1 |
| P2 | 0 |
| P3 | 0 |
总体风险判断
中等风险。回退逻辑本身正确(移除了脆弱的 SoC 探测和隐式环境变量改写),符合 Issue #2561 的期望。但回退不完整:benchmarks/torchbench/torchbench.py:50 仍依赖已删除的 torch_npu._is_ascend950(),会在 benchmark 运行时因 AttributeError 崩溃。建议在该 PR 中一并修复该调用方。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


🟠 High Priority
diff 删除了 torch_npu/__init__.py 中的 _is_ascend950() 函数(第8-20行),但未同步清理调用方 benchmarks/torchbench/torchbench.py:50,该处仍通过 torch_npu._is_ascend950() 调用已不存在的函数。
失败路径:
torch_npu可正常 import(不会触发ImportError)- 执行
torch_npu._is_ascend950()时抛出AttributeError - 由于外层
try...except ImportError只捕获ImportError,AttributeError不会被捕获 - 异常向上传播导致 benchmark 脚本崩溃
受影响的代码在 benchmarks/torchbench/torchbench.py:452 使用 is_ascend950 判断 Ascend950 上的容差策略,该变量在崩溃路径上不会被赋值。
建议:在同一个 PR 中也回退 benchmarks/torchbench/torchbench.py 中对 torch_npu._is_ascend950() 的调用,改为使用已存在的内部 API(如 torch_npu._inductor.config.is_ascend950)或从 torch_npu._C._npu_get_soc_version() 自行判断 soc_version >= 260,并保留 except ImportError 回退逻辑。


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/approve


/lgtm


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


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




1. Origin pull request:
https://gitcode.com/Ascend/pytorch/merge_requests/39678
2. Original pull request related issue(s):
https://gitcode.com/Ascend/pytorch/issues/2561
3. Original pull request related commit(s):
This reverts commit acebf35339791ea6fcac6f116acdb242a1c09096.
Removes the _is_ascend950() SoC auto-detection and the SoC-based default-value assignment for TORCH_NPU_USE_COMPATIBLE_IMPL in torch_npu/init.py, and drops test_compatible_impl_soc_detect.py.
Co-Authored-By: Claude noreply@anthropic.com