Skip to main content

TorchNPU

Overview

TorchNPU is a PyTorch adapter plugin that brings Ascend NPU support into the PyTorch ecosystem, enabling developers to harness the high-performance computing power of Ascend AI processors.

Ascend is a full-stack AI computing infrastructure for industry applications and services based on Huawei Ascend processors and software. For more information about Ascend, see Ascend Community.

Installation

From Binary

Provide users with wheel package to quickly install TorchNPU. Before installing TorchNPU, complete the installation of CANN according to Ascend Auxiliary Software. To obtain the CANN installation package, refer to the CANN Installation.

  1. Install PyTorch

    Install PyTorch through pip.

    For Aarch64:

    pip3 install torch==2.12.0 --index-url https://download.pytorch.org/whl/cpu
    

    For x86:

    pip3 install torch==2.12.0+cpu  --index-url https://download.pytorch.org/whl/cpu
    
  2. Install TorchNPU dependencies

    Run the following command to install dependencies.

    pip3 install pyyaml
    pip3 install setuptools
    

    If the installation fails, use the download link or visit the PyTorch official website to download the installation package of the corresponding version.

    OS arch Python version link
    x86 Python3.10 link
    x86 Python3.11 link
    x86 Python3.12 link
    aarch64 Python3.10 link
    aarch64 Python3.11 link
    aarch64 Python3.12 link
  3. Install TorchNPU

    pip3 install torch-npu==2.12.0rc1
    

From Source

In some special scenarios, users may need to compile TorchNPU by themselves.Select a branch in table Ascend Auxiliary Software and a Python version in table PyTorch and Python Version Matching Table first. The docker image is recommended for compiling TorchNPU through the following steps(It is recommended to mount the working path only and avoid the system path to reduce security risks.), the generated .whl file path is ./dist/. Note that gcc version has the following constraints if you try to compile without using docker image: we recommend to use gcc 13.3 for both ARM and X86.

  1. Clone TorchNPU

    git clone https://gitcode.com/ascend/pytorch.git -b v2.12.0 --depth 1
    
  2. Build Docker Image

    cd pytorch/ci/docker/{arch} # {arch} for X86 or ARM
    docker build -t manylinux-builder:v1 .
    
  3. Enter Docker Container

    docker run -it -v /{code_path}/pytorch:/home/pytorch manylinux-builder:v1 bash
    # {code_path} is the torch_npu source code path
    
  4. Compile TorchNPU

    Take Python 3.10 as an example.

    cd /home/pytorch
    bash ci/build.sh --python=3.10
    

    Use --torch=<version> to build against a specific PyTorch version (supported: 2.10.0, 2.11.0, 2.12.0). The installed PyTorch must match the specified version.

    bash ci/build.sh --python=3.8 --torch=2.10.0
    

Tips

If you would like to compile with new C++ ABI, then first run this command, at this point, the recommended compilation environment is same to community torch package: glibc 2.28, gcc 13.3

export _GLIBCXX_USE_CXX11_ABI=1

Meanwhile, we support configuring -fabi-version using the following variables,require consistency with the community torch package

export _ABI_VERSION=18

Getting Started

Prerequisites

Initialize CANN environment variable by running the command as shown below.

# Default path, change it if needed.
source /usr/local/Ascend/ascend-toolkit/set_env.sh

Quick Verification

You can quickly experience Ascend NPU by the following simple examples.

import torch
- import torch_npu # No longer needed in TorchNPU 2.5.1 and later versions

x = torch.randn(2, 2).npu()
y = torch.randn(2, 2).npu()
z = x.mm(y)

print(z)

User Manual

Refer to API of TorchNPU for more detailed information.

PyTorch and Python Version Matching Table

PyTorch Version Python Version
PyTorch1.11.0 Python3.7.x(>=3.7.5),Python3.8.x,Python3.9.x,Python3.10.x
PyTorch2.1.0 Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.2.0 Python3.8.x,Python3.9.x,Python3.10.x
PyTorch2.3.1 Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.4.0 Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.5.1 Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.6.0 Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.7.1 Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.8.0 Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.9.0 Python3.10.x,Python3.11.x,Python3.12.x
PyTorch2.10.0 Python3.10.x,Python3.11.x,Python3.12.x
PyTorch2.11.0 Python3.10.x,Python3.11.x,Python3.12.x
PyTorch2.12.0 Python3.10.x,Python3.11.x,Python3.12.x

Ascend Auxiliary Software

PyTorch Extension versions follow the naming convention {PyTorch version}-{Ascend version}, where the former represents the PyTorch version compatible with the PyTorch Extension, and the latter is used to match the CANN version. The detailed matching is as follows:

CANN Version Supported PyTorch Version Supported Extension Version Github Branch
CANN 8.5.0 2.12.0 2.12.0rc1 v2.12.0
2.11.0 2.11.0rc1 v2.11.0
2.10.0 2.10.0rc2 v2.10.0
2.9.0 2.9.0 v2.9.0-7.3.0
2.8.0 2.8.0.post2 v2.8.0-7.3.0
2.7.1 2.7.1.post2 v2.7.1-7.3.0
2.6.0 2.6.0.post5 v2.6.0-7.3.0
CANN 8.3.RC1 2.8.0 2.8.0 v2.8.0-7.2.0
2.7.1 2.7.1 v2.7.1-7.2.0
2.6.0 2.6.0.post3 v2.6.0-7.2.0
2.1.0 2.1.0.post17 v2.1.0-7.2.0
CANN 8.2.RC1 2.6.0 2.6.0 v2.6.0-7.1.0
2.5.1 2.5.1.post1 v2.5.1-7.1.0
2.1.0 2.1.0.post13 v2.1.0-7.1.0
CANN 8.1.RC1 2.5.1 2.5.1 v2.5.1-7.0.0
2.4.0 2.4.0.post4 v2.4.0-7.0.0
2.3.1 2.3.1.post6 v2.3.1-7.0.0
2.1.0 2.1.0.post12 v2.1.0-7.0.0
CANN 8.0.0 2.4.0 2.4.0.post2 v2.4.0-6.0.0
2.3.1 2.3.1.post4 v2.3.1-6.0.0
2.1.0 2.1.0.post10 v2.1.0-6.0.0
CANN 8.0.RC3 2.4.0 2.4.0 v2.4.0-6.0.rc3
2.3.1 2.3.1.post2 v2.3.1-6.0.rc3
2.1.0 2.1.0.post8 v2.1.0-6.0.rc3
CANN 8.0.RC2 2.3.1 2.3.1 v2.3.1-6.0.rc2
2.2.0 2.2.0.post2 v2.2.0-6.0.rc2
2.1.0 2.1.0.post6 v2.1.0-6.0.rc2
1.11.0 1.11.0.post14 v1.11.0-6.0.rc2
CANN 8.0.RC1 2.2.0 2.2.0 v2.2.0-6.0.rc1
2.1.0 2.1.0.post4 v2.1.0-6.0.rc1
1.11.0 1.11.0.post11 v1.11.0-6.0.rc1
CANN 7.0.0 2.1.0 2.1.0 v2.1.0-5.0.0
2.0.1 2.0.1.post1 v2.0.1-5.0.0
1.11.0 1.11.0.post8 v1.11.0-5.0.0
CANN 7.0.RC1 2.1.0 2.1.0.rc1 v2.1.0-5.0.rc3
2.0.1 2.0.1 v2.0.1-5.0.rc3
1.11.0 1.11.0.post4 v1.11.0-5.0.rc3
CANN 6.3.RC3.1 1.11.0 1.11.0.post3 v1.11.0-5.0.rc2.2
CANN 6.3.RC3 1.11.0 1.11.0.post2 v1.11.0-5.0.rc2.1
CANN 6.3.RC2 2.0.1 2.0.1.rc1 v2.0.1-5.0.rc2
1.11.0 1.11.0.post1 v1.11.0-5.0.rc2
1.8.1 1.8.1.post2 v1.8.1-5.0.rc2
CANN 6.3.RC1 1.11.0 1.11.0 v1.11.0-5.0.rc1
1.8.1 1.8.1.post1 v1.8.1-5.0.rc1
CANN 6.0.1 1.5.0 1.5.0.post8 v1.5.0-3.0.0
1.8.1 1.8.1 v1.8.1-3.0.0
1.11.0 1.11.0.rc2(beta) v1.11.0-3.0.0
CANN 6.0.RC1 1.5.0 1.5.0.post7 v1.5.0-3.0.rc3
1.8.1 1.8.1.rc3 v1.8.1-3.0.rc3
1.11.0 1.11.0.rc1(beta) v1.11.0-3.0.rc3
CANN 5.1.RC2 1.5.0 1.5.0.post6 v1.5.0-3.0.rc2
1.8.1 1.8.1.rc2 v1.8.1-3.0.rc2
CANN 5.1.RC1 1.5.0 1.5.0.post5 v1.5.0-3.0.rc1
1.8.1 1.8.1.rc1 v1.8.1-3.0.rc1
CANN 5.0.4 1.5.0 1.5.0.post4 2.0.4.tr5
CANN 5.0.3 1.8.1 1.5.0.post3 2.0.3.tr5
CANN 5.0.2 1.5.0 1.5.0.post2 2.0.2.tr5

Hardware support

The Ascend training device includes the following models, all of which can be used as training environments for PyTorch models

Product series Product model
Atlas Training series products Atlas 800(model: 9000)
Atlas 800(model:9010)
Atlas 900 PoD(model:9000)
Atlas 300T(model:9000)
Atlas 300T Pro(model:9000)
Atlas A2 Training series products Atlas 800T A2
Atlas 900 A2 PoD
Atlas 200T A2 Box16
Atlas 300T A2

The Ascend inference device includes the following models, all of which can be used as inference environments for large models

Product series Product model
Atlas 800I A2 Inference product Atlas 800I A2

Pipeline Status

Due to the asynchronous development mechanism of upstream and downstream, incompatible modifications in upstream may cause some functions of TorchNPU to be unavailable (only upstream and downstream development branches are involved, excluding stable branches). Therefore, we built a set of daily tasks that make it easy to detect relevant issues in time and fix them within 48 hours (under normal circumstances), providing users with the latest features and stable quality.

OS CANN Version(Docker Image) Upstream Branch Downstream Branch Period Status
openEuler 24.03 SP2 CANN 8.5 main master UTC 1200 daily Ascend NPU

Suggestions and Communication

Everyone is welcome to contribute to the community. If you have any questions or suggestions, you can submit Github Issues. We will reply to you as soon as possible. Thank you very much.

Branch Maintenance Policies

The version branches of AscendPyTorch have the following maintenance phases:

Status Duration Description
Planning 1-3 months Plan features.
Development 6-12 months Develop new features and fix issues, regularly release new versions. Different strategies are adopted for different versions of PyTorch, with a regular branch development cycle of 6 months and a long-term support branch development cycle of 12 months.
Maintained 1 year/3.5 years Regular Release branch for 1 year, Long Term Support branch maintenance for 3.5 years. Fix major issues, do not incorporate new features, and release patch versions based on the impact of fixed bugs.
End Of Life (EOL) N/A Do not accept any modification to a branch.

PyTorch Maintenance Policies

PyTorch Maintenance Policies Status Launch Date Subsequent Status EOL Date
2.12.0 Regular Release Development 2026/05/10 Expected to enter maintenance status from November 23, 2026 -
2.11.0 Regular Release Development 2026/03/23 Expected to enter maintenance status from September 23, 2026 -
2.10.0 Regular Release Development 2026/01/22 Expected to enter maintenance status from July 22, 2026 -
2.9.0 Regular Release Development 2026/01/15 Expected to enter maintenance status from July 15, 2026 -
2.8.0 Regular Release Development 2025/10/15 Expected to enter maintenance status from March 15, 2026 -
2.7.1 Long Term Support Development 2025/10/15 Expected to enter maintenance status from October 15, 2026
2.6.0 Regular Release Development 2025/07/25 Expected to enter maintenance status from January 15, 2026 -
2.5.1 Regular Release Maintained 2024/11/08 Expected to enter maintenance free status from August 8, 2026
2.4.0 Regular Release Maintained 2024/10/15 Expected to enter maintenance free status from June 15, 2026
2.3.1 Regular Release Maintained 2024/06/06 Expected to enter maintenance free status from June 7, 2026
2.2.0 Regular Release EOL 2024/04/01 2025/10/14
2.1.0 Long Term Support Maintained 2023/10/15 Expected to enter maintenance free status from December 30, 2026
2.0.1 Regular Release EOL 2023/7/19 2024/3/14
1.11.0 Long Term Support EOL 2023/4/19 2025/10/25
1.8.1 Long Term Support EOL 2022/4/10 2023/4/10
1.5.0 Long Term Support EOL 2021/7/29 2022/7/29

Reference Documents

For more detailed information on installation guides, model migration, training/inference tutorials, and API lists, please refer to the TorchNPU on the HiAI Community.

Document Name Document Link
Installation Guide link
Network Model Migration and Training link
Operator Adaptation link
TorchNPU (Custom Interfaces) link

License

TorchNPU has a BSD-style license, as found in the LICENSE file.

Release files for torch-npu 2.12.0.post3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for torch-npu 2.12.0.post3
File
torch_npu-2.12.0.post3-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details
torch_npu-2.12.0.post3-cp314-cp314-manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ ARM64 Details
torch_npu-2.12.0.post3-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
torch_npu-2.12.0.post3-cp313-cp313-manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ ARM64 Details
torch_npu-2.12.0.post3-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
torch_npu-2.12.0.post3-cp312-cp312-manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ ARM64 Details
torch_npu-2.12.0.post3-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
torch_npu-2.12.0.post3-cp311-cp311-manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ ARM64 Details
torch_npu-2.12.0.post3-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
torch_npu-2.12.0.post3-cp310-cp310-manylinux_2_28_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ ARM64 Details

Total release size: 409.1 MB

Release files / torch_npu-2.12.0.post3-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL torch_npu-2.12.0.post3-cp314-cp314-manylinux_2_28_x86_64.whl
Size 42.8 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d5f521f7d7bc12e15ec1af588f496020cfdc1b70fa1a5a93f946bf20c487416e
BLAKE2b-256 checksum
How to use checksums
bd0183140b91ef2bba01ab27294c20480204b588940b3efaa0e6ece52b5d7ba4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp314-cp314-manylinux_2_28_aarch64.whl

Download URL torch_npu-2.12.0.post3-cp314-cp314-manylinux_2_28_aarch64.whl
Size 39.0 MB
Tags CPython 3.14 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
e6ee2f06fb62c04188a02e713d1a4a50f856e057ecdd0c5d14961dab16ff168e
BLAKE2b-256 checksum
How to use checksums
7b3d5c082a5e181805addfa2da277df039e3752504b42ab2e334d175505c546a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL torch_npu-2.12.0.post3-cp313-cp313-manylinux_2_28_x86_64.whl
Size 42.8 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b49b6317ca740e3ebf94f9918b92097ba624b870237015b3c16210ba3d8eed3f
BLAKE2b-256 checksum
How to use checksums
5e2cfc3c388680e032622fa8dcd0a8d22e9b60ac44e611bd77fbdbbd751e6ed9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp313-cp313-manylinux_2_28_aarch64.whl

Download URL torch_npu-2.12.0.post3-cp313-cp313-manylinux_2_28_aarch64.whl
Size 39.0 MB
Tags CPython 3.13 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
7f9a1492527d85871c757642461710f9cd167a4771b00c9e42b21857afa0f4c7
BLAKE2b-256 checksum
How to use checksums
23aaaa008396e94cfb2e99456a8835a07a5f5ae9dbc6bac3c53bf71304d9cef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL torch_npu-2.12.0.post3-cp312-cp312-manylinux_2_28_x86_64.whl
Size 42.8 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
3173b1e960216c5fa1ecbece6dde9537087cc313692f89ff0fe17b59ca3fdd57
BLAKE2b-256 checksum
How to use checksums
51551edae019c14ee1c191ad1f3b1e228e15817792bd74801e8bb5b4217cb46c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp312-cp312-manylinux_2_28_aarch64.whl

Download URL torch_npu-2.12.0.post3-cp312-cp312-manylinux_2_28_aarch64.whl
Size 39.0 MB
Tags CPython 3.12 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
d553e741081ca9cbc672175281b486c9c3b06676928590087f9afa70f0bceb6b
BLAKE2b-256 checksum
How to use checksums
09da5105e28c81f42db07dec2ece49c592334b848607038d7aa974083817bd14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL torch_npu-2.12.0.post3-cp311-cp311-manylinux_2_28_x86_64.whl
Size 42.8 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
70776a5afc58c3291efb38bcce8a83284fb3285758bd4472b9d47841788a2be1
BLAKE2b-256 checksum
How to use checksums
39da6ba59b304463c876ed4f28b8c8e550e72c8d41cca3fb779c609a4dc21cae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp311-cp311-manylinux_2_28_aarch64.whl

Download URL torch_npu-2.12.0.post3-cp311-cp311-manylinux_2_28_aarch64.whl
Size 39.0 MB
Tags CPython 3.11 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
2a4a605404021689af7b13dd676651b151130c49326fc7054ed58fe4884e5d33
BLAKE2b-256 checksum
How to use checksums
57bd794542cae8729221161e5d819ab1c08c732650322cc1cf7f8e60e7fd0831
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL torch_npu-2.12.0.post3-cp310-cp310-manylinux_2_28_x86_64.whl
Size 42.8 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
677c5f5520ea3e9d00299599829b539dbf166ce30e03bd8b4a75b11134859d1d
BLAKE2b-256 checksum
How to use checksums
351e4b4885fcc4ccd1fb9f76d7a0d3dc017fdb15f945bca4f5450e0a029cab25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / torch_npu-2.12.0.post3-cp310-cp310-manylinux_2_28_aarch64.whl

Download URL torch_npu-2.12.0.post3-cp310-cp310-manylinux_2_28_aarch64.whl
Size 39.0 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
26f745cd551f13aca0ef6b1ef577de3c60564a42944569ba0d0eb94a083e81fc
BLAKE2b-256 checksum
How to use checksums
119c31381544a8c158de29ee72fb1cbc01031e56a36e24f72e82a270b0ab7d57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

2.12.0.post3 This release

10 release files

2.12.0

8 release files

2.11.0

8 release files

2.9.1

8 release files

2.9.0

6 release files

2.8.0

6 release files

2.7.1

6 release files

2.6.0

6 release files

2.5.1

6 release files

2.4.0

8 release files

2.3.1

6 release files

2.2.0

6 release files

2.1.0

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page