Ascend for PyTorch 训练营学习笔记第二期
【摘要】 安装与构建 昇腾(Ascend)for PyTorch 训练营(https://www.chaspark.com/#/s/AscendforPyTorch2026?multi=zh) 第二期代码仓库结构两个主要仓库:Ascend for PyTorch(https://atomgit.com/Ascend/pytorch):昇腾 PyTorch 插件,提供框架能力,使昇腾 NPU 适配 Py...
安装与构建 昇腾(Ascend)for PyTorch 训练营(https://www.chaspark.com/#/s/AscendforPyTorch2026?multi=zh) 第二期

代码仓库结构
-
两个主要仓库:
- Ascend for PyTorch(
https://atomgit.com/Ascend/pytorch):昇腾 PyTorch 插件,提供框架能力,使昇腾 NPU 适配 PyTorch。(这个仓库还有一个地址是gitcode上也有,内容一样) - op-plugin(
https://atomgit.com/Ascend/op-plugin):为torch_npu提供算子适配文件。
- Ascend for PyTorch(
-
版本解耦架构:
- PyTorch 2.6 / 2.7 / 2.x 各自对应
torch_npu2.6 / 2.7 / 2.x。 - 各版本
torch_npu通过统一的 interface 层对接同一个 Op-plugin。 - Op-plugin 再统一对接 CANN 8.5 的 aclnn 算子库。
- 算子不感知 torch 版本,实现版本解耦。
- PyTorch 2.6 / 2.7 / 2.x 各自对应
-
编译关系:op-plugin 是 Ascend for PyTorch 的 submodule,编译时共同编译进
torch_npu.so。
当前还没有提供在线安装方式(就是还不支持pip install直接在线安装方式),那么离线安装就是指导先下载whl文件然后pip install安装。
再就是源码安装方式,推荐容器方式,因为要先编译pytorch,对gcc版本,cmake版本有些要求,容器里都帮你弄好了。
后面有实操过程。
后面的实操过程最后还是看一看参考一下,因为自己实践编译的时候,还是会碰到很多的问题。比如:
In file included from /workspace/pytorch/torch_npu/csrc/toolkit/profiler/common/utils.cpp:1:
/workspace/pytorch/torch_npu/csrc/toolkit/profiler/common/utils.h: In static member function ‘static uint64_t torch_npu::toolkit::profiler::Utils::GetClockMonotonicRawNs()’:
/workspace/pytorch/torch_npu/csrc/toolkit/profiler/common/utils.h:114:23: error: ‘CLOCK_MONOTONIC_RAW’ was not declared in this scope
114 | clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
| ^~~~~~~~~~~~~~~~~~~
/workspace/pytorch/torch_npu/csrc/toolkit/profiler/common/utils.h:114:23: note: the macro ‘CLOCK_MONOTONIC_RAW’ had not yet been defined
In file included from /usr/include/time.h:33,
from /usr/include/pthread.h:23,
from /usr/include/c++/12/aarch64-openEuler-linux/bits/gthr-default.h:35,
from /usr/include/c++/12/aarch64-openEuler-linux/bits/gthr.h:148,
from /usr/include/c++/12/ext/atomicity.h:35,
from /usr/include/c++/12/bits/ios_base.h:39,
from /usr/include/c++/12/ios:42,
from /usr/include/c++/12/istream:38,
from /usr/include/c++/12/sstream:38,
from /workspace/pytorch/torch_npu/csrc/toolkit/profiler/common/utils.cpp:3:
/usr/include/bits/time.h:54: note: it was later defined here
54 | # define CLOCK_MONOTONIC_RAW 4
|
/workspace/pytorch/torch_npu/csrc/toolkit/profiler/common/utils.h:114:9: error: ‘clock_gettime’ was not declared in this scope; did you mean ‘SYS_clock_gettime’?
114 | clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
| ^~~~~~~~~~~~~
| SYS_clock_gettime
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)