Compare commits

...
118 Commits
Author SHA1 Message Date
AtlasAccount 89ccfe98c5 同步1.5.0 f65ae6da5e9651ee8c8aa10c1cfab9ee9ed69272
!2821 taakqueue场景下release para不使用queue
    Merge pull request !2821 from shibo/2.0.4.B030
同步1.8.1 438c8daf58550d882e8b4763910cc93b927d89f7
2021-12-05 15:35:22 +08:00
AtlasAccount 358dc94e35 同步1.5.0 c8a3fa5ae181cf41e79044e132d2ec89390e14a5
!2820 [Bugfix] 转变NpuMemoryCheck顺序,防止storage()未定义
    Merge pull request !2820 from 宇世康/master
同步1.8.1 438c8daf58550d882e8b4763910cc93b927d89f7
2021-12-04 16:18:36 +08:00
AtlasAccount e9a794a491 同步1.5.0 b08d8f7bbfa236bc413a16d0d2f8c8c086c3d654
!2798 【需求】【1.8反合1.5】1.8版本增加NPU独有算子反合1.5版本
    Merge pull request !2798 from 姚斌/master
同步1.8.1 438c8daf58550d882e8b4763910cc93b927d89f7
2021-12-01 12:00:44 +08:00
AtlasAccount 141d1b4c51 同步1.5.0 18dad28e5f25f2334f456aaf6d5f32680bccff25
!2784 提交图模式 test_contiguous ut 测试代码
    Merge pull request !2784 from 薛磊/test_nllloss
--
    !2776 Task: clean codecheck warnings
    Merge pull request !2776 from 赵光灿/master
--
    !2797 graph mode ut code style 3
    Merge pull request !2797 from 薛磊/pr_ut_1130
--
    !2767 modify: std规避ReduceStdWithMean算子输入0维或者1维1个元素时报错的问题
    Merge pull request !2767 from 郭夏/std_modify
--
    !2795 graph mode ut code style 2
    Merge pull request !2795 from 薛磊/pr_ut_code_check_v2
同步1.8.1 438c8daf58550d882e8b4763910cc93b927d89f7
2021-11-30 23:00:47 +08:00
AtlasAccount 9961ec03ae 同步1.5.0 58174932de2d5809cc64768eb3c43ea2bf981618
!2760 【优化】Div适配优化
    Merge pull request !2760 from 吴贤坤/fixbug5.0
同步1.8.1 438c8daf58550d882e8b4763910cc93b927d89f7
2021-11-30 12:00:58 +08:00
i-robot e8e641b331 !82 刷新docs文档:提示切换分支
Merge pull request !82 from shibo/add_docs
2021-11-30 01:50:08 +00:00
AtlasAccount eb29fd3e36 同步1.5.0 5185b6cbd85176ff1854db1ed80ef1c87147a3b0
!2786 【图模式】Run图接口添加RecordHostFunc,记录耗时
    Merge pull request !2786 from 宇世康/master
--
    !2792 PR门禁脚本改为运行test/test_npu/XXX/目录下脚本
    Merge pull request !2792 from 龚俊强/master
--
    !2788 graph mode ut code style
    Merge pull request !2788 from 薛磊/test_code_check
--
    !2755 【Bugfix】grid_sampler2d修改test_batchnormbackwardreduce脚本参数名修改重构
    Merge pull request !2755 from 吴贤坤/fixbug4.0
同步1.8.1 438c8daf58550d882e8b4763910cc93b927d89f7
    !2790 Task: clean codecheck warnings
    Merge pull request !2790 from 赵光灿/pytorch1.8.1
--
    !2773 1.8.1算子适配:ge,le
    Merge pull request !2773 from 王晓/1.8_ge_le_gt_lt
2021-11-29 23:00:45 +08:00
i-robot 0c5c61e3bc !81 Added README.en.md.
Merge pull request !81 from yanhuiling/master
2021-11-29 11:22:14 +00:00
shibo19 3708204f40 update docs 2021-11-29 10:55:12 +08:00
AtlasAccount fbdf33ddd0 同步1.5.0 2e9004844c45a4ef97f1642ec3ed395451115879
!2781 【Patch】gru bias bug 修复补丁
    Merge pull request !2781 from 吴贤坤/grupatch
--
    !2778 [Feature] 支持python3.9
    Merge pull request !2778 from 李超/py39
同步1.8.1 c2fd32bc49a6ce4170114c122a503d1c92589716
2021-11-27 12:00:47 +08:00
AtlasAccount 676978f973 同步1.5.0 ce7a96cd1f0d4ea0cc24bb1b134e534aca6c3ca9
!2783 nllloss2d 修改调用接口,删除老接口
    Merge pull request !2783 from 薛磊/dev_nllloss
--
    !2780 删除图模式contiguous, pow相关用例
    Merge pull request !2780 from 薛磊/del_contiguous
--
    !2771 解决图模式下 nllloss 适配层内存拷贝问题
    Merge pull request !2771 from 薛磊/pr_calcu_nllloss
--
    !2732 图模式ut
    Merge pull request !2732 from 薛磊/ut_graph
--
    !2779 【图模式】修复is graph mode接口的double free问题
    Merge pull request !2779 from 宇世康/master
--
    !2769 【图模式】 去除图模式的abi为1的依赖,需要等cann包更新后合入
    Merge pull request !2769 from 宇世康/ysk
同步1.8.1 c2fd32bc49a6ce4170114c122a503d1c92589716
2021-11-26 23:02:48 +08:00
AtlasAccount 6ff723d026 同步1.5.0 528664affa111c3976ff6a72ab9befa42ff96fef
!2713 【optimize】3d 类模型格式转换优化
    Merge pull request !2713 from 李超/3d_transdata
--
    !2727 add test case for the cross-device copy check
    Merge pull request !2727 from weili10/master
--
    !2761 Task: clean codecheck warnings
    Merge pull request !2761 from 赵光灿/master
同步1.8.1 c2fd32bc49a6ce4170114c122a503d1c92589716
    !2770 【BugFix】【需求】NPU独有算子适配apply_adam_out_npu、bert_apply_adam_out_npu
    Merge pull request !2770 from 姚斌/pytorch1.8.1
--
    !2762 Task: clean codecheck warnings
    Merge pull request !2762 from 赵光灿/pytorch1.8.1
2021-11-25 23:00:47 +08:00
AtlasAccount 184db237b1 同步1.5.0 841a9a8d082265efd5649d0d9c7cf050ea9379aa
!2748 [Requirement] 模型需求 rotated_overlaps算子adapt
    Merge pull request !2748 from 吴贤坤/rto
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
2021-11-25 12:00:51 +08:00
AtlasAccount df03cbe8d6 同步1.5.0 0941c08390a26f4ab4627f73371adf4bdd49b7c1
!2766 【优化】Dropout适配优化
    Merge pull request !2766 from 陈庆/drop
--
    !2753 修改PR门禁以及全量UT测试的判错标准
    Merge pull request !2753 from 龚俊强/master
--
    !2758 [contrib/npu/optimized_lib/] avoid warning
    Merge pull request !2758 from 王姜奔/master
--
    !2768 【图模式】set graph mode varibale mem max size to 1M
    Merge pull request !2768 from 王强/master
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
2021-11-24 23:00:47 +08:00
yanhuiling 02b5954125 added README.en.md.
added  README.en.md.
2021-11-24 14:05:14 +00:00
AtlasAccount c3723c6db0 同步1.5.0 5655fb8d0be5580b7870c5e8ec65f3ac2e9197a8
!2754 modify: 调用dot时修改为直接调用NPU函数,保证模糊编译能够正常运行
    Merge pull request !2754 from 郭夏/matmul
--
    !2757 【图模式】图模式与单算子模式都在empty与empty with format中将storage添加入context中
    Merge pull request !2757 from 宇世康/master
--
    !2756 【图模式】bugfix of switch between graph mode and single-op mode
    Merge pull request !2756 from 王强/master
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
2021-11-24 12:04:05 +08:00
AtlasAccount 2125edf662 同步1.5.0 57fb197351ff3087282bd37a01da3d2f59f67491
!2734 dump图以支持aoe功能
    Merge pull request !2734 from shibo/aoe
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
2021-11-23 23:00:48 +08:00
AtlasAccount e698adf379 同步1.5.0 482cf5c72cbb3b52ebf4a626566aeaa6da014824
!2750 【FixBug】修复mse_loss在非nd场景下的报错
    Merge pull request !2750 from 王晓/mseloss
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
2021-11-23 12:00:42 +08:00
AtlasAccount 172a8154f8 同步1.5.0 49dfa00e664e205b94843572ac10064546583660
!2744 [acl profiling]兼容msprof,对msprof已经运行的错误不做处理
    Merge pull request !2744 from lijing/master
--
    !2729 【适配】npu_min接口适配
    Merge pull request !2729 from 陈庆/minv1
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
2021-11-22 23:01:02 +08:00
AtlasAccount e6c9ed0c77 同步1.5.0 774fb0bd7f1e7c30f18517e3ef5f41a7dc4761d6
!2730 【性能优化】优化出队列间隙耗时
    Merge pull request !2730 from 蒋荣强/optimize1
--
    !2743 跨so调用增加TORCH_NPU_API维护GraphExecutor单例
    Merge pull request !2743 from 宇世康/master
--
    !2741 【图模式】原地算子中,内存overlap判断情形增加IS_NULL
    Merge pull request !2741 from 宇世康/master
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
2021-11-19 23:01:33 +08:00
weili10 d938e07a73 update README.zh.md. 2021-11-19 08:17:21 +00:00
weili10 8a5c0b30a1 update README.zh.md. 2021-11-19 08:14:41 +00:00
weili10 262d785419 update README.zh.md. 2021-11-19 08:14:05 +00:00
AtlasAccount cebdde8f48 同步1.5.0 fbee31be058af34c021da0f152d128ecf5e86c5d
同步1.8.1 b220e1bfda03c88c7a5d72322e2fe2b68794149e
    !2740 【bugfix】【需求】【1.8NPU独有算子适配整改】npu_bert_apply_adam
    Merge pull request !2740 from 姚斌/pytorch1.8.1
2021-11-19 00:41:55 +08:00
AtlasAccount e9257ed887 同步1.5.0 fbee31be058af34c021da0f152d128ecf5e86c5d
!2728 【功能修复】解决event入队列后的死锁问题
    Merge pull request !2728 from 蒋荣强/bug1
--
    !2677 graph mode cat和stack代码适配修改
    Merge pull request !2677 from 薛磊/dev_cat_stack
同步1.8.1 63b24dfd62f070475f36d43df01a74181ce90aa5
2021-11-18 19:54:32 +08:00
i-robot e420c35be6 !80 需求合入
Merge pull request !80 from liuquan/master
2021-11-18 09:27:43 +00:00
weili10 c5581b6189 update OWNERS. 2021-11-18 09:26:13 +00:00
AtlasAccount f44d2a8710 同步1.5.0 241bab3b3b873e4219bacf244e178e88abe85994
!2737 增加一些图模式需要的函数打桩+修复cuda版本的编译问题
    Merge pull request !2737 from 宇世康/master
--
    !2736 【图模式pr】view and contiguous changes of graph mode
    Merge pull request !2736 from 王强/master
--
    !2731 【Bugfix】LSTM反向梯度丢失
    Merge pull request !2731 from 陈庆/master
同步1.8.1 63b24dfd62f070475f36d43df01a74181ce90aa5
2021-11-18 12:00:45 +08:00
AtlasAccount 4eb5bbd3fe 同步1.5.0 a79fa0808e178fe36ee49ae22d874fa5cfa15bff
!2724 【图模式PR_2】pr_2的主要修改是融合GraphCommandImpl到OpCommandBase中,接管Opcmd的接口,在不改变单算子适配的情况下使能图构造
    Merge pull request !2724 from 宇世康/graph_mode
--
    !2725 fix broadcast opt verification conditions, avoid incorrect recognition of expand + view
    Merge pull request !2725 from 王强/master
同步1.8.1 63b24dfd62f070475f36d43df01a74181ce90aa5
2021-11-17 16:09:04 +08:00
AtlasAccount 0c58e128e7 同步1.5.0 cd7987730df2e98d4d725ddbee973db7645c656a
!2726 【功能修复】开启queue后删除oom保护机制
    Merge pull request !2726 from 蒋荣强/bug
--
    !2719 【FixBug】AICPU算子upsample_nearest3d正反向支持fp16
    Merge pull request !2719 from 王晓/up_n3d_b
同步1.8.1 63b24dfd62f070475f36d43df01a74181ce90aa5
    !2702 【需求】【1.8NPU独有算子适配】npu_bert_apply_adam、npu_apply_adam
    Merge pull request !2702 from 姚斌/pytorch1.8.1
--
    !2722 add cross-device copy check
    Merge pull request !2722 from weili10/pytorch1.8.1
2021-11-16 23:22:38 +08:00
AtlasAccount 0e1d68761b 同步1.5.0 73424f02c30a6800cf967c23920a27e5f4fbc212
!2721 add cross-device copy check
    Merge pull request !2721 from weili10/master
同步1.8.1 07edd5926b30109419e105521bc675f55ae0e3f6
2021-11-16 12:00:53 +08:00
AtlasAccount e161be6f75 同步1.5.0 474fcee57578ecb93985b22b3b50aff461250fd2
!2716 【图模式】 PR_1 :增量修改,增加图构造,图执行,图缓存的能力以及增加pytorch层的四个接口
    Merge pull request !2716 from 宇世康/graph_mode
同步1.8.1 07edd5926b30109419e105521bc675f55ae0e3f6
2021-11-16 10:11:52 +08:00
AtlasAccount 40e0982fe4 同步1.5.0 e0da7d2e6931d71edb7bbcba6d68d3d12f1bd20f
!2709 [contrib/npu/optimized_lib/] add SiLU
    Merge pull request !2709 from 王姜奔/silu
--
    !2714 【功能修复】解决record event入队列后,event资源延迟释放导致的evnet资源耗尽问题
    Merge pull request !2714 from 蒋荣强/bug
--
    !2670 【Bugfix】 修改&补充test.constant_pad_nd测试用例
    Merge pull request !2670 from 吴贤坤/fixbug2.0
--
    !2711 【FixBug】修复mv在输入为转置tensor时报错的问题
    Merge pull request !2711 from 王晓/mv
--
    !2712 调用aclopCompileAndExecute时判断gil锁是否被持有,持有的话释放。目的时防止TE编译算子时无法获取gil锁。
    Merge pull request !2712 from 宇世康/ysk
同步1.8.1 07edd5926b30109419e105521bc675f55ae0e3f6
2021-11-15 14:40:25 +08:00
liuquan 3a36da0345 modify IR2TBE 2021-11-13 17:44:27 +08:00
AtlasAccount 6a32513e71 同步1.5.0 226265063cfb50661352605720c96d09498e7564
!2697 【适配优化】constant_pad_nd性能优化
    Merge pull request !2697 from 陈庆/master
--
    !2695 【Bugfix】nll_loss输出格式修改
    Merge pull request !2695 from 吴贤坤/fixbug3.0
同步1.8.1 07edd5926b30109419e105521bc675f55ae0e3f6
2021-11-12 09:30:13 +08:00
AtlasAccount 3b92e80698 同步1.5.0 2f47f3a0304a181ecc4f75c6a36f329e6435b0b6
!2672 【Requirement】Gru多层双向功能适配补充
    Merge pull request !2672 from 吴贤坤/gru
--
    !2704 add: bincount for 1.5.1
    Merge pull request !2704 from 郭夏/bincount
--
    !2674 【FixBug】softmax_backward移除多余格式转换
    Merge pull request !2674 from 王晓/softmax_backward_nz
同步1.8.1 07edd5926b30109419e105521bc675f55ae0e3f6
    !2599 add:  erf op for ver 1.8.1
    Merge pull request !2599 from 郭夏/erf
2021-11-11 12:00:45 +08:00
AtlasAccount 127ddaeb87 同步1.5.0 ee9cf0fbc27e260173c16ce55a829f477e51f84f
同步1.8.1 120ae5365ebb24137b534ce063c7d7dc7a408c61
    !2657 【1.8.1】适配“upsamplebilinear2d”
Merge: 1fb062334 049b1e4f2
    !2662 【1.8.1】适配“Scatter_”
    Merge pull request !2662 from 李攀/do_1.8.1
--
    !2647 delete redundant check_match and invalid trans-contiguous code
    Merge pull request !2647 from weili10/pytorch1.8.1
2021-11-10 23:00:45 +08:00
AtlasAccount eb42aa1431 同步1.5.0 ee9cf0fbc27e260173c16ce55a829f477e51f84f
!2705 【性能优化】新增SCALAR_TO_HOST_MEM环境变量用于控制scalar输入的是否转为host memory
    Merge pull request !2705 from 蒋荣强/bug
同步1.8.1 a355a602d33f0fe3b65a627d9d0cf784309c1466
    !2700 bugfix: 修复profiler打印信息错误问题
    Merge pull request !2700 from shibo/profiler_bug
2021-11-10 20:46:37 +08:00
liuquan 3a1a239c76 modify format 2021-11-10 17:34:32 +08:00
liuquan 62c4f91fff modify format 2021-11-10 17:17:15 +08:00
liuquan ba0cdcc6f5 profiler 新增功能 2021-11-10 16:46:54 +08:00
AtlasAccount 9d8ba72c9b 同步1.5.0 7d56e9e47baa563428026b1315ea3e7155e29082
同步1.8.1 db8554c8db96ce9bac588aa6c0a9b6321482d76d
    !2696 【1.8算子适配】cdist、cdist_backward、pdist
    Merge pull request !2696 from 姚斌/pytorch1.8.1_1
2021-11-09 23:00:56 +08:00
AtlasAccount 77069c2c3e 同步1.5.0 7d56e9e47baa563428026b1315ea3e7155e29082
!2663 【图模式】Graph execute/construct/cache/utils功能以及正式python接口
    Merge pull request !2663 from 宇世康/master
同步1.8.1 c3ca90462e9c6d7cdefec410ce71b6d01ac76142
2021-11-09 12:00:50 +08:00
AtlasAccount 5510f37292 同步1.5.0 61e1a032928f4b80953bf4b130debba5f971a53d
!2699 修复RECORD_HOST_FUNCTION宏的bug,acl task queue线程也可以使用RECORD_HOST_FUNCTION
    Merge pull request !2699 from wangyu/master
--
    !2698  提供RECORD_HOST_FUNCTION宏,用于只记录host侧耗时
    Merge pull request !2698 from wangyu/master
--
    !2684 [dump utils] ThnnConvDepthwise2DBackward 在特定情况下仍然走cudnn
    Merge pull request !2684 from lijing/master
同步1.8.1 c3ca90462e9c6d7cdefec410ce71b6d01ac76142
    !2661 【1.8算子适配】softmax、true_divide
    Merge pull request !2661 from 姚斌/pytorch1.8.1
2021-11-08 23:00:44 +08:00
AtlasAccount 49aac16852 同步1.5.0 5dbbdd469a94c9e120360555c61fc66011478e26
同步1.8.1 87c1ee679055f052ab9a2bcdfc7bbfd065dd0ade
    !2642 【pytorch 1.8 算子适配】提交算子addmv、addr
    Merge pull request !2642 from TD_lihan/py18_addmv
--
    !2640 【pytorch 1.8 算子适配】提交算子adaptive_avg_pool1d
    Merge pull request !2640 from TD_lihan/py18_AdaptiveAvgPool1d
--
    !2604 【1.8算子迁移】卷积类修改等
    Merge pull request !2604 from 吴贤坤/conv_1.8
--
    !2654 增加profiler UT
    Merge pull request !2654 from shibo/profiler_ut
--
    !2668 【1.8算子适配】celu、selu
    Merge pull request !2668 from 姚斌/pytorch1.8.1_1
2021-11-08 12:00:45 +08:00
AtlasAccount 25b61ee2ee 同步1.5.0 5dbbdd469a94c9e120360555c61fc66011478e26
同步1.8.1 ddeb6df954cd6db748138cdd7d27e6d61de80b14
    !2683 1.8版本增加HCCL环境变量
    Merge pull request !2683 from shibo/add_env
--
    !2681 ddp在fp32场景下训练失败修复
    Merge pull request !2681 from shibo/dd_bugfix
--
    !2682 修复npu tensor类型转换丢失梯度属性问题
    Merge pull request !2682 from shibo/cast_bugfix
2021-11-06 16:37:10 +08:00
AtlasAccount 2ece9b72f6 同步1.5.0 5dbbdd469a94c9e120360555c61fc66011478e26
!2649 使用Identity代替Transdata
    Merge pull request !2649 from 詹隽/Identity_dev
--
    !2667 【性能优化】add record event to queue
    Merge pull request !2667 from 蒋荣强/RecordEvent
--
    !2660 1.5版本profiler功能优化
    Merge pull request !2660 from shibo/profiler_15
--
    !2658 【Bugfix】修改oom问题当调Conv3d时
    Merge pull request !2658 from 吴贤坤/fixbug
同步1.8.1 9702fe1349fd09e99d12a9d6799da5783da84663
    !2601 PyTorch1.8算子适配:uniform_
    Merge pull request !2601 from 牛作东/uniform_
2021-11-04 23:00:44 +08:00
AtlasAccount 2572775832 同步1.5.0 98d45fbd807b8bff03f51a05aedc3ac5efca29e3
!2666 Task: clean codecheck warnings
    Merge pull request !2666 from 赵光灿/master
同步1.8.1 80e9f656f8a2e05d80cd616847d7b7cb2586efc0
    !2645 Task: clean codecheck warnings
    Merge pull request !2645 from 赵光灿/pytorch1.8.1
2021-11-04 12:01:01 +08:00
AtlasAccount 500b51dd61 同步1.5.0 0a6f40ccd42088c4e0266ca62f22c3a1e1812ac7
同步1.8.1 b505d498eb6541469d8c8fdc07ed96c1a80f63c8
2021-11-03 12:01:11 +08:00
AtlasAccount bda7456cd9 同步1.5.0 0a6f40ccd42088c4e0266ca62f22c3a1e1812ac7
!2634 【1.5适配】“BatchNormBackwardElemt”
    Merge pull request !2634 from 李攀/bugfix
--
    !2629 东北大学TensorEqual算子适配测试文件交付
    Merge pull request !2629 from k188/TensorEqual
--
    !2650 Task: clean codecheck warnings
    Merge pull request !2650 from 赵光灿/master
同步1.8.1 b505d498eb6541469d8c8fdc07ed96c1a80f63c8
    !2655 【1.8算子适配】randperm、stack
    Merge pull request !2655 from 姚斌/pytorch1.8.1_1
--
    !2652 【1.8算子适配】std、std_mean、trunc
    Merge pull request !2652 from 姚斌/pytorch1.8.1
--
    !2646 【1.8.1】适配“maxunpool3d”
    Merge pull request !2646 from 李攀/do_1.8.1_2
--
    !2638 【pytorch 1.8 算子适配】提交算子abs
    Merge pull request !2638 from TD_lihan/py18_abs
--
    !2648 【1.8适配】“优化test_floatstatus.py”
    Merge pull request !2648 from 李攀/do_1.8.1
2021-11-03 09:39:32 +08:00
AtlasAccount 040029c1a1 同步1.5.0 58a86f5a7d8cfbb02dba057f04537b9e004f4593
同步1.8.1 cfa8827d1fb5c28878e856d6c5d1ec5f261ab206
2021-11-02 12:01:04 +08:00
AtlasAccount ec371989b4 同步1.5.0 58a86f5a7d8cfbb02dba057f04537b9e004f4593
!2641 Task: clean codecheck warnings
    Merge pull request !2641 from 赵光灿/master
--
    !2621 【算子适配】grid_sampler_2d算子正反向
    Merge pull request !2621 from 姚斌/master
--
    !2632 【Bugfix】算子不支持batch_first为True,适配层需将输出的Batch轴作为第0轴
    Merge pull request !2632 from 陈庆/master
同步1.8.1 cfa8827d1fb5c28878e856d6c5d1ec5f261ab206
    !2639 【pytorch 1.8 算子适配】提交算子acos
    Merge pull request !2639 from TD_lihan/py18_acos
--
    !2626 【1.8升级】L1Loss
2021-11-01 23:00:57 +08:00
liuquan ca59aaf3c6 修改格式 2021-11-01 18:42:41 +08:00
liuquan 78f946c17d 新增:IR映射TBE 2021-11-01 18:37:42 +08:00
AtlasAccount ef4e7240b6 同步1.5.0 790429b1a174b47714d38e7dd2b18a36bef01f83
同步1.8.1 1901c67035192c760ebdd32f422ea86fa40bf922
2021-10-31 23:00:50 +08:00
AtlasAccount 6ac16dfab0 同步1.5.0 790429b1a174b47714d38e7dd2b18a36bef01f83
同步1.8.1 1901c67035192c760ebdd32f422ea86fa40bf922
2021-10-31 12:00:49 +08:00
AtlasAccount 283e923317 同步1.5.0 790429b1a174b47714d38e7dd2b18a36bef01f83
!2637 异步拷贝入队列
    Merge pull request !2637 from 蒋荣强/async
--
    !2635 Task: clean codecheck warnings
    Merge pull request !2635 from 赵光灿/master
同步1.8.1 1901c67035192c760ebdd32f422ea86fa40bf922
    !2624 【适配】To/Rsub算子适配
    Merge pull request !2624 from 陈庆/pytorch1.8.1
--
    !2603 1.8算子迁移】ps_roi_pooling,npu_roi_align, npu_iou等
    Merge pull request !2603 from 吴贤坤/npu_fd_bd_1.8_bnms
--
    !2636 1.8版本优化profiler
    Merge pull request !2636 from shibo/profiler_simple
2021-10-30 23:02:03 +08:00
AtlasAccount e6e7203cce 同步1.5.0 caf3ceb04e4a115ce8d1498952c110fb4b9bc317
!2625 修改OpCommandBase中input和output接口参数
    Merge pull request !2625 from 薛磊/dev_opcommand_parameter
同步1.8.1 2bfd20f98a90ed25faa3a019ec42379e6e153b3e
2021-10-30 12:00:39 +08:00
AtlasAccount 6bb0e87a77 同步1.5.0 639610b805d6bc4abfe4ee632e6291aa48835d3c
!2630 Task: clean codecheck warnings
    Merge pull request !2630 from 赵光灿/master
同步1.8.1 2bfd20f98a90ed25faa3a019ec42379e6e153b3e
2021-10-29 23:00:56 +08:00
AtlasAccount 2497544a76 同步1.5.0 b1f4e771b0b6f736386bba9838e28edb0556e743
同步1.8.1 2bfd20f98a90ed25faa3a019ec42379e6e153b3e
    !2631 Task: clean codecheck warnings
    Merge pull request !2631 from 赵光灿/pytorch1.8.1
2021-10-29 12:00:48 +08:00
AtlasAccount ae597b5e21 同步1.5.0 b1f4e771b0b6f736386bba9838e28edb0556e743
同步1.8.1 c1fa09ac6f19542adfd7a1dded1561b1a0fb3fd9
    !2616 1.8.1算子tril、ne、eq适配迁移
    Merge pull request !2616 from 王晓/tril
--
    !2613 1.8.1算子triu适配迁移
    Merge pull request !2613 from 王晓/1.8.1_triu
2021-10-28 23:00:49 +08:00
AtlasAccount c0723277c4 同步1.5.0 b1f4e771b0b6f736386bba9838e28edb0556e743
同步1.8.1 ebba68383c462ce8351d6fc4c1f19b3039568925
2021-10-28 12:00:53 +08:00
AtlasAccount 64daba9637 同步1.5.0 b1f4e771b0b6f736386bba9838e28edb0556e743
同步1.8.1 ebba68383c462ce8351d6fc4c1f19b3039568925
2021-10-27 23:15:47 +08:00
AtlasAccount d9e50e3a9f 同步1.5.0 b1f4e771b0b6f736386bba9838e28edb0556e743
同步1.8.1 ebba68383c462ce8351d6fc4c1f19b3039568925
2021-10-27 12:00:50 +08:00
AtlasAccount 4dec0c82a1 同步1.5.0 b1f4e771b0b6f736386bba9838e28edb0556e743
!2622 solve input type mismatch problem of mul
    Merge pull request !2622 from 蒋荣强/scalar
同步1.8.1 ebba68383c462ce8351d6fc4c1f19b3039568925
    !2600 add:  exp op for 1.8.1
    Merge pull request !2600 from 郭夏/exp
--
    !2565 1.8.1适配“maxpool3d, smoothL1Loss, SoftMarginLoss”
    Merge pull request !2565 from 李攀/do_1.8.1_2
2021-10-26 23:00:52 +08:00
AtlasAccount e6b84a7986 同步1.5.0 bf7628c383f445fbdb4c95fb3aa002bff260a9f3
!2620 op proto for graph mode
    Merge pull request !2620 from 薛磊/dev_op_proto
--
    !2619 [dump utils]修复op map返回为空的问题
    Merge pull request !2619 from lijing/master
同步1.8.1 62372aba9b1c73f87ef30f87027886e93d960382
    !2617  【function】add python3.8 compiling to pytorch1.8
    Merge pull request !2617 from 李超/pytorch1.8.1
--
    !2612 【1.8算子迁移】tanh,sigmoidgrad等
    Merge pull request !2612 from 吴贤坤/backward_1.8
--
    !2610 【1.8适配】nllloss2dbackward
    Merge pull request !2610 from 李攀/do_1.8.1_5
--
    !2618 1.8版本profiling支持屏蔽适配层内算子
    Merge pull request !2618 from shibo/profiler_simple
--
    !2611 【1.8算子适配】min、mv、ones
    Merge pull request !2611 from 姚斌/pytorch1.8.1
2021-10-26 12:00:48 +08:00
i-robot f2e2a4168d !78 update the catalog of en docs
Merge pull request !78 from yinzijun/master
2021-10-26 01:32:56 +00:00
AtlasAccount 92f9e54783 同步1.5.0 081357bddfac9aafadf4c37cfbccffbe21e392fe
!2595 [dump utils]新增view类黑名单算子
    Merge pull request !2595 from lijing/master
--
    !2615 [contrib/npu/optimized_lib/] add giou
    Merge pull request !2615 from 王姜奔/giou
--
    !2614 dynamicShape: forbiden roialign and roialigngrad
    Merge pull request !2614 from 周司南/master
同步1.8.1 87920ba2ff21bb968a8e371f11dc4ba47b94a768
2021-10-25 23:00:45 +08:00
AtlasAccount 5d23983945 同步1.5.0 88bb20489508d6783c1d2816eb911dae21757f7a
同步1.8.1 87920ba2ff21bb968a8e371f11dc4ba47b94a768
2021-10-24 23:00:55 +08:00
AtlasAccount 0850d4e22a 同步1.5.0 88bb20489508d6783c1d2816eb911dae21757f7a
同步1.8.1 87920ba2ff21bb968a8e371f11dc4ba47b94a768
2021-10-24 12:01:05 +08:00
AtlasAccount c788e1a85c 同步1.5.0 88bb20489508d6783c1d2816eb911dae21757f7a
!2594 使用 OpCommand 接口适配relu和gelu backward算子
    Merge pull request !2594 from 薛磊/dev_relu_gelu
同步1.8.1 87920ba2ff21bb968a8e371f11dc4ba47b94a768
2021-10-23 23:00:46 +08:00
AtlasAccount f414fe6e4c 同步1.5.0 7508158b533e4974558a4e72653917aa45d694c3
同步1.8.1 87920ba2ff21bb968a8e371f11dc4ba47b94a768
    !2607 【1.8算子适配】round、rsqrt、sqrt
    Merge pull request !2607 from 姚斌/pytorch1.8.1
2021-10-22 23:00:57 +08:00
ZijunYin af726a697e update en docs. 2021-10-22 17:30:59 +08:00
AtlasAccount afa8699efc 同步1.5.0 7508158b533e4974558a4e72653917aa45d694c3
同步1.8.1 c3e7e61c49a22e7564a914ec70ea3e37d99adef0
2021-10-22 00:58:31 +08:00
AtlasAccount 89f71305c3 同步1.5.0 7508158b533e4974558a4e72653917aa45d694c3
!2598 add Enqueue profiling
    Merge pull request !2598 from 蒋荣强/queue
同步1.8.1 c3e7e61c49a22e7564a914ec70ea3e37d99adef0
2021-10-21 12:00:46 +08:00
AtlasAccount 2bd42a661f 同步1.5.0 46cd8d05f7f053fd22ccf4d1d35ff0ae881b071f
同步1.8.1 c3e7e61c49a22e7564a914ec70ea3e37d99adef0
2021-10-20 23:05:13 +08:00
AtlasAccount 88cbcb90dd 同步1.5.0 46cd8d05f7f053fd22ccf4d1d35ff0ae881b071f
!2590 Add Version + 1
    Merge pull request !2590 from 周司南/master
--
    !2570 ifdef 和 if defined 不能混用
    Merge pull request !2570 from shibo/bug_fix
--
    Merge pull request !2593 from weili10/revert-merge-2554-master
--
    Merge pull request !2592 from weili10/revert-merge-2584-master
--
    !2587 [dump utils]fix compile error
    Merge pull request !2587 from lijing/master
同步1.8.1 c3e7e61c49a22e7564a914ec70ea3e37d99adef0
    !2582 【1.8算子迁移】thnn_conv2d_forward重构
    Merge pull request !2582 from 吴贤坤/thnn_conv_1.8
--
    !2581 【1.8算子迁移】Upsample部分
    Merge pull request !2581 from 吴贤坤/up3d_1.8
--
    !2579 1.8.1算子适配 cross
    Merge pull request !2579 from 王晓/1.8_cross
2021-10-20 16:04:06 +08:00
AtlasAccount 706b56bf41 同步1.5.0 0178176bcf5feb64a463ee5eea17e15e30acd60f
!2586 【dump utils】修复当tensor某些维度为0时load报错问题
    Merge pull request !2586 from lijing/master
同步1.8.1 1e37554a67274f6244ece6522a8ba7a5888c426e
    !2495 【pytorch1.8适配】Where、Resize、Norm、Pow适配
    Merge pull request !2495 from 陈庆/pytorch1.8.1
--
    !2577 【1.8算子迁移】col2im等
    Merge pull request !2577 from 吴贤坤/colim_1.8
--
    !2574 pytorch1.8 pprofiling功能
    Merge pull request !2574 from shibo/profiler_update
2021-10-19 12:02:15 +08:00
AtlasAccount 5f1e9f8cc8 同步1.5.0 9305e2ee100c65f034ef8d0128d3c4b2faa40c29
同步1.8.1 71641840df36c327d5400f22bbdc02d825bee026
2021-10-18 12:00:49 +08:00
AtlasAccount 4317ec1bca 同步1.5.0 9305e2ee100c65f034ef8d0128d3c4b2faa40c29
同步1.8.1 71641840df36c327d5400f22bbdc02d825bee026
2021-10-17 12:00:56 +08:00
i-robot ace7ba9a8b !76 update image in Installation Guide
Merge pull request !76 from yinzijun/master
2021-10-15 10:30:49 +00:00
weili10 8dc400cd8a update README.zh.md. 2021-10-15 10:06:20 +00:00
ZijunYin f2c1df9134 update image in docs/en/PyTorch Installation Guide 2021-10-15 17:52:30 +08:00
i-robot 728b16d171 !74 update English docs
Merge pull request !74 from yinzijun/master
2021-10-15 09:36:48 +00:00
ZijunYin 6285b3b60f Merge branch 'master' of https://gitee.com/yinzijun/pytorch 2021-10-15 17:22:45 +08:00
ZijunYin 1017d89d57 update English docs. 2021-10-15 17:22:34 +08:00
AtlasAccount 424de74a3a 同步1.5.0 7682920856d82fcc09bd1806585cf042a5a99b3b
!2584 solve accuracy problem due to adding async copy to queue
    Merge pull request !2584 from 蒋荣强/master
同步1.8.1 82054017ffd27967cfd4224f6142fdaf23000b5b
    !2566 1.8.1适配“mseloss, avgpool2d, avgpool3d”
2021-10-15 12:01:11 +08:00
AtlasAccount 7e05a39e42 同步1.5.0 da42cdf6867c2e854c21278dbf0ca135e036beb4
!2573 modify scalar input to host memory input
    Merge pull request !2573 from 蒋荣强/scalar
同步1.8.1 290416bb037a6ca8168f266e5f0ad547f2b5afc5
    !2575 1.8.1“float_status”
    Merge pull request !2575 from 李攀/do_1.8.1
2021-10-14 12:00:53 +08:00
i-robot 24bfeaa78c !72 更新readme
Merge pull request !72 from shibo/update_readme
2021-10-13 09:30:49 +00:00
AtlasAccount 47e8fac4ae 同步1.5.0 86ce2266c01b28e46d42f1c34c81f73a70e238cf
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-13 12:01:01 +08:00
AtlasAccount c916024ec7 同步1.5.0 86ce2266c01b28e46d42f1c34c81f73a70e238cf
!2563 适配silu正反向算子
    Merge pull request !2563 from 王夏夏/master
--
    !2569 solve codex problem
    Merge pull request !2569 from 蒋荣强/master
--
    !2567 fix codexbug
    Merge pull request !2567 from 周司南/master
--
    !2568 修复codedex告警
    Merge pull request !2568 from 詹隽/mm_nd_dev
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-12 12:00:58 +08:00
AtlasAccount 710ce99fa7 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-11 12:00:48 +08:00
shibo19 14f78e1593 update 2021-10-11 11:32:48 +08:00
shibo19 ad48d8f66b update 2021-10-11 11:30:40 +08:00
shibo19 5dee0e68b4 update 2021-10-11 11:29:04 +08:00
AtlasAccount 20034c4f3b 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-10 12:01:13 +08:00
i-robot ecd705896a !70 update RELEASENOTE with 2.0.2
Merge pull request !70 from yinzijun/master
2021-10-09 10:11:51 +00:00
ZijunYin a1297c462f update RELEASENOTE.md 2021-10-09 17:53:59 +08:00
yinzijun 04e467e6c2 !69 update README
Merge pull request !69 from liuquan/master
2021-10-09 08:43:04 +00:00
刘全 33a911c624 update docs/zh/RELEASENOTE/RELEASENOTE.md. 2021-10-09 07:20:02 +00:00
yinzijun 14bd359387 !65 add releasenote
Merge pull request !65 from yinzijun/master
2021-10-09 07:03:12 +00:00
AtlasAccount 52701635fa 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-09 12:01:54 +08:00
ZijunYin f8028e788f add RELEASENOTE.md 2021-10-09 09:54:11 +08:00
weili10 2e5af37b40 update README.zh.md. 2021-10-09 01:12:54 +00:00
AtlasAccount 472a02ee7b 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-08 12:01:05 +08:00
AtlasAccount 03077bc002 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-07 12:00:48 +08:00
AtlasAccount 8027eddae2 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-06 12:01:02 +08:00
AtlasAccount 4e12aed2c4 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-05 12:01:05 +08:00
AtlasAccount d60a312292 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-04 12:01:10 +08:00
AtlasAccount ed5baac37f 同步1.5.0 2d8899df9adbfe0234c5d913dff8a8fddee61ada
!2554 add AsyncMemcpy to queue
    Merge pull request !2554 from 蒋荣强/fuzzy
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-10-03 12:00:54 +08:00
yinzijun d3fca1bddd !63 update docs 2.0.3.B090
Merge pull request !63 from yinzijun/master
2021-09-30 07:15:55 +00:00
ZijunYin 4082c74535 update docs/zh/PyTorch API支持清单/PyTorch API支持清单.md & docs/zh/PyTorch网络模型移植&训练指南/PyTorch网络模型移植&训练指南.md 2021-09-30 15:02:46 +08:00
ZijunYin 7b0b8cc5b9 update docs 2.0.3.B090 2021-09-30 14:41:32 +08:00
AtlasAccount bd49e63f36 同步1.5.0 a4dfab7869d894d1f2a3629463f1aed4b63bec1b
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-09-30 12:31:03 +08:00
AtlasAccount c47ca17bee 同步1.5.0 a4dfab7869d894d1f2a3629463f1aed4b63bec1b
!2560 【BugFix】修复输入shape不一致,算子侧未broadcast,导致不支持
    Merge pull request !2560 from 姚斌/master
--
    !2557 modify: 去除UT中1维NZ格式的用例
    Merge pull request !2557 from 郭夏/ut_modify
--
    !2555 修复IOU输出数据类型转换
    Merge pull request !2555 from 李攀/bugfix
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-09-29 12:01:07 +08:00
AtlasAccount 6e78d9b798 同步1.5.0 f9ff07a2aef09f4901025c8375dfcb4157fe38e0
!2551 add fuzzy flag to queue
    Merge pull request !2551 from 蒋荣强/fuzzy
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-09-28 12:00:45 +08:00
AtlasAccount 325e0c9686 同步1.5.0 6ee40447c11dc17c5f58d7fcad9ae9f1a078057e
!2552 修复load模式时conv2d反向dump结果ir_name被覆盖的问题
    Merge pull request !2552 from gaokai21/master
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-09-27 20:58:36 +08:00
AtlasAccount 8b46a4fa68 同步1.5.0 68aca6bc147877979b06059240f3f246f0625a07
!2477 [contrib/npu/optimized_lib/] 修复iou和bbox_coder在输入经过归一化时精度下降的问题
    Merge pull request !2477 from 王姜奔/20210903
--
    !2456 [contrib/npu/optimized_lib/] fix import bug in __init__
    Merge pull request !2456 from 王姜奔/master
--
    !2543 修复maxunpool2dbackward执行报错
    Merge pull request !2543 from 李攀/bugfix
同步1.8.1 7afd57f35ebc3b81dd4c3f642e3f8ba81c1f07f0
2021-09-27 12:00:48 +08:00
780 changed files with 66813 additions and 12565 deletions
+1 -1
View File
@@ -1,6 +1,7 @@
approvers:
- blian
- nalinaly
- weili10
reviewers:
- zhou_sinan
- shibo19
@@ -14,6 +15,5 @@ reviewers:
- yskhhh
- lvpeiyuan
- xchu42
- weili10
- goodjobwubai
- fairwarning
+261
View File
@@ -0,0 +1,261 @@
# 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.
# 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.)
# System Dependencies
## CentOS & EulerOS
yum install -y cmake zlib-devel libffi-devel openssl-devel libjpeg-turbo-devel gcc-c++ sqlite-devel dos2unix openblas
## 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
# 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.)|
# Method of Use - Full Code Generation and Compilation
## Obtain the native PyTorch source code and third-party code.
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.
```sh
// Version 1.5.0
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.)
```sh
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.
## Generate the PyTorch code adapted 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.)
```sh
// The default version is 1.5.0.
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.
## Install the Python dependency.
Go to the **pytorch/pytorch/** directory and install the Python dependency.
```python3
pip3 install -r requirements.txt
```
## Compile the binary package of Torch.
Go to the **pytorch/pytorch/** directory and 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.
# Installation
### (Version 1.5.0 is used as an example. The same rule applies to version 1.8.1.)
**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
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
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
```
# Running
## Execute environment variables.
Run the script for setting environment variables in the root directory of the current repository.
```
source pytorch/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.
```
## Run the unit test script.
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
```
# Documentation
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).
# Suggestions and Communication
We sincerely welcome you to join discussions in the community and contribute your suggestions. We will reply to you as soon as possible.
# Branch Maintenance Policies
The version branches of AscendPyTorch have the following maintenance phases:
| **Status**| **Duration**| **Description**|
| ----------------- | ------------- | -------------------------------------------------- |
| Planning | 1 - 3 months | Plan features.|
| Development | 3 months | Develop features.|
| Maintained | 6 - 12 months | Allow the incorporation of all resolved issues and release the version.|
| Unmaintained | 0 - 3 months | Allow the incorporation of all resolved issues. No dedicated maintenance personnel are available. No version will be released.|
| End Of Life (EOL) | N/A | Do not accept any modifications 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 | |
# FAQs
## The error message "no module named yaml/typing_extensions." is displayed when **bash build.sh** is run during compilation.
PyTorch compilation depends on the YAML and typing_extensions libraries, which need to be manually installed.
```
pip3 install pyyaml
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
Development state:
```
cd /urs/local/ascend-toolkit/latest/fwkacllib/lib64
```
User state:
```
cd /urs/local/nnae/latest/fwkacllib/lib64
pip3 install --upgrade topi-0.4.0-py3-none-any.whl
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.
Download the Linux version from the CMake official website and install it. (The current version is 3.18.0.)
1. Run the **yum install -y cmake==3.18.0** command to install it.
2. Download the **cmake sh** script and install it. (For details, see the CMake official website.)
Recommended script in the x86_64 environment: **cmake-3.18.2-Linux-x86_64.sh**
## GCC version switch errors occur.
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:
gcc, g++, c++ (The version must be 7.3.0.)
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
```
# Release Notes
For details, see [Release Notes](https://gitee.com/ascend/pytorch/tree/master/docs/en/RELEASENOTE).
+24 -27
View File
@@ -26,10 +26,10 @@ apt-get install -y gcc g++ make build-essential libssl-dev zlib1g-dev libbz2-dev
# Ascend配套软件
| AscendPyTorch版本 | CANN版本 |
| :------------ | :----------- |
| 2.0.2 | CANN 5.0.2 |
| 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模型) |
# 使用方式 --生成全量代码并编译
@@ -100,7 +100,7 @@ bash build.sh --python=3.8
torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl (实际可能附带小版本号例如torch-1.5.0.post2+ascend-cp37-cp37m-linux_x86_64.whl)
```python
```shell
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_x86_64.whl
```
@@ -110,7 +110,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)
```python
```shell
pip3 uninstall torch
pip3 install --upgrade torch-1.5.0+ascend-cp37-cp37m-linux_aarch64.whl
```
@@ -151,36 +151,20 @@ export DYNAMIC_OP="ADD#MUL" # 算子实现,ADD和MUL算子在不同场景下
验证运行, 输出结果OK
```python
```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
```
# 路标
# 文档
以下将展示AscendPyTorch近期的计划,我们会根据用户的反馈诉求,持续调整计划的优先级。
有关安装指南、模型迁移和训练/推理教程和API列表等更多详细信息,请参考[用户文档](docs/zh)。
总体而言,我们会努力在以下几个方面不断改进。
# 建议与交流
1、pytorch AICPU多核能力补齐
2、pytorch单算子模式const节点输入
3、pytorch场景支持算子非连续输入
4、pytorch单算子模式支持动态shape
5、NLP网络格式转化方案完善
6、pytorch的基线格式调整
7、reshapeType总体方案梳理优化
8、AICPU针对pytorch方案梳理优化
热忱希望各位在用户社区加入讨论,并贡献您的建议。
热忱希望各位在用户社区加入讨论,并贡献您的建议,我们会尽快给您回复。
# 分支维护策略
@@ -199,10 +183,20 @@ 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 | |
# FAQ
## 编译过程执行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问题
开发态:
@@ -257,3 +251,6 @@ Ubuntu环境
apt install libopenblas-dev
```
# 版本说明
版本说明请参阅[ReleseNote](docs/zh/RELEASENOTE)
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

@@ -0,0 +1,555 @@
# 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 Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)
<h2 id="overviewmd">Overview</h2>
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.
**Figure 1** Environment setup process<a name="en-us_topic_0000001119176876_fig1938918396117"></a>
![](figures/210926103326800.png)
<h2 id="manual-build-and-installationmd">Manual Build and Installation</h2>
- **[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)**
<h3 id="prerequisitesmd">Prerequisites</h3>
#### 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_.
- 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 or 3.8 has been installed.
- The Patch and Git tools have been installed in the environment. To install the tools for Ubuntu and CentOS, run the following commands:
- Ubuntu
```
apt-get install patch
apt-get install git
```
- CentOS
```
yum install patch
yum install git
```
<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:
```
git clone https://gitee.com/ascend/pytorch.git
```
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. Run the following commands to 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
```
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**
<h3 id="configuring-environment-variablesmd">Configuring Environment Variables</h3>
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).
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:
```
source pytorch/env.sh
```
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" # 1.1.1.1 is the NIC IP address of the host. Change it based on the site requirements. Ensure that the NIC IP addresses in use can communicate with each other in the cluster.
```
3. \(Optional\) Configure function or performance environment variables in the NPU scenario. The variables are disabled by default.
```
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.
```
4. \(Optional\) 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
<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>
</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>
</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>
</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>
</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>
</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>
</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>
#### Prerequisites<a name="en-us_topic_0000001106176190_section3225481020"></a>
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>
1. Log in to the server as the **root** user or a non-root user.
2. Obtain the Apex source code.
1. Run the following command to obtain the Apex source code adapted to Ascend AI Processors:
```
git clone https://gitee.com/ascend/apex.git
```
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 create a 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:
```
cd apex
git clone https://github.com/NVIDIA/apex.git
```
After the native Apex source code is downloaded, the main directory structure of the code is as follows:
```
apex
│ ├─apex # Directory for storing the native Apex code
│ ├─patch # Directory of the patch adapted to Ascend AI Processors
│ ├─npu.patch
│ ├─scripts # Build and create a 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
```
>![](public_sys-resources/icon-note.gif) **NOTE:**
>Due to network fluctuation, it may take a long time to obtain the source code.
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.
```
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 compile and generate the binary installation package of Apex.
```
cd ../apex
python3 setup.py --cpp_ext --npu_float_status bdist_wheel
```
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**.
4. <a name="en-us_topic_0000001106176190_li425495374416"></a>Install Apex.
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**.
>![](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**
<h2 id="referencesmd">References</h2>
- **[Installing CMake](#installing-cmakemd)**
- **[How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md)**
- **[What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?](#what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd)**
<h3 id="installing-cmakemd">Installing CMake</h3>
Procedure for upgrading CMake to 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
```
2. Decompress the package and go to the software package directory.
```
tar -xf cmake-3.12.1.tar.gz
cd cmake-3.12.1/
```
3. Run the configuration, build, 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.1" is displayed, the installation is successful.
<h3 id="how-do-i-install-gcc-7-3-0md">How Do I Install GCC 7.3.0?</h3>
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. 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:
```
tar -zxvf gcc-7.3.0.tar.gz
```
2. Go to the extracted directory and run the following command to 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 validation fails, check whether the dependency packages are repeatedly downloaded. The packages should be downloaded at a time.
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.
```
./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
```
>![](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**.
5. Set the environment variable.
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](#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/**.
>![](public_sys-resources/icon-note.gif) **NOTE:**
>Skip this step if you do not need to use the compilation environment with GCC upgraded.
<h3 id="what-do-i-do-if-torch-1-5-0xxxx-and-torchvision-do-not-match-when-torch--whl-is-installedmd">What Do I Do If "torch 1.5.0xxxx" and "torchvision" Do Not Match When torch-\*.whl Is Installed?</h3>
#### Symptom<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section197270431505"></a>
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.
![](figures/en-us_image_0000001190081735.png)
#### Possible Causes<a name="en-us_topic_0000001105856364_en-us_topic_0175549220_section169499490501"></a>
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.
#### Solution<a name="en-us_topic_0000001105856364_section108142031907"></a>
This problem has no impact on the actual result, and no action is required.
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

@@ -0,0 +1,599 @@
# PyTorch Online Inference Guide
- [Application Scenario](#application-scenariomd)
- [Basic Workflow](#basic-workflowmd)
- [Prerequisites](#prerequisitesmd)
- [Online Inference Process](#online-inference-processmd)
- [Environment Variable Configuration](#environment-variable-configurationmd)
- [Sample Reference](#sample-referencemd)
- [Special Topics](#special-topicsmd)
- [Mixed Precision](#mixed-precisionmd)
- [How Do I Install GCC 7.3.0?](#how-do-i-install-gcc-7-3-0md)
<h2 id="application-scenariomd">Application Scenario</h2>
Online inference, unlike offline inference, allows developers to perform inference directly with PyTorch models using the **model.eval\(\)** method.
In this way, PyTorch-based inference apps can be directly ported to the Ascend AI Processor, which is especially useful in the data center inference scenarios.
### Supported Processors<a name="section15598658104219"></a>
Ascend 910 AI Processor
Ascend 710 AI Processor
<h2 id="basic-workflowmd">Basic Workflow</h2>
- **[Prerequisites](#prerequisitesmd)**
- **[Online Inference Process](#online-inference-processmd)**
- **[Environment Variable Configuration](#environment-variable-configurationmd)**
- **[Sample Reference](#sample-referencemd)**
<h3 id="prerequisitesmd">Prerequisites</h3>
The PyTorch framework and mixed precision module have been installed. For details, see the _PyTorch Installation Guide_.
<h3 id="online-inference-processmd">Online Inference Process</h3>
[Figure 1](#fig13802941161818) shows the online inference process.
**Figure 1** Online inference process<a name="fig13802941161818"></a>
![](figures/online-inference-process.png "online-inference-process")
<h3 id="environment-variable-configurationmd">Environment Variable Configuration</h3>
The following are the environment variables required for starting the inference process on PyTorch:
```
# Set the environment variable for the installation path of the infrastructure software on which online inference depends. The following assumes that the installation user is HwHiAiUser, and the default installation path is used.
# Method 1: Install Ascend-CANN-Toolkit for inference on an Ascend AI device, which serves as the development environment.
. /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
# Method 2: Install Ascend-CANN-NNAE on an Ascend AI device.
. /home/HwHiAiUser/Ascend/nnae/set_env.sh
# If multiple Python 3 versions exist in the operating environment, configure the installation path of Python 3.7.5 in environment variables.
export PATH=/usr/local/python3.7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
# Sets the logical ID of a processor.
export ASCEND_DEVICE_ID=0
# Outputs log information. Replace it as required.
export ASCEND_SLOG_PRINT_TO_STDOUT=1
export ASCEND_GLOBAL_LOG_LEVEL=0
# Task issued with multiple threads
export TASK_QUEUE_ENABLE=0
```
**Table 1** Description of environment variables
<a name="table2072027194819"></a>
<table><thead align="left"><tr id="row1173527114812"><th class="cellrowborder" valign="top" width="46.75467546754676%" id="mcps1.2.4.1.1"><p id="p073027114816"><a name="p073027114816"></a><a name="p073027114816"></a>Environment Variable</p>
</th>
<th class="cellrowborder" valign="top" width="43.18431843184319%" id="mcps1.2.4.1.2"><p id="p157362712480"><a name="p157362712480"></a><a name="p157362712480"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="10.061006100610062%" id="mcps1.2.4.1.3"><p id="p187392714485"><a name="p187392714485"></a><a name="p187392714485"></a>Required/Optional</p>
</th>
</tr>
</thead>
<tbody><tr id="row2732273481"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p57382719481"><a name="p57382719481"></a><a name="p57382719481"></a>LD_LIBRARY_PATH</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p07319271480"><a name="p07319271480"></a><a name="p07319271480"></a>Dynamic library search path. Set this variable based on the preceding example.</p>
<div class="note" id="note119943144912"><a name="note119943144912"></a><a name="note119943144912"></a><span class="notetitle"> NOTE: </span><div class="notebody"><p id="p49933104915"><a name="p49933104915"></a><a name="p49933104915"></a>If GCC 7.3.0 is installed in OSs such as CentOS 7.6, Debian, and BC-Linux, configure the related environment variables. For details, see <a href="#how-do-i-install-gcc-7-3-0md#en-us_topic_0000001146754749_en-us_topic_0000001072593337_l5e5c9395407d46439788b12f0e6342bc">5</a>.</p>
</div></div>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p187352744817"><a name="p187352744817"></a><a name="p187352744817"></a>Required</p>
</td>
</tr>
<tr id="row17342744812"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p4731227184818"><a name="p4731227184818"></a><a name="p4731227184818"></a>PATH</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p97310276484"><a name="p97310276484"></a><a name="p97310276484"></a>Executable program search path. Set this variable based on the preceding example.</p>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p1573142711483"><a name="p1573142711483"></a><a name="p1573142711483"></a>Required</p>
</td>
</tr>
<tr id="row95241840165613"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p15242404566"><a name="p15242404566"></a><a name="p15242404566"></a>ASCEND_DEVICE_ID</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p688447526"><a name="p688447526"></a><a name="p688447526"></a>Sets the logical ID of a processor.</p>
<p id="p178824712212"><a name="p178824712212"></a><a name="p178824712212"></a>The value range is [0, <em id="i18812110304"><a name="i18812110304"></a><a name="i18812110304"></a>N</em> – 1] and the default value is<strong id="b1381717104019"><a name="b1381717104019"></a><a name="b1381717104019"></a> 0</strong>. <em id="i1156411211703"><a name="i1156411211703"></a><a name="i1156411211703"></a>N</em> indicates the device count in the physical machine, VM, or container.</p>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p105245400562"><a name="p105245400562"></a><a name="p105245400562"></a>Optional</p>
</td>
</tr>
<tr id="row203705529819"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p53705522810"><a name="p53705522810"></a><a name="p53705522810"></a>ASCEND_SLOG_PRINT_TO_STDOUT</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001073203258_p763102116322"><a name="en-us_topic_0000001073203258_p763102116322"></a><a name="en-us_topic_0000001073203258_p763102116322"></a>Enables or disables log printing. Values:</p>
<a name="en-us_topic_0000001073203258_ul95291245104113"></a><a name="en-us_topic_0000001073203258_ul95291245104113"></a><ul id="en-us_topic_0000001073203258_ul95291245104113"><li><strong id="b1877191971104041"><a name="b1877191971104041"></a><a name="b1877191971104041"></a>0</strong> or not configured: disabled</li><li><strong id="b737654378104041"><a name="b737654378104041"></a><a name="b737654378104041"></a>1</strong>: enabled</li></ul>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p6370125217818"><a name="p6370125217818"></a><a name="p6370125217818"></a>Optional</p>
</td>
</tr>
<tr id="row188405280914"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p5840928594"><a name="p5840928594"></a><a name="p5840928594"></a>ASCEND_GLOBAL_LOG_LEVEL</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="en-us_topic_0000001073521184_p763102116322"><a name="en-us_topic_0000001073521184_p763102116322"></a><a name="en-us_topic_0000001073521184_p763102116322"></a>Sets the global log level. Values:</p>
<a name="en-us_topic_0000001073521184_u4d735da6e0494e55abbf5eb6aefe988d"></a><a name="en-us_topic_0000001073521184_u4d735da6e0494e55abbf5eb6aefe988d"></a><ul id="en-us_topic_0000001073521184_u4d735da6e0494e55abbf5eb6aefe988d"><li><strong id="b1731786453104041"><a name="b1731786453104041"></a><a name="b1731786453104041"></a>0</strong>: DEBUG</li><li><strong id="b758139838104041"><a name="b758139838104041"></a><a name="b758139838104041"></a>1</strong>: INFO</li><li><strong id="b539270545104041"><a name="b539270545104041"></a><a name="b539270545104041"></a>2</strong>: WARNING</li><li><strong id="b444623067104041"><a name="b444623067104041"></a><a name="b444623067104041"></a>3</strong>: ERROR</li><li><strong id="b1157662181104041"><a name="b1157662181104041"></a><a name="b1157662181104041"></a>4</strong>: NULL (no log output)</li><li>Other values: invalid</li></ul>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p6841928598"><a name="p6841928598"></a><a name="p6841928598"></a>Optional</p>
</td>
</tr>
<tr id="row17638114219104"><td class="cellrowborder" valign="top" width="46.75467546754676%" headers="mcps1.2.4.1.1 "><p id="p20638342191018"><a name="p20638342191018"></a><a name="p20638342191018"></a>TASK_QUEUE_ENABLE</p>
</td>
<td class="cellrowborder" valign="top" width="43.18431843184319%" headers="mcps1.2.4.1.2 "><p id="p126381842151019"><a name="p126381842151019"></a><a name="p126381842151019"></a>Enables or disables the task delivery in multi-thread mode. When this function is enabled, the training performance of the entire network is improved in most cases. Values:</p>
<a name="ul6194152711118"></a><a name="ul6194152711118"></a><ul id="ul6194152711118"><li><strong id="b166811333191713"><a name="b166811333191713"></a><a name="b166811333191713"></a>0</strong> or not configured: disabled</li><li><strong id="b3865153321914"><a name="b3865153321914"></a><a name="b3865153321914"></a>1</strong>: enabled</li></ul>
</td>
<td class="cellrowborder" valign="top" width="10.061006100610062%" headers="mcps1.2.4.1.3 "><p id="p86386423103"><a name="p86386423103"></a><a name="p86386423103"></a>Optional</p>
</td>
</tr>
</tbody>
</table>
>![](public_sys-resources/icon-note.gif) **NOTE:**
>For more log information, see the _CANN Log Reference_.
<h3 id="sample-referencemd">Sample Reference</h3>
#### Sample Code<a name="section2017032418274"></a>
Try to minimize the initialization frequency across the app lifetime during inference. The inference mode is set using the **model.eval\(\)** method, and the inference process must run under the code branch **with torch.no\_grad\(\):**.
The following uses Python code of the ResNet-50 network as an example for description.
**resnet50\_infer\_for\_pytorch.py** sample code:
```
import argparse
import os
import time
import torch
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
import torchvision.transforms as transforms
import torchvision.datasets as datasets
import torchvision.models as models
import torch.npu
from apex import amp
model_names = sorted(name for name in models.__dict__
if name.islower() and not name.startswith("__")
and callable(models.__dict__[name]))
def parse_args():
""" User-defined dataset path and model path """
parser = argparse.ArgumentParser(description='PyTorch ImageNet Training')
parser.add_argument('--data', metavar='DIR', default="/data/imagenet",
help='path to dataset')
parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet50',
choices=model_names,
help='model architecture: ' +
' | '.join(model_names) +
' (default: resnet18)')
parser.add_argument('--epochs', default=100, type=int, metavar='N',
help='number of total epochs to run')
parser.add_argument('-b', '--batch_size', default=512, type=int,
metavar='N',
help='mini-batch size (default: 256), this is the total '
'batch size of all GPUs on the current node when '
'using Data Parallel or Distributed Data Parallel')
parser.add_argument('--resume', default='', type=str, metavar='PATH',
help='path to latest checkpoint (default: none)')
parser.add_argument('--pretrained', dest='pretrained', action='store_true',
help='use pre-trained model')
parser.add_argument('--npu', default=None, type=int,
help='NPU id to use.')
parser.add_argument('-j', '--workers', default=32, type=int, metavar='N',
help='number of data loading workers (default: 8)')
parser.add_argument('--lr', '--learning_rate', default=0.1, type=float,
metavar='LR', help='initial learning rate', dest='lr')
parser.add_argument('--wd', '--weight_decay', default=1e-4, type=float,
metavar='W', help='weight decay (default: 1e-4)',
dest='weight_decay')
args, unknown_args = parser.parse_known_args()
if len(unknown_args) > 0:
for bad_arg in unknown_args:
print("ERROR: Unknown command line arg: %s" % bad_arg)
raise ValueError("Invalid command line arg(s)")
return args
# =========================================================================
# Main function entry
# =========================================================================
def main():
args = parse_args()
if args.npu is None:
args.npu = 0
global CALCULATE_DEVICE
CALCULATE_DEVICE = "npu:{}".format(args.npu)
torch.npu.set_device(CALCULATE_DEVICE)
print("use ", CALCULATE_DEVICE)
main_worker(args.npu, args)
def main_worker(npu, args):
global best_acc1
args.npu = npu
# =========================================================================
# Create a model.
# =========================================================================
print("=> creating model '{}'".format(args.arch))
model = models.__dict__[args.arch](zero_init_residual=True)
# Copy the model data to the Ascend AI Processor.
model = model.to(CALCULATE_DEVICE)
optimizer = torch.optim.SGD([
{'params': [param for name, param in model.named_parameters() if name[-4:] == 'bias'], 'weight_decay': 0.0},
{'params': [param for name, param in model.named_parameters() if name[-4:] != 'bias'],
'weight_decay': args.weight_decay}],
args.lr)
# =========================================================================
# Initialize the mixed precision model. After the model is used, the calculation can be accelerated, but the accuracy may slightly decrease. Determine whether to use the model based on the actual scenario.
# =========================================================================
model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1)
# =========================================================================
# Load the trained model parameters.
# =========================================================================
# Restore model parameters from the model file.
if os.path.isfile(args.resume):
print("=> loading checkpoint '{}'".format(args.resume))
checkpoint = torch.load(args.resume)
best_acc1 = checkpoint['best_acc1']
best_acc1 = best_acc1.to("npu:{}".format(args.npu))
model.load_state_dict(checkpoint['state_dict'])
print("=> loaded checkpoint '{}' (epoch {})".format(args.resume, checkpoint['epoch']))
else:
print("=> no checkpoint found at '{}'".format(args.resume))
# =========================================================================
# Initialize the database.
# =========================================================================
# Load and preprocess image data.
valdir = os.path.join(args.data, 'val')
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
val_loader = torch.utils.data.DataLoader(
datasets.ImageFolder(valdir, transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
normalize,
])),
batch_size=args.batch_size, shuffle=True,
num_workers=args.workers, pin_memory=True)
# =========================================================================
# Run the validate command.
# =========================================================================
validate(val_loader, model, args)
# =========================================================================
# Implement the sample API for online inference.
# =========================================================================
def validate(val_loader, model, args):
batch_time = AverageMeter('Time', ':6.3f')
top1 = AverageMeter('Acc@1', ':6.2f')
top5 = AverageMeter('Acc@5', ':6.2f')
progress = ProgressMeter(
len(val_loader),
[batch_time, top1, top5],
prefix='Test: ')
# =========================================================================
# Switch to the inference mode.
# =========================================================================
model.eval()
# =========================================================================
# Execute the model forward propagation under the torch.no_grad(): branch.
# =========================================================================
with torch.no_grad():
end = time.time()
for i, (images, target) in enumerate(val_loader):
# Place the image data on the NPU.
images = images.to(CALCULATE_DEVICE, non_blocking=True)
target = target.to(torch.int32).to(CALCULATE_DEVICE, non_blocking=True)
# Calculate the output.
output = model(images)
# Collect statistics on result precisions.
acc1, acc5 = accuracy(output, target, topk=(1, 5))
top1.update(acc1[0], images.size(0))
top5.update(acc5[0], images.size(0))
# Measure the running time.
batch_time.update(time.time() - end)
end = time.time()
# Print inference logs.
progress.display(i)
print(' * Acc@1 {top1.avg:.3f} Acc@5 {top5.avg:.3f}'.format(top1=top1, top5=top5))
return top1.avg
class AverageMeter(object):
"""Calculate and store the average value and current value."""
def __init__(self, name, fmt=':f'):
self.name = name
self.fmt = fmt
self.reset()
self.start_count_index = 10
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
def update(self, val, n=1):
if self.count == 0:
self.batchsize = n
self.val = val
self.count += n
if self.count > (self.start_count_index * self.batchsize):
self.sum += val * n
self.avg = self.sum / (self.count - self.start_count_index * self.batchsize)
def __str__(self):
fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})'
return fmtstr.format(**self.__dict__)
class ProgressMeter(object):
"""Record model computing information."""
def __init__(self, num_batches, meters, prefix=""):
self.batch_fmtstr = self._get_batch_fmtstr(num_batches)
self.meters = meters
self.prefix = prefix
def display(self, batch):
entries = [self.prefix + self.batch_fmtstr.format(batch)]
entries += [str(meter) for meter in self.meters]
print('\t'.join(entries))
def _get_batch_fmtstr(self, num_batches):
num_digits = len(str(num_batches // 1))
fmt = '{:' + str(num_digits) + 'd}'
return '[' + fmt + '/' + fmt.format(num_batches) + ']'
def accuracy(output, target, topk=(1,)):
"""Calculate the precision of k top predictions based on the specified value k."""
with torch.no_grad():
maxk = max(topk)
batch_size = target.size(0)
_, pred = output.topk(maxk, 1, True, True)
pred = pred.t()
correct = pred.eq(target.view(1, -1).expand_as(pred))
res = []
for k in topk:
correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)
res.append(correct_k.mul_(100.0 / batch_size))
return res
if __name__ == '__main__':
main()
```
#### Sample Running<a name="section340764716270"></a>
The following uses the ResNet-50 model as an example to describe how to perform online inference.
1. Download a pre-trained model.
Visit [Ascend ModelZoo](https://www.hiascend.com/en/software/modelzoo) and click **Download Model** to download a pre-trained ResNet-50 model.
2. Edit the inference script.
Create a model script file **resnet50\_infer\_for\_pytorch.py** and write code by referring to [Sample Code]().
3. Run inference.
Set environment variables by referring to [Environment Variable Configuration](#environment-variable-configurationmd) and then run the following command:
```
python3 pytorch-resnet50-apex.py --data /data/imagenet \
--npu 7 \
--epochs 90 \
--resume ./checkpoint.pth.tar # ./checkpoint.pth.tar is the path of the sample pre-trained model file.
```
>![](public_sys-resources/icon-note.gif) **NOTE:**
>The preceding command is an example only. Modify the arguments as needed.
<h2 id="special-topicsmd">Special Topics</h2>
- **[Mixed Precision](#mixed-precisionmd)**
<h3 id="mixed-precisionmd">Mixed Precision</h3>
#### Overview<a name="section14734122962615"></a>
Based on the architecture features of the NPU, mixed precision is involved in the model computing, that is, the scenario where the float16 and float32 data types are used together. Replacing float32 with float16 has the following advantages:
- The memory usage of intermediate variables is reduced.
- The data transfer time decreases because the memory usage is reduced.
- The compute units of float16 provide better computing performance.
However, the mixed precision training is limited by the precision range expressed by float16. If float32 is converted into float16, the training convergence is affected. To use float16 for acceleration in some computations and ensure training convergence, the mixed precision module Apex is used. The mixed precision module Apex is a comprehensive optimization library that features high optimization performance and precision.
#### Supported Features<a name="section175201458521"></a>
[Table 1](#en-us_topic_0278765773_table10717173813332) describes the functions and optimization of the mixed precision module.
**Table 1** Functions of the mixed precision module
<a name="en-us_topic_0278765773_table10717173813332"></a>
<table><thead align="left"><tr id="en-us_topic_0278765773_row371716385333"><th class="cellrowborder" valign="top" width="32.269999999999996%" id="mcps1.2.3.1.1"><p id="en-us_topic_0278765773_p13717163815333"><a name="en-us_topic_0278765773_p13717163815333"></a><a name="en-us_topic_0278765773_p13717163815333"></a>Function</p>
</th>
<th class="cellrowborder" valign="top" width="67.73%" id="mcps1.2.3.1.2"><p id="en-us_topic_0278765773_p14400173910345"><a name="en-us_topic_0278765773_p14400173910345"></a><a name="en-us_topic_0278765773_p14400173910345"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="en-us_topic_0278765773_row1571763813334"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p4502732153412"><a name="en-us_topic_0278765773_p4502732153412"></a><a name="en-us_topic_0278765773_p4502732153412"></a>O1 configuration</p>
</td>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p640053920348"><a name="en-us_topic_0278765773_p640053920348"></a><a name="en-us_topic_0278765773_p640053920348"></a>Conv and Matmul use float16 for computing, and Softmax and BN use float32.</p>
</td>
</tr>
<tr id="en-us_topic_0278765773_row3717173817336"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p11503103210344"><a name="en-us_topic_0278765773_p11503103210344"></a><a name="en-us_topic_0278765773_p11503103210344"></a>O2 configuration</p>
</td>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p164001639143419"><a name="en-us_topic_0278765773_p164001639143419"></a><a name="en-us_topic_0278765773_p164001639143419"></a>BN uses float32, and others use float16.</p>
</td>
</tr>
<tr id="en-us_topic_0278765773_row14717193815334"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p1950318328349"><a name="en-us_topic_0278765773_p1950318328349"></a><a name="en-us_topic_0278765773_p1950318328349"></a>Static loss scale</p>
</td>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p1440033983418"><a name="en-us_topic_0278765773_p1440033983418"></a><a name="en-us_topic_0278765773_p1440033983418"></a>Parameters are statically set to ensure the convergence of mixed precision training.</p>
</td>
</tr>
<tr id="en-us_topic_0278765773_row871733813317"><td class="cellrowborder" valign="top" width="32.269999999999996%" headers="mcps1.2.3.1.1 "><p id="en-us_topic_0278765773_p1550303243417"><a name="en-us_topic_0278765773_p1550303243417"></a><a name="en-us_topic_0278765773_p1550303243417"></a>Dynamic loss scale</p>
</td>
<td class="cellrowborder" valign="top" width="67.73%" headers="mcps1.2.3.1.2 "><p id="en-us_topic_0278765773_p15400143963412"><a name="en-us_topic_0278765773_p15400143963412"></a><a name="en-us_topic_0278765773_p15400143963412"></a>The loss scale value is dynamically calculated to determine whether overflow occurs.</p>
</td>
</tr>
</tbody>
</table>
>![](public_sys-resources/icon-note.gif) **NOTE:**
>In the current version, Apex is implemented using Python and does not support AscendCL or CUDA optimization.
#### Initializing the Mixed Precision Model<a name="section18178125518268"></a>
1. To use the mixed precision module Apex, you need to import the amp module from the Apex library as follows:
```
from apex import amp
```
2. After the amp module is imported, you need to initialize it so that it can modify the model, optimizer, and PyTorch internal functions. The initialization code is as follows:
```
model, optimizer = amp.initialize(model, optimizer)
```
For details, see "Initialize the mixed precision model."# in [Sample Code](#sample-referencemd).
```
model, optimizer = amp.initialize(model, optimizer, opt_level="O2", loss_scale=1024, verbosity=1)
```
#### Mixed Precision Inference<a name="section818071513288"></a>
After the mixed precision model is initialized, perform model forward propagation.
Sample code: For details, see the implementation of **validate\(val\_loader, model, args\)** in [Sample Code](#sample-referencemd).
<h2 id="how-do-i-install-gcc-7-3-0md">How Do I Install GCC 7.3.0?</h2>
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. To install GCC, you need to reserve adequate temporary space. Run the following command to clear the **/tmp** directory before the installation:
```
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. Build and install GCC.
1. Go to the directory where the source code package **gcc-7.3.0.tar.gz** is located and run the following command to extract it:
```
tar -zxvf gcc-7.3.0.tar.gz
```
2. Go to the extracted directory and run the following command to 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 downloading the preceding dependency packages, run the following command:
```
./contrib/download_prerequisites
```
If the verification fails, check whether the dependency package is repeatedly downloaded. The package should be downloaded at a time.
3. <a name="en-us_topic_0000001146754749_en-us_topic_0000001072593337_l75d31a2874534a2092e80a5f865b46f0"></a>Run the following commands for configuration, build, and installation.
```
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0
make -j15 # The value 15 indicates the number of CPUs, which is configurable and can be queried by running grep -w processor /proc/cpuinfo|wc -l.
make install
```
>![](public_sys-resources/icon-notice.gif) **NOTICE:**
>The **--prefix** parameter 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**.
5. Set the environment variable.
The build environment after GCC upgrade is required for training. Therefore, you need to configure the following environment variable in the 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.](#en-us_topic_0000001146754749_en-us_topic_0000001072593337_l75d31a2874534a2092e80a5f865b46f0). In this example, the GCC 7.3.0 installation path is **/usr/local/linux\_gcc7.3.0/**.
>![](public_sys-resources/icon-note.gif) **NOTE:**
>The environment variable needs to be configured only when you need to use the build environment after the GCC upgrade.
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

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