From 0bea88315f9ca098fce2e31c50fa8445ec2cdc74 Mon Sep 17 00:00:00 2001 From: cai-weiwei1989 <734267852@qq.com> Date: Thu, 23 May 2024 17:50:51 +0800 Subject: [PATCH 1/6] =?UTF-8?q?[compare=5Ftools]=E9=80=82=E9=85=8DMindSpor?= =?UTF-8?q?e=E5=9C=BA=E6=99=AF=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- profiler/compare_tools/README.md | 58 ++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/profiler/compare_tools/README.md b/profiler/compare_tools/README.md index 16eaeaccd7..855eceac8d 100644 --- a/profiler/compare_tools/README.md +++ b/profiler/compare_tools/README.md @@ -8,6 +8,8 @@ compare_tools(性能比对工具)支持比较GPU与NPU之间、NPU与NPU之 场景二:PyTorch训练工程在NPU上,不同版本之间存在性能差距,通过工具定位具体差异。 +场景三:PyTorch训练工程从GPU迁移至MindSpore NPU后出现性能劣化,通过工具分析出劣化点。 + ## 使用指导 ### 环境依赖 @@ -21,7 +23,7 @@ pip3 install pandas pip3 install numpy ``` -### 性能数据采集 +### PyTorch框架性能数据采集 使用本工具之前需要采集GPU或者NPU的性能数据,然后进行性能比对分析。 @@ -32,11 +34,11 @@ pip3 install numpy 采集样例代码参考一: ```Python -with torch_npu.profiler.profile( +with torch.profiler.profile( profile_memory=True, # 内存数据采集的开关 record_shapes=True, # 算子input shape信息采集的开关 - schedule=torch_npu.profiler.schedule(wait=10, warmup=0, active=1, repeat=1), - on_trace_ready=torch_npu.profiler.tensorboard_trace_handler("./result_dir") + schedule=torch.profiler.schedule(wait=10, warmup=0, active=1, repeat=1), + on_trace_ready=torch.profiler.tensorboard_trace_handler("./result_dir") ) as prof: for step in ranges(step_number): train_one_step() @@ -46,10 +48,10 @@ with torch_npu.profiler.profile( 采集样例代码参考二: ```Python -prof = torch_npu.profiler.profile( +prof = torch.profiler.profile( profile_memory=True, # 内存数据采集的开关 record_shapes=True, # 算子input shape信息采集的开关 - on_trace_ready=torch_npu.profiler.tensorboard_trace_handler("./result_dir")) + on_trace_ready=torch.profiler.tensorboard_trace_handler("./result_dir")) for step in range(step_number): if step == 11: prof.start() @@ -58,7 +60,7 @@ for step in range(step_number): prof.stop() ``` -pytorch profiler数据目录结构如下: +PyTorch Profiler采集结果数据目录结构如下: ```Python |- pytorch_profiling @@ -66,13 +68,12 @@ pytorch profiler数据目录结构如下: ``` #### NPU性能数据采集 -通过Ascend PyTorch Profiler工具(与PyTorch Profiler工具对标)采集NPU的性能数据,采集参数配置跟GPU一致,具体可以参考链接:[Profiling数据采集](https://gitee.com/ascend/att/tree/master/profiler)。 -将GPU的性能数据采集代码中torch.profiler替换成torch_npu.profiler。 +通过Ascend PyTorch Profiler工具采集NPU的性能数据,采集参数配置与GPU基本一致,只需将GPU的性能数据采集代码中torch.profiler替换成torch_npu.profiler。,参考链接:[Profiling数据采集](https://gitee.com/ascend/att/tree/master/profiler)。 -ascend pytorch profiler数据目录结构如下: +Ascend PyTorch Profiler采集结果数据目录结构如下: -``` +```bash |- ascend_pytorch_profiling |- * _ascend_pt |- ASCEND_PROFILER_OUTPUT @@ -82,6 +83,23 @@ ascend pytorch profiler数据目录结构如下: |- * _ascend_pt ``` +### MindSpore框架性能数据采集 + +#### NPU性能数据采集 + +当前MindSpore场景仅支持采集NPU环境性能数据,与PyTorch GPU性能数据进行比对。 + +通过MindSpore性能调试工具采集NPU的性能数据,参考链接:[性能调试(Ascend)](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.3/performance_profiling_ascend.html)。 + +MindSpore性能调试工具采集结果数据目录结构如下: + +``` +|- profiler/{rank-*}_{timestamps}_ascend_ms + |- ASCEND_PROFILER_OUTPUT + |- kernel_details.csv + |- trace_view.json +``` + ### 性能数据比对 性能比对工具将总体性能拆解为训练耗时和内存占用,其中训练耗时可拆分为算子(包括算子和nn.Module)、通信、调度三个维度,以打屏的形式输出总体指标,帮助用户定界劣化的方向。与此同时,工具还会生成performance_comparison_result_*.xlsx,展示每个算子在执行耗时、通信耗时、内存占用的优劣,可通过DIFF列大于0筛选出劣化算子。详细介绍请参见“**比对结果说明**”。 @@ -119,12 +137,12 @@ python performance_compare.py [基准性能数据文件所在路径] [比对性 #### 通用参数说明 -| 参数名 | 说明 | 是否必选 | -|--------------------------------|-----------|------| -| --enable_profiling_compare | 开启总体性能比对。 | 否 | -| --enable_operator_compare | 开启算子性能比对。 | 否 | -| --enable_communication_compare | 开启通信性能比对。 | 否 | -| --enable_memory_compare | 开启算子内存比对。 | 否 | +| 参数名 | 说明 | 是否必选 | +| ------------------------------ | ----------------------------------------- | -------- | +| --enable_profiling_compare | 开启总体性能比对。 | 否 | +| --enable_operator_compare | 开启算子性能比对。MindSpore场景暂不支持。 | 否 | +| --enable_communication_compare | 开启通信性能比对。 | 否 | +| --enable_memory_compare | 开启算子内存比对。MindSpore场景暂不支持。 | 否 | 说明:以上4个开关均不设置的情况下,**工具默认开启所有的性能比对**,当用户设置了以上开关,则按照用户设置的开关进行性能比对,示例如下: @@ -151,6 +169,8 @@ python performance_compare.py [基准性能数据文件] [比对性能数据文 ## 比对结果说明 +MindSpore场景仅支持**总体性能**和**通信性能**的对比。 + ### 总体性能 总体性能比对结果以打屏的形式呈现。 @@ -192,6 +212,8 @@ activities配置仅采集NPU数据,不配置experimental_config参数以及其 ### 算子性能 +MindSpore场景暂不支持。 + #### 比对数据无Python Function 算子性能比对结果在performance_comparison_result_*.xlsx中OperatorCompare和OperatorCompareStatistic的sheet页呈现。 @@ -259,6 +281,8 @@ ModuleCompare:模块及模块下算子比对的明细展示,可以查看每 ### 算子内存 +MindSpore场景暂不支持。 + 算子内存比对结果在performance_comparison_result_*.xlsx中MemoryCompare和MemoryCompareStatistic的sheet页呈现。 - MemoryCompareStatistic:算子为粒度的统计呈现,按照算子占用的总内存与基准算子的差距值(Diff Memory(MB))进行逆序。 -- Gitee From 27bf084389e8fd9859d82aee817976b4cc9f36d7 Mon Sep 17 00:00:00 2001 From: cai-weiwei1989 <734267852@qq.com> Date: Thu, 23 May 2024 17:52:55 +0800 Subject: [PATCH 2/6] =?UTF-8?q?[compare=5Ftools]=E9=80=82=E9=85=8DMindSpor?= =?UTF-8?q?e=E5=9C=BA=E6=99=AF=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- profiler/compare_tools/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiler/compare_tools/README.md b/profiler/compare_tools/README.md index 855eceac8d..afeba1076b 100644 --- a/profiler/compare_tools/README.md +++ b/profiler/compare_tools/README.md @@ -6,7 +6,7 @@ compare_tools(性能比对工具)支持比较GPU与NPU之间、NPU与NPU之 场景一:PyTorch训练工程从GPU迁移至NPU后出现性能劣化,通过工具分析出劣化点。 -场景二:PyTorch训练工程在NPU上,不同版本之间存在性能差距,通过工具定位具体差异。 +场景二:PyTorch或MindSpore训练工程在NPU上,不同版本之间存在性能差距,通过工具定位具体差异。 场景三:PyTorch训练工程从GPU迁移至MindSpore NPU后出现性能劣化,通过工具分析出劣化点。 -- Gitee From 3788f8f7324bcaba1c6af70628a731a0037f0379 Mon Sep 17 00:00:00 2001 From: cai-weiwei1989 <734267852@qq.com> Date: Thu, 23 May 2024 17:56:47 +0800 Subject: [PATCH 3/6] =?UTF-8?q?[compare=5Ftools]=E9=80=82=E9=85=8DMindSpor?= =?UTF-8?q?e=E5=9C=BA=E6=99=AF=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- profiler/compare_tools/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiler/compare_tools/README.md b/profiler/compare_tools/README.md index afeba1076b..ee214ea36c 100644 --- a/profiler/compare_tools/README.md +++ b/profiler/compare_tools/README.md @@ -87,7 +87,7 @@ Ascend PyTorch Profiler采集结果数据目录结构如下: #### NPU性能数据采集 -当前MindSpore场景仅支持采集NPU环境性能数据,与PyTorch GPU性能数据进行比对。 +当前MindSpore场景仅支持采集NPU环境性能数据,与PyTorch GPU性能数据进行比对;以及MindSpore训练工程在NPU上,不同版本之间的性能数据进行比对。 通过MindSpore性能调试工具采集NPU的性能数据,参考链接:[性能调试(Ascend)](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.3/performance_profiling_ascend.html)。 -- Gitee From e6c88d9ddc6bcf89b0fda122e635974f33c933e3 Mon Sep 17 00:00:00 2001 From: cai-weiwei1989 <734267852@qq.com> Date: Thu, 23 May 2024 18:18:17 +0800 Subject: [PATCH 4/6] =?UTF-8?q?[compare=5Ftools]=E9=80=82=E9=85=8DMindSpor?= =?UTF-8?q?e=E5=9C=BA=E6=99=AF=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- profiler/compare_tools/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/profiler/compare_tools/README.md b/profiler/compare_tools/README.md index ee214ea36c..0b9e8f918f 100644 --- a/profiler/compare_tools/README.md +++ b/profiler/compare_tools/README.md @@ -87,7 +87,7 @@ Ascend PyTorch Profiler采集结果数据目录结构如下: #### NPU性能数据采集 -当前MindSpore场景仅支持采集NPU环境性能数据,与PyTorch GPU性能数据进行比对;以及MindSpore训练工程在NPU上,不同版本之间的性能数据进行比对。 +当前MindSpore场景仅支持NPU环境性能数据与PyTorch GPU性能数据进行比对;以及MindSpore训练工程在NPU上,不同版本之间的性能数据进行比对。 通过MindSpore性能调试工具采集NPU的性能数据,参考链接:[性能调试(Ascend)](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.3/performance_profiling_ascend.html)。 @@ -100,6 +100,8 @@ MindSpore性能调试工具采集结果数据目录结构如下: |- trace_view.json ``` +进行性能比对时,MindSpore采集的性能数据须指定到`profiler/{rank-*}_{timestamps}_ascend_ms`或`ASCEND_PROFILER_OUTPUT`层级。 + ### 性能数据比对 性能比对工具将总体性能拆解为训练耗时和内存占用,其中训练耗时可拆分为算子(包括算子和nn.Module)、通信、调度三个维度,以打屏的形式输出总体指标,帮助用户定界劣化的方向。与此同时,工具还会生成performance_comparison_result_*.xlsx,展示每个算子在执行耗时、通信耗时、内存占用的优劣,可通过DIFF列大于0筛选出劣化算子。详细介绍请参见“**比对结果说明**”。 -- Gitee From 2e388678c60084acb71903f0c9466f1b5102de39 Mon Sep 17 00:00:00 2001 From: cai-weiwei1989 <734267852@qq.com> Date: Sat, 25 May 2024 18:47:39 +0800 Subject: [PATCH 5/6] =?UTF-8?q?[profiler]=E8=BF=AD=E4=BB=A3=E4=B8=89?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E5=8C=85=E5=90=88=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- profiler/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/profiler/README.md b/profiler/README.md index e297e1e128..661a7c3c25 100644 --- a/profiler/README.md +++ b/profiler/README.md @@ -91,6 +91,7 @@ ascend pytorch profiler数据目录结构如下: | profiler版本 | 发布日期 | 下载链接 | 校验码 | | ------------ | ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ | + | 1.1.T1 | 2024-05-25 | [msprof_analyze-1.1.T1-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/profiler/package/1.1.T1/msprof_analyze-1.1.T1-py3-none-any.whl) | d49890a6452bd584e9135ca2fb89354e1460393aed3d910bfc6db3d9a2cd1def | | 1.0 | 2024-05-10 | [msprof_analyze-1.0-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/profiler/package/1.0/msprof_analyze-1.0-py3-none-any.whl) | bcded626f639cea32ba814f88cbc563b48609d2c832a9f9b12c455c0626137ed | -- Gitee From 3c110a91f24f985540c015e127ad3c7617807853 Mon Sep 17 00:00:00 2001 From: cai-weiwei1989 <734267852@qq.com> Date: Sat, 25 May 2024 18:50:17 +0800 Subject: [PATCH 6/6] =?UTF-8?q?[profiler]=E8=BF=AD=E4=BB=A3=E4=B8=89?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E5=8C=85=E5=90=88=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- profiler/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiler/README.md b/profiler/README.md index 661a7c3c25..314606cb08 100644 --- a/profiler/README.md +++ b/profiler/README.md @@ -92,7 +92,7 @@ ascend pytorch profiler数据目录结构如下: | profiler版本 | 发布日期 | 下载链接 | 校验码 | | ------------ | ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | 1.1.T1 | 2024-05-25 | [msprof_analyze-1.1.T1-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/profiler/package/1.1.T1/msprof_analyze-1.1.T1-py3-none-any.whl) | d49890a6452bd584e9135ca2fb89354e1460393aed3d910bfc6db3d9a2cd1def | - | 1.0 | 2024-05-10 | [msprof_analyze-1.0-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/profiler/package/1.0/msprof_analyze-1.0-py3-none-any.whl) | bcded626f639cea32ba814f88cbc563b48609d2c832a9f9b12c455c0626137ed | + | 1.0 | 2024-05-10 | [msprof_analyze-1.0-py3-none-any.whl](https://ptdbg.obs.myhuaweicloud.com/profiler/package/1.0/msprof_analyze-1.0-py3-none-any.whl) | 95b2f41c8c8e8afe4887b738c8cababcb4f412e1874483b6adae4a025fcbb7d4 | -- Gitee