已合并
[sync] PR-38376: fix: remove the deprecated get_cann_version() in _optim.py to reduce import time #38522
ascend-robot创建于 6月15日
[sync] PR-38376: fix: remove the deprecated get_cann_version() in _optim.py to reduce import time #38522
已合并
ascend-robot创建于 6月15日
ascend-robot
ascend-robot成员
6月15日

1. Origin pull request:

https://gitcode.com/Ascend/pytorch/merge_requests/38376

https://gitcode.com/Ascend/pytorch/issues/2370

Sha Datetime Message
145499ed 2026-06-13 11:19:22 +0800 CST perf: remove obsolete CANN 8.0 blacklist from _optim.py

torch_npu 2.7.1 requires CANN >= 8.2, so the CANN 8.0 blacklist
and cann_version check are no longer reachable. Removing them
eliminates the _get_cann_version() call from import path.

Co-Authored-By: Claude noreply@anthropic.com
30946b2a 2026-06-12 16:25:50 +0800 CST perf: simplify _optim.py to use C++ get_cann_version and remove obsolete CANN 8.0 blacklist

- Replace collect_env.get_cann_version() (os.walk over ASCEND_HOME_PATH,
~250ms) with torch_npu._C._get_cann_version() (C++ impl, ~0.014ms)
- Remove obsolete CANN 8.0.x blacklist entries (8.0.RC1/RC2, T1~T52)
- Remove global state (_cann_version, _device_name) in favor of local
variables - no caching needed with <1ms C++ API calls
- Remove collect_env dependency entirely

Co-Authored-By: Claude noreply@anthropic.com
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 ascend-robot 的贡献)
ascend-robotascend-robot成员
6月15日 restored source branch `sync-pr38376-fix/lazy-load-optim-get-cann-version-to-v2.9.0`
ascend-robotascend-robot成员
6月15日 update merge request[project id: 7404318, iid: 38522, commit_id: ba463e5970bd651b5e9736eaf86f8fc60265a919] virtual merging success
ascend-robotascend-robot成员
6月15日 创建了 pull request,commit fb5a7ceb
ascend-robotascend-robot成员
6月15日 关联了issue:[Bug]: import torch 时 torch_npu.utils._optim 模块因 os.walk 遍历 ASCEND_HOME_PATH 导致 250ms 不必要开销
ascend-robotascend-robot成员
6月15日 添加了label:stat/needs-squash
ascend-robotascend-robot成员
6月15日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
6月15日 评论:

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
torch_npu/utils liujunzhu, ffmh (2/2) liujunzhu (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
ascend-robot
ascend-robot成员
6月15日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
6月15日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
6月15日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robot
ascend-robot成员
6月15日 评论:

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

likedislike
ascend-robotascend-robot成员
6月15日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
6月15日 添加了label:docs-ci-pipeline-success
ascend-robot
ascend-robot成员
6月15日 评论:

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

likedislike
wuyouqi1
wuyouqi1成员
6月15日 评论:

compile

likedislike
ascend-robot
ascend-robot成员
6月15日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
6月15日 删除了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
6月15日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
6月15日 评论:

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

likedislike
ascend-robotascend-robot成员
6月15日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
6月15日 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
6月15日 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
6月15日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
6月15日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
6月15日 评论:
流水线 PR-pipeline_pytorch#32237 已完成
阶段 任务名 状态 详情
编译构建 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 >>>
likedislike
wanglijun55成员
6月15日 评论:

/lgtm

likedislike
liujunzhu
liujunzhu成员
6月15日 评论:

/approve

likedislike
ascend-robot
ascend-robot成员
6月15日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
wanglijun55

likedislike
ascend-robotascend-robot成员
6月15日 添加了label:approved
ascend-robot
ascend-robot成员
6月15日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
wanglijun55

likedislike
ffmh
ffmh成员
6月16日 评论:

/lgtm

likedislike
ascend-robot
ascend-robot成员
6月16日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
wanglijun55

likedislike
ascend-robotascend-robot成员
6月16日 添加了label:lgtm
ascend-robotascend-robot成员
6月16日 合入了pull request