Ascend PyTorch adapter (torch_npu). Mirror of https://gitcode.com/Ascend/pytorch
See the codePyTorch Adapter Plugin for Ascend NPU
English | 简体中文
Supported Versions · Installation · Quick Start · Compatibility · Support · Contributing · Docs · Community
As the core component of the Ascend for PyTorch community, TorchNPU is a deep learning adapter plugin built by Ascend for PyTorch, enabling the PyTorch framework to directly invoke Ascend NPU and providing developers with the powerful compute capabilities of Ascend AI processors.
Ascend is a full-stack AI computing infrastructure for industry applications and services based on Huawei Ascend AI processors and software. For more information about Ascend, see Ascend Community.
TorchNPU fully inherits and reuses extensive mature capabilities from upstream PyTorch, and on this foundation provides deep adaptation and optimization for Ascend NPU. The diagram below illustrates the main functional modules of TorchNPU:
Key Modules:
This branch adapts to multiple PyTorch versions from a single source tree. The PyTorch versions it currently supports are declared in version.txt, which is the single source of truth and is updated as new versions are adapted.
For the compatibility matrix of released packages (TorchNPU / PyTorch / CANN / Python), please refer to Compatibility.
Take installing TorchNPU 2.12.0 as an example. Run the following commands for installation. For other versions, please refer to the community download page: TorchNPU Download.
Install CANN 9.1.0 and the NPU driver and firmware matching your hardware. Use a compatible Python version from the compatibility matrix. For detailed steps, please refer to the CANN Installation Guide.
Run the following command to install PyTorch 2.12.0:
pip install torch==2.12.0 --index-url https://download.pytorch.org/whl/cpu
Run the following command to install TorchNPU 2.12.0:
pip install torch-npu==2.12.0
For detailed steps on compiling TorchNPU, please refer to the Source Installation Guide.
# Default path, modify according to your actual installation location
source /usr/local/Ascend/cann/set_env.sh
import torch
import torch_npu
x = torch.randn(2, 2).npu()
y = torch.randn(2, 2).npu()
z = x.mm(y)
print(z)
Starting from TorchNPU 2.5.1,
import torch_npuis no longer mandatory (auto-registration occurs), but explicit import is still recommended to ensure device initialization.
If the following output appears, the execution is successful:
tensor([[-0.0515, 0.3664],
[-0.1258, -0.5425]], device='npu:0')
For complete model migration and training tutorials, please refer to the Quick Start Guide.
The Ascend for PyTorch community is coordinated by the Technical Committee (TC), with Special Interest Groups (SIGs) responsible for development, maintenance, and community collaboration in specific technical areas. The table below introduces the TC and current SIGs. Click the corresponding links for details.
| TC / SIG Name | Description | Link |
|---|---|---|
| TC | Oversees technical direction and major technical decisions, SIG governance, and release reviews for Ascend for PyTorch. | 🔗 Learn more |
| Core SIG | Focuses on the development of the PyTorch core adaptation layer on the Ascend NPU platform, responsible for the design, implementation, and maintenance of the TorchNPU extension library and its operator plugin OpPlugin. | 🔗 Learn more |
| Distributed SIG | Dedicated to building efficient, easy-to-use, and scalable parallel training capabilities based on the PyTorch distributed training framework (torch.distributed) on the Ascend NPU hardware foundation, delivering extreme performance for LLM, multimodal, and reinforcement learning scenarios. | 🔗 Learn more |
| Graph Mode SIG | Focuses on core technologies such as Dynamo, Inductor, and NPUGraph, aiming to bridge the gap between "ease of use" and "high performance" through automated graph capture and compilation optimization. | 🔗 Learn more |
| Usability SIG | Dedicated to improving the usability experience of Ascend for PyTorch, including documentation, tutorials, examples, and more. | 🔗 Learn more |
Each SIG holds regular meetings, mailing lists, and contribution guides. Click the corresponding SIG links to view detailed contact information, goals, and participation guidelines. Everyone is welcome to contribute to the community. If you have any questions or suggestions, please submit GitHub Issues. We will reply as soon as possible. Thank you for your support.
For system security hardening, recommended user configurations, and file permission controls for TorchNPU, please refer to the Security Note.
This plugin is for debugging and development purposes only. Users are responsible for ensuring the security of input commands and properly controlling access to data generated during use. By using this plugin, you agree to and accept the above statement.
For the license of TorchNPU, please refer to the LICENSE file. For the license of TorchNPU documentation, please refer to the LICENSE file.
Thanks for every PR from the community! We welcome developers to contribute code to the TorchNPU plugin!
373 followers · starred Feb 2025
19 followers · starred Feb 2025
69 followers · starred Jan 2024
65 followers · starred Feb 2026
Ascend PyTorch adapter (torch_npu). Mirror of https://gitcode.com/Ascend/pytorch
See the codePyTorch Adapter Plugin for Ascend NPU
English | 简体中文
Supported Versions · Installation · Quick Start · Compatibility · Support · Contributing · Docs · Community
As the core component of the Ascend for PyTorch community, TorchNPU is a deep learning adapter plugin built by Ascend for PyTorch, enabling the PyTorch framework to directly invoke Ascend NPU and providing developers with the powerful compute capabilities of Ascend AI processors.
Ascend is a full-stack AI computing infrastructure for industry applications and services based on Huawei Ascend AI processors and software. For more information about Ascend, see Ascend Community.
TorchNPU fully inherits and reuses extensive mature capabilities from upstream PyTorch, and on this foundation provides deep adaptation and optimization for Ascend NPU. The diagram below illustrates the main functional modules of TorchNPU:
Key Modules:
This branch adapts to multiple PyTorch versions from a single source tree. The PyTorch versions it currently supports are declared in version.txt, which is the single source of truth and is updated as new versions are adapted.
For the compatibility matrix of released packages (TorchNPU / PyTorch / CANN / Python), please refer to Compatibility.
Take installing TorchNPU 2.12.0 as an example. Run the following commands for installation. For other versions, please refer to the community download page: TorchNPU Download.
Install CANN 9.1.0 and the NPU driver and firmware matching your hardware. Use a compatible Python version from the compatibility matrix. For detailed steps, please refer to the CANN Installation Guide.
Run the following command to install PyTorch 2.12.0:
pip install torch==2.12.0 --index-url https://download.pytorch.org/whl/cpu
Run the following command to install TorchNPU 2.12.0:
pip install torch-npu==2.12.0
For detailed steps on compiling TorchNPU, please refer to the Source Installation Guide.
# Default path, modify according to your actual installation location
source /usr/local/Ascend/cann/set_env.sh
import torch
import torch_npu
x = torch.randn(2, 2).npu()
y = torch.randn(2, 2).npu()
z = x.mm(y)
print(z)
Starting from TorchNPU 2.5.1,
import torch_npuis no longer mandatory (auto-registration occurs), but explicit import is still recommended to ensure device initialization.
If the following output appears, the execution is successful:
tensor([[-0.0515, 0.3664],
[-0.1258, -0.5425]], device='npu:0')
For complete model migration and training tutorials, please refer to the Quick Start Guide.
The Ascend for PyTorch community is coordinated by the Technical Committee (TC), with Special Interest Groups (SIGs) responsible for development, maintenance, and community collaboration in specific technical areas. The table below introduces the TC and current SIGs. Click the corresponding links for details.
| TC / SIG Name | Description | Link |
|---|---|---|
| TC | Oversees technical direction and major technical decisions, SIG governance, and release reviews for Ascend for PyTorch. | 🔗 Learn more |
| Core SIG | Focuses on the development of the PyTorch core adaptation layer on the Ascend NPU platform, responsible for the design, implementation, and maintenance of the TorchNPU extension library and its operator plugin OpPlugin. | 🔗 Learn more |
| Distributed SIG | Dedicated to building efficient, easy-to-use, and scalable parallel training capabilities based on the PyTorch distributed training framework (torch.distributed) on the Ascend NPU hardware foundation, delivering extreme performance for LLM, multimodal, and reinforcement learning scenarios. | 🔗 Learn more |
| Graph Mode SIG | Focuses on core technologies such as Dynamo, Inductor, and NPUGraph, aiming to bridge the gap between "ease of use" and "high performance" through automated graph capture and compilation optimization. | 🔗 Learn more |
| Usability SIG | Dedicated to improving the usability experience of Ascend for PyTorch, including documentation, tutorials, examples, and more. | 🔗 Learn more |
Each SIG holds regular meetings, mailing lists, and contribution guides. Click the corresponding SIG links to view detailed contact information, goals, and participation guidelines. Everyone is welcome to contribute to the community. If you have any questions or suggestions, please submit GitHub Issues. We will reply as soon as possible. Thank you for your support.
For system security hardening, recommended user configurations, and file permission controls for TorchNPU, please refer to the Security Note.
This plugin is for debugging and development purposes only. Users are responsible for ensuring the security of input commands and properly controlling access to data generated during use. By using this plugin, you agree to and accept the above statement.
For the license of TorchNPU, please refer to the LICENSE file. For the license of TorchNPU documentation, please refer to the LICENSE file.
Thanks for every PR from the community! We welcome developers to contribute code to the TorchNPU plugin!
373 followers · starred Feb 2025
19 followers · starred Feb 2025
69 followers · starred Jan 2024
65 followers · starred Feb 2026