ascend-ai-coding/awesome-ascend-skills/migration-ascend-torchnpu-skills-torch-npu-reference
Claude Code and agent skill by ascend-ai-coding/awesome-ascend-skills
- community
Checking that the SKILL.md file is still in the repository.
Provides torch\_npu API compatibility reference and interface mapping knowledge. Invoke when checking NPU interface support, finding equivalent replacements, or resolving torch\_npu compatibility issues.
Install
npx vskill@latest install ascend-ai-coding/awesome-ascend-skills/migration-ascend-torchnpu-skills-torch-npu-referenceSKILL.md
Skill: torch\_npu接口兼容性参考
你是一位精通torch\_npu接口适配的工程师。本Skill提供torch\_npu的接口兼容性查询和扩展接口参考。
官方参考文档(以下链接含版本号路径,MUST实时从昇腾官网查阅最新版本文档,链接仅供参考):- 训练迁移指导:昇腾官网 → 文档 → PyTorch框架适配 → 训练迁移指导- PyTorch原生接口支持度:昇腾官网 → 文档 → PyTorch框架适配 → 接口参考 → PyTorch原生接口- torch\_npu扩展接口:昇腾官网 → 文档 → PyTorch框架适配 → 接口参考 → 扩展接口- torch\_npu官方仓库:<https://gitcode.com/Ascend/pytorch>
<constraints>
- MUST 查询最新版本的torch_npu支持列表,NEVER凭记忆判断接口支持状态
- NEVER 在未验证的情况下假设某个接口在NPU上行为与CUDA完全一致
- 查询接口支持度时,MUST根据实际使用的PyTorch版本查阅对应版本的接口文档
- MUST 优先使用镜像站或ModelScope获取模型/数据集资源,NEVER默认使用HuggingFace官网;仅在用户明确确认网络可达HuggingFace时方可使用HuggingFace官网
- MUST 使用pip安装时优先指定第三方镜像源(如阿里源、清华源),仅在镜像源失败时回退至pip默认源
</constraints>
一、torch\_npu概述
1.1 torch\_npu定位
torch\_npu是PyTorch的昇腾NPU适配扩展,通过PyTorch 2.1版本提供的插件机制,动态添加昇腾后端适配,包含NPU设备、HCCL等一系列能力的支持。
1.2 torch\_npu安装与导入
MUST实时查阅昇腾官网最新版本文档,以下链接仅供参考:昇腾官网 → 文档 → PyTorch框架适配 → 软件安装指南 → 安装 → 使用二进制包安装参考链接:<https://www.hiascend.com/document/detail/zh/Pytorch/2600/configandinstg/instg/docs/zh/installation_guide/installation_via_binary_package.md>根据目标PyTorch版本、架构(aarch64/x86\_64)、Python版本,从上述文档查找对应的下载链接。
1.3 torch\_npu源码仓库
- 仓库地址:<https://gitcode.com/Ascend/pytorch>
- Release下载:<https://gitcode.com/Ascend/pytorch/releases>
1.4 从源码获取解决方案
当无法从本Skill或官方文档解决接口适配问题时,可拉取torch\_npu代码仓,根据实际代码分析接口实现和适配方案:
二、PyTorch接口NPU支持状态
2.1 接口支持度查询
昇腾官方提供了按PyTorch版本区分的接口支持度清单,MUST根据实际使用的PyTorch版本查阅对应文档:
| PyTorch版本 | 接口文档路径 | |
|---|---|---|
| 2.10.0 | apiref/PyTorchNativeapi/docs/zh/native_apis/pytorch_2-10-0/overview.md | |
| 2.9.0 | apiref/PyTorchNativeapi/docs/zh/native_apis/pytorch_2-9-0/overview.md | |
| 2.8.0 | apiref/PyTorchNativeapi/docs/zh/native_apis/pytorch_2-8-0/overview.md | |
| 2.7.1 | apiref/PyTorchNativeapi/docs/zh/native_apis/pytorch_2-7-1/overview.md | |
| 2.6.0 | apiref/PyTorchNativeapi/docs/zh/native_apis/pytorch_2-6-0/overview.md | |
| 2.1.0 | apiref/PyTorchNativeapi/docs/zh/native_apis/pytorch_2-1-0/overview.md |
以上路径均基于文档根目录https://www.hiascend.com/document/detail/zh/Pytorch/2600/下。版本迭代较快,MUST以官网最新版本文档为准。
查询方法:
- 确定当前项目使用的PyTorch版本
- 打开对应版本的接口支持度文档
- 搜索目标接口名称,查看是否在支持列表中
- 如在支持列表中,确认接口的行为差异说明
- 如不在支持列表中,查阅torch\_npu扩展接口文档是否有替代
2.2 torch\_npu扩展接口
torch\_npu提供了昇腾NPU专用的扩展接口,MUST查阅官方扩展接口文档确认接口名称、参数和使用方式:
- 扩展接口文档:昇腾官网 → 文档 → PyTorch框架适配 → 接口参考 → 扩展接口
2.3 常见不支持或行为差异的接口
| 接口 | 状态 | 替代方案 | |
|---|---|---|---|
torch.cuda.* | 需替换为 torch.npu.* | 参见 迁移Skill 第二章设备映射替换规则 | |
torch.backends.cudnn.* | 不支持 | 删除或条件跳过 | |
| 自定义CUDA扩展(.cu) | 不支持 | 使用torch\_npu扩展接口或PyTorch原生实现 |
<verification> 完成接口查询后逐项检查:
- [ ] 所有torch接口已查询NPU支持状态
- [ ] 不支持的接口已有替代方案
- [ ] 替代方案已验证数学一致性
- [ ] 接口兼容性查询结果已纳入迁移报告
</verification>
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/inference/migration-ascend-torchnpu-skills/migration-ascend-torchnpu-skills-torch-npu-reference/SKILL.md
Popularity
- Repository stars
- 128
- Repository forks
- 51
- 7-day trend score
- 24
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 4 Jul 2026, 4 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ascend-ai-coding/awesome-ascend-skills/migration-ascend-torchnpu-skills-torch-npu-reference)