Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
774baebe55 | ||
|
|
287579ada1 | ||
|
|
131dd9aae8 | ||
|
|
d2f35b9777 | ||
|
|
30160ae4de | ||
|
|
c719415fef | ||
|
|
ddf5b83206 | ||
|
|
26911511de | ||
|
|
6e5dbc57ca | ||
|
|
ba1931a441 | ||
|
|
431e636e9e | ||
|
|
3e91839843 | ||
|
|
4850443eba | ||
|
|
e29e5dd9b9 | ||
|
|
660da0e85d | ||
|
|
f420148b77 | ||
|
|
e50c34dfea | ||
|
|
aad0b4de4e | ||
|
|
8e33c02f0f | ||
|
|
92322edbc4 | ||
|
|
d8bc3ab390 | ||
|
|
4303b8e77f | ||
|
|
c01fcce508 | ||
|
|
3694f59418 | ||
|
|
2fa5dc6b0b | ||
|
|
883d7e923e | ||
|
|
20750f0a9a | ||
|
|
2eaf9d2944 | ||
|
|
7c67039927 | ||
|
|
0488caf153 | ||
|
|
89c6412295 | ||
|
|
c5ac2f45a9 | ||
|
|
4ea5135d4d | ||
|
|
50d3504b51 | ||
|
|
046244ed74 | ||
|
|
1cb32e90a7 | ||
|
|
dc1ef0eb00 | ||
|
|
caf9a961a6 | ||
|
|
746688c5be | ||
|
|
e03782361b | ||
|
|
ef1793c9e2 | ||
|
|
e8697157a2 | ||
|
|
b2e048fc97 | ||
|
|
f65d54dcfa | ||
|
|
2df89a8d08 | ||
|
|
34ac9dfd52 | ||
|
|
5e8296002d | ||
|
|
e5da392470 | ||
|
|
a3ecdfba7a | ||
|
|
058c855e48 | ||
|
|
0edce2564c | ||
|
|
efa59b2200 | ||
|
|
c95745e790 | ||
|
|
bdf3d95bd6 | ||
|
|
735eace090 | ||
|
|
5a26719308 | ||
|
|
3633a172e7 | ||
|
|
9df30bd765 | ||
|
|
8ff2d0947d | ||
|
|
524f6a9663 | ||
|
|
5bf3c1722a | ||
|
|
d9a7fc180a | ||
|
|
24d1c22e18 | ||
|
|
f06123b41a | ||
|
|
0562c43fcc | ||
|
|
0ddf5e6ebc | ||
|
|
41a0d2e918 | ||
|
|
10086fd264 | ||
|
|
a3c056fa5d | ||
|
|
3178fd9561 | ||
|
|
3142dcecea | ||
|
|
fa2157ce49 | ||
|
|
2a0c8f1196 | ||
|
|
05050c7e6b | ||
|
|
e7bf9e6a1c | ||
|
|
1b95bdcdd3 | ||
|
|
b084d6df58 | ||
|
|
db8edc442d | ||
|
|
109ca03752 | ||
|
|
6ce98a9a92 | ||
|
|
31709876be | ||
|
|
c62ab664a5 | ||
|
|
533e520179 | ||
|
|
586cf41a3f | ||
|
|
0ee3963ed6 | ||
|
|
c06919b836 | ||
|
|
8615ed3b4f | ||
|
|
37080cf443 | ||
|
|
c78232d2c0 | ||
|
|
d16be41674 | ||
|
|
630723267c | ||
|
|
795b968518 | ||
|
|
2757d5e475 | ||
|
|
318739a04d | ||
|
|
3131cd3e3d | ||
|
|
c5e9f8a65d | ||
|
|
bf96de52ce | ||
|
|
3d00ccb838 | ||
|
|
0958ececf5 | ||
|
|
dca1a1e942 | ||
|
|
6c2dc57411 | ||
|
|
5bd3a895e9 | ||
|
|
e7328150c8 | ||
|
|
32a5b98293 | ||
|
|
bceda430c8 | ||
|
|
9edb9058f0 | ||
|
|
4e7e9da29c | ||
|
|
d7d201d251 | ||
|
|
95e9590880 | ||
|
|
68897be92e | ||
|
|
6c9cce4cb8 | ||
|
|
6adf15d1dd | ||
|
|
1424ab9c91 | ||
|
|
0a25bdb394 | ||
|
|
a60114d389 | ||
|
|
8fbcaa2542 | ||
|
|
2c4dd2a28e | ||
|
|
9ff2ac83a7 | ||
|
|
a8ed592d30 | ||
|
|
f3953ad39f | ||
|
|
558385f933 | ||
|
|
5931ccc0e0 | ||
|
|
510d4e38bf | ||
|
|
abe3638940 | ||
|
|
4276d15246 | ||
|
|
68e6904aad | ||
|
|
c1b685ec15 | ||
|
|
ae3acfa89c | ||
|
|
905556dc1f | ||
|
|
b97f3d4125 | ||
|
|
dd1a210f0b | ||
|
|
1f17bd7b31 | ||
|
|
c837ed95f9 | ||
|
|
c4718c766a | ||
|
|
2d9d2c3954 | ||
|
|
bde8b65340 | ||
|
|
4bc8ff49b0 | ||
|
|
4971b7b495 | ||
|
|
4ef294bcc1 | ||
|
|
4c32e388f8 | ||
|
|
6a17bae281 | ||
|
|
14996a93fc | ||
|
|
9fc040820b | ||
|
|
c78f539229 | ||
|
|
efd072dbb8 | ||
|
|
f0a7a317d7 | ||
|
|
deaf49c0f0 | ||
|
|
4dd75516a2 | ||
|
|
c53382e05a | ||
|
|
33fe989f66 | ||
|
|
7d42332443 | ||
|
|
32de06a915 | ||
|
|
246a84e3fc | ||
|
|
58f18b5294 | ||
|
|
6d181d7004 | ||
|
|
fa7a9e758d | ||
|
|
b02893d253 | ||
|
|
8a18825d2b | ||
|
|
a388e6de95 | ||
|
|
3fb8100078 | ||
|
|
1917d214e1 | ||
|
|
28d2812ebf | ||
|
|
2eefe1f1b0 | ||
|
|
ab8b1916bf | ||
|
|
9e27f353fa | ||
|
|
e763367d81 | ||
|
|
1986ba362e | ||
|
|
92c00609f1 | ||
|
|
61daeb2ec0 | ||
|
|
a25a3f18ff | ||
|
|
e5d06ab18a | ||
|
|
5e10771032 | ||
|
|
e42a5e79f0 | ||
|
|
f3f9aec20f | ||
|
|
61972e558a | ||
|
|
58bb15db8d | ||
|
|
b4163275eb | ||
|
|
b44bcea8db | ||
|
|
2aee971f9d | ||
|
|
e502a7c848 | ||
|
|
754cc15934 | ||
|
|
d29db7cc67 | ||
|
|
7d04486423 | ||
|
|
6dbdc16833 | ||
|
|
89179e9144 | ||
|
|
a77cbf6e97 | ||
|
|
3861938495 | ||
|
|
57321fab56 | ||
|
|
01e7fae8a3 | ||
|
|
a0e28b3c66 | ||
|
|
15b328eb42 | ||
|
|
eb4004a53d | ||
|
|
e674440b47 | ||
|
|
ceea4fe18f | ||
|
|
32df77e9b7 | ||
|
|
3a82f9463f | ||
|
|
1413e8ae6d | ||
|
|
8c7f762370 | ||
|
|
2f63c547c4 | ||
|
|
46accd209d | ||
|
|
749276da5d | ||
|
|
ccd7267cee | ||
|
|
7dc5159e6d | ||
|
|
89c499e336 | ||
|
|
2bcdf464d4 | ||
|
|
744c908831 | ||
|
|
6d681e0002 | ||
|
|
5c11c8b594 | ||
|
|
184e7af7f9 | ||
|
|
6baa844d09 | ||
|
|
63e4905e0d | ||
|
|
59ada59f12 | ||
|
|
ad159d4008 | ||
|
|
a1ee328dba | ||
|
|
45d935d980 | ||
|
|
4d19446a9c | ||
|
|
41340a0504 | ||
|
|
56fb98d377 | ||
|
|
3bf1ddde1b | ||
|
|
4ef89b5009 | ||
|
|
46065dfb91 | ||
|
|
9eef5f5a13 | ||
|
|
24d72ba3b5 | ||
|
|
6b840a21cd | ||
|
|
805ed0b767 | ||
|
|
276a6fd592 | ||
|
|
6dc23bbcb5 | ||
|
|
0154df7c4c | ||
|
|
4e4a123868 | ||
|
|
e97e5ed2fa | ||
|
|
7d0e020038 | ||
|
|
57c068062d | ||
|
|
8497afbc67 | ||
|
|
50277fc97a | ||
|
|
bd152ae9c9 | ||
|
|
5908caa6c6 | ||
|
|
39c1373934 | ||
|
|
1d112602c3 | ||
|
|
e3a6732327 | ||
|
|
6316eeabb8 | ||
|
|
a03ac753db | ||
|
|
6193332a63 | ||
|
|
329788183e | ||
|
|
b2ec030dab | ||
|
|
0c60492bd7 | ||
|
|
2c9e79c777 | ||
|
|
db40d88649 | ||
|
|
8ce6140b6c | ||
|
|
554167543e | ||
|
|
f0015e8d69 | ||
|
|
ffd17028e2 | ||
|
|
618e228e31 | ||
|
|
f45fc228a1 | ||
|
|
4df4b1d021 | ||
|
|
6198b7013b | ||
|
|
a4a586c099 | ||
|
|
5ce381ee29 | ||
|
|
faf4f8f4a1 | ||
|
|
d03d9902a5 | ||
|
|
ced11d481d | ||
|
|
45f75b2d91 | ||
|
|
22c866562a | ||
|
|
e98fb3e7a9 | ||
|
|
73ec4aa20a | ||
|
|
29c4e3177e | ||
|
|
e557a670f7 | ||
|
|
ac2be3d4b3 | ||
|
|
6b70ebc508 | ||
|
|
2a5c8d712c | ||
|
|
5ae140b269 | ||
|
|
accf0ad0b9 | ||
|
|
901f7aa6a9 | ||
|
|
9846f84eb1 | ||
|
|
2f362da467 | ||
|
|
f112fad7bf | ||
|
|
67b833a230 | ||
|
|
d10fa4eac6 | ||
|
|
484bbfea80 | ||
|
|
7cb21ab5c9 | ||
|
|
988c67fe4a | ||
|
|
02277f6bb8 | ||
|
|
be4930fb5e | ||
|
|
cba848741e | ||
|
|
de4619188c | ||
|
|
fff99b3219 | ||
|
|
c48f3c8406 | ||
|
|
703047dd98 | ||
|
|
783acb8bf1 | ||
|
|
f1107b1799 | ||
|
|
ab33067954 | ||
|
|
33aff05f8b | ||
|
|
7dffeb3877 | ||
|
|
546ed2b617 | ||
|
|
cd65e8be97 | ||
|
|
c7ecb68fd9 | ||
|
|
5cf3dbb015 | ||
|
|
1cf96d4ef5 | ||
|
|
54f51718e3 | ||
|
|
1ea15096a4 | ||
|
|
499097c474 | ||
|
|
598a152b1c | ||
|
|
c2de09166e | ||
|
|
c8aff7cb3e | ||
|
|
c5924abc19 | ||
|
|
912a0494e6 | ||
|
|
b862c56315 | ||
|
|
5d3aa66939 | ||
|
|
75d2a2a05b | ||
|
|
81030a0de6 | ||
|
|
e3a0019cc2 | ||
|
|
fb1ed121b9 | ||
|
|
02af7db9a6 | ||
|
|
a370d2c5ec | ||
|
|
1fb16225e3 | ||
|
|
a843b9e341 | ||
|
|
84b648e708 | ||
|
|
605bc33d1b | ||
|
|
b99ac6da04 | ||
|
|
cf83f8e254 | ||
|
|
9d44cba582 | ||
|
|
32bc6aa8a5 | ||
|
|
a5261b8776 | ||
|
|
291e32ad75 | ||
|
|
a3f914ffff | ||
|
|
4a1995885c | ||
|
|
510bf64e08 | ||
|
|
d9f9579c05 | ||
|
|
01f118eff5 | ||
|
|
c948c58690 | ||
|
|
789b74e496 | ||
|
|
bf2b9c1e70 | ||
|
|
2d19f7bcc4 | ||
|
|
be54a1ae16 | ||
|
|
5821884d10 | ||
|
|
16b654d181 | ||
|
|
a15941b531 | ||
|
|
4c7d261c5d | ||
|
|
d511986f8e | ||
|
|
ad23aa3072 | ||
|
|
069460e0b1 | ||
|
|
8738fdf440 | ||
|
|
97b5cc3747 | ||
|
|
b9b78c4da4 | ||
|
|
794650ffb6 | ||
|
|
f9d863f194 | ||
|
|
2a41383d6e | ||
|
|
ec151adbb7 | ||
|
|
69a12427f2 | ||
|
|
58611cfdc2 | ||
|
|
76803d7a2e | ||
|
|
32ea7725d6 | ||
|
|
7d0b9dffb2 | ||
|
|
58ce863f66 | ||
|
|
ed725f16f9 | ||
|
|
0a9db8d5bc | ||
|
|
1c335f3734 | ||
|
|
15bb908e6d | ||
|
|
05d12f12cd | ||
|
|
b775c31dd6 | ||
|
|
25d5ee5bb5 | ||
|
|
c0019d0c1c | ||
|
|
cbb73d7d7d | ||
|
|
8e34f19670 | ||
|
|
5aa01f8f74 | ||
|
|
aab1760132 | ||
|
|
4aa5714e57 | ||
|
|
708daf9168 | ||
|
|
b55f60052b | ||
|
|
58aabf5807 | ||
|
|
f884ffe7d4 | ||
|
|
a3265a868d | ||
|
|
e5deeac584 | ||
|
|
5ef79b6c4e | ||
|
|
3bf4f83b66 | ||
|
|
5936da408a | ||
|
|
cb77c09b97 | ||
|
|
3a67565f67 | ||
|
|
7fcb40495c | ||
|
|
1d12efd9b3 | ||
|
|
06fed4347b | ||
|
|
0368c9d196 | ||
|
|
240df38f54 | ||
|
|
9f8a959b13 | ||
|
|
ea93144083 | ||
|
|
88f3722a7e | ||
|
|
578699fe7c | ||
|
|
c8e320840a | ||
|
|
10cda1bfcf | ||
|
|
b51465ccc4 | ||
|
|
c35da010df | ||
|
|
f42d1adbf2 | ||
|
|
60c876fccd | ||
|
|
85078b7a6d | ||
|
|
0f30ce7c90 | ||
|
|
43b649c9c3 | ||
|
|
0c3a39d2eb | ||
|
|
8e67bc79c5 | ||
|
|
01525c8043 | ||
|
|
0560393277 | ||
|
|
eaa979182e | ||
|
|
105ce9b9b7 | ||
|
|
7cb2f3f615 | ||
|
|
2c599ad2ab | ||
|
|
5823172995 | ||
|
|
3da9a07053 | ||
|
|
cfc3f32e02 | ||
|
|
6f29462a9b | ||
|
|
3e7c76d4f5 | ||
|
|
52c2074f92 | ||
|
|
d02a477ee1 | ||
|
|
87ef723b94 | ||
|
|
f4bb4b4b97 | ||
|
|
67cf4f85bf | ||
|
|
195dab2fde | ||
|
|
9fa200d68d | ||
|
|
a7158a1929 | ||
|
|
2fb5dc8a49 | ||
|
|
a23d501c29 | ||
|
|
d988e05c1e | ||
|
|
7004fdc8c1 | ||
|
|
1ffbd2c529 | ||
|
|
0ebd5bc2de | ||
|
|
2dab50e911 | ||
|
|
c378e36a49 | ||
|
|
ae60dadb0c | ||
|
|
b2471c6019 | ||
|
|
f23017520f | ||
|
|
59974ffb1f | ||
|
|
a4a74ef608 | ||
|
|
682f4916bc | ||
|
|
98cacfd424 | ||
|
|
6fa6a82725 | ||
|
|
3fb4baa9ae | ||
|
|
4df3f6c129 | ||
|
|
87cd5ddc67 | ||
|
|
4bb25f12a1 | ||
|
|
7670985e45 | ||
|
|
68b3519bba | ||
|
|
f2f1f86dc7 | ||
|
|
61d0e69a87 | ||
|
|
4ffb7eb40a | ||
|
|
a0316876e5 | ||
|
|
c0bcc5cb92 | ||
|
|
8f8e68860e | ||
|
|
1f4e3405b9 | ||
|
|
fbc55e8ae5 | ||
|
|
bd74e86d31 | ||
|
|
98dd3950e3 | ||
|
|
d9256f66f4 | ||
|
|
7aec2ef7b3 | ||
|
|
5455e9181f | ||
|
|
a3abdfeb01 | ||
|
|
a4457668f9 | ||
|
|
8ba5fbcae8 | ||
|
|
e5319854a4 | ||
|
|
1455dcdefb | ||
|
|
78c93d343a | ||
|
|
6e33590fe1 | ||
|
|
1ccb012c63 | ||
|
|
b66b9d76da | ||
|
|
a27ed04728 | ||
|
|
116a7637e9 | ||
|
|
26d8351efb | ||
|
|
b8f7ebf540 | ||
|
|
7d20630d3e | ||
|
|
0e1635a3a5 | ||
|
|
c1046a88a7 | ||
|
|
c68ff46887 | ||
|
|
6e4bd4b8d1 | ||
|
|
3e6aa13e26 | ||
|
|
0cf1761227 | ||
|
|
14a496d500 |
@@ -84,6 +84,7 @@ endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pedantic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=redundant-decls")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=old-style-cast")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(notdir $(abspath $<))\"'")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
|
||||
# These flags are not available in GCC-4.8.5. Set only when using clang.
|
||||
@@ -194,6 +195,7 @@ target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/lib
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libacl_op_compiler.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libge_runner.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libgraph.so)
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libacl_tdt_channel.so)
|
||||
|
||||
target_link_libraries(${PLUGIN_NAME} PUBLIC torch torch_cpu c10 python3.7m)
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ approvers:
|
||||
- blian
|
||||
- nalinaly
|
||||
- weili10
|
||||
- you-ansheng
|
||||
reviewers:
|
||||
- shibo19
|
||||
- Ronnie_zheng
|
||||
- xiaxia3
|
||||
- li_chao10
|
||||
- petissue
|
||||
- td__lihan
|
||||
- ascendzyj
|
||||
@@ -20,4 +20,14 @@ reviewers:
|
||||
- fairwarning
|
||||
- you-ansheng
|
||||
- yinzijun
|
||||
- weili10
|
||||
- weili10
|
||||
- granpad7
|
||||
- clinglai
|
||||
- shaoyf
|
||||
- yanpengquan07
|
||||
- xiong05
|
||||
- liu-jiaweikf
|
||||
- xiepeng20
|
||||
- brightlyking
|
||||
- chenhao_1209
|
||||
- wbigat
|
||||
@@ -488,6 +488,11 @@ To verify the torch_npu reference, switch to another directory. If you perform t
|
||||
|
||||
<img src="figures/FAQ torch_npu.png" style="zoom:150%;" />
|
||||
|
||||
## Multi card training is stuck in initialization stage until timeout
|
||||
|
||||
IPv6 address is used in the "init_process_group" function of multi card communication, for example ::1 (Note that localhost may point to IPv6 address)
|
||||
Use IPv4 to avoid this problem
|
||||
|
||||
# Version Description
|
||||
|
||||
For details, see [Release Notes](https://gitee.com/ascend/pytorch/tree/master/docs/en/RELEASENOTE).
|
||||
|
||||
@@ -30,19 +30,26 @@ apt-get install -y gcc==7.3.0 cmake==3.12.0
|
||||
|
||||
|
||||
# Ascend配套软件
|
||||
| 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 |
|
||||
| AscendPyTorch版本 | CANN版本 | 支持PyTorch版本 | Gitee分支名称 | AscendHub镜像版本 |
|
||||
| :------------ | :----------- | :----------- | ------------- | ------------- |
|
||||
| 2.0.2 | CANN 5.0.2 | 1.5.0.post2 | 2.0.2.tr5 | 21.0.2 |
|
||||
| 2.0.3 | CANN 5.0.3 | 1.5.0.post3 | 2.0.3.tr5 | 21.0.3 |
|
||||
| 2.0.4 | CANN 5.0.4 | 1.5.0.post4 | 2.0.4.tr5 | 21.0.4 |
|
||||
| 3.0.rc1 | CANN 5.1.RC1 | 1.5.0.post5 | v1.5.0-3.0.rc1 | 22.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 | 22.0.RC2 |
|
||||
| 3.0.rc2 | CANN 5.1.RC2 | 1.8.1.rc2 | v1.8.1-3.0.rc2 | 22.0.RC2-1.8.1 |
|
||||
| 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 | 22.0.RC3-1.8.1 |
|
||||
| 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 | \ |
|
||||
|
||||
|
||||
# 安装方式
|
||||
|
||||
## 安装Pytorch依赖环境
|
||||
## 安装PyTorch依赖环境
|
||||
|
||||
如果使用非root用户安装,用户需要在本步骤的每句命令后加**--user**,示例如:pip3 install pyyaml --user。
|
||||
|
||||
@@ -59,15 +66,19 @@ pip3 install wheel
|
||||
#x86_64
|
||||
pip3 install torch==1.8.1+cpu #若使用pip命令安装cpu版本PyTorch报错,请手动下载whl包安装,下载地址:(https://download.pytorch.org/whl/torch)
|
||||
|
||||
#aarch64
|
||||
#社区未提供arm架构cpu安装包,请参见FAQ第一条,使用源码编译安装pytorch
|
||||
#aarch64(推荐使用镜像)
|
||||
1.可在docker中使用AscendHub镜像仓库提供的基于PyTorch版本制作的基础镜像,包含训练、转换和推理等功能。
|
||||
#镜像仓库地址:(https://ascendhub.huawei.com/#/detail/pytorch-modelzoo)
|
||||
2.鲲鹏arm服务器可在鲲鹏开源软件文件共享中心获取编译好的PyTorch二进制安装包。
|
||||
#鲲鹏文件共享中心地址:(https://mirrors.huaweicloud.com/kunpeng/archive/Ascend/PyTorch/)
|
||||
3.社区未提供的arm架构cpu安装包,可参见FAQ第一条,使用源码编译安装pytorch。
|
||||
```
|
||||
|
||||
编译生成pytorch插件的二进制安装包。
|
||||
|
||||
```
|
||||
# 下载master分支代码,进入插件根目录
|
||||
git clone -b master https://gitee.com/ascend/pytorch.git
|
||||
# 下载1.8.1-3.0.0分支代码,进入插件根目录
|
||||
git clone -b v1.8.1-3.0.0 https://gitee.com/ascend/pytorch.git
|
||||
cd pytorch
|
||||
# 指定python版本编包方式:
|
||||
bash ci/build.sh --python=3.7
|
||||
@@ -80,7 +91,7 @@ bash ci/build.sh --python=3.9
|
||||
然后安装pytorch/dist下生成的插件torch_npu包,{arch}为架构名称。
|
||||
|
||||
```
|
||||
pip3 install --upgrade dist/torch_npu-1.8.1rc2-cp37-cp37m-linux_{arch}.whl
|
||||
pip3 install --upgrade dist/torch_npu-1.8.1-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
|
||||
下载torchvision。
|
||||
@@ -181,11 +192,13 @@ 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
|
||||
|
||||
@@ -205,6 +218,12 @@ git submodule sync
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
配置环境变量
|
||||
|
||||
```
|
||||
export USE_XNNPACK=0
|
||||
```
|
||||
|
||||
执行编译安装。
|
||||
|
||||
```
|
||||
@@ -485,7 +504,7 @@ warning如下图所示,由Tensor.set_data浅拷贝操作触发。主要原因
|
||||
|
||||
该warning不影响模型的精度和性能,可以忽略。
|
||||
|
||||
待NPU 设备号合入社区或者后续Pytorch版本`_has_compatible_shallow_copy_type`注册方式发生变动,该warning会被解决。
|
||||
待NPU 设备号合入社区或者后续PyTorch版本`_has_compatible_shallow_copy_type`注册方式发生变动,该warning会被解决。
|
||||
|
||||

|
||||
|
||||
@@ -493,9 +512,53 @@ warning如下图所示,由Tensor.set_data浅拷贝操作触发。主要原因
|
||||
|
||||
验证torch_npu的引入,请切换至其他目录进行,在编译目录执行会提示如下错误。
|
||||
|
||||
|
||||
<img src="figures/FAQ torch_npu.png" style="zoom:150%;" />
|
||||
|
||||
## 在执行import torch_npu时出现ModuleNotFooundError: NO module named '_lzma'报错问题
|
||||
|
||||
在python命令行下,执行import torch_npu测试时,出现ModuleNotFooundError: NO module named '_lzma'问题,可能由于Python环境失效,重装Python即可。<img src="figures/QA.png" />
|
||||
|
||||
## 编译过程中出现XNNPACK相关的Make Error报错
|
||||
|
||||
编译原生pytorch时,未配置相关环境变量,导致编译不成功。
|
||||
|
||||

|
||||
|
||||
1. 执行命令设置环境变量
|
||||
|
||||
```
|
||||
export USE_XNNPACK=0
|
||||
```
|
||||
|
||||
2. 执行命令清除当前编译内容
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
3. 重新编译
|
||||
|
||||
## 编译时出现Breakpad error: field 'regs' has incomplete type 'google_breakpad::user_regs_struct'报错
|
||||
|
||||
编译原生pytorch时,未配置相关环境变量,导致编译不成功。
|
||||
|
||||
1. 执行命令配置环境变量
|
||||
|
||||
```
|
||||
export BUILD_BREAKPAD=0
|
||||
```
|
||||
|
||||
2. 执行命令清除当前编译内容
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
3. 重新编译
|
||||
|
||||
## 多卡训练初始化阶段卡顿至超时
|
||||
|
||||
init_process_group 函数中使用了IPV6地址,例如::1(注意localhost 可能指向IPv6的地址),使用IPv4可以避免这个问题
|
||||
# 版本说明
|
||||
|
||||
版本说明请参阅[ReleseNote](docs/zh/RELEASENOTE)
|
||||
@@ -52,6 +52,9 @@ apt-get install -y gcc==7.3.0 cmake==3.12.0
|
||||
| 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 | v1.11.0-3.0.rc3 |
|
||||
|
||||
# 安装方式<a name="安装方式"></a>
|
||||
|
||||
@@ -79,8 +82,8 @@ pip3 install torch==1.8.1+cpu #若使用pip命令安装cpu版本PyTorch报错,
|
||||
编译生成pytorch插件的二进制安装包。
|
||||
|
||||
```
|
||||
# 下载master分支代码,进入插件根目录
|
||||
git clone -b master https://gitee.com/ascend/pytorch.git
|
||||
# 下载v1.8.1-3.0.rc3分支代码,进入插件根目录
|
||||
git clone -b v1.8.1-3.0.rc3 https://gitee.com/ascend/pytorch.git
|
||||
cd pytorch
|
||||
# 指定python版本编包方式:
|
||||
bash ci/build.sh --python=3.7
|
||||
@@ -93,7 +96,7 @@ bash ci/build.sh --python=3.9
|
||||
然后安装pytorch/dist下生成的插件torch_npu包,{arch}为架构名称。
|
||||
|
||||
```
|
||||
pip3 install --upgrade dist/torch_npu-1.8.1rc2-cp37-cp37m-linux_{arch}.whl
|
||||
pip3 install --upgrade dist/torch_npu-1.8.1rc3-cp37-cp37m-linux_{arch}.whl
|
||||
```
|
||||
下载torchvision。
|
||||
```
|
||||
@@ -475,8 +478,53 @@ warning如下图所示,由Tensor.set_data浅拷贝操作触发。主要原因
|
||||
|
||||
<img src="figures/FAQ torch_npu.png" style="zoom:150%;" />
|
||||
|
||||
## 在执行import torch_npu时出现ModuleNotFooundError: NO module named '_lzma'报错问题
|
||||
|
||||
5在python命令行下,执行import torch_npu测试时,出现ModuleNotFooundError: NO module named '_lzma'问题,可能由于Python环境失效,重装Python即可。<img src="figures/QA.png" />
|
||||
|
||||
## 编译过程中出现XNNPACK相关的Make Error报错
|
||||
|
||||
编译原生pytorch时,未配置相关环境变量,导致编译不成功。
|
||||
|
||||

|
||||
|
||||
1. 执行命令设置环境变量
|
||||
|
||||
```
|
||||
export USE_XNNPACK=0
|
||||
```
|
||||
|
||||
2. 执行命令清除当前编译内容
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
3. 重新编译
|
||||
|
||||
## 编译时出现Breakpad error: field 'regs' has incomplete type 'google_breakpad::user_regs_struct'报错
|
||||
|
||||
编译原生pytorch时,未配置相关环境变量,导致编译不成功。
|
||||
|
||||
1. 执行命令配置环境变量
|
||||
|
||||
```
|
||||
export BUILD_BREAKPAD=0
|
||||
```
|
||||
|
||||
2. 执行命令清除当前编译内容
|
||||
|
||||
```
|
||||
make clean
|
||||
```
|
||||
|
||||
3. 重新编译
|
||||
|
||||
## 多卡训练初始化阶段卡顿至超时
|
||||
|
||||
init_process_group 函数中使用了IPV6地址,例如::1(注意localhost 可能指向IPv6的地址),使用IPv4可以避免这个问题
|
||||
|
||||
|
||||
# 版本说明<a name='版本说明'></a>
|
||||
|
||||
版本说明请参阅[ReleseNote](https://gitee.com/ascend/pytorch/blob/master/docs/zh/RELEASENOTE/RELEASENOTE.md)
|
||||
版本说明请参阅[ReleseNote](https://gitee.com/ascend/pytorch/blob/v1.8.1-3.0.rc3/docs/zh/RELEASENOTE/RELEASENOTE.md)
|
||||
|
||||
|
After Width: | Height: | Size: 377 KiB |
|
After Width: | Height: | Size: 288 KiB |
@@ -29,7 +29,7 @@
|
||||
- [自定义算子导出方法](#自定义算子导出方法md)
|
||||
<h2 id="简介md">简介</h2>
|
||||
|
||||
### 概述<a name="zh-cn_topic_0000001125558589_section7405182695312"></a>
|
||||
#### 概述<a name="zh-cn_topic_0000001125558589_section7405182695312"></a>
|
||||
|
||||
为了实现PyTorch深度学习框架在昇腾AI处理器上运行,需要将框架算子用TBE自定义开发。
|
||||
|
||||
@@ -167,7 +167,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
- 当前昇腾AI处理器中支持的算子以及对应的算子约束可以通过以下两种方式查询。
|
||||
- 命令行开发方式下,您可以参见《CANN 算子清单 \(Ascend 910\)》进行离线查询。
|
||||
- MindStudio开发方式下,您可以通过MindStudio进行在线查询,详细查看方法可参见《MindStudio 用户指南》中的“算子&模型速查”章节。
|
||||
- 当前PyTorch适配的算子列表可以参见[《PyTorch API支持清单》](https://gitee.com/ascend/pytorch/blob/master/docs/zh/PyTorch%20API%E6%94%AF%E6%8C%81%E6%B8%85%E5%8D%95.md)。
|
||||
- 当前PyTorch适配的算子列表可以参见[《PyTorch API支持清单》](https://gitee.com/ascend/pytorch/blob/v1.8.1-3.0.rc3/docs/zh/PyTorch%20API%E6%94%AF%E6%8C%81%E6%B8%85%E5%8D%95.md)。
|
||||
|
||||
<h2 id="算子适配开发md">算子适配开发</h2>
|
||||
|
||||
@@ -189,7 +189,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
|
||||
<h3 id="获取PyTorch源码md">获取PyTorch源码</h3>
|
||||
|
||||
针对pytorch1.8.1版本,PyTorch源码获取请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/master/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_v1.8.1"目录生成适配昇腾AI处理器的全量代码步骤。将在pytorch/pytorch目录中进行PyTorch 算子适配开发。
|
||||
针对pytorch1.8.1版本,PyTorch源码获取请参见[《PyTorch安装指南》](https://gitee.com/ascend/pytorch/blob/v1.8.1-3.0.rc3/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_v1.8.1"目录生成适配昇腾AI处理器的全量代码步骤。将在pytorch/pytorch目录中进行PyTorch 算子适配开发。
|
||||
|
||||
<h3 id="注册算子开发md">注册算子开发</h3>
|
||||
|
||||
@@ -200,7 +200,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
|
||||
<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,会生成在 torch_npu/csrc/aten/RegisterNPU.cpp。
|
||||
|
||||
<h4 id="PyTorch1-8-1-注册算子开发md">PyTorch1.8.1 注册算子开发</h4>
|
||||
|
||||
@@ -208,7 +208,7 @@ PyTorch算子开发包含TBE算子开发和PyTorch框架下的算子适配。
|
||||
|
||||
1. 打开native\_functions.yaml文件。
|
||||
|
||||
native\_functions.yaml 文件中,定义了所有算子函数原型,包括函数名称和参数等信息,每个算子函数支持不同硬件平台的派发信息。该文件所在路径为pytorch/aten/src/ATen/native/native\_functions.yaml。
|
||||
native\_functions.yaml 文件中,定义了所有算子函数原型,包括函数名称和参数等信息,每个算子函数支持不同硬件平台的派发信息。该文件所在路径为scripts/codegen/native\_functions.yaml。
|
||||
|
||||
2. 确定需要派发函数。
|
||||
- yaml 中已存在的算子
|
||||
@@ -688,7 +688,7 @@ pip3 install --upgrade torch_npu-1.8.1rc1-cp37-cp37m-linux_{arch}.whl
|
||||
|
||||
3. 执行测试用例脚本
|
||||
|
||||
进入test\_add.py所在的目录,执行:
|
||||
进入test\_add.py所在的目录/test/test_network_ops,执行:
|
||||
|
||||
```
|
||||
python3.7 test_add.py
|
||||
@@ -831,7 +831,7 @@ pip3.7 install torchvision --no-deps
|
||||
至此步骤,不应该有错误,屏幕应该输出 "add" 中增加的日志打印。若出错,请完成代码清理排查,保证无新开发的代码影响测试。
|
||||
|
||||
3. 将新开发的“自定义TBE算子”合并到"cann"中,在对应的在算子入口增加日志打印,作为运行标识。
|
||||
4. 完成上面的"cann"编译、安装,调用“python3.7.5 test\_add.py”进行测试。
|
||||
4. 完成上面的"cann"编译、安装,调用“python3.7 test\_add.py”进行测试。
|
||||
|
||||
> **说明:**
|
||||
>根据Ascend的设计逻辑,用户开发安装的“custom”算子包优先级高于“built-in”的内置算子包,在运行加载时,会优先加载调度“custom”包中的算子。过程中,若解析“custom”中的算子信息文件失败,则会跳过“custom”算子包,不加载调度任何“custom”算子包中的任何算子。
|
||||
@@ -839,11 +839,11 @@ pip3.7 install torchvision --no-deps
|
||||
>- 若此步骤出错,或屏幕未输出 "add" 中增加的日志打印,则说明新开发的“自定义TBE算子”有错误,影响了“自定义算子包”的加载,建议**优先排查新开发的“自定义TBE算子”中的“算子信息定义”是否正确**。
|
||||
>- 若此步骤正确,至少说明 **新开发的“自定义TBE算子”中的“算子信息定义”不影响运行**。
|
||||
|
||||
5. 调用“python3.7.5 xxx\_testcase.py”进行测试;
|
||||
5. 调用“python3.7 xxx\_testcase.py”进行测试,xxx为新增算子名称;
|
||||
|
||||
> **说明:**
|
||||
>- 若屏幕正常输出新开发的“自定义TBE算子”中增加的日志打印,则至少说明调度到了新开发的算子。
|
||||
>- 若屏幕未输出新开发的“自定义TBE算子”中增加的日志打印,则问题可能出现在“PyTorch适配”中,需要排查这一部分的实现代码,较多的可能会出现在“XxxxKernelNpu.cpp”中的输入、输出未能正确适配。
|
||||
>- 若屏幕未输出新开发的“自定义TBE算子”中增加的日志打印,则问题可能出现在“PyTorch适配”中,需要排查这一部分的实现代码,较多的可能会出现在“XxxxKernelNpu.cpp”中的输入、输出未能正确适配,XxxxKernelNpu.cpp为新增算子信息文件。
|
||||
|
||||
|
||||
|
||||
@@ -859,7 +859,7 @@ pip3.7 install torchvision --no-deps
|
||||
1. 打开安装在用户目录下的算子包安装目录。
|
||||
|
||||
```
|
||||
cd ~/.local/Ascend/opp/op_impl/built-in/ai_core/tbe/impl
|
||||
cd /usr/local/Ascend/ascend-toolkit/op_impl/build-in/ai_core/tbe/config/ascend910/
|
||||
ll
|
||||
```
|
||||
|
||||
|
||||
@@ -12,7 +12,14 @@
|
||||
|
||||
在同一模型或算子调试过程中,遇到算子相关的计算精度问题,定位时费时费力,所以推出了一个精度比对工具。
|
||||
|
||||
精度对比工具,通过在PyTorch模型中注入hook,跟踪计算图中算子的前向传播与反向传播时的输入与输出,对比npu芯片中的算子计算数值与cpu(gpu)芯片中的算子计算数值进行对比,排查npu算子在npu芯片中存在计算精度误差,进行问题的精准定位。
|
||||
精度对比工具,通过在PyTorch模型中注入hook,跟踪计算图中算子的前向传播与反向传播时的输入与输出,排查存在计算精度误差,进行问题的精准定位。
|
||||
|
||||
主要的使用场景包括:
|
||||
|
||||
- 同一模型,从gpu(或cpu)移植到npu中存在精度下降问题,对比npu芯片中的算子计算数值与gpu(cpu)芯片中的算子计算数值,进行问题定位。
|
||||
- 同一模型,进行迭代(模型、算子或设备迭代)时存在的精度下降问题,对比相同模型在迭代前后版本的算子计算数值,进行问题定位。
|
||||
|
||||
以gpu为参照定位精度问题,使用ptdbg_ascend插件来进行数据dump和比对,请参考[ptdbg_ascend](https://gitee.com/ascend/tools/tree/master/ptdbg_ascend)。
|
||||
|
||||
## **前提条件**
|
||||
|
||||
@@ -61,7 +68,7 @@
|
||||
cos(\theta) = \frac{\sum_{i=1}^{n} (\hat{y_{i}} \times y_{i})}
|
||||
{\sqrt{\sum_{i=1}^{n}\hat{y_{i}}} \times \sqrt{\sum_{i=1}^{n}y_{i}^{2}}}
|
||||
$$
|
||||
当余弦夹角数值越接近于1说明计算出的两个张量越相似
|
||||
当余弦夹角数值越接近于1说明计算出的两个张量越相似,在计算中可能会存在nan,主要由于可能会出现其中一个向量为0
|
||||
|
||||
2. 均方根误差(RMSE):
|
||||
|
||||
@@ -89,7 +96,7 @@ import os
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from torch_npu.hooks import set_dump_path, seed_all, register_acc_cmp_hook
|
||||
from torch_npu.hooks import set_dump_path, seed_all, register_hook, wrap_acc_cmp_hook
|
||||
from torch_npu.hooks.tools import compare
|
||||
|
||||
|
||||
@@ -108,10 +115,10 @@ class ModuleOP(nn.Module):
|
||||
r1 = self.relu(x2)
|
||||
return r1
|
||||
|
||||
|
||||
# 对该网络进行hook注入和数据dump
|
||||
module = ModuleOp()
|
||||
register_acc_cmp_hook(module) # 对模型注入forwar和backward的hooks
|
||||
# 对模型注入forwar和backward的hooks,如需关闭,请使用register_hook(model_cpu, wrap_acc_cmp_hook, sample=False)
|
||||
register_hook(model_cpu, wrap_acc_cmp_hook)
|
||||
seed_all()
|
||||
x = torch.randn(2, 2)
|
||||
|
||||
@@ -135,7 +142,7 @@ compare("./npu_module_op.pkl", "./cpu_module_op.pkl", "./module_result.csv")
|
||||
```
|
||||
|
||||
|
||||
使用精度比对工具进行torchvision下现有模型的计算精度比对,整体思路相同,以resnet50模型为例代码如下:
|
||||
使用精度比对工具进行torchvision下现有模型的计算精度比对,整体思路相同,其中cpu和npu的对比思路与npu和npu的对比思路也是相同,以resnet50模型为例代码如下:
|
||||
```python
|
||||
import os
|
||||
import copy
|
||||
@@ -143,7 +150,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
from torchvision import models, datasets, transforms
|
||||
|
||||
from torch_npu.hooks import set_dump_path, seed_all, register_acc_cmp_hook
|
||||
from torch_npu.hooks import set_dump_path, seed_all, register_hook, wrap_acc_cmp_hook
|
||||
from torch_npu.hooks.tools import compare
|
||||
|
||||
|
||||
@@ -153,12 +160,12 @@ model_cpu.eval()
|
||||
model_npu = copy.deepcopy(model_cpu)
|
||||
model_npu.eval()
|
||||
|
||||
# 对该计算进行hook注入和数据dump
|
||||
register_acc_cmp_hook(model_cpu)
|
||||
register_acc_cmp_hook(model_npu)
|
||||
seed_all()
|
||||
# 对该计算进行hook注入和数据dump,采样功能默认开启,如需关闭,请使用register_hook(model_cpu, wrap_acc_cmp_hook, sample=False)
|
||||
register_hook(model_cpu, wrap_acc_cmp_hook)
|
||||
register_hook(model_npu, wrap_acc_cmp_hook)
|
||||
|
||||
# 需要根据不同的模型输入和标签生成相应的tensor(或读取实际数据),损失函数等
|
||||
# 需要根据不同的模型输入和标签生成相应的tensor(或读取实际数据),损失函数等,如果是随机生成的标签需要保证数据的有效性
|
||||
inputs = torch.randn(1, 3, 244, 244)
|
||||
labels = torch.randn(1).long()
|
||||
criterion = nn.CrossEntropyLoss()
|
||||
@@ -181,4 +188,17 @@ loss.backward()
|
||||
# 对比dump出的数据精度,生成csv文件
|
||||
compare("./npu_resnet50_op.pkl", "./cpu_resnet50_op.pkl", "./resnet50_result.csv")
|
||||
```
|
||||
如需相对生成的pkl文件解析读取数据,可参考下列代码
|
||||
```python
|
||||
import json
|
||||
|
||||
pkl_file=open(pkl_path,'r') # pkl_path:需要解析的文件
|
||||
tensor_line=pkl_file.readline() # 读取行数据
|
||||
tensor_data=json.loads(tensor_line)
|
||||
|
||||
print(tensor_data[0]) # 算子名称
|
||||
print(tensor_data[1]) # 对应数据
|
||||
print(tensor_data[2]) # 数据类型
|
||||
print(tensor_data[3]) # 数据尺寸
|
||||
|
||||
```
|
||||
@@ -11,6 +11,7 @@
|
||||
华为对自有训练模型算子进行了优化,其中包括算子消除、算子融合、算子拆分等,以更好的适配NPU等训练设备。
|
||||
因此在模型迁移的过程中,有时会遇到自有实现的算子运算的结果与业界标准算子运算结果存在偏差,精度不达标的问题,需要借助计算精度比对工具得出模型中的哪些算子在GPU和NPU的计算中会存在较大的差异,从而重点分析这些算子的表现性能,帮助开发人员快速定位并解决算子精度问题。
|
||||
|
||||
此外在进行模型版本迭代、底层算子迭代、计算设备(npu)迭代时也可能会引入计算精度的问题,有时会遇到新实现的算子运算的结果与要被替代的算子运算结果存在偏差等,需要借助计算精度对比工具得出那些算子在不同的版本或在不同的设备上存在较大的计算差异,从而快速定位计算精度问题。
|
||||
## **已有的精度对比脚本工具**
|
||||
|
||||
目前已经有一些可以进行精度比对的脚本示例,其主要思路都是相同的,包括整网对比和单算子对比,如图所示。
|
||||
|
||||
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 607 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 946 B |
|
After Width: | Height: | Size: 356 B |
|
After Width: | Height: | Size: 946 B |
|
After Width: | Height: | Size: 356 B |
|
After Width: | Height: | Size: 329 KiB |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 103 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 580 B |
|
After Width: | Height: | Size: 394 B |
|
After Width: | Height: | Size: 406 B |
|
After Width: | Height: | Size: 253 B |
|
After Width: | Height: | Size: 580 B |
@@ -1,4 +1,18 @@
|
||||
# FrameworkPTAdapter 3.0.RC2 版本说明书
|
||||
# FrameworkPTAdapter 3.0.0 版本说明书
|
||||
- [FrameworkPTAdapter 3.0.0](#FrameworkPTAdapter-3-0-0md)
|
||||
- [用户须知](#用户须知md)
|
||||
- [新增特性](#新增特性md)
|
||||
- [特性修改](#特性修改md)
|
||||
- [已修复问题](#已修复问题md)
|
||||
- [已知问题](#已知问题md)
|
||||
- [兼容性](#兼容性md)
|
||||
- [FrameworkPTAdapter 3.0.RC3](#FrameworkPTAdapter-3-0-RC3md)
|
||||
- [用户须知](#用户须知md)
|
||||
- [新增特性](#新增特性md)
|
||||
- [特性修改](#特性修改md)
|
||||
- [已修复问题](#已修复问题md)
|
||||
- [已知问题](#已知问题md)
|
||||
- [兼容性](#兼容性md)
|
||||
- [FrameworkPTAdapter 3.0.RC2](#FrameworkPTAdapter-3-0-RC2md)
|
||||
- [用户须知](#用户须知md)
|
||||
- [新增特性](#新增特性md)
|
||||
@@ -35,6 +49,174 @@
|
||||
- [已知问题](#已知问题-4md)
|
||||
- [兼容性](#兼容性-5md)
|
||||
|
||||
<h2 id="FrameworkPTAdapter-3-0-0md">FrameworkPTAdapter 3.0.0</h2>
|
||||
|
||||
<h3 id="用户须知md">用户须知</h3>
|
||||
|
||||
本框架基于Facebook主导的开源PyTorch进行修改,延续原生的PyTorch特性,使用NPU进行动态图训练;以算子粒度进行模型适配,代码重用性好,支持现有的网络只修改设备类型或数据类型,即可迁移到NPU上使用。
|
||||
|
||||
PyTorch1.8.1版本开始采用插件化适配方式,与原生PyTorch框架实现彻底解耦,功能、性能与PyTorch1.5.0基本保持一致,对后端算子适配提供较好开发体验。PyTorch 1.11.0当前为beta版本,建议优先使用PyTorch 1.8.1版本。
|
||||
|
||||
<h3 id="新增特性md">新增特性</h3>
|
||||
|
||||
**表 1** PyTorch支持的版本特性列表
|
||||
|
||||
<a name="t76c34275cbb74753970f7c5a9eb594fa"></a>
|
||||
|
||||
<table><thead align="left"><tr id="r0c10e7163bf54fe8816ab5ca2d77ccc4"><th class="cellrowborder" valign="top" width="25.590000000000003%" 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="15.52%" 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="58.89%" id="mcps1.2.4.1.3"><p id="a2a1562364b09433a83133fa10b3cf2b3"><a name="a2a1562364b09433a83133fa10b3cf2b3"></a><a name="a2a1562364b09433a83133fa10b3cf2b3"></a>说明</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row91681125173610"><td class="cellrowborder" valign="top" width="25.590000000000003%" headers="mcps1.2.4.1.1 "><p id="p1712174492611"><a name="p1712174492611"></a><a name="p1712174492611"></a>适配NPU的PyTorch1.5.0特性</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.52%" headers="mcps1.2.4.1.2 "><p id="p2168172519364"><a name="p2168172519364"></a><a name="p2168172519364"></a>框架基础功能</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="58.89%" headers="mcps1.2.4.1.3 "><p id="p1416815259367"><a name="p1416815259367"></a><a name="p1416815259367"></a>适配CANN算子IR变更。</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row2620183971614"><td class="cellrowborder" rowspan="3" valign="top" width="25.590000000000003%" headers="mcps1.2.4.1.1 "><p id="p0819102247"><a name="p0819102247"></a><a name="p0819102247"></a>适配NPU的PyTorch1.8.1特性</p>
|
||||
<p id="p15488161812213"><a name="p15488161812213"></a><a name="p15488161812213"></a></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.52%" headers="mcps1.2.4.1.2 "><p id="p76365489137"><a name="p76365489137"></a><a name="p76365489137"></a>框架基础功能</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="58.89%" headers="mcps1.2.4.1.3 "><p id="p363616485131"><a name="p363616485131"></a><a name="p363616485131"></a>支持NPU Tensor类型,修复少量BUG</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row945906124515"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1077934311314"><a name="p1077934311314"></a><a name="p1077934311314"></a>序列化存取</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p977954315133"><a name="p977954315133"></a><a name="p977954315133"></a>支持NPU Tensor直接序列化存取,完善torch.save/load接口能力</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13545374516"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p44561110214"><a name="p44561110214"></a><a name="p44561110214"></a>精度对比工具</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p412459182110"><a name="p412459182110"></a><a name="p412459182110"></a>支持溢出检测,优化数据dump性能</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row3722227133312"><td class="cellrowborder" rowspan="3" valign="top" width="25.590000000000003%" headers="mcps1.2.4.1.1 "><p id="p107221327153315"><a name="p107221327153315"></a><a name="p107221327153315"></a>适配NPU的PyTorch1.11.0特性</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="15.52%" headers="mcps1.2.4.1.2 "><p id="p153563917719"><a name="p153563917719"></a><a name="p153563917719"></a>框架基础功能</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="58.89%" headers="mcps1.2.4.1.3 "><p id="p272242719336"><a name="p272242719336"></a><a name="p272242719336"></a>支持NPU Tensor类型,修复少量BUG</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row6631141014305"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1416445591310"><a name="p1416445591310"></a><a name="p1416445591310"></a>序列化存取</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p11164185561312"><a name="p11164185561312"></a><a name="p11164185561312"></a>支持NPU Tensor直接序列化存取,完善torch.save/load接口能力</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row270811563411"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p121645556134"><a name="p121645556134"></a><a name="p121645556134"></a>精度对比工具</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1716425591313"><a name="p1716425591313"></a><a name="p1716425591313"></a>支持溢出检测,优化数据dump性能</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>
|
||||
</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-RC3md">FrameworkPTAdapter 3.0.RC3</h2>
|
||||
|
||||
<h3 id="用户须知md">用户须知</h3>
|
||||
|
||||
本框架基于Facebook主导的开源PyTorch进行修改,延续原生的PyTorch特性,使用NPU进行动态图训练;以算子粒度进行模型适配,代码重用性好,支持现有的网络只修改设备类型或数据类型,即可迁移到NPU上使用。
|
||||
|
||||
PyTorch1.8.1版本开始采用插件化适配方式,与原生PyTorch框架实现彻底解耦,功能、性能与PyTorch1.5.0基本保持一致,对后端算子适配提供较好开发体验。
|
||||
|
||||
<h3 id="新增特性md">新增特性</h3>
|
||||
|
||||
**表 1** PyTorch支持的版本特性列表
|
||||
|
||||
| 一级特性 | 二级特性 | 说明 |
|
||||
| -------------------------- | -------------------------------- | ---------------------------------------------- |
|
||||
| 适配NPU的PyTorch1.5.0特性 | 框架基础功能 | 适配CANN算子IR变更。 |
|
||||
| 适配NPU的PyTorch1.8.1特性 | 精度对比工具 | 支持NPU与CPU精度对比工具。 |
|
||||
| profiling | 支持自定义算子profiling。 | |
|
||||
| API满足度提升 | 新增部分API适配(详见API清单)。 | |
|
||||
| 适配NPU的PyTorch1.11.0特性 | 框架基础功能 | 支持模型训练功能,适配算子API(详见API清单)。 |
|
||||
| 混合精度 | 支持apex混合精度训练。 | |
|
||||
| 分布式 | 支持DDP分布式训练功能。 | |
|
||||
| profiling | 支持E2E profiling功能。 | |
|
||||
|
||||
<h3 id="特性修改md">特性修改</h3>
|
||||
|
||||
不涉及
|
||||
|
||||
<h3 id="已修复问题md">已修复问题</h3>
|
||||
|
||||
不涉及
|
||||
|
||||
<h3 id="已知问题md">已知问题</h3>
|
||||
|
||||
| 已知问题 | 问题描述 |
|
||||
| --------------------------------------------- | ------------------------------------------------------------ |
|
||||
| 数据类型支持 | NPU不支持float16类型的inf/nan数据输入输出。 |
|
||||
| 数据Format | 出现4D以上的format时不能降维。 |
|
||||
| 集合通信约束 | 要求一次训练任务中不同device上执行的图相同。 |
|
||||
| 当前只支持1/2/4/8P粒度的分配。 | |
|
||||
| 只支持int8,int32,float16和float32数据类型。 | |
|
||||
| Apex功能支持 | Apex当前版本的实现方式主要为python实现,不支持APEX中的自定义优化CUDA Kernel。 |
|
||||
|
||||
<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-RC2md">FrameworkPTAdapter 3.0.RC2</h2>
|
||||
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 377 KiB |
|
After Width: | Height: | Size: 288 KiB |
@@ -25,7 +25,11 @@ backend = None
|
||||
|
||||
def transfer_args_of_wrapper_func_to_cpu(sig: DispatcherSignature, func: NativeFunction) -> Tuple[str, List[str]]:
|
||||
convert: str = f"// Convert args to cpu in order to use at::native kernel \n " \
|
||||
f"std::cout << \"Cur kernel: {sig.func.name} is running on cpu.\" << std::endl; \n "
|
||||
f"static auto warn_once = [](){{ \n " \
|
||||
f"std::cout << \"Warning: kernel [{sig.func.name}] is not supported by NPU currently. " \
|
||||
f"Now this kernel is running on CPU.\" << std::endl; \n " \
|
||||
f"return true; \n " \
|
||||
f"}}(); \n "
|
||||
args_names: List[str] = []
|
||||
args = native_arguments(sig.func, func.use_c10_dispatcher)
|
||||
for arg in args:
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <torch/csrc/Device.h>
|
||||
#include <torch/csrc/tensor/python_tensor.h>
|
||||
|
||||
#include "torch_npu/csrc/core/Device.h"
|
||||
|
||||
namespace at_npu {
|
||||
namespace key {
|
||||
static constexpr c10::DeviceType NativeDeviceType = c10::DeviceType::XLA;
|
||||
@@ -40,7 +42,7 @@ static bool isDeviceTensor(const at::Tensor &tensor) {
|
||||
}
|
||||
|
||||
static at::Device parse_npu_device(PyObject* obj) {
|
||||
if (!obj) {
|
||||
if (!obj || obj == Py_None) {
|
||||
return at::Device(c10::backendToDeviceType(c10::dispatchKeyToBackend(torch::tensors::get_default_dispatch_key())));
|
||||
}
|
||||
if (THPUtils_checkLong(obj)) {
|
||||
@@ -60,6 +62,8 @@ static at::Device parse_npu_device(PyObject* obj) {
|
||||
const auto device = reinterpret_cast<THPDevice*>(obj);
|
||||
return device->device;
|
||||
}
|
||||
const auto device = reinterpret_cast<TNPDevice*>(obj);
|
||||
return device->device;
|
||||
}
|
||||
|
||||
static c10::optional<at::Device> parse_npu_device_optional(PyObject* obj) {
|
||||
|
||||
@@ -13,18 +13,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import numpy
|
||||
import torch
|
||||
|
||||
|
||||
import torch_npu
|
||||
from torch_npu.utils.device_guard import torch_device_guard, device
|
||||
|
||||
|
||||
@torch_device_guard
|
||||
def _device(*args, **kwargs):
|
||||
new_device = torch_npu.new_device(*args, **kwargs)
|
||||
if new_device.type == torch.npu.native_device:
|
||||
return device(type=torch_npu.npu.npu_device, index=new_device.index)
|
||||
return new_device
|
||||
from torch_npu.utils.device_guard import torch_device_guard
|
||||
|
||||
|
||||
@torch_device_guard
|
||||
@@ -62,26 +55,31 @@ def _npu_dropout_gen_mask(*args, **kwargs):
|
||||
return torch_npu.npu_dropout_gen_mask(*args, **kwargs)
|
||||
|
||||
|
||||
@torch_device_guard
|
||||
def _new_device(*args, **kwargs):
|
||||
return torch_npu._C.device(*args, **kwargs)
|
||||
|
||||
|
||||
def jit_script(obj, optimize=None, _frames_up=0, _rcb=None):
|
||||
# (Ascend) Disable extension of torch.jit.script
|
||||
return obj
|
||||
|
||||
|
||||
def _as_tensor(*args, **kwargs):
|
||||
if isinstance(args[0], torch.Tensor):
|
||||
dst_device = args[0].device
|
||||
else:
|
||||
dst_device = "cpu"
|
||||
|
||||
if kwargs and "device" in kwargs:
|
||||
dst_device = kwargs.get("device")
|
||||
if "npu" in str(dst_device):
|
||||
if isinstance(args[0], numpy.ndarray):
|
||||
return torch.from_numpy(args[0]).to(dst_device)
|
||||
else:
|
||||
return args[0].to(dst_device)
|
||||
return torch._C._VariableFunctions.as_tensor(*args, **kwargs)
|
||||
dst_device = kwargs.pop("device")
|
||||
|
||||
return torch._C._VariableFunctions.as_tensor(*args, **kwargs).to(dst_device)
|
||||
|
||||
|
||||
${device_methods_def_py_dispatch}
|
||||
|
||||
def add_torch_funcs():
|
||||
torch.device = _device
|
||||
torch.tensor = _tensor
|
||||
torch.full = _full
|
||||
torch.randint = _randint
|
||||
@@ -91,5 +89,6 @@ def add_torch_funcs():
|
||||
torch.npu_dropout_gen_mask = _npu_dropout_gen_mask
|
||||
torch.jit.script = jit_script
|
||||
torch.as_tensor = _as_tensor
|
||||
torch.new_device = _new_device
|
||||
|
||||
${device_methods_def_py}
|
||||
@@ -19,10 +19,12 @@ import multiprocessing.pool
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import traceback
|
||||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
import distutils.ccompiler
|
||||
import distutils.command.clean
|
||||
@@ -36,7 +38,21 @@ from setuptools.command.build_clib import build_clib
|
||||
from setuptools.command.egg_info import egg_info
|
||||
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
VERSION = '1.8.1rc3'
|
||||
VERSION = '1.8.1'
|
||||
|
||||
|
||||
def generate_torch_npu_version():
|
||||
torch_npu_root = Path(__file__).parent
|
||||
version_path = torch_npu_root / "torch_npu" / "version.py"
|
||||
if version_path.exists():
|
||||
version_path.unlink()
|
||||
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
|
||||
modes = stat.S_IWUSR | stat.S_IRUSR
|
||||
with os.fdopen(os.open(version_path, flags, modes), 'w') as f:
|
||||
f.write("__version__ = '{version}'\n".format(version=VERSION))
|
||||
|
||||
|
||||
generate_torch_npu_version()
|
||||
|
||||
|
||||
def which(thefile):
|
||||
@@ -226,6 +242,8 @@ def get_src_py_and_dst():
|
||||
ret = []
|
||||
generated_python_files = glob.glob(
|
||||
os.path.join(BASE_DIR, "torch_npu", '**/*.py'),
|
||||
recursive=True) + glob.glob(
|
||||
os.path.join(BASE_DIR, "torch_npu", '**/*.yaml'),
|
||||
recursive=True)
|
||||
for src in generated_python_files:
|
||||
dst = os.path.join(
|
||||
|
||||
@@ -63,19 +63,38 @@ class WN(torch.nn.Module):
|
||||
|
||||
class TestSerialization(TestCase):
|
||||
'''
|
||||
The saved data is transferred to PyTorch CPU device before being saved, so a
|
||||
following `torch.load()` will load CPU data.
|
||||
The saved data is saved by using the PyTorch CPU storage structure, but
|
||||
following `torch.load()` will load the corresponding NPU data.
|
||||
'''
|
||||
def test_save(self):
|
||||
x = torch.randn(5).npu()
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
path = os.path.join(tmpdir, 'data.pt')
|
||||
torch.save(x, path)
|
||||
self.assertExpectedInline(str(x.device), f'{torch_npu.npu.native_device}:0')
|
||||
self.assertExpectedInline(f'{x.device.type}:{x.device.index}', f'{torch_npu.npu.npu_device}:0')
|
||||
x_loaded = torch.load(path, map_location="npu:0")
|
||||
x_loaded = x_loaded.npu()
|
||||
self.assertRtolEqual(x.cpu(), x_loaded.cpu())
|
||||
y_loaded = torch.load(path, map_location="npu")
|
||||
self.assertRtolEqual(x.cpu(), y_loaded.cpu())
|
||||
z_loaded = torch.load(path, map_location=torch.device("npu"))
|
||||
self.assertRtolEqual(x.cpu(), z_loaded.cpu())
|
||||
m_loaded = torch.load(path, map_location="cpu")
|
||||
self.assertRtolEqual(x.cpu(), m_loaded)
|
||||
n_loaded = torch.load(path, map_location=torch.device("cpu"))
|
||||
self.assertRtolEqual(x.cpu(), n_loaded)
|
||||
|
||||
def test_load_maplocation(self):
|
||||
x = torch.randn(2, 3)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
path = os.path.join(tmpdir, 'data.pt')
|
||||
torch.save(x, path)
|
||||
x_loaded = torch.load(path, map_location="npu:0")
|
||||
self.assertExpectedInline(f'{x_loaded.device.type}', f'{torch_npu.npu.npu_device}')
|
||||
self.assertRtolEqual(x, x_loaded.cpu())
|
||||
x_loaded = torch.load(path, map_location=torch.device("npu:0"))
|
||||
self.assertExpectedInline(f'{x_loaded.device.type}', f'{torch_npu.npu.npu_device}')
|
||||
self.assertRtolEqual(x, x_loaded.cpu())
|
||||
|
||||
def test_save_string(self):
|
||||
x = dict(ds_version='0.6.0+0b40f54')
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
@@ -100,7 +119,7 @@ class TestSerialization(TestCase):
|
||||
path = os.path.join(tmpdir, 'data.pt')
|
||||
torch.save((x, model, number), path)
|
||||
x_loaded, model_loaded, number_loaded = torch.load(path)
|
||||
self.assertRtolEqual(x.cpu(), x_loaded)
|
||||
self.assertRtolEqual(x.cpu(), x_loaded.cpu())
|
||||
self.assertExpectedInline(str(model), str(model_loaded))
|
||||
self.assertTrue(number, number_loaded)
|
||||
|
||||
|
||||
@@ -177,6 +177,12 @@ class TestCreationOps(TestCase):
|
||||
cpu_output = torch.as_tensor(npu_input, device="cpu")
|
||||
self.assertRtolEqual(cpu_output.numpy(), npu_input.cpu().numpy())
|
||||
|
||||
# npu tesor to npu tensor
|
||||
npu_input = torch.tensor([1, 2, 3]).npu()
|
||||
npu_output = torch.as_tensor(npu_input)
|
||||
self.assertEqual(npu_input.device, npu_output.device)
|
||||
self.assertRtolEqual(npu_input.cpu().numpy(), npu_output.cpu().numpy())
|
||||
|
||||
def test_as_strided(self):
|
||||
x = torch.randn(3, 3, device='npu:0')
|
||||
npu_output1 = torch.as_strided(x, (2, 2), (1, 2))
|
||||
|
||||
@@ -19,7 +19,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
import torch_npu
|
||||
from torch_npu.contrib.module import NpuFairseqDropout
|
||||
from torch_npu.contrib.module import NpuFairseqDropout, NpuCachedDropout
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
@@ -32,24 +32,25 @@ class NpuMNIST(nn.Module):
|
||||
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
|
||||
self.fc1 = nn.Linear(320, 50)
|
||||
self.fc2 = nn.Linear(50, 10)
|
||||
self.dropout = NpuFairseqDropout(p=1)
|
||||
|
||||
def forward(self, x):
|
||||
def forward(self, x, dropout):
|
||||
x = F.relu(F.max_pool2d(self.conv1(x), 2))
|
||||
x = F.relu(F.max_pool2d(self.conv2(x), 2))
|
||||
x = self.dropout(x)
|
||||
x = dropout(x)
|
||||
x = x.view(-1, 40)
|
||||
return x
|
||||
|
||||
|
||||
class TestEnsembleDropout(unittest.TestCase):
|
||||
def test_EnsembleDropout(self):
|
||||
model = NpuMNIST().to("npu")
|
||||
x = torch.randn(2,10,16,16).to("npu")
|
||||
NpuFairseqDropout.enable_dropout_ensemble(model)
|
||||
output = model(x)
|
||||
dropout = NpuFairseqDropout(p=1)
|
||||
output = model(x, dropout)
|
||||
|
||||
NpuCachedDropout.enable_dropout_ensemble(model)
|
||||
dropout = NpuCachedDropout(p=1)
|
||||
output = model(x, dropout)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ class TestDevice(TestCase):
|
||||
npu_tensor = func(self, *args, **kwargs)
|
||||
self.assertEqual(npu_tensor.device.type, "npu")
|
||||
self.assertEqual(npu_tensor.device.index, device_id)
|
||||
kwargs["device"] = None
|
||||
func(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
@@ -67,6 +69,66 @@ class TestDevice(TestCase):
|
||||
cpu_input = torch.randn(2,3)
|
||||
return cpu_input.npu(device)
|
||||
|
||||
@device_monitor
|
||||
def test_torch_func_tensor_with_device_input(self, device=None):
|
||||
return torch.tensor((2, 3), device=device)
|
||||
|
||||
|
||||
def test_device_argument_as_input(self):
|
||||
device_str = "npu:0"
|
||||
|
||||
torch.npu.set_device(device_str)
|
||||
device = torch.device(device_str)
|
||||
assert isinstance(device, torch.device)
|
||||
|
||||
torch.npu.set_device(device)
|
||||
tensor = torch.rand(2,3).npu()
|
||||
assert isinstance(tensor.device, torch.device)
|
||||
assert tensor.device.type == "npu"
|
||||
assert tensor.device.index == 0
|
||||
|
||||
new_device = torch.device(device)
|
||||
assert isinstance(new_device, torch.device)
|
||||
assert new_device.type == "npu"
|
||||
assert new_device.index == 0
|
||||
|
||||
new_device = torch.device(device=device)
|
||||
assert isinstance(new_device, torch.device)
|
||||
assert new_device.type == "npu"
|
||||
assert new_device.index == 0
|
||||
|
||||
new_device = torch.device(device=device_str)
|
||||
assert isinstance(new_device, torch.device)
|
||||
assert new_device.type == "npu"
|
||||
assert new_device.index == 0
|
||||
|
||||
new_device = torch.device(type="npu", index=0)
|
||||
assert isinstance(new_device, torch.device)
|
||||
assert new_device.type == "npu"
|
||||
assert new_device.index == 0
|
||||
|
||||
new_device = torch.device(torch._C.device(device_str.replace("npu", "xla")))
|
||||
assert isinstance(new_device, torch.device)
|
||||
assert new_device.type == "npu"
|
||||
assert new_device.index == 0
|
||||
|
||||
assert not isinstance(torch._C.device(device_str.replace("npu", "xla")), torch.device)
|
||||
|
||||
new_device = torch.new_device(torch._C.device(device_str.replace("npu", "xla")))
|
||||
assert isinstance(new_device, torch.device)
|
||||
assert new_device.type == "npu"
|
||||
assert new_device.index == 0
|
||||
|
||||
new_device = torch.new_device(torch.device(device_str))
|
||||
assert isinstance(new_device, torch.device)
|
||||
assert new_device.type == "npu"
|
||||
assert new_device.index == 0
|
||||
|
||||
|
||||
device = torch.device(None)
|
||||
assert device.type == "cpu"
|
||||
device = torch.device(device=None)
|
||||
assert device.type == "cpu"
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_tests()
|
||||
@@ -12,11 +12,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch_npu
|
||||
import numpy as np
|
||||
import torch.distributed as dist
|
||||
import torch.multiprocessing as mp
|
||||
|
||||
@@ -75,8 +75,10 @@ class HcclReduceTest(TestCase):
|
||||
for shape in shape_format:
|
||||
if shape[0] == np.int8:
|
||||
shape[1] = 0
|
||||
expected, input1 = create_common_tensor(shape, -10, 10)
|
||||
expected *= world_size
|
||||
exp_input, input1 = create_common_tensor(shape, -10, 10)
|
||||
expected = 0
|
||||
for _ in range(world_size):
|
||||
expected += exp_input
|
||||
self._test_multiprocess(HcclReduceTest._test_reduce,
|
||||
HcclReduceTest._init_dist_hccl, expected, input1, world_size)
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
# 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.
|
||||
|
||||
|
||||
import os
|
||||
import torch
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.hooks import set_dump_path, seed_all, register_acc_cmp_hook
|
||||
from torch_npu.hooks.tools import compare
|
||||
|
||||
|
||||
class TestFunctionalOP(torch.nn.Linear):
|
||||
|
||||
def forward(self, x):
|
||||
x1 = torch.nn.functional.linear(x, self.weight, self.bias)
|
||||
x2 = torch.nn.functional.relu(x1)
|
||||
if (x2 == 0).any():
|
||||
return x1
|
||||
return x2
|
||||
|
||||
|
||||
class TestTensorBuiltinOP(torch.nn.Module):
|
||||
|
||||
def forward(self, x, y):
|
||||
z_add = x + y
|
||||
z_sub = x - y
|
||||
z = z_add * z_sub
|
||||
if (z == z_add).any():
|
||||
return z_sub
|
||||
return z
|
||||
|
||||
|
||||
class TestTorchOP(torch.nn.Module):
|
||||
|
||||
def forward(self, x, y):
|
||||
z_add = torch.add(x, y)
|
||||
z_sub = torch.sub(x, y)
|
||||
z_relu = torch.relu(z_add)
|
||||
z = torch.add(z_sub, z_relu)
|
||||
if (z != z_sub).any():
|
||||
return z_sub
|
||||
return z
|
||||
|
||||
|
||||
class TestAccCmpHookBackwardhook(TestCase):
|
||||
|
||||
def test_function_op(self):
|
||||
module = TestFunctionalOP(3, 4)
|
||||
register_acc_cmp_hook(module)
|
||||
seed_all()
|
||||
set_dump_path("./cpu_functional_op.pkl")
|
||||
x = torch.randn(2, 3, 3)
|
||||
x.requires_grad = True
|
||||
out = module(x)
|
||||
loss = torch.sum(out)
|
||||
loss.backward()
|
||||
set_dump_path("./npu_functional_op.pkl")
|
||||
module.npu()
|
||||
x = x.npu()
|
||||
out = module(x)
|
||||
loss = out.sum()
|
||||
loss.backward()
|
||||
assert os.path.exists("./cpu_functional_op.pkl") and os.path.exists("./npu_functional_op.pkl")
|
||||
compare("./npu_functional_op.pkl", "./cpu_functional_op.pkl", "./functional_op_result.csv")
|
||||
assert os.path.exists("./functional_op_result.csv")
|
||||
|
||||
def test_tensor_bulitin_op(self):
|
||||
module = TestTensorBuiltinOP()
|
||||
register_acc_cmp_hook(module)
|
||||
seed_all()
|
||||
set_dump_path("./cpu_tensor_builtin_op.pkl")
|
||||
x = torch.randn(2, 3, 4)
|
||||
y = torch.randn(2, 3, 4)
|
||||
x.requires_grad = True
|
||||
y.requires_grad = True
|
||||
out = module(x, y)
|
||||
loss = out.sum()
|
||||
loss.backward()
|
||||
set_dump_path("./npu_tensor_builtin_op.pkl")
|
||||
module.npu()
|
||||
x = x.npu()
|
||||
y = y.npu()
|
||||
out = module(x, y)
|
||||
loss = out.sum()
|
||||
loss.backward()
|
||||
assert os.path.exists("./cpu_tensor_builtin_op.pkl") and os.path.exists("./npu_tensor_builtin_op.pkl")
|
||||
compare("./npu_tensor_builtin_op.pkl", "./cpu_tensor_builtin_op.pkl", "./tensor_builtin_op_result.csv")
|
||||
assert os.path.exists("./tensor_builtin_op_result.csv")
|
||||
|
||||
def test_tensor_op(self):
|
||||
module = TestTorchOP()
|
||||
register_acc_cmp_hook(module)
|
||||
seed_all()
|
||||
set_dump_path("./cpu_torch_op.pkl")
|
||||
x = torch.randn(2, 3, 4)
|
||||
y = torch.randn(2, 3, 4)
|
||||
x.requires_grad = True
|
||||
y.requires_grad = True
|
||||
out = module(x, y)
|
||||
loss = torch.sum(out)
|
||||
loss.backward()
|
||||
set_dump_path("./npu_torch_op.pkl")
|
||||
module.npu()
|
||||
x = x.npu()
|
||||
y = y.npu()
|
||||
out = module(x, y)
|
||||
loss = out.sum()
|
||||
loss.backward()
|
||||
assert os.path.exists("./cpu_torch_op.pkl") and os.path.exists("./npu_torch_op.pkl")
|
||||
compare("./npu_torch_op.pkl", "./cpu_torch_op.pkl", "./torch_op_result.csv")
|
||||
assert os.path.exists("./torch_op_result.csv")
|
||||
|
||||
def tearDown(self) -> None:
|
||||
for filename in os.listdir('./'):
|
||||
if filename.endswith(".pkl"):
|
||||
os.remove("./" + filename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run_tests()
|
||||
@@ -0,0 +1,93 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
|
||||
import torch
|
||||
import numpy as np
|
||||
import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
|
||||
|
||||
class TestAminmax(TestCase):
|
||||
def cpu_op_exec(self, input0):
|
||||
output = torch._aminmax(input0)
|
||||
output0 = output[0].numpy()
|
||||
output1 = output[1].numpy()
|
||||
return output0, output1
|
||||
|
||||
def npu_op_exec(self, input0):
|
||||
output = torch._aminmax(input0)
|
||||
output0 = output[0].cpu().numpy()
|
||||
output1 = output[1].cpu().numpy()
|
||||
return output0, output1
|
||||
|
||||
def cpu_op_dim_exec(self, input0, dim, keepdim):
|
||||
output = torch._aminmax(input0, dim, keepdim)
|
||||
output0 = output[0].numpy()
|
||||
output1 = output[1].numpy()
|
||||
return output0, output1
|
||||
|
||||
def npu_op_dim_exec(self, input0, dim, keepdim):
|
||||
output = torch._aminmax(input0, dim, keepdim)
|
||||
output0 = output[0].cpu().numpy()
|
||||
output1 = output[1].cpu().numpy()
|
||||
return output0, output1
|
||||
|
||||
def test__aminmax_shape_format(self, device="npu"):
|
||||
shape_format = [
|
||||
[np.float16, 0, [256, 1000]],
|
||||
[np.float32, 0, [1000]],
|
||||
[np.int8, 0, [256, 1000, 4, 4]],
|
||||
[np.int16, 0, [1000, 128, 3]],
|
||||
[np.int32, 0, [256]],
|
||||
[np.uint8, 0, [100, 128, 1000]],
|
||||
[np.int64, 0, [100, 128, 1000]],
|
||||
]
|
||||
|
||||
for item in shape_format:
|
||||
cpu_input, npu_input = create_common_tensor(item, 0, 100)
|
||||
if cpu_input.dtype == torch.half:
|
||||
cpu_input = cpu_input.to(torch.float)
|
||||
|
||||
cpu_output0, cpu_output1 = self.cpu_op_exec(cpu_input)
|
||||
npu_output0, npu_output1 = self.npu_op_exec(npu_input)
|
||||
|
||||
self.assertRtolEqual(cpu_output0.astype(npu_output0.dtype), npu_output0)
|
||||
self.assertRtolEqual(cpu_output1.astype(npu_output1.dtype), npu_output1)
|
||||
|
||||
def test__aminmax_dim_shape_format(self, device="npu"):
|
||||
shape_format = [
|
||||
[np.float16, 0, [64, 4]],
|
||||
[np.float32, 0, [32, 4, 16, 8]],
|
||||
]
|
||||
|
||||
for item in shape_format:
|
||||
cpu_input, npu_input = create_common_tensor(item, 0, 100)
|
||||
dim = np.random.randint(len(item[2]))
|
||||
keepdim = np.random.randint(10) > 4
|
||||
if cpu_input.dtype == torch.half:
|
||||
cpu_input = cpu_input.to(torch.float)
|
||||
|
||||
cpu_output0, cpu_output1 = self.cpu_op_dim_exec(cpu_input, dim, keepdim)
|
||||
npu_output0, npu_output1 = self.npu_op_dim_exec(npu_input, dim, keepdim)
|
||||
|
||||
self.assertRtolEqual(cpu_output0.astype(npu_output0.dtype), npu_output0)
|
||||
self.assertRtolEqual(cpu_output1.astype(npu_output1.dtype), npu_output1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
@@ -18,6 +18,7 @@ import numpy as np
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
from torch_npu.testing.decorator import graph_mode
|
||||
|
||||
|
||||
class TestAdaptiveMaxPool2d(TestCase):
|
||||
@@ -31,6 +32,7 @@ class TestAdaptiveMaxPool2d(TestCase):
|
||||
output = m(input1)
|
||||
return output.cpu().numpy()
|
||||
|
||||
@graph_mode
|
||||
def test_adaptiveMaxPool2d_shape_format_fp32_6(self):
|
||||
format_list = [-1]
|
||||
# (1, 8, 9) IndexError
|
||||
@@ -47,6 +49,7 @@ class TestAdaptiveMaxPool2d(TestCase):
|
||||
|
||||
self.assertRtolEqual(cpu_output, npu_output, 0.0004)
|
||||
|
||||
@graph_mode
|
||||
def test_adaptiveMaxPool2d_case_in_photo2cartoon(self):
|
||||
cpu_x = torch.rand(1, 256, 31, 31)
|
||||
npu_x = cpu_x.npu()
|
||||
@@ -54,6 +57,7 @@ class TestAdaptiveMaxPool2d(TestCase):
|
||||
npu_out = F.adaptive_max_pool2d(npu_x, 1)
|
||||
self.assertRtolEqual(cpu_out, npu_out.cpu(), 0.0003)
|
||||
|
||||
@graph_mode
|
||||
def test_adaptiveMaxPool2d_case_in_photo2cartoon_fp16(self):
|
||||
cpu_x = torch.rand(1, 256, 31, 31).half()
|
||||
npu_x = cpu_x.npu()
|
||||
|
||||
@@ -19,6 +19,7 @@ import numpy as np
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
from torch_npu.testing.decorator import graph_mode
|
||||
|
||||
|
||||
class TestAdaptiveMaxPool2dBackward(TestCase):
|
||||
@@ -39,6 +40,7 @@ class TestAdaptiveMaxPool2dBackward(TestCase):
|
||||
npu_grad = npu_grad.to("cpu")
|
||||
return npu_grad
|
||||
|
||||
@graph_mode
|
||||
def test_adaptiveMaxPool2d_shape_format_fp32_6(self):
|
||||
format_list = [0, 3]
|
||||
shape_list = [(1, 3, 8, 9)]
|
||||
@@ -55,6 +57,7 @@ class TestAdaptiveMaxPool2dBackward(TestCase):
|
||||
npu_output = self.npu_op_exec(npu_input, output_size)
|
||||
self.assertRtolEqual(cpu_output, npu_output)
|
||||
|
||||
@graph_mode
|
||||
def test_adaptiveMaxPool2d_backward_case_in_photo2cartoon(self):
|
||||
cpu_x = torch.rand(1, 256, 31, 31)
|
||||
npu_x = cpu_x.npu()
|
||||
@@ -66,6 +69,7 @@ class TestAdaptiveMaxPool2dBackward(TestCase):
|
||||
npu_out.backward(torch.ones_like(npu_out))
|
||||
self.assertRtolEqual(cpu_x.grad, npu_x.grad.cpu(), 0.0003)
|
||||
|
||||
@graph_mode
|
||||
def test_adaptiveMaxPool2d_backward_case_in_photo2cartoon_fp16(self):
|
||||
cpu_x = torch.rand(1, 256, 31, 31).half()
|
||||
npu_x = cpu_x.npu()
|
||||
|
||||
@@ -13,13 +13,16 @@
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
|
||||
import torch
|
||||
import torch_npu
|
||||
import numpy as np
|
||||
|
||||
import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
|
||||
|
||||
class TestAddCMul(TestCase):
|
||||
def generate_data(self, min_d, max_d, shape, dtype):
|
||||
input1 = np.random.uniform(min_d, max_d, shape).astype(dtype)
|
||||
|
||||
@@ -13,13 +13,16 @@
|
||||
|
||||
import copy
|
||||
import sys
|
||||
|
||||
import torch
|
||||
import torch_npu
|
||||
import numpy as np
|
||||
|
||||
import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
|
||||
|
||||
class Test_AmpForeachNonFiniteCheckAndUnscale_(TestCase):
|
||||
def generate_data(self, min_d, max_d, shape, dtype, input3):
|
||||
input1 = np.random.uniform(min_d, max_d, shape).astype(dtype)
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
|
||||
import torch
|
||||
import torch_npu
|
||||
import numpy as np
|
||||
|
||||
import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
from torch_npu.testing.decorator import graph_mode
|
||||
|
||||
class TestAvgPool2d(TestCase):
|
||||
def cpu_op_exec(self, input1, ceil_mode):
|
||||
@@ -34,7 +35,8 @@ class TestAvgPool2d(TestCase):
|
||||
output = output.detach().numpy()
|
||||
return output
|
||||
|
||||
def test_avg_pool2d_backward_shape_format_fp16(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool2d_backward_shape_format_fp16(self):
|
||||
shape_format = [
|
||||
[[np.float16, 0, (1, 3, 147, 147)], True],
|
||||
[[np.float16, 0, (1, 3, 147, 147)], True]
|
||||
@@ -47,7 +49,8 @@ class TestAvgPool2d(TestCase):
|
||||
npu_output = self.npu_op_exec(npu_input, item[1])
|
||||
self.assertRtolEqual(cpu_output, npu_output, prec16=0.002)
|
||||
|
||||
def test_avg_pool2d_backward_shape_format_fp32(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool2d_backward_shape_format_fp32(self):
|
||||
shape_format = [
|
||||
[[np.float32, 0, (1, 3, 147, 147)], True],
|
||||
[[np.float32, 0, (1, 3, 147, 147)], True]
|
||||
@@ -59,6 +62,28 @@ class TestAvgPool2d(TestCase):
|
||||
npu_output = self.npu_op_exec(npu_input, item[1])
|
||||
self.assertRtolEqual(cpu_output, npu_output, 0.0009)
|
||||
|
||||
def test_avg_pool2d_3d_fp32(self):
|
||||
cinput = torch.randn(128, 32, 7)
|
||||
ninput = cinput.npu()
|
||||
cmodel = torch.nn.AvgPool2d((4, 5))
|
||||
nmodel = cmodel.npu()
|
||||
cpu_output = cmodel(cinput)
|
||||
npu_output = nmodel(ninput)
|
||||
self.assertRtolEqual(cpu_output.numpy(), npu_output.cpu().numpy())
|
||||
|
||||
def test_avg_pool2d_4d_fp32(self):
|
||||
cinput = torch.randn(18, 43, 12, 400)
|
||||
ninput = cinput.npu()
|
||||
kernel = 13
|
||||
padding = 6
|
||||
stride = 10
|
||||
ceil_mode = True
|
||||
cmodel = torch.nn.AvgPool2d(kernel, stride = stride, padding = padding, ceil_mode = ceil_mode)
|
||||
nmodel = cmodel.npu()
|
||||
cpu_output = cmodel(cinput)
|
||||
npu_output = nmodel(ninput)
|
||||
self.assertRtolEqual(cpu_output.numpy(), npu_output.cpu().numpy())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
||||
@@ -19,6 +19,7 @@ import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
from torch_npu.testing.decorator import graph_mode
|
||||
|
||||
|
||||
class TestAvgPool2dBackward(TestCase):
|
||||
@@ -46,7 +47,8 @@ class TestAvgPool2dBackward(TestCase):
|
||||
|
||||
return output_grad, output
|
||||
|
||||
def test_avg_pool2d_backward_shape_format_fp16(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool2d_backward_shape_format_fp16(self):
|
||||
format_list = [0, 3]
|
||||
shape_list = [(5, 20, 8, 8)]
|
||||
shape_format = [
|
||||
@@ -63,7 +65,8 @@ class TestAvgPool2dBackward(TestCase):
|
||||
self.assertRtolEqual(cpu_output, npu_output)
|
||||
self.assertRtolEqual(cpu_output_grad, npu_output_grad)
|
||||
|
||||
def test_avg_pool2d_backward_shape_format_fp32(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool2d_backward_shape_format_fp32(self):
|
||||
format_list = [0, 3]
|
||||
shape_list = [(5, 20, 8, 8)]
|
||||
shape_format = [
|
||||
|
||||
@@ -20,6 +20,7 @@ import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
from torch_npu.testing.decorator import graph_mode
|
||||
|
||||
|
||||
class TestAvgPool3D(TestCase):
|
||||
@@ -39,7 +40,8 @@ class TestAvgPool3D(TestCase):
|
||||
output_data = m(input1)
|
||||
return output_data
|
||||
|
||||
def test_avg_pool_3d_fp32(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool_3d_fp32(self):
|
||||
shape_format = [
|
||||
[[np.float32, -1, (20, 16, 50, 44, 31)], (3, 2, 2), (2, 1, 2)],
|
||||
[[np.float32, -1, (2, 1, 4, 4, 4)], 3, 2],
|
||||
@@ -53,7 +55,8 @@ class TestAvgPool3D(TestCase):
|
||||
cpu_output = self.cpu_op_exec(item[1], item[2], cpu_input1)
|
||||
self.assertRtolEqual(cpu_output, npu_output.cpu(), 1.e-3)
|
||||
|
||||
def test_avg_pool_3d_fp16(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool_3d_fp16(self):
|
||||
shape_format = [
|
||||
[[np.float16, -1, (20, 16, 50, 44, 31)], (3, 2, 2), (2, 1, 2)],
|
||||
[[np.float16, -1, (2, 1, 4, 4, 4)], 3, 2],
|
||||
|
||||
@@ -20,6 +20,7 @@ import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.common_utils import create_common_tensor
|
||||
from torch_npu.testing.decorator import graph_mode
|
||||
|
||||
|
||||
class TestAvgPool3DBackward(TestCase):
|
||||
@@ -57,7 +58,8 @@ class TestAvgPool3DBackward(TestCase):
|
||||
output = output.detach().numpy()
|
||||
return output_grad, output
|
||||
|
||||
def test_avg_pool_3d_fp32(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool_3d_fp32(self):
|
||||
shape_format = [
|
||||
[[np.float32, -1, (20, 16, 50, 44, 31)], (3, 2, 2), (2, 1, 2)],
|
||||
[[np.float32, -1, (2, 1, 4, 4, 4)], 3, 2],
|
||||
@@ -72,7 +74,8 @@ class TestAvgPool3DBackward(TestCase):
|
||||
self.assertRtolEqual(cpu_output, npu_output, 1.e-3)
|
||||
self.assertRtolEqual(cpu_output_grad, npu_output_grad, 1.e-3)
|
||||
|
||||
def test_avg_pool_3d_fp16(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_avg_pool_3d_fp16(self):
|
||||
shape_format = [
|
||||
[[np.float16, -1, (20, 16, 50, 44, 31)], (3, 2, 2), (2, 1, 2)],
|
||||
[[np.float16, -1, (2, 1, 4, 4, 4)], 3, 2],
|
||||
|
||||
@@ -16,9 +16,12 @@ import torch
|
||||
import torch_npu
|
||||
|
||||
from torch_npu.testing.testcase import TestCase, run_tests
|
||||
from torch_npu.testing.decorator import graph_mode
|
||||
|
||||
|
||||
class TestBatchNormElemt(TestCase):
|
||||
def test_batch_norm_elent(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_batch_norm_elent(self):
|
||||
input1 = torch.tensor([[1.], [2.], [3.]]).npu()
|
||||
weight = torch.tensor([1.]).npu()
|
||||
bias = torch.tensor([10.]).npu()
|
||||
@@ -29,7 +32,8 @@ class TestBatchNormElemt(TestCase):
|
||||
expect_out = torch.tensor([[8.], [10.], [12.]])
|
||||
self.assertRtolEqual(expect_out, out.cpu())
|
||||
|
||||
def test_batch_norm_elent_out(self, device="npu"):
|
||||
@graph_mode
|
||||
def test_batch_norm_elent_out(self):
|
||||
input1 = torch.tensor([[1.], [2.], [3.]]).npu()
|
||||
weight = torch.tensor([1.]).npu()
|
||||
bias = torch.tensor([10.]).npu()
|
||||
|
||||