torch_npu

Integrate Huawei Ascend NPU hardware with PyTorch for training and inference.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/dongg622/china-ai-chip-skill --skill torch-npu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: torch_npu
Source: https://github.com/dongg622/china-ai-chip-skill/tree/main/Ascend/torch_npu
Command: npx skills add https://github.com/dongg622/china-ai-chip-skill --skill torch-npu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch-npu, pyyaml, setuptools, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill enables developers to efficiently utilize Huawei Ascend NPU hardware within PyTorch, enhancing training and inference speed.

Core Features & Use Cases

  • Environment setup and validation: Check if PyTorch and Ascend NPU environment are correctly configured for development.
  • Device management and memory utilization: Manage NPU devices, monitor memory, and optimize resource allocation.
  • Code conversion and optimization: Assist in format casting and tensor layout adjustments for better performance and compatibility.
  • Distributed training support: Enable multi-device and multi-node training with HCCL and RPC.
  • Use Case: Transitioning a PyTorch image classification model from GPU to Ascend NPU for faster training and deployment.

Quick Start

Install the torch_npu package, source the environment setup script, and verify device availability before running your training scripts directly on the NPU.

Frequently Asked Questions about torch_npu

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I accelerate PyTorch training on Huawei Ascend NPU?

To accelerate PyTorch training on Huawei Ascend NPU, install the torch_npu package, source the environment setup script, and verify device availability before running your training scripts directly on the NPU. This provides native PyTorch API integration for enhanced speed.

Can I use native PyTorch APIs for distributed training on Ascend NPU?

Yes, you can use native PyTorch APIs for distributed training on Ascend NPU. The torch_npu package enables multi-device and multi-node training with HCCL and RPC, allowing seamless distributed training workflows directly on Ascend hardware.

What do I need to set up before running PyTorch models on Ascend NPU?

Before running PyTorch models on Ascend NPU, you need to install the torch_npu package and source the specific environment setup script. You must also check if PyTorch and the Ascend NPU environment are correctly configured for development.

How do I manage tensor format casting and memory for Ascend NPU devices?

You can manage tensor format casting and memory for Ascend NPU devices using torch_npu to adjust tensor layouts for better compatibility and monitor memory utilization to optimize resource allocation across the NPU hardware.

Does PyTorch work with Ascend NPU for inference tasks?

Yes, PyTorch works with Ascend NPU for inference tasks. The torch_npu integration enhances both training and inference speed, allowing you to transition existing PyTorch models like image classification from GPU to Ascend NPU for faster deployment.

What is the best way to profile performance when transitioning PyTorch models to Ascend NPU?

The best way to profile performance when transitioning PyTorch models to Ascend NPU is using the built-in performance profiling features in torch_npu, which help monitor device management, memory utilization, and resource allocation during your deep learning workflows.