Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0d724c3c6 | ||
|
|
0ea0d95f7b | ||
|
|
d4ffa0a823 | ||
|
|
a47d202e3e | ||
|
|
6db8b2d88d | ||
|
|
03a193fd0d | ||
|
|
513f46decc | ||
|
|
2b48121bbf | ||
|
|
e3e229839f | ||
|
|
88719bd40a | ||
|
|
3fc20b8b30 | ||
|
|
e751f65710 | ||
|
|
86a79738b3 | ||
|
|
5fcd2ba271 | ||
|
|
cb18de2fef | ||
|
|
b292bc05c9 | ||
|
|
95cf34f163 | ||
|
|
eb4a799674 | ||
|
|
d1305fd848 | ||
|
|
c5f7e64aa5 | ||
|
|
abc10caebd | ||
|
|
fd7a52be39 | ||
|
|
847cbbbb1a | ||
|
|
681f5543e4 | ||
|
|
1a380aefee | ||
|
|
d52f542aa7 | ||
|
|
e434ebc805 | ||
|
|
41bfe9c544 | ||
|
|
df05b7a031 | ||
|
|
c39e008d3b | ||
|
|
3d3750411f | ||
|
|
11e4eb7eb8 | ||
|
|
defe0587f6 | ||
|
|
dffecfba93 | ||
|
|
d57152e0cd | ||
|
|
04c8dfea99 | ||
|
|
db66d80806 | ||
|
|
9ab75c8967 | ||
|
|
c8085ae921 | ||
|
|
2032d04858 | ||
|
|
255de550cc | ||
|
|
7a8ecbca90 | ||
|
|
43f5a19a2f | ||
|
|
93a2fdc566 | ||
|
|
6d23724871 | ||
|
|
32f82f58ef | ||
|
|
dfec8bbb20 | ||
|
|
4fd08f5fc6 | ||
|
|
e5e76d5ff0 | ||
|
|
1ca343fff0 | ||
|
|
99172aa0ca | ||
|
|
2b58bddcb0 | ||
|
|
4f7caaaf7f | ||
|
|
02298ccc80 | ||
|
|
f80b97dadc | ||
|
|
b31dfee2d7 | ||
|
|
64c1e12c6a | ||
|
|
732ae7c134 | ||
|
|
333c907f8d | ||
|
|
2e7e39b507 | ||
|
|
57cc74e900 | ||
|
|
c3a5d05424 | ||
|
|
a18e48a834 | ||
|
|
5930dbec25 | ||
|
|
a932e65f9e | ||
|
|
6e3dbfa3c7 | ||
|
|
889d2ae716 | ||
|
|
bdc0d2a819 | ||
|
|
d5aca3c9d8 | ||
|
|
5b477928d5 | ||
|
|
6daeb34d1e | ||
|
|
67b74b6919 | ||
|
|
8c019dc9f6 | ||
|
|
138ccbab13 | ||
|
|
e8e34e1648 | ||
|
|
c693353ef1 | ||
|
|
f9b8c654cf | ||
|
|
350a490e87 | ||
|
|
e7d59cbfaf | ||
|
|
32ca47c016 | ||
|
|
88bc2d63eb | ||
|
|
7c14ecce0d | ||
|
|
a05df6bdda | ||
|
|
b3a7f790c8 | ||
|
|
88e7cd0667 | ||
|
|
38267666fe | ||
|
|
b387a3427d | ||
|
|
3f4ffba595 | ||
|
|
154bcfced6 | ||
|
|
12303a6da0 | ||
|
|
7a20b65e2f | ||
|
|
d11cd94156 | ||
|
|
c45de03e71 | ||
|
|
c87f2cd51b | ||
|
|
a6189a76e5 | ||
|
|
73c47b1e64 | ||
|
|
2d7d639562 | ||
|
|
ace64b8445 | ||
|
|
c06ce48b89 | ||
|
|
274b892c56 | ||
|
|
7e2c3d7979 | ||
|
|
4b396515d5 | ||
|
|
2d8ece95b3 | ||
|
|
de3435090b | ||
|
|
27cf56f730 | ||
|
|
4dc478adab | ||
|
|
e1f9bb08d1 | ||
|
|
4b28c57993 | ||
|
|
6afb6c635b | ||
|
|
3ae0c6ae3f | ||
|
|
30b9ebb94d | ||
|
|
844328508e | ||
|
|
ec0828a267 | ||
|
|
54c1b37228 | ||
|
|
4b31ff2cb5 | ||
|
|
150ead5660 | ||
|
|
cfcc3a2f8b | ||
|
|
aeba162110 | ||
|
|
7c31e72e10 | ||
|
|
e3e79304fd | ||
|
|
3c84bfa2c3 | ||
|
|
7759024b2c | ||
|
|
0e5945d7e7 | ||
|
|
af794ca02d | ||
|
|
433d206ff7 | ||
|
|
15c670d1f8 | ||
|
|
5a9ac1dece | ||
|
|
03739b8421 | ||
|
|
94f19f9447 | ||
|
|
13e1c247bc | ||
|
|
cfe4effb45 | ||
|
|
bf2a5a75f0 | ||
|
|
9edee0857d | ||
|
|
4f38dbfe21 | ||
|
|
e23edc496a | ||
|
|
7b620de388 | ||
|
|
49e47199f0 | ||
|
|
40394042b1 | ||
|
|
b3927b466a | ||
|
|
6285c99df0 | ||
|
|
2005dfa5cf | ||
|
|
7f42d3111f | ||
|
|
e05a732de7 | ||
|
|
9ee9b54722 | ||
|
|
120ab81ead | ||
|
|
d1ec3489a8 | ||
|
|
8af1e10abc | ||
|
|
d0cfe101cf | ||
|
|
c1e759b93c | ||
|
|
3e878edfd5 | ||
|
|
34aad3ba20 | ||
|
|
2d3c963a8b | ||
|
|
36b69a909b | ||
|
|
e65c39e589 | ||
|
|
96e2e34cbb | ||
|
|
5fa7efcfba | ||
|
|
d0a4b62e54 | ||
|
|
2ea0c67fc1 | ||
|
|
4caa12ab7d | ||
|
|
10a9e48f97 | ||
|
|
cb45330ce1 | ||
|
|
dc98244a89 | ||
|
|
682eca49df | ||
|
|
71554f76d1 | ||
|
|
c279e2e92a | ||
|
|
9fcd859d96 | ||
|
|
294aef2b9b | ||
|
|
47b089cb6c | ||
|
|
fbde60dc1d | ||
|
|
3a44ffc52e | ||
|
|
cb3d7402d2 | ||
|
|
22c2d837ca | ||
|
|
dca21b621a | ||
|
|
c2a7d66b13 | ||
|
|
5e5a2a7925 | ||
|
|
a3bb1f25c4 | ||
|
|
0d33ee3e0d | ||
|
|
796d41d691 | ||
|
|
bdb376cdb3 | ||
|
|
4dc31edf9a | ||
|
|
aafe2061ac | ||
|
|
2eaee92eb0 | ||
|
|
416deb85dd | ||
|
|
f1891c36af | ||
|
|
e7e6580ca2 | ||
|
|
c1f3ad0761 | ||
|
|
913f54dc61 | ||
|
|
31c3f964bd | ||
|
|
f70a8b1e31 | ||
|
|
6d5a62b73d | ||
|
|
4f5ed6616a | ||
|
|
8d535a9189 | ||
|
|
563de6fbd9 | ||
|
|
ed367a62b7 | ||
|
|
3eecafe015 | ||
|
|
274004f7ad | ||
|
|
6b9315ad91 | ||
|
|
3c9a47cd8c | ||
|
|
586b3fa039 | ||
|
|
e093b4359a | ||
|
|
a861f3cb96 | ||
|
|
47b5c52129 | ||
|
|
f738240fd5 | ||
|
|
c837a70844 | ||
|
|
2a323fab49 | ||
|
|
1a08ccad88 | ||
|
|
f7b065414b | ||
|
|
b3fbc1dee0 | ||
|
|
ba413bdc6c | ||
|
|
5193ae8b44 | ||
|
|
48b35ef669 | ||
|
|
e382982f9f | ||
|
|
3107fe16f7 | ||
|
|
178f3bc3c8 | ||
|
|
c085ad4eb7 | ||
|
|
0fc3c3a7c4 | ||
|
|
f89c8a2187 | ||
|
|
aeca353926 | ||
|
|
6e3d104476 | ||
|
|
d003421c1a | ||
|
|
193772bbea | ||
|
|
9ae625472e | ||
|
|
26178c3a1b | ||
|
|
be5356c0c6 | ||
|
|
b3372ee933 | ||
|
|
e96c816b06 | ||
|
|
7eeb579f3f | ||
|
|
c489d97007 | ||
|
|
ca485063d0 | ||
|
|
3cd7ed797d | ||
|
|
6ca23d5514 | ||
|
|
287c6e6cc3 | ||
|
|
316cc29ee2 | ||
|
|
f77253ae52 | ||
|
|
ae834d5ab6 | ||
|
|
824e689004 | ||
|
|
456439d5fa | ||
|
|
073a7ea5ff | ||
|
|
5f3a2c11fc | ||
|
|
c61f676a86 | ||
|
|
05b72bbd37 | ||
|
|
5cc52fb0d1 | ||
|
|
fd7df84a23 | ||
|
|
b9b4bb55f2 | ||
|
|
5c4774edfd | ||
|
|
9e8c744c9b | ||
|
|
c69b311610 | ||
|
|
4fc41a0ba9 | ||
|
|
5e85916c11 | ||
|
|
087c31c639 | ||
|
|
5043e98a9d | ||
|
|
da46157333 | ||
|
|
e4d4da89fb | ||
|
|
33ddeeacc1 | ||
|
|
7c25c163b5 | ||
|
|
44456a207d | ||
|
|
e4545fc3a1 | ||
|
|
4c55098d78 | ||
|
|
6e5333f278 | ||
|
|
5de24000dc | ||
|
|
a70b2dc515 | ||
|
|
ce1a48074f | ||
|
|
e6c723cf1d | ||
|
|
5bd7ddf2b6 | ||
|
|
f519cc5110 | ||
|
|
3dd19b2755 | ||
|
|
c441c8ab11 | ||
|
|
675e0d7869 | ||
|
|
4c9cc52b0e | ||
|
|
5f326039fd | ||
|
|
62fed021fe | ||
|
|
91837b9a3b | ||
|
|
57299e8539 | ||
|
|
3a01034b86 | ||
|
|
e6ed5931a7 | ||
|
|
f7cd5ac04a | ||
|
|
b05f263002 | ||
|
|
8c5dd060e3 | ||
|
|
ac5c210a3f | ||
|
|
dde15147ef | ||
|
|
b08e75eb9b | ||
|
|
8eb3985a69 | ||
|
|
745ea1d2ca | ||
|
|
67d8b2d801 | ||
|
|
0774236c93 | ||
|
|
40c47421ab | ||
|
|
3fbdcf7b02 | ||
|
|
150a34d6b9 | ||
|
|
53296dbd84 | ||
|
|
b81e31a023 | ||
|
|
4a91d7f244 | ||
|
|
f99e45f951 | ||
|
|
6b932a1c14 | ||
|
|
081221378d | ||
|
|
8ef0a73f52 | ||
|
|
fb4a88b4df | ||
|
|
dbc635ffd8 | ||
|
|
341a0d458e | ||
|
|
30dea0aa6b | ||
|
|
9e457706a6 | ||
|
|
9541c9b673 |
@@ -0,0 +1,24 @@
|
||||
<!-- Thanks for sending a pull request!
|
||||
-->
|
||||
|
||||
**What type of PR is this?**
|
||||
> Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line:
|
||||
>
|
||||
> /kind bug
|
||||
> /kind task
|
||||
> /kind feature
|
||||
|
||||
|
||||
**What does this PR do / why do we need it**:
|
||||
|
||||
|
||||
**Which issue(s) this PR fixes**:
|
||||
<!--
|
||||
*Automatically closes linked issue when PR is merged.
|
||||
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
|
||||
-->
|
||||
Fixes #
|
||||
|
||||
**Special notes for your reviewers**:
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ approvers:
|
||||
- blian
|
||||
- nalinaly
|
||||
- weili10
|
||||
- you-ansheng
|
||||
reviewers:
|
||||
- zhou_sinan
|
||||
- shibo19
|
||||
- Ronnie_zheng
|
||||
- xiaxia3
|
||||
@@ -11,9 +11,21 @@ reviewers:
|
||||
- petissue
|
||||
- td__lihan
|
||||
- ascendzyj
|
||||
- wangyu0516
|
||||
- wudingyuan
|
||||
- yskhhh
|
||||
- lvpeiyuan
|
||||
- xchu42
|
||||
- matrixplayer
|
||||
- li_jing_hw
|
||||
- wangjiangben_hw
|
||||
- qingfenxiaochong
|
||||
- goodjobwubai
|
||||
- fairwarning
|
||||
- fairwarning
|
||||
- you-ansheng
|
||||
- yinzijun
|
||||
- weili10
|
||||
- shaoyf
|
||||
- yanpengquan07
|
||||
- xiong05
|
||||
- liu-jiaweikf
|
||||
- xiepeng20
|
||||
- brightlyking
|
||||
- chenhao_1209
|
||||
@@ -1,85 +1,102 @@
|
||||
# AscendPyTorch
|
||||
|
||||
|
||||
# Project Introduction
|
||||
This project develops the PyTorch Adapter plugin to adapt Ascend to the PyTorch framework so that developers who use the PyTorch framework can obtain powerful compute capabilities of Ascend AI Processors.
|
||||
<h1 id="introductionmd">Introduction</h1>
|
||||
This project develops the PyTorch Adapter plugin to adapt Ascend to the PyTorch framework so that developers who use the PyTorch framework can obtain powerful compute capabilities of Ascend AI Processors. When setting up the environment for model development and running under PyTorch, you can manually build and install modules adapted to the PyTorch framework on a server.
|
||||
|
||||
# Compilation/Execution Constraints
|
||||
|
||||
GCC version: 7.3.0 (required only in compilation scenarios)
|
||||
|
||||
CMake version: 3.12.0 or later (required only in compilation scenarios)
|
||||
|
||||
Python versions: 3.7.5 and 3.8.*x* (The compilation methods are different. For details, see the script compilation section.)
|
||||
<h3 id="prerequisitesmd">Prerequisites</h3>
|
||||
|
||||
- The development or operating environment of CANN has been installed. For details, see the *CANN Software Installation Guide*.
|
||||
- Python version: 3.7.5 or 3.8
|
||||
|
||||
# System Dependencies
|
||||
|
||||
## CentOS & EulerOS
|
||||
|
||||
yum install -y cmake zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas
|
||||
yum install -y patch zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas git dos2unix
|
||||
|
||||
yum install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
## Ubuntu
|
||||
|
||||
apt-get install -y gcc g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 cmake dos2unix libopenblas-dev
|
||||
apt-get install -y patch g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 dos2unix libopenblas-dev git dos2unix
|
||||
|
||||
apt-get install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
|
||||
|
||||
> **NOTE:**
|
||||
>If an error occurs during the installation of the GCC and CMake dependency commands, use the source code for installation. For details, see the FAQ.
|
||||
|
||||
|
||||
|
||||
# Ascend Auxiliary Software
|
||||
|
||||
| AscendPyTorch Version| CANN Version| Supported PyTorch Version|
|
||||
| :---------------- | :--------- | :------------------------------- |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0 and 1.8.1 (Only the ResNet-50 model is supported.)|
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0 and 1.8.1 (Only the ResNet-50 model is supported.)|
|
||||
| AscendPyTorch Version| CANN Version| Supported PyTorch Version| Gitee Branch|
|
||||
| :------------ | :----------- | :----------- | ------------ |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0.post2 | 2.0.2.tr5 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | 2.0.3.tr5 |
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | 2.0.4.tr5 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5 | v1.5.0-3.0.rc1 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.8.1.rc1 | v1.8.1-3.0.rc1 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.5.0.post6 | v1.5.0-3.0.rc2 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.8.1.rc2 | v1.8.1-3.0.rc2 |
|
||||
|
||||
# Method of Use - Full Code Generation and Compilation
|
||||
# Installation Methods
|
||||
|
||||
## Obtain the native PyTorch source code and third-party code.
|
||||
## Installing the PyTorch Environment Dependencies
|
||||
|
||||
Currently, PyTorch 1.5.0 and 1.8.1 are supported. Obtain the native PyTorch source code from the root directory **pytorch/** in the current repository as required.
|
||||
|
||||
Obtain the PyTorch source code (from the current repository) that adapts to Ascend AI Processors.
|
||||
|
||||
```
|
||||
git clone -b v1.5.0-3.0.rc2 https://gitee.com/ascend/pytorch.git
|
||||
```
|
||||
|
||||
## Obtaining the Native PyTorch Source Code and Third-Party Code
|
||||
|
||||
Obtain the native PyTorch 1.5.0 source code from the root directory **/pytorch** of the current repository. Check whether there are fixed security-related issues in the Security and Issues categories in the PyTorch native repository. Update the native PyTorch code if there are any fixes.
|
||||
|
||||
```sh
|
||||
// Version 1.5.0
|
||||
cd pytorch
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
// Version 1.8.1
|
||||
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
Go to the **pytorch/pytorch/** directory and obtain the passive dependency code of PyTorch. (It takes a long time to obtain the code.)
|
||||
Go to the **pytorch/pytorch/** directory and obtain the passive dependency code of PyTorch. It takes a long time to obtain the code.
|
||||
|
||||
```sh
|
||||
cd pytorch
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
If no error is reported after the preceding operations are complete, the PyTorch and third-party code on which PyTorch depends is generated.
|
||||
If no error is reported, the PyTorch and third-party code on which PyTorch depends is generated.
|
||||
|
||||
## Generate the PyTorch code adapted to Ascend AI Processors.
|
||||
## Generating Full PyTorch Code That Adapts to Ascend AI Processors
|
||||
|
||||
Go to the **pytorch/scripts** directory and run the script based on the selected version. (Note: The downloaded native PyTorch source code must match the following version. Otherwise, an error may occur.)
|
||||
Go to the **pytorch/scripts** directory and run the script of the selected version. (Note: The downloaded native PyTorch source code must match the following version. Otherwise, an error may occur.)
|
||||
|
||||
```sh
|
||||
// The default version is 1.5.0.
|
||||
cd ../scripts/
|
||||
bash gen.sh
|
||||
// For version 1.8.1, use the -v option to specify the version number.
|
||||
bash gen.sh -v 1.8.1
|
||||
```
|
||||
|
||||
The full code adapted to NPUs is generated in the **pytorch/pytorch/** directory.
|
||||
The full code adapted to the NPU is generated in the **pytorch/pytorch/** directory.
|
||||
|
||||
|
||||
## Install the Python dependency.
|
||||
## Installing the Python Dependency Library
|
||||
|
||||
Go to the **pytorch/pytorch/** directory and install the Python dependency.
|
||||
Go to the **pytorch/pytorch/** directory and install the Python dependency library.
|
||||
|
||||
```python3
|
||||
cd ../pytorch
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
|
||||
## Compile the binary package of Torch.
|
||||
## Compiling Torch Binary Package
|
||||
|
||||
Go to the **pytorch/pytorch/** directory and run the following command:
|
||||
In the **pytorch/pytorch/** directory, run the following command:
|
||||
|
||||
```sh
|
||||
# Python 3.7
|
||||
@@ -93,24 +110,25 @@ bash build.sh --python=3.8
|
||||
|
||||
The generated binary package is in the **pytorch/pytorch/dist/** directory.
|
||||
|
||||
# Installation
|
||||
|
||||
### (Version 1.5.0 is used as an example. The same rule applies to version 1.8.1.)
|
||||
## Installing PyTorch
|
||||
|
||||
**x86_64:**
|
||||
|
||||
**torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl** (The actual name may contain the minor version number, for example, **torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl**.)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
|
||||
```
|
||||
|
||||
|
||||
**arm:**
|
||||
|
||||
**torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl** (The actual name may contain the minor version number, for example, **torch-1.5.0.post2+ascend-cp37-cp37m-linux_aarch64.whl**.)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
@@ -118,47 +136,76 @@ pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
|
||||
|
||||
# Running
|
||||
|
||||
## Execute environment variables.
|
||||
## Executing Environment Variables
|
||||
|
||||
Run the script for setting environment variables in the root directory of the current repository.
|
||||
Run the script for setting environment variables in the **pytorch/pytorch/** directory.
|
||||
|
||||
```
|
||||
source pytorch/env.sh
|
||||
cd ../
|
||||
source env.sh
|
||||
```
|
||||
|
||||
|
||||
## Customize environment variables.
|
||||
|
||||
The following environment variables are function classes used in NPU scenarios or environment variables that can improve performance:
|
||||
|
||||
```
|
||||
export TASK_QUEUE_ENABLE=1 # Delivered by an asynchronous task to asynchronously call the ACL interface. You are advised to enable this environment variable and set its value to 1.
|
||||
export PTCOPY_ENABLE=1 # Use the PTCopy operator mode to accelerate continuous rotation and copy. You are advised to enable this environment variable and set its value to 1.
|
||||
```
|
||||
|
||||
The following are optional environment variables that may affect running models:
|
||||
|
||||
```
|
||||
export DYNAMIC_COMPILE_ENABLE=1 # Dynamic shape feature. This environment variable is optional for shape change scenarios. To enable it, set its value to 1.
|
||||
export COMBINED_ENABLE=1 # Optimization of scenarios where two inconsecutive operators are combined. This environment variable is optional. To enable it, set its value to 1.
|
||||
export TRI_COMBINED_ENABLE=1 # Optimization of scenarios where three inconsecutive operators are combined. This environment variable is optional. To enable it, set its value to 1.
|
||||
export ACL_DUMP_DATA=1 # Operator data dump function, which is used for debugging. This environment variable is optional. To enable it, set its value to 1.
|
||||
export DYNAMIC_OP="ADD#MUL" # Operator implementation. The ADD and MUL operators have different performance in different scenarios. This environment variable is optional.
|
||||
|
||||
export COMBINED_ENABLE=1 # (Optional) Discontinuous-to-continuous level-2 derivation optimization. To enable this function, set the value to **1**. When a large number of time-consuming AsStrided operators are called in the model, you can enable this function to improve the device execution efficiency.
|
||||
export ACL_DUMP_DATA=1 # (Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to **1**.
|
||||
export TASK_QUEUE_ENABLE=1 # Delivered by an asynchronous task to asynchronously call the ACL interface. You are advised to enable this environment variable and set its value to **1**.
|
||||
|
||||
```
|
||||
If the system is openEuler or its inherited OS, such as UOS, run the following command to cancel CPU core binding.
|
||||
|
||||
```
|
||||
# unset GOMP_CPU_AFFINITY
|
||||
```
|
||||
**Table 1** Description of environment variables
|
||||
|
||||
## Run the unit test script.
|
||||
<a name="zh-cn_topic_0000001152616261_table42017516135"></a>
|
||||
<table><thead align="left"><tr id="zh-cn_topic_0000001152616261_row16198951191317"><th class="cellrowborder" valign="top" width="55.48%" id="mcps1.2.3.1.1"><p id="zh-cn_topic_0000001152616261_p51981251161315"><a name="zh-cn_topic_0000001152616261_p51981251161315"></a><a name="zh-cn_topic_0000001152616261_p51981251161315"></a>Environment Variable</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="44.519999999999996%" id="mcps1.2.3.1.2"><p id="zh-cn_topic_0000001152616261_p9198135114133"><a name="zh-cn_topic_0000001152616261_p9198135114133"></a><a name="zh-cn_topic_0000001152616261_p9198135114133"></a>Description</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(Optional) Discontinuous-to-continuous level-2 derivation optimization. To enable this function, set the value to **1**. When a large number of time-consuming AsStrided operators are called in the model, you can enable this function to improve the device execution efficiency.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to **1**.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16711563237"><a name="zh-cn_topic_0000001152616261_p16711563237"></a><a name="zh-cn_topic_0000001152616261_p16711563237"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p0711356152317"><a name="zh-cn_topic_0000001152616261_p0711356152317"></a><a name="zh-cn_topic_0000001152616261_p0711356152317"></a>(Optional) Use asynchronous task delivery to asynchronously invoke the ACL interface. To enable this function, set it to **1** (recommended default setting).</p>
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Running the Unit Test Script
|
||||
|
||||
Verify the running. The output is **OK**.
|
||||
|
||||
Verify the execution. The output result is OK.
|
||||
|
||||
```shell
|
||||
// Select a test script that matches the preceding version. The following uses the 1.5.0 version as an example.
|
||||
python3 pytorch1.5.0/test/test_npu/test_div.py
|
||||
// The following uses the 1.8.1 version as an example.
|
||||
python3 pytorch1.8.1/test/test_npu/test_div.py
|
||||
cd ../
|
||||
python3 pytorch1.5.0/test/test_npu/test_network_ops/test_div.py
|
||||
```
|
||||
# (Optional) Installing the Mixed Precision Module
|
||||
|
||||
# Documentation
|
||||
Select the APEX module based on the following functions. For details about how to build and install the APEX module, see the [README.en](https://gitee.com/ascend/apex/tree/v1.5.0-3.0.rc2).
|
||||
|
||||
- APEX
|
||||
- O1 configuration mode: Conv and Matmul use the float16 precision for computing, and Softmax and BN use float32.
|
||||
- O2 configuration mode: BN uses the float32 precision for computing, and others use float16.
|
||||
- Static loss scale: Parameters are statically set to ensure the convergence of training with mixed precision.
|
||||
- Dynamic loss scale: The loss scale value is dynamically calculated to determine whether overflow occurs.
|
||||
|
||||
# Documents
|
||||
|
||||
For more details about the installation guide, model porting and training/inference tutorials, and API list, see [User Documents](https://gitee.com/ascend/pytorch/tree/master/docs/en).
|
||||
|
||||
@@ -170,24 +217,45 @@ We sincerely welcome you to join discussions in the community and contribute you
|
||||
|
||||
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 modifications to a branch. |
|
||||
| **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** | Maintained | 2021-07-29 | Unmaintained <br> 2022-07-29 estimated | |
|
||||
| **v2.0.3** | Maintained | 2021-10-15 | Unmaintained <br> 2022-10-15 estimated | |
|
||||
| **v2.0.4** | Maintained | 2022-11-15 | Unmaintained <br> 2023-01-15 estimated | |
|
||||
| **Branch Name**| **Status** | **Launch Date** | **Subsequent Status** | **EOL Date**|
|
||||
|------------|--------------|----------------------|----------------------------------------|------------|
|
||||
| **v2.0.2** | Maintained | 2021-07-29 | Unmaintained <br> 2022-07-29 estimated | |
|
||||
| **v2.0.3** | Maintained | 2021-10-15 | Unmaintained <br> 2022-10-15 estimated | |
|
||||
| **v2.0.4** | Maintained | 2022-01-15 | Unmaintained <br> 2023-01-15 estimated | |
|
||||
| **v3.0.rc1** | Maintained | 2022-04-10 | Unmaintained <br> 2023-04-10 estimated | |
|
||||
| **v3.0.rc2** | Maintained | 2022-07-15 | Unmaintained <br> 2023-07-15 estimated | |
|
||||
|
||||
# FAQ
|
||||
|
||||
## When PIP is set to the Huawei source, a Python environment error occurs after the typing dependency in the **requirements.txt** file is installed.
|
||||
|
||||
When PIP is set to the Huawei source, open the **requirements.txt** file, delete the typing dependency, and then run the following command:
|
||||
|
||||
```
|
||||
pip3 install -r requirments.txt
|
||||
```
|
||||
|
||||
|
||||
|
||||
## The **libhccl.so** cannot be found by **import torch**.
|
||||
|
||||
Environment variables are not configured. You need to configure them using the **env.sh** script.
|
||||
|
||||
```
|
||||
source pytorch/pytorch1.5.0/src/env.sh
|
||||
```
|
||||
|
||||
|
||||
# FAQs
|
||||
|
||||
## The error message "no module named yaml/typing_extensions." is displayed when **bash build.sh** is run during compilation.
|
||||
|
||||
@@ -200,18 +268,24 @@ pip3 install typing_extensions
|
||||
|
||||
After the installation is successful, run **make clean** and then **bash build.sh** to perform compilation. Otherwise, an unknown compilation error may occur due to the cache.
|
||||
|
||||
## TE cannot be found during running
|
||||
|
||||
|
||||
## TE cannot be found during running.
|
||||
|
||||
Development state:
|
||||
|
||||
```
|
||||
cd /urs/local/ascend-toolkit/latest/fwkacllib/lib64
|
||||
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64 # {arch} indicates the architecture name.
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
User state:
|
||||
|
||||
```
|
||||
cd /urs/local/nnae/latest/fwkacllib/lib64
|
||||
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64 # {arch} indicates the architecture name.
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
@@ -220,27 +294,168 @@ pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
|
||||
|
||||
|
||||
## An error message is reported during CMake compilation, indicating that the version is too early.
|
||||
## During CMake installation through the CLI, an error is reported indicating that the package cannot be found. During CMake compilation, another error is reported indicating that the version is too early. In this cause, you can use the installation script or source code to compile and install CMake.
|
||||
|
||||
Download the Linux version from the CMake official website and install it. (The current version is 3.18.0.)
|
||||
Method 1: Download the installation script and install CMake. (For details, see the CMake official website.)
|
||||
|
||||
1. Run the **yum install -y cmake==3.18.0** command to install it.
|
||||
x86_64 environment: cmake-3.12.0-Linux-x86_64.sh
|
||||
|
||||
2. Download the **cmake sh** script and install it. (For details, see the CMake official website.)
|
||||
AArch64 environment: cmake-3.12.0-Linux-aarch64.sh
|
||||
|
||||
Recommended script in the x86_64 environment: **cmake-3.18.2-Linux-x86_64.sh**
|
||||
1. Run the following commands:
|
||||
|
||||
|
||||
```
|
||||
./cmake-3.12.0-Linux-{arch}.sh #{arch} indicates the architecture name.
|
||||
```
|
||||
|
||||
## GCC version switch errors occur.
|
||||
2. Set the soft link.
|
||||
|
||||
When the test environment is switched from GCC 4.8.5 to GCC 7.3.0, errors may occur and the PyTorch compilation may fail. The following lists the libraries that require soft connections:
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
gcc, g++, c++ (The version must be 7.3.0.)
|
||||
3. Run the following command to check whether CMake has been installed:
|
||||
|
||||
libstdc++->libstdc++.so.6.0.24 (7.3.0)
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
If the message "cmake version 3.12.0" is displayed, the installation is successful.
|
||||
|
||||
|
||||
Method 2: Use the source code to compile and install.
|
||||
|
||||
1. Obtain the CMake software package.
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
|
||||
```
|
||||
|
||||
2. Decompress the package and go to the software package directory.
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.0.tar.gz
|
||||
cd cmake-3.12.0/
|
||||
```
|
||||
|
||||
3. Run the configuration, compilation, and installation commands.
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
4. Set the soft link.
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
5. Run the following command to check whether CMake has been installed:
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
If the message "cmake version 3.12.0" is displayed, the installation is successful.
|
||||
|
||||
|
||||
|
||||
## During GCC installation through the CLI, an error is reported indicating that the package cannot be found. During GCC compilation, another error is reported.
|
||||
|
||||
When downloading GCC from some sources, you may be prompted by an error message indicating that the package cannot be found. In this case, use the source code to compile and install GCC.
|
||||
|
||||
Perform the following steps as the **root** user.
|
||||
|
||||
1. Download **gcc-7.3.0.tar.gz** from [https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz).
|
||||
|
||||
2. GCC installation requires adequate temporary space. Run the following command to clear the **/tmp** directory in advance:
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
3. Install the dependency package. (CentOS and Ubuntu are used as examples.)
|
||||
|
||||
- For CentOS, run the following command:
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
- For Ubuntu, run the following command:
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
4. Compile and install GCC.
|
||||
|
||||
1. Go to the directory where the source package **gcc-7.3.0.tar.gz** is located and run the following command to decompress it:
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
|
||||
2. Go to the extracted directory and download the GCC dependency packages:
|
||||
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If an error is reported during the command execution, run the following commands in the **gcc-7.3.0/** directory to download the dependency packages:
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
After the preceding dependencies are downloaded, run the following command again:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If the verification fails, check whether there are duplicate dependency packages in the folder. If yes, delete duplicate ones.
|
||||
|
||||
3. <a name="zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310"></a>Run the configuration, compilation, and installation commands.
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # Check the number of CPUs by running **grep -w processor /proc/cpuinfo|wc -l**. In this example, the number is 15. You can set the parameters as required.
|
||||
make install
|
||||
```
|
||||
|
||||
>  **NOTE:**
|
||||
>The **--prefix** option is used to specify the **linux_gcc7.3.0** installation path, which is configurable. Do not set it to **/usr/local** or **/usr,** which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to **/usr/local/linux_gcc7.3.0**.
|
||||
|
||||
4. Change the soft links.
|
||||
|
||||
```
|
||||
ln -s ${install_path}/bin/gcc /usr/bin/gcc
|
||||
ln -s ${install_path}/bin/g++ /usr/bin/g++
|
||||
ln -s ${install_path}/bin/c++ /usr/bin/c++
|
||||
```
|
||||
|
||||
5. Configure environment variables.
|
||||
|
||||
Training must be performed in the compilation environment with GCC upgraded. If you want to run training, configure the following environment variable in your training script:
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
**${install_path}** indicates the GCC 7.3.0 installation path configured in [3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310). In this example, the GCC 7.3.0 installation path is **/usr/local/linux_gcc7.3.0/**.
|
||||
|
||||
> **NOTE:**
|
||||
>Skip this step if you do not need to use the compilation environment with GCC upgraded.
|
||||
|
||||
If the PyTorch compilation fails, check whether the soft link library is correct.
|
||||
|
||||
libstdc++->libstdc++.so.6.0.24(7.3.0)
|
||||
|
||||
## libblas.so cannot be found.
|
||||
|
||||
@@ -258,6 +473,28 @@ Ubuntu
|
||||
apt install libopenblas-dev
|
||||
```
|
||||
|
||||
|
||||
|
||||
## torchvision fails to be installed using pip in the Arm environment.
|
||||
|
||||
The source code can be used for installation. (You need to install the AscendPyTorch first and configure environment variables using **env.sh**.)
|
||||
|
||||
```
|
||||
git clone -b v0.6.0 https://github.com/pytorch/vision.git
|
||||
cd vision
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
Verify that the torchvision is successfully installed.
|
||||
|
||||
```
|
||||
python -c "import torchvision"
|
||||
```
|
||||
|
||||
If no error is reported, the installation is successful.
|
||||
|
||||
|
||||
|
||||
# Release Notes
|
||||
|
||||
For details, see [Release Notes](https://gitee.com/ascend/pytorch/tree/master/docs/en/RELEASENOTE).
|
||||
For details, see [Release Notes](docs/en/RELEASENOTE).
|
||||
|
||||
@@ -1,63 +1,77 @@
|
||||
# AscendPyTorch
|
||||
|
||||
|
||||
# 项目简介
|
||||
本项目开发了PyTorch Adapter插件,用于昇腾适配PyTorch框架,为使用PyTorch框架的开发者提供昇腾AI处理器的超强算力。
|
||||
<h1 id="简介md">简介</h1>
|
||||
本项目开发了PyTorch Adapter插件,用于昇腾适配PyTorch框架,为使用PyTorch框架的开发者提供昇腾AI处理器的超强算力。用户在准备相关环境进行基于PyTorch框架模型的开发、运行时,可以选择在服务器中手动编译安装PyTorch框架相关模块。
|
||||
|
||||
# 编译/执行约束
|
||||
|
||||
gcc版本: 7.3.0(只在编译场景要求)
|
||||
|
||||
cmake版本:3.12.0以上版本(只在编译场景要求)
|
||||
|
||||
python版本:3.7.5 和 3.8.x(编译方法有差别,详见脚本编译章节)
|
||||
<h3 id="前提条件md">前提条件</h3>
|
||||
|
||||
- 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南》。
|
||||
- Python支持版本:3.7.5、3.8。
|
||||
|
||||
# 系统依赖库
|
||||
|
||||
## CentOS & EulerOS
|
||||
|
||||
yum install -y cmake zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas
|
||||
yum install -y patch zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas git dos2unix
|
||||
|
||||
yum install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
## Ubuntu
|
||||
|
||||
apt-get install -y gcc g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 cmake dos2unix libopenblas-dev
|
||||
apt-get install -y patch g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 dos2unix libopenblas-dev git dos2unix
|
||||
|
||||
apt-get install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
|
||||
|
||||
> **说明:**
|
||||
>若安装gcc与cmake依赖命令报错,请参考FAQ使用源码安装。
|
||||
|
||||
|
||||
|
||||
# Ascend配套软件
|
||||
|
||||
| AscendPyTorch版本 | CANN版本 | 支持PyTorch版本 |
|
||||
| :------------ | :----------- | :----------- |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0,1.8.1(仅支持resnet50模型) |
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0,1.8.1(仅支持resnet50模型) |
|
||||
| AscendPyTorch版本 | CANN版本 | 支持PyTorch版本 | Gitee分支名称 |
|
||||
| :------------ | :----------- | :----------- | ------------ |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0.post2 | 2.0.2.tr5 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | 2.0.3.tr5 |
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | 2.0.4.tr5 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5 | v1.5.0-3.0.rc1 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.8.1.rc1 | v1.8.1-3.0.rc1 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.5.0.post6 | v1.5.0-3.0.rc2 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.8.1.rc2 | v1.8.1-3.0.rc2 |
|
||||
| 3.0.rc3 | CANN 6.0.RC1 | 1.5.0.post7 | v1.5.0-3.0.rc3 |
|
||||
| 3.0.rc3 | CANN 6.0.RC1 | 1.8.1.rc3 | v1.8.1-3.0.rc3 |
|
||||
| 3.0.rc3 | CANN 6.0.RC1 | 1.11.0.rc1(beta) | v1.11.0-3.0.rc3 | \ |
|
||||
| 3.0.0 | CANN 6.0.1 | 1.5.0.post8 | v1.5.0-3.0.0 | \ |
|
||||
| 3.0.0 | CANN 6.0.1 | 1.8.1 | v1.8.1-3.0.0 | \ |
|
||||
| 3.0.0 | CANN 6.0.1 | 1.11.0.rc2(beta) | v1.11.0-3.0.0 | \ |
|
||||
|
||||
# 使用方式 --生成全量代码并编译
|
||||
# 安装方式
|
||||
|
||||
## 获取适配昇腾AI处理器的PyTorch源代码patch
|
||||
## 安装PyTorch依赖环境
|
||||
|
||||
获取适配昇腾AI处理器的PyTorch源代码(即当前仓库代码),并切换到所需的分支。
|
||||
|
||||
获取适配昇腾AI处理器的PyTorch源代码(即当前仓库代码)。
|
||||
|
||||
```
|
||||
git clone https://gitee.com/ascend/pytorch.git
|
||||
# 默认是masterf分支,若需要其他分支请使用git checkout 命令切换
|
||||
# git checkout -b 2.0.3.tr5 remotes/origin/2.0.3.tr5
|
||||
git clone -b v1.5.0 https://gitee.com/ascend/pytorch.git
|
||||
```
|
||||
|
||||
## 获取原生PyTorch源代码和third_party代码
|
||||
|
||||
当前支持pytorch 1.5.0和1.8.1的版本。根据需求,在当前仓库根目录pytorch/下获取原生PyTorch的源代码
|
||||
在当前仓库根目录pytorch/下获取原生PyTorch1.5.0的源代码。请关注PyTorch原生社区的安全板块与Issue板块是否有安全相关问题修复,并根据社区修复及时更新原生PyTorch代码。
|
||||
|
||||
```sh
|
||||
// 1.5.0 版本
|
||||
cd pytorch
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
// 1.8.1 版本
|
||||
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
进入到pytorch/pytorch/目录下, 获取PyTorch被动依赖代码(获取时间较长,请耐心等待)。
|
||||
|
||||
```sh
|
||||
cd pytorch
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
@@ -66,13 +80,11 @@ git submodule update --init --recursive
|
||||
|
||||
## 生成适配昇腾AI处理器的PyTorch全量代码。
|
||||
|
||||
进入到pytorch/scripts目录,根据选择的版本执行,执行脚本(注意:下载原生Pytorch源代码和下面版本要对应,否则可能出错)
|
||||
进入到pytorch/scripts目录,根据选择的版本执行,执行脚本(注意:下载原生PyTorch源代码和下面版本要对应,否则可能出错)
|
||||
|
||||
```sh
|
||||
// 默认为1.5.0版本
|
||||
cd ../scripts/
|
||||
bash gen.sh
|
||||
// 对于1.8.1版本,则通过-v 参数指定
|
||||
bash gen.sh -v 1.8.1
|
||||
```
|
||||
|
||||
会在pytorch/pytorch/目录中生成npu适配全量代码
|
||||
@@ -83,13 +95,14 @@ bash gen.sh -v 1.8.1
|
||||
进入到pytorch/pytorch/目录,依赖库安装:
|
||||
|
||||
```python3
|
||||
cd ../pytorch
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
|
||||
## 编译torch的二进制包
|
||||
|
||||
进入到pytorch/pytorch/目录,执行
|
||||
在pytorch/pytorch/目录,执行
|
||||
|
||||
```sh
|
||||
# python3.7版本
|
||||
@@ -103,15 +116,14 @@ bash build.sh --python=3.8
|
||||
|
||||
生成的二进制包在pytorch/pytorch/dist/目录下
|
||||
|
||||
# 安装
|
||||
|
||||
### (以1.5.0版本为例,1.8.1版本同理)
|
||||
## 安装pytorch
|
||||
|
||||
**x86_64:**
|
||||
|
||||
torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
|
||||
```
|
||||
@@ -122,6 +134,7 @@ pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
|
||||
torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_aarch64.whl)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
@@ -131,43 +144,75 @@ pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
|
||||
|
||||
## 运行环境变量
|
||||
|
||||
在当前仓库根目录中执行设置环境变量脚本
|
||||
在pytorch/pytorch/中执行设置环境变量脚本
|
||||
|
||||
```
|
||||
source pytorch/env.sh
|
||||
cd ../
|
||||
source env.sh
|
||||
```
|
||||
|
||||
|
||||
## 自定义环境变量
|
||||
|
||||
以下环境变量为NPU场景下使用的功能类或可以提升性能的环境变量:
|
||||
|
||||
```
|
||||
export TASK_QUEUE_ENABLE=1 # 使用异步任务下发,异步调用acl接口,建议默认开启,开启设置为1
|
||||
export PTCOPY_ENABLE=1 # 使用PTCopy算子模式,加速转连续及copy等过程,建议默认开启,开启设置为1
|
||||
```
|
||||
|
||||
可选的环境变量可能会对运行的模型产生影响:
|
||||
|
||||
```
|
||||
export DYNAMIC_COMPILE_ENABLE=1 # 动态shape特性功能,针对shape变化场景,可选,开启设置为1
|
||||
export COMBINED_ENABLE=1 # 非连续两个算子组合类场景优化,可选,开启设置为1
|
||||
export TRI_COMBINED_ENABLE=1 # 非连续三个算子组合类场景优化,可选,开启设置为1
|
||||
|
||||
export COMBINED_ENABLE=1 # 非连续转连续二级推导优化,可选,开启设置为1。当模型中有大量AsStrided高耗时算子被调用时,可以尝试开启此优化以获得潜在的device执行效率的提升
|
||||
export ACL_DUMP_DATA=1 # 算子数据dump功能,调试时使用,可选,开启设置为1
|
||||
export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下有不同的性能表现。可选
|
||||
export TASK_QUEUE_ENABLE=1 # 使用异步任务下发,异步调用acl接口,建议默认开启,开启设置为1
|
||||
|
||||
```
|
||||
当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。
|
||||
|
||||
```
|
||||
# unset GOMP_CPU_AFFINITY
|
||||
```
|
||||
**表 1** 环境变量说明
|
||||
|
||||
<a name="zh-cn_topic_0000001152616261_table42017516135"></a>
|
||||
<table><thead align="left"><tr id="zh-cn_topic_0000001152616261_row16198951191317"><th class="cellrowborder" valign="top" width="55.48%" id="mcps1.2.3.1.1"><p id="zh-cn_topic_0000001152616261_p51981251161315"><a name="zh-cn_topic_0000001152616261_p51981251161315"></a><a name="zh-cn_topic_0000001152616261_p51981251161315"></a>配置项</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="44.519999999999996%" id="mcps1.2.3.1.2"><p id="zh-cn_topic_0000001152616261_p9198135114133"><a name="zh-cn_topic_0000001152616261_p9198135114133"></a><a name="zh-cn_topic_0000001152616261_p9198135114133"></a>说明</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(可选)非连续转连续二级推导优化,可选,开启设置为1。当模型中有大量AsStrided高耗时算子被调用时,可以尝试开启此优化以获得潜在的device执行效率的提升。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(可选)算子数据dump功能,调试时使用,开启设置为1。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16711563237"><a name="zh-cn_topic_0000001152616261_p16711563237"></a><a name="zh-cn_topic_0000001152616261_p16711563237"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p0711356152317"><a name="zh-cn_topic_0000001152616261_p0711356152317"></a><a name="zh-cn_topic_0000001152616261_p0711356152317"></a>(可选)使用异步任务下发,异步调用acl接口,建议默认开启,开启设置为1。 </p>
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
## 执行单元测试脚本
|
||||
|
||||
验证运行, 输出结果OK
|
||||
|
||||
|
||||
```shell
|
||||
// 根据前述版本,选择对应的测试脚本,以下为1.5.0版本
|
||||
python3 pytorch1.5.0/test/test_npu/test_div.py
|
||||
// 以下为1.8.1版本
|
||||
python3 pytorch1.8.1/test/test_npu/test_div.py
|
||||
cd ../
|
||||
python3 pytorch1.5.0/test/test_npu/test_network_ops/test_div.py
|
||||
```
|
||||
# 安装混合精度模块(可选)
|
||||
|
||||
请用户根据以下功能需要选择使用,若需要安装Apex模块请参考相关[README文档](https://gitee.com/ascend/apex/tree/v1.5.0)进行编译安装Apex模块。
|
||||
|
||||
- APEX
|
||||
- O1配置模式:Conv,Matmul等使用float16精度计算,其他如softmax、BN使用float32精度。
|
||||
- O2配置模式:除BN使用float32精度外,其他部分使用float16精度。
|
||||
- 静态loss scale:静态设置参数确保混合精度训练收敛。
|
||||
- 动态loss scale:动态计算loss scale的值并判断是否溢出。
|
||||
|
||||
# 文档
|
||||
|
||||
@@ -193,60 +238,261 @@ Ascend PyTorch的版本分支有以下几种维护阶段:
|
||||
|
||||
| **分支名** | **当前状态** | **上线时间** | **后续状态** | **EOL 日期**|
|
||||
|------------|--------------|----------------------|----------------------------------------|------------|
|
||||
| **v2.0.2** | Maintained | 2021-07-29 | Unmaintained <br> 2022-07-29 estimated | |
|
||||
| **v2.0.3** | Maintained | 2021-10-15 | Unmaintained <br> 2022-10-15 estimated | |
|
||||
| **v2.0.4** | Maintained | 2022-01-15 | Unmaintained <br> 2023-01-15 estimated | |
|
||||
| **v2.0.2** | EOL | 2021-07-29 | N/A | |
|
||||
| **v2.0.3** | EOL | 2021-10-15 | N/A | |
|
||||
| **v2.0.4** | Unmaintained | 2022-01-15 | EOL <br> 2023-04-15 estimated | |
|
||||
| **v3.0.rc1** | Maintained | 2022-04-10 | Unmaintained <br> 2023-04-10 estimated | |
|
||||
| **v3.0.rc2** | Maintained | 2022-07-15 | Unmaintained <br> 2023-07-15 estimated | |
|
||||
| **v3.0.rc3** | Maintained | 2022-10-20 | Unmaintained <br> 2023-10-20 estimated | |
|
||||
| **v3.0.0** | Maintained | 2023-1-20 | Unmaintained <br> 2024-1-20 estimated | |
|
||||
|
||||
|
||||
# FAQ
|
||||
|
||||
## 在PIP设置为华为源时,安装requirments.txt中的typing依赖后,会导致python环境错误。
|
||||
|
||||
在PIP设置为华为源时,需打开requirments.txt文件,删除typing依赖,再执行命令。
|
||||
|
||||
```
|
||||
pip3 install -r requirments.txt
|
||||
```
|
||||
|
||||
|
||||
|
||||
## import torch 报找不到libhccl.so错误
|
||||
|
||||
未配置环境变量,需通过env.sh脚本配置
|
||||
|
||||
```
|
||||
source pytorch/pytorch1.5.0/src/env.sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 编译过程执行bash build.sh报错FAILED:confu-deps/XNNPACK/CMakefiles/XNNPACK.dir/src/f32-gemm/gen-inc/4x8inc-minmax-{arch}-neonfma-cortex-a{xx}.S.o
|
||||
|
||||
编译前,环境变量默认USE_XNNPACK=1,编译时会报错,需设置重设该环境变量,再次编译。
|
||||
|
||||
1. 重设环境变量
|
||||
|
||||
```
|
||||
export USE_XNNPACK=0
|
||||
```
|
||||
|
||||
2. 清除编译缓存
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
3. 重新编译
|
||||
|
||||
```
|
||||
bash build.sh --python={python_version}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 编译过程执行bash build.sh报错no module named yaml/typing_extensions.
|
||||
|
||||
pytorch编译依赖 yaml库和typing_extensions库,需要手动安装。
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
pip3 install typing_extensions
|
||||
```
|
||||
|
||||
安装成功后,注意需要执行make clean在执行bash build.sh进行编译,否则可能因缓存出现未知编译错误。
|
||||
|
||||
|
||||
|
||||
## 运行遇到找不到te问题
|
||||
|
||||
开发态:
|
||||
|
||||
cd /urs/local/ascend-toolkit/latest/fwkacllib/lib64
|
||||
|
||||
用户态:
|
||||
|
||||
cd /urs/local/nnae/latest/fwkacllib/lib64
|
||||
```
|
||||
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64 #{arch}为架构名称。
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
用户态:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64 #{arch}为架构名称
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 编译cmake报错版本过低
|
||||
## 命令行安装cmake依赖时提示找不到包、编译cmake报错版本过低,可使用安装脚本或源码编译安装。
|
||||
|
||||
cmake官网下载linux版本安装(当前3.18.0)
|
||||
方法一:下载安装脚本安装cmake。(参考cmake官网)
|
||||
|
||||
1. 使用yum命令安装: yum install -y cmake==3.18.0
|
||||
X86_64环境脚本安装:cmake-3.12.0-Linux-x86_64.sh
|
||||
|
||||
2. 下载cmake sh脚本安装:(参考cmake官网)
|
||||
aarch64环境脚本安装:cmake-3.12.0-Linux-aarch64.sh
|
||||
|
||||
X86_64环境推荐脚本安装: cmake-3.18.2-Linux-x86_64.sh
|
||||
1. 执行命令。
|
||||
|
||||
|
||||
```
|
||||
./cmake-3.12.0-Linux-{arch}.sh #{arch}为架构名称
|
||||
```
|
||||
|
||||
## GCC版本问题切换问题
|
||||
2. 设置软连接。
|
||||
|
||||
目前存在测试环境从GCC4.8.5 切换到 GCC7.3.0。这个过程容易出现错误导致pytorch编译不过,以下是需要软连接的库
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
gcc, g++,c++(--version 必须是7.3.0)
|
||||
3. 执行如下命令验证是否安装成功。
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
如显示“cmake version 3.12.0”则表示安装成功。
|
||||
|
||||
|
||||
方法二:使用源码编译安装。
|
||||
|
||||
1. 获取Cmake软件包。
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
|
||||
```
|
||||
|
||||
2. 解压并进入软件包目录。
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.0.tar.gz
|
||||
cd cmake-3.12.0/
|
||||
```
|
||||
|
||||
3. 执行配置、编译和安装命令。
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
4. 设置软连接。
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
5. 执行如下命令验证是否安装成功。
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
如显示“cmake version 3.12.0”则表示安装成功。
|
||||
|
||||
|
||||
|
||||
## 命令行安装gcc依赖时提示找不到包、编译时gcc报错问题
|
||||
|
||||
部分源下载gcc时会提示无法找到包,需要使用源码编译安装。
|
||||
|
||||
以下步骤请在root用户下执行。
|
||||
|
||||
1. 下载gcc-7.3.0.tar.gz,下载地址为[https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz)。
|
||||
|
||||
2. 安装gcc时候会占用大量临时空间,所以先执行下面的命令清空/tmp目录:
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
3. 安装依赖(以CentOS和Ubuntu系统为例)。
|
||||
|
||||
- CentOS执行如下命令安装。
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
- Ubuntu执行如下命令安装。
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
4. 编译安装gcc。
|
||||
|
||||
1. 进入gcc-7.3.0.tar.gz源码包所在目录,解压源码包,命令为:
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
|
||||
2. 进入解压后的文件夹,执行如下命令下载gcc依赖包:
|
||||
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
如果执行上述命令报错,需要执行如下命令在“gcc-7.3.0/“文件夹下下载依赖包:
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
下载好上述依赖包后,重新执行以下命令:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
如果命令校验失败,需要确认上述依赖包在文件夹中的唯一性,无重复下载,若存在重复的依赖包,需删除。
|
||||
|
||||
3. <a name="zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310"></a>执行配置、编译和安装命令:
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # 通过grep -w processor /proc/cpuinfo|wc -l查看cpu数,示例为15,用户可自行设置相应参数。
|
||||
make install
|
||||
```
|
||||
|
||||
>  **须知:**
|
||||
>其中“--prefix“参数用于指定linux_gcc7.3.0安装路径,用户可自行配置,但注意不要配置为“/usr/local“及“/usr“,因为会与系统使用软件源默认安装的gcc相冲突,导致系统原始gcc编译环境被破坏。示例指定为“/usr/local/linux_gcc7.3.0“。
|
||||
|
||||
4. 修改软连接。
|
||||
|
||||
```
|
||||
ln -s ${install_path}/gcc-7.3.0/bin/gcc /usr/bin/gcc
|
||||
ln -s ${install_path}/gcc-7.3.0/bin/g++ /usr/bin/g++
|
||||
ln -s ${install_path}/gcc-7.3.0/bin/c++ /usr/bin/c++
|
||||
```
|
||||
|
||||
5.配置环境变量。
|
||||
|
||||
当用户执行训练时,需要用到gcc升级后的编译环境,因此要在训练脚本中配置环境变量,通过如下命令配置。
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
其中$\{install\_path\}为[3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310)中配置的gcc7.3.0安装路径,本示例为“/usr/local/gcc7.3.0/“。
|
||||
|
||||
> **说明:**
|
||||
>本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。
|
||||
|
||||
若存在pytorch编译不过,请检查软连接的库是否正确。
|
||||
|
||||
libstdc++->libstdc++.so.6.0.24(7.3.0)
|
||||
|
||||
|
||||
|
||||
## 找不到libblas.so问题
|
||||
|
||||
环境缺少openblas库,需要安装openblas库
|
||||
@@ -263,6 +509,28 @@ Ubuntu环境
|
||||
apt install libopenblas-dev
|
||||
```
|
||||
|
||||
|
||||
|
||||
## ARM环境pip安装torchvision失败
|
||||
|
||||
可采用源码安装(需先安装昇腾pytorch并通过env.sh配置环境变量)
|
||||
|
||||
```
|
||||
git clone -b v0.6.0 https://github.com/pytorch/vision.git
|
||||
cd vision
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
验证torchvision是否安装成功
|
||||
|
||||
```
|
||||
python -c "import torchvision"
|
||||
```
|
||||
|
||||
若不报错,则说明安装成功
|
||||
|
||||
|
||||
|
||||
# 版本说明
|
||||
|
||||
版本说明请参阅[ReleseNote](docs/zh/RELEASENOTE)
|
||||
@@ -709,12 +709,12 @@ The training can be started manually or using the shell script.
|
||||
3. Open the **/etc/hosts** file on each server and add the corresponding IP address and host name of the server to the first line of the file. If the file already contains the IP address and host name, skip this step. The following is an example of the content to be added:
|
||||
|
||||
```
|
||||
10.90.140.199 ubuntu
|
||||
xxx.xxx.xxx.111 ubuntu
|
||||
```
|
||||
|
||||
In the preceding content, **10.90.140.199** is the IP address of the server, and **ubuntu** is the host name.
|
||||
In the preceding content, **xxx.xxx.xxx.111** is the IP address of the server, and **ubuntu** is the host name.
|
||||
|
||||
4. Run the following commands on the first server to generate a public key (Assume that the IP address of the first server is **10.90.140.199**.):
|
||||
4. Run the following commands on the first server to generate a public key (Assume that the IP address of the first server is **xxx.xxx.xxx.111**.):
|
||||
|
||||
```
|
||||
cd ~/.ssh/ # If the directory does not exist, run the ssh localhost command first.
|
||||
@@ -742,7 +742,7 @@ The training can be started manually or using the shell script.
|
||||
6. Run the following commands on each of the other servers to copy the public key of the first server to each of the other servers:
|
||||
|
||||
cd ~/.ssh/
|
||||
scp root@10.90.140.199:~/.ssh/authorized_keys ./
|
||||
scp root@xxx.xxx.xxx.111:~/.ssh/authorized_keys ./
|
||||
|
||||
7. Run the following command on each server to test password-free login:
|
||||
|
||||
@@ -750,7 +750,7 @@ The training can be started manually or using the shell script.
|
||||
ssh User name@IP address
|
||||
```
|
||||
|
||||
For example, run the **ssh root@10.90.140.231** command to log in to the server whose IP address is 10.90.140.231 from the first server whose IP address is 10.90.140.199 without a password.
|
||||
For example, run the **ssh root@xxx.xxx.xxx.222** command to log in to the server whose IP address is xxx.xxx.xxx.222 from the first server whose IP address is xxx.xxx.xxx.111 without a password.
|
||||
|
||||
If information similar to the following is displayed, the login without a password is successful.
|
||||
|
||||
@@ -770,7 +770,7 @@ The training can be started manually or using the shell script.
|
||||
|
||||
```
|
||||
logout
|
||||
Connection to 10.90.140.231 closed.
|
||||
Connection to xxx.xxx.xxx.222 closed.
|
||||
```
|
||||
3. Use Open MPI to start model training.
|
||||
|
||||
@@ -838,7 +838,7 @@ if [ -d ${install_path}/toolkit ]; then
|
||||
export ASCEND_OPP_PATH=${install_path}/opp
|
||||
else
|
||||
if [ -d ${install_path}/nnae/latest ];then
|
||||
exportLD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH
|
||||
export LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH
|
||||
export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/
|
||||
export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/
|
||||
export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so
|
||||
|
||||
|
Before Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 406 B |
|
Before Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 580 B |
@@ -1,561 +1,486 @@
|
||||
# PyTorch Installation Guide
|
||||
- [Overview](#overviewmd)
|
||||
- [Manual Build and Installation](#manual-build-and-installationmd)
|
||||
- [Prerequisites](#prerequisitesmd)
|
||||
- [Installing the PyTorch Framework](#installing-the-pytorch-frameworkmd)
|
||||
- [Configuring Environment Variables](#configuring-environment-variablesmd)
|
||||
- [Installing the Mixed Precision Module](#installing-the-mixed-precision-modulemd)
|
||||
- [References](#referencesmd)
|
||||
- [Installing CMake](#installing-cmakemd)
|
||||
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md)
|
||||
- [What to Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-to-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)
|
||||
<h2 id="overviewmd">Overview</h2>
|
||||
- [Overview](#overview)
|
||||
|
||||
When setting up the environment for PyTorch model development and running, you can manually build and install the modules adapted to the PyTorch framework on a server.
|
||||
- [System Dependencies](#system-dependencies)
|
||||
|
||||
**Figure 1** Environment setup process<a name="en-us_topic_0000001119176876_fig1938918396117"></a>
|
||||
- [Ascend Auxiliary Software](#ascend-auxiliary-software)
|
||||
|
||||
- [Installation Methods](#installation-methods)
|
||||
|
||||

|
||||
- [Running] (#running)
|
||||
|
||||
<h2 id="manual-build-and-installationmd">Manual Build and Installation</h2>
|
||||
- [(Optional) Installing the Mixed Precision Module](#optional-installing-the-mixed-precision-module)
|
||||
|
||||
- **[Prerequisites](#prerequisitesmd)**
|
||||
- [FAQ](#faq)
|
||||
|
||||
- **[Installing the PyTorch Framework](#installing-the-pytorch-frameworkmd)**
|
||||
- [Release Notes](#release-notes)
|
||||
|
||||
- **[Configuring Environment Variables](#configuring-environment-variablesmd)**
|
||||
|
||||
|
||||
- **[Installing the Mixed Precision Module](#installing-the-mixed-precision-modulemd)**
|
||||
# Overview<a name="Overview"></a>
|
||||
|
||||
This project develops the PyTorch Adapter plugin to adapt Ascend to the PyTorch framework so that developers who use the PyTorch framework can obtain powerful compute capabilities of Ascend AI Processors. When setting up the environment for model development and running under PyTorch, you can manually build and install modules adapted to the PyTorch framework on a server.
|
||||
|
||||
<h3 id="prerequisitesmd">Prerequisites</h3>
|
||||
## Prerequisites
|
||||
|
||||
#### Prerequisites<a name="en-us_topic_0000001105856382_en-us_topic_0275872734_section108914373254"></a>
|
||||
- The development or operating environment of CANN has been installed. For details, see the *CANN Software Installation Guide*.
|
||||
- Python version: 3.7.5 or 3.8
|
||||
|
||||
- The development or operating environment of CANN has been installed. For details, see the _CANN Software Installation Guide_.
|
||||
- CMake 3.12.0 or later has been installed. For details about how to install CMake, see [Installing CMake](#installing-cmakemd).
|
||||
- GCC 7.3.0 or later has been installed. For details about how to install and use GCC 7.3.0, see [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md).
|
||||
- Python 3.7.5, 3.8, or 3.9 has been installed.
|
||||
- Note that PyTorch 1.5 does not support Python 3.9 build and installation. Only Torch 1.8.1 supports Python 3.9 build and installation.
|
||||
- The Patch and Git tools have been installed in the environment. To install the tools for Ubuntu and CentOS, run the following commands:
|
||||
- Ubuntu
|
||||
# System Dependencies<a name="System Dependencies"></a>
|
||||
|
||||
```
|
||||
apt-get install patch
|
||||
apt-get install git
|
||||
```
|
||||
## CentOS & EulerOS
|
||||
|
||||
- CentOS
|
||||
yum install -y patch zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas git dos2unix
|
||||
|
||||
```
|
||||
yum install patch
|
||||
yum install git
|
||||
```
|
||||
yum install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
## Ubuntu
|
||||
|
||||
apt-get install -y patch g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 dos2unix libopenblas-dev git dos2unix
|
||||
|
||||
apt-get install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
|
||||
|
||||
<h3 id="installing-the-pytorch-frameworkmd">Installing the PyTorch Framework</h3>
|
||||
|
||||
#### Installation Process<a name="en-us_topic_0000001152776301_section1611810384557"></a>
|
||||
|
||||
1. Log in to the server as the **root** user or a non-root user.
|
||||
2. Run the following commands in sequence to install the PyTorch dependencies.
|
||||
|
||||
If you install Python and its dependencies as a non-root user, add **--user** at the end of each command in this step. Example command: **pip3.7 install pyyaml --user**.
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
pip3 install wheel
|
||||
```
|
||||
|
||||
3. Obtain the PyTorch source code.
|
||||
|
||||
1. Run the following command to obtain the PyTorch source code adapted to Ascend AI Processors and switch to the required branch:
|
||||
|
||||
```
|
||||
git clone https://gitee.com/ascend/pytorch.git
|
||||
# By default, the masterf branch is used. If other branches are required, run the git checkout command to switch to that branch.
|
||||
# git checkout -b 2.0.3.tr5 remotes/origin/2.0.3.tr5
|
||||
|
||||
```
|
||||
|
||||
The directory structure of the downloaded source code is as follows:
|
||||
|
||||
```
|
||||
├── patch # Directory of the patch adapted to Ascend AI Processors
|
||||
│ ├── pytorch1.5.0_npu.patch # Patch for PyTorch 1.5.0
|
||||
│ └── pytorch1.8.1_npu.patch # Patch for PyTorch 1.8.1
|
||||
├── pytorch1.5.0 # Source code and test directory for PyTorch 1.5.0
|
||||
│ ├── access_control_test.py
|
||||
│ ├── src # Source code directory
|
||||
│ └── test # Directory for storing test cases
|
||||
├── pytorch1.8.1 # Source code and test directory for PyTorch 1.8.1
|
||||
│ ├── access_control_test.py
|
||||
│ ├── src # Source code directory
|
||||
│ └── test # Directory for storing test cases
|
||||
└── scripts # Build and create a directory.
|
||||
```
|
||||
|
||||
2. Obtain the native PyTorch source code from the root directory **/pytorch** of the current repository.
|
||||
- If PyTorch 1.5.0 is installed, run the following command:
|
||||
|
||||
```
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
- If PyTorch 1.8.1 is installed, run the following command:
|
||||
|
||||
```
|
||||
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
3. Go to the native PyTorch code directory **pytorch** and obtain the PyTorch passive dependency code.
|
||||
|
||||
```
|
||||
cd pytorch
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
> **NOTE:**
|
||||
>Due to network fluctuation, it may take a long time to obtain the source code. If no error is reported after the download is complete, the PyTorch and third-party code on which PyTorch depends are generated.
|
||||
|
||||
4. Generate the PyTorch installation package adapted to Ascend AI Processors.
|
||||
1. Go to the **pytorch/scripts** directory and run the conversion script to generate full code adapted to Ascend AI Processors.
|
||||
|
||||
```
|
||||
cd ../scripts
|
||||
# If PyTorch 1.5.0 is installed:
|
||||
bash gen.sh
|
||||
# If PyTorch 1.8.1 is installed:
|
||||
bash gen.sh -v 1.8.1
|
||||
```
|
||||
|
||||
The full code adapted to Ascend AI Processors is generated in the **pytorch/pytorch** directory.
|
||||
|
||||
2. Go to the **pytorch/pytorch/** directory and install the dependency library.
|
||||
|
||||
```
|
||||
cd ../pytorch
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Build and generate the binary installation package of PyTorch.
|
||||
|
||||
```
|
||||
bash build.sh --python=3.7
|
||||
or
|
||||
bash build.sh --python=3.8
|
||||
or
|
||||
bash build.sh --python=3.9 # PyTorch 1.5 does not support build and installation using Python 3.9.
|
||||
|
||||
```
|
||||
|
||||
Specify the Python version in the environment for build. The generated binary package is stored in the current dist directory **pytorch/pytorch/dist**.
|
||||
|
||||
5. <a name="en-us_topic_0000001152776301_li49671667141"></a>Install PyTorch.
|
||||
|
||||
Go to the **pytorch/pytorch/dist** directory and run the following command to install PyTorch:
|
||||
|
||||
```
|
||||
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
|
||||
_\{**arch\}**_ indicates the architecture information. The value can be **aarch64** or **x86\_64**.
|
||||
|
||||
> **NOTE:**
|
||||
>To upgrade PyTorch in the environment, uninstall the PyTorch software package installed in the environment and then perform [Step 5 Install PyTorch](#en-us_topic_0000001152776301_li49671667141). Run the following command to check whether PyTorch has been installed:
|
||||
>**pip3 list | grep torch**
|
||||
> **NOTE:**
|
||||
>If an error occurs during the installation of the GCC and CMake dependency commands, use the source code for installation. For details, see the FAQ.
|
||||
|
||||
|
||||
<h3 id="configuring-environment-variablesmd">Configuring Environment Variables</h3>
|
||||
# Ascend Auxiliary Software<a name="Ascend Auxiliary Software"></a>
|
||||
|
||||
After the software packages are installed, configure environment variables to use Ascend PyTorch. For details about the environment variables, see [Table 1](#en-us_topic_0000001152616261_table42017516135).
|
||||
| AscendPyTorch Version| CANN Version| Supported PyTorch Version| Gitee Branch|
|
||||
| :------------ | :----------- | :----------- | ------------ |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0.post2 | 2.0.2.tr5 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | 2.0.3.tr5 |
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | 2.0.4.tr5 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5 | v1.5.0-3.0.rc1 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.8.1.rc1 | v1.8.1-3.0.rc1 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.5.0.post6 | v1.5.0-3.0.rc2 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.8.1.rc2 | v1.8.1-3.0.rc2 |
|
||||
|
||||
1. Configure the operating environment variables by running the following command in the **root** directory of the PyTorch source code adapted to Ascend AI Processors:
|
||||
# Installation Methods<a name="Installation Methods"></a>
|
||||
|
||||
```
|
||||
source pytorch/env.sh
|
||||
```
|
||||
## Installing the PyTorch Environment Dependencies
|
||||
|
||||
2. Select a proper HCCL initialization mode based on the actual scenario and configure the corresponding environment variables.
|
||||
|
||||
```
|
||||
# Scenario 1: Single-node scenario
|
||||
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
|
||||
# Scenario 2: Multi-node scenario
|
||||
export HCCL_WHITELIST_DISABLE=1 # Disable the HCCL trustlist.
|
||||
export HCCL_IF_IP="1.1.1.1" # Replace 1.1.1.1 with the actual NIC IP address of the host. Ensure that the NIC IP addresses in use can communicate with each other in the cluster.
|
||||
```
|
||||
Obtain the PyTorch source code (from the current repository) that adapts to Ascend AI Processors.
|
||||
|
||||
3. \(Optional\) Configure function or performance environment variables in the NPU scenario. The variables are disabled by default.
|
||||
```
|
||||
git clone -b v1.5.0-3.0.rc2 https://gitee.com/ascend/pytorch.git
|
||||
```
|
||||
|
||||
```
|
||||
export DYNAMIC_COMPILE_ENABLE=1 # (Optional) Dynamic shape feature, which is used when the shape changes. To enable this function, set the value to 1. (PyTorch 1.8.1 does not support this environment variable.)
|
||||
export COMBINED_ENABLE=1 # (Optional) Optimizes the scenario where two inconsecutive operators are combined. To enable this function, set the value to 1.
|
||||
export TRI_COMBINED_ENABLE=1 # (Optional) Optimizes the scenario where three inconsecutive operators are combined. To enable this function, set the value to 1.
|
||||
export ACL_DUMP_DATA=1 # (Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to 1.
|
||||
export DYNAMIC_OP="ADD#MUL" # (Optional) Operator implementation. The performance of the ADD and MUL operators varies depending on the scenarios.
|
||||
```
|
||||
## Obtaining the Native PyTorch Source Code and Third-Party Code
|
||||
|
||||
4. \(Optional\) If the system is openEuler or its inherited OS, such as UOS, run the following command to cancel CPU core binding.
|
||||
Obtain the native PyTorch 1.5.0 source code from the root directory **/pytorch** of the current repository. Check whether there are fixed security-related issues in the Security and Issues categories in the PyTorch native repository. Update the native PyTorch code if there are any fixes.
|
||||
|
||||
```sh
|
||||
cd pytorch
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
Go to the **pytorch/pytorch/** directory and obtain the passive dependency code of PyTorch. It takes a long time to obtain the code.
|
||||
|
||||
```sh
|
||||
cd pytorch
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
If no error is reported, the PyTorch and third-party code on which PyTorch depends is generated.
|
||||
|
||||
## Generating Full PyTorch Code That Adapts to Ascend AI Processors
|
||||
|
||||
Go to the **pytorch/scripts** directory and run the script of the selected version. (Note: The downloaded native PyTorch source code must match the following version. Otherwise, an error may occur.)
|
||||
|
||||
```sh
|
||||
cd ../scripts/
|
||||
bash gen.sh
|
||||
```
|
||||
|
||||
The full code adapted to the NPU is generated in the **pytorch/pytorch/** directory.
|
||||
|
||||
|
||||
## Installing the Python Dependency Library
|
||||
|
||||
Go to the **pytorch/pytorch/** directory and install the Python dependency library.
|
||||
|
||||
```python3
|
||||
cd ../pytorch
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
|
||||
## Compiling Torch Binary Package
|
||||
|
||||
In the **pytorch/pytorch/** directory, run the following command:
|
||||
|
||||
```sh
|
||||
# Python 3.7
|
||||
bash build.sh
|
||||
or
|
||||
bash build.sh --python=3.7 (recommended)
|
||||
|
||||
# Python 3.8
|
||||
bash build.sh --python=3.8
|
||||
```
|
||||
|
||||
The generated binary package is in the **pytorch/pytorch/dist/** directory.
|
||||
|
||||
## Installing PyTorch
|
||||
|
||||
**x86_64:**
|
||||
|
||||
**torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl** (The actual name may contain the minor version number, for example, **torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl**.)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
|
||||
```
|
||||
|
||||
|
||||
**arm:**
|
||||
|
||||
**torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl** (The actual name may contain the minor version number, for example, **torch-1.5.0.post2+ascend-cp37-cp37m-linux_aarch64.whl**.)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
|
||||
|
||||
# Running<a name="Running"></a>
|
||||
|
||||
## Executing Environment Variables
|
||||
|
||||
Run the script for setting environment variables in the **pytorch/pytorch/** directory.
|
||||
|
||||
```
|
||||
cd ../
|
||||
source env.sh
|
||||
```
|
||||
|
||||
|
||||
The following are optional environment variables that may affect running models:
|
||||
|
||||
```
|
||||
|
||||
export COMBINED_ENABLE=1 # (Optional) Discontinuous-to-continuous level-2 derivation optimization. To enable this function, set the value to **1**. When a large number of time-consuming AsStrided operators are called in the model, you can enable this function to improve the device execution efficiency.
|
||||
export ACL_DUMP_DATA=1 # (Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to **1**.
|
||||
export TASK_QUEUE_ENABLE=1 # Delivered by an asynchronous task to asynchronously call the ACL interface. You are advised to enable this environment variable and set its value to **1**.
|
||||
|
||||
```
|
||||
If the system is openEuler or its inherited OS, such as UOS, run the following command to cancel CPU core binding.
|
||||
|
||||
```
|
||||
# unset GOMP_CPU_AFFINITY
|
||||
```
|
||||
**Table 1** Description of environment variables
|
||||
|
||||
|
||||
**Table 1** Description of environment variables
|
||||
|
||||
<a name="en-us_topic_0000001152616261_table42017516135"></a>
|
||||
<table><thead align="left"><tr id="en-us_topic_0000001152616261_row16198951191317"><th class="cellrowborder" valign="top" width="55.48%" id="mcps1.2.3.1.1"><p id="en-us_topic_0000001152616261_p51981251161315"><a name="en-us_topic_0000001152616261_p51981251161315"></a><a name="en-us_topic_0000001152616261_p51981251161315"></a>Environment Variable</p>
|
||||
<a name="zh-cn_topic_0000001152616261_table42017516135"></a>
|
||||
<table><thead align="left"><tr id="zh-cn_topic_0000001152616261_row16198951191317"><th class="cellrowborder" valign="top" width="55.48%" id="mcps1.2.3.1.1"><p id="zh-cn_topic_0000001152616261_p51981251161315"><a name="zh-cn_topic_0000001152616261_p51981251161315"></a><a name="zh-cn_topic_0000001152616261_p51981251161315"></a>Environment Variable</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="44.519999999999996%" id="mcps1.2.3.1.2"><p id="en-us_topic_0000001152616261_p9198135114133"><a name="en-us_topic_0000001152616261_p9198135114133"></a><a name="en-us_topic_0000001152616261_p9198135114133"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="en-us_topic_0000001152616261_row6882121917329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p688241953218"><a name="en-us_topic_0000001152616261_p688241953218"></a><a name="en-us_topic_0000001152616261_p688241953218"></a>LD_LIBRARY_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p1888291915322"><a name="en-us_topic_0000001152616261_p1888291915322"></a><a name="en-us_topic_0000001152616261_p1888291915322"></a>Dynamic library search path. Set this variable based on the preceding example.</p>
|
||||
<p id="p1292181892120"><a name="p1292181892120"></a><a name="p1292181892120"></a>If you need to upgrade GCC in OSs such as CentOS, Debian, and BC-Linux, add <strong id="b6163826603"><a name="b6163826603"></a><a name="b6163826603"></a><em id="i161631926505"><a name="i161631926505"></a><a name="i161631926505"></a>${install_path}</em>/lib64</strong> to the <span class="parmname" id="parmname161637265015"><a name="parmname161637265015"></a><a name="parmname161637265015"></a><b>LD_LIBRARY_PATH</b></span> variable of the dynamic library search path. Replace <em id="i01649261704"><a name="i01649261704"></a><a name="i01649261704"></a><strong id="b1216317261109"><a name="b1216317261109"></a><a name="b1216317261109"></a>{install_path}</strong></em> with the GCC installation path. For details, see <a href="#how-do-i-install-gcc-7-3-0md#en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li9745165315131">5</a>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row16194175523010"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p16195185523019"><a name="en-us_topic_0000001152616261_p16195185523019"></a><a name="en-us_topic_0000001152616261_p16195185523019"></a>PYTHONPATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p19637083322"><a name="en-us_topic_0000001152616261_p19637083322"></a><a name="en-us_topic_0000001152616261_p19637083322"></a>Python search path. Set this variable based on the preceding example.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row2954102119329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p195452113218"><a name="en-us_topic_0000001152616261_p195452113218"></a><a name="en-us_topic_0000001152616261_p195452113218"></a>PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p964914893211"><a name="en-us_topic_0000001152616261_p964914893211"></a><a name="en-us_topic_0000001152616261_p964914893211"></a>Executable program search path. Set this variable based on the preceding example.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row58592816294"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p1886016892913"><a name="en-us_topic_0000001152616261_p1886016892913"></a><a name="en-us_topic_0000001152616261_p1886016892913"></a>ASCEND_OPP_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p28608892915"><a name="en-us_topic_0000001152616261_p28608892915"></a><a name="en-us_topic_0000001152616261_p28608892915"></a>Operator package (OPP) root directory. Set this variable based on the preceding example.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row144592037903"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p104601373014"><a name="en-us_topic_0000001152616261_p104601373014"></a><a name="en-us_topic_0000001152616261_p104601373014"></a>OPTION_EXEC_EXTERN_PLUGIN_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p1046013716017"><a name="en-us_topic_0000001152616261_p1046013716017"></a><a name="en-us_topic_0000001152616261_p1046013716017"></a>Path of the operator information library.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row16184379493"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p131851873492"><a name="en-us_topic_0000001152616261_p131851873492"></a><a name="en-us_topic_0000001152616261_p131851873492"></a>ASCEND_AICPU_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p181851575497"><a name="en-us_topic_0000001152616261_p181851575497"></a><a name="en-us_topic_0000001152616261_p181851575497"></a>Path of the AI CPU operator package.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row234714854615"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p2034724894619"><a name="en-us_topic_0000001152616261_p2034724894619"></a><a name="en-us_topic_0000001152616261_p2034724894619"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p53477489462"><a name="en-us_topic_0000001152616261_p53477489462"></a><a name="en-us_topic_0000001152616261_p53477489462"></a>Whether to asynchronously deliver tasks and call the ACL APIs. You are advised to set this parameter to <strong id="en-us_topic_0000001152616261_b186701714141819"><a name="en-us_topic_0000001152616261_b186701714141819"></a><a name="en-us_topic_0000001152616261_b186701714141819"></a>1</strong> to enable this function.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row1680820246202"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p4809112415207"><a name="en-us_topic_0000001152616261_p4809112415207"></a><a name="en-us_topic_0000001152616261_p4809112415207"></a>HCCL_WHITELIST_DISABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p952814428206"><a name="en-us_topic_0000001152616261_p952814428206"></a><a name="en-us_topic_0000001152616261_p952814428206"></a>Whether to enable the communication trustlist when the HCCL is used.</p>
|
||||
<a name="ul928845132310"></a><a name="ul928845132310"></a><ul id="ul928845132310"><li><strong id="b12793231525"><a name="b12793231525"></a><a name="b12793231525"></a>0</strong>: enable the trustlist. The HCCL communication trustlist does not need to be verified.</li><li><strong id="b1146142619212"><a name="b1146142619212"></a><a name="b1146142619212"></a>1</strong>: disable the trustlist. The HCCL communication trustlist needs to be verified.</li></ul>
|
||||
<p id="en-us_topic_0000001152616261_p5809162416201"><a name="en-us_topic_0000001152616261_p5809162416201"></a><a name="en-us_topic_0000001152616261_p5809162416201"></a>The default value is <strong id="en-us_topic_0000001152616261_b1270332516435"><a name="en-us_topic_0000001152616261_b1270332516435"></a><a name="en-us_topic_0000001152616261_b1270332516435"></a>0</strong>, indicating that the trustlist is enabled by default.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row0671137162115"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p4671203792114"><a name="en-us_topic_0000001152616261_p4671203792114"></a><a name="en-us_topic_0000001152616261_p4671203792114"></a>HCCL_IF_IP</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p1822165982114"><a name="en-us_topic_0000001152616261_p1822165982114"></a><a name="en-us_topic_0000001152616261_p1822165982114"></a>IP address of the NIC for initializing communication in the HCCL.</p>
|
||||
<a name="ul2676102292415"></a><a name="ul2676102292415"></a><ul id="ul2676102292415"><li>The IP address is in dotted decimal notation.</li><li>Currently, only the host NIC is supported.</li></ul>
|
||||
<p id="en-us_topic_0000001152616261_p1167163719217"><a name="en-us_topic_0000001152616261_p1167163719217"></a><a name="en-us_topic_0000001152616261_p1167163719217"></a>By default, the host communication NICs are selected in the following sequence: NICs other than Docker/local NICs (in ascending alphabetical order of NIC names) > Docker NICs > local NICs.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="en-us_topic_0000001152616261_row1371356152313"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p15106173103120"><a name="p15106173103120"></a><a name="p15106173103120"></a>PTCOPY_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p71055317311"><a name="p71055317311"></a><a name="p71055317311"></a>Use the PTCopy operator mode to accelerate the operation of converting non-contiguous tensors to contiguous tensors and copy process. You are advised to set the value to <strong id="b114621515513"><a name="b114621515513"></a><a name="b114621515513"></a>1</strong> to enable this function. </p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row743212132309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p17433111312307"><a name="p17433111312307"></a><a name="p17433111312307"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p6433151393018"><a name="p6433151393018"></a><a name="p6433151393018"></a>(Optional) Whether to enable the log printing function.</p>
|
||||
<a name="ul760201917473"></a><a name="ul760201917473"></a><ul id="ul760201917473"><li><strong id="b1955232216215"><a name="b1955232216215"></a><a name="b1955232216215"></a>0</strong>: uses the default log output mode.</li><li><strong id="b22913272211"><a name="b22913272211"></a><a name="b22913272211"></a>1</strong>: prints the logs to the screen.</li><li>Other values: invalid</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19237171814300"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p14238161893019"><a name="p14238161893019"></a><a name="p14238161893019"></a>ASCEND_GLOBAL_LOG_LEVEL</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p223841810303"><a name="p223841810303"></a><a name="p223841810303"></a>Sets the global log level of app logs.</p>
|
||||
<a name="ul175714586453"></a><a name="ul175714586453"></a><ul id="ul175714586453"><li><strong id="b94698561835"><a name="b94698561835"></a><a name="b94698561835"></a>0</strong>: DEBUG</li><li><strong id="b1612516597314"><a name="b1612516597314"></a><a name="b1612516597314"></a>1</strong>: INFO</li><li><strong id="b82051911547"><a name="b82051911547"></a><a name="b82051911547"></a>2</strong>: WARNING</li><li><strong id="b04351021945"><a name="b04351021945"></a><a name="b04351021945"></a>3</strong>: ERROR</li><li><strong id="b116153316418"><a name="b116153316418"></a><a name="b116153316418"></a>4</strong>: NULL (no log output)</li><li>Other values: invalid</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row1348192313303"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1734815235305"><a name="p1734815235305"></a><a name="p1734815235305"></a>ASCEND_GLOBAL_EVENT_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p12348202373018"><a name="p12348202373018"></a><a name="p12348202373018"></a>Whether to enable event logging for apps.</p>
|
||||
<a name="ul416352114610"></a><a name="ul416352114610"></a><ul id="ul416352114610"><li><strong id="b425610311940"><a name="b425610311940"></a><a name="b425610311940"></a>0</strong>: disabled</li><li><strong id="b198984321741"><a name="b198984321741"></a><a name="b198984321741"></a>1</strong>: enabled</li><li>Other values: invalid</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17878184693015"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1878194683016"><a name="p1878194683016"></a><a name="p1878194683016"></a>DYNAMIC_COMPILE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p1887894620304"><a name="p1887894620304"></a><a name="p1887894620304"></a>(Optional) Dynamic shape feature, which is used when the shape changes. To enable this function, set the value to <strong id="b11281447194117"><a name="b11281447194117"></a><a name="b11281447194117"></a>1</strong>. (PyTorch 1.8.1 does not support this environment variable.)</p>
|
||||
<th class="cellrowborder" valign="top" width="44.519999999999996%" id="mcps1.2.3.1.2"><p id="zh-cn_topic_0000001152616261_p9198135114133"><a name="zh-cn_topic_0000001152616261_p9198135114133"></a><a name="zh-cn_topic_0000001152616261_p9198135114133"></a>Description</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(Optional) Optimizes the scenario where two inconsecutive operators are combined. To enable this function, set the value to <strong id="b19824817612"><a name="b19824817612"></a><a name="b19824817612"></a>1</strong>.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17630155212342"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p66309527341"><a name="p66309527341"></a><a name="p66309527341"></a>RI_COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p19630185220345"><a name="p19630185220345"></a><a name="p19630185220345"></a>(Optional) Optimizes the scenario where three inconsecutive operators are combined. To enable this function, set the value to <strong id="b10522121418612"><a name="b10522121418612"></a><a name="b10522121418612"></a>1</strong>.</p>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(Optional) Discontinuous-to-continuous level-2 derivation optimization. To enable this function, set the value to **1**. When a large number of time-consuming AsStrided operators are called in the model, you can enable this function to improve the device execution efficiency.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to <strong id="b1861154419918"><a name="b1861154419918"></a><a name="b1861154419918"></a>1</strong>.</p>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(Optional) Operator data dump function, which is used for debugging. To enable this function, set the value to **1**.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row27481914203518"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p674813144357"><a name="p674813144357"></a><a name="p674813144357"></a>DYNAMIC_OP</p>
|
||||
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16711563237"><a name="zh-cn_topic_0000001152616261_p16711563237"></a><a name="zh-cn_topic_0000001152616261_p16711563237"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p974891414353"><a name="p974891414353"></a><a name="p974891414353"></a>(Optional) Operator implementation. The performance of the ADD and MUL operators varies depending on the scenarios. This parameter is not set by default.</p>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p0711356152317"><a name="zh-cn_topic_0000001152616261_p0711356152317"></a><a name="zh-cn_topic_0000001152616261_p0711356152317"></a>(Optional) Use asynchronous task delivery to asynchronously invoke the ACL interface. To enable this function, set it to **1** (recommended default setting). </p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0000001152616261_p16711563237"><a name="en-us_topic_0000001152616261_p16711563237"></a><a name="en-us_topic_0000001152616261_p16711563237"></a>unset GOMP_CPU_AFFINITY</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0000001152616261_p0711356152317"><a name="en-us_topic_0000001152616261_p0711356152317"></a><a name="en-us_topic_0000001152616261_p0711356152317"></a>(Optional) If the system is openEuler or its inherited OS, such as UOS, run this command to cancel CPU core binding.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3 id="installing-the-mixed-precision-modulemd">Installing the Mixed Precision Module</h3>
|
||||
## Running the Unit Test Script
|
||||
|
||||
#### Prerequisites<a name="en-us_topic_0000001106176190_section3225481020"></a>
|
||||
Verify the running. The output is **OK**.
|
||||
|
||||
1. Ensure that the PyTorch framework adapted to Ascend AI Processors in the operating environment can be used properly.
|
||||
2. Before building and installing Apex, you have configured the environment variables on which the build depends. See [Configuring Environment Variables](#configuring-environment-variablesmd).
|
||||
|
||||
#### Installation Process<a name="en-us_topic_0000001106176190_section11880164819567"></a>
|
||||
```shell
|
||||
// Select a test script that matches the preceding version. The following uses the 1.5.0 version as an example.
|
||||
cd ../
|
||||
python3 pytorch1.5.0/test/test_npu/test_network_ops/test_div.py
|
||||
```
|
||||
# (Optional) Installing the Mixed Precision Module<a name="(Optional) Installing the Mixed Precision Module"></a>
|
||||
|
||||
1. Log in to the server as the **root** user or a non-root user.
|
||||
2. Obtain the Apex source code.
|
||||
Select the APEX module based on the following functions. For details about how to build and install the APEX module, see the [README.en](https://gitee.com/ascend/apex/tree/v1.5.0-3.0.rc2/).
|
||||
|
||||
1. Run the following command to obtain the Apex source code adapted to Ascend AI Processors:
|
||||
- APEX
|
||||
- O1 configuration mode: Conv and Matmul use the float16 precision for computing, and Softmax and BN use float32.
|
||||
- O2 configuration mode: BN uses the float32 precision for computing, and others use float16.
|
||||
- Static loss scale: Parameters are statically set to ensure the convergence of training with mixed precision.
|
||||
- Dynamic loss scale: The loss scale value is dynamically calculated to determine whether overflow occurs.
|
||||
|
||||
```
|
||||
git clone https://gitee.com/ascend/apex.git
|
||||
```
|
||||
# FAQ
|
||||
|
||||
The directory structure of the downloaded source code is as follows:
|
||||
|
||||
```
|
||||
apex
|
||||
│ ├─patch # Directory of the patch adapted to Ascend AI Processors
|
||||
│ ├─npu.patch
|
||||
│ ├─scripts # Build and creation directory
|
||||
│ ├─gen.sh
|
||||
│ ├─src # Source code directory
|
||||
│ ├─tests # Directory for storing test cases
|
||||
```
|
||||
|
||||
2. Run the following commands to go to the **apex** directory and obtain the native Apex source code:
|
||||
## When PIP is set to the Huawei source, a Python environment error occurs after the typing dependency in the **requirements.txt** file is installed.
|
||||
|
||||
```
|
||||
cd apex
|
||||
git clone https://github.com/NVIDIA/apex.git
|
||||
```
|
||||
When PIP is set to the Huawei source, open the **requirements.txt** file, delete the typing dependency, and then run the following command:
|
||||
|
||||
After the native Apex source code is downloaded, the main directory structure of the code is as follows:
|
||||
```
|
||||
pip3 install -r requirments.txt
|
||||
```
|
||||
|
||||
```
|
||||
apex
|
||||
│ ├─apex # Directory for storing the native Apex code
|
||||
│ ├─patch # Directory of the patch adapted to Ascend AI Processors
|
||||
│ ├─npu.patch
|
||||
│ ├─scripts # Build and creation directory
|
||||
│ ├─gen.sh
|
||||
│ ├─src # Source code directory
|
||||
│ ├─tests # Directory for storing test cases
|
||||
```
|
||||
|
||||
3. Go to the native Apex code directory, that is, **apex/apex**. Switch to the code branch whose commit ID is 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a.
|
||||
|
||||
```
|
||||
cd apex
|
||||
git checkout 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a
|
||||
```
|
||||
## The **libhccl.so** cannot be found by **import torch**.
|
||||
|
||||
> **NOTE:**
|
||||
>Due to network fluctuation, it may take a long time to obtain the source code.
|
||||
Environment variables are not configured. You need to configure them using the **env.sh** script.
|
||||
|
||||
3. Generate the Apex installation package adapted to Ascend AI Processors.
|
||||
1. Go to the **apex/scripts** directory and run the conversion script to generate full code adapted to Ascend AI Processors.
|
||||
```
|
||||
source pytorch/pytorch1.5.0/src/env.sh
|
||||
```
|
||||
|
||||
```
|
||||
cd ../scripts
|
||||
bash gen.sh
|
||||
```
|
||||
|
||||
The full code adapted to Ascend AI Processors is generated in the **apex/apex** directory.
|
||||
|
||||
2. Go to the full code directory **apex/apex**, and build and generate the binary installation package of Apex.
|
||||
## The error message "no module named yaml/typing_extensions." is displayed when **bash build.sh** is run during compilation.
|
||||
|
||||
```
|
||||
cd ../apex
|
||||
python3 setup.py --cpp_ext --npu_float_status bdist_wheel
|
||||
```
|
||||
PyTorch compilation depends on the YAML and typing_extensions libraries, which need to be manually installed.
|
||||
|
||||
The Python version must be the same as that used by PyTorch. The generated binary package is stored in the current **dist** directory, that is, **apex/apex/dist**.
|
||||
```
|
||||
pip3 install pyyaml
|
||||
pip3 install typing_extensions
|
||||
```
|
||||
|
||||
4. <a name="en-us_topic_0000001106176190_li425495374416"></a>Install Apex.
|
||||
After the installation is successful, run **make clean** and then **bash build.sh** to perform compilation. Otherwise, an unknown compilation error may occur due to the cache.
|
||||
|
||||
Go to the **apex/apex/dist** directory and run the following command to install Apex:
|
||||
|
||||
```
|
||||
pip3 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
|
||||
_\{**arch\}**_ indicates the architecture information. The value can be **aarch64** or **x86\_64**.
|
||||
## TE cannot be found during running.
|
||||
|
||||
> **NOTE:**
|
||||
>To upgrade PyTorch in the environment, uninstall the PyTorch software package installed in the environment and then perform [Step 4 Install Apex](#en-us_topic_0000001106176190_li425495374416). Run the following command to check whether PyTorch has been installed:
|
||||
>**pip3 list | grep apex**
|
||||
Development state:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64 # {arch} is the architecture name.
|
||||
|
||||
<h2 id="referencesmd">References</h2>
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
- **[Installing CMake](#installing-cmakemd)**
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
- **[How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md)**
|
||||
User state:
|
||||
|
||||
- **[What to Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-to-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)**
|
||||
```
|
||||
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64 # {arch} is the architecture name.
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
<h3 id="installing-cmakemd">Installing CMake</h3>
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
The following describes how to install CMake 3.12.1.
|
||||
|
||||
1. Obtain the CMake software package.
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.1.tar.gz --no-check-certificate
|
||||
```
|
||||
## During CMake installation through the CLI, an error is reported indicating that the package cannot be found. During CMake compilation, another error is reported indicating that the version is too early. In this cause, you can use the installation script or source code to compile and install CMake.
|
||||
|
||||
2. Decompress the package and go to the software package directory.
|
||||
Method 1: Download the installation script and install CMake. (For details, see the CMake official website.)
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.1.tar.gz
|
||||
cd cmake-3.12.1/
|
||||
```
|
||||
x86_64 environment: cmake-3.12.0-Linux-x86_64.sh
|
||||
|
||||
3. Run the configuration, build, and installation commands.
|
||||
AArch64 environment: cmake-3.12.0-Linux-aarch64.sh
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
1. Run the following command:
|
||||
|
||||
4. Set the soft link.
|
||||
```
|
||||
./cmake-3.12.0-Linux-{arch}.sh #{arch} indicates the architecture name.
|
||||
```
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
2. Set the soft link.
|
||||
|
||||
5. Check whether CMake has been installed.
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
If the message "cmake version 3.12.1" is displayed, the installation is successful.
|
||||
3. Run the following command to check whether CMake has been installed:
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
<h3 id="how-do-i-install-gcc-7-3-0md">How Do I Install GCC 7.3.0?</h3>
|
||||
If the message "cmake version 3.12.0" is displayed, the installation is successful.
|
||||
|
||||
Perform the following steps as the **root** user.
|
||||
|
||||
1. Download **gcc-7.3.0.tar.gz** from [https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz).
|
||||
2. GCC installation requires adequate temporary space. Run the following command to clear the **/tmp** directory in advance:
|
||||
Method 2: Use the source code to compile and install.
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
1. Obtain the CMake software package.
|
||||
|
||||
3. Install the dependency package. \(CentOS and Ubuntu are used as examples.\)
|
||||
- For CentOS, run the following command:
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
|
||||
```
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
2. Decompress the package and go to the software package directory.
|
||||
|
||||
- For Ubuntu, run the following command:
|
||||
```
|
||||
tar -xf cmake-3.12.0.tar.gz
|
||||
cd cmake-3.12.0/
|
||||
```
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
3. Run the configuration, compilation, and installation commands.
|
||||
|
||||
4. Build and install GCC.
|
||||
1. Go to the directory where the source package **gcc-7.3.0.tar.gz** is located and run the following command to decompress it:
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
4. Set the soft link.
|
||||
|
||||
2. Go to the extracted directory and run the following command to download the GCC dependency packages:
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
5. Run the following command to check whether CMake has been installed:
|
||||
|
||||
If an error is reported during the command execution, run the following commands in the **gcc-7.3.0/** directory to download the dependency packages:
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
If the message "cmake version 3.12.0" is displayed, the installation is successful.
|
||||
|
||||
After the preceding dependencies are downloaded, run the following command again:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If the validation fails, check whether the dependency packages are repeatedly downloaded. The packages should be downloaded at a time.
|
||||
## During GCC installation through the CLI, an error is reported indicating that the package cannot be found. During GCC compilation, another error is reported.
|
||||
|
||||
3. <a name="en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li1649343041310"></a>Run the configuration, build, and installation commands.
|
||||
When downloading GCC from some sources, you may be prompted by an error message indicating that the package cannot be found. In this case, use the source code to compile and install GCC.
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # Check the number of CPUs by running grep -w processor /proc/cpuinfo|wc -l. In this example, the number is 15.
|
||||
make install
|
||||
```
|
||||
Perform the following steps as the **root** user.
|
||||
|
||||
> **NOTICE:**
|
||||
>The **--prefix** option is used to specify the linux\_gcc7.3.0 installation path, which is configurable. Do not set it to **/usr/local** or **/usr**, which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to **/usr/local/linux\_gcc7.3.0**.
|
||||
1. Download **gcc-7.3.0.tar.gz** from [https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz).
|
||||
|
||||
2. GCC installation requires adequate temporary space. Run the following command to clear the **/tmp** directory in advance:
|
||||
|
||||
5. Set the environment variable.
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
Training must be performed in the compilation environment with GCC upgraded. Therefore, configure the following environment variable in your training script:
|
||||
3. Install the dependency package. (CentOS and Ubuntu are used as examples.)
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
- For CentOS, run the following command:
|
||||
|
||||
**$\{install\_path\}** indicates the GCC 7.3.0 installation path configured in [3](#en-us_topic_0000001135347812_en-us_topic_0000001173199577_en-us_topic_0000001172534867_en-us_topic_0276688294_li1649343041310). In this example, the GCC 7.3.0 installation path is **/usr/local/gcc7.3.0/**.
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
> **NOTE:**
|
||||
>Skip this step if you do not need to use the compilation environment with GCC upgraded.
|
||||
- For Ubuntu, run the following command:
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
<h3 id="what-to-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd">What to Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?</h3>
|
||||
4. Compile and install GCC.
|
||||
|
||||
#### Symptom<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section197270431505"></a>
|
||||
1. Go to the directory where the source package **gcc-7.3.0.tar.gz** is located and run the following command to decompress it:
|
||||
|
||||
During the installation of **torch-**_\*_**.whl**, the message "ERROR: torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible" is displayed.
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
|
||||

|
||||
2. Go to the extracted directory and download the GCC dependency packages:
|
||||
|
||||
#### Possible Causes<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section169499490501"></a>
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
When the PyTorch is installed, the version check is automatically triggered. The version of the torchvision installed in the environment is 0.6.0. During the check, it is found that the version of the **torch-**_\*_**.whl** is inconsistent with the required version 1.5.0. As a result, an error message is displayed, but the installation is successful.
|
||||
If an error is reported during the command execution, run the following commands in the **gcc-7.3.0/** directory to download the dependency packages:
|
||||
|
||||
#### Solution<a name="en-us_topic_0000001105856364_section108142031907"></a>
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
This problem has no impact on the actual result, and no action is required.
|
||||
After the preceding dependencies are downloaded, run the following command again:
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
If the verification fails, check whether there are duplicate dependency packages in the folder. If yes, delete duplicate ones.
|
||||
|
||||
3. <a name="zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310"></a>Run the configuration, compilation, and installation commands.
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # Check the number of CPUs by running **grep -w processor /proc/cpuinfo|wc -l**. In this example, the number is 15. You can set the parameters as required.
|
||||
make install
|
||||
```
|
||||
|
||||
>  **NOTE: **
|
||||
>The **--prefix** option is used to specify the **linux_gcc7.3.0** installation path, which is configurable. Do not set it to **/usr/local** or **/usr,** which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to **/usr/local/linux_gcc7.3.0**.
|
||||
|
||||
4. Change the soft links.
|
||||
|
||||
```
|
||||
ln -s ${install_path}/bin/gcc /usr/bin/gcc
|
||||
ln -s ${install_path}/bin/g++ /usr/bin/g++
|
||||
ln -s ${install_path}/bin/c++ /usr/bin/c++
|
||||
```
|
||||
|
||||
5. Configure environment variables.
|
||||
|
||||
Training must be performed in the compilation environment with GCC upgraded. If you want to run training, configure the following environment variable in your training script:
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
**${install_path}** indicates the GCC 7.3.0 installation path configured in [3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310). In this example, the GCC 7.3.0 installation path is **/usr/local/linux_gcc7.3.0/**.
|
||||
|
||||
> **NOTE:**
|
||||
>Skip this step if you do not need to use the compilation environment with GCC upgraded.
|
||||
|
||||
If the PyTorch compilation fails, check whether the soft link library is correct.
|
||||
|
||||
libstdc++->libstdc++.so.6.0.24(7.3.0)
|
||||
|
||||
## libblas.so cannot be found.
|
||||
|
||||
The OpenBLAS library is missing in the environment. You need to install it.
|
||||
|
||||
CentOS and EulerOS
|
||||
|
||||
```sh
|
||||
yum -y install openblas
|
||||
```
|
||||
|
||||
Ubuntu
|
||||
|
||||
```sh
|
||||
apt install libopenblas-dev
|
||||
```
|
||||
|
||||
|
||||
|
||||
## torchvision fails to be installed using pip in the Arm environment.
|
||||
|
||||
The source code can be used for installation. (You need to install the AscendPyTorch first and configure environment variables using **env.sh**.)
|
||||
|
||||
```
|
||||
git clone -b v0.6.0 https://github.com/pytorch/vision.git
|
||||
cd vision
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
Verify that the torchvision is successfully installed.
|
||||
|
||||
```
|
||||
python -c "import torchvision"
|
||||
```
|
||||
|
||||
If no error is reported, the installation is successful.
|
||||
|
||||
|
||||
|
||||
For details about releases, see [Release Notes](https://gitee.com/ascend/pytorch/blob/v1.5.0-3.0.rc2/docs/zh/RELEASENOTE/RELEASENOTE.md).
|
||||
|
||||
@@ -18,7 +18,7 @@ In this way, PyTorch-based inference apps can be directly ported to the Ascend
|
||||
|
||||
Ascend 910 AI Processor
|
||||
|
||||
Ascend 710 AI Processor
|
||||
Ascend 310P AI Processor
|
||||
|
||||
<h2 id="basic-workflowmd">Basic Workflow</h2>
|
||||
|
||||
@@ -596,4 +596,3 @@ Perform the following steps as the **root** user.
|
||||
> **NOTE:**
|
||||
>Skip this step if you do not the compilation environment with GCC upgraded.
|
||||
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 406 B |
|
Before Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 580 B |
@@ -18,7 +18,7 @@
|
||||
|
||||
昇腾910 AI处理器
|
||||
|
||||
昇腾710 AI处理器
|
||||
昇腾310P AI处理器
|
||||
|
||||
<h2 id="基本使用流程md">基本使用流程</h2>
|
||||
|
||||
@@ -596,4 +596,3 @@ if __name__ == '__main__':
|
||||
> **说明:**
|
||||
>本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。
|
||||
|
||||
|
||||
|
||||
@@ -1,309 +1,192 @@
|
||||
# PyTorch安装指南
|
||||
- [简介](#简介md)
|
||||
- [手动编译安装](#手动编译安装md)
|
||||
- [前提条件](#前提条件md)
|
||||
- [安装PyTorch框架](#安装PyTorch框架md)
|
||||
- [配置环境变量](#配置环境变量md)
|
||||
- [安装混合精度模块](#安装混合精度模块md)
|
||||
- [参考信息](#参考信息md)
|
||||
- [CMake安装方法](#CMake安装方法md)
|
||||
- [安装7.3.0版本gcc](#安装7-3-0版本gccmd)
|
||||
- [安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md)
|
||||
<h2 id="简介md">简介</h2>
|
||||
- [简介](#简介)
|
||||
|
||||
用户在准备相关环境进行基于PyTorch框架模型的开发、运行时,可以选择在服务器中手动编译安装PyTorch框架相关模块。
|
||||
- [系统依赖库](#系统依赖库)
|
||||
|
||||
**图 1** 环境准备流程图<a name="zh-cn_topic_0000001119176876_fig1938918396117"></a>
|
||||
- [Ascend配套软件](#Ascend配套软件)
|
||||
|
||||
- [安装方式](#安装方式)
|
||||
|
||||

|
||||
- [运行](#运行)
|
||||
|
||||
<h2 id="手动编译安装md">手动编译安装</h2>
|
||||
- [安装混合精度模块(可选)](#安装混合精度模块(可选))
|
||||
|
||||
- **[前提条件](#前提条件md)**
|
||||
- [FAQ](#FAQ)
|
||||
|
||||
- **[安装PyTorch框架](#安装PyTorch框架md)**
|
||||
- [版本说明](#版本说明)
|
||||
|
||||
- **[配置环境变量](#配置环境变量md)**
|
||||
|
||||
|
||||
- **[安装混合精度模块](#安装混合精度模块md)**
|
||||
# 简介<a name="简介"></a>
|
||||
|
||||
本项目开发了PyTorch Adapter插件,用于昇腾适配PyTorch框架,为使用PyTorch框架的开发者提供昇腾AI处理器的超强算力。用户在准备相关环境进行基于PyTorch框架模型的开发、运行时,可以选择在服务器中手动编译安装PyTorch框架相关模块。
|
||||
|
||||
<h3 id="前提条件md">前提条件</h3>
|
||||
|
||||
#### 前提条件<a name="zh-cn_topic_0000001105856382_zh-cn_topic_0275872734_section108914373254"></a>
|
||||
|
||||
- 需完成CANN开发或运行环境的安装,具体操作请参考《CANN 软件安装指南》。
|
||||
- Python支持版本为3.7.5、3.8。
|
||||
|
||||
- 需安装3.12.0以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法md)。
|
||||
# 系统依赖库<a name="系统依赖库"></a>
|
||||
|
||||
- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参考[安装7.3.0版本gcc](#安装7-3-0版本gccmd)。
|
||||
## CentOS & EulerOS
|
||||
|
||||
- 需安装python版本为3.7.5、3.8、3.9。
|
||||
yum install -y patch zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas git dos2unix
|
||||
|
||||
- 需注意torch1.5版本不支持python3.9编译安装(与官方保持一致),仅torch1.8.1版本支持python版本3.9进行编译安装。
|
||||
yum install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
- 需确保环境中已安装patch、git工具,以Ubuntu和CentOS系统为例,命令如下:
|
||||
- Ubuntu系统
|
||||
## Ubuntu
|
||||
|
||||
```
|
||||
apt-get install patch
|
||||
apt-get install git
|
||||
```
|
||||
apt-get install -y patch g++ make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev m4 dos2unix libopenblas-dev git dos2unix
|
||||
|
||||
- CentOS系统
|
||||
|
||||
```
|
||||
yum install patch
|
||||
yum install git
|
||||
```
|
||||
apt-get install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
|
||||
|
||||
<h3 id="安装PyTorch框架md">安装PyTorch框架</h3>
|
||||
|
||||
#### 安装流程<a name="zh-cn_topic_0000001152776301_section1611810384557"></a>
|
||||
|
||||
1. 以root或非root用户登录服务器。
|
||||
2. 依次执行如下命令安装PyTorch依赖环境。
|
||||
|
||||
如果使用非root用户安装Python及其依赖,用户需要在本步骤中的每句命令结尾加上**--user**,命令示例为:**pip3.7 install pyyaml --user**
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
pip3 install wheel
|
||||
```
|
||||
|
||||
3. 获取PyTorch源代码。
|
||||
|
||||
1. 运行如下命令,获取适配昇腾AI处理器的PyTorch源代码,并切换到所需的分支。
|
||||
|
||||
```
|
||||
git clone https://gitee.com/ascend/pytorch.git
|
||||
# 默认是masterf分支,若需要其他分支请使用git checkout 命令切换
|
||||
# git checkout -b 2.0.3.tr5 remotes/origin/2.0.3.tr5
|
||||
```
|
||||
|
||||
下载的源码主要目录结构如下所示:
|
||||
|
||||
```
|
||||
├── patch # 昇腾AI处理器适配补丁目录
|
||||
│ ├── pytorch1.5.0_npu.patch # pytorch1.5.0版本补丁
|
||||
│ └── pytorch1.8.1_npu.patch # pytorch1.8.1版本补丁
|
||||
├── pytorch1.5.0 # pytorch1.5.0源码及测试目录
|
||||
│ ├── access_control_test.py
|
||||
│ ├── src # 源码目录
|
||||
│ └── test # 测试用例存放目录
|
||||
├── pytorch1.8.1 # pytorch1.8.1源码及测试目录
|
||||
│ ├── access_control_test.py
|
||||
│ ├── src # 源码目录
|
||||
│ └── test # 测试用例存放目录
|
||||
└── scripts # 编译构建目录
|
||||
```
|
||||
|
||||
2. 在当前仓根目录“/pytorch“下获取原生PyTorch源代码。
|
||||
- 若安装pytorch1.5.0版本,执行如下命令。
|
||||
|
||||
```
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
- 若安装pytorch1.8.1版本,执行如下命令。
|
||||
|
||||
```
|
||||
git clone -b v1.8.1 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
3. 运行如下命令,进入原生pytorch代码目录“pytorch“,并获取PyTorch被动依赖代码。
|
||||
|
||||
```
|
||||
cd pytorch
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
> **说明:**
|
||||
>受网络波动影响,源码获取时间可能较长,下载过程中请耐心等待。 下载完成之后若没有报错,即生成了PyTorch及其依赖的第三方代码。
|
||||
|
||||
4. 编译生成适配昇腾AI处理器的PyTorch安装包。
|
||||
1. 进入“pytorch/scripts“文件夹,执行转换脚本,生成适配昇腾AI处理器的全量代码。
|
||||
|
||||
```
|
||||
cd ../scripts
|
||||
# 若安装1.5.0版本
|
||||
bash gen.sh
|
||||
# 若安装1.8.1版本
|
||||
bash gen.sh -v 1.8.1
|
||||
```
|
||||
|
||||
将在"pytorch/pytorch"目录中生成适配昇腾AI处理器的全量代码。
|
||||
|
||||
2. 进入到“pytorch/pytorch/“目录,依赖库安装。
|
||||
|
||||
```
|
||||
cd ../pytorch
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
3. 编译生成pytorch的二进制安装包。
|
||||
|
||||
```
|
||||
bash build.sh --python=3.7
|
||||
或
|
||||
bash build.sh --python=3.8
|
||||
或
|
||||
bash build.sh --python=3.9 #torch1.5不支持使用python3.9编译安装
|
||||
```
|
||||
|
||||
请指定环境中python版本进行编译。生成的二进制包在当前的dist目录下,即“pytorch/pytorch/dist”文件夹目录下。
|
||||
|
||||
5. <a name="zh-cn_topic_0000001152776301_li49671667141"></a>安装PyTorch。
|
||||
|
||||
进入“pytorch/pytorch/dist“文件夹目录,执行如下命令安装。
|
||||
|
||||
```
|
||||
pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
|
||||
**\{arch\}**表示架构信息,为aarch64或x86\_64。
|
||||
|
||||
> **说明:**
|
||||
>若对环境中的PyTorch进行升级时,需要先卸载环境中已安装的PyTorch软件包再执行[5. 安装PyTorch。](#zh-cn_topic_0000001152776301_li49671667141)可以通过执行如下命令查询环境上是否已安装PyTorch。
|
||||
>**pip3 list | grep torch**
|
||||
> **说明:**
|
||||
>若安装gcc与cmake依赖命令报错,请参考FAQ使用源码安装。
|
||||
|
||||
|
||||
<h3 id="配置环境变量md">配置环境变量</h3>
|
||||
# Ascend配套软件<a name="Ascend配套软件"></a>
|
||||
|
||||
安装完软件包后,需要配置环境变量才能正常使用昇腾PyTorch。相关环境变量介绍参见[表1](#zh-cn_topic_0000001152616261_table42017516135)。
|
||||
| AscendPyTorch版本 | CANN版本 | 支持PyTorch版本 | Gitee分支名称 |
|
||||
| :------------ | :----------- | :----------- | ------------ |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0.post2 | 2.0.2.tr5 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | 2.0.3.tr5 |
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | 2.0.4.tr5 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5 | v1.5.0-3.0.rc1 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.8.1.rc1 | v1.8.1-3.0.rc1 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.5.0.post6 | v1.5.0-3.0.rc2 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.8.1.rc2 | v1.8.1-3.0.rc2 |
|
||||
|
||||
1. 配置运行环境变量,在适配昇腾AI处理器的PyTorch源代码根目录中运行如下命令。
|
||||
# 安装方式<a name="安装方式"></a>
|
||||
|
||||
```
|
||||
source pytorch/env.sh
|
||||
```
|
||||
## 安装PyTorch依赖环境
|
||||
|
||||
2. 请依据实际场景,选择合适的HCCL初始化方式,并配置相应环境变量。
|
||||
|
||||
```
|
||||
# 场景一:单机场景
|
||||
export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单
|
||||
# 场景二:多机场景。
|
||||
export HCCL_WHITELIST_DISABLE=1 # 关闭HCCL通信白名单
|
||||
export HCCL_IF_IP="1.1.1.1" # “1.1.1.1”为示例使用的host网卡IP,请根据实际修改。需要保证使用的网卡IP在集群内是互通的。
|
||||
```
|
||||
获取适配昇腾AI处理器的PyTorch源代码(即当前仓库代码)。
|
||||
|
||||
3. (可选)NPU场景下配置功能或性能环境变量。默认为不开启。
|
||||
```
|
||||
git clone -b v1.5.0 https://gitee.com/ascend/pytorch.git
|
||||
```
|
||||
|
||||
```
|
||||
export DYNAMIC_COMPILE_ENABLE=1 # 动态shape特性功能,针对shape变化场景,可选,开启设置为1(PyTorch1.8.1不支持该环境变量)
|
||||
export COMBINED_ENABLE=1 # 非连续两个算子组合类场景优化,可选,开启设置为1
|
||||
export TRI_COMBINED_ENABLE=1 # 非连续三个算子组合类场景优化,可选,开启设置为1
|
||||
export ACL_DUMP_DATA=1 # 算子数据dump功能,调试时使用,可选,开启设置为1
|
||||
export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下有不同的性能表现。可选
|
||||
```
|
||||
## 获取原生PyTorch源代码和third_party代码
|
||||
|
||||
4. (可选)当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。
|
||||
在当前仓库根目录pytorch/下获取原生PyTorch1.5.0的源代码。请关注PyTorch原生社区的安全板块与Issue板块是否有安全相关问题修复,并根据社区修复及时更新原生PyTorch代码。
|
||||
|
||||
```sh
|
||||
cd pytorch
|
||||
git clone -b v1.5.0 --depth=1 https://github.com/pytorch/pytorch.git
|
||||
```
|
||||
|
||||
进入到pytorch/pytorch/目录下, 获取PyTorch被动依赖代码(获取时间较长,请耐心等待)。
|
||||
|
||||
```sh
|
||||
cd pytorch
|
||||
git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
完成且没有报错之后就生成了PyTorch及其依赖的三方代码
|
||||
|
||||
## 生成适配昇腾AI处理器的PyTorch全量代码。
|
||||
|
||||
进入到pytorch/scripts目录,根据选择的版本执行,执行脚本(注意:下载原生Pytorch源代码和下面版本要对应,否则可能出错)
|
||||
|
||||
```sh
|
||||
cd ../scripts/
|
||||
bash gen.sh
|
||||
```
|
||||
|
||||
会在pytorch/pytorch/目录中生成npu适配全量代码
|
||||
|
||||
|
||||
## python依赖库
|
||||
|
||||
进入到pytorch/pytorch/目录,依赖库安装:
|
||||
|
||||
```python3
|
||||
cd ../pytorch
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
|
||||
## 编译torch的二进制包
|
||||
|
||||
在pytorch/pytorch/目录,执行
|
||||
|
||||
```sh
|
||||
# python3.7版本
|
||||
bash build.sh
|
||||
或者
|
||||
bash build.sh --python=3.7(推荐)
|
||||
|
||||
# python3.8版本
|
||||
bash build.sh --python=3.8
|
||||
```
|
||||
|
||||
生成的二进制包在pytorch/pytorch/dist/目录下
|
||||
|
||||
## 安装pytorch
|
||||
|
||||
**x86_64:**
|
||||
|
||||
torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
|
||||
```
|
||||
|
||||
|
||||
**arm:**
|
||||
|
||||
torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_aarch64.whl)
|
||||
|
||||
```shell
|
||||
cd dist
|
||||
pip3 uninstall torch
|
||||
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
|
||||
```
|
||||
|
||||
|
||||
# 运行<a name="运行"></a>
|
||||
|
||||
## 运行环境变量
|
||||
|
||||
在pytorch/pytorch/中执行设置环境变量脚本
|
||||
|
||||
```
|
||||
cd ../
|
||||
source env.sh
|
||||
```
|
||||
|
||||
|
||||
可选的环境变量可能会对运行的模型产生影响:
|
||||
|
||||
```
|
||||
|
||||
export COMBINED_ENABLE=1 # 非连续转连续二级推导优化,可选,开启设置为1。当模型中有大量AsStrided高耗时算子被调用时,可以尝试开启此优化以获得潜在的device执行效率的提升
|
||||
export ACL_DUMP_DATA=1 # 算子数据dump功能,调试时使用,可选,开启设置为1
|
||||
export TASK_QUEUE_ENABLE=1 # 使用异步任务下发,异步调用acl接口,建议默认开启,开启设置为1
|
||||
|
||||
```
|
||||
当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。
|
||||
|
||||
```
|
||||
# unset GOMP_CPU_AFFINITY
|
||||
```
|
||||
|
||||
|
||||
**表 1** 环境变量说明
|
||||
|
||||
<a name="zh-cn_topic_0000001152616261_table42017516135"></a>
|
||||
<table><thead align="left"><tr id="zh-cn_topic_0000001152616261_row16198951191317"><th class="cellrowborder" valign="top" width="55.48%" id="mcps1.2.3.1.1"><p id="zh-cn_topic_0000001152616261_p51981251161315"><a name="zh-cn_topic_0000001152616261_p51981251161315"></a><a name="zh-cn_topic_0000001152616261_p51981251161315"></a>配置项</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="44.519999999999996%" id="mcps1.2.3.1.2"><p id="zh-cn_topic_0000001152616261_p9198135114133"><a name="zh-cn_topic_0000001152616261_p9198135114133"></a><a name="zh-cn_topic_0000001152616261_p9198135114133"></a>说明</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="zh-cn_topic_0000001152616261_row6882121917329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p688241953218"><a name="zh-cn_topic_0000001152616261_p688241953218"></a><a name="zh-cn_topic_0000001152616261_p688241953218"></a>LD_LIBRARY_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p1888291915322"><a name="zh-cn_topic_0000001152616261_p1888291915322"></a><a name="zh-cn_topic_0000001152616261_p1888291915322"></a>动态库的查找路径,参考上述举例配置。</p>
|
||||
<p id="p1292181892120"><a name="p1292181892120"></a><a name="p1292181892120"></a>若训练所在系统环境需要升级gcc(例如CentOS、Debian和BClinux系统),则<span class="parmname" id="parmname795020446318"><a name="parmname795020446318"></a><a name="parmname795020446318"></a>“LD_LIBRARY_PATH”</span>配置项处动态库查找路径需要添加<span class="filepath" id="zh-cn_topic_0256062644_filepath115819811512"><a name="zh-cn_topic_0256062644_filepath115819811512"></a><a name="zh-cn_topic_0256062644_filepath115819811512"></a>“${install_path}/lib64”</span>,其中<span class="filepath" id="zh-cn_topic_0256062644_filepath195951574421"><a name="zh-cn_topic_0256062644_filepath195951574421"></a><a name="zh-cn_topic_0256062644_filepath195951574421"></a>“{install_path}”</span>为gcc升级安装路径。请参见<a href="#安装7-3-0版本gccmd#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li9745165315131">5</a>。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row16194175523010"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16195185523019"><a name="zh-cn_topic_0000001152616261_p16195185523019"></a><a name="zh-cn_topic_0000001152616261_p16195185523019"></a>PYTHONPATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p19637083322"><a name="zh-cn_topic_0000001152616261_p19637083322"></a><a name="zh-cn_topic_0000001152616261_p19637083322"></a>Python搜索路径,参考上述举例配置。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row2954102119329"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p195452113218"><a name="zh-cn_topic_0000001152616261_p195452113218"></a><a name="zh-cn_topic_0000001152616261_p195452113218"></a>PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p964914893211"><a name="zh-cn_topic_0000001152616261_p964914893211"></a><a name="zh-cn_topic_0000001152616261_p964914893211"></a>可执行程序的查找路径,参考上述举例配置。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row58592816294"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p1886016892913"><a name="zh-cn_topic_0000001152616261_p1886016892913"></a><a name="zh-cn_topic_0000001152616261_p1886016892913"></a>ASCEND_OPP_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p28608892915"><a name="zh-cn_topic_0000001152616261_p28608892915"></a><a name="zh-cn_topic_0000001152616261_p28608892915"></a>算子根目录,参考上述举例配置。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row144592037903"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p104601373014"><a name="zh-cn_topic_0000001152616261_p104601373014"></a><a name="zh-cn_topic_0000001152616261_p104601373014"></a>OPTION_EXEC_EXTERN_PLUGIN_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p1046013716017"><a name="zh-cn_topic_0000001152616261_p1046013716017"></a><a name="zh-cn_topic_0000001152616261_p1046013716017"></a>算子信息库路径。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row16184379493"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p131851873492"><a name="zh-cn_topic_0000001152616261_p131851873492"></a><a name="zh-cn_topic_0000001152616261_p131851873492"></a>ASCEND_AICPU_PATH</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p181851575497"><a name="zh-cn_topic_0000001152616261_p181851575497"></a><a name="zh-cn_topic_0000001152616261_p181851575497"></a>aicpu算子包路径。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row234714854615"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p2034724894619"><a name="zh-cn_topic_0000001152616261_p2034724894619"></a><a name="zh-cn_topic_0000001152616261_p2034724894619"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p53477489462"><a name="zh-cn_topic_0000001152616261_p53477489462"></a><a name="zh-cn_topic_0000001152616261_p53477489462"></a>使用异步任务下发,异步调用acl接口。建议开启,开启设置为1。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row1680820246202"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p4809112415207"><a name="zh-cn_topic_0000001152616261_p4809112415207"></a><a name="zh-cn_topic_0000001152616261_p4809112415207"></a>HCCL_WHITELIST_DISABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p952814428206"><a name="zh-cn_topic_0000001152616261_p952814428206"></a><a name="zh-cn_topic_0000001152616261_p952814428206"></a>配置在使用HCCL时是否开启通信白名单。</p>
|
||||
<a name="ul928845132310"></a><a name="ul928845132310"></a><ul id="ul928845132310"><li>0:开启白名单,无需校验HCCL通信白名单。</li><li>1:关闭白名单,需校验HCCL通信白名单。</li></ul>
|
||||
<p id="zh-cn_topic_0000001152616261_p5809162416201"><a name="zh-cn_topic_0000001152616261_p5809162416201"></a><a name="zh-cn_topic_0000001152616261_p5809162416201"></a>缺省值为0,默认开启白名单。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row0671137162115"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p4671203792114"><a name="zh-cn_topic_0000001152616261_p4671203792114"></a><a name="zh-cn_topic_0000001152616261_p4671203792114"></a>HCCL_IF_IP</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p1822165982114"><a name="zh-cn_topic_0000001152616261_p1822165982114"></a><a name="zh-cn_topic_0000001152616261_p1822165982114"></a>配置HCCL的初始化通信网卡IP。</p>
|
||||
<a name="ul2676102292415"></a><a name="ul2676102292415"></a><ul id="ul2676102292415"><li>ip格式为点分十进制。</li><li>暂只支持host网卡。</li></ul>
|
||||
<p id="zh-cn_topic_0000001152616261_p1167163719217"><a name="zh-cn_topic_0000001152616261_p1167163719217"></a><a name="zh-cn_topic_0000001152616261_p1167163719217"></a>缺省时,按照以下优先级选定host通信网卡名:docker/local以外网卡(网卡名字字典序升序排列)>docker 网卡 > local网卡</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="zh-cn_topic_0000001152616261_row1371356152313"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p15106173103120"><a name="p15106173103120"></a><a name="p15106173103120"></a>PTCOPY_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p71055317311"><a name="p71055317311"></a><a name="p71055317311"></a>使用PTCopy算子模式,加速转连续及copy等过程,建议开启,开启设置为1</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row743212132309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p17433111312307"><a name="p17433111312307"></a><a name="p17433111312307"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p6433151393018"><a name="p6433151393018"></a><a name="p6433151393018"></a>(可选)设置是否开启日志打屏。</p>
|
||||
<a name="ul760201917473"></a><a name="ul760201917473"></a><ul id="ul760201917473"><li>0:表示采用日志的默认输出方式。</li><li>1:表示日志打屏显示。</li><li>其他值为非法值。</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19237171814300"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p14238161893019"><a name="p14238161893019"></a><a name="p14238161893019"></a>ASCEND_GLOBAL_LOG_LEVEL</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p223841810303"><a name="p223841810303"></a><a name="p223841810303"></a>设置应用类日志的全局日志级别。</p>
|
||||
<a name="ul175714586453"></a><a name="ul175714586453"></a><ul id="ul175714586453"><li>0:对应DEBUG级别。</li><li>1:对应INFO级别。</li><li>2:对应WARNING级别。</li><li>3:对应ERROR级别。</li><li>4:对应NULL级别,不输出日志。</li><li>其他值为非法值。</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row1348192313303"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1734815235305"><a name="p1734815235305"></a><a name="p1734815235305"></a>ASCEND_GLOBAL_EVENT_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p12348202373018"><a name="p12348202373018"></a><a name="p12348202373018"></a>设置应用类日志是否开启Event日志。</p>
|
||||
<a name="ul416352114610"></a><a name="ul416352114610"></a><ul id="ul416352114610"><li>0:不开启Event日志。</li><li>1:开启Event日志。</li><li>其他值为非法值。</li></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17878184693015"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1878194683016"><a name="p1878194683016"></a><a name="p1878194683016"></a>DYNAMIC_COMPILE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p1887894620304"><a name="p1887894620304"></a><a name="p1887894620304"></a>(可选)动态shape特性功能,针对shape变化场景,开启设置为1(PyTorch1.8.1不支持该环境变量)。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row78312162301"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p1832171673019"><a name="p1832171673019"></a><a name="p1832171673019"></a>COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(可选)非连续两个算子组合类场景优化,开启设置为1。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row17630155212342"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p66309527341"><a name="p66309527341"></a><a name="p66309527341"></a>RI_COMBINED_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p19630185220345"><a name="p19630185220345"></a><a name="p19630185220345"></a>(可选)非连续三个算子组合类场景优化,开启设置为1。</p>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p583261643014"><a name="p583261643014"></a><a name="p583261643014"></a>(可选)非连续转连续二级推导优化,可选,开启设置为1。当模型中有大量AsStrided高耗时算子被调用时,可以尝试开启此优化以获得潜在的device执行效率的提升。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row183041355123411"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p730435533415"><a name="p730435533415"></a><a name="p730435533415"></a>ACL_DUMP_DATA</p>
|
||||
@@ -311,255 +194,293 @@
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p16304105533412"><a name="p16304105533412"></a><a name="p16304105533412"></a>(可选)算子数据dump功能,调试时使用,开启设置为1。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row27481914203518"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="p674813144357"><a name="p674813144357"></a><a name="p674813144357"></a>DYNAMIC_OP</p>
|
||||
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16711563237"><a name="zh-cn_topic_0000001152616261_p16711563237"></a><a name="zh-cn_topic_0000001152616261_p16711563237"></a>TASK_QUEUE_ENABLE</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="p974891414353"><a name="p974891414353"></a><a name="p974891414353"></a>(可选)算子实现,ADD和MUL算子在不同场景下有不同的性能表现。默认不设置。</p>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p0711356152317"><a name="zh-cn_topic_0000001152616261_p0711356152317"></a><a name="zh-cn_topic_0000001152616261_p0711356152317"></a>(可选)使用异步任务下发,异步调用acl接口,建议默认开启,开启设置为1。 </p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row19173161510309"><td class="cellrowborder" valign="top" width="55.48%" headers="mcps1.2.3.1.1 "><p id="zh-cn_topic_0000001152616261_p16711563237"><a name="zh-cn_topic_0000001152616261_p16711563237"></a><a name="zh-cn_topic_0000001152616261_p16711563237"></a>unset GOMP_CPU_AFFINITY</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="44.519999999999996%" headers="mcps1.2.3.1.2 "><p id="zh-cn_topic_0000001152616261_p0711356152317"><a name="zh-cn_topic_0000001152616261_p0711356152317"></a><a name="zh-cn_topic_0000001152616261_p0711356152317"></a>(可选)当系统为openEuler及其继承操作系统时,如UOS,需设置此命令,取消CPU绑核。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3 id="安装混合精度模块md">安装混合精度模块</h3>
|
||||
## 执行单元测试脚本
|
||||
|
||||
#### 前提条件<a name="zh-cn_topic_0000001106176190_section3225481020"></a>
|
||||
|
||||
1. 请确保运行环境中适配昇腾AI处理器的PyTorch框架能正常使用。
|
||||
2. 编译安装Apex前,需参见[配置环境变量](#配置环境变量md)配置好编译过程依赖的环境变量。
|
||||
|
||||
#### 安装流程<a name="zh-cn_topic_0000001106176190_section11880164819567"></a>
|
||||
|
||||
1. 以root或非root用户登录服务器。
|
||||
2. 获取apex源代码。
|
||||
|
||||
1. 运行如下命令,获取适配昇腾AI处理器的apex源代码。
|
||||
|
||||
```
|
||||
git clone https://gitee.com/ascend/apex.git
|
||||
```
|
||||
|
||||
下载的源码主要目录结构如下所示:
|
||||
|
||||
```
|
||||
apex
|
||||
│ ├─patch # 昇腾AI处理器适配补丁目录
|
||||
│ ├─npu.patch
|
||||
│ ├─scripts # 编译构建目录
|
||||
│ ├─gen.sh
|
||||
│ ├─src # 源码目录
|
||||
│ ├─tests # 测试用例存放目录
|
||||
```
|
||||
|
||||
2. 运行如下命令,进入“apex“目录,并获取原生apex源代码。
|
||||
|
||||
```
|
||||
cd apex
|
||||
git clone https://github.com/NVIDIA/apex.git
|
||||
```
|
||||
|
||||
下载原生apex源码后,代码主要目录结构如下所示:
|
||||
|
||||
```
|
||||
apex
|
||||
│ ├─apex # 原生apex代码目录
|
||||
│ ├─patch # 昇腾AI处理器适配补丁目录
|
||||
│ ├─npu.patch
|
||||
│ ├─scripts # 编译构建目录
|
||||
│ ├─gen.sh
|
||||
│ ├─src # 源码目录
|
||||
│ ├─tests # 测试用例存放目录
|
||||
```
|
||||
|
||||
3. 进入原生apex代码目录,即“apex/apex“目录。切换至commitid为4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a的代码分支。
|
||||
|
||||
```
|
||||
cd apex
|
||||
git checkout 4ef930c1c884fdca5f472ab2ce7cb9b505d26c1a
|
||||
```
|
||||
|
||||
> **说明:**
|
||||
>受网络波动影响,源码获取时间可能较长,下载过程中请耐心等待。
|
||||
|
||||
3. 编译生成适配昇腾AI处理器的apex安装包。
|
||||
1. 进入“apex/scripts“文件夹,执行转换脚本,生成适配昇腾AI处理器的全量代码。
|
||||
|
||||
```
|
||||
cd ../scripts
|
||||
bash gen.sh
|
||||
```
|
||||
|
||||
将在"apex/apex"目录中生成适配昇腾AI处理器的全量代码。
|
||||
|
||||
2. 进入适配后的全量代码目录,即“apex/apex“目录,编译生成apex的二进制安装包。
|
||||
|
||||
```
|
||||
cd ../apex
|
||||
python3 setup.py --cpp_ext --npu_float_status bdist_wheel
|
||||
```
|
||||
|
||||
Python版本需与PyTorch使用的Python一致,生成的二进制包在当前的dist目录下,即“apex/apex/dist”文件夹目录下。
|
||||
|
||||
4. <a name="zh-cn_topic_0000001106176190_li425495374416"></a>安装apex。
|
||||
|
||||
进入“apex/apex/dist“文件夹目录,执行如下命令安装。
|
||||
|
||||
```
|
||||
pip3 install --upgrade apex-0.1+ascend-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
|
||||
**\{arch\}**表示架构信息,为aarch64或x86\_64。
|
||||
|
||||
> **说明:**
|
||||
>若对环境中的Apex进行升级时,需要先卸载环境中已安装的PyTorch软件包再执行[4. 安装apex。](#zh-cn_topic_0000001106176190_li425495374416)可以通过执行如下命令查询环境上是否已安装PyTorch。
|
||||
>**pip3 list | grep apex**
|
||||
验证运行, 输出结果OK
|
||||
|
||||
|
||||
<h2 id="参考信息md">参考信息</h2>
|
||||
```shell
|
||||
// 根据前述版本,选择对应的测试脚本,以下为1.5.0版本
|
||||
cd ../
|
||||
python3 pytorch1.5.0/test/test_npu/test_network_ops/test_div.py
|
||||
```
|
||||
# 安装混合精度模块(可选)<a name="安装混合精度模块(可选)"></a>
|
||||
|
||||
- **[CMake安装方法](#CMake安装方法md)**
|
||||
请用户根据以下功能需要选择使用,若需要安装Apex模块请参考相关[README文档](https://gitee.com/ascend/apex/tree/v1.5.0/)进行编译安装Apex模块。
|
||||
|
||||
- **[安装7.3.0版本gcc](#安装7-3-0版本gccmd)**
|
||||
- APEX
|
||||
- O1配置模式:Conv,Matmul等使用float16精度计算,其他如softmax、BN使用float32精度。
|
||||
- O2配置模式:除BN使用float32精度外,其他部分使用float16精度。
|
||||
- 静态loss scale:静态设置参数确保混合精度训练收敛。
|
||||
- 动态loss scale:动态计算loss scale的值并判断是否溢出。
|
||||
|
||||
- **[安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配](#安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md)**
|
||||
# FAQ
|
||||
|
||||
|
||||
<h3 id="CMake安装方法md">CMake安装方法</h3>
|
||||
|
||||
CMake版本升级为3.12.1的方法
|
||||
## 在PIP设置为华为源时,安装requirments.txt中的typing依赖后,会导致python环境错误。
|
||||
|
||||
1. 获取Cmake软件包。
|
||||
在PIP设置为华为源时,需打开requirments.txt文件,删除typing依赖,再执行命令。
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.1.tar.gz --no-check-certificate
|
||||
```
|
||||
|
||||
2. 解压并进入软件包目录。
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.1.tar.gz
|
||||
cd cmake-3.12.1/
|
||||
```
|
||||
|
||||
3. 执行配置、编译和安装命令。
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
4. 设置软连接。
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
5. 执行如下命令验证是否安装成功。
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
如显示“cmake version 3.12.1”则表示安装成功。
|
||||
```
|
||||
pip3 install -r requirments.txt
|
||||
```
|
||||
|
||||
|
||||
<h3 id="安装7-3-0版本gccmd">安装7.3.0版本gcc</h3>
|
||||
|
||||
## import torch 报找不到libhccl.so错误
|
||||
|
||||
未配置环境变量,需通过env.sh脚本配置
|
||||
|
||||
```
|
||||
source pytorch/pytorch1.5.0/src/env.sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 编译过程执行bash build.sh报错no module named yaml/typing_extensions.
|
||||
|
||||
pytorch编译依赖 yaml库和typing_extensions库,需要手动安装。
|
||||
|
||||
```
|
||||
pip3 install pyyaml
|
||||
pip3 install typing_extensions
|
||||
```
|
||||
|
||||
安装成功后,注意需要执行make clean在执行bash build.sh进行编译,否则可能因缓存出现未知编译错误。
|
||||
|
||||
|
||||
|
||||
## 运行遇到找不到te问题
|
||||
|
||||
开发态:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/ascend-toolkit/latest/{arch}-linux/lib64 #{arch}为架构名称。
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
用户态:
|
||||
|
||||
```
|
||||
cd /urs/local/Ascend/nnae/latest/{arch}-linux/lib64 #{arch}为架构名称
|
||||
|
||||
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
|
||||
|
||||
pip3 install --upgrade te-0.4.0-py3-none-any.whl
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 命令行安装cmake依赖时提示找不到包、编译cmake报错版本过低,可使用安装脚本或源码编译安装。
|
||||
|
||||
方法一:下载安装脚本安装cmake。(参考cmake官网)
|
||||
|
||||
X86_64环境脚本安装:cmake-3.12.0-Linux-x86_64.sh
|
||||
|
||||
aarch64环境脚本安装:cmake-3.12.0-Linux-aarch64.sh
|
||||
|
||||
1. 执行命令。
|
||||
|
||||
```
|
||||
./cmake-3.12.0-Linux-{arch}.sh #{arch}为架构名称
|
||||
```
|
||||
|
||||
2. 设置软连接。
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
3. 执行如下命令验证是否安装成功。
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
如显示“cmake version 3.12.0”则表示安装成功。
|
||||
|
||||
|
||||
方法二:使用源码编译安装。
|
||||
|
||||
1. 获取Cmake软件包。
|
||||
|
||||
```
|
||||
wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
|
||||
```
|
||||
|
||||
2. 解压并进入软件包目录。
|
||||
|
||||
```
|
||||
tar -xf cmake-3.12.0.tar.gz
|
||||
cd cmake-3.12.0/
|
||||
```
|
||||
|
||||
3. 执行配置、编译和安装命令。
|
||||
|
||||
```
|
||||
./configure --prefix=/usr/local/cmake
|
||||
make && make install
|
||||
```
|
||||
|
||||
4. 设置软连接。
|
||||
|
||||
```
|
||||
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
|
||||
```
|
||||
|
||||
5. 执行如下命令验证是否安装成功。
|
||||
|
||||
```
|
||||
cmake --version
|
||||
```
|
||||
|
||||
如显示“cmake version 3.12.0”则表示安装成功。
|
||||
|
||||
|
||||
|
||||
## 命令行安装gcc依赖时提示找不到包、编译时gcc报错问题
|
||||
|
||||
部分源下载gcc时会提示无法找到包,需要使用源码编译安装。
|
||||
|
||||
以下步骤请在root用户下执行。
|
||||
|
||||
1. 下载gcc-7.3.0.tar.gz,下载地址为[https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz)。
|
||||
2. 安装gcc时候会占用大量临时空间,所以先执行下面的命令清空/tmp目录:
|
||||
1. 下载gcc-7.3.0.tar.gz,下载地址为[https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz](https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz)。
|
||||
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
2. 安装gcc时候会占用大量临时空间,所以先执行下面的命令清空/tmp目录:
|
||||
|
||||
3. 安装依赖(以CentOS和Ubuntu系统为例)。
|
||||
- CentOS执行如下命令安装。
|
||||
```
|
||||
sudo rm -rf /tmp/*
|
||||
```
|
||||
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
3. 安装依赖(以CentOS和Ubuntu系统为例)。
|
||||
|
||||
- Ubuntu执行如下命令安装。
|
||||
- CentOS执行如下命令安装。
|
||||
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
```
|
||||
yum install bzip2
|
||||
```
|
||||
|
||||
4. 编译安装gcc。
|
||||
1. 进入gcc-7.3.0.tar.gz源码包所在目录,解压源码包,命令为:
|
||||
- Ubuntu执行如下命令安装。
|
||||
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
```
|
||||
apt-get install bzip2
|
||||
```
|
||||
|
||||
2. 进入解压后的文件夹,执行如下命令下载gcc依赖包:
|
||||
4. 编译安装gcc。
|
||||
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
1. 进入gcc-7.3.0.tar.gz源码包所在目录,解压源码包,命令为:
|
||||
|
||||
如果执行上述命令报错,需要执行如下命令在“gcc-7.3.0/“文件夹下下载依赖包:
|
||||
```
|
||||
tar -zxvf gcc-7.3.0.tar.gz
|
||||
```
|
||||
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
2. 进入解压后的文件夹,执行如下命令下载gcc依赖包:
|
||||
|
||||
下载好上述依赖包后,重新执行以下命令:
|
||||
```
|
||||
cd gcc-7.3.0
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
如果执行上述命令报错,需要执行如下命令在“gcc-7.3.0/“文件夹下下载依赖包:
|
||||
|
||||
如果上述命令校验失败,需要确保依赖包为一次性下载成功,无重复下载现象。
|
||||
```
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
|
||||
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
|
||||
```
|
||||
|
||||
3. <a name="zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310"></a>执行配置、编译和安装命令:
|
||||
下载好上述依赖包后,重新执行以下命令:
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # 通过grep -w processor /proc/cpuinfo|wc -l查看cpu数,示例为15,用户可自行设置相应参数。
|
||||
make install
|
||||
```
|
||||
```
|
||||
./contrib/download_prerequisites
|
||||
```
|
||||
|
||||
> **须知:**
|
||||
>其中“--prefix“参数用于指定linux\_gcc7.3.0安装路径,用户可自行配置,但注意不要配置为“/usr/local“及“/usr“,因为会与系统使用软件源默认安装的gcc相冲突,导致系统原始gcc编译环境被破坏。示例指定为“/usr/local/linux\_gcc7.3.0“。
|
||||
如果命令校验失败,需要确认上述依赖包在文件夹中的唯一性,无重复下载,若存在重复的依赖包,需删除。
|
||||
|
||||
3. <a name="zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310"></a>执行配置、编译和安装命令:
|
||||
|
||||
```
|
||||
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
|
||||
make -j15 # 通过grep -w processor /proc/cpuinfo|wc -l查看cpu数,示例为15,用户可自行设置相应参数。
|
||||
make install
|
||||
```
|
||||
|
||||
>  **须知:**
|
||||
>其中“--prefix“参数用于指定linux_gcc7.3.0安装路径,用户可自行配置,但注意不要配置为“/usr/local“及“/usr“,因为会与系统使用软件源默认安装的gcc相冲突,导致系统原始gcc编译环境被破坏。示例指定为“/usr/local/linux_gcc7.3.0“。
|
||||
|
||||
4. 修改软连接。
|
||||
|
||||
```
|
||||
ln -s ${install_path}/gcc-7.3.0/bin/gcc /usr/bin/gcc
|
||||
ln -s ${install_path}/gcc-7.3.0/bin/g++ /usr/bin/g++
|
||||
ln -s ${install_path}/gcc-7.3.0/bin/c++ /usr/bin/c++
|
||||
```
|
||||
|
||||
5.配置环境变量。
|
||||
|
||||
当用户执行训练时,需要用到gcc升级后的编译环境,因此要在训练脚本中配置环境变量,通过如下命令配置。
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
|
||||
其中$\{install\_path\}为[3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310)中配置的gcc7.3.0安装路径,本示例为“/usr/local/gcc7.3.0/“。
|
||||
|
||||
> **说明:**
|
||||
>本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。
|
||||
|
||||
若存在pytorch编译不过,请检查软连接的库是否正确。
|
||||
|
||||
libstdc++->libstdc++.so.6.0.24(7.3.0)
|
||||
|
||||
## 找不到libblas.so问题
|
||||
|
||||
环境缺少openblas库,需要安装openblas库
|
||||
|
||||
Centos,EulerOS环境
|
||||
|
||||
```sh
|
||||
yum -y install openblas
|
||||
```
|
||||
|
||||
Ubuntu环境
|
||||
|
||||
```sh
|
||||
apt install libopenblas-dev
|
||||
```
|
||||
|
||||
|
||||
5. 配置环境变量。
|
||||
|
||||
当用户执行训练时,需要用到gcc升级后的编译环境,因此要在训练脚本中配置环境变量,通过如下命令配置。
|
||||
## ARM环境pip安装torchvision失败
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=${install_path}/lib64:${LD_LIBRARY_PATH}
|
||||
```
|
||||
可采用源码安装(需先安装昇腾pytorch并通过env.sh配置环境变量)
|
||||
|
||||
其中$\{install\_path\}为[3.](#zh-cn_topic_0000001135347812_zh-cn_topic_0000001173199577_zh-cn_topic_0000001172534867_zh-cn_topic_0276688294_li1649343041310)中配置的gcc7.3.0安装路径,本示例为“/usr/local/gcc7.3.0/“。
|
||||
```
|
||||
git clone -b v0.6.0 https://github.com/pytorch/vision.git
|
||||
cd vision
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
> **说明:**
|
||||
>本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。
|
||||
验证torchvision是否安装成功
|
||||
|
||||
```
|
||||
python -c "import torchvision"
|
||||
```
|
||||
|
||||
<h3 id="安装-torch--whl-提示-torch-1-5-0xxxx-与-torchvision-所依赖的版本不匹配md">安装“torch-\*.whl ”提示“torch 1.5.0xxxx”与“torchvision”所依赖的版本不匹配</h3>
|
||||
若不报错,则说明安装成功
|
||||
|
||||
#### 现象描述<a name="zh-cn_topic_0000001105856364_zh-cn_topic_0175549220_section197270431505"></a>
|
||||
|
||||
安装“torch-\*.whl”时,提示"ERROR:torchvision 0.6.0 has requirement torch==1.5.0, but you'll have torch 1.5.0a0+1977093 which is incompatible"。
|
||||
|
||||

|
||||
|
||||
#### 可能原因<a name="zh-cn_topic_0000001105856364_zh-cn_topic_0175549220_section169499490501"></a>
|
||||
|
||||
安装torch时,会自动触发torchvision进行依赖版本检查,环境中安装的torchvision版本为0.6.0,检查时发现我们安装的torch-\*.whl的版本号与要求的1.5.0不一致,所以提示报错,但实际安装成功 。
|
||||
|
||||
#### 处理方法<a name="zh-cn_topic_0000001105856364_section108142031907"></a>
|
||||
|
||||
对实际结果无影响,无需处理。
|
||||
# 版本说明<a name='版本说明'></a>
|
||||
|
||||
版本说明请参阅[ReleseNote](https://gitee.com/ascend/pytorch/blob/v1.5.0/docs/zh/RELEASENOTE/RELEASENOTE.md)
|
||||
|
||||
@@ -714,12 +714,12 @@ pytorch分布式训练基本概念
|
||||
3. 在每台服务器上分别打开**/etc/hosts**文件,在该文件中添加本服务器对应的IP地址和主机名,且需要添加到该文件的首行。如果文件中已添加,则跳过此步骤。添加内容示例如下:
|
||||
|
||||
```
|
||||
10.90.140.199 ubuntu
|
||||
xxx.xxx.xxx.111 ubuntu
|
||||
```
|
||||
|
||||
其中10.90.140.199为该服务器的IP地址,ubuntu为主机名。
|
||||
其中xxx.xxx.xxx.111为该服务器的IP地址,ubuntu为主机名。
|
||||
|
||||
4. 在第一台服务器执行如下命令生成公钥(例如第一台服务器IP为10.90.140.199)。
|
||||
4. 在第一台服务器执行如下命令生成公钥(例如第一台服务器IP为xxx.xxx.xxx.111)。
|
||||
|
||||
```
|
||||
cd ~/.ssh/ # 若没有该目录,请先执行一次ssh localhost
|
||||
@@ -748,7 +748,7 @@ pytorch分布式训练基本概念
|
||||
6. 在其他每台服务器上执行如下命令将第一台服务器制作好的公钥复制到其他每台服务器内。
|
||||
|
||||
cd ~/.ssh/
|
||||
scp root@10.90.140.199:~/.ssh/authorized_keys ./
|
||||
scp root@xxx.xxx.xxx.111:~/.ssh/authorized_keys ./
|
||||
|
||||
7. 在每台服务器执行如下命令测试免密登录。
|
||||
|
||||
@@ -756,9 +756,9 @@ pytorch分布式训练基本概念
|
||||
ssh 用户名@IP地址
|
||||
```
|
||||
|
||||
例如:在第一台服务器10.90.140.199免密登录服务器10.90.140.231,执行**ssh root@10.90.140.231**命令。
|
||||
例如:在第一台服务器xxx.xxx.xxx.111免密登录服务器xxx.xxx.xxx.222,执行**ssh root@xxx.xxx.xxx.222**命令。
|
||||
|
||||
若显示类似如下信息,说明已免密登录服务器10.90.140.231。
|
||||
若显示类似如下信息,说明已免密登录服务器xxx.xxx.xxx.222。
|
||||
|
||||
```
|
||||
Linux ubuntu 4.19.28 #1 SMP Tue Jun 23 19:05:23 EDT 2020 x86_64
|
||||
@@ -776,7 +776,7 @@ pytorch分布式训练基本概念
|
||||
|
||||
```
|
||||
logout
|
||||
Connection to 10.90.140.231 closed.
|
||||
Connection to xxx.xxx.xxx.222 closed.
|
||||
```
|
||||
|
||||
3. 使用OpenMPI拉起模型训练。
|
||||
@@ -845,7 +845,8 @@ if [ -d ${install_path}/toolkit ]; then
|
||||
export ASCEND_OPP_PATH=${install_path}/opp
|
||||
else
|
||||
if [ -d ${install_path}/nnae/latest ];then
|
||||
exportLD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH
|
||||
export
|
||||
LD_LIBRARY_PATH=/usr/local/:/usr/local/python3.7.5/lib/:/usr/local/openblas/lib:/usr/local/lib/:/usr/lib64/:/usr/lib/:${install_path}/nnae/latest/fwkacllib/lib64/:${install_path}/driver/lib64/common/:${install_path}/driver/lib64/driver/:${install_path}/add-ons/:/usr/lib/aarch64_64-linux-gnu:$LD_LIBRARY_PATH
|
||||
export PATH=$PATH:${install_path}/nnae/latest/fwkacllib/ccec_compiler/bin/:${install_path}/nnae/latest/toolkit/tools/ide_daemon/bin/
|
||||
export ASCEND_OPP_PATH=${install_path}/nnae/latest/opp/
|
||||
export OPTION_EXEC_EXTERN_PLUGIN_PATH=${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libfe.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libaicpu_engine.so:${install_path}/nnae/latest/fwkacllib/lib64/plugin/opskernel/libge_local_engine.so
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
- [注册算子开发](#注册算子开发md)
|
||||
- [概述](#概述md)
|
||||
- [PyTorch1.5.0 注册算子开发](#PyTorch1-5-0-注册算子开发md)
|
||||
- [PyTorch1.8.1 注册算子开发](#PyTorch1-8-1-注册算子开发md)
|
||||
- [算子适配插件开发](#算子适配插件开发md)
|
||||
- [编译和安装PyTorch框架](#编译和安装PyTorch框架md)
|
||||
- [算子功能验证](#算子功能验证md)
|
||||
@@ -136,7 +135,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
- 需安装3.12.0及以上版本的CMake,安装方法请参考[CMake安装方法](#CMake安装方法md)。
|
||||
- 需确保已安装7.3.0以上版本的gcc,7.3.0版本gcc具体安装及使用方式请参见《CANN 软件安装指南》中的“安装7.3.0版本gcc”章节。
|
||||
- 需确保环境中已安装git工具,以Ubuntu和CentOS系统为例,命令如下:
|
||||
- Ubuntu系统
|
||||
- Ubuntu、EulerOS系统
|
||||
|
||||
```
|
||||
apt-get install patch
|
||||
@@ -165,8 +164,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
- 当前昇腾AI处理器中支持的算子以及对应的算子约束可以通过以下两种方式查询。
|
||||
- 命令行开发方式下,您可以参见《CANN 算子清单 \(Ascend 910\)》进行离线查询。
|
||||
- MindStudio开发方式下,您可以通过MindStudio进行在线查询,详细查看方法可参见《MindStudio 用户指南》中的“算子&模型速查”章节。
|
||||
|
||||
- 当前PyTorch适配的算子列表可以参见《PyTorch适配算子清单》。
|
||||
- 当前PyTorch适配的算子列表可以参见[《PyTorch API支持清单_1.5.0》](https://gitee.com/ascend/pytorch/blob/v1.5.0/docs/zh/PyTorch%20API%E6%94%AF%E6%8C%81%E6%B8%85%E5%8D%95_1.5.0.md) 。
|
||||
|
||||
<h2 id="算子适配开发md">算子适配开发</h2>
|
||||
|
||||
@@ -188,20 +186,19 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
|
||||
<h3 id="获取PyTorch源码md">获取PyTorch源码</h3>
|
||||
|
||||
目前只支持PyTorch1.5.0和1.8.1版本,PyTorch源码获取请参见《PyTorch安装指南》中“安装PyTorch框架”章节,完成在"pytorch/pytorch"目录生成适配昇腾AI处理器的全量代码步骤。将在pytorch/pytorch目录中进行PyTorch 算子适配开发。
|
||||
目前只支持PyTorch1.5.0和1.8.1版本,PyTorch源码获取请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/v1.5.0/docs/zh/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97/PyTorch%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97.md) 中“安装PyTorch框架”章节,完成在"pytorch/pytorch"目录生成适配昇腾AI处理器的全量代码步骤。将在pytorch/pytorch目录中进行PyTorch 算子适配开发。
|
||||
|
||||
<h3 id="注册算子开发md">注册算子开发</h3>
|
||||
|
||||
- **[概述](#概述md)**
|
||||
|
||||
- **[PyTorch1.5.0 注册算子开发](#PyTorch1-5-0-注册算子开发md)**
|
||||
- **[PyTorch1.5.0 注册算子开发](#PyTorch1-5-0-注册算子开发md)**
|
||||
|
||||
- **[PyTorch1.8.1 注册算子开发](#PyTorch1-8-1-注册算子开发md)**
|
||||
|
||||
|
||||
<h4 id="概述md">概述</h4>
|
||||
|
||||
当前制定的NPU适配派发原则是NPU算子的派发不经过框架公共函数,直接派发成NPU适配的函数,即算子执行调用栈中只包含NPU适配的函数调用,不包含框架公共函数。PyTorch框架在编译时,会根据 native\_functions.yaml 的定义,按框架中定义的类型和设备分发原则,生成相应的新算子的中间层的调用说明。对于NPU,会生成在 build/aten/src/ATen/NPUType.cpp。
|
||||
当前制定的NPU适配派发原则是NPU算子的派发不经过框架公共函数,直接派发成NPU适配的函数,即算子执行调用栈中只包含NPU适配的函数调用,不包含框架公共函数。PyTorch框架在编译时,会根据 native\_functions.yaml 的定义,按框架中定义的类型和设备分发原则,生成相应的新算子的中间层的调用说明。对于NPU,会生成在 pytorch/pytorch/build/aten/src/ATen/NPUType.cpp。
|
||||
|
||||
<h4 id="PyTorch1-5-0-注册算子开发md">PyTorch1.5.0 注册算子开发</h4>
|
||||
|
||||
@@ -333,96 +330,6 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
supports_named_tensor: True
|
||||
```
|
||||
|
||||
|
||||
|
||||
<h4 id="PyTorch1-8-1-注册算子开发md">PyTorch1.8.1 注册算子开发</h4>
|
||||
|
||||
##### 注册算子开发方法<a name="section575212111125"></a>
|
||||
|
||||
1. 打开native\_functions.yaml文件。
|
||||
|
||||
native\_functions.yaml 文件中,定义了所有算子函数原型,包括函数名称和参数等信息,每个算子函数支持不同硬件平台的派发信息。该文件所在路径为pytorch/aten/src/ATen/native/native\_functions.yaml。
|
||||
|
||||
2. 确定需要派发函数。
|
||||
- yaml 中已存在的算子
|
||||
|
||||
将所有与待适配算子相关的函数进行派发。
|
||||
|
||||
- yaml中未存在的自定义算子
|
||||
|
||||
由于yaml中没有相关算子的信息,需要手动添加相关函数,包括函数名,参数信息,返回类型信息。添加规则及方法请参见“pytorch/aten/src/ATen/native/README.md“。
|
||||
|
||||
```
|
||||
- func:适配算子名称(输入参数信息) -> 返回类型
|
||||
```
|
||||
|
||||
|
||||
|
||||
##### 示例<a name="section434031421219"></a>
|
||||
|
||||
以torch.add\(\)算子为例介绍注册算子开发过程。
|
||||
|
||||
1. 打开native\_functions.yaml文件。
|
||||
2. 搜索相关函数。
|
||||
|
||||
在yaml中搜索add,找到与add算子相关的函数描述func。由于add是PyTorch内置算子,不需要手动添加func。若是自定义算子,需要手动添加func。
|
||||
|
||||
3. 确定算子相关函数名称及其类型的func描述。
|
||||
- add.Tensor 的函数分发描述。
|
||||
|
||||
```
|
||||
- func: add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
|
||||
structured_delegate: add.out
|
||||
variants: function, method
|
||||
dispatch:
|
||||
SparseCPU, SparseCUDA: add_sparse
|
||||
MkldnnCPU: mkldnn_add
|
||||
```
|
||||
|
||||
- add.Scalar 的函数分发描述。
|
||||
|
||||
```
|
||||
- func: add.Scalar(Tensor self, Scalar other, Scalar alpha=1) -> Tensor
|
||||
variants: function, method
|
||||
dispatch:
|
||||
DefaultBackend: add
|
||||
```
|
||||
|
||||
- add\_.Tensor 的函数分发描述。
|
||||
|
||||
```
|
||||
- func: add_.Tensor(Tensor(a!) self, Tensor other, *, Scalar alpha=1) -> Tensor(a!)
|
||||
variants: method
|
||||
structured_delegate: add.out
|
||||
dispatch:
|
||||
SparseCPU, SparseCUDA: add_sparse_
|
||||
MkldnnCPU: mkldnn_add_
|
||||
```
|
||||
|
||||
- add\_.Scalar 的函数分发描述。
|
||||
|
||||
```
|
||||
- func: add_.Scalar(Tensor(a!) self, Scalar other, Scalar alpha=1) -> Tensor(a!)
|
||||
variants: method
|
||||
dispatch:
|
||||
DefaultBackend: add_
|
||||
```
|
||||
|
||||
- add.out 的函数分发描述。
|
||||
|
||||
```
|
||||
- func: add.out(Tensor self, Tensor other, *, Scalar alpha=1, Tensor(a!) out) -> Tensor(a!)
|
||||
structured: True
|
||||
structured_inherits: TensorIteratorBase
|
||||
dispatch:
|
||||
CPU, CUDA: add_out
|
||||
SparseCPU: add_out_sparse_cpu
|
||||
SparseCUDA: add_out_sparse_cuda
|
||||
MkldnnCPU: mkldnn_add_out
|
||||
```
|
||||
|
||||
|
||||
|
||||
<h3 id="算子适配插件开发md">算子适配插件开发</h3>
|
||||
|
||||
#### 简介<a name="zh-cn_topic_0000001125315877_section16410139174517"></a>
|
||||
@@ -433,7 +340,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
|
||||
1. 创建适配插件文件。
|
||||
|
||||
NPU TBE算子适配文件保存在pytorch/aten/src/ATen/native/npu目录下,命名风格采用大驼峰,命名格式:<算子名\> + <KernelNpu\>.cpp,如:AddKernelNpu.cpp。
|
||||
NPU TBE算子适配文件保存在pytorch/pytorch/aten/src/ATen/native/npu目录下,命名风格采用大驼峰,命名格式:<算子名\> + <KernelNpu\>.cpp,如:AddKernelNpu.cpp。
|
||||
|
||||
2. 引入依赖头文件。
|
||||
|
||||
@@ -446,24 +353,10 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
|
||||
根据注册算子开发中的分发函数确定自定义算子适配主体函数。
|
||||
|
||||
4. 分别实现适配主体函数。
|
||||
4. 分别实现适配主体函数。
|
||||
|
||||
实现算子适配主题函数,根据TBE算子原型构造得到对应的input、output、attr。
|
||||
实现算子适配主题函数,根据TBE算子原型构造得到对应的input、output、attr。
|
||||
|
||||
5. (仅1.8.1版本需要操作该步骤)使用TORCH\_LIBRARY\_IMPL宏关联注册算子开发中native\_functions.yaml文件的算子描述func。
|
||||
|
||||
TORCH\_LIBRARY\_IMPL是PyTorch提供的用于注册算子分发的宏,使用方法如下。
|
||||
|
||||
```
|
||||
Torch_LIBRARY_IMPL(aten, PrivateUse1, m){
|
||||
m.impl("yaml中算子func方法名1", TORCH_FN("对应的适配主体函数名1"))
|
||||
m.impl("yaml中算子func方法名2", TORCH_FN("对应的适配主体函数名2"))
|
||||
}
|
||||
```
|
||||
|
||||
- aten为命名空间,可以根据实现文件命名空间自行定义。
|
||||
- PrivateUse1为dispatchKey, 固定设置NPU。
|
||||
- m为固定字段。
|
||||
|
||||
|
||||
#### 示例<a name="zh-cn_topic_0000001125315877_section18021337113012"></a>
|
||||
@@ -618,14 +511,6 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
}
|
||||
```
|
||||
|
||||
5. (仅1.8.1版本需要操作该步骤)使用TORCH\_LIBRARY\_IMPL宏关联注册算子。
|
||||
|
||||
```
|
||||
TORCH_LIBRARY_IMPL(aten, NPU, m) {
|
||||
m.impl("add.Tensor", TORCH_FN(add_npu));
|
||||
m.impl("add_.Tensor", TORCH_FN(add_npu_));
|
||||
m.impl("add.out", TORCH_FN(add_out_npu));}
|
||||
```
|
||||
|
||||
|
||||
> **说明:**
|
||||
@@ -650,7 +535,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
bash build.sh --python=3.8
|
||||
```
|
||||
|
||||
请指定环境中python版本进行编译。编译成功后,会在pytorch/pytorch/dist”文件夹目录下生成二进制包 torch-\*.whl ,例如:torch-1.5.0+ascend.post3-cp37-cp37m-linux\_x86.whl或者torch-1.8.1+ascend-cp37-cp37m-linux\_x86.whl。
|
||||
请指定环境中python版本进行编译。编译成功后,会在pytorch/pytorch/dist”文件夹目录下生成二进制包 torch-\*.whl ,例如:torch-1.5.0+ascend.post3-cp37-cp37m-linux\_x86.whl。
|
||||
|
||||
|
||||
#### 安装PyTorch框架<a name="zh-cn_topic_0000001125736777_section119821419153412"></a>
|
||||
@@ -664,7 +549,9 @@ pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
|
||||
**\{arch\}**表示架构信息,为aarch64或x86\_64。
|
||||
|
||||
> **说明:**
|
||||
>若环境中已安装PyTorch时,需要先卸载环境中已安装的PyTorch软件包再执行,可以通过执行如下命令查询环境上是否已安装PyTorch。
|
||||
>--upgrade:卸载环境中已安装的PyTorch插件软件包再执行更新安装。
|
||||
>
|
||||
>可以通过执行如下命令查询环境上是否已安装PyTorch。
|
||||
>**pip3 list | grep torch**
|
||||
|
||||
修改代码之后,需要重新执行“编译”和“安装”PyTorch过程。
|
||||
@@ -688,7 +575,7 @@ pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
|
||||
|
||||
进行自定义算子功能验证,通过PyTorch前端构造自定义算子的函数并运行验证。
|
||||
|
||||
在https://gitee.com/ascend/pytorch中 "pytorch/test/test\_npu"目录下提供了测试用例及测试工具,供用户参考。
|
||||
在https://gitee.com/ascend/pytorch 中 "pytorch/pytorch1.5..0/test/test\_npu"目录下提供了测试用例及测试工具,供用户参考。
|
||||
|
||||
<h3 id="实现过程md">实现过程</h3>
|
||||
|
||||
@@ -698,12 +585,14 @@ pip3 install --upgrade torch-1.5.0+ascend.post3-cp37-cp37m-linux_{arch}.whl
|
||||
|
||||
#### 操作步骤<a name="zh-cn_topic_0000001164276377_section02504494109"></a>
|
||||
|
||||
1. 设置环境变量。
|
||||
1. 设置环境变量。
|
||||
|
||||
```
|
||||
# 进行环境变量设置。具体如下(以HwHiAiUser用户安装,安装路径为默认路径为例):
|
||||
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
|
||||
```
|
||||
```
|
||||
# 进行环境变量设置。具体如下(以root用户安装,安装路径为默认路径为例):
|
||||
usr/local/Ascend/ascend-toolkit/set_env.sh
|
||||
# 进行环境变量设置。具体如下(以非root用户安装,安装路径为默认路径为例):
|
||||
${HOME}/Ascend/ascend-toolkit/set_env.sh
|
||||
```
|
||||
|
||||
2. 编写测试脚本。以add算子为例,在“pytorch/test/test\_npu/test\_network\_ops“路径下编写测试脚本文件: test\_add.py。
|
||||
|
||||
@@ -802,7 +691,9 @@ pillow==5.3.0安装失败。
|
||||
执行以下命令安装所需依赖。
|
||||
|
||||
```
|
||||
apt-get install libjpeg python-devel zlib-devel libjpeg-turbo-devel
|
||||
apt-get install libjpeg python-devel zlib-devel libjpeg-turbo-devel #Ubuntu、EulerOS
|
||||
|
||||
yum install libjpeg python-devel zlib-devel libjpeg-turbo-devel #CentOS
|
||||
```
|
||||
|
||||
<h3 id="pip3-7-install-torchvision安装失败md">pip3.7 install torchvision安装失败</h3>
|
||||
@@ -847,13 +738,15 @@ pip3.7 install torchvision --no-deps
|
||||
|
||||
设置日志输出到屏幕,重定向到指定文本文件
|
||||
|
||||
1. 设置环境变量,将当前用户的日志到屏幕。
|
||||
1. 设置环境变量,将当前用户的日志到屏幕。
|
||||
|
||||
```
|
||||
export SLOG_PRINT_TO_STDOUT=1
|
||||
```
|
||||
```
|
||||
export SLOG_PRINT_TO_STDOUT=1
|
||||
export ASCEND_GLOBAL_LOG_LEVEL=1
|
||||
#0:debug等级;1:info;2:warning;3:error
|
||||
```
|
||||
|
||||
设置完成后,直接运行测试用例,就可以将相关的日志输出到屏幕,为了方便查看和回溯,建议根据需要使用[2](#zh-cn_topic_0000001125315889_li168732325719)运行。
|
||||
设置完成后,直接运行测试用例,就可以将相关的日志输出到屏幕,为了方便查看和回溯,建议根据需要使用[2](#zh-cn_topic_0000001125315889_li168732325719)运行。
|
||||
|
||||
2. <a name="zh-cn_topic_0000001125315889_li168732325719"></a>运行测试用例时,将日志重定向到指定文件。
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 36 KiB |
@@ -1,5 +1,19 @@
|
||||
# FrameworkPTAdapter 2.0.4 版本说明书
|
||||
- [FrameworkPTAdapter 2.0.4](#FrameworkPTAdapter-2-0-3md)
|
||||
# FrameworkPTAdapter 3.0.RC2 版本说明书
|
||||
- [FrameworkPTAdapter 3.0.RC2](#FrameworkPTAdapter-3-0-RC2md)
|
||||
- [用户须知](#用户须知md)
|
||||
- [新增特性](#新增特性md)
|
||||
- [特性修改](#特性修改md)
|
||||
- [已修复问题](#已修复问题md)
|
||||
- [已知问题](#已知问题md)
|
||||
- [兼容性](#兼容性md)
|
||||
- [FrameworkPTAdapter 3.0.RC1](#FrameworkPTAdapter-3-0-RC1md)
|
||||
- [用户须知](#用户须知md)
|
||||
- [新增特性](#新增特性md)
|
||||
- [特性修改](#特性修改md)
|
||||
- [已修复问题](#已修复问题md)
|
||||
- [已知问题](#已知问题md)
|
||||
- [兼容性](#兼容性md)
|
||||
- [FrameworkPTAdapter 2.0.4](#FrameworkPTAdapter-2-0-4md)
|
||||
- [用户须知](#用户须知md)
|
||||
- [新增特性](#新增特性md)
|
||||
- [特性修改](#特性修改md)
|
||||
@@ -21,7 +35,238 @@
|
||||
- [已知问题](#已知问题-4md)
|
||||
- [兼容性](#兼容性-5md)
|
||||
|
||||
<h2 id="FrameworkPTAdapter-2-0-3md">FrameworkPTAdapter 2.0.4</h2>
|
||||
<h2 id="FrameworkPTAdapter-3-0-RC2md">FrameworkPTAdapter 3.0.RC2</h2>
|
||||
|
||||
|
||||
<h3 id="用户须知md">用户须知</h3>
|
||||
|
||||
本框架基于Facebook主导的开源PyTorch1.5.0和1.8.1版本进行修改,延续原生的PyTorch特性,使用NPU进行动态图训练;以算子粒度进行模型适配,代码重用性好,支持现有的网络只修改设备类型或数据类型,即可迁移到NPU上使用。
|
||||
|
||||
PyTorch1.8.1版本采用插件化适配方式,与原生PyTorch框架实现彻底解耦,当前功能、性能与PyTorch1.5.0基本保持一致,对后端算子适配提供较好开发体验。
|
||||
支持AOE调优工具。
|
||||
|
||||
<h3 id="新增特性md">新增特性</h3>
|
||||
|
||||
**表 1** PyTorch支持的版本特性列表
|
||||
|
||||
<a name="t76c34275cbb74753970f7c5a9eb594fa"></a>
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>一级特性</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>二级特性</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>说明</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="2" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>适配NPU的PyTorch1.5.0特性</p>
|
||||
</td>
|
||||
</tr>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a> 框架基础功能。</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a> 少量BUG修复。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="3" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>适配NPU的PyTorch1.8.1特性</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>插件化解耦</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>torch_npu插件与原生PyTorch框架实现彻底解耦。</p>
|
||||
</td>
|
||||
<tr>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>性能优化</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>优化单算子下发以及集合通讯功能</p>
|
||||
</td>
|
||||
</tr>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>API满足度提升。</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>新增部分API适配(详情见API清单)。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="特性修改md">特性修改</h3>
|
||||
|
||||
不涉及
|
||||
|
||||
<h3 id="已修复问题md">已修复问题</h3>
|
||||
|
||||
不涉及
|
||||
|
||||
<h3 id="已知问题md">已知问题</h3>
|
||||
|
||||
<a name="table1969972073016"></a>
|
||||
|
||||
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>已知问题</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>问题描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>数据类型支持</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPU不支持float16类型的inf/nan数据输入输出。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>数据Format</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>出现4D以上的format时不能降维。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>集合通信约束</p>
|
||||
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>要求一次训练任务中不同device上执行的图相同。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>当前只支持1/2/4/8P粒度的分配。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>只支持int8,int32,float16和float32数据类型。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex功能支持</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>Apex当前版本的实现方式主要为python实现,不支持APEX中的自定义优化CUDA Kernel。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="兼容性md">兼容性</h3>
|
||||
|
||||
A800-9010:CentOS 7.6/Ubuntu 18.04, 2.04/BC-Linux 7.6/Debian 9.9/Debian 10/OpenEuler 20.03 LTS
|
||||
|
||||
A800-9000:CentOS 7.6/Ubuntu 18.04, 2.04/Euler 2.8, 2.10/Kylin v10/BC-Linux 7.6/OpenEuler 20.03 LTS/UOS 20 1020e
|
||||
|
||||
<h2 id="FrameworkPTAdapter-3-0-RC1md">FrameworkPTAdapter 3.0.RC1</h2>
|
||||
|
||||
|
||||
<h3 id="用户须知md">用户须知</h3>
|
||||
|
||||
本框架基于Facebook主导的开源PyTorch1.5.0和1.8.1版本进行修改,延续原生的PyTorch特性,使用NPU进行动态图训练;以算子粒度进行模型适配,代码重用性好,支持现有的网络只修改设备类型或数据类型,即可迁移到NPU上使用。
|
||||
|
||||
PyTorch1.8.1版本采用插件化适配方式,延续PyTorch1.5.0特性,功能基本保持一致,对后端算子适配提供较好开发体验。
|
||||
支持AOE调优工具。
|
||||
|
||||
<h3 id="新增特性md">新增特性</h3>
|
||||
|
||||
**表 1** PyTorch支持的版本特性列表
|
||||
|
||||
<a name="t76c34275cbb74753970f7c5a9eb594fa"></a>
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="10.459999999999999%" id="mcps1.2.4.1.1"><p id="a7888762cf8294977b7d114b1c898d1bd"><a name="a7888762cf8294977b7d114b1c898d1bd"></a><a name="a7888762cf8294977b7d114b1c898d1bd"></a>一级特性</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="26.27%" id="mcps1.2.4.1.2"><p id="a4581ffde4a5f455faadfba144243a9d4"><a name="a4581ffde4a5f455faadfba144243a9d4"></a><a name="a4581ffde4a5f455faadfba144243a9d4"></a>二级特性</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="63.27%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>说明</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="2" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>适配NPU的PyTorch1.5.0特性</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>支持AOE调优工具</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>支持AOE自动调优工具,提升模型性能。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13971435754"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79831331353"><a name="p79831331353"></a><a name="p79831331353"></a>框架基础功能</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p109832331055"><a name="p109832331055"></a><a name="p109832331055"></a> 新增适配算子开发(详见API清单)。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row7979351559"><td class="cellrowborder" rowspan="3" valign="top" width="10.459999999999999%" headers="mcps1.2.4.1.1 "><p id="p69836331553"><a name="p69836331553"></a><a name="p69836331553"></a>适配NPU的PyTorch1.8.1特性</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>插件化解耦</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>将NPU适配代码解耦迁移至torch_npu插件,实现昇腾适配代码与PyTorch原生代码解耦。</p>
|
||||
</td>
|
||||
<tr>
|
||||
<td class="cellrowborder" valign="top" width="26.27%" headers="mcps1.2.4.1.2 "><p id="p149831333357"><a name="p149831333357"></a><a name="p149831333357"></a>支持AOE调优工具</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="63.27%" headers="mcps1.2.4.1.3 "><p id="p1398313336511"><a name="p1398313336511"></a><a name="p1398313336511"></a>支持AOE自动调优工具,提升模型性能。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row109719353511"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p18983183315515"><a name="p18983183315515"></a><a name="p18983183315515"></a>框架API满足度提升</p>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p836221112812"><a name="p836221112812"></a><a name="p836221112812"></a>支持昇腾PyTorch1.5.0版本已适配API(详情见API清单)。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 id="特性修改md">特性修改</h3>
|
||||
|
||||
不涉及
|
||||
|
||||
<h3 id="已修复问题md">已修复问题</h3>
|
||||
|
||||
不涉及
|
||||
|
||||
<h3 id="已知问题md">已知问题</h3>
|
||||
|
||||
<a name="table1969972073016"></a>
|
||||
|
||||
<table><thead align="left"><tr id="row3699162017307"><th class="cellrowborder" valign="top" width="18.22%" id="mcps1.1.3.1.1"><p id="p16992020153010"><a name="p16992020153010"></a><a name="p16992020153010"></a>已知问题</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="81.78%" id="mcps1.1.3.1.2"><p id="p269919203308"><a name="p269919203308"></a><a name="p269919203308"></a>问题描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row9699142003011"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1769932017300"><a name="p1769932017300"></a><a name="p1769932017300"></a>数据类型支持</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p13699152010301"><a name="p13699152010301"></a><a name="p13699152010301"></a>NPU不支持float16类型的inf/nan数据输入输出。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row146991520153016"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p156997200308"><a name="p156997200308"></a><a name="p156997200308"></a>数据Format</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p10699182020308"><a name="p10699182020308"></a><a name="p10699182020308"></a>出现4D以上的format时不能降维。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row11121205610549"><td class="cellrowborder" rowspan="3" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p1647216219558"><a name="p1647216219558"></a><a name="p1647216219558"></a>集合通信约束</p>
|
||||
<p id="p0465121912402"><a name="p0465121912402"></a><a name="p0465121912402"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p3116115695415"><a name="p3116115695415"></a><a name="p3116115695415"></a>要求一次训练任务中不同device上执行的图相同。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row51211656105411"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p1311616560541"><a name="p1311616560541"></a><a name="p1311616560541"></a>当前只支持1/2/4/8P粒度的分配。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row8647195765419"><td class="cellrowborder" valign="top" headers="mcps1.1.3.1.1 "><p id="p2064225716544"><a name="p2064225716544"></a><a name="p2064225716544"></a>只支持int8,int32,float16和float32数据类型。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row4646195719548"><td class="cellrowborder" valign="top" width="18.22%" headers="mcps1.1.3.1.1 "><p id="p4642195718541"><a name="p4642195718541"></a><a name="p4642195718541"></a>Apex功能支持</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="81.78%" headers="mcps1.1.3.1.2 "><p id="p864205725412"><a name="p864205725412"></a><a name="p864205725412"></a>Apex当前版本的实现方式主要为python实现,不支持APEX中的自定义优化CUDA Kernel。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<h3 id="兼容性md">兼容性</h3>
|
||||
|
||||
A800-9010:CentOS 7.6/Ubuntu 18.04, 2.04/BC-Linux 7.6/Debian 9.9/Debian 10/OpenEuler 20.03 LTS
|
||||
|
||||
A800-9000:CentOS 7.6/Ubuntu 18.04, 2.04/Euler 2.8, 2.10/Kylin v10/BC-Linux 7.6/OpenEuler 20.03 LTS/UOS 20 1020e
|
||||
|
||||
<h2 id="FrameworkPTAdapter-2-0-4md">FrameworkPTAdapter 2.0.4</h2>
|
||||
|
||||
|
||||
<h3 id="用户须知md">用户须知</h3>
|
||||
|
||||
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 394 B After Width: | Height: | Size: 394 B |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 406 B |
|
Before Width: | Height: | Size: 253 B After Width: | Height: | Size: 253 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 44 KiB |
@@ -116,9 +116,7 @@ class TestMgr():
|
||||
for ut in self.ut_files:
|
||||
if ut.split('/')[-1] == 'run_tests.py':
|
||||
self.ut_files.remove(ut)
|
||||
|
||||
if len(self.ut_files) == 0:
|
||||
self.ut_files.append(DEFAULT_UT_FILE)
|
||||
self.ut_files.append(DEFAULT_UT_FILE)
|
||||
|
||||
def get_ut_files(self):
|
||||
return self.ut_files
|
||||
@@ -192,10 +190,6 @@ def main():
|
||||
test_mgr.print_ut_files()
|
||||
|
||||
ret = exec_ut(ut_files)
|
||||
if ret and DEFAULT_UT_FILE not in ut_files:
|
||||
print("***** start resnet18:")
|
||||
os.chdir(cur_dir)
|
||||
exec_ut([DEFAULT_UT_FILE])
|
||||
sys.exit(ret)
|
||||
|
||||
|
||||
|
||||
@@ -1769,8 +1769,6 @@
|
||||
# `align_corners = True`.
|
||||
- func: grid_sampler(Tensor input, Tensor grid, int interpolation_mode, int padding_mode, bool align_corners) -> Tensor
|
||||
use_c10_dispatcher: full
|
||||
npu_dispatch:
|
||||
NPU: grid_sampler_npu
|
||||
|
||||
- func: grid_sampler_2d(Tensor input, Tensor grid, int interpolation_mode, int padding_mode, bool align_corners) -> Tensor
|
||||
use_c10_dispatcher: full
|
||||
@@ -3734,6 +3732,8 @@
|
||||
dispatch:
|
||||
CPU: unique_consecutive_cpu
|
||||
CUDA: unique_consecutive_cuda
|
||||
npu_dispatch:
|
||||
NPU: unique_consecutive_npu
|
||||
|
||||
- func: unique_dim_consecutive(Tensor self, int dim, bool return_inverse=False, bool return_counts=False) -> (Tensor, Tensor, Tensor)
|
||||
variants: function
|
||||
@@ -4691,7 +4691,9 @@
|
||||
- func: rnn_relu.data(Tensor data, Tensor batch_sizes, Tensor hx, Tensor[] params, bool has_biases, int num_layers, float dropout, bool train, bool bidirectional) -> (Tensor, Tensor)
|
||||
|
||||
- func: lstm_cell(Tensor input, Tensor[] hx, Tensor w_ih, Tensor w_hh, Tensor? b_ih=None, Tensor? b_hh=None) -> (Tensor, Tensor)
|
||||
|
||||
npu_dispatch:
|
||||
NPU: lstm_cell_npu
|
||||
|
||||
- func: gru_cell(Tensor input, Tensor hx, Tensor w_ih, Tensor w_hh, Tensor? b_ih=None, Tensor? b_hh=None) -> Tensor
|
||||
|
||||
- func: rnn_tanh_cell(Tensor input, Tensor hx, Tensor w_ih, Tensor w_hh, Tensor? b_ih=None, Tensor? b_hh=None) -> Tensor
|
||||
@@ -7646,12 +7648,16 @@
|
||||
dispatch:
|
||||
CPU: reflection_pad1d_out_cpu
|
||||
CUDA: reflection_pad1d_out_cuda
|
||||
npu_dispatch:
|
||||
NPU: reflection_pad1d_out_npu
|
||||
|
||||
- func: reflection_pad1d(Tensor self, int[2] padding) -> Tensor
|
||||
python_module: nn
|
||||
dispatch:
|
||||
CPU: reflection_pad1d_cpu
|
||||
CUDA: reflection_pad1d_cuda
|
||||
npu_dispatch:
|
||||
NPU: reflection_pad1d_npu
|
||||
|
||||
- func: reflection_pad1d_backward.grad_input(Tensor grad_output, Tensor self, int[2] padding, *, Tensor(a!) grad_input) -> Tensor(a!)
|
||||
python_module: nn
|
||||
@@ -7702,24 +7708,32 @@
|
||||
dispatch:
|
||||
CPU: replication_pad1d_out_cpu
|
||||
CUDA: replication_pad1d_out_cuda
|
||||
npu_dispatch:
|
||||
NPU: replication_pad1d_out_npu
|
||||
|
||||
- func: replication_pad1d(Tensor self, int[2] padding) -> Tensor
|
||||
python_module: nn
|
||||
dispatch:
|
||||
CPU: replication_pad1d_cpu
|
||||
CUDA: replication_pad1d_cuda
|
||||
npu_dispatch:
|
||||
NPU: replication_pad1d_npu
|
||||
|
||||
- func: replication_pad1d_backward.grad_input(Tensor grad_output, Tensor self, int[2] padding, *, Tensor(a!) grad_input) -> Tensor(a!)
|
||||
python_module: nn
|
||||
dispatch:
|
||||
CPU: replication_pad1d_backward_out_cpu
|
||||
CUDA: replication_pad1d_backward_out_cuda
|
||||
npu_dispatch:
|
||||
NPU: replication_pad1d_backward_out_npu
|
||||
|
||||
- func: replication_pad1d_backward(Tensor grad_output, Tensor self, int[2] padding) -> Tensor
|
||||
python_module: nn
|
||||
dispatch:
|
||||
CPU: replication_pad1d_backward_cpu
|
||||
CUDA: replication_pad1d_backward_cuda
|
||||
npu_dispatch:
|
||||
NPU: replication_pad1d_backward_npu
|
||||
|
||||
- func: replication_pad2d.out(Tensor self, int[4] padding, *, Tensor(a!) out) -> Tensor(a!)
|
||||
python_module: nn
|
||||
@@ -8322,11 +8336,21 @@
|
||||
device_guard: False
|
||||
supports_named_tensor: True
|
||||
|
||||
- func: get_npu_format(Tensor self) -> int
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
NPU: get_npu_format
|
||||
|
||||
- func: npu_format_cast(Tensor self, int acl_format) -> Tensor
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
NPU: format_cast_npu
|
||||
|
||||
- func: npu_format_cast.Tensor(Tensor self, Tensor dst) -> Tensor
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
NPU: format_cast_npu
|
||||
|
||||
- func: npu_format_cast_.acl_format(Tensor(a!) self, int acl_format) -> Tensor(a!)
|
||||
variants: method
|
||||
npu_dispatch_only:
|
||||
@@ -8337,11 +8361,6 @@
|
||||
npu_dispatch_only:
|
||||
NPU: format_cast_npu_
|
||||
|
||||
- func: npu_transpose_to_contiguous(Tensor self) -> Tensor
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
NPU: transpose_to_contiguous_npu
|
||||
|
||||
- func: npu_transpose(Tensor self, int[] perm) -> Tensor
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
@@ -8732,6 +8751,71 @@
|
||||
npu_dispatch_only:
|
||||
NPU: rotated_iou_npu
|
||||
|
||||
- func: npu_hcom_allreduce.out(Tensor self, str reduction, str group, int fusion, int fusion_id, float alpha, float beta, Tensor(a!) out) -> Tensor(a!)
|
||||
- func: npu_hcom_allreduce.out(Tensor self, str reduction, str group, int fusion, int fusion_id, float alpha, float beta, Tensor(a!) out, int? hccl_comm) -> Tensor(a!)
|
||||
npu_dispatch_only:
|
||||
NPU: hcom_allreduce_npu
|
||||
|
||||
- func: npu_stride_copy(Tensor self, int[] shape, int[] stride, Scalar storage_offset) -> Tensor
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
NPU: stride_copy_npu
|
||||
|
||||
- func: npu_stride_copy.out(Tensor self, int[] shape, int[] stride, Scalar storage_offset, *, Tensor(a!) out) -> Tensor(a!)
|
||||
npu_dispatch_only:
|
||||
NPU: stride_copy_out_npu
|
||||
|
||||
- func: dropout_with_byte_mask(Tensor self, float p, bool train) -> Tensor
|
||||
|
||||
- func: dropout_with_byte_mask_(Tensor(a!) self, float p, bool train) -> Tensor(a!)
|
||||
|
||||
- func: _dropout_with_byte_mask(Tensor self, float p) -> (Tensor, Tensor)
|
||||
npu_dispatch_only:
|
||||
NPU: _dropout_with_byte_mask_npu
|
||||
|
||||
- func: _dropout_with_byte_mask_inplace(Tensor(a!) result, float p) -> (Tensor(a!), Tensor)
|
||||
npu_dispatch_only:
|
||||
NPU: _dropout_with_byte_mask_npu_inplace
|
||||
|
||||
- func: _dropout_with_byte_mask_backward(Tensor grad_output, Tensor mask, float p) -> Tensor
|
||||
npu_dispatch_only:
|
||||
NPU: dropout_with_byte_mask_backward_npu
|
||||
|
||||
- func: npu_dropout_with_add_softmax(Tensor self, Tensor x1, Scalar alpha, float prob, int dim) -> (Tensor, Tensor, Tensor)
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
NPU: dropout_with_add_softmax_npu
|
||||
|
||||
- func: npu_dropout_with_add_softmax_backward(Tensor grad, Tensor mask, Tensor softmax_out, Scalar alpha, float prob, int dim) -> (Tensor, Tensor)
|
||||
variants: function, method
|
||||
npu_dispatch_only:
|
||||
NPU: dropout_with_add_softmax_backward_npu
|
||||
|
||||
- func: npu_multi_head_attention(Tensor query, Tensor key, Tensor value, Tensor query_weight, Tensor key_weight, Tensor value_weight, Tensor attn_mask, Tensor out_proj_weight, Tensor? query_bias, Tensor? key_bias, Tensor? value_bias, Tensor? out_proj_bias, Tensor? dropout_mask, int attn_head_num, int attn_dim_per_head, int src_len, int tgt_len, float dropout_prob, bool softmax_use_float) -> (Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor)
|
||||
npu_dispatch_only:
|
||||
NPU: multi_head_attention_npu
|
||||
|
||||
- func: npu_multi_head_attention_backward(Tensor query, Tensor key, Tensor value, Tensor query_weight, Tensor key_weight, Tensor value_weight, Tensor out_proj_weight, Tensor? query_bias, Tensor? key_bias, Tensor? value_bias, Tensor? out_proj_bias, Tensor query_res, Tensor key_res, Tensor value_res, Tensor attn_scores, Tensor attn_res, Tensor context, Tensor y_grad, Tensor dropout_mask, int attn_head_num, int attn_dim_per_head, int src_len, int tgt_len, float dropout_prob, bool softmax_use_float) -> (Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor)
|
||||
npu_dispatch_only:
|
||||
NPU: multi_head_attention_backward_npu
|
||||
|
||||
- func: npu_dropout_gen_mask(int[] size, float p, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
|
||||
npu_dispatch_only:
|
||||
NPU: dropout_gen_mask_impl
|
||||
|
||||
- func: npu_dropout_do_mask(Tensor self, Tensor mask, float p) -> (Tensor, Tensor)
|
||||
npu_dispatch_only:
|
||||
NPU: dropout_do_mask_impl
|
||||
|
||||
- func: npu_enque_tensor(Tensor[] tensors, str format_string) -> ()
|
||||
npu_dispatch_only:
|
||||
NPU: enque_tensor_npu
|
||||
|
||||
- func: npu_lstm_cell(Tensor input, Tensor w_ih, Tensor w_hh, Tensor h, Tensor c, Tensor? bias=None) -> (Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor)
|
||||
variants: function
|
||||
npu_dispatch_only:
|
||||
NPU: lstm_cell_npu
|
||||
|
||||
- func: npu_lstm_cell_backward(Tensor? grady, Tensor? gradh, Tensor? gradc, Tensor input, Tensor w_ih, Tensor w_hh, Tensor h, Tensor c, Tensor y_output, Tensor h_output, Tensor c_output, Tensor i, Tensor j, Tensor f, Tensor o, Tensor tanhc) -> (Tensor, Tensor, Tensor, Tensor, Tensor, Tensor)
|
||||
variants: function
|
||||
npu_dispatch_only:
|
||||
NPU: lstm_cell_backward_npu
|
||||
@@ -59,7 +59,7 @@ Tensor& adds_out_npu_nocheck(
|
||||
}
|
||||
cmd.Name("Add")
|
||||
.Input(self)
|
||||
.Input(value, self.scalar_type())
|
||||
.Input(Scalar(value), self.scalar_type())
|
||||
.Output(result, "", nullopt, real_type)
|
||||
.Run();
|
||||
|
||||
@@ -100,21 +100,12 @@ Tensor& add_out_npu_nocheck(
|
||||
.Output(result, "", nullopt, real_type)
|
||||
.Run();
|
||||
} else {
|
||||
if (c10::npu::OptionsManager::CheckDynamicOptimizer("ADD")) {
|
||||
cmd.Name("AxpyV2")
|
||||
.Input(self)
|
||||
.Input(other)
|
||||
.Input(alpha, self.scalar_type())
|
||||
.Output(result)
|
||||
.Run();
|
||||
} else {
|
||||
cmd.Name("Axpy")
|
||||
.Input(self)
|
||||
.Input(other)
|
||||
.Attr("alpha", alpha)
|
||||
.Output(result)
|
||||
.Run();
|
||||
}
|
||||
cmd.Name("AxpyV2")
|
||||
.Input(self)
|
||||
.Input(other)
|
||||
.Input(alpha, self.scalar_type())
|
||||
.Output(result)
|
||||
.Run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ Tensor addmm_npu(
|
||||
const Tensor& mat2,
|
||||
Scalar beta,
|
||||
Scalar alpha) {
|
||||
TORCH_CHECK(self.scalar_type() == mat1.scalar_type(), "The input 0 and input 1 must have the same dtype.");
|
||||
// calculate the output size
|
||||
auto outputSize = addmm_npu_output_size(self, mat1, mat2, beta, alpha);
|
||||
|
||||
@@ -69,6 +70,7 @@ Tensor& addmm_npu_(
|
||||
const Tensor& mat2,
|
||||
Scalar beta,
|
||||
Scalar alpha) {
|
||||
TORCH_CHECK(self.scalar_type() == mat1.scalar_type(), "The input 0 and input 1 must have the same dtype.");
|
||||
SmallVector<Tensor, N> inputs = {self, mat1, mat2};
|
||||
SmallVector<Tensor, N> outputs = {self};
|
||||
CalcuOpUtil::check_memory_over_laps(inputs, outputs);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2020 Huawei Technologies Co., Ltd
|
||||
// Copyright (c) 2019, Facebook CORPORATION.
|
||||
// Copyright (c) 2019, Facebook CORPORATION.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensed under the BSD 3-Clause License (the "License");
|
||||
@@ -28,18 +28,10 @@ Tensor& affine_grid_generator_npu_nocheck(
|
||||
const Tensor& theta,
|
||||
IntArrayRef size,
|
||||
bool align_corners) {
|
||||
int value = size.size();
|
||||
vector<int> tmp_vector = {};
|
||||
for (int i = 0; i < value; i++) {
|
||||
tmp_vector.emplace_back(size[i]);
|
||||
}
|
||||
Tensor sizeTensor_cpu = from_blob((void*)tmp_vector.data(), {value}, at::kInt);
|
||||
Tensor sizeTensor_npu = CalcuOpUtil::copy_tensor_host_to_device(sizeTensor_cpu);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("AffineGrid")
|
||||
.Input(theta)
|
||||
.InputPair(sizeTensor_npu, sizeTensor_cpu)
|
||||
.Input(size, at::kInt)
|
||||
.Output(result)
|
||||
.Attr("align_corners", align_corners)
|
||||
.Run();
|
||||
@@ -51,7 +43,7 @@ Tensor affine_grid_generator_npu(
|
||||
const Tensor& theta,
|
||||
IntArrayRef size,
|
||||
bool align_corners) {
|
||||
TORCH_CHECK(size.size() == 4 || size.size() == 5,
|
||||
TORCH_CHECK(size.size() == 4 || size.size() == 5,
|
||||
"AffineGridGenerator needs 4d or 5d size(input).");
|
||||
// calculate the output size
|
||||
SmallVector<int64_t, SIZE> outputSize = { };
|
||||
@@ -65,8 +57,8 @@ Tensor affine_grid_generator_npu(
|
||||
Tensor result = OpPreparation::ApplyTensor(theta, outputSize);
|
||||
// calculate the output result of the NPU
|
||||
affine_grid_generator_npu_nocheck(
|
||||
result,
|
||||
theta,
|
||||
result,
|
||||
theta,
|
||||
size,
|
||||
align_corners);
|
||||
|
||||
|
||||
@@ -27,32 +27,14 @@ inline Tensor all_out_npu_nocheck(
|
||||
const Tensor& self,
|
||||
SmallVector<int64_t, N> dimList,
|
||||
bool keepdim) {
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()){
|
||||
OpCommand cmd;
|
||||
cmd.Name("ReduceAll")
|
||||
.Input(self)
|
||||
.Input(dimList, at::kLong)
|
||||
.Output(result)
|
||||
.Attr("keep_dims", keepdim)
|
||||
.Run();
|
||||
} else {
|
||||
OpDynamicCommand cmd;
|
||||
cmd.Name("ReduceAllD")
|
||||
.Input(self)
|
||||
.Output(result)
|
||||
.Attr("axes", dimList)
|
||||
.Attr("keep_dims", keepdim);
|
||||
// DYNAMIC
|
||||
Tensor dimTensor_cpu = from_blob((void*)dimList.data(), {dimList.size()}, at::kLong).to(at::kInt);
|
||||
Tensor dimTensor_npu = CalcuOpUtil::copy_tensor_host_to_device(dimTensor_cpu);
|
||||
cmd.DynamicName("ReduceAll")
|
||||
.DynamicInput(self)
|
||||
.DynamicInput(dimTensor_npu)
|
||||
.DynamicOutput(result, "", FIXED_NONE, false)
|
||||
.DynamicAttr("keep_dims", keepdim)
|
||||
.DynamicOpRun();
|
||||
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("ReduceAll")
|
||||
.Input(self)
|
||||
.Input(dimList, at::kLong)
|
||||
.Output(result)
|
||||
.Attr("keep_dims", keepdim)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -82,51 +64,77 @@ Tensor& all_out_npu(
|
||||
Tensor all_npu(const Tensor& self, int64_t dim, bool keepdim) {
|
||||
TORCH_CHECK(self.scalar_type() == ScalarType::Bool || self.scalar_type() == ScalarType::Byte,
|
||||
"all only supports torch.uint8 and torch.bool dtypes");
|
||||
TORCH_CHECK(dim >= -(self.dim()) && dim < self.dim(),
|
||||
"The value of dim must be greater than or equal to -self.dim() and less than self.dim()");
|
||||
Tensor selfCopy = self;
|
||||
if(selfCopy.scalar_type() == ScalarType::Byte){
|
||||
selfCopy = selfCopy.npu_dtype_cast(ScalarType::Bool);
|
||||
}
|
||||
if (self.numel() == 0) {
|
||||
Tensor res = at::empty_with_format({}, self.options().dtype(kInt), CalcuOpUtil::get_tensor_npu_format(self)).fill_(1).to(ScalarType::Bool);
|
||||
SmallVector<int64_t, N> outputSize;
|
||||
for(int64_t i = 0; i < self.dim(); i++){
|
||||
if(dim != i){
|
||||
outputSize.emplace_back(self.size(i));
|
||||
}
|
||||
}
|
||||
Tensor res = OpPreparation::ApplyTensorWithFormat(
|
||||
outputSize,
|
||||
self.options().dtype(kInt),
|
||||
CalcuOpUtil::get_tensor_npu_format(self)).fill_(1).npu_dtype_cast(self.scalar_type());
|
||||
return res;
|
||||
}
|
||||
|
||||
// calculate the output size
|
||||
IntArrayRef dims(dim);
|
||||
auto outputSize = reduce_ops_npu_output_size(self, dims, keepdim);
|
||||
auto outputSize = reduce_ops_npu_output_size(selfCopy, dims, keepdim);
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(
|
||||
outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
|
||||
Tensor result = OpPreparation::ApplyTensorWithFormat(
|
||||
outputSize, selfCopy.options(), CalcuOpUtil::get_tensor_npu_format(selfCopy));
|
||||
|
||||
// calculate the output result of the NPU
|
||||
all_out_npu_nocheck(result, self, {dim}, keepdim);
|
||||
|
||||
all_out_npu_nocheck(result, selfCopy, {dim}, keepdim);
|
||||
if(self.scalar_type() == ScalarType::Byte){
|
||||
result = result.npu_dtype_cast(ScalarType::Byte);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor all_npu(const Tensor& self) {
|
||||
TORCH_CHECK(self.scalar_type() == ScalarType::Bool || self.scalar_type() == ScalarType::Byte,
|
||||
"all only supports torch.uint8 and torch.bool dtypes");
|
||||
Tensor selfCopy = self;
|
||||
if(selfCopy.scalar_type() == ScalarType::Byte){
|
||||
selfCopy = selfCopy.npu_dtype_cast(ScalarType::Bool);
|
||||
}
|
||||
|
||||
if (self.numel() == 0) {
|
||||
Tensor res = at::empty_with_format(
|
||||
Tensor res = OpPreparation::ApplyTensorWithFormat(
|
||||
{},
|
||||
self.options().dtype(kInt),
|
||||
CalcuOpUtil::get_tensor_npu_format(self)).fill_(1).to(ScalarType::Bool);
|
||||
CalcuOpUtil::get_tensor_npu_format(self)).fill_(1).npu_dtype_cast(self.scalar_type());
|
||||
return res;
|
||||
}
|
||||
|
||||
// calculate the output size
|
||||
IntArrayRef dims;
|
||||
auto outputSize = reduce_ops_npu_output_size(self, dims, false);
|
||||
auto outputSize = reduce_ops_npu_output_size(selfCopy, dims, false);
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(
|
||||
outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
|
||||
Tensor result = OpPreparation::ApplyTensorWithFormat(
|
||||
outputSize, selfCopy.options(), CalcuOpUtil::get_tensor_npu_format(selfCopy));
|
||||
|
||||
// calculate the output result of the NPU
|
||||
all_out_npu_nocheck(
|
||||
result,
|
||||
self,
|
||||
CalcuOpUtil::get_dimlist_for_tensor(self),
|
||||
selfCopy,
|
||||
CalcuOpUtil::get_dimlist_for_tensor(selfCopy),
|
||||
false);
|
||||
|
||||
if(self.scalar_type() == ScalarType::Byte){
|
||||
result = result.npu_dtype_cast(ScalarType::Byte);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,31 +26,14 @@ inline Tensor& any_out_npu_nocheck(
|
||||
const Tensor& self,
|
||||
SmallVector<int64_t, N> dimList,
|
||||
bool keepdim) {
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()){
|
||||
OpCommand cmd;
|
||||
cmd.Name("ReduceAny")
|
||||
.Input(self)
|
||||
.Input(dimList)
|
||||
.Output(result)
|
||||
.Attr("keep_dims", keepdim)
|
||||
.Run();
|
||||
} else {
|
||||
OpDynamicCommand cmd;
|
||||
cmd.Name("ReduceAnyD")
|
||||
.Input(self)
|
||||
.Output(result)
|
||||
.Attr("axes", dimList)
|
||||
.Attr("keep_dims", keepdim);
|
||||
// DYNAMIC
|
||||
Tensor dimTensor_cpu = from_blob((void*)dimList.data(), {dimList.size()}, at::kLong).to(at::kInt);
|
||||
Tensor dimTensor_npu = CalcuOpUtil::copy_tensor_host_to_device(dimTensor_cpu);
|
||||
cmd.DynamicName("ReduceAny")
|
||||
.DynamicInput(self)
|
||||
.DynamicInput(dimTensor_npu, "axes")
|
||||
.DynamicOutput(result, "", FIXED_NONE, false)
|
||||
.DynamicAttr("keep_dims", keepdim)
|
||||
.DynamicOpRun();
|
||||
}
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("ReduceAny")
|
||||
.Input(self)
|
||||
.Input(dimList)
|
||||
.Output(result)
|
||||
.Attr("keep_dims", keepdim)
|
||||
.Run();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -111,7 +94,7 @@ Tensor any_npu(const Tensor& self) {
|
||||
self.options().dtype(ScalarType::Float),
|
||||
CalcuOpUtil::get_tensor_npu_format(self))
|
||||
.fill_(self.item())
|
||||
.to(ScalarType::Bool);
|
||||
.npu_dtype_cast(ScalarType::Bool);
|
||||
return any_npu(self_tmp, 0, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ std::tuple<Tensor, Tensor, Tensor> apply_adam_out_npu_nocheck(
|
||||
c10::optional<bool> use_locking,
|
||||
c10::optional<bool> use_nesterov) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("ApplyAdam")
|
||||
cmd.Name("ApplyAdamD")
|
||||
.Input(var_out)
|
||||
.Input(m_out)
|
||||
.Input(v_out)
|
||||
@@ -45,7 +45,9 @@ std::tuple<Tensor, Tensor, Tensor> apply_adam_out_npu_nocheck(
|
||||
.Input(beta2, var_out.scalar_type())
|
||||
.Input(epsilon, var_out.scalar_type())
|
||||
.Input(grad)
|
||||
.Output(var_out);
|
||||
.Output(var_out)
|
||||
.Output(m_out)
|
||||
.Output(v_out);
|
||||
if (use_locking != c10::nullopt) {
|
||||
cmd.Attr("use_locking", bool(use_locking));
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ Tensor arange_npu(
|
||||
|
||||
// check start == end
|
||||
Tensor result_check = set_to_integral_dtype
|
||||
? at::empty_with_format({0}, options.dtype(at::ScalarType::Int), ACL_FORMAT_ND)
|
||||
? at::empty_with_format({0}, options.dtype(at::ScalarType::Long), ACL_FORMAT_ND)
|
||||
: at::empty_with_format({0}, options, ACL_FORMAT_ND);
|
||||
if (start_value == end_value) {
|
||||
return result_check;
|
||||
@@ -89,17 +89,17 @@ Tensor arange_npu(
|
||||
SmallVector<int64_t, SIZE> outputSize = {size_value};
|
||||
|
||||
Tensor result = set_to_integral_dtype
|
||||
? at::empty_with_format(outputSize, options.dtype(at::ScalarType::Int), ACL_FORMAT_ND)
|
||||
? at::empty_with_format(outputSize, options.dtype(at::ScalarType::Long), ACL_FORMAT_ND)
|
||||
: at::empty_with_format(outputSize, options, ACL_FORMAT_ND);
|
||||
|
||||
if(options.dtype() == at::kHalf) {
|
||||
result = result.to(at::kFloat);
|
||||
result = result.npu_dtype_cast(at::kFloat);
|
||||
}
|
||||
|
||||
arange_out_npu_nocheck(result, start, end, step);
|
||||
|
||||
if(options.dtype() == at::kHalf) {
|
||||
result = result.to(at::kHalf);
|
||||
result = result.npu_dtype_cast(at::kHalf);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -42,7 +42,7 @@ Tensor argmax_npu(const Tensor& self, optional<int64_t> dim, bool keepdim) {
|
||||
.Attr("keep_dims", realKeepDim)
|
||||
.Run();
|
||||
|
||||
result = result.to(ScalarType::Long);
|
||||
result = result.npu_dtype_cast(ScalarType::Long);
|
||||
return result;
|
||||
}
|
||||
} // namespace native
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2020, Huawei Technologies.All rights reserved.
|
||||
//
|
||||
// Licensed under the BSD 3-Clause License (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://opensource.org/licenses/BSD-3-Clause
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include <torch/csrc/autograd/record_function.h>
|
||||
#include "ATen/native/npu/common/InnerNpuNativeFunction.h"
|
||||
#include "ATen/native/npu/frame/StorageDescHelper.h"
|
||||
#include "ATen/native/npu/utils/NpuStorageOffsetGuard.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor& stride_copy_out_npu_nocheck(
|
||||
Tensor& result,
|
||||
const Tensor& self,
|
||||
IntArrayRef shape,
|
||||
IntArrayRef stride,
|
||||
Scalar storage_offset) {
|
||||
if ((result.nbytes() < 32) && (!StorageDescHelper::MetaDataAreMatch(&result))) {
|
||||
// [算子限制] 对于1. 小于一个block的数据搬运 2.result不match,Astrided暂不支持。
|
||||
copy_kernel_npu(result, self, false);
|
||||
return result;
|
||||
}
|
||||
RECORD_HOST_FUNCTION("npuAsStrided", std::vector<c10::IValue>({self}));
|
||||
E2E_RECORD_FUNCTION("npuAsStrided");
|
||||
// Set the offset of input discontiguous tensor to be 0.
|
||||
// The accurate offset would be provided as a attr to op.
|
||||
OpCommand cmd;
|
||||
if (c10::npu::NpuRunMode::IsGraphMode()) {
|
||||
NpuStorageOffsetGuard guard_input(const_cast<Tensor &>(self));
|
||||
cmd.Name("AsStrided")
|
||||
.InputWithoutContiguous(self)
|
||||
.Input(shape)
|
||||
.Input(stride)
|
||||
.Input(storage_offset, at::kLong, CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
// (Ascend) Fix multi-compiling of asstrided op by wrapping attr storage_offset as a NPU Tensor instead of GE Const node.
|
||||
// If GE Data node can pass vaule of storage_offset to op, we can switch storage_offset to Data node finally.
|
||||
cmd.Name("AsStrided")
|
||||
.InputWithoutContiguous(self)
|
||||
.Input(shape)
|
||||
.Input(stride)
|
||||
.InputScalarToNPUTensor(at::Scalar(0), at::kLong)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& stride_copy_out_npu(
|
||||
Tensor& result,
|
||||
const Tensor& self,
|
||||
IntArrayRef shape,
|
||||
IntArrayRef stride,
|
||||
Scalar storage_offset) {
|
||||
stride_copy_out_npu_nocheck(result, self, shape, stride, storage_offset);
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor stride_copy_npu(
|
||||
const Tensor& self,
|
||||
IntArrayRef shape,
|
||||
IntArrayRef stride,
|
||||
Scalar storage_offset) {
|
||||
// AsStrided OP only supports ND input
|
||||
Tensor result = OpPreparation::ApplyTensorWithFormat(
|
||||
shape, self.options(), ACL_FORMAT_ND);
|
||||
stride_copy_out_npu_nocheck(result, self, shape, stride, storage_offset);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
@@ -14,31 +14,37 @@
|
||||
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
SmallVector<NPUTensorDesc, N> baddbmm_npu_input(
|
||||
const Tensor& self,
|
||||
const Tensor& other) {
|
||||
return CalcuOpUtil::create_npu_input_tensor_desc({self, other});
|
||||
}
|
||||
Tensor& baddbmm_nocheck(
|
||||
const Tensor& self,
|
||||
const Tensor& tensor1,
|
||||
const Tensor& tensor2,
|
||||
Scalar beta,
|
||||
Scalar alpha,
|
||||
Tensor& result) {
|
||||
auto outputSize = baddbmm_npu_output_size(tensor1, tensor2);
|
||||
Tensor BatchMatMulTensor = OpPreparation::ApplyTensor(self, outputSize);
|
||||
bool isSelfT = CalcuOpUtil::is_transpose_last_two_dims(tensor1);
|
||||
bool isMat2T = CalcuOpUtil::is_transpose_last_two_dims(tensor2);
|
||||
|
||||
SmallVector<NPUTensorDesc, N> baddbmm_npu_output(
|
||||
const Tensor& result) {
|
||||
return CalcuOpUtil::create_npu_output_tensor_desc({result});
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("BatchMatMul")
|
||||
.Input(tensor1)
|
||||
.Input(tensor2)
|
||||
.Output(BatchMatMulTensor)
|
||||
.Attr("adj_x1", isSelfT)
|
||||
.Attr("adj_x2", isMat2T)
|
||||
.Run();
|
||||
|
||||
SmallVector<NPUAttrDesc, N> baddbmm_npu_attr(
|
||||
const Tensor& self,
|
||||
const Tensor& mat2) {
|
||||
bool isSelfT = CalcuOpUtil::is_transpose_last_two_dims(self);
|
||||
bool isMat2T = CalcuOpUtil::is_transpose_last_two_dims(mat2);
|
||||
NPUAttrDesc npuAttrSelfTranspose = NPUAttrDesc("adj_x1", isSelfT);
|
||||
NPUAttrDesc npuAttrMat2Transpose = NPUAttrDesc("adj_x2", isMat2T);
|
||||
SmallVector<NPUAttrDesc, N> attrs = {npuAttrSelfTranspose, npuAttrMat2Transpose};
|
||||
return attrs;
|
||||
Tensor alphaMulTensor = at::mul(BatchMatMulTensor, alpha);
|
||||
Tensor betaMulTensor = at::mul(self, beta);
|
||||
at::add_out(result, alphaMulTensor, betaMulTensor, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& baddbmm_out_npu(
|
||||
@@ -47,21 +53,13 @@ Tensor& baddbmm_out_npu(
|
||||
const Tensor& tensor1,
|
||||
const Tensor& tensor2,
|
||||
Scalar beta,
|
||||
Scalar alpha) {
|
||||
auto outputSize = baddbmm_npu_output_size(tensor1, tensor2);
|
||||
Tensor BatchMatMulTensor = OpPreparation::ApplyTensor(self, outputSize);
|
||||
|
||||
auto inputs = baddbmm_npu_input(tensor1, tensor2);
|
||||
auto outputs = baddbmm_npu_output({BatchMatMulTensor});
|
||||
auto attrs = baddbmm_npu_attr(tensor1, tensor2);
|
||||
CalcuOpUtil::execute_npu_operate("BatchMatMul", inputs, outputs, attrs);
|
||||
|
||||
Tensor alphaMulTensor = at::mul(BatchMatMulTensor, alpha);
|
||||
|
||||
Tensor betaMulTensor = at::mul(self, beta);
|
||||
|
||||
at::add_out(result, alphaMulTensor, betaMulTensor);
|
||||
|
||||
Scalar alpha){
|
||||
|
||||
OpPreparation::CheckOut(
|
||||
{self, tensor1, tensor2},
|
||||
result,
|
||||
self);
|
||||
baddbmm_nocheck(self, tensor1, tensor2, beta, alpha, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -73,10 +71,9 @@ Tensor baddbmm_npu(
|
||||
Scalar alpha) {
|
||||
Tensor outputTensor = self;
|
||||
auto outputSize = baddbmm_npu_output_size(tensor1, tensor2);
|
||||
Tensor result = at::empty_with_format(
|
||||
outputSize,
|
||||
outputTensor.options(),
|
||||
CalcuOpUtil::get_tensor_npu_format(outputTensor));
|
||||
Tensor result = OpPreparation::ApplyTensor(
|
||||
outputTensor,
|
||||
outputSize);
|
||||
baddbmm_out_npu(result, self, tensor1, tensor2, beta, alpha);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -30,16 +30,16 @@ std::tuple<Tensor, Tensor, Tensor, Tensor> batch_nms_npu(
|
||||
// construct the output tensor of the NPU
|
||||
Tensor nmsed_boxes = OpPreparation::ApplyTensor(
|
||||
{self.size(0), max_total_size, 4},
|
||||
self.options().dtype(at::kHalf),
|
||||
self.options(),
|
||||
self);
|
||||
Tensor nmsed_scores = OpPreparation::ApplyTensor(
|
||||
{self.size(0), max_total_size},
|
||||
self.options().dtype(at::kHalf),
|
||||
self.options(),
|
||||
self);
|
||||
|
||||
Tensor nmsed_classes = OpPreparation::ApplyTensor(
|
||||
{self.size(0), max_total_size},
|
||||
self.options().dtype(at::kHalf),
|
||||
self.options(),
|
||||
self);
|
||||
|
||||
Tensor nmsed_num = OpPreparation::ApplyTensor(
|
||||
|
||||
@@ -15,100 +15,77 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "c10/npu/SecondaryStreamGuard.h"
|
||||
#include "c10/npu/NPUCachingAllocator.h"
|
||||
#include "ATen/npu/NPUGenerator.h"
|
||||
#include "ATen/Utils.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor& bernoulli_npu_nocheck(Tensor& result, const Tensor& self, double p) {
|
||||
auto original_stream = c10::npu::getCurrentNPUStream();
|
||||
{
|
||||
c10::npu::SecondaryStreamGuard guard(c10::npu::getCurrentSecondaryStream());
|
||||
OpCommand cmd;
|
||||
cmd.Name("Bernoulli")
|
||||
.Input(self)
|
||||
.Input(p, ScalarType::Float)
|
||||
.Output(result)
|
||||
.Run();
|
||||
}
|
||||
c10::npu::NPUCachingAllocator::recordStream(self.storage().data_ptr(), original_stream);
|
||||
|
||||
return result;
|
||||
Tensor& bernoulli_npu_nocheck(Tensor& y, double prob, int64_t seed, int64_t offset) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("StatelessBernoulli")
|
||||
.Input(y.sizes(), at::kLong, CompileType::MEMORY_HOST_COMPILE_INDEPENDENT)
|
||||
.Input(Scalar(prob), ScalarType::Float)
|
||||
.Input(Scalar(seed), ScalarType::Long)
|
||||
.Input(Scalar(offset), ScalarType::Long)
|
||||
.Output(y)
|
||||
.Attr("dtype", y.scalar_type())
|
||||
.Run();
|
||||
return y;
|
||||
}
|
||||
|
||||
Tensor& bernoulli_npu_nocheck(Tensor& result, const Tensor& self, const Tensor& p) {
|
||||
auto original_stream = c10::npu::getCurrentNPUStream();
|
||||
{
|
||||
c10::npu::SecondaryStreamGuard guard(c10::npu::getCurrentSecondaryStream());
|
||||
OpCommand cmd;
|
||||
cmd.Name("Bernoulli")
|
||||
.Input(self)
|
||||
.Input(p)
|
||||
.Output(result)
|
||||
.Run();
|
||||
}
|
||||
c10::npu::NPUCachingAllocator::recordStream(self.storage().data_ptr(), original_stream);
|
||||
c10::npu::NPUCachingAllocator::recordStream(p.storage().data_ptr(), original_stream);
|
||||
|
||||
return result;
|
||||
Tensor& bernoulli_npu_nocheck(Tensor& y, const Tensor& prob, int64_t seed, int64_t offset) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("StatelessBernoulli")
|
||||
.Input(y.sizes(), at::kLong, CompileType::MEMORY_HOST_COMPILE_INDEPENDENT)
|
||||
.Input(prob)
|
||||
.Input(Scalar(seed), ScalarType::Long)
|
||||
.Input(Scalar(offset), ScalarType::Long)
|
||||
.Output(y)
|
||||
.Attr("dtype", y.scalar_type())
|
||||
.Run();
|
||||
return y;
|
||||
}
|
||||
|
||||
Tensor& bernoulli_npu_(Tensor& self, double p, Generator* gen) {
|
||||
OpPreparation::CheckMemory({self}, {self});
|
||||
ScalarType selfType = self.scalar_type();
|
||||
Tensor selfFp32 = self;
|
||||
if (self.scalar_type() == ScalarType::Half) {
|
||||
selfFp32 = self.to(ScalarType::Float);
|
||||
}
|
||||
auto gen_ = get_generator_or_default<NPUGenerator>(gen, at::npu::detail::getDefaultNPUGenerator());
|
||||
auto pair = gen_->philox_engine_inputs(10);
|
||||
const int64_t seed = pair.first;
|
||||
const int64_t offset = pair.second;
|
||||
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(selfFp32);
|
||||
Tensor result = bernoulli_npu_nocheck(contiguousSelf, contiguousSelf, p);
|
||||
NpuUtils::format_fresh_view(self, result);
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(self);
|
||||
bernoulli_npu_nocheck(contiguousSelf, p, seed, offset);
|
||||
NpuUtils::format_fresh_view(self, contiguousSelf);
|
||||
} else {
|
||||
bernoulli_npu_nocheck(selfFp32, selfFp32, p);
|
||||
self.copy_(selfFp32);
|
||||
}
|
||||
|
||||
if(self.scalar_type() != selfType){
|
||||
self = self.to(ScalarType::Half);
|
||||
bernoulli_npu_nocheck(self, p, seed, offset);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
Tensor& bernoulli_npu_(Tensor& self, const Tensor& p, Generator* gen) {
|
||||
OpPreparation::CheckMemory({self}, {self});
|
||||
ScalarType selfType = self.scalar_type();
|
||||
Tensor selfFp32 = self;
|
||||
Tensor pFp32 = OpPreparation::CastBackToOriFormat(p);
|
||||
if (self.scalar_type() == ScalarType::Half) {
|
||||
selfFp32 = self.to(ScalarType::Float);
|
||||
pFp32 = p.to(ScalarType::Float);
|
||||
}
|
||||
auto gen_ = get_generator_or_default<NPUGenerator>(gen, at::npu::detail::getDefaultNPUGenerator());
|
||||
auto pair = gen_->philox_engine_inputs(10);
|
||||
const int64_t seed = pair.first;
|
||||
const int64_t offset = pair.second;
|
||||
|
||||
Tensor pOriFormat = OpPreparation::CastBackToOriFormat(p);
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(selfFp32);
|
||||
Tensor result = bernoulli_npu_nocheck(contiguousSelf, contiguousSelf, pFp32);
|
||||
NpuUtils::format_fresh_view(self, result);
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(self);
|
||||
bernoulli_npu_nocheck(contiguousSelf, pOriFormat, seed, offset);
|
||||
NpuUtils::format_fresh_view(self, contiguousSelf);
|
||||
} else {
|
||||
bernoulli_npu_nocheck(selfFp32, selfFp32, pFp32);
|
||||
self.copy_(selfFp32);
|
||||
}
|
||||
|
||||
if(self.scalar_type() != selfType){
|
||||
self = self.to(ScalarType::Half);
|
||||
bernoulli_npu_nocheck(self, pOriFormat, seed, offset);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
Tensor bernoulli_npu(const Tensor& self, Generator* gen) {
|
||||
const Tensor p = self;
|
||||
Tensor selfCopy = at::empty_with_format(
|
||||
self.sizes(), self.options(), ACL_FORMAT_ND);
|
||||
Tensor selfCopy = OpPreparation::ApplyTensorWithFormat(self.sizes(), self.options(), ACL_FORMAT_ND);
|
||||
selfCopy.copy_(self);
|
||||
return bernoulli_npu_(selfCopy, p, gen);
|
||||
return bernoulli_npu_(selfCopy, self, gen);
|
||||
}
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
@@ -30,15 +31,7 @@ Tensor& binary_cross_entropy_backward_out_npu(
|
||||
Tensor weightTensor = weight.defined() ? weight :
|
||||
at::ones(self.sizes(), self.options());
|
||||
|
||||
string reductionStr;
|
||||
if (reduction == Reduction::None) {
|
||||
reductionStr = "none";
|
||||
} else if (reduction == Reduction::Mean) {
|
||||
reductionStr = "mean";
|
||||
} else if (reduction == Reduction::Sum) {
|
||||
reductionStr = "sum";
|
||||
}
|
||||
|
||||
std::string reductionStr = NpuUtils::get_reduction_str(reduction);
|
||||
OpCommand cmd;
|
||||
cmd.Name("BinaryCrossEntropyGrad")
|
||||
.Input(self)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
@@ -32,12 +33,7 @@ Tensor& binary_cross_entropy_out_npu(
|
||||
}
|
||||
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
string reductionStr = "mean";
|
||||
if (reduction == Reduction::None) {
|
||||
reductionStr = "none";
|
||||
} else if (reduction == Reduction::Sum) {
|
||||
reductionStr = "sum";
|
||||
}
|
||||
std::string reductionStr = NpuUtils::get_reduction_str(reduction);
|
||||
|
||||
// executing the NPU operator
|
||||
OpCommand cmd;
|
||||
@@ -70,7 +66,7 @@ Tensor binary_cross_entropy_npu(
|
||||
Tensor result = OpPreparation::ApplyTensor(self, outputSize);
|
||||
if (self.numel() == 0) {
|
||||
// In this scenario, needs to return nan. And the nan of the NPU can only be fp32.
|
||||
result = result.to(at::kFloat).fill_(0);
|
||||
result = result.npu_dtype_cast(at::kFloat).fill_(0);
|
||||
result = result / 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
@@ -46,14 +47,7 @@ Tensor binary_cross_entropy_with_logits_backward_npu(
|
||||
|
||||
Tensor doutTensor = broadcast_npu(grad_output, self.sizes());
|
||||
|
||||
string reductionStr;
|
||||
if (reduction == Reduction::None) {
|
||||
reductionStr = "none";
|
||||
} else if (reduction == Reduction::Mean) {
|
||||
reductionStr = "mean";
|
||||
} else if (reduction == Reduction::Sum) {
|
||||
reductionStr = "sum";
|
||||
}
|
||||
std::string reductionStr = NpuUtils::get_reduction_str(reduction);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("SigmoidCrossEntropyWithLogitsGradV2")
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
@@ -60,14 +61,7 @@ Tensor binary_cross_entropy_with_logits_npu(
|
||||
}
|
||||
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
string reductionStr;
|
||||
if (reduction == Reduction::None) {
|
||||
reductionStr = "none";
|
||||
} else if (reduction == Reduction::Mean) {
|
||||
reductionStr = "mean";
|
||||
} else if (reduction == Reduction::Sum) {
|
||||
reductionStr = "sum";
|
||||
}
|
||||
std::string reductionStr = NpuUtils::get_reduction_str(reduction);
|
||||
|
||||
// executing the NPU operator
|
||||
OpCommand cmd;
|
||||
|
||||
@@ -29,7 +29,7 @@ Tensor& bincount_npu_nocheck(
|
||||
OpCommand cmd;
|
||||
cmd.Name("Bincount")
|
||||
.Input(self)
|
||||
.Input(sizes, ScalarType::Int)
|
||||
.Input(Scalar(sizes), ScalarType::Int)
|
||||
.Input(weights)
|
||||
.Output(result)
|
||||
.Run();
|
||||
|
||||
@@ -65,7 +65,6 @@ Tensor& bmm_out_npu(Tensor& result, const Tensor& self, const Tensor& mat2) {
|
||||
Tensor bmm_npu(const Tensor& self, const Tensor& mat2) {
|
||||
// calculate the output size
|
||||
auto outputSize = {self.size(0), self.size(1), mat2.size(2)};
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result;
|
||||
|
||||
@@ -79,19 +78,18 @@ Tensor bmm_npu(const Tensor& self, const Tensor& mat2) {
|
||||
(!(static_cast<uint64_t>(mat2.size(2)) & 0x0000000F));
|
||||
};
|
||||
// There is a data trampling problem in non-aligned scenes. For the time being, only aligned scenes are supported.
|
||||
if (env::CheckMmBmmNDEnable() && FormatHelper::IsBaseFormatType(self) &&
|
||||
FormatHelper::IsBaseFormatType(mat2) && isAligin() ) {
|
||||
if (env::CheckMmBmmNDEnable() && FormatHelper::IsBaseFormatType(self) &&
|
||||
FormatHelper::IsBaseFormatType(mat2) && isAligin()) {
|
||||
result = at::empty_with_format(outputSize, self.options());
|
||||
} else {
|
||||
result = at::empty_with_format(outputSize, self.options(), ACL_FORMAT_FRACTAL_NZ);
|
||||
result = at::empty_with_format(
|
||||
outputSize, self.options(), ACL_FORMAT_FRACTAL_NZ);
|
||||
}
|
||||
} else {
|
||||
result = at::empty_with_format(outputSize, self.options(), ACL_FORMAT_ND);
|
||||
}
|
||||
|
||||
// calculate the output result of the NPU
|
||||
bmm_out_npu(result, self, mat2);
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace native
|
||||
|
||||
@@ -27,39 +27,19 @@ Tensor& broadcast_out_npu(
|
||||
const Tensor& self,
|
||||
IntArrayRef size) {
|
||||
// executing the NPU operator
|
||||
int value = size.size();
|
||||
vector<int> tmp_vector = {};
|
||||
for (int i = 0; i < value; i++){
|
||||
tmp_vector.emplace_back(size[i]);
|
||||
}
|
||||
Tensor shapeCpuTensor = from_blob((void*)tmp_vector.data(), {value}, at::kInt);
|
||||
Tensor shapeNpuTensor = CalcuOpUtil::copy_tensor_host_to_device(shapeCpuTensor);
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()){
|
||||
OpCommand cmd;
|
||||
cmd.Name("BroadcastTo")
|
||||
.Input(self)
|
||||
.InputPair(shapeNpuTensor, shapeCpuTensor)
|
||||
.Output(result)
|
||||
.Run();
|
||||
} else {
|
||||
OpDynamicCommand cmd;
|
||||
cmd.Name("BroadcastTo")
|
||||
.Input(self)
|
||||
.InputPair(shapeNpuTensor, shapeCpuTensor)
|
||||
.Output(result);
|
||||
cmd.DynamicName("BroadcastTo")
|
||||
.DynamicInput(self)
|
||||
.DynamicInput(shapeNpuTensor, "shape")
|
||||
.DynamicOutput(result)
|
||||
.DynamicOpRun();
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("BroadcastTo")
|
||||
.Input(self)
|
||||
.Input(size)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor broadcast_npu(const Tensor& self, IntArrayRef size) {
|
||||
Tensor input = self;
|
||||
if (self.dtype() == at::kBool) {
|
||||
input = input.to(at::kInt);
|
||||
input = input.npu_dtype_cast(at::kInt);
|
||||
}
|
||||
|
||||
Tensor result = at::empty_with_format(
|
||||
@@ -70,7 +50,7 @@ Tensor broadcast_npu(const Tensor& self, IntArrayRef size) {
|
||||
broadcast_out_npu(result, input, size);
|
||||
|
||||
if (self.dtype() == at::kBool) {
|
||||
result = result.to(at::kBool);
|
||||
result = result.npu_dtype_cast(at::kBool);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -37,6 +37,9 @@ SmallVector<Tensor, N> cat_dest_tensor_list(TensorList tensors) {
|
||||
SmallVector<Tensor, N> dstTensorList;
|
||||
// pytorch supports empty tensors, which needs to be removed from the NPU.
|
||||
for (Tensor tensor : tensors) {
|
||||
// ConcatD needs all input tensor have same dtype
|
||||
TORCH_CHECK(tensors[0].scalar_type() == tensor.scalar_type(), "all inputs must have same dtype.")
|
||||
|
||||
if (tensor.dim() == 1 && tensor.sizes()[0] == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -112,68 +115,34 @@ Tensor& _cat_out_npu(Tensor& result, TensorList tensors, int64_t dim) {
|
||||
|
||||
// executing the NPU operator
|
||||
int64_t input_number = 0;
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("ConcatD");
|
||||
OpCommand cmd;
|
||||
cmd.Name("ConcatD");
|
||||
|
||||
// In graph mode, if all of input tensors are null numel,
|
||||
// these null tensors should be passed to ConcatD as inputs.
|
||||
// Otherwise, an error will be reported when infershape.
|
||||
bool tensors_empty_in_graph_mode = false;
|
||||
if (c10::npu::NpuRunMode::IsGraphMode()) {
|
||||
tensors_empty_in_graph_mode = true;
|
||||
for (int i = 0; i < inputTensors.size(); i++) {
|
||||
if (inputTensors[i].numel() != 0) {
|
||||
tensors_empty_in_graph_mode = false;
|
||||
break;
|
||||
}
|
||||
// In graph mode, if all of input tensors are null numel,
|
||||
// these null tensors should be passed to ConcatD as inputs.
|
||||
// Otherwise, an error will be reported when infershape.
|
||||
bool tensors_empty_in_graph_mode = false;
|
||||
if (c10::npu::NpuRunMode::IsGraphMode()) {
|
||||
tensors_empty_in_graph_mode = true;
|
||||
for (int i = 0; i < inputTensors.size(); i++) {
|
||||
if (inputTensors[i].numel() != 0) {
|
||||
tensors_empty_in_graph_mode = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
input_number = 0;
|
||||
for (int i = 0; i < inputTensors.size(); i++) {
|
||||
if (inputTensors[i].numel() != 0 || tensors_empty_in_graph_mode) {
|
||||
string inputName = "x" + to_string(input_number++);
|
||||
cmd.Input(inputTensors[i], inputName);
|
||||
}
|
||||
}
|
||||
cmd.DynamicInputReg(concat_func<ge::op::ConcatD>, {{input_number, 0}})
|
||||
.Output(result)
|
||||
.Attr("N", input_number)
|
||||
.Attr("concat_dim", dim)
|
||||
.Run();
|
||||
} else {
|
||||
OpDynamicCommand cmd;
|
||||
cmd.Name("ConcatD");
|
||||
input_number = 0;
|
||||
for (int i = 0; i < inputTensors.size(); i++) {
|
||||
if (inputTensors[i].numel() == 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
input_number = 0;
|
||||
for (int i = 0; i < inputTensors.size(); i++) {
|
||||
if (inputTensors[i].numel() != 0 || tensors_empty_in_graph_mode) {
|
||||
string inputName = "x" + to_string(input_number++);
|
||||
cmd.Input(inputTensors[i], inputName);
|
||||
}
|
||||
cmd.Output(result)
|
||||
.Attr("N", input_number)
|
||||
.Attr("concat_dim", dim);
|
||||
|
||||
// DYNAMIC
|
||||
SmallVector<int64_t, N> dimVec = {dim};
|
||||
|
||||
cmd.DynamicName("Concat")
|
||||
.DynamicInput(dimVec, at::kLong, at::kInt, "", true, FIXED_CONST_VALUE);
|
||||
input_number = 0;
|
||||
for (int i = 0; i < inputTensors.size(); i++) {
|
||||
if (inputTensors[i].numel() == 0) {
|
||||
continue;
|
||||
}
|
||||
string inputName = "x" + to_string(input_number++);
|
||||
cmd.DynamicInput(inputTensors[i], inputName);
|
||||
}
|
||||
|
||||
cmd.DynamicOutput(result)
|
||||
.DynamicAttr("N", input_number)
|
||||
.DynamicOpRun();
|
||||
}
|
||||
cmd.DynamicInputReg(concat_func<ge::op::ConcatD>, {{input_number, 0}})
|
||||
.Output(result)
|
||||
.Attr("N", input_number)
|
||||
.Attr("concat_dim", dim)
|
||||
.Run();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,55 +11,15 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
SmallVector<NPUTensorDesc, N> cdist_npu_input(
|
||||
const Tensor& x1,
|
||||
const Tensor& x2) {
|
||||
SmallVector<NPUTensorDesc, N> inputs = CalcuOpUtil::create_npu_input_tensor_desc({x1, x2});
|
||||
return inputs;
|
||||
}
|
||||
|
||||
SmallVector<NPUAttrDesc, N> cdist_npu_attr(const float p) {
|
||||
NPUAttrDesc npuAttrValue = NPUAttrDesc("p", p);
|
||||
SmallVector<NPUAttrDesc, N> attrs = {npuAttrValue};
|
||||
return attrs;
|
||||
}
|
||||
|
||||
SmallVector<NPUTensorDesc, N> cdist_npu_output(const Tensor& result) {
|
||||
return CalcuOpUtil::create_npu_output_tensor_desc({result});
|
||||
}
|
||||
|
||||
Tensor cdist_npu(
|
||||
const Tensor& x1,
|
||||
const Tensor& x2,
|
||||
const double p,
|
||||
c10::optional<int64_t> compute_mode) {
|
||||
return at::_cdist_forward(x1, x2, p, compute_mode);
|
||||
}
|
||||
|
||||
Tensor& cdist_out_npu(
|
||||
Tensor &result,
|
||||
const Tensor& x1,
|
||||
const Tensor& x2,
|
||||
const float p_float) {
|
||||
auto inputs = cdist_npu_input(x1, x2);
|
||||
auto attrs = cdist_npu_attr(p_float);
|
||||
auto outputs = cdist_npu_output({result});
|
||||
|
||||
// Executing the NPU operator.
|
||||
CalcuOpUtil::execute_npu_operate("Cdist", inputs, outputs, attrs);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor _cdist_forward_npu(
|
||||
const Tensor& x1,
|
||||
const Tensor& x2,
|
||||
@@ -75,13 +35,12 @@ Tensor _cdist_forward_npu(
|
||||
// Since double is not supported in NPU, the type of P needs to be converted from double to float.
|
||||
float p_float;
|
||||
if (std::isinf(p)) {
|
||||
p_float = std::numeric_limits<float>::infinity();
|
||||
p_float = -1;
|
||||
}
|
||||
else {
|
||||
TORCH_CHECK(p <= std::numeric_limits<float>::max(), "npu dose not support float64" );
|
||||
p_float = static_cast<float>(p);
|
||||
}
|
||||
|
||||
int64_t mode = compute_mode.value_or(0);
|
||||
TORCH_CHECK(mode >= 0 && mode <= 2, "possible modes: 0, 1, 2, but was: ", mode);
|
||||
|
||||
@@ -100,7 +59,6 @@ Tensor _cdist_forward_npu(
|
||||
tensor1_expand_size.insert(tensor1_expand_size.end(), {r1, c1});
|
||||
std::vector<int64_t> tensor2_expand_size(expand_batch_portion);
|
||||
tensor2_expand_size.insert(tensor2_expand_size.end(), {r2, c2});
|
||||
|
||||
int expand_batch_product = std::accumulate(expand_batch_portion.begin(), expand_batch_portion.end(), 1, std::multiplies<int64_t>());
|
||||
std::vector<int64_t> tensor1_view{expand_batch_product, r1, 1, c1};
|
||||
std::vector<int64_t> tensor2_view{expand_batch_product, 1, r2, c2};
|
||||
@@ -110,23 +68,29 @@ Tensor _cdist_forward_npu(
|
||||
// Broadcast batch dim.
|
||||
Tensor tensor1_expanded = x1.expand(tensor1_expand_size).contiguous().view(tensor1_view);
|
||||
Tensor tensor2_expanded = x2.expand(tensor2_expand_size).contiguous().view(tensor2_view);
|
||||
|
||||
// Broadcast r1 and r2.
|
||||
Tensor tensor1_broadcast = tensor1_expanded.expand(tensor_broadcast_size).contiguous();
|
||||
Tensor tensor2_broadcast = tensor2_expanded.expand(tensor_broadcast_size).contiguous();
|
||||
|
||||
// Executing the NPU operator.
|
||||
auto output_size = cdist_npu_output_size(x1, x2);
|
||||
Tensor result = OpPreparation::ApplyTensor(tensor1_broadcast, result_size);
|
||||
|
||||
Tensor result = at::empty_with_format(
|
||||
result_size,
|
||||
tensor1_broadcast.options(),
|
||||
CalcuOpUtil::get_tensor_npu_format(tensor1_broadcast));
|
||||
|
||||
cdist_out_npu(result, tensor1_broadcast, tensor2_broadcast, p_float);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("Cdist")
|
||||
.Input(tensor1_broadcast)
|
||||
.Input(tensor2_broadcast)
|
||||
.Attr("p", p_float)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result.view(output_size);
|
||||
}
|
||||
|
||||
Tensor cdist_npu(
|
||||
const Tensor& x1,
|
||||
const Tensor& x2,
|
||||
const double p,
|
||||
c10::optional<int64_t> compute_mode) {
|
||||
return at::_cdist_forward(x1, x2, p, compute_mode);
|
||||
}
|
||||
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
} // namespace at
|
||||
|
||||
@@ -22,7 +22,7 @@ using namespace at::native::npu;
|
||||
|
||||
Tensor celu_out_npu_nocheck(Tensor& result, const Tensor& self, Scalar alpha) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("Celu")
|
||||
cmd.Name("CeluV2")
|
||||
.Input(self)
|
||||
.Output(result)
|
||||
.Attr("alpha", alpha)
|
||||
|
||||
@@ -12,52 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <c10/npu/NPUCachingAllocator.h>
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
SmallVector<NPUTensorDesc, N> col2im_backward_npu_input(
|
||||
const SmallVector<Tensor, N>& inputTensor) {
|
||||
return CalcuOpUtil::create_npu_input_tensor_desc(inputTensor);
|
||||
}
|
||||
|
||||
SmallVector<NPUTensorDesc, N> col2im_backward_npu_output(
|
||||
const SmallVector<Tensor, N>& outputTensor) {
|
||||
return CalcuOpUtil::create_npu_output_tensor_desc(outputTensor);
|
||||
}
|
||||
|
||||
SmallVector<NPUAttrDesc, N> col2im_backward_npu_attr(
|
||||
IntArrayRef kernel_size,
|
||||
IntArrayRef dilation,
|
||||
IntArrayRef padding,
|
||||
IntArrayRef stride) {
|
||||
|
||||
SmallVector<int64_t, N> kernelSize = {1, kernel_size[0], kernel_size[1], 1};
|
||||
|
||||
SmallVector<int64_t, N> stridesSize = {1, stride[0], stride[1], 1};
|
||||
|
||||
string paddings = "SAME";
|
||||
|
||||
SmallVector<int64_t, N> dilations = {1, dilation[0], dilation[1], 1};
|
||||
|
||||
NPUAttrDesc npuAttrKsize = NPUAttrDesc("ksizes", kernelSize);
|
||||
NPUAttrDesc npuAttrStrides = NPUAttrDesc("strides", stridesSize);
|
||||
NPUAttrDesc npuAttrPads = NPUAttrDesc("padding", paddings);
|
||||
NPUAttrDesc npuAttrDilations = NPUAttrDesc("dilations", dilations);
|
||||
SmallVector<NPUAttrDesc, N> attrs = {
|
||||
npuAttrKsize,
|
||||
npuAttrStrides,
|
||||
npuAttrPads,
|
||||
npuAttrDilations
|
||||
};
|
||||
return attrs;
|
||||
}
|
||||
|
||||
Tensor col2im_backward_out_npu_template(
|
||||
Tensor& grad_input,
|
||||
const Tensor& grad_output,
|
||||
@@ -65,12 +27,19 @@ Tensor col2im_backward_out_npu_template(
|
||||
IntArrayRef dilation,
|
||||
IntArrayRef padding,
|
||||
IntArrayRef stride) {
|
||||
auto inputs = col2im_backward_npu_input({grad_output});
|
||||
SmallVector<int64_t, N> kernelSize = {1, kernel_size[0], kernel_size[1], 1};
|
||||
SmallVector<int64_t, N> stridesSize = {1, stride[0], stride[1], 1};
|
||||
SmallVector<int64_t, N> dilations = {1, dilation[0], dilation[1], 1};
|
||||
|
||||
auto outputs = col2im_backward_npu_output({grad_input});
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
auto attrs = col2im_backward_npu_attr(kernel_size, stride, padding, dilation);
|
||||
CalcuOpUtil::execute_npu_operate("ExtractImagePatches", inputs, outputs,attrs);
|
||||
OpCommand cmd;
|
||||
cmd.Name("ExtractImagePatches")
|
||||
.Input(grad_output, "x", ACL_FORMAT_NCHW)
|
||||
.Output(grad_input)
|
||||
.Attr("ksizes", kernelSize)
|
||||
.Attr("strides", stridesSize)
|
||||
.Attr("padding", (string) "SAME")
|
||||
.Attr("dilations", dilations)
|
||||
.Run();
|
||||
return grad_input;
|
||||
}
|
||||
|
||||
@@ -81,7 +50,9 @@ Tensor& col2im_backward_out_npu(
|
||||
IntArrayRef dilation,
|
||||
IntArrayRef padding,
|
||||
IntArrayRef stride) {
|
||||
col2im_backward_out_npu_template(grad_input, grad_output,kernel_size, dilation,padding,stride);
|
||||
OpPreparation::CheckOut({grad_output}, grad_input, grad_output);
|
||||
col2im_backward_out_npu_template(
|
||||
grad_input, grad_output, kernel_size, dilation, padding, stride);
|
||||
return grad_input;
|
||||
}
|
||||
|
||||
@@ -91,14 +62,10 @@ Tensor col2im_backward_npu(
|
||||
IntArrayRef dilation,
|
||||
IntArrayRef padding,
|
||||
IntArrayRef stride) {
|
||||
// construct the input tensor of the NPU
|
||||
Tensor grad_input = at::empty_with_format(grad_output.sizes(), grad_output.options(),CalcuOpUtil::get_tensor_npu_format(grad_output));
|
||||
|
||||
col2im_backward_out_npu_template(grad_input, grad_output,kernel_size, dilation,padding,stride);
|
||||
|
||||
Tensor grad_input = OpPreparation::ApplyTensor(grad_output);
|
||||
col2im_backward_out_npu_template(
|
||||
grad_input, grad_output, kernel_size, dilation, padding, stride);
|
||||
return grad_input;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,15 +58,15 @@ Tensor conv_tbc_npu(
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("Conv2D")
|
||||
.Input(self_tensor)
|
||||
.Input(weight_tensor)
|
||||
.Input(bias)
|
||||
.Output(result)
|
||||
.Attr("pads", paddings)
|
||||
.Attr("strides", stridesSize)
|
||||
.Attr("dilations", dilations)
|
||||
.Attr("data_format", (string)"NCHW")
|
||||
.Run();
|
||||
.Input(self_tensor, "x", ACL_FORMAT_NCHW)
|
||||
.Input(weight_tensor, "filter", ACL_FORMAT_NCHW)
|
||||
.Input(bias)
|
||||
.Output(result, "y", ACL_FORMAT_NCHW)
|
||||
.Attr("pads", paddings)
|
||||
.Attr("strides", stridesSize)
|
||||
.Attr("dilations", dilations)
|
||||
.Attr("data_format", (string) "NCHW")
|
||||
.Run();
|
||||
|
||||
result = result.squeeze(2).transpose(0, 2).transpose(1, 2);
|
||||
return result;
|
||||
|
||||
@@ -43,8 +43,22 @@ std::tuple<Tensor, Tensor> ctc_loss_npu(
|
||||
auto inputLengthsTensor = at::tensor(inputLengths, targetsCast.options());
|
||||
auto targetLengthsTensor = at::tensor(targetLengths, targetsCast.options());
|
||||
|
||||
int64_t maxLength = 0;
|
||||
if (targetsCast.dim() == 2) {
|
||||
maxLength = targetsCast.size(1);
|
||||
} else if (targetsCast.dim() == 1) {
|
||||
for (auto &i : targetLengths) {
|
||||
if (i > maxLength) {
|
||||
maxLength = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
auto shape = logProbs.sizes();
|
||||
|
||||
auto blankNew = blank + maxLength * shape[2];
|
||||
|
||||
// calculate the output size
|
||||
auto outputSizes = ctc_loss_npu_output_size(logProbs, targetsCast, targetLengths);
|
||||
auto outputSizes = ctc_loss_npu_output_size(logProbs, targetsCast, targetLengths, maxLength);
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor negLogLikelihood = at::empty_with_format(
|
||||
@@ -59,7 +73,8 @@ std::tuple<Tensor, Tensor> ctc_loss_npu(
|
||||
|
||||
// calculate the output result of the NPU
|
||||
OpCommand cmd;
|
||||
cmd.Name("CTCLossV2")
|
||||
if (targetsCast.dim() == 2) {
|
||||
cmd.Name("CTCLossV2")
|
||||
.Input(logProbsNeed)
|
||||
.Input(targetsCast)
|
||||
.Input(inputLengthsTensor)
|
||||
@@ -69,7 +84,19 @@ std::tuple<Tensor, Tensor> ctc_loss_npu(
|
||||
.Attr("blank", blank)
|
||||
.Attr("zero_infinity", zeroInfinity)
|
||||
.Run();
|
||||
|
||||
} else if (targetsCast.dim() == 1) {
|
||||
cmd.Name("CTCLossV2")
|
||||
.Input(logProbsNeed)
|
||||
.Input(targetsCast)
|
||||
.Input(inputLengthsTensor)
|
||||
.Input(targetLengthsTensor)
|
||||
.Output(negLogLikelihood)
|
||||
.Output(logAlpha)
|
||||
.Attr("blank", blankNew)
|
||||
.Attr("zero_infinity", zeroInfinity)
|
||||
.Run();
|
||||
}
|
||||
|
||||
if (logProbs.scalar_type() == ScalarType::Half) {
|
||||
negLogLikelihood = negLogLikelihood.npu_dtype_cast(ScalarType::Half);
|
||||
logAlpha = logAlpha.to(ScalarType::Half);
|
||||
|
||||
@@ -31,7 +31,7 @@ void cummin_out_npu_nocheck (
|
||||
.Input(self)
|
||||
.Output(values)
|
||||
.Output(indices)
|
||||
.Attr("dim", dim)
|
||||
.Attr("axis", dim)
|
||||
.Run();
|
||||
}
|
||||
|
||||
@@ -60,14 +60,14 @@ void cummin_helper_npu(const Tensor& self, Tensor& values, Tensor& indices, int6
|
||||
|
||||
cummin_out_npu_nocheck(transposeValue, transposeIndices, transposeSelf, firstDim);
|
||||
// Indices must to be long
|
||||
transposeIndices = transposeIndices.to(kLong);
|
||||
transposeIndices = transposeIndices.npu_dtype_cast(kLong);
|
||||
at::npu_transpose_out(values, transposeValue, perm);
|
||||
at::npu_transpose_out(indices, transposeIndices, perm);
|
||||
} else {
|
||||
Tensor valuesTemp = OpPreparation::ApplyTensor(self);
|
||||
Tensor indicesTemp = OpPreparation::ApplyTensor(self, self.options().dtype(kInt));
|
||||
cummin_out_npu_nocheck(valuesTemp, indicesTemp, self, dim);
|
||||
indicesTemp = indicesTemp.to(kLong);
|
||||
indicesTemp = indicesTemp.npu_dtype_cast(kLong);
|
||||
values.copy_(valuesTemp);
|
||||
indices.copy_(indicesTemp);
|
||||
}
|
||||
|
||||
@@ -20,28 +20,19 @@ using namespace at::native::npu;
|
||||
|
||||
Tensor& _cumsum_out_npu(Tensor& result, const Tensor& self, int64_t dim) {
|
||||
OpCommand cmd;
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()) {
|
||||
// if dim = 0, performance in Aicpu is better than Aicore
|
||||
// if dim > INT32_MAX, we should use long to store dim for ensuring function correctness.
|
||||
// use host memory instead of scalar to improve delivery performance
|
||||
Scalar dimScalar(dim);
|
||||
cmd.Name("Cumsum")
|
||||
.Input(self);
|
||||
if (dim == 0 || dim > INT32_MAX) {
|
||||
cmd.Input(dimScalar, at::kLong, CompileType::MEMORY_HOST_COMPILE_DEPENDENT);
|
||||
} else {
|
||||
cmd.Input(dimScalar, at::kInt, CompileType::MEMORY_HOST_COMPILE_DEPENDENT);
|
||||
}
|
||||
cmd.Output(result)
|
||||
.Run();
|
||||
// if dim = 0, performance in Aicpu is better than Aicore
|
||||
// if dim > INT32_MAX, we should use long to store dim for ensuring function correctness.
|
||||
// use host memory instead of scalar to improve delivery performance
|
||||
Scalar dimScalar(dim);
|
||||
cmd.Name("Cumsum")
|
||||
.Input(self);
|
||||
if (dim == 0 || dim > INT32_MAX) {
|
||||
cmd.Input(dimScalar, at::kLong, CompileType::MEMORY_HOST_COMPILE_DEPENDENT);
|
||||
} else {
|
||||
cmd.Name("CumsumD")
|
||||
.Input(self)
|
||||
.Output(result)
|
||||
.Attr("axis", dim)
|
||||
.Run();
|
||||
cmd.Input(dimScalar, at::kInt, CompileType::MEMORY_HOST_COMPILE_DEPENDENT);
|
||||
}
|
||||
|
||||
cmd.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,56 +12,36 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <iostream>
|
||||
#include "c10/npu/npu_log.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
#include "c10/npu/npu_log.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
SmallVector<NPUTensorDesc, N> det_npu_input(
|
||||
const SmallVector<Tensor, N>& inputTensor) {
|
||||
return CalcuOpUtil::create_npu_input_tensor_desc(inputTensor);
|
||||
}
|
||||
|
||||
SmallVector<NPUTensorDesc, N> det_npu_output(
|
||||
const SmallVector<Tensor, N>& outputTensor) {
|
||||
|
||||
return CalcuOpUtil::create_npu_output_tensor_desc(outputTensor);
|
||||
}
|
||||
|
||||
SmallVector<NPUAttrDesc, N> det_npu_attr(const Tensor& self) {
|
||||
SmallVector<NPUAttrDesc, N> attrs = {};
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
Tensor& det_out_npu(Tensor& result, const Tensor& self) {
|
||||
// constructs the input and output NPUTensorDesc
|
||||
auto inputs = det_npu_input({self});
|
||||
auto outputs = det_npu_output({result});
|
||||
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
auto attrs = det_npu_attr(self);
|
||||
|
||||
// executing the NPU operator
|
||||
CalcuOpUtil::execute_npu_operate("Det", inputs, outputs, attrs);
|
||||
auto outputSize = det_npu_output_size(self);
|
||||
OpPreparation::CheckOut(
|
||||
{self},
|
||||
result,
|
||||
self,
|
||||
outputSize);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("Det")
|
||||
.Input(self)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor det_npu(const Tensor& self) {
|
||||
// calculate the output size
|
||||
|
||||
auto outputSize = det_npu_output_size(self);
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(
|
||||
outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
|
||||
// calculate the output result of the NPU
|
||||
Tensor result = OpPreparation::ApplyTensor(self, outputSize);
|
||||
det_out_npu(result, self);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor dropout_backward_npu(
|
||||
Tensor dropout_backward_impl(
|
||||
const string& opType,
|
||||
const Tensor& grad_output,
|
||||
const Tensor& mask,
|
||||
double scale) {
|
||||
@@ -34,15 +35,29 @@ Tensor dropout_backward_npu(
|
||||
Tensor result = OpPreparation::ApplyTensor(grad_output);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("DropOutDoMask")
|
||||
cmd.Name(opType)
|
||||
.Input(grad_output)
|
||||
.Input(mask)
|
||||
.Input(retain, grad_output.scalar_type(), CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Input(Scalar(retain), grad_output.scalar_type(), CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Output(result)
|
||||
.Run();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor dropout_backward_npu(
|
||||
const Tensor& grad_output,
|
||||
const Tensor& mask,
|
||||
double scale) {
|
||||
return dropout_backward_impl("DropOutDoMask", grad_output, mask, scale);
|
||||
}
|
||||
|
||||
Tensor dropout_with_byte_mask_backward_npu(
|
||||
const Tensor& grad_output,
|
||||
const Tensor& mask,
|
||||
double scale) {
|
||||
return dropout_backward_impl("DropOutDoMaskV3", grad_output, mask, scale);
|
||||
}
|
||||
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
|
||||
@@ -39,14 +39,36 @@ Tensor dropout_do_mask(
|
||||
return result;
|
||||
}
|
||||
|
||||
std::tuple<Tensor, Tensor> dropout_do_mask_impl(
|
||||
const Tensor& self,
|
||||
const Tensor& mask,
|
||||
double p) {
|
||||
Scalar prob = Scalar(1. - p);
|
||||
Tensor result = OpPreparation::ApplyTensor(self);
|
||||
OpCommand cmd;
|
||||
cmd.Name("DropOutDoMask")
|
||||
.Input(self)
|
||||
.Input(mask)
|
||||
.Input(prob, self.scalar_type(), CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Output(result)
|
||||
.Run();
|
||||
|
||||
return std::tie(result, mask);
|
||||
}
|
||||
|
||||
Tensor dropout_gen_mask(const Tensor& self, Scalar prob) {
|
||||
uint32_t length = (self.numel() + 128 - 1) / 128 * 128;
|
||||
bool isFuzzyCompile = env::CheckFuzzyEnable();
|
||||
int64_t numels;
|
||||
auto desc_ = self.storage().get_npu_desc();
|
||||
numels = isFuzzyCompile ? prod_intlist(desc_.storage_sizes_) : self.numel();
|
||||
|
||||
uint32_t length = (numels + 128 - 1) / 128 * 128;
|
||||
Tensor mask = at::empty_with_format(
|
||||
{length / 8},
|
||||
self.options().dtype(at::kByte),
|
||||
ACL_FORMAT_ND);
|
||||
|
||||
IntArrayRef selfShape = self.sizes();
|
||||
IntArrayRef selfShape = isFuzzyCompile ? desc_.storage_sizes_ : self.sizes();
|
||||
|
||||
OpCommand cmd;
|
||||
// If either seed or seed2 are set to be non-zero, the random number generator
|
||||
@@ -63,34 +85,57 @@ Tensor dropout_gen_mask(const Tensor& self, Scalar prob) {
|
||||
return mask;
|
||||
}
|
||||
|
||||
Tensor dropout_gen_mask_impl(IntArrayRef size, double p, const TensorOptions& options) {
|
||||
Scalar prob = Scalar(1. - p);
|
||||
int64_t numels = prod_intlist(size);
|
||||
|
||||
uint32_t length = (numels + 128 - 1) / 128 * 128;
|
||||
Tensor mask = OpPreparation::ApplyTensorWithFormat(IntArrayRef{length / 8}, options.dtype(at::kByte), ACL_FORMAT_ND);
|
||||
|
||||
OpCommand cmd;
|
||||
// If either seed or seed2 are set to be non-zero, the random number generator
|
||||
// is seeded by the given seed. Otherwise, it is seeded by a random seed.
|
||||
int64_t seed = 0;
|
||||
int64_t seed2 = 0;
|
||||
cmd.Name("DropOutGenMask")
|
||||
.Input(size)
|
||||
.Input(prob, c10::typeMetaToScalarType(options.dtype()), CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Output(mask)
|
||||
.Attr("seed", seed)
|
||||
.Attr("seed2", seed2)
|
||||
.Run();
|
||||
return mask;
|
||||
}
|
||||
|
||||
std::tuple<Tensor, Tensor> dropout_v1_npu_impl(
|
||||
Tensor result,
|
||||
const Tensor& self,
|
||||
double p) {
|
||||
Tensor selfCp = NpuUtils::format_contiguous(self);
|
||||
TORCH_CHECK(
|
||||
p >= 0 && p <= 1,
|
||||
"dropout probability has to be between 0 and 1, but got ",
|
||||
p);
|
||||
TORCH_CHECK(
|
||||
at::isFloatingType(self.scalar_type()),
|
||||
at::isFloatingType(selfCp.scalar_type()),
|
||||
"dropout only supports floating-point dtypes");
|
||||
|
||||
|
||||
double retain = 1. - p;
|
||||
Scalar prob = Scalar(retain);
|
||||
Tensor mask;
|
||||
auto original_stream = c10::npu::getCurrentNPUStream();
|
||||
{
|
||||
// During the life cycle of this raii instance, the calcu stream is set as the
|
||||
// secondary stream, and tasks are distributed to the secondary stream. At the
|
||||
// secondary stream, and tasks are distributed to the secondary stream. At the
|
||||
// same time, according to the one-stream-one-pool principle, memory is also
|
||||
// alloced from the pool of the secondary stream.
|
||||
c10::npu::SecondaryStreamGuard guard(c10::npu::getCurrentSecondaryStream());
|
||||
mask = dropout_gen_mask(self, prob);
|
||||
mask = dropout_gen_mask(selfCp, prob);
|
||||
}
|
||||
// When tasks on multiple streams read and write the same block of memory,
|
||||
// recordStream needs to be called to ensure the correctness of memory reuse.
|
||||
c10::npu::NPUCachingAllocator::recordStream(mask.storage().data_ptr(), original_stream);
|
||||
dropout_do_mask(result, self, mask, prob);
|
||||
dropout_do_mask(result, selfCp, mask, prob);
|
||||
|
||||
return std::tie(result, mask);
|
||||
}
|
||||
@@ -107,7 +152,7 @@ std::tuple<Tensor, Tensor> _dropout_npu_inplace(
|
||||
return dropout_v1_npu_impl(self, self, p);
|
||||
}
|
||||
|
||||
Tensor dropout_npu(const Tensor& self, double p, bool train) {
|
||||
Tensor dropout_npu(const Tensor& self, double p, bool train) {
|
||||
if (p == 0 || !train || self.numel() == 0) {
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2020 Huawei Technologies Co., Ltd
|
||||
// Copyright (c) 2019, Facebook CORPORATION.
|
||||
// Copyright (c) 2019, Facebook CORPORATION.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensed under the BSD 3-Clause License (the "License");
|
||||
@@ -20,27 +20,32 @@ namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor _log_softmax_backward_npu(
|
||||
const Tensor& grad_output,
|
||||
const Tensor& output,
|
||||
int64_t dim,
|
||||
const Tensor& self) {
|
||||
tuple<Tensor, Tensor> dropout_with_add_softmax_backward_npu(
|
||||
const Tensor& grad_out,
|
||||
const Tensor& mask,
|
||||
const Tensor& softmax_out,
|
||||
Scalar alpha,
|
||||
double p,
|
||||
int64_t dim){
|
||||
Tensor result = OpPreparation::ApplyTensor(softmax_out);
|
||||
Tensor grad_res = OpPreparation::ApplyTensor(softmax_out);
|
||||
SmallVector<int64_t, N> dimList = {dim};
|
||||
Tensor grad_input = OpPreparation::ApplyTensor(grad_output);
|
||||
double retain = 1. - p;
|
||||
Scalar prob = Scalar(retain);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("LogSoftmaxGrad")
|
||||
.Input(grad_output)
|
||||
.Input(output)
|
||||
.Output(grad_input)
|
||||
.Attr("axis", dimList)
|
||||
.Run();
|
||||
|
||||
return grad_input;
|
||||
cmd.Name("DropoutWithMulsAndSoftmaxGrad")
|
||||
.Input(grad_out)
|
||||
.Input(mask)
|
||||
.Input(softmax_out)
|
||||
.Output(result)
|
||||
.Attr("alpha", alpha)
|
||||
.Attr("input_keep_prob", prob)
|
||||
.Attr("axes", dimList)
|
||||
.Run();
|
||||
grad_res = grad_out;
|
||||
return std::tie(result, grad_res);
|
||||
}
|
||||
|
||||
TORCH_LIBRARY_IMPL(aten, NPU, m) {
|
||||
m.impl("_log_softmax_backward_data", TORCH_FN(_log_softmax_backward_npu));
|
||||
}
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright (c) 2020 Huawei Technologies Co., Ltd
|
||||
// Copyright (c) 2019, Facebook CORPORATION.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensed under the BSD 3-Clause License (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://opensource.org/licenses/BSD-3-Clause
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "c10/npu/NPUCachingAllocator.h"
|
||||
#include "c10/npu/SecondaryStreamGuard.h"
|
||||
#include <ATen/npu/NPUGenerator.h>
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor dropout_genmask(const Tensor& self, Scalar prob){
|
||||
uint32_t length = (self.numel() + 128 - 1) / 128 * 128;
|
||||
Tensor mask = OpPreparation::ApplyTensorWithFormat(
|
||||
{length},
|
||||
self.options().dtype(at::kByte),
|
||||
ACL_FORMAT_ND);
|
||||
IntArrayRef selfShape = self.sizes();
|
||||
|
||||
int64_t seed = 2;
|
||||
int64_t seed2 = 0;
|
||||
OpCommand cmd;
|
||||
cmd.Name("DropOutGenMaskV3")
|
||||
.Input(selfShape)
|
||||
.Input(prob, self.scalar_type(), CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Output(mask)
|
||||
.Attr("seed", seed)
|
||||
.Attr("seed2", seed2)
|
||||
.Run();
|
||||
return mask;
|
||||
}
|
||||
|
||||
std::tuple<Tensor, Tensor, Tensor> dropout_with_add_softmax_npu(
|
||||
const Tensor& self,
|
||||
const Tensor& x1,
|
||||
Scalar alpha,
|
||||
double p,
|
||||
int64_t dim){
|
||||
Tensor result_softmax = OpPreparation::ApplyTensor(x1);
|
||||
Tensor result_dropout = OpPreparation::ApplyTensor(self);
|
||||
SmallVector<int64_t, N> dimList = {dim};
|
||||
double retain = 1. - p;
|
||||
Scalar prob = Scalar(retain);
|
||||
Tensor mask;
|
||||
auto original_stream = c10::npu::getCurrentNPUStream();
|
||||
{
|
||||
c10::npu::SecondaryStreamGuard guard(c10::npu::getCurrentSecondaryStream());
|
||||
mask = dropout_genmask(x1, prob);
|
||||
}
|
||||
c10::npu::NPUCachingAllocator::recordStream(mask.storage().data_ptr(), original_stream);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("AxpyWithSoftmaxAndDropOutDoMask")
|
||||
.Input(x1)
|
||||
.Input(self)
|
||||
.Input(mask)
|
||||
.Output(result_softmax)
|
||||
.Output(result_dropout)
|
||||
.Attr("alpha", alpha)
|
||||
.Attr("input_keep_prob", prob)
|
||||
.Attr("axis", dimList)
|
||||
.Run();
|
||||
return std::tie(mask, result_softmax, result_dropout);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Copyright (c) 2020 Huawei Technologies Co., Ltd
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensed under the BSD 3-Clause License (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://opensource.org/licenses/BSD-3-Clause
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
#include "ATen/native/npu/utils/OpTemplate.h"
|
||||
#include "c10/npu/SecondaryStreamGuard.h"
|
||||
#include "c10/npu/NPUCachingAllocator.h"
|
||||
#include "ATen/npu/NPUGenerator.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
Tensor dropout_do_mask_with_byte_mask(
|
||||
Tensor& result,
|
||||
const Tensor& self,
|
||||
const Tensor& mask,
|
||||
Scalar prob) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("DropOutDoMaskV3")
|
||||
.Input(self)
|
||||
.Input(mask)
|
||||
.Input(prob, self.scalar_type(), CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor dropout_gen_byte_mask(const Tensor& self, Scalar prob) {
|
||||
IntArrayRef selfShape = self.sizes();
|
||||
Tensor mask = at::empty_with_format(
|
||||
selfShape,
|
||||
self.options().dtype(at::kByte),
|
||||
ACL_FORMAT_ND);
|
||||
OpCommand cmd;
|
||||
// If either seed or seed2 are set to be non-zero, the random number generator
|
||||
// is seeded by the given seed. Otherwise, it is seeded by a random seed.
|
||||
// DropOutGenMaskV3 use seed and seed2 to generator a seed, like this:
|
||||
// seed2 seed
|
||||
// 127~64 63~0
|
||||
// so, we set seed2 = 0 to ensure the seed which user set is equal to the seed
|
||||
// used by the operator DropOutGenMaskV3
|
||||
const auto gen = at::npu::detail::getDefaultNPUGenerator();
|
||||
AT_ASSERT(gen != nullptr);
|
||||
const int64_t seed = static_cast<int64_t>(gen->current_seed());
|
||||
const int64_t seed2 = 0;
|
||||
cmd.Name("DropOutGenMaskV3")
|
||||
.Input(selfShape)
|
||||
.Input(prob, self.scalar_type(), CompileType::MEMORY_HOST_COMPILE_DEPENDENT)
|
||||
.Output(mask)
|
||||
.Attr("seed", seed)
|
||||
.Attr("seed2", seed2)
|
||||
.Run();
|
||||
return mask;
|
||||
}
|
||||
|
||||
std::tuple<Tensor, Tensor> dropout_npu_impl(
|
||||
Tensor result,
|
||||
const Tensor& self,
|
||||
double p) {
|
||||
Tensor selfCp = NpuUtils::format_contiguous(self);
|
||||
TORCH_CHECK(
|
||||
p >= 0 && p <= 1,
|
||||
"dropout probability has to be between 0 and 1, but got ", p);
|
||||
TORCH_CHECK(
|
||||
at::isFloatingType(selfCp.scalar_type()),
|
||||
"dropout only supports floating-point dtypes");
|
||||
|
||||
double retain = 1. - p;
|
||||
Scalar prob = Scalar(retain);
|
||||
Tensor mask;
|
||||
auto original_stream = c10::npu::getCurrentNPUStream();
|
||||
{
|
||||
// During the life cycle of this raii instance, the calcu stream is set as the
|
||||
// secondary stream, and tasks are distributed to the secondary stream. At the
|
||||
// same time, according to the one-stream-one-pool principle, memory is also
|
||||
// alloced from the pool of the secondary stream.
|
||||
c10::npu::SecondaryStreamGuard guard(c10::npu::getCurrentSecondaryStream());
|
||||
mask = dropout_gen_byte_mask(selfCp, prob);
|
||||
}
|
||||
// When tasks on multiple streams read and write the same block of memory,
|
||||
// recordStream needs to be called to ensure the correctness of memory reuse.
|
||||
c10::npu::NPUCachingAllocator::recordStream(mask.storage().data_ptr(), original_stream);
|
||||
dropout_do_mask_with_byte_mask(result, selfCp, mask, prob);
|
||||
|
||||
return std::tie(result, mask);
|
||||
}
|
||||
|
||||
std::tuple<Tensor, Tensor> _dropout_with_byte_mask_npu(
|
||||
const Tensor& self,
|
||||
double p) {
|
||||
Tensor result = OpPreparation::ApplyTensor(self);
|
||||
return dropout_npu_impl(result, self, p);
|
||||
}
|
||||
|
||||
std::tuple<Tensor, Tensor> _dropout_with_byte_mask_npu_inplace(
|
||||
Tensor& self,
|
||||
double p) {
|
||||
return dropout_npu_impl(self, self, p);
|
||||
}
|
||||
|
||||
Tensor dropout_with_byte_mask(const Tensor& self, double p, bool train) {
|
||||
TORCH_CHECK(
|
||||
self.is_npu(),
|
||||
"dropout_with_byte_mask only supports device for NPU!");
|
||||
if (p == 0 || !train || self.numel() == 0) {
|
||||
return self;
|
||||
}
|
||||
if (p == 1) {
|
||||
return self.mul(at::zeros(self.sizes(), self.options()));
|
||||
}
|
||||
return std::get<0>(at::_dropout_with_byte_mask(self, p));
|
||||
}
|
||||
|
||||
Tensor& dropout_with_byte_mask_(Tensor& self, double p, bool train) {
|
||||
TORCH_CHECK(
|
||||
self.is_npu(),
|
||||
"dropout_with_byte_mask only supports device for NPU!");
|
||||
if (p == 0 || !train || self.numel() == 0) {
|
||||
return self;
|
||||
}
|
||||
if (p == 1) {
|
||||
return self.mul_(at::zeros(self.sizes(), self.options()));
|
||||
}
|
||||
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor result = NpuUtils::format_contiguous(self);
|
||||
at::_dropout_with_byte_mask_inplace(result, p);
|
||||
NpuUtils::format_fresh_view(self, result);
|
||||
} else {
|
||||
at::_dropout_with_byte_mask_inplace(self, p);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
@@ -12,44 +12,35 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
SmallVector<NPUTensorDesc, N> elu_backward_npu_input(const Tensor& grads,const Tensor& activations) {
|
||||
auto inputs = CalcuOpUtil::create_npu_input_tensor_desc({grads, activations});
|
||||
return inputs;
|
||||
}
|
||||
|
||||
SmallVector<NPUTensorDesc, N> elu_backward_npu_output(const Tensor& result) {
|
||||
return CalcuOpUtil::create_npu_output_tensor_desc({result});
|
||||
}
|
||||
|
||||
SmallVector<NPUAttrDesc, N> elu_backward_npu_attr(Scalar alpha) {
|
||||
float value = CalcuOpUtil::get_scalar_float_value(alpha);
|
||||
NPUAttrDesc npuAttrScalar = NPUAttrDesc("alpha", value);
|
||||
SmallVector<NPUAttrDesc, N> attrs = {npuAttrScalar};
|
||||
return attrs;
|
||||
}
|
||||
|
||||
Tensor& elu_backward_out_npu(Tensor& grad_input, const Tensor& grad_output, Scalar alpha, Scalar scale, Scalar input_scale, const Tensor& output) {
|
||||
auto inputs = elu_backward_npu_input(grad_output, output);
|
||||
auto outputs = elu_backward_npu_output({grad_input});
|
||||
auto attrs = elu_backward_npu_attr(alpha);
|
||||
CalcuOpUtil::execute_npu_operate("EluGradV2", inputs, outputs, attrs);
|
||||
return grad_input;
|
||||
OpPreparation::CheckOut(
|
||||
{grad_output},
|
||||
grad_input,
|
||||
grad_output);
|
||||
float value = CalcuOpUtil::get_scalar_float_value(alpha);
|
||||
OpCommand cmd;
|
||||
cmd.Name("EluGradV2")
|
||||
.Input(grad_output)
|
||||
.Input(output)
|
||||
.Output(grad_input)
|
||||
.Attr("alpha", value)
|
||||
.Run();
|
||||
return grad_input;
|
||||
}
|
||||
|
||||
Tensor elu_backward_npu(const Tensor& grad_output, Scalar alpha, Scalar scale, Scalar input_scale, const Tensor& output) {
|
||||
// calculate the output size
|
||||
auto outputSize = input_same_output_size(grad_output);
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(outputSize, grad_output.options(), CalcuOpUtil::get_tensor_npu_format(grad_output));
|
||||
// calculate the output result of the NPU
|
||||
elu_backward_out_npu(result, grad_output, alpha, scale, input_scale, output);
|
||||
return result;
|
||||
Tensor result = OpPreparation::ApplyTensor(grad_output);
|
||||
elu_backward_out_npu(result, grad_output, alpha, scale, input_scale, output);
|
||||
return result;
|
||||
}
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
|
||||
@@ -28,7 +28,7 @@ Tensor& embedding_dense_backward_nocheck(
|
||||
int64_t padding_idx,
|
||||
bool scale_grad_by_freq) {
|
||||
// indices must be int64 in pytorch, but npu can only support int32
|
||||
auto indices_int32 = indices.to(at::kInt);
|
||||
auto indices_int32 = indices.npu_dtype_cast(at::kInt);
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("EmbeddingDenseGrad")
|
||||
|
||||
@@ -30,30 +30,13 @@ Tensor& embedding_out_npu(
|
||||
bool scale_grad_by_freq,
|
||||
bool sparse) {
|
||||
SmallVector<int64_t, N> dimVec = {0};
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("GatherV2")
|
||||
.Input(weight)
|
||||
.Input(indices)
|
||||
.Input(dimVec, at::kInt)
|
||||
.Output(result)
|
||||
.Run();
|
||||
} else {
|
||||
OpDynamicCommand cmd;
|
||||
cmd.Name("GatherV2D")
|
||||
.Input(weight)
|
||||
.Input(indices)
|
||||
.Output(result)
|
||||
.Attr("axis", (int64_t)0);
|
||||
Tensor dimTensor_cpu = from_blob((void*)dimVec.data(), {1}, at::kLong).to(at::kInt);
|
||||
Tensor dimTensor_npu = CalcuOpUtil::copy_tensor_host_to_device(dimTensor_cpu);
|
||||
cmd.DynamicName("GatherV2")
|
||||
.DynamicInput(weight)
|
||||
.DynamicInput(indices)
|
||||
.DynamicInput(dimTensor_npu, "axis")
|
||||
.DynamicOutput(result)
|
||||
.DynamicOpRun();
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("GatherV2")
|
||||
.Input(weight)
|
||||
.Input(indices)
|
||||
.Input(dimVec, at::kInt)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ Tensor& embedding_renorm_execute_out_npu(
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Tensor& embedding_renorm_scatter_update_out_npu(
|
||||
Tensor& result,
|
||||
const Tensor& self,
|
||||
@@ -70,41 +69,28 @@ Tensor& embedding_renorm_out_npu(
|
||||
const Tensor& self,
|
||||
const Tensor& indices,
|
||||
double max_norm,
|
||||
double norm_type){
|
||||
|
||||
// get the outSize of GatherV2 , the middle tensor
|
||||
double norm_type) {
|
||||
SmallVector<int64_t, SIZE> midSize = {indices.size(0), self.size(1)};
|
||||
Tensor mid_input = OpPreparation::ApplyTensor(self, midSize);
|
||||
Tensor mid_output = OpPreparation::ApplyTensor(self, midSize);
|
||||
|
||||
// execute the NPU operate GatherV2D, generate new tensor by indices
|
||||
embedding_renorm_gather2d_out_npu(mid_input,self,indices);
|
||||
|
||||
// execute the NPU operate Renorm
|
||||
embedding_renorm_gather2d_out_npu(mid_input, self, indices);
|
||||
embedding_renorm_execute_out_npu(mid_output, mid_input, max_norm, norm_type);
|
||||
|
||||
// execute the NPU operate ZerosLike or RangeD, generate new tensor by indices.numel()
|
||||
Tensor mid_output_copy = mid_output.clone();
|
||||
auto num_indices = indices.numel();
|
||||
Tensor input_indices;
|
||||
|
||||
// RangeD not support range(0,0)
|
||||
if (num_indices - 1 == 0) {
|
||||
input_indices = at::zeros({1}, self.options()).to(at::kLong);
|
||||
auto num_indices = indices.numel();
|
||||
if (num_indices == 1) {
|
||||
input_indices = npu_dtype_cast(at::zeros({1}, self.options()), at::kLong);
|
||||
} else {
|
||||
input_indices = at::range(0, num_indices-1, self.options()).to(at::kLong);
|
||||
input_indices = npu_dtype_cast(at::range(0, num_indices - 1, self.options()), at::kLong);
|
||||
}
|
||||
|
||||
// execute the NPU operate MUL, generate change result
|
||||
auto num_mid_output = mid_output.numel();
|
||||
resize_npu_(mid_output_copy, num_mid_output);
|
||||
Tensor mid_output_copy = mid_output.clone();
|
||||
Tensor scalar_out = OpPreparation::ApplyTensor(self, {num_indices, 1});
|
||||
resize_npu_(mid_output_copy, num_mid_output);
|
||||
embedding_renorm_gather2d_out_npu(scalar_out, mid_output_copy, input_indices);
|
||||
Tensor out_res = mid_input * scalar_out;
|
||||
|
||||
// executing the NPU operator ScatterUpdate
|
||||
embedding_renorm_scatter_update_out_npu(result, self, indices, out_res);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -113,26 +99,19 @@ Tensor& embedding_renorm_npu_(
|
||||
const Tensor& indices,
|
||||
double max_norm,
|
||||
double norm_type) {
|
||||
|
||||
// check dim and type
|
||||
auto self_arg = TensorArg(self, "self", 1);
|
||||
auto indices_arg = TensorArg(indices, "indices", 2);
|
||||
checkDim("embedding_renorm_", self_arg, 2);
|
||||
checkScalarType("embedding_renorm_", indices_arg, kLong);
|
||||
|
||||
// resize indices to 1D
|
||||
Tensor indices_copy = indices.clone();
|
||||
auto num_indices = indices.numel();
|
||||
resize_npu_(indices_copy, num_indices);
|
||||
|
||||
OpPipeWithDefinedOut pipe;
|
||||
pipe.CheckMemory({self, indices_copy}, {self})
|
||||
.Func([&self, &indices_copy, max_norm, norm_type](Tensor& result){
|
||||
embedding_renorm_out_npu(self, self, indices_copy, max_norm, norm_type);})
|
||||
pipe.CheckMemory({self, indices}, {self})
|
||||
.Func([&self, &indices, max_norm, norm_type](Tensor& result){
|
||||
embedding_renorm_out_npu(self, self, indices, max_norm, norm_type);})
|
||||
.Call(self);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2020, Huawei Technologies.All rights reserved.
|
||||
//
|
||||
// Licensed under the BSD 3-Clause License (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://opensource.org/licenses/BSD-3-Clause
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <c10/npu/OptionsManager.h>
|
||||
#include <ATen/native/npu/graph/util/TdtChannelForPrint.h>
|
||||
#include <ATen/native/npu/utils/OpAdapter.h>
|
||||
#include <ATen/native/npu/utils/CalcuOpUtil.h>
|
||||
#include <third_party/acl/inc/op_proto/data_flow_ops.h>
|
||||
namespace {
|
||||
at::native::npu::DynamicInputRegFunc outfeedenque_func =
|
||||
[] (c10::npu::graph::DyNumAndIndex num_and_index,
|
||||
std::string op_name) -> ge::OperatorPtr {
|
||||
auto ge_op =
|
||||
std::make_shared<ge::op::OutfeedEnqueueOpV2>(op_name.c_str());
|
||||
ge_op->create_dynamic_input_byindex_x(num_and_index.front().first,
|
||||
num_and_index.front().second);
|
||||
return ge_op;
|
||||
};
|
||||
}
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
void enque_tensor_npu(TensorList tensors, string tensor_name) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("OutfeedEnqueueOpV2");
|
||||
size_t input_num = tensors.size();
|
||||
for (size_t i = 0UL; i < input_num; i++) {
|
||||
string input_name = "x" + to_string(i);
|
||||
cmd.Input(tensors[i], input_name);
|
||||
}
|
||||
|
||||
std::string channel_name = at::native::npu::TdtChannelForPrint::GetInstance().GetChannelName();
|
||||
TORCH_CHECK(!channel_name.empty(), "Get channel for npu enque tensor failed");
|
||||
cmd.DynamicInputReg(outfeedenque_func, {{input_num, 0}})
|
||||
.Input(tensor_name)
|
||||
.Attr("channel_name", channel_name)
|
||||
.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,8 @@ Tensor& eq_out_npu_nocheck(Tensor& result, const Tensor& self, const Tensor& oth
|
||||
Tensor selfCast = self;
|
||||
Tensor otherCast = other;
|
||||
if (self.dtype() == ScalarType::Int || other.dtype() == ScalarType::Int) {
|
||||
selfCast = self.to(ScalarType::Float);
|
||||
otherCast = other.to(ScalarType::Float);
|
||||
selfCast = self.npu_dtype_cast(ScalarType::Float);
|
||||
otherCast = other.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
auto unified_result = OpPreparation::comparison_op_check(result, selfCast, otherCast, true);
|
||||
OpCommand cmd;
|
||||
@@ -43,7 +43,7 @@ Tensor& eq_out_npu_nocheck(Tensor& result, const Tensor& self, const Tensor& oth
|
||||
Tensor& eq_out_npu_nocheck(Tensor& result, const Tensor& self, Scalar other) {
|
||||
Tensor selfCast = self;
|
||||
if (self.dtype() == ScalarType::Int) {
|
||||
selfCast = self.to(ScalarType::Float);
|
||||
selfCast = self.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("Equal")
|
||||
|
||||
@@ -12,67 +12,48 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor erfinv_npu(const Tensor &self) {
|
||||
auto output_size = self.sizes();
|
||||
auto output_t = at::empty_with_format(output_size, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
|
||||
|
||||
auto inputs = CalcuOpUtil::create_npu_input_tensor_desc({self});
|
||||
auto outputs = CalcuOpUtil::create_npu_output_tensor_desc({output_t});
|
||||
SmallVector<NPUAttrDesc, N> attrs = {};
|
||||
CalcuOpUtil::execute_npu_operate("Erfinv", inputs, outputs, attrs);
|
||||
return output_t;
|
||||
}
|
||||
|
||||
SmallVector<NPUTensorDesc, N> erfinv_npu_input(const SmallVector<Tensor, N>& inputTensor)
|
||||
{
|
||||
return CalcuOpUtil::create_npu_input_tensor_desc(inputTensor);
|
||||
}
|
||||
|
||||
SmallVector<NPUTensorDesc, N> erfinv_npu_output(const SmallVector<Tensor, N>& outputTensor)
|
||||
{
|
||||
return CalcuOpUtil::create_npu_output_tensor_desc(outputTensor);
|
||||
}
|
||||
|
||||
SmallVector<NPUAttrDesc, N> erfinv_npu_attr(const Tensor& self)
|
||||
{
|
||||
SmallVector<NPUAttrDesc, N> attrs = { };
|
||||
return attrs;
|
||||
}
|
||||
|
||||
Tensor& erfinv_out_npu(Tensor& result, const Tensor& self)
|
||||
{
|
||||
// constructs the input and output NPUTensorDesc
|
||||
auto inputs = erfinv_npu_input({self});
|
||||
auto outputs = erfinv_npu_output({result});
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
auto attrs = erfinv_npu_attr(self);
|
||||
// executing the NPU operator
|
||||
CalcuOpUtil::execute_npu_operate("Erfinv", inputs, outputs, attrs);
|
||||
Tensor& erfinv_out_npu_nocheck(const Tensor& self, Tensor& result) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("Erfinv")
|
||||
.Input(self)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& erfinv_npu_(Tensor& self)
|
||||
{
|
||||
SmallVector<Tensor, N> inputs = {self};
|
||||
SmallVector<Tensor, N> outputs = {self};
|
||||
CalcuOpUtil::check_memory_over_laps(inputs, outputs);
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(self);
|
||||
Tensor result = erfinv_out_npu(contiguousSelf, contiguousSelf);
|
||||
NpuUtils::format_fresh_view(self, result);
|
||||
Tensor& erfinv_out_npu(Tensor& result, const Tensor& self) {
|
||||
OpPreparation::CheckOut(
|
||||
{self},
|
||||
result,
|
||||
self);
|
||||
if (!NpuUtils::check_match(&result)) {
|
||||
Tensor contiguousResult = NpuUtils::format_contiguous(result);
|
||||
erfinv_out_npu_nocheck(self, contiguousResult);
|
||||
NpuUtils::format_fresh_view(result, contiguousResult);
|
||||
} else {
|
||||
erfinv_out_npu(self, self);
|
||||
erfinv_out_npu_nocheck(self, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor erfinv_npu(const Tensor &self) {
|
||||
auto result = OpPreparation::ApplyTensor(self);
|
||||
erfinv_out_npu_nocheck(self, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& erfinv_npu_(Tensor& self) {
|
||||
erfinv_out_npu(self, self);
|
||||
return self;
|
||||
}
|
||||
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
} // namespace at
|
||||
|
||||
@@ -11,32 +11,22 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "ATen/native/npu/utils/CalcuOpUtil.h"
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
#include "ATen/native/npu/utils/NpuUtils.h"
|
||||
|
||||
#include "ATen/native/npu/utils/OpAdapter.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
SmallVector<NPUTensorDesc, N> eye_npu_output(const Tensor& result) {
|
||||
return CalcuOpUtil::create_npu_output_tensor_desc({result});
|
||||
}
|
||||
|
||||
SmallVector<NPUAttrDesc, N> eye_npu_attr(int64_t n) {
|
||||
NPUAttrDesc npuDescScalarRow = NPUAttrDesc("num_rows", n);
|
||||
NPUAttrDesc npuDescScalarCol = NPUAttrDesc("num_columns", n);
|
||||
SmallVector<NPUAttrDesc, N> attrs = {npuDescScalarRow, npuDescScalarCol};
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
SmallVector<NPUAttrDesc, N> eye_npu_attr(int64_t n, int64_t m) {
|
||||
NPUAttrDesc npuDescScalarRow = NPUAttrDesc("num_rows", n);
|
||||
NPUAttrDesc npuDescScalarCol = NPUAttrDesc("num_columns", m);
|
||||
SmallVector<NPUAttrDesc, N> attrs = {npuDescScalarRow, npuDescScalarCol};
|
||||
|
||||
return attrs;
|
||||
Tensor& eye_out_npu_nocheck(Tensor& result, int64_t n, int64_t m){
|
||||
OpCommand cmd;
|
||||
cmd.Name("Eye")
|
||||
.Output(result)
|
||||
.Attr("num_rows", n)
|
||||
.Attr("num_columns", m)
|
||||
.Run();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& eye_out_npu(Tensor& result, int64_t n) {
|
||||
@@ -51,47 +41,43 @@ Tensor& eye_out_npu(Tensor& result, int64_t n, int64_t m) {
|
||||
}
|
||||
|
||||
result.resize_({n, m});
|
||||
|
||||
SmallVector<NPUTensorDesc, N> inputs;
|
||||
|
||||
// constracts the output NPUTensorDesc
|
||||
auto outputs = eye_npu_output(result);
|
||||
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
auto attrs = eye_npu_attr(n, m);
|
||||
|
||||
// executing the NPU operator
|
||||
CalcuOpUtil::execute_npu_operate("Eye", inputs, outputs, attrs);
|
||||
|
||||
eye_out_npu_nocheck(result, n, m);
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor eye_npu(int64_t n, const TensorOptions& options) {
|
||||
|
||||
// get the output size
|
||||
auto outputSize = SmallVector<int64_t, N>{n, n};
|
||||
SmallVector<int64_t, N> outputSize = {n, n};
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(outputSize, options, ACL_FORMAT_ND);
|
||||
// The operator does not support the bool type and needs to be converted to an integer.
|
||||
Tensor result = (options.dtype() == at::kBool)
|
||||
? OpPreparation::ApplyTensorWithFormat(outputSize, options.dtype(at::ScalarType::Int), ACL_FORMAT_ND)
|
||||
: OpPreparation::ApplyTensorWithFormat(outputSize, options, ACL_FORMAT_ND);
|
||||
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
eye_out_npu(result, n);
|
||||
|
||||
if(options.dtype() == at::kBool){
|
||||
result = result.npu_dtype_cast(at::kBool);
|
||||
}
|
||||
|
||||
// calculate the output result of the NPU
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor eye_npu(int64_t n, int64_t m, const TensorOptions& options) {
|
||||
// get the output size
|
||||
auto outputSize = SmallVector<int64_t, N>{n, m};
|
||||
SmallVector<int64_t, N> outputSize = {n, m};
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(outputSize, options, ACL_FORMAT_ND);
|
||||
// The operator does not support the bool type and needs to be converted to an integer.
|
||||
Tensor result = (options.dtype() == at::kBool)
|
||||
? OpPreparation::ApplyTensorWithFormat(outputSize, options.dtype(at::ScalarType::Int), ACL_FORMAT_ND)
|
||||
: OpPreparation::ApplyTensorWithFormat(outputSize, options, ACL_FORMAT_ND);
|
||||
|
||||
// constructs the attr of the NPUAttrDesc
|
||||
eye_out_npu(result, n, m);
|
||||
eye_out_npu_nocheck(result, n, m);
|
||||
|
||||
if(options.dtype() == at::kBool){
|
||||
result = result.npu_dtype_cast(at::kBool);
|
||||
}
|
||||
|
||||
// calculate the output result of the NPU
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,27 +22,18 @@ namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor& fill_out_npu(Tensor& result, Tensor& self, const Tensor& other) {
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()) {
|
||||
SmallVector<int64_t, N> dims;
|
||||
if (self.dim() != 0){
|
||||
dims = array_to_small_vector(self.sizes());
|
||||
} else {
|
||||
dims = {1};
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("Fill")
|
||||
.Input(dims, at::kLong)
|
||||
.Input(other)
|
||||
.Output(result)
|
||||
.Run();
|
||||
SmallVector<int64_t, N> dims;
|
||||
if (self.dim() != 0){
|
||||
dims = array_to_small_vector(self.sizes());
|
||||
} else {
|
||||
OpCommand cmd;
|
||||
cmd.Name("FillD")
|
||||
dims = {1};
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("Fill")
|
||||
.Input(dims, at::kLong)
|
||||
.Input(other)
|
||||
.Output(result)
|
||||
.Attr("dims", self.sizes())
|
||||
.Run();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,25 +22,12 @@ using namespace at::native::npu;
|
||||
Tensor flip_npu(const Tensor& self, IntArrayRef dims){
|
||||
Tensor result = OpPreparation::ApplyTensor(self);
|
||||
SmallVector<int64_t,N> dimVec = array_to_small_vector(dims);
|
||||
if (!c10::npu::OptionsManager::CheckDynamicEnable()) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("ReverseV2")
|
||||
.Input(self)
|
||||
.Input(dimVec, at::kLong)
|
||||
.Output(result)
|
||||
.Run();
|
||||
} else {
|
||||
OpDynamicCommand cmd;
|
||||
cmd.Name("ReverseV2D")
|
||||
.Input(self)
|
||||
.Output(result)
|
||||
.Attr("axis", dims);
|
||||
cmd.DynamicName("ReverseV2")
|
||||
.DynamicInput(self)
|
||||
.DynamicInput(dimVec, at::kLong, at::kInt, "axis")
|
||||
.DynamicOutput(result)
|
||||
.DynamicOpRun();
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("ReverseV2")
|
||||
.Input(self)
|
||||
.Input(dimVec, at::kLong)
|
||||
.Output(result)
|
||||
.Run();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <ATen/native/npu/graph/util/GraphModeGuard.h>
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
#include "ATen/native/npu/utils/OpTemplate.h"
|
||||
|
||||
@@ -37,6 +38,8 @@ Tensor get_float_status_npu(const Tensor& self) {
|
||||
}
|
||||
|
||||
Tensor clear_float_status_npu(const Tensor& self) {
|
||||
GraphModeGuard mode_guard(c10::npu::ModeKind::SINGLE_OP_MODE);
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty({FLOAT_STATUS_OP_DIMS_SIZE}, self.options());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor& floor_divide_out_npu(Tensor& result, const Tensor& self, Scalar other) {
|
||||
Tensor& floor_divide_scalar_npu_nocheck(Tensor& result, const Tensor& self, Scalar other) {
|
||||
OpCommand cmd;
|
||||
cmd.Name("FloorDiv")
|
||||
.Input(self)
|
||||
@@ -31,11 +31,19 @@ Tensor& floor_divide_out_npu(Tensor& result, const Tensor& self, Scalar other) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& floor_divide_out_npu(Tensor& result, const Tensor& self, const Tensor& other) {
|
||||
Tensor& floor_divide_out_npu_nocheck(Tensor& result, const Tensor& self, const Tensor& other) {
|
||||
auto unified_result = OpPreparation::binary_op_check(result, self, other, true);
|
||||
// executing the NPU operator
|
||||
Tensor formatCastOfSelf = OpPreparation::CastBackToOriFormat(self);
|
||||
auto outputSize = formatCastOfSelf.sizes();
|
||||
OpPreparation::CheckOut(
|
||||
{self, other},
|
||||
result,
|
||||
CalcuOpUtil::get_tensor_npu_format(self),
|
||||
result.scalar_type(),
|
||||
outputSize);
|
||||
|
||||
if (other.dim() == 0) {
|
||||
floor_divide_out_npu(result, self, other.item());
|
||||
floor_divide_scalar_npu_nocheck(result, self, other.item());
|
||||
} else {
|
||||
OpCommand cmd;
|
||||
cmd.Name("FloorDiv")
|
||||
@@ -45,88 +53,91 @@ Tensor& floor_divide_out_npu(Tensor& result, const Tensor& self, const Tensor& o
|
||||
.Output(result)
|
||||
.Run();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& check_self_dtype_npu(Tensor& self){
|
||||
if (self.dtype() == ScalarType::Bool ||
|
||||
self.dtype() == ScalarType::Int) {
|
||||
self = self.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
std::tuple<Tensor, Tensor> check_dtype_npu(Tensor& self, Tensor& other){
|
||||
if (self.dtype() == ScalarType::Bool ||
|
||||
self.dtype() == ScalarType::Int &&
|
||||
other.scalar_type() == ScalarType::Double) {
|
||||
self = self.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
if (other.scalar_type() == ScalarType::Double) {
|
||||
other = other.to(ScalarType::Float);
|
||||
}
|
||||
if (other.scalar_type() == ScalarType::Long) {
|
||||
other = other.to(ScalarType::Int);
|
||||
}
|
||||
return std::tie(self, other);
|
||||
}
|
||||
|
||||
Tensor& floor_divide_out_npu(Tensor& result, const Tensor& self, const Tensor& other) {
|
||||
Tensor selfCast = self;
|
||||
Tensor otherCast = other;
|
||||
check_dtype_npu(selfCast, otherCast);
|
||||
floor_divide_out_npu_nocheck(result, selfCast, otherCast);
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor floor_divide_npu(const Tensor& self, const Tensor& other) {
|
||||
Tensor selfCast = self;
|
||||
if(self.dtype() == ScalarType::Bool){
|
||||
selfCast = self.to(ScalarType::Float);
|
||||
}
|
||||
Tensor temp = other;
|
||||
if (other.scalar_type() == ScalarType::Double) {
|
||||
temp = other.to(ScalarType::Float);
|
||||
}
|
||||
if (other.scalar_type() == ScalarType::Long) {
|
||||
temp = other.to(ScalarType::Int);
|
||||
}
|
||||
|
||||
// calculate the output size
|
||||
Tensor otherCast = other;
|
||||
check_dtype_npu(selfCast, otherCast);
|
||||
bool isSelfWrapped = CalcuOpUtil::is_scalar_wrapped_to_tensor(selfCast);
|
||||
Tensor outputTensor = isSelfWrapped ? temp : selfCast;
|
||||
Tensor outputTensor = isSelfWrapped ? otherCast : selfCast;
|
||||
auto outputSize = broadcast_ops_npu_output_size(selfCast, otherCast);
|
||||
|
||||
auto outputSize = broadcast_ops_npu_output_size(selfCast, temp);
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(
|
||||
Tensor result = OpPreparation::ApplyTensorWithFormat(
|
||||
outputSize,
|
||||
outputTensor.options(),
|
||||
CalcuOpUtil::get_tensor_npu_format(selfCast));
|
||||
|
||||
// calculate the output result of the NPU
|
||||
floor_divide_out_npu(result, selfCast, temp);
|
||||
|
||||
floor_divide_out_npu_nocheck(result, selfCast, otherCast);
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor floor_divide_npu(const Tensor& self, Scalar other) {
|
||||
|
||||
// calculate the output size
|
||||
auto outputSize = input_same_output_size(self);
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(
|
||||
outputSize, self.options(), CalcuOpUtil::get_tensor_npu_format(self));
|
||||
|
||||
// calculate the output result of the NPU
|
||||
floor_divide_out_npu(result, self, other);
|
||||
|
||||
return result;
|
||||
Tensor selfCast = self;
|
||||
check_self_dtype_npu(selfCast);
|
||||
Tensor result = OpPreparation::ApplyTensor(selfCast);
|
||||
floor_divide_scalar_npu_nocheck(result, selfCast, other);
|
||||
return result;
|
||||
}
|
||||
|
||||
Tensor& floor_divide_npu_(Tensor& self, const Tensor& other) {
|
||||
Tensor temp = other;
|
||||
if (other.scalar_type() == ScalarType::Double) {
|
||||
temp = other.to(ScalarType::Float);
|
||||
}
|
||||
if (other.scalar_type() == ScalarType::Long) {
|
||||
temp = other.to(ScalarType::Int);
|
||||
}
|
||||
SmallVector<Tensor, N> inputs = {self, temp};
|
||||
SmallVector<Tensor, N> outputs = {self};
|
||||
CalcuOpUtil::check_memory_over_laps(inputs, outputs);
|
||||
Tensor otherCast = other;
|
||||
check_dtype_npu(self, otherCast);
|
||||
SmallVector<Tensor, N> inputs = {self, otherCast};
|
||||
SmallVector<Tensor, N> outputs = {self};
|
||||
CalcuOpUtil::check_memory_over_laps(inputs, outputs);
|
||||
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(self);
|
||||
Tensor result = floor_divide_out_npu(contiguousSelf, contiguousSelf, other);
|
||||
NpuUtils::format_fresh_view(self, result);
|
||||
} else {
|
||||
floor_divide_out_npu(self, self, temp);
|
||||
}
|
||||
|
||||
return self;
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(self);
|
||||
Tensor result = floor_divide_out_npu_nocheck(contiguousSelf, contiguousSelf, other);
|
||||
NpuUtils::format_fresh_view(self, result);
|
||||
} else {
|
||||
floor_divide_out_npu_nocheck(self, self, otherCast);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
Tensor& floor_divide_npu_(Tensor& self, Scalar other) {
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(self);
|
||||
floor_divide_out_npu(contiguousSelf, contiguousSelf, other);
|
||||
NpuUtils::format_fresh_view(self, contiguousSelf);
|
||||
} else {
|
||||
floor_divide_out_npu(self, self, other);
|
||||
}
|
||||
return self;
|
||||
check_self_dtype_npu(self);
|
||||
if (!NpuUtils::check_match(&self)) {
|
||||
Tensor contiguousSelf = NpuUtils::format_contiguous(self);
|
||||
floor_divide_scalar_npu_nocheck(contiguousSelf, contiguousSelf, other);
|
||||
NpuUtils::format_fresh_view(self, contiguousSelf);
|
||||
} else {
|
||||
floor_divide_scalar_npu_nocheck(self, self, other);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
} // namespace native
|
||||
|
||||
@@ -26,8 +26,8 @@ Tensor& ge_out_npu_nocheck(Tensor& result, const Tensor& self, const Tensor& oth
|
||||
Tensor otherCast = other;
|
||||
if(self.dtype() == ScalarType::Int || other.dtype() == ScalarType::Int
|
||||
|| self.dtype() == ScalarType::Bool || other.dtype() == ScalarType::Bool){
|
||||
selfCast = self.to(ScalarType::Float);
|
||||
otherCast = other.to(ScalarType::Float);
|
||||
selfCast = self.npu_dtype_cast(ScalarType::Float);
|
||||
otherCast = other.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
auto unified_result = OpPreparation::comparison_op_check(result, selfCast, otherCast, true);
|
||||
OpCommand cmd;
|
||||
@@ -60,7 +60,7 @@ Tensor& ge_out_npu(Tensor& result, const Tensor& self, const Tensor& other) {
|
||||
Tensor& ge_out_npu_nocheck(Tensor& result, const Tensor& self, Scalar other) {
|
||||
Tensor selfCast = self;
|
||||
if(self.dtype() == ScalarType::Int || self.dtype() == ScalarType::Bool){
|
||||
selfCast = self.to(ScalarType::Float);
|
||||
selfCast = self.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
OpCommand cmd;
|
||||
cmd.Name("GreaterEqual")
|
||||
|
||||
@@ -50,14 +50,15 @@ Tensor grid_sampler_2d_npu(
|
||||
formatCastOfGrid.size(2)};
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = OpPreparation::ApplyTensorWithFormat(formatCastOfSelf, outputSize, ACL_FORMAT_ND);
|
||||
|
||||
std::string interMode[] = {"bilinear", "nearest", "bicubic"};
|
||||
std::string paddingMode[] = {"zeros", "border", "reflection"};
|
||||
OpCommand cmd;
|
||||
cmd.Name("GridSampler2D")
|
||||
.Input(formatCastOfSelf)
|
||||
.Input(formatCastOfGrid)
|
||||
.Output(result)
|
||||
.Attr("interpolation_mode", interpolation_mode)
|
||||
.Attr("padding_mode", padding_mode)
|
||||
.Attr("interpolation_mode", interMode[interpolation_mode])
|
||||
.Attr("padding_mode", paddingMode[padding_mode])
|
||||
.Attr("align_corners", align_corners)
|
||||
.Run();
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright (c) 2020 Huawei Technologies Co., Ltd
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensed under the BSD 3-Clause License (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://opensource.org/licenses/BSD-3-Clause
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "ATen/native/npu/utils/KernelNpuOutputSize.h"
|
||||
#include "ATen/native/npu/utils/OpTemplate.h"
|
||||
|
||||
namespace at {
|
||||
namespace native {
|
||||
using namespace at::native::npu;
|
||||
|
||||
Tensor grid_sampler_npu(const Tensor& self, const Tensor& grid,
|
||||
int64_t interpolation_mode, int64_t padding_mode, bool align_corners) {
|
||||
Tensor formatCastOfSelf = self.npu_format_cast(ACL_FORMAT_ND);
|
||||
Tensor formatCastOfGrid = grid.npu_format_cast(ACL_FORMAT_ND);
|
||||
if (formatCastOfSelf.scalar_type() == ScalarType::Half) {
|
||||
formatCastOfSelf = formatCastOfSelf.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
if (formatCastOfGrid.scalar_type() == ScalarType::Half) {
|
||||
formatCastOfGrid = formatCastOfGrid.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
|
||||
// calculate the output size
|
||||
SmallVector<int64_t, SIZE> outputSize = {formatCastOfSelf.size(0),
|
||||
formatCastOfSelf.size(1),
|
||||
formatCastOfGrid.size(1),
|
||||
formatCastOfGrid.size(2)};
|
||||
|
||||
// construct the output tensor of the NPU
|
||||
Tensor result = at::empty_with_format(
|
||||
outputSize, formatCastOfSelf.options(), ACL_FORMAT_ND);
|
||||
|
||||
// calculate the output result of the NPU
|
||||
OpCommand cmd;
|
||||
cmd.Name("GridSampler2D")
|
||||
.Input(formatCastOfSelf)
|
||||
.Input(formatCastOfGrid)
|
||||
.Output(result)
|
||||
.Attr("interpolation_mode", interpolation_mode)
|
||||
.Attr("padding_mode", padding_mode)
|
||||
.Attr("align_corners", align_corners)
|
||||
.Run();
|
||||
|
||||
if (result.scalar_type() != self.scalar_type()) {
|
||||
result = result.npu_dtype_cast(ScalarType::Half);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace native
|
||||
} // namespace at
|
||||
@@ -27,8 +27,8 @@ Tensor& gt_out_npu_nocheck(Tensor& result, const Tensor& self, const Tensor& oth
|
||||
Tensor selfCast = self;
|
||||
Tensor otherCast = other;
|
||||
if(self.dtype() == ScalarType::Bool || other.dtype() == ScalarType::Bool){
|
||||
selfCast = self.to(ScalarType::Float);
|
||||
otherCast = other.to(ScalarType::Float);
|
||||
selfCast = self.npu_dtype_cast(ScalarType::Float);
|
||||
otherCast = other.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
|
||||
OpCommand cmd;
|
||||
@@ -61,7 +61,7 @@ Tensor& gt_out_npu(Tensor& result, const Tensor& self, const Tensor& other) {
|
||||
Tensor& gt_out_npu_nocheck(Tensor& result, const Tensor& self, Scalar other) {
|
||||
Tensor selfCast = self;
|
||||
if(self.dtype() == ScalarType::Bool){
|
||||
selfCast = self.to(ScalarType::Float);
|
||||
selfCast = self.npu_dtype_cast(ScalarType::Float);
|
||||
}
|
||||
|
||||
OpCommand cmd;
|
||||
|
||||
@@ -42,9 +42,9 @@ Tensor& im2col_backward_out_npu_nocheck(
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("Col2im")
|
||||
.Input(gradOutput)
|
||||
.Input(gradOutput, "x", ACL_FORMAT_NCHW)
|
||||
.Input(inputSize, at::kInt)
|
||||
.Output(grad_input)
|
||||
.Output(grad_input, "y", ACL_FORMAT_NCHW)
|
||||
.Attr("kernel_size", kernelSize)
|
||||
.Attr("dilation", dilations)
|
||||
.Attr("padding", paddings)
|
||||
|
||||
@@ -110,7 +110,7 @@ Tensor& im2col_out_npu_nocheck(Tensor& result, const Tensor &self, IntArrayRef k
|
||||
|
||||
OpCommand cmd;
|
||||
cmd.Name("Im2col")
|
||||
.Input(self)
|
||||
.Input(self, "x", ACL_FORMAT_NCHW)
|
||||
.Output(result)
|
||||
.Attr("ksizes", kernelSize)
|
||||
.Attr("strides", stridesSize)
|
||||
|
||||