已合并
关闭torch自动加载后端组件(torch_npu等组件),修复只安装toolkit包报错找不到libhccl.so问题 #233
chen-shuai创建于 5月8日
关闭torch自动加载后端组件(torch_npu等组件),修复只安装toolkit包报错找不到libhccl.so问题 #233
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 chen-shuai 的贡献)5月8日 创建了 pull request,commit 833dec79
CANN-robot
5月8日 评论:
5月8日 评论:
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-cann/cann-samples | ✅ zhangzijie, 杨阳 (2/2) | ✅ zhangzijie, 杨阳 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
chen-shuai, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月8日 添加了label:cann-cla/yes
此处折叠了17条事件消息 查看更多
Cchen-shuai
5月8日 修改标题为 “关闭torch自动加载后端组件(torch_npu等组件),修复只安装toolkit包报错找不到libhccl.so问题”,原标题为“关闭torch自动加载后端组件(torch_npu等组件),修复只安装toolkit包报错找不到libhccl.so问标题”
5月8日 修改标题为 “关闭torch自动加载后端组件(torch_npu等组件),修复只安装toolkit包报错找不到libhccl.so问题”,原标题为“关闭torch自动加载后端组件(torch_npu等组件),修复只安装toolkit包报错找不到libhccl.so问标题”
chen-shuai
5月8日 评论:
5月8日 评论:
compile


5月8日 修改了pull request 的描述
5月8日 添加了label:ci-pipeline-running
CANN-robot
5月8日 评论:
5月8日 评论:
流水线任务触发成功 [流水线指导]
任务链接 [650149af4db347c4aed54a16e0f6c8e7]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ❌ FAILED | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| anti_virus | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Check_pr | ✅ SUCCESS | ||
| Compile_Ascend_X86_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| codecheck_codestyle | ✅ SUCCESS | ||
| precommit | ✅ SUCCESS |


5月8日 删除了label:ci-pipeline-running
5月8日 添加了label:ci-pipeline-failed
chen-shuai
5月8日 评论:
5月8日 评论:
compile


5月8日 删除了label:ci-pipeline-failed
5月8日 添加了label:ci-pipeline-running
CANN-robot
5月8日 评论:
5月8日 评论:
流水线任务触发成功 [流水线指导]
任务链接 [face35bb5fbf483cabe3f2e709bb3401]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| anti_virus | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Check_pr | ✅ SUCCESS | ||
| Compile_Ascend_X86_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| codecheck_codestyle | ✅ SUCCESS | ||
| precommit | ✅ SUCCESS |
[2026-05-08 17:19:47] CI执行结束


5月8日 删除了label:ci-pipeline-running
5月8日 添加了label:ci-pipeline-passed
zhangzijie
5月8日 评论:
5月8日 评论:
/lgtm
/approve


5月8日 添加了label:approved
yangyang016
5月8日 评论:
5月8日 评论:
/lgtm
/approve


5月8日 添加了label:lgtm
CANN-robot
5月8日 评论:
5月8日 评论:
Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: zhangzijie, 杨阳.
Reviewers who wrote a comment of /lgtm are: 杨阳, zhangzijie.


5月8日 关闭了关联的issue
5月8日 合入了pull request
描述
解决的问题:使用 PyTorch 生成 golden 数据或校验结果的样例脚本只依赖torch cpu,import torch后会自动加载torch_npu。torch_npu依赖了ops包的libhccl.so,导致只装toolkit包直接运行会报错找不到libhccl.so。关闭torch后端组件自动加载修复问题
主要改动:
给使用 PyTorch 生成 golden 数据或校验结果的样例脚本,统一关闭 PyTorch 设备后端自动加载。
在 15 个 Python 脚本中,在 import torch 或函数内 import torch 之前增加:
os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = "0"
部分原本没有 import os 的 verify_result.py 也同步补了:
import os
主要覆盖这些样例:
Samples/1_Features/memory_optimization/scale_cache
Samples/2_Performance/matmul_story
Samples/2_Performance/grouped_matmul_story
涉及脚本类型包括:
gen_data.py
verify_result.py
目的
这些脚本只是在 CPU 侧用 torch 做数据生成、矩阵乘、bf16 视图转换或结果校验,不需要自动加载 NPU/设备后端组件。
只影响 Python 脚本导入 torch 时的后端自动加载行为。
环境兼容性修复,让 matmul / grouped matmul / scale cache 相关 Python 数据生成和校验脚本在导入 PyTorch 时不自动加载设备后端。
关联的Issue
https://gitcode.com/cann/cann-samples/issues/153
测试
测试脚本是否正常运行,不影响精度
文档更新
NA
类型标签