Compare commits

..
301 Commits
Author SHA1 Message Date
weili10 e0d724c3c6 update cann version.
Signed-off-by: weili10 <liwei386@huawei.com>
2023-01-30 13:19:59 +00:00
weili10 0ea0d95f7b update README.zh.md.
Signed-off-by: weili10 <liwei386@huawei.com>
2023-01-19 08:02:48 +00:00
i-robot d4ffa0a823 !2129 Unified version number format.
Merge pull request !2129 from 闫鹏全/v1.5.0
2023-01-17 06:18:50 +00:00
闫鹏全 a47d202e3e Unified version number format. 2023-01-14 18:49:24 +08:00
AtlasAccount 6db8b2d88d 同步1.5.0 bb20140941c0d6e6dcbdba9a0510bbbe5e20b791
!3620 Add exclude aicore engine of viewcopy and index.
    Merge pull request !3620 from 於欣洁/master
2022-12-26 23:00:43 +08:00
AtlasAccount 03a193fd0d 同步1.5.0 4ece93ce4b22e422f5e7bb9a71ae3df4b607a0d9
!3619 [Fix] revert Pull Request !3618 : [Feature] Modify the size of AvgPoolV2Grad to int32
    Merge pull request !3619 from weili10/revert-merge-3618-master
2022-12-16 16:31:09 +08:00
AtlasAccount 513f46decc 同步1.5.0 b152e9648995ac6de929cbac3e20dbcd1435ac66
!3618 [Feature] Modify the size of AvgPoolV2Grad to int32
    Merge pull request !3618 from 戢芳/avg_pool2d_grad1.5
2022-12-15 12:00:45 +08:00
weili10 2b48121bbf update OWNERS.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-12-13 09:28:10 +00:00
weili10 e3e229839f update OWNERS.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-12-09 02:14:36 +00:00
weili10 88719bd40a update OWNERS.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-11-30 06:40:47 +00:00
i-robot 3fc20b8b30 !1600 新API清单更新
Merge pull request !1600 from 彭子荣/v1.5.0
2022-11-17 12:08:48 +00:00
pengzirong e751f65710 api清单更新 2022-11-16 16:29:52 +08:00
weili10 86a79738b3 update OWNERS.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-11-14 09:23:47 +00:00
weili10 5fcd2ba271 update OWNERS.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-11-14 08:59:57 +00:00
AtlasAccount cb18de2fef 同步1.5.0 f98435a698ede814e377438beb38045da3aeec04
!3614 【BugFix】补充nllloss_2d的weight赋0的判断条件
    Merge pull request !3614 from 戢芳/nllloss_debug1.5
2022-11-07 12:00:50 +08:00
AtlasAccount b292bc05c9 同步1.5.0 ffe03b307b8cbd4d2e60b19588cf5f250d5e0b2a
!3613 [refactor]npu_dtype_cast replace to function.
    Merge pull request !3613 from darin123/master
--
    !3608 [refactor]npu_dtype_cast replace to function.
    Merge pull request !3608 from darin123/master
2022-11-01 23:00:43 +08:00
AtlasAccount 95cf34f163 同步1.5.0 ee09df85b727ced2406ae91ab6045b1438a8a098
!3610 【Refactor】taskqueue重构:优化usleep与结构体析构
    Merge pull request !3610 from yangxiaorun/master
2022-10-27 23:00:56 +08:00
weili10 eb4a799674 update README.zh.md.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-10-22 04:05:54 +00:00
AtlasAccount d1305fd848 同步1.5.0 eee06586452597ab040198a7bb79b7bcc1874c2d
Merge: 00ae3c23f 03716faf1
    !3605 [fix] scalar scene and rank=1 scene do not support nz
    Merge pull request !3605 from 王强/master
Merge: 4b3479311 f01d27c64
    !3606 index和viewcopy修改入参编译选项
    Merge pull request !3606 from 王晓/index_viewcopy_independent
    index and viewcopy fix
    [fix] scalar scene and rank=1 scene do not support nz
2022-10-20 19:31:13 +08:00
weili10 c5f7e64aa5 update README.zh.md.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-10-20 01:46:06 +00:00
AtlasAccount abc10caebd 同步1.5.0 4b347931184da0fbc47dfacb77e6a9425a433727
!3598 index indexput v3
    Merge pull request !3598 from 王晓/index_v3_new
2022-10-15 00:11:48 +08:00
AtlasAccount fd7a52be39 同步1.5.0 d8d3a108ba68f16924a3402ede78741168feb87b
!3601 更改版本号6->7
    Merge pull request !3601 from 王夏夏/master
2022-10-12 23:00:39 +08:00
AtlasAccount 847cbbbb1a 同步1.5.0 9b3fd49c7369bd86888e11e14d6885be70a58cd9
!3591 【bernoulli适配】 bernoulli IR修改,适配层对齐 & cast 问题处理
    Merge pull request !3591 from 沈鹏程/108_bernoulli_IR
--
    !3585 GridSampler2D入参修改符合 算子IR
    Merge pull request !3585 from aikede/1.5_bug_grid
--
    !3590 修复index中转连续走aicpu导致性能下降问题
    Merge pull request !3590 from 王晓/index_mae
--
    !3587 修复index_select反向index_add不支持index为0维问题
    Merge pull request !3587 from 王晓/index_add
--
    !3586 【BugFix】修复index_put check indices报错
    Merge pull request !3586 from hxf12345677/inp
2022-10-08 23:00:55 +08:00
AtlasAccount 681f5543e4 同步1.5.0 012b968a50c9b3557045dc9a0b09da03c6ea6424
!3583 【BugFix】修复maksed_select的输出shape
    Merge pull request !3583 from 戢芳/maksed_select1.5
--
    !3582 【BugFix】修复avgpool2d 算子输出shape错误问题, 对不支持三维输入做增维操作
    Merge pull request !3582 from 戢芳/avgpool2d
--
    !3584 【BCM】indexput 适配
    Merge pull request !3584 from hxf12345677/indexput
2022-09-29 23:00:43 +08:00
AtlasAccount 1a380aefee 同步1.5.0 42069cd2f18462b54e5822b0d6b439fe35b462d1
!3581 【BugFix】_unique2算子fp16场景存在精度问题,转fp32规避
    Merge pull request !3581 from 戢芳/unique1.5
--
    !3580 masked_select支持非bool mask
    Merge pull request !3580 from 王晓/maskedselect
2022-09-27 23:00:44 +08:00
AtlasAccount d52f542aa7 同步1.5.0 88e743638d41a0f36453d07936e8d5b647d60b39
!3573 【BCM】upsample_nearest1d调用Resize
    Merge pull request !3573 from 戢芳/resize1.5
--
    !3570 【算子适配】 MaskedSelect改为第三类算子适配
    Merge pull request !3570 from hxf12345677/maskselect
2022-09-20 23:00:43 +08:00
AtlasAccount e434ebc805 同步1.5.0 240174e62da5c45598faea4e89da5fbef194a904
!3566 【算子适配】 unique2改为第三类算子适配
    Merge pull request !3566 from hxf12345677/un
--
    !3564 Modify randperm adapt to StatelessRandperm
    Merge pull request !3564 from 王晓/1.5randperm_n_input
2022-09-19 23:04:53 +08:00
AtlasAccount 41bfe9c544 同步1.5.0 6a60895589b231dd9384f70f5cba13e8dc122339
!3563 index算子IR变更(商分)
    Merge pull request !3563 from 王晓/1.5rc3_index
2022-09-17 23:01:05 +08:00
AtlasAccount df05b7a031 同步1.5.0 5a0f37cc0c586468171426572ac3b9e5c5953c90
!3561 【bugfix】修复onehot算子,入参为scalar时,性能下降问题
    Merge pull request !3561 from hxf12345677/oneh
2022-09-16 23:00:38 +08:00
AtlasAccount c39e008d3b 同步1.5.0 810a702dc3adf05f76e18879fb1ffd6f1cbfb048
!3559 index算子IR变更
    Merge pull request !3559 from 王晓/1.5index_new
2022-09-15 23:00:38 +08:00
AtlasAccount 3d3750411f 同步1.5.0 9d0053314e398e674a0be7a5ee85efb9ae584e3d
!3543 【算子适配】nms_rotated_npu调用NPU算子IR更新
    Merge pull request !3543 from 赖长铃/rotatednms
2022-09-14 23:00:43 +08:00
AtlasAccount 11e4eb7eb8 同步1.5.0 c3e94122d4a11c7f269e7d0a345fcba578a99736
!3554 【BCM整改】multinomial增加seed、offset
    Merge pull request !3554 from 戢芳/multinomial
2022-09-13 23:00:42 +08:00
AtlasAccount defe0587f6 同步1.5.0 0513d0db60b14371538432e8162b44be92a94fbc
!3557 cummin算子IR变更,适配同步修改
    Merge pull request !3557 from 王晓/cummin_axis
2022-09-06 23:00:42 +08:00
AtlasAccount dffecfba93 同步1.5.0 de2ef9dae9391c65c614e2d9a6db5812b53704d2
!3553 index算子调用添加输入IR名称
    Merge pull request !3553 from 赖长铃/index
2022-09-03 12:00:40 +08:00
AtlasAccount d57152e0cd 同步1.5.0 e064c1da43eb595f7e3d399f4c292bf246ef6a07
!3548 随机数算子uniform_, random_, normal更换算子,固定seed
    Merge pull request !3548 from 王晓/stateless_ops
2022-09-01 12:00:38 +08:00
AtlasAccount 04c8dfea99 同步1.5.0 9fd6202960a4d44aeded5f13d3a779c940214709
!3550 【bugfix】 修改index 算子mask入参为const节点
    Merge pull request !3550 from hxf12345677/inde
--
    !3551 add: 新增npu_convolution_transpose_backward的反向函数绑定
    Merge pull request !3551 from 郭夏/master
2022-08-30 23:07:01 +08:00
i-robot db66d80806 !1181 网络模型移植与训练指南全文问题检查&多机多卡训练适配指南资料修改
Merge pull request !1181 from 彭子荣/v1.5.0
2022-08-29 12:42:32 +00:00
pengzirong 9ab75c8967 网络模型移植与训练指南全文问题检查&环境变量代码缺少空格 2022-08-26 10:27:19 +08:00
AtlasAccount c8085ae921 同步1.5.0 6f5fbe514fc753be519861b9a7365e651be96c92
!3546 回退 Pull Request !3508 : sum算子对int64型数据的支持
    Merge pull request !3546 from weili10/revert-merge-3508-master
2022-08-25 23:00:54 +08:00
AtlasAccount 2032d04858 同步1.5.0 653dafb269ce01c9a69fee887ada4259390cedc8
!3545 移除module.forward中未使用的increase_step
    Merge pull request !3545 from lj_new/master
2022-08-25 12:01:14 +08:00
AtlasAccount 255de550cc 同步1.5.0 f2176df2b7169e8d6207f0627414dbef54b75bd6
!3544 ptcopy切换为viewcopy
    Merge pull request !3544 from 王晓/viewcopy1.5
2022-08-24 23:00:42 +08:00
weili10 7a8ecbca90 update OWNERS.
Signed-off-by: weili10 <liwei386@huawei.com>
2022-08-18 11:53:17 +00:00
AtlasAccount 43f5a19a2f 同步1.5.0 f0cc489eb4751724ad1dbdefa32d924afe5fe661
!3538 【BugFix】同步embedding_renorm算子适配逻辑与1.8一致
    Merge pull request !3538 from 戢芳/embedding1.5
2022-08-11 23:00:35 +08:00
AtlasAccount 93a2fdc566 同步1.5.0 2bbc1d6af71acaf0a9b983fd6ef5bbda648813ba
!3539 【适配】bernoulli 适配    算子原型改动,适配层对齐修改
    Merge pull request !3539 from 沈鹏程/IR_by_bernoulli
2022-08-09 23:03:15 +08:00
i-robot 6d23724871 !1095 网络模型移植与训练指南修改
Merge pull request !1095 from 彭子荣/v1.5.0
2022-08-08 12:28:31 +00:00
pengzirong 32f82f58ef 更新跳转链接与分布式训练添加 2022-08-08 16:35:51 +08:00
AtlasAccount dfec8bbb20 同步1.5.0 a92bbcbb21ebb73ac4d19283eae79f24fc1b128a
!3537 【1.5】回退非host memory修改
    Merge pull request !3537 from 周和光/fix_storage_format
2022-08-04 12:04:24 +08:00
AtlasAccount 4fd08f5fc6 同步1.5.0 b17ba4b0bac8928b2684843afaf123ac3fb113e7
!3533 回退 Pull Request !3525 : sum算子对int64型数据的支持
    Merge pull request !3533 from weili10/revert-merge-3525-master
--
    !3532 【bernoulli】remove stream synchronization for model
    Merge pull request !3532 from 沈鹏程/modify_bernoulli
2022-07-29 23:01:37 +08:00
AtlasAccount e5e76d5ff0 同步1.5.0 f3228834e071b9ab9653d095546e2c8af48e0cf7
!3531 【1.5】修正host memory未设置storage Shape/Format问题
    Merge pull request !3531 from 周和光/fix_storage_format
--
    !3527 bernoulli 算子适配,算子新增优化随机数机制,提高兼容性
    Merge pull request !3527 from 沈鹏程/adapt_bernoulli
2022-07-28 23:00:37 +08:00
AtlasAccount 1ca343fff0 同步1.5.0 a9374eaab1592005e73feafddd74ee679b303113
!3528 【bugfix】修复one_hot算子走aicpu分支时报错场景
    Merge pull request !3528 from hxf12345677/one
2022-07-27 23:00:54 +08:00
i-robot 99172aa0ca !1088 Updated English docs.
Merge pull request !1088 from zwy/v1.5.0
2022-07-26 06:20:15 +00:00
AtlasAccount 2b58bddcb0 同步1.5.0 0d9083e346bb706963742f6cdfc845506f3422ad
!3525 sum算子对int64型数据的支持
    Merge pull request !3525 from aikede/b_sum_dtype
2022-07-26 12:01:12 +08:00
AtlasAccount 4f7caaaf7f 同步1.5.0 36b80ca87a878ac507db4bef09f19404d4b126d8
!3510 回退sort修改
    Merge pull request !3510 from 王夏夏/master
2022-07-25 23:00:42 +08:00
yanhuiling 02298ccc80 Updated English docs. 2022-07-25 17:26:26 +08:00
AtlasAccount f80b97dadc 同步1.5.0 8578cd9a5cd15907af28c87f2a097dae7f8a7366
!3517 支持rng_state
    Merge pull request !3517 from hanjun/master
2022-07-20 12:01:07 +08:00
AtlasAccount b31dfee2d7 同步1.5.0 7d9dd60df7b13268f8ec703cddf03598dd31e4d5
!3504 opcmd支持dtype传参
    Merge pull request !3504 from 王晓/dtype_attr
2022-07-18 23:00:37 +08:00
AtlasAccount 64c1e12c6a 同步1.5.0 3e6c6f59c99032f0dfe854079dc237cc8d9f9895
!3508 sum算子对int64型数据的支持
    Merge pull request !3508 from aikede/b_sum_dtype
2022-07-15 12:00:38 +08:00
weili10 732ae7c134 update maintenance status for 3.0.rc2 2022-07-15 03:30:31 +00:00
i-robot 333c907f8d !1048 多机多卡训练适配指南 英文资料更新
Merge pull request !1048 from 彭子荣/v1.5.0
2022-07-13 08:32:22 +00:00
pengzirong 2e7e39b507 update ip tothe smple ip
1
2022-07-12 15:30:50 +08:00
i-robot 57cc74e900 !1043 Update README and PyTorch Installation Guide based on Chinese revisions.
Merge pull request !1043 from zwy/v1.5.0
2022-07-11 13:30:52 +00:00
weili10 c3a5d05424 !1034 网络模型移植与训练指南修改
Merge pull request !1034 from 彭子荣/v1.5.0
2022-07-11 09:35:58 +00:00
zwy a18e48a834 Updated README and PyTorch Installation Guide based on Chinese revisions. 2022-07-11 16:42:26 +08:00
pengzirong 5930dbec25 网络模型移植与训练指南新增硬件支持说明 2022-07-11 14:48:31 +08:00
AtlasAccount a932e65f9e 同步1.5.0 d5b893e768dc36d410b90986c4534cf4f9a3bf63
!3507 [bugfix] right lock for task queue
    Merge pull request !3507 from 蒋荣强/master
2022-07-11 12:00:47 +08:00
i-robot 6e3dbfa3c7 !1028 V1.5.0资料更新
Merge pull request !1028 from 彭子荣/v1.5.0
2022-07-11 03:33:36 +00:00
pengzirong 889d2ae716 v1.5.0README与安装指南修改
1

1
2022-07-11 09:51:52 +08:00
AtlasAccount bdc0d2a819 同步1.5.0 ece606e4dc43d9a9e0d6986b524b077ef76174a2
!3505 bugfix:删除cmake中的rpath=True设置
    Merge pull request !3505 from 施博/master
2022-07-09 23:00:43 +08:00
AtlasAccount d5aca3c9d8 同步1.5.0 9cb0b5fffe4a53ce5a086488a0d3fff32b3f4379
!3500 sort算子走fp32 && 更新版本号post5->post6
    Merge pull request !3500 from 王夏夏/master
2022-07-07 23:00:40 +08:00
weili10 5b477928d5 !1012 README与安装指南差异修改
Merge pull request !1012 from 彭子荣/v1.5.0
2022-07-07 09:53:39 +00:00
pengzirong 6daeb34d1e 更新README与安装指南差异与问题
更新依赖下载

i
2022-07-07 16:55:05 +08:00
AtlasAccount 67b74b6919 同步1.5.0 6f0751810b75da99796af08cdf031057982e11e8
!3496 ASCEND_OPP_PATH 路径错误增加GE报错信息
    Merge pull request !3496 from 汪瑞哲/master
2022-07-04 12:00:48 +08:00
i-robot 8c019dc9f6 !988 torch1.5 环境变量说明调整
Merge pull request !988 from 李超/v1.5.0
2022-07-02 03:12:50 +00:00
李超 138ccbab13 update environment variables 2022-07-02 09:57:47 +08:00
AtlasAccount e8e34e1648 同步1.5.0 533ca3e0e3162f24ac8a6634b02e832a635ffcc5
!3497 回退 Pull Request !3486 : Conv2d适配模糊编译二进制
    Merge pull request !3497 from weili10/revert-merge-3486-master
2022-07-01 23:00:43 +08:00
i-robot c693353ef1 !981 API 支持度资料修改
Merge pull request !981 from 彭子荣/v1.5.0
2022-07-01 06:46:10 +00:00
pengzirong f9b8c654cf torch.cdist支持度修改 2022-07-01 09:40:45 +08:00
i-robot 350a490e87 !976 README更新
Merge pull request !976 from 彭子荣/v1.5.0
2022-06-30 08:23:26 +00:00
pengzirong e7d59cbfaf 多机多卡训练适配指南修改资料中IP为样例IP 2022-06-30 15:49:06 +08:00
pengzirong 32ca47c016 readme与安装指南合并,内容拷贝到安装指南 2022-06-30 15:42:22 +08:00
AtlasAccount 88bc2d63eb 同步1.5.0 206e8a36c89c7493c546e7840f544a853b7edc40
!3494 【bugfix】 修复cdist算子,属性p=inf,npu报错
    Merge pull request !3494 from hxf12345677/cdist
2022-06-30 12:00:41 +08:00
AtlasAccount 7c14ecce0d 同步1.5.0 0e58834e66ebecc031387b2ca0d71fa163eaa4e1
!3488 wrap AclopCompileAndExecuteV2
    Merge pull request !3488 from 王晓/unique_consecutive_wrap
--
    !3481 【bugfix】修复all算子输入为空Tensor,计算结果错误场景
    Merge pull request !3481 from hxf12345677/all
--
    !3482 【BugFix】修复floor_divide算子int32格式的精度问题(同步1.8)
    Merge pull request !3482 from 戢芳/divide1.5
2022-06-27 23:03:17 +08:00
AtlasAccount a05df6bdda 同步1.5.0 4caaee8d3fcaede8044157f462739d2997b33f39
!3480 BernoulliCust适配
    Merge pull request !3480 from 李思杰/bernoulli_cust
--
    !3486 Conv2d适配模糊编译二进制
    Merge pull request !3486 from 郭鹏/master
--
    !3478 unique_consecutive适配
    Merge pull request !3478 from 王晓/unique_consecutive
2022-06-25 23:00:34 +08:00
AtlasAccount b3a7f790c8 同步1.5.0 e71da1b59d7e685f8c2260a4dbb4f1eee12149fd
!3483 回退 Pull Request !3466 : randn算子适配,支持seed配置,以及对dtype类型的attr支持
    Merge pull request !3483 from weili10/revert-merge-3466-master
--
    !3477 all算子支持uint8入参
    Merge pull request !3477 from aikede/b_all
2022-06-23 23:00:42 +08:00
AtlasAccount 88e7cd0667 同步1.5.0 0b1ffcfd22b713fc3bdbbb1be8b4cc91cf1cff9c
!3473 fix bug of lazy print
    Merge pull request !3473 from wangyu/dev
2022-06-21 12:00:34 +08:00
AtlasAccount 38267666fe 同步1.5.0 61605a199df457a6bb82d1311f7b1d03681cbbc3
!3471 去除InputPair操作
    Merge pull request !3471 from hxf12345677/ho
2022-06-20 23:00:43 +08:00
AtlasAccount b387a3427d 同步1.5.0 a7cf1481f9b810ad1fcef773781df9e7d6a4d89b
!3465 ne支持int32输入
    Merge pull request !3465 from aikede/b_ne
2022-06-16 23:02:02 +08:00
AtlasAccount 3f4ffba595 同步1.5.0 1db3bc5742446fb80b5cde89057e00318cc11cef
!3462 删除requirements.txt文件中重复pyyaml
    Merge pull request !3462 from 王夏夏/master
--
    !3466 randn算子适配,支持seed配置,以及对dtype类型的attr支持
    Merge pull request !3466 from 王晓/randn_seed
--
    !3459 Fixed Split K BUG
    Merge pull request !3459 from 唐超/fixed_NZ_bug
2022-06-16 12:01:19 +08:00
i-robot 154bcfced6 !911 安装指南资料修改
Merge pull request !911 from 彭子荣/v1.5.0
2022-06-15 07:01:20 +00:00
AtlasAccount 12303a6da0 同步1.5.0 99252a026bee508d110da24ca95a5185afff6664
!3461 修复部分模型因为算子重复编译导致的asstride性能下降问题
    Merge pull request !3461 from 李超/dev-asstrided
2022-06-14 23:01:40 +08:00
pengzirong 7a20b65e2f 修改下载昇腾适配APEX的源码命令 2022-06-14 17:12:06 +08:00
i-robot d11cd94156 !897 处理器名称更新
Merge pull request !897 from 彭子荣/v1.5.0
2022-06-10 10:00:31 +00:00
pengzirong c45de03e71 ASCEND 710 -->ASCEND 310P 2022-06-10 16:48:42 +08:00
AtlasAccount c87f2cd51b 同步1.5.0 612acab3aa879a5479b280cf55ba66affbd61e96
!3456 【BugFix】thredshold算子去D
    Merge pull request !3456 from 戢芳/threshold1.5
2022-06-07 12:01:35 +08:00
AtlasAccount a6189a76e5 同步1.5.0 953a0f6b93c6bf0fc8f35545f493fb7e5de3f34d
!3455 【BugFix】lstm_cell_backward构造bias输出时,type与i一致
    Merge pull request !3455 from 戢芳/lstm_cell_fix
2022-06-02 23:00:47 +08:00
AtlasAccount 73c47b1e64 同步1.5.0 23f0a06a8b1571ddbfce2b334dc27dc68e3ee8ff
!3430 BernoulliCust算子适配
    Merge pull request !3430 from 龚政/Bernoulli
2022-06-01 23:04:31 +08:00
AtlasAccount 2d7d639562 同步1.5.0 09cc7f597fc187168c6c77ca235d56658c97d8d9
!3453 arange算子默认输出类型和cpu修改一致
    Merge pull request !3453 from aikede/b_arange
2022-06-01 12:08:14 +08:00
AtlasAccount ace64b8445 同步1.5.0 140c0f720af4fb23b979e3d435182295b655b534
!3452 为Mul算子tensor*scalar新增一个UT
    Merge pull request !3452 from 詹隽/add_test
2022-05-31 23:00:45 +08:00
AtlasAccount c06ce48b89 同步1.5.0 179c0ba3b26763b29fb3208b44aaa7ed749a1e52
!3445 【功能修复】适配层主动调用cpu的cast方法解决算子不支持不同dtype输入问题
    Merge pull request !3445 from 詹隽/scalar_bug
--
    !3447 【新接口】1.5动态shape新接口
    Merge pull request !3447 from 詹隽/dynamic_interface
--
    !3428 Only_MM_Split_k
    Merge pull request !3428 from 唐超/only_mm_split
2022-05-25 23:00:52 +08:00
i-robot 274b892c56 !829 1.5新增combine_grad说明
Merge pull request !829 from lj_new/v1.5.0
2022-05-25 03:04:23 +00:00
AtlasAccount 7e2c3d7979 同步1.5.0 63ee4d2144db51de342e2f477f482ef9ee2bd26f
!3431 [optimize] 非连续流程优化
    Merge pull request !3431 from 李超/git
--
    !3443 【BugFix】file rename
    Merge pull request !3443 from 戢芳/rename1.8
2022-05-24 23:00:50 +08:00
i-robot 4b396515d5 !818 README更新
Merge pull request !818 from 彭子荣/v1.5.0
2022-05-24 09:19:12 +00:00
AtlasAccount 2d8ece95b3 同步1.5.0 90382c1c71d343f9609471fd2055e9f551ada92b
!3439 【FixBug】修复lstm中lengths[0]不为T时的场景
    Merge pull request !3439 from 王晓/lstm_shape
--
    !3435 【1.5算子适配】lstm_cell、lstm_cell_backward
    Merge pull request !3435 from 戢芳/lstm_cell1.5
2022-05-23 23:04:59 +08:00
lj_new de3435090b 1.5新增combine_grad说明 2022-05-23 04:00:20 +00:00
lj_new 27cf56f730 1.5文档新增combine_ddp使用说明 2022-05-23 03:57:50 +00:00
AtlasAccount 4dc478adab 同步1.5.0 f45f80fb2d571e175dc7a9be2e9e3ced6d4ca11b
!3414 【bugfix】sub适配新增other的device判断、addmm和cat增加输入tensor类型检查
    Merge pull request !3414 from 郭夏/sub
--
    !3422 [Bugfix] Lt support LongTensor.
    Merge pull request !3422 from 尤安升/master
2022-05-19 15:26:49 +08:00
pengzirong e1f9bb08d1 更新配套参考表格 2022-05-19 11:45:42 +08:00
weili10 4b28c57993 update docs/zh/PyTorch安装指南/PyTorch安装指南.md. 2022-05-18 10:43:11 +00:00
weili10 6afb6c635b update README.zh.md. 2022-05-18 10:41:46 +00:00
weili10 3ae0c6ae3f !814 安装指南与README新增安装提示说明
Merge pull request !814 from 彭子荣/v1.5.0
2022-05-18 10:40:33 +00:00
pengzirong 30b9ebb94d 安装指南与README更新提示 2022-05-18 17:36:35 +08:00
AtlasAccount 844328508e 同步1.5.0 2cb9f26f9b0221d4951c1c2818af51b4954bd3c5
!3421 回退 Pull Request !3408 : 【1.5新算子适配】norm适配LpNorm算子
    Merge pull request !3421 from weili10/revert-merge-3408-master
2022-05-13 12:00:57 +08:00
AtlasAccount ec0828a267 同步1.5.0 1556b0eccd6f26c7570812b362754fa3b3201248
!3408 【1.5新算子适配】norm适配LpNorm算子
    Merge pull request !3408 from 肖代鹏/1.8_adapt_222
--
    !3412 下发优化代码回退
    Merge pull request !3412 from 李超/master-git
2022-05-12 11:57:25 +08:00
AtlasAccount 54c1b37228 同步1.5.0 9ecfb14a51719a8d6a917337560e90f5358dba40
!3397 更新apply_adam底层算子
    Merge pull request !3397 from 王晓/applyadam
--
    !3409 [bugfix] 暂时回退 get_npu_format修改
    Merge pull request !3409 from 李超/master
2022-05-10 23:01:53 +08:00
AtlasAccount 4b31ff2cb5 同步1.5.0 21a1c102215b8dbe98a41a0592126e48e09b6ff7
!3398 调整shutdown阶段资源释放流程
    Merge pull request !3398 from wangyu/dev
--
    !3391 调整进程退出阶段资源释放流程
    Merge pull request !3391 from wangyu/dev
2022-05-06 23:00:52 +08:00
AtlasAccount 150ead5660 同步1.5.0 09ea7e8fa7de87420d217775375b44f3509c26c1
!3393 sync dev to master
    Merge pull request !3393 from 王强/dev
2022-05-05 12:02:00 +08:00
AtlasAccount cfcc3a2f8b 同步1.5.0 4baf85d4d061ed874fe71c96b5a053aa973a5cd2
!3387 randperm 适配
    Merge pull request !3387 from 沈鹏程/randperm
2022-04-29 23:00:46 +08:00
weili10 aeba162110 update ascend pytorch version 2022-04-29 03:10:06 +00:00
AtlasAccount 7c31e72e10 同步1.5.0 0e3c8619b6df6775666c912ee8c35f8e663a6e93
!3384 【FixBug】修复max.out接口checkout错误场景
    Merge pull request !3384 from hxf12345677/max
--
    !3386 【bugfix】:修复embedding_renorm_适配导致图模式用例失败的问题
    Merge pull request !3386 from 郭夏/master
2022-04-27 23:00:56 +08:00
AtlasAccount e3e79304fd 同步1.5.0 08c9f799c3ebed16f8cab47bd6518c0598bcce76
!3381 [optimize] 非连续+适配层下发优化3
    Merge pull request !3381 from 李超/git
--
    !3380 dev合入master
    Merge pull request !3380 from 蒋荣强/dev
--
    !3379 merge master to dev
    Merge pull request !3379 from 蒋荣强/dev
--
    !3376 print入图功能,修复生成string的bug
    Merge pull request !3376 from wangyu/dev
--
    !3374 修复print入参场景下,异步h2d没有做内存释放控制的bug
    Merge pull request !3374 from wangyu/dev
--
    !3372 add format adaptation for ops that only support NCHW/NHWC
    Merge pull request !3372 from 王强/dev
--
    !3371 CMD重构,master to dev
    Merge pull request !3371 from 王强/dev
--
    !3362 print入图支持传递tensor name
    Merge pull request !3362 from wangyu/dev
--
    !3350 【1.5算子重构】 Pdist,QuantizePerChannel,Renorm,UpsampleLinear1d,SoftShrink
    Merge pull request !3350 from 肖代鹏/1.5_adapt_construction
    !3359 【1.5代码重构】quantize_per_tensor,repeat_interleave,soft_margin_loss,softshrink_backward,upsample_bicubic2d_backward
    Merge pull request !3359 from 肖代鹏/1.5_adapt_construction3
--
    !3370 add format adaptation for strideadd and col2im
    Merge pull request !3370 from 王强/dev
--
    !3367 【BugFix】logical_or,logsigmoid,logdet,matrix,nms_v4,nms_with_mask
    Merge pull request !3367 from 周凡/cg10
--
    !3369 【refactor】strideadd,one_hot,index,nllloss2d_backward
    Merge pull request !3369 from 王强/dev
    !3345 【refactor】strideadd,one_hot,index,nllloss2d_backward
    Merge pull request !3345 from 周凡/cg4zf
2022-04-25 23:00:47 +08:00
AtlasAccount 3c84bfa2c3 同步1.5.0 d39f2510376f93bd80161f9ab3fdf9b21e826a53
!3366 【fixbug】embedding_backward, embeddingdensebackward算子ut修改
    Merge pull request !3366 from hxf12345677/embedding
2022-04-21 12:00:59 +08:00
i-robot 7759024b2c !712 add pull request template
Merge pull request !712 from weili10/v1.5.0
2022-04-21 01:39:51 +00:00
AtlasAccount 0e5945d7e7 同步1.5.0 9ac4ebdfae709ae01e2b407c209b648551684920
!3364 【FixBug】修复kl_div_backward算子Reduction为Mean计算结果错误场景
    Merge pull request !3364 from hxf12345677/kld
--
    !3357 【BugFix】delete npu_transpose_to_contiguous
    Merge pull request !3357 from 戢芳/transpose1.5
--
    !3355 【FixBug】Celu算子名修改
    Merge pull request !3355 from hxf12345677/fix
2022-04-20 23:01:35 +08:00
weili10 af794ca02d add pull request template 2022-04-20 14:55:03 +08:00
i-robot 433d206ff7 !706 Updated README-EN and the LSTMCELL operator in the API Support (English version).
Merge pull request !706 from zwy/v1.5.0
2022-04-20 06:25:52 +00:00
AtlasAccount 15c670d1f8 同步1.5.0 e4200efc7b53ea596890b89f1b95af0cec999939
!3350 【1.5算子重构】 Pdist,QuantizePerChannel,Renorm,UpsampleLinear1d,SoftShrink
    Merge pull request !3350 from 肖代鹏/1.5_adapt_construction
--
    !3359 【1.5代码重构】quantize_per_tensor,repeat_interleave,soft_margin_loss,softshrink_backward,upsample_bicubic2d_backward
    Merge pull request !3359 from 肖代鹏/1.5_adapt_construction3
2022-04-19 23:00:47 +08:00
AtlasAccount 5a9ac1dece 同步1.5.0 ca6538008f5430012823113d501b241ca28d1ba3
!3353 增加e2e 打点,和pytorch profiler对应
    Merge pull request !3353 from 施博/master
2022-04-18 23:00:45 +08:00
yanhuiling 03739b8421 Update 2022-04-18 18:36:40 +08:00
yanhuiling 94f19f9447 Update 2022-04-18 18:21:13 +08:00
yinzijun 13e1c247bc !698 Updated English docs.
Merge pull request !698 from zwy/v1.5.0
2022-04-18 01:26:00 +00:00
yanhuiling cfe4effb45 Update 2022-04-16 17:42:05 +08:00
i-robot bf2a5a75f0 !694 安装指南中新增CANN版本配套表-v1.5.0
Merge pull request !694 from yinzijun/v1.5.0
2022-04-16 07:21:09 +00:00
yinzijun 9edee0857d 新增cann版本配套表 2022-04-16 06:54:57 +00:00
AtlasAccount 4f38dbfe21 同步1.5.0 a518461dd8e0665deb42ed7f0537c56b37b1edee
!3343 【BugFix】logical_or,logsigmoid,logdet,matrix,nms_v4,nms_with_mask
    Merge pull request !3343 from 周凡/cgmodzf
2022-04-16 12:00:52 +08:00
AtlasAccount e23edc496a 同步1.5.0 dac15bb346999be5a58602240d847cb6ce1efa10
!3349 【图模式】add const ops to graph inputs for graph construction
    Merge pull request !3349 from 王强/dev
--
    !3345 【refactor】strideadd,one_hot,index,nllloss2d_backward
    Merge pull request !3345 from 周凡/cg4zf
--
    !3344 回退lstm_cell的正反向适配
    Merge pull request !3344 from 戢芳/cell_back_master
2022-04-15 23:00:47 +08:00
i-robot 7b620de388 !685 AOE工具内容修改
Merge pull request !685 from 彭子荣/v1.5.0
2022-04-15 08:30:50 +00:00
pengzirong 49e47199f0 用户知识库目录修改 2022-04-15 09:56:20 +08:00
i-robot 40394042b1 !682 v1.5.0分支增加arm环境torchvision安装指导
Merge pull request !682 from 王夏夏/v1.5.0
2022-04-15 01:41:31 +00:00
AtlasAccount b3927b466a 同步1.5.0 43f88e44daf41afe422170bbcd5051aded1760ac
!3337 【max_pool2d算子补充ut】adaptive_max_pool2d,adaptive_max_pool2d_backward,max_pool2d_backward,max_pool2d_with_indices_backward
    Merge pull request !3337 from 周凡/modut
--
    !3333 【功能需求】print入图等需求合入
    Merge pull request !3333 from 蒋荣强/master
--
    !3336 【BugFix】take算子ApplyTensor使用错误
    Merge pull request !3336 from 戢芳/take1.5
2022-04-14 23:01:34 +08:00
xiaxia3 6285c99df0 v1.5.0 arm 安装torchvision指导 2022-04-14 21:27:45 +08:00
i-robot 2005dfa5cf !673 算子支持度修改
Merge pull request !673 from 彭子荣/v1.5.0
2022-04-14 08:29:03 +00:00
AtlasAccount 7f42d3111f 同步1.5.0 9e07c268868154f274d4f65da5a2f5562d942a82
!3322 [bugfix] 修复asstride计算错误问题
    Merge pull request !3322 from 李超/master
2022-04-14 12:00:48 +08:00
pengzirong e05a732de7 修改LSTMCELL算子不支持场景 2022-04-14 09:41:32 +08:00
AtlasAccount 9ee9b54722 同步1.5.0 f504941d8f78d7fae48644f368d065efa055b8b5
!3332 回退 Pull Request !3327 : 【refactor】strideadd,one_hot,index,nllloss2d_backward
    Merge pull request !3332 from weili10/revert-merge-3327-master
--
    !3331 【性能优化】dev优化合入到master
    Merge pull request !3331 from 蒋荣强/master
2022-04-13 23:00:46 +08:00
AtlasAccount 120ab81ead 同步1.5.0 69885324ad8af2b219cf45658f5e265f3c06e0bd
!3329 【refactor】logical_or,logsigmoid,logdet,matrix,nms_v4,nms_with_mask
    Merge pull request !3329 from 周凡/opcgzf1
--
    !3328 【1.5算子重构】take、gatherv2d、erfinv、elu_backeard
    Merge pull request !3328 from 戢芳/move1.5_2
--
    !3327 【refactor】strideadd,one_hot,index,nllloss2d_backward
    Merge pull request !3327 from 周凡/opcgzf
--
    !3324 【1.5算子重构】cdist,baddbmm,nnpack_spatial_convolution,det,true_divide
    Merge pull request !3324 from 戢芳/move1.5
--
    !3321 【1.5算子重构】col2im_backward
    Merge pull request !3321 from 戢芳/col2im1.5
2022-04-12 23:00:45 +08:00
i-robot d1ec3489a8 !659 补充NPU自定算子列表中缺失的算子
Merge pull request !659 from 彭子荣/v1.5.0
2022-04-12 01:44:15 +00:00
pengzirong 8af1e10abc 补充NPU自定算子列表中缺失的算子 (详细算子清单说明中存在)
u

u
2022-04-12 09:17:38 +08:00
weili10 d0cfe101cf !656 V1.5.0 问题单修改
Merge pull request !656 from 彭子荣/v1.5.0
2022-04-09 10:15:12 +00:00
pengzirong c1e759b93c V1.5.0问题单修改 2022-04-09 17:14:10 +08:00
i-robot 3e878edfd5 !650 刷新cann prof资料
Merge pull request !650 from 施博/v1.5
2022-04-09 03:21:55 +00:00
shibo19 34aad3ba20 刷新cann prof资料 2022-04-09 11:09:18 +08:00
AtlasAccount 2d3c963a8b 同步1.5.0 233b0f0a21bd2bfdd74bfda0eb149acdb09f8a93
!3313 【BugFix】规避lstm_cell_backward精度问题
    Merge pull request !3313 from 戢芳/lstm_cell_backward1.5
--
    !3314 删除cann prof不必要的参数设置
    Merge pull request !3314 from 施博/fix_e2e
--
    !3316 cann profiling默认关闭TRAINING_TRACE
    Merge pull request !3316 from lijing/master
2022-04-08 21:50:57 +08:00
i-robot 36b69a909b !645 版本说明与E2E工具内容更新
Merge pull request !645 from 彭子荣/v1.5.0
2022-04-08 11:24:52 +00:00
pengzirong e65c39e589 3.0.RC1版本说明书更新 2022-04-08 17:32:04 +08:00
pengzirong 96e2e34cbb 更新E2E prof工具内容 2022-04-08 17:19:09 +08:00
AtlasAccount 5fa7efcfba 同步1.5.0 22c1ca725cda8d89622b92d747a2c5d428423ca3
!3307 【bugfix】deformable_conv2d_backward
    Merge pull request !3307 from 周凡/defzf
--
    !3305 【功能修复】当eventfd相关接口发生EINTR错误,程序继续运行
    Merge pull request !3305 from 蒋荣强/master
--
    !3310 nll_loss加入溢出检测黑名单
    Merge pull request !3310 from 王夏夏/master
--
    !3309 增加编译选项控制
    Merge pull request !3309 from wangyu/master
2022-04-06 22:43:53 +08:00
AtlasAccount d0a4b62e54 同步1.5.0 04d73412bb8586ea1f72775753e04bc2f1ab2b95
!3306 aoe功能创建路径问题解决
    Merge pull request !3306 from 施博/fix_aoe_bug
2022-04-02 23:00:46 +08:00
AtlasAccount 2ea0c67fc1 同步1.5.0 bdc61eac1f3061568c7c46b7af40843b667bac04
!3302 shutdown前主动释放processgroup相关资源
    Merge pull request !3302 from wangyu/master
--
    !3300 刷新e2e 功能报错信息
    Merge pull request !3300 from 施博/fix_e2e_bug
2022-04-02 11:59:11 +08:00
weili10 4caa12ab7d update docs/zh/PyTorch安装指南/PyTorch安装指南.md. 2022-04-01 13:25:47 +00:00
i-robot 10a9e48f97 !596 删除1.8.1相关
Merge pull request !596 from 彭子荣/v1.5.0
2022-04-01 13:16:19 +00:00
weili10 cb45330ce1 update README.zh.md. 2022-04-01 13:13:39 +00:00
weili10 dc98244a89 update README.zh.md. 2022-04-01 12:39:18 +00:00
weili10 682eca49df update README.zh.md. 2022-04-01 12:37:00 +00:00
weili10 71554f76d1 update scripts/gen.sh. 2022-04-01 12:33:06 +00:00
weili10 c279e2e92a update scripts/gen.sh. 2022-04-01 12:20:40 +00:00
weili10 9fcd859d96 update README.zh.md. 2022-04-01 12:19:48 +00:00
weili10 294aef2b9b update scripts/gen.sh. 2022-04-01 12:06:14 +00:00
weili10 47b089cb6c update README.zh.md. 2022-04-01 12:00:45 +00:00
pengzirong fbde60dc1d 删除1.8.1相关 2022-04-01 19:54:58 +08:00
weili10 3a44ffc52e update scripts/gen.sh. 2022-04-01 10:37:27 +00:00
weili10 cb3d7402d2 update README.zh.md. 2022-04-01 09:24:07 +00:00
weili10 22c2d837ca update README.zh.md. 2022-04-01 09:12:23 +00:00
weili10 dca21b621a update scripts/gen.sh. 2022-04-01 09:11:03 +00:00
weili10 c2a7d66b13 update scripts/gen.sh. 2022-04-01 09:09:14 +00:00
weili10 5e5a2a7925 update README.zh.md. 2022-04-01 09:08:05 +00:00
AtlasAccount a3bb1f25c4 同步1.5.0 fd0ceb73a7c14a6b28d3839ecbd9c95ae74ab1c6
!3299 [bugfix] 修复 BN scale参数dtype引起精度问题
    Merge pull request !3299 from 李超/master1
--
    !3288 [feature] 解除asstrided算子精确编译限制
    Merge pull request !3288 from 李超/master
2022-03-31 23:00:46 +08:00
i-robot 0d33ee3e0d !585 刷新api资料,diag算子仅支持diagonal=0场景
Merge pull request !585 from 戢芳/msg_diag
2022-03-31 13:31:04 +00:00
pipihugh 796d41d691 刷新api资料,diag算子仅支持diagonal=0场景 2022-03-31 19:35:06 +08:00
AtlasAccount bdb376cdb3 同步1.5.0 7c9813a3a6d68c0231749a53486299bbc9352858
!3297 shutdown 前主动释放process group相关资源
    Merge pull request !3297 from wangyu/master
2022-03-31 09:39:20 +08:00
AtlasAccount 4dc31edf9a 同步1.5.0 6a8be028864854d4e204677c90f8ed9e421211e9
!3287 【BugFix】修复inverse不支持fp16 out场景
    Merge pull request !3287 from 王晓/inverse
--
    !3290 【BugFix】lstm_cell增加bias=false的场景
    Merge pull request !3290 from 戢芳/lstm_cell_debug
--
    !3294 回退 Pull Request !3284 : 在npu shutdown流程前主动释放process group
    Merge pull request !3294 from weili10/revert-merge-3284-master
2022-03-29 23:00:51 +08:00
AtlasAccount aafe2061ac 同步1.5.0 1fe05e27602d1ceed302541e3da9b6b02ef19aea
!3284 在npu shutdown流程前主动释放process group
    Merge pull request !3284 from wangyu/master
2022-03-28 12:23:43 +08:00
AtlasAccount 2eaee92eb0 同步1.5.0 392a9d7e12c3af78ce45a4f4241e26f6cc7d7336
!3280 【1.5算子适配】 ReplicationPad1dBackward 算子适配
    Merge pull request !3280 from 沈鹏程/replicatback
2022-03-26 23:00:46 +08:00
AtlasAccount 416deb85dd 同步1.5.0 e48e6bd63caa8764fd85ed823ca563e182e15465
!3277 [feature] 删除TRI_COMBINED_ENABLE环境变量
    Merge pull request !3277 from 李超/master
--
    !3272 【1.5算子适配】lstm_cell_backward
    Merge pull request !3272 from 戢芳/lstm_cell_back1.5
--
    !3275 规避as strided算子精度问题
    Merge pull request !3275 from 蒋荣强/master
--
    !3262 Add verbose in enable graph mode & Enhance error information about GE interface
    Merge pull request !3262 from 汪瑞哲/coding
2022-03-24 22:17:53 +08:00
AtlasAccount f1891c36af 同步1.5.0 73ce683bf259cd2cc357989a7a0fc0dd8de070f7
!3271 修复MobileNetV2网络dump问题
    Merge pull request !3271 from 周司南/master
2022-03-24 15:34:53 +08:00
AtlasAccount e7e6580ca2 同步1.5.0 d4966fde08017b8ef41b0d6fa15b2593d0f1df76
!3264 【图模式】enbale static memory opt
    Merge pull request !3264 from 王强/master
2022-03-23 19:51:38 +08:00
尤安升 c1f3ad0761 del pytorch1.8.1 2022-03-23 19:50:28 +08:00
AtlasAccount 913f54dc61 同步1.5.0 af5a43963bf86227fce4005d608fa87b83de6ed9
!3265 【BugFix】dropout_with_add_softmax算子名回退
    Merge pull request !3265 from 戢芳/dropout1.5
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-22 21:12:04 +08:00
AtlasAccount 31c3f964bd 同步1.5.0 db48001ed53f91ab992c88990cb9f70f9cd9fd8c
!3261 增加显式调用domask和genmask的接口
    Merge pull request !3261 from lijing/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-22 15:35:59 +08:00
AtlasAccount f70a8b1e31 同步1.5.0 8e14e688a1d328e931838d6b6f0be1fd28c69484
!3259 [bugfix] 修复asstride计算错误问题
    Merge pull request !3259 from 李超/master
--
    !3253 【1.5算子适配】lstm_cell
    Merge pull request !3253 from 戢芳/lstm_cell_forward1.5
--
    !3239 DDP:修复broadcast_coalesced部分数据错误的问题
    Merge pull request !3239 from 袁舰/master
--
    !3251 [bugfix] 修复asstride计算错误问题
    Merge pull request !3251 from 李超/master
--
    !3258 【BugFix】dropout_with_add_softmax修改算子名
    Merge pull request !3258 from 戢芳/dropout1.5
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-21 23:01:05 +08:00
AtlasAccount 6d5a62b73d 同步1.5.0 acd1a7fe34e0da7552bad2978550fa1bd20f6ddb
!3255 【Sortv2支持-1轴排序】sort_without_indices
    Merge pull request !3255 from 周凡/sortwizf
--
    !3256 aoe刷新支持的算子列表
    Merge pull request !3256 from 施博/fix_aoe
--
    !3254 【Topk算子实现改变,删除large_topk分支】topk
    Merge pull request !3254 from 周凡/topk318
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-18 23:01:17 +08:00
AtlasAccount 4f5ed6616a 同步1.5.0 9f59490e7edb5454f8fba51febee6002564c2377
!3246 增加融合算子MultiHeadAttention正反向适配
    Merge pull request !3246 from 李思杰/multi_head_attention
--
    !3245 【bugfix】修复batch_nms问题
    Merge pull request !3245 from 王晓/batch_nms
--
    !3250 【BugFix】layer_norm算子UT更改
    Merge pull request !3250 from 戢芳/layer_norm1.5
--
    !3247 aoe dump功能:屏蔽对不进行调优的算子
    Merge pull request !3247 from 施博/fix_aoe
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-17 23:00:54 +08:00
AtlasAccount 8d535a9189 同步1.5.0 a9ff45c79ee5b4ac41cf226589c428dce579cf65
!3249 [feature] 非连续环境变量移除
    Merge pull request !3249 from 李超/master
--
    !3248 同步刷新aoe接口
    Merge pull request !3248 from 施博/aoe_update
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-16 23:00:53 +08:00
AtlasAccount 563de6fbd9 同步1.5.0 35e6c75271c1bc4b6b9c0739cf734a458fa6b439
!3244 【图模式】deal with the problem of constructing graphs for op NPUClearFloatStatus.
    Merge pull request !3244 from 王强/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-16 12:01:24 +08:00
AtlasAccount ed367a62b7 同步1.5.0 eb8fa3576eed877700b0619b7a54eec4a5506847
!3238 支持cann prof区分step信息
    Merge pull request !3238 from 施博/fix_cann
--
    !3237 图模式 scalar-memory能力增强+单算子场景指定标量格式为ND
    Merge pull request !3237 from 王强/dev
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-14 12:01:04 +08:00
AtlasAccount 3eecafe015 同步1.5.0 0da5e0e53b04208d0556cb58e8e275c7f08b8e46
!3236 【BugFix】修复dropout_with_add_softmax用例bug
    Merge pull request !3236 from 戢芳/drop1.5
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-11 23:01:00 +08:00
AtlasAccount 274004f7ad 同步1.5.0 1bec1e30648214d6b887241e85d52a9359efb6a0
!3234 【BugFix】修复layer_norm结果不匹配的问题
    Merge pull request !3234 from 戢芳/layer_norm1.5
--
    !3229 【功能回退】暂时不使能aclrtQueryEventStatus接口
    Merge pull request !3229 from 蒋荣强/master
--
    !3210 bugfix: 修改Bernoulli启动第2个aicpu代码,原方案不可行,只能支持一种输入情况开启并行
    Merge pull request !3210 from 郭夏/b
--
    !3220 【ctclossv2算子泛化,支持输入targets为1D的场景(原仅支持2D)】ctc_losss
    Merge pull request !3220 from 周凡/ctczf
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-10 23:00:54 +08:00
AtlasAccount 6b9315ad91 同步1.5.0 f12e79810fc1f2347baa10d36a02ef2e417ea0ce
!3224 dev 合入 master
    Merge pull request !3224 from 王强/master
--
    !3216 【BugFix】layer_norm算子问题修复
    Merge pull request !3216 from 戢芳/layer_norm1.5
--
    !3219 合并dev
    Merge pull request !3219 from wangyu/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-08 23:01:01 +08:00
AtlasAccount 3c9a47cd8c 同步1.5.0 702251cf53328a3761755877cb919a7c0cbd9680
!3214 kl_div 1.5算子需求增加
    Merge pull request !3214 from hxf12345677/kl
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-08 12:01:10 +08:00
AtlasAccount 586b3fa039 同步1.5.0 0bb991acd040a67ff19c124b6c4d5f02d04ace4c
!3211 【BugFix】grid_sampler算子的问题修复
    Merge pull request !3211 from 戢芳/gridsampler1.5
--
    !3207 修复dropout_with_byte_mask_精度bug
    Merge pull request !3207 from 詹隽/dropoutv3_dev_fix
--
    !3208 refactor(NpuAny Type): reimplement Npu Any type
    Merge pull request !3208 from 宇世康/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-07 23:00:51 +08:00
AtlasAccount e093b4359a 同步1.5.0 89cc8d62897d765284d550bf432f34d950dd5210
!3204 [bugfix] 禁止asstrided算子参与模糊编译
    Merge pull request !3204 from 李超/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-04 23:01:08 +08:00
AtlasAccount a861f3cb96 同步1.5.0 161dc9d87f9db4ae1cc4d688ad771bc2602f86e5
!3199 【FixBug】topk大规模场景性能问题适配规避
    Merge pull request !3199 from 王晓/topk
--
    !3197 【1.5算子适配】dropout_with_add_softmax融合算子
    Merge pull request !3197 from 戢芳/dropadd
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-03 23:00:52 +08:00
AtlasAccount 47b5c52129 同步1.5.0 89cc2e50c164bc3f5bf17e7c46af7280c2024d77
!3182 pytorch适配DropoutV3
    Merge pull request !3182 from 詹隽/dropoutv3
--
    !3189 【Topk算子实现改变,删除large_topk分支】topk
    Merge pull request !3189 from 周凡/topkzf
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-03-02 23:00:53 +08:00
weili10 f738240fd5 update OWNERS. 2022-03-02 09:21:52 +00:00
i-robot c837a70844 !338 资料合入
Merge pull request !338 from 彭子荣/master
2022-03-01 09:47:50 +00:00
weili10 2a323fab49 update OWNERS. 2022-03-01 09:43:37 +00:00
pengzirong 1a08ccad88 update pics&contents of pytroch网络模型移植&训练指南&Pytroch 安装指南
update

update url of Pytorch installation

update url of Pytorch installation
2022-03-01 17:29:35 +08:00
AtlasAccount f7b065414b 同步1.5.0 d710800a5dafa29aefd6d80bd12150f6f5d2b615
!3181 修改InputWithoutContiguous warning级别,避免强制打屏
    Merge pull request !3181 from 李超/master
--
    !3169 增加npu_format_cast.Tensor、get_npu_format接口,test: format_cast
    Merge pull request !3169 from 王晓/format_cast
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-25 15:59:50 +08:00
AtlasAccount b3fbc1dee0 同步1.5.0 055bf8ca2bc6b3e2fcb09d23844017800bdb2302
!3168 移动NPUEvent.h到c10路径下
    Merge pull request !3168 from wangyu/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-21 12:00:49 +08:00
AtlasAccount ba413bdc6c 同步1.5.0 d1d273166807a809d3c72126b166a4d9115ea527
!3163 合并dev分支
    Merge pull request !3163 from weili10/dev
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-18 12:00:59 +08:00
i-robot 5193ae8b44 !274 刷新api资料,query接口不支持
Merge pull request !274 from 施博/master
2022-02-18 01:31:52 +00:00
shibo19 48b35ef669 刷新api资料,query接口不支持 2022-02-17 19:52:32 +08:00
AtlasAccount e382982f9f 同步1.5.0 362f14f3d12c289a1269e79b9b94f1ebba5a6136
!3155 更改非连续Torch warn类别
    Merge pull request !3155 from 李超/master
--
    !3136 HCCL:修改计算bucket采用的size标准
    Merge pull request !3136 from 袁舰/master
--
    !3137 modify: 修改median调用fill_传参形式,避免调用scalar接口导致频繁编译问题
    Merge pull request !3137 from 郭夏/median
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-14 23:01:04 +08:00
AtlasAccount 3107fe16f7 同步1.5.0 ee97ee4d3b4402b50322b002425cf2cca8939f7c
!3143 [optimize] 转连续通用PTCopy算子替换为asStrided算子
    Merge pull request !3143 from 李超/git_asstride
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-14 12:00:45 +08:00
AtlasAccount 178f3bc3c8 同步1.5.0 f318a3ebbfa9ffda6f09c187824b24b0b53cc183
!3149 1.5.0 小版本号变更
    Merge pull request !3149 from 周司南/masterbk
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-11 14:28:35 +08:00
AtlasAccount c085ad4eb7 同步1.5.0 7e62822bd52eb78d27b9161dc7b68caf77a3094c
!3146 提供DDP分布式流程下,skip grad allreduce的能力
    Merge pull request !3146 from wangyu/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-08 23:00:43 +08:00
彭子荣 0fc3c3a7c4 参考图片 2022-02-08 03:12:34 +00:00
AtlasAccount f89c8a2187 同步1.5.0 a6e7c66af4d9f068792ba80afc3e521bb86d9a85
!3141 【功能维测】新增ut防止开启队列的动态场景下算子attr被重复释放
    Merge pull request !3141 from 蒋荣强/ut
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-02-07 23:00:46 +08:00
i-robot aeca353926 !171 bugfix:修复英文资料的路径和拼写错误
Merge pull request !171 from shibo/master
2022-01-29 09:31:36 +00:00
shibo 6e3d104476 修复英文资料的路径和拼写错误 2022-01-29 16:48:50 +08:00
i-robot d003421c1a !166 bugfix: 修复资料中拼写错误
Merge pull request !166 from shibo/master
2022-01-29 08:37:35 +00:00
shibo 193772bbea 修复拼写错误 2022-01-29 15:35:06 +08:00
AtlasAccount 9ae625472e 同步1.5.0 a37d767dd4110c6561b35a19ae53f265ea71f563
!3139 图模式去除设置High Precision
    Merge pull request !3139 from wangyu/master
--
    !3138 [optimization]非连续下发优化
    Merge pull request !3138 from 李超/git_contiguous
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-01-28 23:01:27 +08:00
AtlasAccount 26178c3a1b 同步1.5.0 2f354fcc04b2186126affa38d94613d733c1af6b
!3134 【维持】queue执行接口加RECORD_HOST_FUNCTION
    Merge pull request !3134 from 蒋荣强/record
--
    !3130 默认开启模糊编译缓存文件落盘
    Merge pull request !3130 from 宇世康/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-01-27 12:01:08 +08:00
AtlasAccount be5356c0c6 同步1.5.0 994f343554d44acd58bea036c0b21d05cd90bd80
!3132 修改门禁把resnet作为必跑用例
    Merge pull request !3132 from 龚俊强/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-01-26 23:01:14 +08:00
AtlasAccount b3372ee933 同步1.5.0 fc962f2d66fc3ebb4183a5305f1c083cac522e7f
!3129 merge dev
    Merge pull request !3129 from 宇世康/master
--
    !3117 LinearBackwardKernelNpu中增加对grad的format校验,避免两次linear_backward_out_npu中对grad重复的transdata
    Merge pull request !3117 from 王姜奔/master
--
    !3124 【1.5算子适配】 ReplicationPad1d 算子适配(2)
    Merge pull request !3124 from 沈鹏程/rep
--
    !3102 【1.5算子适配】 reflectionPad1d 算子适配
    Merge pull request !3102 from 沈鹏程/reflectionPad1d
--
    !3126 回退 Pull Request !3114 : [optimize] 非连续转连续下发优化
    Merge pull request !3126 from weili10/revert-merge-3114-master
--
    !3120 fix option
    Merge pull request !3120 from 宇世康/dev
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-01-25 23:00:43 +08:00
AtlasAccount e96c816b06 同步1.5.0 05af491da69a887ee164bc6907ffbfec7df8a6c1
!3114 [optimize] 非连续转连续下发优化
    Merge pull request !3114 from 李超/contiguous0121
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-01-24 23:01:59 +08:00
AtlasAccount 7eeb579f3f 同步1.5.0 b5bb63fbee5ef9d0147b66a474d26f4129203516
!3116 [optimize] 非连续转连续下发优化-part1-UT修改
    Merge pull request !3116 from 李超/master
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
2022-01-23 23:01:10 +08:00
AtlasAccount c489d97007 同步1.5.0 e41693cd9a610d956c3fe7ea93cc14f96685fe2b
同步1.8.1 5ef4201b03e2651946576f806bef9fdaa7aa1d86
    !2903 1.8.1 addcmul算子适配
    Merge pull request !2903 from 孙幸/1.8_addcmul
--
    !3071 【1.8算子移植】 rsub 算子适配
    Merge pull request !3071 from 沈鹏程/1.8_rsub
--
    !2906 1.8.1 affinegridgenerator算子适配
    Merge pull request !2906 from 孙幸/1.8_affinegridgenerator
--
    !3105 【1.8.1算子适配】ger
    Merge pull request !3105 from 戢芳/ger1.8.1
--
    !3066 remainder1.8.1算子适配
    Merge pull request !3066 from hxf12345677/remainder
2022-01-22 12:00:45 +08:00
i-robot ca485063d0 !106 Updated FrameworkPTAdapter 2.0.4 Release Notes
Merge pull request !106 from yanhuiling/master
2022-01-22 02:48:07 +00:00
AtlasAccount 3cd7ed797d 同步1.5.0 e41693cd9a610d956c3fe7ea93cc14f96685fe2b
!3081 UT 公共文件调整
    Merge pull request !3081 from 龚俊强/master
同步1.8.1 82c1938da320d69e05d03498163d64defc76eb1a
    !3115 ceil算子1.8.1移植
    Merge pull request !3115 from hxf12345677/ceil
--
    !3108 【1.8.1算子适配】 Add Arange Operator
    Merge pull request !3108 from 周凡/NewArangezf
2022-01-21 23:00:55 +08:00
AtlasAccount 6ca23d5514 同步1.5.0 bc11aeb9574ec4229d260f6e335f9b94b9898d3a
同步1.8.1 7b005e2b1e14a04f1aea3a5d4f2e79279f7afff5
    !3103 batch_norm_backward_reduce算子1.8.1移植
    Merge pull request !3103 from hxf12345677/batch_norm_backward_reduce
2022-01-21 12:01:25 +08:00
yanhuiling 287c6e6cc3 update docs/en/RELEASENOTE/FrameworkPTAdapter 2.0.4 Release Notes.md. 2022-01-21 02:30:39 +00:00
yanhuiling 316cc29ee2 Updated this file 2022-01-21 02:27:55 +00:00
yanhuiling f77253ae52 删除文件 docs/en/RELEASENOTE/RELEASENOTE.md 2022-01-21 02:27:44 +00:00
AtlasAccount ae834d5ab6 同步1.5.0 bc11aeb9574ec4229d260f6e335f9b94b9898d3a
!3094 新增对ACL_AUTO_TUNE_MODE的设置的回调函数
    Merge pull request !3094 from 王姜奔/master
同步1.8.1 1fef46b8e6ced0439c22e93488794af076d0bb14
    !3083 【1.8算子迁移】npu_giou
    Merge pull request !3083 from wuxiankun/1.8giou
--
    !3089 【1.8算子适配】 Addbmm 算子适配
    Merge pull request !3089 from 沈鹏程/fix_errorName
--
    !3088 【1.8算子适配】 BinaryCrossEntropy 算子
    Merge pull request !3088 from 沈鹏程/1.8_Bce
--
    !3093 【1.8算子迁移】fast_gelu
    Merge pull request !3093 from wuxiankun/1.8fastgelu
--
    !3033 【1.8.1算子适配】log2
    Merge pull request !3033 from 王晓/1.8.1_log2
2022-01-20 23:00:53 +08:00
i-robot 824e689004 !103 资料合入1.18
Merge pull request !103 from 彭子荣/master
2022-01-20 11:10:54 +00:00
i-robot 456439d5fa !105 [资料修改] readme添加支持python3.9描述
Merge pull request !105 from 李超/master
2022-01-20 04:00:50 +00:00
李超 073a7ea5ff add python 3.9 to readme 2022-01-20 09:21:01 +08:00
AtlasAccount 5f3a2c11fc 同步1.5.0 a64dee29b83da4595f794a8a3f732750deac1fbb
!3082 【功能维测】增加acl接口失败时error msg打印
    Merge pull request !3082 from 蒋荣强/errmsg
同步1.8.1 4068c9ee00fc7808716c5bc10366340e58b837f4
    !3051 gather1.8.1算子移植
    Merge pull request !3051 from hxf12345677/gather
--
    !3070 【1.8算子适配】index
    Merge pull request !3070 from 戢芳/index1.8.1
2022-01-19 23:00:48 +08:00
彭子荣 c61f676a86 update docs/zh/RELEASENOTE/RELEASENOTE.md. 2022-01-19 02:12:47 +00:00
AtlasAccount 05b72bbd37 同步1.5.0 874be2eee35aa7e78f38d50936501a33a7992783
!3069 check_operators_in_prof 函数移入common目录
    Merge pull request !3069 from 龚俊强/master
--
    !3025 【Bugfix】pow不合理ut修改
    Merge pull request !3025 from wuxiankun/powfix
--
    !3068 pytorch单算子&图模式 GE初始化归一
    Merge pull request !3068 from wangyu/master
同步1.8.1 ec77daa5dbb2c1576105932848cd7411eb762d16
    !2679 add: grid_sampler_3d and backward for 1.8.1
    Merge pull request !2679 from 郭夏/grid_sampler_3d
2022-01-18 23:00:48 +08:00
pengzirong 5cc52fb0d1 delete 2022-01-18 17:23:39 +08:00
pengzirong fd7df84a23 update &delete 2022-01-18 17:22:07 +08:00
AtlasAccount b9b4bb55f2 同步1.5.0 007013d041515737cdc132a588baef68937739bc
!3024 【Optim】dropout模糊编译场景下用storage_size
    Merge pull request !3024 from wuxiankun/dropoutfix
同步1.8.1 de30180167ec61b5a87b6b736dce099e48b702f0
    !3049 【1.8.1算子适配】 Add Embedding Operator
    Merge pull request !3049 from 周凡/Embeddingzf
2022-01-17 23:00:51 +08:00
AtlasAccount 5c4774edfd 同步1.5.0 d47b18923e83b31836a378c1f25a7d6b38a35246
同步1.8.1 7b5815af14f46887f5a6f96a853ec42540d45439
    !3050 【1.8.1算子适配】nonzero
    Merge pull request !3050 from 戢芳/nonzero1.8.1
--
    !3048 【1.8.1算子适配】log
    Merge pull request !3048 from 戢芳/log1.8.1
--
    !3036 full1.8.1移植
    Merge pull request !3036 from hxf12345677/full
2022-01-17 12:00:50 +08:00
i-robot 9e8c744c9b !95 资料合入
Merge pull request !95 from 彭子荣/master
2022-01-17 03:29:33 +00:00
weili10 c69b311610 update README.zh.md. 2022-01-17 02:54:41 +00:00
AtlasAccount 4fc41a0ba9 同步1.5.0 d47b18923e83b31836a378c1f25a7d6b38a35246
!3041 非连续ut新增场景识别功能
    Merge pull request !3041 from 李超/contut_git
同步1.8.1 f5798433897cec7315b3c4975ebea87f870216ac
    !3032 bitwise_and 算子1.8.1移植
    Merge pull request !3032 from hxf12345677/bitwise_and
--
    !3007 【1.8算子适配】addcdiv算子适配
    Merge pull request !3007 from 戢芳/addcdiv1.8.1
--
    !3017 floor_divide算子  1.8移植
    Merge pull request !3017 from hxf12345677/floordivided
2022-01-14 23:00:47 +08:00
AtlasAccount 5e85916c11 同步1.5.0 2ed40e98c3f5324ed4688964b8e2e83672a4d11b
!3044 codecheck问题解决
    Merge pull request !3044 from shibo/codecheck_master
同步1.8.1 74798a86310dbeea6f2465943d62b08ff7242a13
    !3045 codecheck问题解决
    Merge pull request !3045 from shibo/codecheck_1.8
2022-01-14 11:08:22 +08:00
AtlasAccount 087c31c639 同步1.5.0 609b84e21970541672b3a3d778b457999d948a61
!3031 【FixBug】修复mul原地接口不支持bool类型的问题
    Merge pull request !3031 from 王晓/bool_mul_
--
    !3038 【BugFix】解决eye不支持bool类型的泛化问题
    Merge pull request !3038 from 陈庆/eye
--
    !2999 【图模式】为AOE不支持私有格式所做的一些工作
    Merge pull request !2999 from 宇世康/master
同步1.8.1 e6365127cfc0cfe901d34cc95687a8ae2b3e59d4
    !3040 【1.8算子适配】norm
    Merge pull request !3040 from 戢芳/norm1.8.1
--
    !3037 【1.8.1算子适配】 Add Bitwise_not Operator
    Merge pull request !3037 from 周凡/bitwise_notzf
--
    !3030 【1.8算子移植  bugfix】asin 算子适配  增加了check memory 、nochenk和checkout操作
    Merge pull request !3030 from 沈鹏程/1.8_asin
2022-01-13 23:00:48 +08:00
i-robot 5043e98a9d !97 Updated English documents in Pytorch docs
Merge pull request !97 from yanhuiling/master
2022-01-13 08:34:36 +00:00
i-robot da46157333 !96 【轻量级 PR】:Updated docs/en/RELEASENOTE/RELEASENOTE.md.
Merge pull request !96 from yanhuiling/N/A
2022-01-13 08:32:37 +00:00
AtlasAccount e4d4da89fb 同步1.5.0 b2885acb09ab80f7e83e7905103428e21767ec1c
!3023 修改cla错误注册路径
    Merge pull request !3023 from 周司南/master
--
    !3021 E2E prof: 增加RTS数据
    Merge pull request !3021 from shibo/update_e2e
同步1.8.1 d5a74a059f253c36d95d2e3147add3b73de69dc1
    !3020 【1.8算子适配】masked_fill_
    Merge pull request !3020 from 戢芳/masked_fill_1.8.1
--
    !3015 【1.8.1算子适配】 Add Sign Operator
    Merge pull request !3015 from 周凡/Signzf
2022-01-13 12:01:08 +08:00
yanhuiling 33ddeeacc1 updated this file 2022-01-13 01:35:53 +00:00
yanhuiling 7c25c163b5 updated this file 2022-01-13 01:24:38 +00:00
AtlasAccount 44456a207d 同步1.5.0 fe7bb42f9ad101851e6666d1f693cc832bb563e8
!2987 重构优化:将获取reducetion算子的reduce str属性方法提取
    Merge pull request !2987 from shibo/reduce_refactor
同步1.8.1 85feac381d2696f90686bddf4a1b20642feac2de
    !3013 【1.8算子适配】sort
    Merge pull request !3013 from 戢芳/sort1.8.1
--
    !2969 【1.8.1算子适配】 asin 算子适配
    Merge pull request !2969 from 沈鹏程/1.8_asin
2022-01-12 23:00:47 +08:00
yanhuiling e4545fc3a1 Updated this file 2022-01-12 13:07:55 +00:00
yanhuiling 4c55098d78 删除文件 docs/en/PyTorch Operator Support/PyTorch Operator Support.md 2022-01-12 13:07:22 +00:00
yanhuiling 6e5333f278 Updated this file 2022-01-12 13:07:00 +00:00
yanhuiling 5de24000dc 删除文件 docs/en/ONNX Operator List/ONNX Operator List.md 2022-01-12 13:06:40 +00:00
yanhuiling a70b2dc515 Updated this file 2022-01-12 13:06:04 +00:00
yanhuiling ce1a48074f 删除文件 docs/en/PyTorch Network Model Porting and Training Guide/PyTorch Network Model Porting and Training Guide.md 2022-01-12 13:05:39 +00:00
yanhuiling e6c723cf1d Added new three files. 2022-01-12 13:03:40 +00:00
彭子荣 5bd7ddf2b6 !1 update docs/en/PyTorch Operator Development Guide/PyTorch Operator Development Guide.md.
Merge pull request !1 from 阿里斯开扇/N/A
2022-01-12 02:08:50 +00:00
彭子荣 f519cc5110 !2 update docs/en/PyTorch Installation Guide/PyTorch Installation Guide.md.
Merge pull request !2 from 阿里斯开扇/N/A
2022-01-12 02:08:16 +00:00
彭子荣 3dd19b2755 !3 update docs/en/PyTorch Online Inference Guide/PyTorch Online Inference Guide.md.
Merge pull request !3 from 阿里斯开扇/N/A
2022-01-12 02:07:24 +00:00
AtlasAccount c441c8ab11 同步1.5.0 e04468a8072a298400e4663930375dac5e7c271b
同步1.8.1 226b38852b3d5f13696bddd50d98be6e4201b169
    !3011 BinaryCrossEntropyWithLogitsKernelNpu 算子适配
    Merge pull request !3011 from 沈鹏程/1.8_BinaryCrossEntropyWithLogitsKernelNpu
--
    !3012 upsample_nearest2d_backward.grad_input修改
    Merge pull request !3012 from hxf12345677/upsample_nearest2d_backward
--
    !2678 add: grid_sampler for 1.8.1
    Merge pull request !2678 from 郭夏/grid_sampler
2022-01-11 23:00:47 +08:00
阿里斯开扇 675e0d7869 update docs/en/PyTorch Online Inference Guide/PyTorch Online Inference Guide.md.
少量优化
2022-01-11 12:13:11 +00:00
阿里斯开扇 4c9cc52b0e update docs/en/PyTorch Installation Guide/PyTorch Installation Guide.md.
少量优化
2022-01-11 11:56:00 +00:00
yanhuiling 5f326039fd Updated docs/en/RELEASENOTE/RELEASENOTE.md.
Updated the English version based on the Chinese version.
2022-01-11 11:24:54 +00:00
阿里斯开扇 62fed021fe update docs/en/PyTorch Operator Development Guide/PyTorch Operator Development Guide.md.
少量优化
2022-01-11 11:19:59 +00:00
AtlasAccount 91837b9a3b 同步1.5.0 3cb40ae6d0f4a1ad2a059428e1d0a52a2a031573
!2883 modify: upsample_nearest3d反向支持FP16输入
    Merge pull request !2883 from 郭夏/upsample_nearest3d
同步1.8.1 b36205a79412c995f8af9d3dc1ce4f689230fdcf
    !2718 【1.8.1适配“MaxUnpool2d”】
    Merge pull request !2718 from 李攀/do_1.8.1
--
    !2988 添加UT:dataloader模块
    Merge pull request !2988 from shibo/add_data_181
--
    !3006 BinaryCrossEntropy算子适配
    Merge pull request !3006 from 沈鹏程/1.8_Bce
--
    !2970 argsort算子适配
    Merge pull request !2970 from 沈鹏程/1.8_argsort
--
    !2985 Argmax算子适配
    Merge pull request !2985 from 沈鹏程/1.8_argmax
2022-01-11 12:01:13 +08:00
AtlasAccount 57299e8539 同步1.5.0 a171f976cd63fd9c1827f0250862d74811a6dfae
同步1.8.1 2d27390353026584b536879952b84532e06ed4d3
    !2994 atan算子适配
    Merge pull request !2994 from 沈鹏程/1.8_atan
--
    !2990 atan2算子适配
    Merge pull request !2990 from 沈鹏程/1.8_atan2
--
    !3005 clamp算子适配
    Merge pull request !3005 from 沈鹏程/1.8_clamp
2022-01-10 23:00:46 +08:00
pengzirong 3a01034b86 update onnx operator support list 2022-01-10 11:46:45 +08:00
AtlasAccount e6ed5931a7 同步1.5.0 a171f976cd63fd9c1827f0250862d74811a6dfae
同步1.8.1 6d17cfd33a1f5783949d45fd9090da0fa886a61e
    !2977 单元测试引用文件结构
    Merge pull request !2977 from 龚俊强/pytorch1.8.1
2022-01-08 23:00:46 +08:00
AtlasAccount f7cd5ac04a 同步1.5.0 a171f976cd63fd9c1827f0250862d74811a6dfae
!3000 路径拼接使用os.path.join 代替直接字符串加
    Merge pull request !3000 from 龚俊强/master
--
    !3001 回退代码
    Merge pull request !3001 from wangyu/master
同步1.8.1 8937dfc7728adc20d3e5a8f8e6907a37361dd7d0
2022-01-07 23:00:52 +08:00
i-robot b05f263002 !93 资料合入
Merge pull request !93 from 彭子荣/master
2022-01-07 04:00:40 +00:00
pengzirong 8c5dd060e3 fix erro 2022-01-07 11:31:36 +08:00
pengzirong ac5c210a3f delete 2022-01-07 09:42:54 +08:00
pengzirong dde15147ef new file 2022-01-07 09:22:24 +08:00
pengzirong b08e75eb9b delete 2022-01-07 09:22:01 +08:00
pengzirong 8eb3985a69 Merge branch 'master' of gitee.com:peng-zirong/pytorch 2022-01-07 09:21:49 +08:00
pengzirong 745ea1d2ca new file 2022-01-07 09:21:24 +08:00
pengzirong 67d8b2d801 delete 2022-01-07 09:21:05 +08:00
pengzirong 0774236c93 new file 2022-01-07 09:18:23 +08:00
pengzirong 40c47421ab delete 2022-01-07 09:17:42 +08:00
pengzirong 3fbdcf7b02 Merge branch 'master' of gitee.com:peng-zirong/pytorch 2022-01-07 09:16:11 +08:00
AtlasAccount 150a34d6b9 同步1.5.0 c38bbfd7b64217ee049b8125ebf7497c2613c50f
!2997 【功能修复】解决因为memset导致的内存泄漏问题
    Merge pull request !2997 from 蒋荣强/memory
--
    !2961 [Requirement] 模型需求 var 算子适配
    Merge pull request !2961 from 沈鹏程/adapt_var
同步1.8.1 8937dfc7728adc20d3e5a8f8e6907a37361dd7d0
2022-01-06 23:00:52 +08:00
pengzirong 53296dbd84 delete 2022-01-06 17:52:47 +08:00
pengzirong b81e31a023 new files 2022-01-06 17:49:27 +08:00
pengzirong 4a91d7f244 delete all files 2022-01-06 17:49:05 +08:00
AtlasAccount f99e45f951 同步1.5.0 752642b4993a90359274fe49efeeace9718cde66
!2967 rotatediou适配     在原基础上增加两个attr属性
    Merge pull request !2967 from 沈鹏程/rotatediou_adapt
同步1.8.1 8937dfc7728adc20d3e5a8f8e6907a37361dd7d0
2022-01-06 12:00:50 +08:00
AtlasAccount 6b932a1c14 同步1.5.0 1e7b9443e574817d7513413e37d52254b0cfd93e
!2980 【bugfix】torch1.5不支持python3.9.不再提供编包支持
    Merge pull request !2980 from 李超/master
同步1.8.1 8937dfc7728adc20d3e5a8f8e6907a37361dd7d0
2022-01-05 23:00:47 +08:00
AtlasAccount 081221378d 同步1.5.0 7448ccd0ad9192c58cab04ef1c1097144c63b624
!2974 优化 graph_utils.py 引用结构
    Merge pull request !2974 from 龚俊强/master
--
    !2971 【泛化】适配层兜底,泛化BatchNormGatherStatsWithCounts算子精度
    Merge pull request !2971 from wuxiankun/bngswc16
同步1.8.1 8937dfc7728adc20d3e5a8f8e6907a37361dd7d0
    !2968 argmin算子适配
    Merge pull request !2968 from 沈鹏程/1.8_Argmin
--
    !2976 【支持3.9】pytorch1.8.1支持python3.9环境编包
    Merge pull request !2976 from 李超/pytorch1.8.1
2022-01-04 23:00:49 +08:00
AtlasAccount 8ef0a73f52 同步1.5.0 4aefefb8b34ba797713af6cea714fd3607fb3fd3
!2964 bugfix   处理   由于输出shape为空,导致模型报错问题
    Merge pull request !2964 from 沈鹏程/bug_fix1
同步1.8.1 b59213c0dad6f3384b4556683c023011f8fe1417
2021-12-31 23:00:47 +08:00
AtlasAccount fb4a88b4df 同步1.5.0 8c5b04d0e2827d4ea72a29f79edaebe8cba38a40
!2960 回退:reduce_op 影响范围广,不能再公共层修改
    Merge pull request !2960 from shibo/master
同步1.8.1 b59213c0dad6f3384b4556683c023011f8fe1417
2021-12-31 12:00:49 +08:00
AtlasAccount dbc635ffd8 同步1.5.0 6fcdca5a55cf72fa4ea07518a9ffedf72d7ae813
!2956 bugfix   处理 由于输出为空shape,导致模型报错问题
    Merge pull request !2956 from 沈鹏程/bug_fix
--
    !2957 bugfix 处理 由于输出为空shape,导致模型报错问题
    Merge pull request !2957 from 沈鹏程/bug_fix1
--
    !2954 【Bugfix】SyncBNTrainingUpdate 支持5hd操作
    Merge pull request !2954 from wuxiankun/204tr204tr5synbcwit
同步1.8.1 b59213c0dad6f3384b4556683c023011f8fe1417
    !2910 All算子适配
    Merge pull request !2910 from 沈鹏程/1.8_all
2021-12-30 23:00:47 +08:00
AtlasAccount 341a0d458e 同步1.5.0 b703cc7e3e21142ce0210f36f9b339e82a79bb92
!2948 【功能优化】队列执行接口增加RECORD_HOST_FUNCTION
    Merge pull request !2948 from 蒋荣强/master
同步1.8.1 ca365306224b30011046732c31a9766a3fcd608a
2021-12-30 12:00:49 +08:00
AtlasAccount 30dea0aa6b 同步1.5.0 15f933e18f5c64b5e1f4f2e46ab6ea59ac0caa85
!2949 修复bug,图模式set option之前先check option长度
    Merge pull request !2949 from wangyu/master
--
    !2945 【性能优化】增大release queue的size,避免队列归一后出现release queue满队列
    Merge pull request !2945 from 蒋荣强/ReleaseQueue
同步1.8.1 ca365306224b30011046732c31a9766a3fcd608a
2021-12-29 23:00:49 +08:00
AtlasAccount 9e457706a6 同步1.5.0 3589de64c034ae33997c1951003db08fb167f751
!2942 E2E prof:ut修改
    Merge pull request !2942 from shibo/e2e_bugfix
同步1.8.1 ca365306224b30011046732c31a9766a3fcd608a
2021-12-29 12:01:04 +08:00
AtlasAccount 9541c9b673 同步1.5.0 e08b3ae490cd0a3f0e358caa3a2a7f3b453e5708
!2932 modify:logical_and适配支持更多dtype类型输入
    Merge pull request !2932 from 郭夏/logical_and
--
    !2929 SyncBatchNorm: 修改命名、修复codecheck
    Merge pull request !2929 from 袁舰/master
--
    !2880 modify: upsample_trilinear3d正反向支持FP16输入
    Merge pull request !2880 from 郭夏/upsample_trilinear3d
同步1.8.1 ca365306224b30011046732c31a9766a3fcd608a
2021-12-28 23:00:44 +08:00
1278 changed files with 22921 additions and 205430 deletions
+24
View File
@@ -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**:
+17 -5
View File
@@ -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
+324 -87
View File
@@ -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
>![](figures/icon-note.gif) **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
```
> ![img](figures/icon-notice.gif) **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/**.
>![](figures/icon-note.gif) **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).
+337 -69
View File
@@ -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
>![](figures/icon-note.gif) **说明:**
>若安装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
```
> ![img](figures/icon-notice.gif) **须知:**
>其中“--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/“。
>![](figures/icon-note.gif) **说明:**
>本步骤为用户在需要用到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
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

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)
![](figures/210926103326800.png)
- [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
```
>![](public_sys-resources/icon-note.gif) **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**.
>![](public_sys-resources/icon-note.gif) **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**
>![](public_sys-resources/icon-note.gif) **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) &gt; Docker NICs &gt; 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**.
>![](public_sys-resources/icon-note.gif) **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.
>![](public_sys-resources/icon-note.gif) **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.
>![](public_sys-resources/icon-notice.gif) **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
```
>![](public_sys-resources/icon-note.gif) **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
```
![](figures/en-us_image_0000001190081735.png)
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
```
> ![img](public_sys-resources/icon-notice.gif) **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/**.
>![](public_sys-resources/icon-note.gif) **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.
>![](public_sys-resources/icon-note.gif) **NOTE:**
>Skip this step if you do not the compilation environment with GCC upgraded.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 580 B

File diff suppressed because it is too large Load Diff
@@ -18,7 +18,7 @@
昇腾910 AI处理器
昇腾710 AI处理器
昇腾310P AI处理器
<h2 id="基本使用流程md">基本使用流程</h2>
@@ -596,4 +596,3 @@ if __name__ == '__main__':
>![](public_sys-resources/icon-note.gif) **说明:**
>本步骤为用户在需要用到gcc升级后的编译环境时才配置环境变量。
+382 -461
View File
@@ -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配套软件)
- [安装方式](#安装方式)
![](figures/210926103326800.png)
- [运行](#运行)
<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
```
>![](public_sys-resources/icon-note.gif) **说明:**
>受网络波动影响,源码获取时间可能较长,下载过程中请耐心等待。 下载完成之后若没有报错,即生成了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。
>![](public_sys-resources/icon-note.gif) **说明:**
>若对环境中的PyTorch进行升级时,需要先卸载环境中已安装的PyTorch软件包再执行[5. 安装PyTorch。](#zh-cn_topic_0000001152776301_li49671667141)可以通过执行如下命令查询环境上是否已安装PyTorch。
>**pip3 list | grep torch**
>![](public_sys-resources/icon-note.gif) **说明:**
>若安装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以外网卡(网卡名字字典序升序排列)&gt;docker 网卡 &gt; 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
```
>![](public_sys-resources/icon-note.gif) **说明:**
>受网络波动影响,源码获取时间可能较长,下载过程中请耐心等待。
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。
>![](public_sys-resources/icon-note.gif) **说明:**
>若对环境中的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
```
>![](public_sys-resources/icon-notice.gif) **须知:**
>其中“--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
```
> ![img](public_sys-resources/icon-notice.gif) **须知:**
>其中“--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/“。
>![](public_sys-resources/icon-note.gif) **说明:**
>本步骤为用户在需要用到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
```
>![](public_sys-resources/icon-note.gif) **说明:**
>本步骤为用户在需要用到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"。
![](figures/zh-cn_image_0000001190081735.png)
#### 可能原因<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));}
```
>![](public_sys-resources/icon-note.gif) **说明:**
@@ -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。
>![](public_sys-resources/icon-note.gif) **说明:**
>若环境中已安装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>运行测试用例时,将日志重定向到指定文件。
Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

+248 -3
View File
@@ -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>
Binary file not shown.

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+1158 -464
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -7
View File
@@ -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)

Some files were not shown because too many files have changed in this diff Show More