Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

torch-npu

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

torch-npu

NPU bridge for PyTorch

  • 2.4.0
  • PyPI
  • Socket score

Maintainers
2

Ascend Extension for PyTorch

Overview

This repository develops the Ascend Extension for PyTorch named torch_npu to adapt Ascend NPU to PyTorch so that developers who use the PyTorch can obtain powerful compute capabilities 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 torch_npu. Before installing torch_npu, 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.4.0

For x86:

pip3 install torch==2.4.0+cpu  --index-url https://download.pytorch.org/whl/cpu
  1. Install torch-npu 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 archPython versionlink
x86Python3.8link
x86Python3.9link
x86Python3.10link
x86Python3.11link
aarch64Python3.8link
aarch64Python3.9link
aarch64Python3.10link
aarch64Python3.11link
  1. Install torch-npu
pip3 install torch-npu==2.4.0

From Source

In some special scenarios, users may need to compile torch-npu 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 torch-npu 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 10.2 for ARM and gcc 9.3.1 for X86.

  1. Clone torch-npu

    git clone https://github.com/ascend/pytorch.git -b v2.4.0-6.0.rc3 --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 torch-npu

    Take Python 3.8 as an example.

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

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

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

print(z)

User Manual

Refer to API of Ascend Extension for PyTorch for more detailed informations.

PyTorch and Python Version Matching Table

PyTorch VersionPython Version
PyTorch1.11.0Python3.7.x(>=3.7.5),Python3.8.x,Python3.9.x,Python3.10.x
PyTorch2.1.0Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.2.0Python3.8.x,Python3.9.x,Python3.10.x
PyTorch2.3.1Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x
PyTorch2.4.0Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.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 VersionSupported PyTorch VersionSupported Extension VersionGithub Branch
CANN 8.0.RC32.4.02.4.0v2.4.0-6.0.rc3
2.3.12.3.1.post2v2.3.1-6.0.rc3
2.1.02.1.0.post8v2.1.0-6.0.rc3
CANN 8.0.RC22.3.12.3.1v2.3.1-6.0.rc2
2.2.02.2.0.post2v2.2.0-6.0.rc2
2.1.02.1.0.post6v2.1.0-6.0.rc2
1.11.01.11.0.post14v1.11.0-6.0.rc2
CANN 8.0.RC2.alpha0022.3.12.3.1rc1v2.3.1
CANN 8.0.RC12.2.02.2.0v2.2.0-6.0.rc1
2.1.02.1.0.post4v2.1.0-6.0.rc1
1.11.01.11.0.post11v1.11.0-6.0.rc1
CANN 7.0.02.1.02.1.0v2.1.0-5.0.0
2.0.12.0.1.post1v2.0.1-5.0.0
1.11.01.11.0.post8v1.11.0-5.0.0
CANN 7.0.RC12.1.02.1.0.rc1v2.1.0-5.0.rc3
2.0.12.0.1v2.0.1-5.0.rc3
1.11.01.11.0.post4v1.11.0-5.0.rc3
CANN 6.3.RC3.11.11.01.11.0.post3v1.11.0-5.0.rc2.2
CANN 6.3.RC31.11.01.11.0.post2v1.11.0-5.0.rc2.1
CANN 6.3.RC22.0.12.0.1.rc1v2.0.1-5.0.rc2
1.11.01.11.0.post1v1.11.0-5.0.rc2
1.8.11.8.1.post2v1.8.1-5.0.rc2
CANN 6.3.RC11.11.01.11.0v1.11.0-5.0.rc1
1.8.11.8.1.post1v1.8.1-5.0.rc1
CANN 6.0.11.5.01.5.0.post8v1.5.0-3.0.0
1.8.11.8.1v1.8.1-3.0.0
1.11.01.11.0.rc2(beta)v1.11.0-3.0.0
CANN 6.0.RC11.5.01.5.0.post7v1.5.0-3.0.rc3
1.8.11.8.1.rc3v1.8.1-3.0.rc3
1.11.01.11.0.rc1(beta)v1.11.0-3.0.rc3
CANN 5.1.RC21.5.01.5.0.post6v1.5.0-3.0.rc2
1.8.11.8.1.rc2v1.8.1-3.0.rc2
CANN 5.1.RC11.5.01.5.0.post5v1.5.0-3.0.rc1
1.8.11.8.1.rc1v1.8.1-3.0.rc1
CANN 5.0.41.5.01.5.0.post42.0.4.tr5
CANN 5.0.31.8.11.5.0.post32.0.3.tr5
CANN 5.0.21.5.01.5.0.post22.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 seriesProduct model
Atlas Training series productsAtlas 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 productsAtlas 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 seriesProduct model
Atlas 800I A2 Inference productAtlas 800I A2

Pipeline Status

Due to the asynchronous development mechanism of upstream and downstream, incompatible modifications in upstream may cause some functions of torch_npu 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.

OSCANN Version(Docker Image)Upstream BranchDownstream BranchPeriodStatus
openEuler 22.03 SP2CANN 7.1mainmasterUTC 1200 dailyAscend 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:

StatusDurationDescription
Planning1-3 monthsPlan features.
Development6-12 monthsDevelop 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.
Maintained3.5 yearsMaintain bugs, do not incorporate new features, and release patch versions based on the impact of bugs.
End Of Life (EOL)N/ADo not accept any modification to a branch.

PyTorch Maintenance Policies

PyTorchMaintenance PoliciesStatusLaunch DateSubsequent StatusEOL Date
2.4.0Regular ReleaseDevelopment2024/10/15Expected to enter maintenance status from March 15, 2025
2.3.1Regular ReleaseDevelopment2024/06/06Expected to enter maintenance status from December 6, 2024
2.2.0Regular ReleaseMaintained2024/04/01Expected to enter maintenance free status from September 10th, 2025
2.1.0Long Term SupportDevelopment2023/10/15Expected to enter maintenance status from March 30, 2025
2.0.1Regular ReleaseEOL2023/7/192024/3/14
1.11.0Long Term SupportMaintained2023/4/19Expected to enter maintenance free status from September 10th, 2025
1.8.1Long Term SupportEOL2022/4/102023/4/10
1.5.0Long Term SupportEOL2021/7/292022/7/29

Reference Documents

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

Document NameDocument Link
Installation Guidelink
Network Model Migration and Traininglink
Operator Adaptationlink
API List (PyTorch and Custom Interfaces)link

License

Ascend Extension for PyTorch has a BSD-style license, as found in the LICENSE file.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc