NPU bridge for PyTorch
Project description
PyTorch Ascend Adapter
Overview
This repository develops the PyTorch Ascend Adapter 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.
- Install PyTorch
Install PyTorch through pip.
For Aarch64:
pip3 install torch==2.1.0
For x86:
pip3 install torch==2.1.0+cpu --index-url https://download.pytorch.org/whl/cpu
- Install torch-npu dependencies
Run the following command to install dependencies.
pip3 install pyyaml
pip3 install setuptools
- Install torch-npu
Take Aarch64 architecture and Python 3.8 as an example.
NOTE: It will be supported to install torch_npu directly from pypi through pip recently.
wget https://gitee.com/ascend/pytorch/releases/download/v5.0.rc3-pytorch2.1.0/torch_npu-2.1.0rc1-cp38-cp38-linux_aarch64.whl
pip3 install torch_npu-2.1.0rc1-cp38-cp38-linux_aarch64.whl
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:
- Clone torch-npu
git clone https://github.com/ascend/pytorch.git -b v2.1.0-5.0.rc3 --depth 1
- Build Docker Image
cd pytorch/ci/docker/{arch} # {arch} for X86 or ARM
docker build -t manylinux-builder:v1 .
- 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
- 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)
PyTorch and Python Version Matching Table
PyTorch Version | Python Version |
---|---|
PyTorch1.8.1 | Python3.7.x(>=3.7.5),Python3.8.x,Python3.9.x |
PyTorch1.11.0 | Python3.7.x(>=3.7.5),Python3.8.x,Python3.9.x,Python3.10.x |
PyTorch2.0.1 | Python3.8.x,Python3.9.x,Python3.10.x |
PyTorch2.1.0 | Python3.8.x,Python3.9.x,Python3.10.x |
Ascend Auxiliary Software
AscendHub Image Version/Name(Link) |
||||
---|---|---|---|---|
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 | 3 months | Develop features. |
Maintained | 6-12 months | Allow the incorporation of all resolved issues and release the version. |
Unmaintained | 0-3 months | Allow the incorporation of all resolved issues. No dedicated maintenance personnel are available. No version will be released. |
End Of Life (EOL) | N/A | Do not accept any modification to a branch. |
Maintenance Status of Existing Branches
Branch Name | Status | Launch Date | Subsequent Status | EOL Date |
---|---|---|---|---|
v2.0.2 | EOL | 2021/7/29 | N/A | |
v2.0.3 | EOL | 2021/10/15 | N/A | |
v2.0.4 | EOL | 2022/1/15 | N/A | |
v3.0.rc1 | EOL | 2022/4/10 | N/A | |
v3.0.rc2 | UnMaintained | 2022/7/15 | EOL 2023-10-15 estimated | |
v3.0.rc3 | Maintained | 2022/10/20 | Unmaintained 2023-10-20 estimated |
|
v3.0.0 | Maintained | 2023/1/18 | Unmaintained 2024-1-18 estimated |
|
v5.0.rc1 | Maintained | 2023/4/19 | Unmaintained 2024-4-19 estimated |
|
v5.0.rc2 | Maintained | 2023/7/19 | Unmaintained 2024-7-19 estimated |
License
PyTorch Ascend Adapter has a BSD-style license, as found in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for torch_npu-2.1.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9127b0d5352806baf76d136714c8759e720052c109166aa30cce518739ca309e |
|
MD5 | 2b11411af9ba42d75ff285352a309edb |
|
BLAKE2b-256 | c009e3560f5d33038913e335aa31a527c5335b9ad61671edf92e0d15c934f7db |
Hashes for torch_npu-2.1.0rc1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caeb473d2df26cafdab91e79852e8edc7af2368b1d656b8f80fe2f45bad4d384 |
|
MD5 | ccb272d1765abebbf64e21af892b1b21 |
|
BLAKE2b-256 | 8afc394f24feb50e07e8db84ab029c56bd8cf953606b9a6e3f636a298c93fb06 |
Hashes for torch_npu-2.1.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff5cb75c84d07ae93db1a50764cb95c498fa992738db4c97e35deacb49e7ee5b |
|
MD5 | 5622203a0dfdee95c37a84e77736d46a |
|
BLAKE2b-256 | d23446eccc36b96096afcb20facd35dfa168255c7a64b886cce4f2a19462b602 |
Hashes for torch_npu-2.1.0rc1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c09c740e3fffee46b86c15102054cf3990c65d50d9c575cb3ee2955eb9d720fa |
|
MD5 | 7ad6854a114e1844961af91157e94478 |
|
BLAKE2b-256 | 9401d7410266e85be35f73333dcc03e32884e5a64b724543e2fce698ba8bfe93 |
Hashes for torch_npu-2.1.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e92c4b952808e4867717bf2014a0971ce3f1a04bf41a1d1694771596ab05709 |
|
MD5 | 73b89102a3dd2148544a5e715135ce69 |
|
BLAKE2b-256 | 2d37d6e5dc2f2389f82da2ce5b965a545aed5663d49c802efadafb143493fb36 |
Hashes for torch_npu-2.1.0rc1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5474fcc4cf0803654cd95b5ac6623a6c68f0c19747af5042dbad92e89443891d |
|
MD5 | 366c82e8c6a1b46ce70eac6eb3c36cdf |
|
BLAKE2b-256 | bfc54f23e4b52badb432fac59829a48be9779d8e60143fd5917a1478c285fcc7 |