From 0853edec1daf40288e7cb1f656f23de7c546bfb4 Mon Sep 17 00:00:00 2001 From: lvmingfu Date: Wed, 24 Mar 2021 10:13:56 +0800 Subject: [PATCH 01/11] modify code formats in operators.ipynb for master --- .../source_zh_cn/operators.ipynb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/programming_guide/source_zh_cn/operators.ipynb b/docs/programming_guide/source_zh_cn/operators.ipynb index d0fe36ca05..7908a4b292 100644 --- a/docs/programming_guide/source_zh_cn/operators.ipynb +++ b/docs/programming_guide/source_zh_cn/operators.ipynb @@ -891,8 +891,13 @@ "[ 1.12317121e+00 8.98950577e-01 4.22795087e-01]\n", "[ 5.13781667e-01 5.12095273e-01 -3.68211865e-01]\n", "[-7.04941899e-02 -1.09924078e+00 6.89047515e-01]]]]\n", - "```\n", - "\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "> 以上代码运行于MindSpore的Ascend版本。" ] }, @@ -1069,9 +1074,9 @@ ], "metadata": { "kernelspec": { - "display_name": "MindSpore-1.1.1", + "display_name": "Python 3", "language": "python", - "name": "mindspore-1.1.1" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -1083,7 +1088,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.5" + "version": "3.7.6" } }, "nbformat": 4, -- Gitee From 1e9cc4ca1702093ab279436241201be2ce1e15fb Mon Sep 17 00:00:00 2001 From: panfei Date: Tue, 23 Mar 2021 18:26:13 +0800 Subject: [PATCH 02/11] modify error links --- docs/migration_guide/source_zh_cn/script_development.md | 2 +- docs/note/source_en/env_var_list.md | 2 +- docs/note/source_zh_cn/env_var_list.md | 2 +- docs/programming_guide/source_en/numpy.md | 2 +- docs/programming_guide/source_zh_cn/numpy.md | 2 +- tutorials/training/source_en/advanced_use/summary_record.md | 4 ++-- .../training/source_zh_cn/advanced_use/summary_record.md | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/migration_guide/source_zh_cn/script_development.md b/docs/migration_guide/source_zh_cn/script_development.md index 37f30aea4d..161dc0d11d 100644 --- a/docs/migration_guide/source_zh_cn/script_development.md +++ b/docs/migration_guide/source_zh_cn/script_development.md @@ -444,7 +444,7 @@ return out ``` - PyTorch和MindSpore在一些基础API的定义上比较相似,比如[mindspore.nn.SequentialCell](https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/nn/mindspore.nn.SequentialCell.html?highlight=sequentialcell#mindspore.nn.SequentialCell)和[torch.nn.Sequential](https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html?highlight=sequential#torch.nn.Sequential),另外,一些算子API可能不尽相同,此处列举一些常见的API对照,更多信息可以参考MindSpore官网的[算子列表](https://www.mindspore.cn/doc/note/zh-CN/master/index.html#operator_api)。 + PyTorch和MindSpore在一些基础API的定义上比较相似,比如[mindspore.nn.SequentialCell](https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/nn/mindspore.nn.SequentialCell.html#mindspore.nn.SequentialCell)和[torch.nn.Sequential](https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html#torch.nn.Sequential),另外,一些算子API可能不尽相同,此处列举一些常见的API对照,更多信息可以参考MindSpore官网的[算子列表](https://www.mindspore.cn/doc/note/zh-CN/master/index.html#operator_api)。 | PyTorch | MindSpore | | :-------------------------------: | :------------------------------------------------: | diff --git a/docs/note/source_en/env_var_list.md b/docs/note/source_en/env_var_list.md index fb165950d8..cf02804fdf 100644 --- a/docs/note/source_en/env_var_list.md +++ b/docs/note/source_en/env_var_list.md @@ -21,7 +21,7 @@ MindSpore environment variables are as follows: |RANK_TABLE_FILE|MindSpore|Specifies the file to which a path points, including `DEVICE_IP`s corresponding to multiple Ascend AI Processor `DEVICE_ID`s. |String|File path, which can be a relative path or an absolute path.|This variable is used together with RANK_SIZE. |Mandatory (when the Ascend AI Processor is used)| |RANK_SIZE|MindSpore|Specifies the number of Ascend AI Processors to be called during deep learning. |Integer|The number of Ascend AI Processors to be called ranges from 1 to 8. | This variable is used together with RANK_TABLE_FILE |Mandatory (when the Ascend AI Processor is used) | |RANK_ID|MindSpore|Specifies the logical ID of the Ascend AI Processor called during deep learning.|Integer|The value ranges from 0 to 7. When multiple servers are running concurrently, `DEVICE_ID`s in different servers may be the same. RANK_ID can be used to avoid this problem. (RANK_ID = SERVER_ID * DEVICE_NUM + DEVICE_ID) |None|Optional| -|MS_SUBMODULE_LOG_v|MindSpore| For details about the function and usage, see [MS_SUBMODULE_LOG_v](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/custom_debugging_info.html?highlight=ms_submodule_log_v#log-related-environment-variables-and-configurations)|Dict{String:Integer...}|LogLevel: 0-DEBUG, 1-INFO, 2-WARNING, 3-ERROR
SubModual: COMMON, MD, DEBUG, DEVICE, COMMON, IR...|None | Optional +|MS_SUBMODULE_LOG_v|MindSpore| For details about the function and usage, see [MS_SUBMODULE_LOG_v](https://www.mindspore.cn/tutorial/training/en/master/advanced_use/custom_debugging_info.html#log-related-environment-variables-and-configurations)|Dict{String:Integer...}|LogLevel: 0-DEBUG, 1-INFO, 2-WARNING, 3-ERROR
SubModual: COMMON, MD, DEBUG, DEVICE, COMMON, IR...|None | Optional |OPTION_PROTO_LIB_PATH|MindSpore|Specifies the RPOTO dependent library path. |String|File path, which can be a relative path or an absolute path.|None|Optional| |MS_RDR_ENABLE|MindSpore|Determines whether to enable running data recorder (RDR). If a running exception occurs in MindSpore, the pre-recorded data in MindSpore is automatically exported to assist in locating the cause of the running exception.|Integer|1:enables RDR
0:disables RDR|This variable is used together with MS_RDR_PATH|Optional| |MS_RDR_PATH|MindSpore|Specifies the system path for storing the data recorded by running data recorder (RDR).|String|Directory path, which should be an absolute path.|This variable is used together with MS_RDR_ENABLE=1|Optional| diff --git a/docs/note/source_zh_cn/env_var_list.md b/docs/note/source_zh_cn/env_var_list.md index ffb92090f5..cc869957e6 100644 --- a/docs/note/source_zh_cn/env_var_list.md +++ b/docs/note/source_zh_cn/env_var_list.md @@ -21,7 +21,7 @@ |RANK_TABLE_FILE|MindSpore|路径指向文件,包含指定多Ascend AI处理器环境中Ascend AI处理器的"device_id"对应的"device_ip"。|String|文件路径,支持相对路径与绝对路径|与RANK_SIZE配合使用|必选(使用Ascend AI处理器时)| |RANK_SIZE|MindSpore|指定深度学习时调用Ascend AI处理器的数量|Integer|1~8,调用Ascend AI处理器的数量|与RANK_TABLE_FILE配合使用|必选(使用Ascend AI处理器时)| |RANK_ID|MindSpore|指定深度学习时调用Ascend AI处理器的逻辑ID|Integer|0~7,多机并行时不同server中DEVICE_ID会有重复,使用RANK_ID可以避免这个问题(多机并行时 RANK_ID = SERVER_ID * DEVICE_NUM + DEVICE_ID|无|可选| -|MS_SUBMODULE_LOG_v|MindSpore|[MS_SUBMODULE_LOG_v功能与用法]()|Dict{String:Integer...}|LogLevel: 0-DEBUG, 1-INFO, 2-WARNING, 3-ERROR
SubModual: COMMON, MD, DEBUG, DEVICE, COMMON, IR...|无|可选 +|MS_SUBMODULE_LOG_v|MindSpore|[MS_SUBMODULE_LOG_v功能与用法](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/custom_debugging_info.html#id9)|Dict{String:Integer...}|LogLevel: 0-DEBUG, 1-INFO, 2-WARNING, 3-ERROR
SubModual: COMMON, MD, DEBUG, DEVICE, COMMON, IR...|无|可选 |OPTION_PROTO_LIB_PATH|MindSpore|RPOTO依赖库库路径|String|目录路径,支持相对路径与绝对路径|无|可选| |MS_RDR_ENABLE|MindSpore|是否开启程序运行数据记录器(RDR),如果MindSpore出现了运行异常,会自动导出MindSpore中预先记录的数据以辅助定位运行异常的原因|Integer|1:开启RDR功能
0:关闭RDR功能|与MS_RDR_PATH一起使用|可选| |MS_RDR_PATH|MindSpore|配置程序运行数据记录器(RDR)的文件导出路径|String|文件路径,仅支持绝对路径|与MS_RDR_ENABLE=1一起使用|可选| diff --git a/docs/programming_guide/source_en/numpy.md b/docs/programming_guide/source_en/numpy.md index dfeed88c32..37615b559b 100644 --- a/docs/programming_guide/source_en/numpy.md +++ b/docs/programming_guide/source_en/numpy.md @@ -362,7 +362,7 @@ from mindspore import ms_function forward_compiled = ms_function(forward) ``` -> Currently, static graph cannot run in command line mode and not all python types can be passed into functions decorated with `ms_function`. For details about the static graph syntax support, see [Syntax Support](https://www.mindspore.cn/doc/note/en/master/static_graph_syntax_support.html). For details about how to use `ms_function`, see [API: ms_function](https://www.mindspore.cn/doc/api_python/en/master/mindspore/mindspore.html?highlight=ms_function#mindspore.ms_function). +> Currently, static graph cannot run in command line mode and not all python types can be passed into functions decorated with `ms_function`. For details about the static graph syntax support, see [Syntax Support](https://www.mindspore.cn/doc/note/en/master/static_graph_syntax_support.html). For details about how to use `ms_function`, see [API: ms_function](https://www.mindspore.cn/doc/api_python/en/master/mindspore/mindspore.html#mindspore.ms_function). ### Use GradOperation to compute deratives diff --git a/docs/programming_guide/source_zh_cn/numpy.md b/docs/programming_guide/source_zh_cn/numpy.md index 51b2193677..a3caf3ef00 100644 --- a/docs/programming_guide/source_zh_cn/numpy.md +++ b/docs/programming_guide/source_zh_cn/numpy.md @@ -366,7 +366,7 @@ from mindspore import ms_function forward_compiled = ms_function(forward) ``` -> 目前静态图不支持在命令行模式中运行,并且有部分语法限制。`ms_function`的更多信息可参考[API: ms_function](https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/mindspore.html?highlight=ms_function#mindspore.ms_function)。 +> 目前静态图不支持在命令行模式中运行,并且有部分语法限制。`ms_function`的更多信息可参考[API: ms_function](https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/mindspore.html#mindspore.ms_function)。 ### GradOperation使用示例 diff --git a/tutorials/training/source_en/advanced_use/summary_record.md b/tutorials/training/source_en/advanced_use/summary_record.md index 36dfa12db2..fec6bdc328 100644 --- a/tutorials/training/source_en/advanced_use/summary_record.md +++ b/tutorials/training/source_en/advanced_use/summary_record.md @@ -139,7 +139,7 @@ if __name__ == '__main__': ``` > 1. When using summary, it is recommended that you set `dataset_sink_mode` argument of `model.train` to `False`. Please see notices for more information. -> 2. When using summary, you need to run the code in `if __name__ == "__main__"`. For more detail, refer to [Python tutorial](https://docs.python.org/3.7/library/multiprocessing.html?highlight=multiprocess#multiprocessing-programming) +> 2. When using summary, you need to run the code in `if __name__ == "__main__"`. For more detail, refer to [Python tutorial](https://docs.python.org/3.7/library/multiprocessing.html#multiprocessing-programming) ### Method two: Custom collection of network data with summary operators and SummaryCollector @@ -315,7 +315,7 @@ In the saved files, `ms_output_after_hwopt.pb` is the computational graph after If you are not using the `Model` interface provided by MindSpore, you can implement a method by imitating `train` method of `Model` interface to control the number of iterations. You can imitate the `SummaryCollector` and record the summary operator data in the following manner. For a detailed custom training cycle tutorial, please [refer to the tutorial on the official website](https://www.mindspore.cn/doc/programming_guide/en/master/train.html#customizing-a-training-cycle). -The following example demonstrates how to record data in a custom training cycle using the summary operator and the `add_value` interface of `SummaryRecord`. For more tutorials about `SummaryRecord`, [refer to the Python API documentation](https://www.mindspore.cn/doc/api_python/en/master/mindspore/mindspore.train.html?highlight=summaryrecord#mindspore.train.summary.SummaryRecord). Please note that `SummaryRecord` will not record computational graph automatically. If you need to record the computational graph, please manually pass the instance of network that inherits from Cell. The recorded computational graph only includes the code and functions used in the construct method. +The following example demonstrates how to record data in a custom training cycle using the summary operator and the `add_value` interface of `SummaryRecord`. For more tutorials about `SummaryRecord`, [refer to the Python API documentation](https://www.mindspore.cn/doc/api_python/en/master/mindspore/mindspore.train.html#mindspore.train.summary.SummaryRecord). Please note that `SummaryRecord` will not record computational graph automatically. If you need to record the computational graph, please manually pass the instance of network that inherits from Cell. The recorded computational graph only includes the code and functions used in the construct method. ```python from mindspore import nn diff --git a/tutorials/training/source_zh_cn/advanced_use/summary_record.md b/tutorials/training/source_zh_cn/advanced_use/summary_record.md index 94ea6b9f18..0aa71bdaf3 100644 --- a/tutorials/training/source_zh_cn/advanced_use/summary_record.md +++ b/tutorials/training/source_zh_cn/advanced_use/summary_record.md @@ -142,7 +142,7 @@ if __name__ == '__main__': ``` > 1. 使用summary功能时,建议将`model.train`的`dataset_sink_mode`参数设置为`False`。请参考文末的注意事项。 -> 2. 使用summary功能时,需要将代码放置到`if __name__ == "__main__"`中运行。详情请[参考Python官网介绍](https://docs.python.org/zh-cn/3.7/library/multiprocessing.html?highlight=multiprocess#multiprocessing-programming)。 +> 2. 使用summary功能时,需要将代码放置到`if __name__ == "__main__"`中运行。详情请[参考Python官网介绍](https://docs.python.org/zh-cn/3.7/library/multiprocessing.html#multiprocessing-programming)。 ### 方式二:结合Summary算子和SummaryCollector,自定义收集网络中的数据 -- Gitee From de36d6560b5039877bcf0491354d581faeec990d Mon Sep 17 00:00:00 2001 From: huangbingjian Date: Wed, 24 Mar 2021 10:10:47 +0800 Subject: [PATCH 03/11] remove ControlDepend --- docs/api_python/source_en/mindspore/mindspore.ops.rst | 2 -- docs/api_python/source_en/mindspore/operations.rst | 10 ---------- .../source_zh_cn/mindspore/mindspore.ops.rst | 2 -- docs/api_python/source_zh_cn/mindspore/operations.rst | 10 ---------- tutorials/notebook/enable_cache.ipynb | 1 - 5 files changed, 25 deletions(-) diff --git a/docs/api_python/source_en/mindspore/mindspore.ops.rst b/docs/api_python/source_en/mindspore/mindspore.ops.rst index 30168edb59..08496ed3d5 100644 --- a/docs/api_python/source_en/mindspore/mindspore.ops.rst +++ b/docs/api_python/source_en/mindspore/mindspore.ops.rst @@ -70,8 +70,6 @@ The functional operators are the pre-instantiated Primitive operators, which can - :class:`mindspore.ops.Primitive` ('bool_or') * - mindspore.ops.cast - :class:`mindspore.ops.Cast` - * - mindspore.ops.control_depend - - :class:`mindspore.ops.ControlDepend` * - mindspore.ops.distribute - :class:`mindspore.ops.Primitive` ('distribute') * - mindspore.ops.dtype diff --git a/docs/api_python/source_en/mindspore/operations.rst b/docs/api_python/source_en/mindspore/operations.rst index 61b09fa0fa..1a82cc29f8 100644 --- a/docs/api_python/source_en/mindspore/operations.rst +++ b/docs/api_python/source_en/mindspore/operations.rst @@ -300,16 +300,6 @@ Common Operators mindspore.ops.ReduceOp mindspore.ops.ReduceScatter -Control Flows -^^^^^^^^^^^^^ - -.. msplatformautosummary:: - :toctree: ops - :nosignatures: - :template: classtemplate.rst - - mindspore.ops.ControlDepend - Debug Operators ^^^^^^^^^^^^^^^ diff --git a/docs/api_python/source_zh_cn/mindspore/mindspore.ops.rst b/docs/api_python/source_zh_cn/mindspore/mindspore.ops.rst index d2bb1d855a..a2a28fce2f 100644 --- a/docs/api_python/source_zh_cn/mindspore/mindspore.ops.rst +++ b/docs/api_python/source_zh_cn/mindspore/mindspore.ops.rst @@ -70,8 +70,6 @@ The functional operators are the pre-instantiated Primitive operators, which can - :class:`mindspore.ops.Primitive` ('bool_or') * - mindspore.ops.cast - :class:`mindspore.ops.Cast` - * - mindspore.ops.control_depend - - :class:`mindspore.ops.ControlDepend` * - mindspore.ops.distribute - :class:`mindspore.ops.Primitive` ('distribute') * - mindspore.ops.dtype diff --git a/docs/api_python/source_zh_cn/mindspore/operations.rst b/docs/api_python/source_zh_cn/mindspore/operations.rst index 61b09fa0fa..1a82cc29f8 100644 --- a/docs/api_python/source_zh_cn/mindspore/operations.rst +++ b/docs/api_python/source_zh_cn/mindspore/operations.rst @@ -300,16 +300,6 @@ Common Operators mindspore.ops.ReduceOp mindspore.ops.ReduceScatter -Control Flows -^^^^^^^^^^^^^ - -.. msplatformautosummary:: - :toctree: ops - :nosignatures: - :template: classtemplate.rst - - mindspore.ops.ControlDepend - Debug Operators ^^^^^^^^^^^^^^^ diff --git a/tutorials/notebook/enable_cache.ipynb b/tutorials/notebook/enable_cache.ipynb index 5f27dfc3f9..effa52a23b 100644 --- a/tutorials/notebook/enable_cache.ipynb +++ b/tutorials/notebook/enable_cache.ipynb @@ -47,7 +47,6 @@ "name": "stdout", "output_type": "stream", "text": [ - "WARNING: 'ControlDepend' is deprecated from version 1.1 and will be removed in a future version, use 'Depend' instead.\n", "/usr/local/cuda/bin:/home/sunny/miniconda3/envs/seb/bin:/home/sunny/miniconda3/condabin:/usr/local/cuda-10.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\n", "/home/sunny/miniconda3/envs/seb/lib/python3.7/site-packages/mindspore:/home/sunny/miniconda3/envs/seb/lib/python3.7/site-packages/mindspore/lib\n" ] -- Gitee From 1601b698dc06a825286e6539ccafc906bf63451e Mon Sep 17 00:00:00 2001 From: z00512249 Date: Wed, 24 Mar 2021 10:29:49 +0800 Subject: [PATCH 04/11] fix master quick_start_codegen.md --- .../quick_start/quick_start_codegen.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tutorials/lite/source_zh_cn/quick_start/quick_start_codegen.md b/tutorials/lite/source_zh_cn/quick_start/quick_start_codegen.md index 5a7b85440e..bd4d6d55ef 100644 --- a/tutorials/lite/source_zh_cn/quick_start/quick_start_codegen.md +++ b/tutorials/lite/source_zh_cn/quick_start/quick_start_codegen.md @@ -63,7 +63,7 @@ #### 使用脚本一键生成代码并执行 -下载[MindSpore源码](https://gitee.com/mindspore/mindspore),进入`mindspore/mindspore/lite/micro/examples/mnist`目录,执行脚本`mnist.sh`自动生成模型推理代码并编译工程目录。 +下载[MindSpore源码](https://gitee.com/mindspore/mindspore),进入`mindspore/mindspore/lite/micro/examples/mnist_x86`目录,执行脚本`mnist.sh`自动生成模型推理代码并编译工程目录。 ```bash bash mnist.sh @@ -84,7 +84,7 @@ run benchmark success #### 生成代码工程说明 -进入`mindspore/mindspore/lite/micro/example/mnist`目录中。 +进入`mindspore/mindspore/lite/micro/example/mnist_x86`目录中。 1. 算子静态库目录说明 @@ -114,7 +114,7 @@ run benchmark success 当前目录下预置了MNIST分类网络生成的代码。 ```text - mnist/ # 生成代码的根目录 + mnist_x86/ # 生成代码的根目录 ├── benchmark # 生成代码的benchmark目录 └── src # 模型推理代码目录 ``` @@ -128,7 +128,7 @@ run benchmark success 进入代码工程目录下,新建并进入build目录: ```bash - mkdir mnist/build && cd mnist/build + mkdir mnist_x86/build && cd mnist_x86/build ``` 开始编译: @@ -164,7 +164,7 @@ run benchmark success [100%] Built target benchmark ``` - 此时在`mnist/build/src/`目录下生成了`libnet.a`,推理执行库,在`mnist/build`目录下生成了`benchmark`可执行文件。 + 此时在`mnist_x86/build/src/`目录下生成了`libnet.a`,推理执行库,在`mnist_x86/build`目录下生成了`benchmark`可执行文件。 #### 代码部署 @@ -176,7 +176,7 @@ run benchmark success ./benchmark mnist_input.bin net.bin ``` -> mnist_input.bin在`example/mnist`目录下,`net.bin`为模型参数文件,在`example/mnist/src`目录下。 +> mnist_input.bin在`example/mnist_x86`目录下,`net.bin`为模型参数文件,在`example/mnist_x86/src`目录下。 生成结果如下: @@ -194,7 +194,7 @@ run benchmark success 本教程中的`benchmark`内部实现主要用于指导用户如何编写以及调用Codegen编译的模型推理代码接口。 -以下为接口调用的详细介绍,详情代码可以参见[examples/mnist](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/micro/example/mnist)下的示例代码示例: +以下为接口调用的详细介绍,详情代码可以参见[examples/mnist_x86](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/micro/example/mnist_x86)下的示例代码示例: #### 构建推理的上下文以及会话 @@ -273,5 +273,5 @@ run benchmark success ### [Android平台编译部署](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/micro/example/mobilenetv2/README.md) -### [Arm Cortex-M平台编译部署](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/micro/example/mnist_stm32f746/README.md) +### [Arm Cortex-M平台编译部署](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/micro/example/mnist_stm32f746/README.md) -- Gitee From ff7498d43a581dc83150cdd2b21de89712540122 Mon Sep 17 00:00:00 2001 From: zhanke Date: Wed, 24 Mar 2021 10:26:47 +0800 Subject: [PATCH 05/11] move nlp_tprr to inference --- tutorials/inference/source_zh_cn/index.rst | 7 +++++++ .../advanced_use => inference/source_zh_cn}/nlp_tprr.md | 4 ++-- tutorials/training/source_zh_cn/advanced_use/nlp.rst | 1 - 3 files changed, 9 insertions(+), 3 deletions(-) rename tutorials/{training/source_zh_cn/advanced_use => inference/source_zh_cn}/nlp_tprr.md (98%) diff --git a/tutorials/inference/source_zh_cn/index.rst b/tutorials/inference/source_zh_cn/index.rst index aa571bf60b..585925818d 100644 --- a/tutorials/inference/source_zh_cn/index.rst +++ b/tutorials/inference/source_zh_cn/index.rst @@ -28,3 +28,10 @@ serving_grpc serving_restful serving_model + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 应用实践 + + nlp_tprr diff --git a/tutorials/training/source_zh_cn/advanced_use/nlp_tprr.md b/tutorials/inference/source_zh_cn/nlp_tprr.md similarity index 98% rename from tutorials/training/source_zh_cn/advanced_use/nlp_tprr.md rename to tutorials/inference/source_zh_cn/nlp_tprr.md index e4373785d0..293d911248 100644 --- a/tutorials/training/source_zh_cn/advanced_use/nlp_tprr.md +++ b/tutorials/inference/source_zh_cn/nlp_tprr.md @@ -18,7 +18,7 @@ - [引用](#引用) -   +   ## 概述 @@ -150,7 +150,7 @@ def ThinkRetrieverConfig(): parser.add_argument("--topk", type=int, default=8, help="top num") parser.add_argument("--onehop_num", type=int, default=8, help="onehop num") parser.add_argument("--batch_size", type=int, default=1, help="batch size") - parser.add_argument("--device_id", type=int, default=0, help="device id") + parser.add_argument("--device_num", type=int, default=8, help="device num") parser.add_argument("--vocab_path", type=str, default='../vocab.txt', help="vocab path") parser.add_argument("--wiki_path", type=str, default='../db_docs_bidirection_new.pkl', help="wiki path") parser.add_argument("--dev_path", type=str, default='../hotpot_dev_fullwiki_v1_for_retriever.json', diff --git a/tutorials/training/source_zh_cn/advanced_use/nlp.rst b/tutorials/training/source_zh_cn/advanced_use/nlp.rst index 226e27e03b..37d9606b68 100644 --- a/tutorials/training/source_zh_cn/advanced_use/nlp.rst +++ b/tutorials/training/source_zh_cn/advanced_use/nlp.rst @@ -6,4 +6,3 @@ nlp_sentimentnet nlp_bert_poetry - nlp_tprr \ No newline at end of file -- Gitee From d1aad71845415fee5730b47636d7ade5c5cf0acd Mon Sep 17 00:00:00 2001 From: chenfei Date: Mon, 22 Mar 2021 22:14:04 +0800 Subject: [PATCH 06/11] change doc of control flow --- .../source_en/static_graph_syntax_support.md | 244 ++++++++++++++---- .../static_graph_syntax_support.md | 244 ++++++++++++++---- 2 files changed, 396 insertions(+), 92 deletions(-) diff --git a/docs/note/source_en/static_graph_syntax_support.md b/docs/note/source_en/static_graph_syntax_support.md index 88a244f0f7..a2565ab693 100644 --- a/docs/note/source_en/static_graph_syntax_support.md +++ b/docs/note/source_en/static_graph_syntax_support.md @@ -25,14 +25,17 @@ - [Identity Operators](#identity-operators) - [Expressions](#expressions) - [Conditional Control Statements](#conditional-control-statements) - - [if](#if) + - [single if](#single-if) + - [side-by-side if](#side-by-side-if) + - [if in if](#if-in-if) - [Loop Statements](#loop-statements) - [for](#for) - [while](#while) - - [Process Control Statements](#process-control-statements) - - [break](#break) - - [continue](#continue) - - [pass](#pass) + - [side-by-side while](#side-by-side-while) + - [while in while](#while-in-while) + - [Conditional Control Statements in Loop Statements](#conditional-control-statements-in-loop-statements) + - [if in for](#if-in-for) + - [if in while](#if-in-while) - [Function Definition Statements](#function-definition-statements) - [def Keyword](#def-keyword) - [lambda Expression](#lambda-expression) @@ -780,7 +783,7 @@ For details about the rules, click y: + out = x +else: + out = y +if z > x: + out = out + 1 +return out +``` + +#### if in if + +Usage: + +- `if (cond1):if (cond2):statements...` + +Parameters: `cond1` and `cond2` -- Consistent with `single if`. + +Restrictions: + +- Inherit all restrictions of `single if`. + +- The total number of `if` in calculating graph can not exceed 50. + +- Too many `if` will cause the compilation time to be too long. Reducing the number of `if` will help improve compilation efficiency. + +Example: + +```python +if x > y: + z = z + 1 + if z > x: + return m +else: + return n +``` ### Loop Statements #### for -Usage: `for i in sequence` +Usage: + +- `for i in sequence` -For example: +Parameter: `sequence` --Iterative sequences (`Tuple` and `List`). + +Restrictions: + +- The total number of graph operations is a multiple of number of iterations of the `for` loop. Excessive number of iterations of the `for` loop may cause the graph to occupy more memory than usage limit. + +Example: ```python z = Tensor(np.ones((2, 3))) @@ -845,82 +913,166 @@ The result is as follows: z: Tensor(shape=[2, 3], dtype=Int64, value=[[7, 7], [7, 7], [7, 7]]) ``` -Parameter: `sequence` --Traverses sequences (`Tuple` and `List`). +#### single while -#### while +Usage: -Usage: `while(cond)` +- `while (cond)` -Parameter: `cond` -- Consistent with `if`. +Parameter: `cond` -- Consistent with `single if`. Restrictions: - During graph building, if `while` is not eliminated, the data type and `shape` of `return` inside `while` must be the same as those outside `while`. -- The data type and `shape` of the updated variables in `while` must be the same as those before the update. +- The data type and shape of the updated variables in `while` must be the same as those before the update. + +- Does not support training scenarios. Example 1: ```python -while x > y: +while x < y: x += 1 return m return n ``` -The `m` data type returned inside `while` inside and `n` data type returned outside `while` must be the same as those of `shape`. +The `m` data type returned inside `while` inside and `n` data type returned outside `while` must be the same as those of shape. Example 2: ```python out = m -while x > y: +while x < y: x += 1 - out = n + out = out + 1 return out ``` -In `while`, the data types of `out` before and after update must be the same as those of `shape`. +In `while`, the data types of `out` before and after update must be the same as those of shape. -### Process Control Statements +#### side-by-side while -The current process control statements support `break`, `continue`, and `pass`. +Usage: -#### break +- `while (cond1):statements while (cond2):statemetns...` -It can be used in the `for` and `while` code blocks to terminate the entire loop. +Parameters: `cond1` and `cond2` -- Consistent with `single if`. -For example: +Restrictions: + +- Inherit all restrictions of `single while`. + +- The total number of `while` in calculating graph can not exceed 50. + +- Too many `while` will cause the compilation time to be too long. Reducing the number of `while` will help improve compilation efficiency. + +Example: ```python -for i in x: - if i == 2: - break - statement_a -statement_b +out = m +while x < y: + x += 1 + out = out + 1 +while out > 10: + out -= 10 +return out ``` -When `i == 2`, the loop ends and `statement_b` is executed. +#### while in while -#### continue +Usage: -It can be used in the `for` and `while` statement blocks to terminate the current loop and directly enter the next loop. +-`while (cond1):while (cond2):statements...` -For example: +Parameters: `cond1` and `cond2` -- Consistent with `single if`. + +Restrictions: + +- Inherit all restrictions of `single while`. + +- The total number of `while` in calculating graph can not exceed 50. + +- Too many `while` will cause the compilation time to be too long. Reducing the number of `while` will help improve compilation efficiency. + +Example: + +```python +out = m +while x < y: + while z < y: + z += 1 + out = out + 1 + x += 1 +return out +``` + +### Conditional Control Statements in Loop Statements + +#### if in for + +Usage: + +- for i in sequence:if (cond)` + +Parameters: + +- `cond` -- Consistent with `single if`. + +- `sequence` -- Iterative sequence(`Tuple`、`List`) + +Restrictions: + +- Inherit all restrictions of `single if`. + +- Inherit all restrictions of `for`. + +- If `cond` is variable, it is forbidden to use `if (cond):return`,`if (cond):continue`,`if (cond):break` statements. + +- The total number of `if` is a multiple of number of iterations of the `for` loop. Excessive number of iterations of the `for` loop may cause the compilation time to be too long. + +Example: ```python +z = Tensor(np.ones((2, 3))) +x = (1, 2, 3) for i in x: - if i == 2: - continue - statement_a -statement_b - ``` + if i < 3: + z += i +return z +``` -When `i == 2`, the current loop ends and the `statement_a` statement is not executed. The next loop starts. +The result is as follows: -#### pass +```text +z: Tensor(shape=[2, 3], dtype=Int64, value=[[4, 4], [4, 4], [4, 4]]) +``` + +#### if in while -It is used as a placeholder statement. +Usage: + +- `while (cond1):if (cond2)` + +Parameters: `cond1` and `cond2` -- Consistent with `single if`. + +Restrictions: + +- Inherit all restrictions of `single if` and `single while`. + +- If `cond2` is variable, it is forbidden to use `if (cond2):return`,`if (cond2):continue`,`if (cond2):break` statements. + +Example: + +```python +out = m +while x < y: + if z > 2*x: + out = out + 1 + x += 1 +return out +``` ### Function Definition Statements diff --git a/docs/note/source_zh_cn/static_graph_syntax_support.md b/docs/note/source_zh_cn/static_graph_syntax_support.md index 2c3868c2fe..5cf5b6a347 100644 --- a/docs/note/source_zh_cn/static_graph_syntax_support.md +++ b/docs/note/source_zh_cn/static_graph_syntax_support.md @@ -25,14 +25,17 @@ - [身份运算符](#身份运算符) - [表达式](#表达式) - [条件控制语句](#条件控制语句) - - [if](#if) + - [单if](#单if) + - [并列if](#并列if) + - [嵌套if](#嵌套if) - [循环语句](#循环语句) - [for](#for) - [while](#while) - - [流程控制语句](#流程控制语句) - - [break](#break) - - [continue](#continue) - - [pass](#pass) + - [并列while](#并列while) + - [嵌套while](#嵌套while) + - [循环嵌套条件控制语句](#循环嵌套条件控制语句) + - [if in for](#if-in-for) + - [if in while](#if-in-while) - [函数定义语句](#函数定义语句) - [def关键字](#def关键字) - [lambda表达式](#lambda表达式) @@ -782,7 +785,7 @@ def generate_tensor(): ### 条件控制语句 -#### if +#### 单if 使用方式: @@ -794,13 +797,15 @@ def generate_tensor(): 限制: -- 在构图时,如果`if`未能消除,则`if`分支`return`的数据类型和`shape`,与`if`分支外`return`的数据类型和`shape`必须一致。 +- 在构图时,如果`if`未能消除,则`if`分支`return`的数据类型和shape,与`if`分支外`return`的数据类型和shape必须一致。 -- 当只有`if`时,`if`分支变量更新后数据类型和`shape`,与更新前数据类型和`shape`必须一致。 +- 当只有`if`时,`if`分支变量更新后数据类型和shape,与更新前数据类型和shape必须一致。 -- 当即有`if`又有`else`时,`if`分支变量更新后数据类型和`shape`,与`else`分支更新后数据类型和`shape`必须一致。 +- 当即有`if`又有`else`时,`if`分支变量更新后数据类型和shape,与`else`分支更新后数据类型和shape必须一致。 -- `if`条件控制语句太多会导致`Ascend`下编译时间变长,尽量减少冗余`if`的使用。 +- 不支持高阶微分场景。 + +- 不支持`elif`语句。 示例1: @@ -811,7 +816,7 @@ else: return n ``` -`if`分支返回的`m`和`else`分支返回的`n`,二者数据类型和`shape`必须一致。 +`if`分支返回的`m`和`else`分支返回的`n`,二者数据类型和shape必须一致。 示例2: @@ -823,15 +828,78 @@ else: return out ``` -`if`分支更新后`out`和`else`分支更新后`out`,二者数据类型和`shape`必须一致。 +`if`分支更新后`out`和`else`分支更新后`out`,二者数据类型和shape必须一致。 + +#### 并列if + +使用方式: + +- `if (cond1):statements else:statements...if (cond2):statements...` + +参数:`cond1`、 `cond2`-- 与`单if`一致。 + +限制: + +- 继承`单if`所有限制。 + +- 计算图总`if`数量不超过50个。 + +- `if`数量过多会导致编译时间过长,减少`if`数量有助于提升编译效率。 + +示例: + +```python +if x > y: + out = x +else: + out = y +if z > x: + out = out + 1 +return out +``` + +#### 嵌套if + +使用方式: + +- `if (cond1):if (cond2):statements...` + +参数:`cond1`、 `cond2`-- 与`单if`一致。 + +限制: + +- 继承`单if`所有限制。 + +- 计算图`if`数量不超过50个。 + +- `if`数量过多会导致编译时间过长,减少`if`数量有助于提升编译效率。 + +示例: + +```python +if x > y: + z = z + 1 + if z > x: + return m +else: + return n +``` ### 循环语句 #### for -使用方式:`for i in sequence` +使用方式: -示例如下: +- `for i in sequence` + +参数:`sequence` -- 遍历序列(`Tuple`、`List`) + +限制: + +- 图的算子数量和`for`循环的迭代次数成倍数关系,`for`循环迭代次数过大可能会导致图占用内存超过使用限制。 + +示例: ```python z = Tensor(np.ones((2, 3))) @@ -847,82 +915,166 @@ return z z: Tensor(shape=[2, 3], dtype=Int64, value=[[7, 7], [7, 7], [7, 7]]) ``` -参数:`sequence` -- 遍历序列(`Tuple`、`List`) +#### 单while -#### while +使用方式: -使用方式:`while(cond)` +- `while (cond)` -参数:`cond` -- 与`if`一致。 +参数:`cond` -- 与`单if`一致。 限制: -- 在构图时,如果`while`未能消除,则`while`内`return`的数据类型和`shape`,与`while`外`return`的数据类型和`shape`必须一致。 +- 在构图时,如果`while`未能消除,则`while`内`return`的数据类型和shape,与`while`外`return`的数据类型和shape必须一致。 + +- `while`内变量更新后数据类型和shape,与更新前数据类型和shape必须一致。 -- `while`内变量更新后数据类型和`shape`,与更新前数据类型和`shape`必须一致。 +- 不支持训练场景。 示例1: ```python -while x > y: +while x < y: x += 1 return m return n ``` -`while`内返回的`m`和`while`外返回的`n`数据类型必须和`shape`一致。 +`while`内返回的`m`和`while`外返回的`n`数据类型必须和shape一致。 示例2: ```python out = m -while x > y: +while x < y: x += 1 - out = n + out = out + 1 return out ``` -`while`内,`out`更新后和更新前的数据类型和`shape`必须一致。 +`while`内,`out`更新后和更新前的数据类型和shape必须一致。 -### 流程控制语句 +#### 并列while -当前流程控制语句支持了`break`、`continue`和`pass`。 +使用方式: -#### break +- `while (cond1):statements while (cond2):statemetns...` -可用于`for`和`while`代码块里,用于终止整个循环。 +参数:`cond1`、 `cond2`-- 与`单if`一致。 -示例如下: +限制: + +- 继承`单while`所有限制。 + +- 并列`while`总数不超过50个。 + +- `while`数量过多会导致编译时间过长,减少`while`数量有助于提升编译效率。 + +示例: ```python -for i in x: - if i == 2: - break - statement_a -statement_b +out = m +while x < y: + x += 1 + out = out + 1 +while out > 10: + out -= 10 +return out ``` -当 `i == 2`时,循环终止,执行`statement_b`。 +#### 嵌套while + +使用方式: + +- `while (cond1):while (cond2):statements...` + +参数:`cond1`、 `cond2`-- 与`单if`一致。 + +限制: + +- 继承`单while`所有限制。 + +- 嵌套`while`总数不超过50个。 + +- `while`数量过多会导致编译时间过长,减少`while`数量有助于提升编译效率。 + +示例: + +```python +out = m +while x < y: + while z < y: + z += 1 + out = out + 1 + x += 1 +return out +``` + +### 循环嵌套条件控制语句 + +#### if in for + +使用方式: + +- `for i in sequence:if (cond)` + +参数: + +`cond` -- 与`单if`一致。 + +`sequence` -- 遍历序列(`Tuple`、`List`) -#### continue +限制: + +- 继承`单if`所有限制。 + +- 继承`for`所有限制。 + +- `cond`为变量时,不能有`if (cond):return`、`if (cond):continue`、`if (cond):break`语句。 -可用于`for`和`while`语句块里,用于终止本轮循环,直接进入下一轮循环。 +- `if`数量和`for`循环的迭代次数成倍数关系,`for`循环迭代次数过大可能会导致编译时间过长。 示例如下: ```python +z = Tensor(np.ones((2, 3))) +x = (1, 2, 3) for i in x: - if i == 2: - continue - statement_a -statement_b - ``` + if i < 3: + z += i +return z +``` -当 `i == 2`时,本轮循环终止,不会往下执行`statement_a`,进入下一轮循环。 +结果如下: -#### pass +```text +z: Tensor(shape=[2, 3], dtype=Int64, value=[[4, 4], [4, 4], [4, 4]]) +``` + +#### if in while -不做任何事情,占位语句。 +使用方式: + +- `while (cond1):if (cond2)` + +参数:`cond1`、 `cond2`-- 与`单if`一致。 + +限制: + +- 继承`单if`、`单while`所有限制。 + +- `cond2`为变量时,不能有`if (cond2):return`、`if (cond2):continue`、`if (cond2):break`语句。 + +示例: + +```python +out = m +while x < y: + if z > 2*x: + out = out + 1 + x += 1 +return out +``` ### 函数定义语句 -- Gitee From c4c3bd81edd9c638b351653b9c3f76868dc2c34e Mon Sep 17 00:00:00 2001 From: lvmingfu Date: Wed, 24 Mar 2021 10:51:19 +0800 Subject: [PATCH 07/11] modify code format in data conversion for master --- .../source_zh_cn/dataset_conversion.ipynb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/programming_guide/source_zh_cn/dataset_conversion.ipynb b/docs/programming_guide/source_zh_cn/dataset_conversion.ipynb index 5b869d1171..b5229f3019 100644 --- a/docs/programming_guide/source_zh_cn/dataset_conversion.ipynb +++ b/docs/programming_guide/source_zh_cn/dataset_conversion.ipynb @@ -38,8 +38,7 @@ "ExecuteTime": { "end_time": "2021-02-22T10:33:34.444561Z", "start_time": "2021-02-22T10:33:34.441434Z" - }, - "scrolled": true + } }, "outputs": [], "source": [ @@ -655,18 +654,7 @@ "cell_type": "code", "execution_count": 14, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "os.system('pip install tensorflow') if os.system('python -c \"import tensorflow\"') else print(\"TensorFlow installed\")" ] -- Gitee From 2597e0b4f8e1a4241bef0ad52aaeb7feb1365fde Mon Sep 17 00:00:00 2001 From: lvmingfu Date: Wed, 24 Mar 2021 11:17:59 +0800 Subject: [PATCH 08/11] modify code formats in context.ipynb for master --- docs/programming_guide/source_en/context.md | 28 +++++++--- .../source_zh_cn/context.ipynb | 52 ++++++++++++------- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/docs/programming_guide/source_en/context.md b/docs/programming_guide/source_en/context.md index 3d7836cc4f..5f05a6c1d0 100644 --- a/docs/programming_guide/source_en/context.md +++ b/docs/programming_guide/source_en/context.md @@ -123,20 +123,32 @@ To facilitate maintenance and fault locating, the context provides a large numbe The system can collect profiling data during training and use the profiling tool for performance analysis. Currently, the following profiling data can be collected: -- `enable_profiling`: indicates whether to enable the profiling function. If this parameter is set to True, the profiling function is enabled, and profiling options are read from enable_options. If this parameter is set to False, the profiling function is disabled and only training_trace is collected. +- `enable_profiling`: indicates whether to enable the profiling function. If this parameter is set to True, the profiling function is enabled, and profiling options are read from `enable_options`. If this parameter is set to False, the profiling function is disabled and only training_trace is collected. - `profiling_options`: profiling collection options. The values are as follows. Multiple data items can be collected. - - result_path: saving the path of the profiling collection result file. The directory spectified by this parameter needs to be created in advance on the training environment (container or host side) and ensure that the running user configured during installation has read and write permissions. It supports the configuration of absolute or relative paths(relative to the current path when executing the command line). The absolute path configuration starts with '/', for example:/home/data/output. The relative path configuration directly starts with the directory name, for example:output; - - training_trace: collect iterative trajectory data, that is, the training task and software information of the AI software stack, to achieve performance analysis of the training task, focusing on data enhancement, forward and backward calculation, gradient aggregation update and other related data. The value is on/off; - - task_trace: collect task trajectory data, that is, the hardware information of the HWTS/AICore of the Ascend 910 processor, and analyze the information of beginning and ending of the task. The value is on/off; - - aicpu_trace: collect profiling data enhanced by aicpu data. The value is on/off; - - fp_point: specify the start position of the forward operator of the training network iteration trajectory, which is used to record the start timestamp of the forward calculation. The configuration value is the name of the first operator specified in the forward direction. when the value is empty, the system will automatically obtain the forward operator name; - - bp_point: specify the end position of the iteration trajectory reversal operator of the training network, record the end timestamp of the backward calculation. The configuration value is the name of the operator after the specified reverse. when the value is empty, the system will automatically obtain the backward operator name; - - ai_core_metrics: the values are as follows: + + - `result_path`: saving the path of the profiling collection result file. The directory spectified by this parameter needs to be created in advance on the training environment (container or host side) and ensure that the running user configured during installation has read and write permissions. It supports the configuration of absolute or relative paths(relative to the current path when executing the command line). The absolute path configuration starts with '/', for example:/home/data/output. The relative path configuration directly starts with the directory name, for example:output; + + - `training_trace`: collect iterative trajectory data, that is, the training task and software information of the AI software stack, to achieve performance analysis of the training task, focusing on data enhancement, forward and backward calculation, gradient aggregation update and other related data. The value is on/off; + + - `task_trace`: collect task trajectory data, that is, the hardware information of the HWTS/AICore of the Ascend 910 processor, and analyze the information of beginning and ending of the task. The value is on/off; + + - `aicpu_trace`: collect profiling data enhanced by aicpu data. The value is on/off; + + - `fp_point`: specify the start position of the forward operator of the training network iteration trajectory, which is used to record the start timestamp of the forward calculation. The configuration value is the name of the first operator specified in the forward direction. when the value is empty, the system will automatically obtain the forward operator name; + + - `bp_point`: specify the end position of the iteration trajectory reversal operator of the training network, record the end timestamp of the backward calculation. The configuration value is the name of the operator after the specified reverse. when the value is empty, the system will automatically obtain the backward operator name; + + - `ai_core_metrics` the values are as follows: + - ArithmeticUtilization: percentage statistics of various calculation indicators; + - PipeUtilization: the time-consuming ratio of calculation unit and handling unit, this item is the default value; + - Memory: percentage of external memory read and write instructions; + - MemoryL0: percentage of internal memory read and write instructions; + - ResourceConflictRatio: proportion of pipline queue instructions. A code example is as follows: diff --git a/docs/programming_guide/source_zh_cn/context.ipynb b/docs/programming_guide/source_zh_cn/context.ipynb index 064dfec081..a17d3997cb 100644 --- a/docs/programming_guide/source_zh_cn/context.ipynb +++ b/docs/programming_guide/source_zh_cn/context.ipynb @@ -147,7 +147,7 @@ "source": [ "## 分布式管理\n", "\n", - "context中有专门用于配置并行训练参数的接口:context.set_auto_parallel_context,该接口必须在初始化网络之前调用。\n", + "context中有专门用于配置并行训练参数的接口:`context.set_auto_parallel_context`,该接口必须在初始化网络之前调用。\n", "\n", "> 分布式并行训练详细介绍可以查看[分布式并行训练](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/distributed_training_tutorials.html)。" ] @@ -164,26 +164,26 @@ "\n", "系统支持在训练过程中采集profiling数据,然后通过profiling工具进行性能分析。当前支持采集的profiling数据包括:\n", "\n", - "- `enable_profiling`:是否开启profiling功能。设置为True,表示开启profiling功能,从enable_options读取profiling的采集选项;设置为False,表示关闭profiling功能,仅采集training_trace。\n", + "- `enable_profiling`:是否开启profiling功能。设置为True,表示开启profiling功能,从`enable_options`读取profiling的采集选项;设置为False,表示关闭profiling功能,仅采集`training_trace`。\n", "\n", "- `profiling_options`:profiling采集选项,取值如下,支持采集多项数据。 \n", - " - result_path: Profiling采集结果文件保存路径。该参数指定的目录需要在启动训练的环境上(容器或Host侧)提前创建且确保安装时配置的运行用户具有读写权限,支持配置绝对路径或相对路径(相对执行命令时的当前路径)。 \n", - " - training_trace:采集迭代轨迹数据,即训练任务及AI软件栈的软件信息,实现对训练任务的性能分析,重点关注数据增强、前后向计算、梯度聚合更新等相关数据,取值on/off。 \n", - " - task_trace:采集任务轨迹数据,即昇腾910处理器HWTS/AICore的硬件信息,分析任务开始、结束等信息,取值on/off。 \n", - " - aicpu_trace: 采集aicpu数据增强的profiling数据。取值on/off。 \n", - " - fp_point: training_trace为on时需要配置。指定训练网络迭代轨迹正向算子的开始位置,用于记录前向算子开始时间戳。配置值为指定的正向第一个算子名字。当该值为空时,系统自动获取正向第一个算子名字。 \n", - " - bp_point: training_trace为on时需要配置。指定训练网络迭代轨迹反向算子的结束位置,用于记录反向算子结束时间戳。配置值为指定的反向最后一个算子名字。当该值为空时,系统自动获取反向最后一个算子名字。 \n", - " - ai_core_metrics: 取值如下:\n", + " - `result_path`:Profiling采集结果文件保存路径。该参数指定的目录需要在启动训练的环境上(容器或Host侧)提前创建且确保安装时配置的运行用户具有读写权限,支持配置绝对路径或相对路径(相对执行命令时的当前路径)。 \n", + " - `training_trace`:采集迭代轨迹数据,即训练任务及AI软件栈的软件信息,实现对训练任务的性能分析,重点关注数据增强、前后向计算、梯度聚合更新等相关数据,取值on/off。 \n", + " - `task_trace`:采集任务轨迹数据,即昇腾910处理器HWTS/AICore的硬件信息,分析任务开始、结束等信息,取值on/off。 \n", + " - `aicpu_trace`:采集aicpu数据增强的profiling数据。取值on/off。 \n", + " - `fp_point`:`training_trace`为on时需要配置。指定训练网络迭代轨迹正向算子的开始位置,用于记录前向算子开始时间戳。配置值为指定的正向第一个算子名字。当该值为空时,系统自动获取正向第一个算子名字。 \n", + " - `bp_point`:`training_trace`为on时需要配置。指定训练网络迭代轨迹反向算子的结束位置,用于记录反向算子结束时间戳。配置值为指定的反向最后一个算子名字。当该值为空时,系统自动获取反向最后一个算子名字。 \n", + " - `ai_core_metrics`取值如下:\n", "\n", - " - ArithmeticUtilization: 各种计算类指标占比统计。\n", + " - ArithmeticUtilization:各种计算类指标占比统计。\n", "\n", - " - PipeUtilization: 计算单元和搬运单元耗时占比,该项为默认值。\n", + " - PipeUtilization:计算单元和搬运单元耗时占比,该项为默认值。\n", "\n", - " - Memory: 外部内存读写类指令占比。\n", + " - Memory:外部内存读写类指令占比。\n", "\n", - " - MemoryL0: 内部内存读写类指令占比。\n", + " - MemoryL0:内部内存读写类指令占比。\n", "\n", - " - ResourceConflictRatio: 流水线队列类指令占比。\n", + " - ResourceConflictRatio:流水线队列类指令占比。\n", "\n", "代码样例如下:\n", "\n", @@ -200,18 +200,24 @@ "source": [ "### 保存MindIR\n", "\n", - "通过context.set_context(save_graphs=True)来保存各个编译阶段的中间代码。\n", + "通过`context.set_context(save_graphs=True)`来保存各个编译阶段的中间代码。\n", "\n", "被保存的中间代码有两种格式:一个是后缀名为`.ir`的文本格式,一个是后缀名为`.dot`的图形化格式。\n", "\n", "当网络规模较大时建议使用更高效的文本格式来查看,当网络规模不大时,建议使用更直观的图形化格式来查看。\n", "\n", "代码样例如下:\n", + "\n", "```python\n", "from mindspore import context\n", "context.set_context(save_graphs=True)\n", - "```\n", - "\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "> MindIR详细介绍可以查看[MindSpore IR(MindIR)](https://www.mindspore.cn/doc/note/zh-CN/master/design/mindspore/mindir.html)。" ] }, @@ -228,11 +234,17 @@ "- `print_file_path`:可以将print算子数据保存到文件,同时关闭屏幕打印功能。如果保存的文件已经存在,则会给文件添加时间戳后缀。数据保存到文件可以解决数据量较大时屏幕打印数据丢失的问题。\n", "\n", "代码样例如下:\n", + "\n", "```python\n", "from mindspore import context\n", "context.set_context(print_file_path=\"print.pb\")\n", - "```\n", - "\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "> context接口详细介绍可以查看[mindspore.context](https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/mindspore.context.html)。" ] } @@ -253,7 +265,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.5" } }, "nbformat": 4, -- Gitee From 94209c0f7fa3616e360a3f4280520df4c72205c5 Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Wed, 24 Mar 2021 13:17:28 +0800 Subject: [PATCH 09/11] cpp api and 310 inference tutorial Signed-off-by: zhoufeng --- docs/api_cpp/source_en/mindspore.md | 6 ++++-- docs/api_cpp/source_zh_cn/mindspore.md | 6 ++++-- .../source_en/multi_platform_inference_ascend_310_mindir.md | 2 +- .../multi_platform_inference_ascend_310_mindir.md | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/api_cpp/source_en/mindspore.md b/docs/api_cpp/source_en/mindspore.md index 2984497351..ca0262886f 100644 --- a/docs/api_cpp/source_en/mindspore.md +++ b/docs/api_cpp/source_en/mindspore.md @@ -64,7 +64,7 @@ Get the current Allocator setting. std::vector> &MutableDeviceInfo(); ``` -Get a mutable reference of DeviceInfoContext vector in this context. Only MindSpore Lite supports heterogeneous scenarios with multiple members in the vector. +Get a mutable reference of [DeviceInfoContext](#deviceinfocontext) vector in this context. Only MindSpore Lite supports heterogeneous scenarios with multiple members in the vector. - Returns @@ -278,12 +278,14 @@ Builds a model so that it can run on a device. - Parameters - `graph`: `GraphCell` is a derivative of `Cell`. `Cell` is not available currently. `GraphCell` can be constructed from `Graph`, for example, `model.Build(GraphCell(graph), context)`. - - `model_context`: used to store the during execution. + - `model_context`: a [context](#context) used to store options during execution. - Returns Status code. +> Modifications to `model_context` after `Build` will no longer take effect. + #### Predict ```cpp diff --git a/docs/api_cpp/source_zh_cn/mindspore.md b/docs/api_cpp/source_zh_cn/mindspore.md index f5df542bf8..045651186e 100644 --- a/docs/api_cpp/source_zh_cn/mindspore.md +++ b/docs/api_cpp/source_zh_cn/mindspore.md @@ -64,7 +64,7 @@ std::shared_ptr GetAllocator() const; std::vector> &MutableDeviceInfo(); ``` -修改该context下的DeviceInfoContext数组,仅mindspore lite支持数组中有多个成员是异构场景。 +修改该context下的[DeviceInfoContext](#deviceinfocontext)数组,仅mindspore lite支持数组中有多个成员是异构场景。 - 返回值 @@ -278,12 +278,14 @@ Status Build(GraphCell graph, const std::shared_ptr &model_context); - 参数 - `graph`: `GraphCell`是`Cell`的一个派生,`Cell`目前没有开放使用。`GraphCell`可以由`Graph`构造,如`model.Build(GraphCell(graph), context)`。 - - `model_context`: 模型context。 + - `model_context`: 模型[Context](#context)。 - 返回值 状态码类`Status`对象,可以使用其公有函数`StatusCode`或`ToString`函数来获取具体错误码及错误信息。 +> `Build`之后对`model_context`的其他修改不再生效。 + #### Predict ```cpp diff --git a/tutorials/inference/source_en/multi_platform_inference_ascend_310_mindir.md b/tutorials/inference/source_en/multi_platform_inference_ascend_310_mindir.md index 8b23958022..356f4528ea 100644 --- a/tutorials/inference/source_en/multi_platform_inference_ascend_310_mindir.md +++ b/tutorials/inference/source_en/multi_platform_inference_ascend_310_mindir.md @@ -36,7 +36,7 @@ This tutorial describes how to use MindSpore to perform inference on the Atlas 2 ## Preparing the Development Environment -For details, see [Inference on the Ascend 310 AI Processor](https://www.mindspore.cn/tutorial/inference/en/master/multi_platform_inference_ascend_310_air.html#preparing-the-development-environment). +Refer to [Inference on the Ascend 310 AI Processor](https://www.mindspore.cn/tutorial/inference/en/master/multi_platform_inference_ascend_310_air.html#preparing-the-development-environment) to install the device, and then refer to [Installation Guide](https://www.mindspore.cn/install/en) to install MindSpore. ## Exporting the MindIR Model diff --git a/tutorials/inference/source_zh_cn/multi_platform_inference_ascend_310_mindir.md b/tutorials/inference/source_zh_cn/multi_platform_inference_ascend_310_mindir.md index 9beca4ed29..1673b5e3ac 100644 --- a/tutorials/inference/source_zh_cn/multi_platform_inference_ascend_310_mindir.md +++ b/tutorials/inference/source_zh_cn/multi_platform_inference_ascend_310_mindir.md @@ -36,7 +36,7 @@ Ascend 310是面向边缘场景的高能效高集成度AI处理器。Atlas 200 ## 开发环境准备 -参考[Ascend 310 AI处理器上使用AIR进行推理#开发环境准备](https://www.mindspore.cn/tutorial/inference/zh-CN/master/multi_platform_inference_ascend_310_air.html#id2) +参考[Ascend 310 AI处理器上使用AIR进行推理#开发环境准备](https://www.mindspore.cn/tutorial/inference/zh-CN/master/multi_platform_inference_ascend_310_air.html#id2)安装设备环境,然后参考[安装指导](https://www.mindspore.cn/install)安装MindSpore。 ## 导出MindIR模型文件 -- Gitee From ee1dcce923a5289b8e5746364fc2e48a90e4a830 Mon Sep 17 00:00:00 2001 From: zhangyi Date: Tue, 23 Mar 2021 09:44:11 +0800 Subject: [PATCH 10/11] modify dump tutorials and IR tutorials. --- .../source_zh_cn/design/mindspore/mindir.md | 141 +++++- .../advanced_use/custom_debugging_info.md | 138 +----- .../advanced_use/dump_data_from_ir_files.md | 264 ----------- .../advanced_use/dump_in_graph_mode.md | 445 ++++++++++-------- tutorials/training/source_zh_cn/index.rst | 2 +- 5 files changed, 411 insertions(+), 579 deletions(-) delete mode 100644 tutorials/training/source_zh_cn/advanced_use/dump_data_from_ir_files.md rename docs/programming_guide/source_zh_cn/dump.md => tutorials/training/source_zh_cn/advanced_use/dump_in_graph_mode.md (53%) diff --git a/docs/note/source_zh_cn/design/mindspore/mindir.md b/docs/note/source_zh_cn/design/mindspore/mindir.md index 01fd8b8ab7..f7b1ac80fa 100644 --- a/docs/note/source_zh_cn/design/mindspore/mindir.md +++ b/docs/note/source_zh_cn/design/mindspore/mindir.md @@ -1,6 +1,6 @@ # MindSpore IR(MindIR) -`Linux` `Windows` `框架开发` `中级` `高级` `贡献者` +`Linux` `Windows` `Ascend` `GPU` `框架开发` `中级` `模型开发` `高级` `贡献者` @@ -9,6 +9,7 @@ - [文法定义](#文法定义) - [示例](#示例) - [如何保存IR](#如何保存ir) + - [IR文件内容介绍](#ir文件内容介绍) - [函数式语义](#函数式语义) - [高阶函数](#高阶函数) - [控制流](#控制流) @@ -23,7 +24,13 @@ 中间表示(IR)是程序编译过程中介于源语言和目标语言之间的程序表示,以方便编译器进行程序分析和优化,因此IR的设计需要考虑从源语言到目标语言的转换难度,同时考虑程序分析和优化的易用性和性能。 -MindIR是一种基于图表示的函数式IR,其最核心的目的是服务于自动微分变换。自动微分采用的是基于函数式编程框架的变换方法,因此IR采用了接近于ANF函数式的语义。此外,借鉴Sea of Nodes[1]和Thorin[2]的优秀设计,采用了一种基于显性依赖图的表示方式。 +MindIR是一种基于图表示的函数式IR,其最核心的目的是服务于自动微分变换。自动微分采用的是基于函数式编程框架的变换方法,因此IR采用了接近于ANF函数式的语义。此外,借鉴Sea of Nodes[1]和Thorin[2]的优秀设计,采用了一种基于显性依赖图的表示方式。关于ANF-IR的具体介绍,可以参考[MindSpore IR文法定义](#id3)。 + +在图模式`context.set_context(mode=context.GRAPH_MODE)`下运行用MindSpore编写的模型时,若配置中设置了`context.set_context(save_graphs=True)`,运行时会输出一些图编译过程中生成的一些中间文件,我们称为IR文件。当前主要有三种格式的IR文件: + +- ir后缀结尾的IR文件:一种比较直观易懂的以文本格式描述模型结构的文件,可以直接用文本编辑软件查看。在下文中我们也将介绍此文件的查看方式。 +- dat后缀结尾的IR文件:一种相对于ir后缀结尾的文件格式定义更为严谨的描述模型结构的文件,包含的内容更为丰富,可以直接用文本编辑软件查看。 +- dot后缀结尾的IR文件:描述了不同节点间的拓扑关系,可以用[graphviz](http://graphviz.org)将此文件作为输入生成图片,方便用户直观地查看模型结构。对于算子比较多的模型,推荐使用可视化组件[MindInsight](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/dashboard.html#id5)对计算图进行可视化。 ## 文法定义 @@ -101,6 +108,136 @@ lambda (x, y) DOT文件可以通过graphviz转换为图片格式来查看,例如将dot转换为png的命令是`dot -Tpng *.dot -o *.png`。 +在训练脚本`train.py`中,我们在`set_context`函数中添加如下代码,运行训练脚本时,MindSpore会自动将编译过程中产生的IR文件存放到指定路径。 + +```python +if __name__ == "__main__": + context.set_context(save_graphs=True, save_graphs_path="path/to/ir/files") +``` + +此处为单机版本的训练脚本。当运行的脚本使用多个计算设备时,MindSpore会为每一个计算设备生成一个独立的进程。因此我们建议用户在多卡版本的训练脚本中读取当前的计算设id,从而为每个设备设置独立的`save_graphs_path`实现将每个设备的IR文件保存在不同的路径下。例如: + +```python +device_id = os.getenv("DEVICE_ID") +context.set_context(save_graphs=True, save_graphs_path="path/to/ir/files"+device_id) +``` + +执行训练命令后,在指定的目录生成如下文件。其中以数字下划线开头的IR文件是在ME编译图过程中输出的,`pipeline`各阶段分别会保存一次计算图。下面介绍比较重要的阶段,例如`parse`阶段会解析入口的`construct`函数;`symbol_resolve`阶段会递归解析入口函数直接或间接引用到的其他函数和对象;`abstract_specialize`阶段会做类型推导和`shape`推导;`optimize`阶段主要是进行和硬件无关的优化,自动微分与自动并行功能也是在该阶段展开;`validate`阶段会校验编译出来的计算图;`task_emit`阶段将计算图传给后端进一步处理;`execute`阶段会执行该计算图。 + +```bash +. +├── 00_parse_[xxxx].ir +├── 00_parse.dat +├── 00_parse.dot +├── 01_symbol_resolve_[xxxx].ir +├── 01_symbol_resolve.dat +├── 01_symbol_resolve.dot +├── 02_combine_like_graphs_[xxxx].ir +├── 02_combine_like_graphs.dat +├── 02_combine_like_graphs.dot +├── 03_inference_opt_prepare_[xxxx].ir +├── 03_inference_opt_prepare.dat +├── 03_inference_opt_prepare.dot +├── 04_abstract_specialize_[xxxx].ir +├── 04_abstract_specialize.dat +├── 04_abstract_specialize.dot +├── 05_inline_[xxxx].ir +├── 05_inline.dat +├── 05_inline.dot +├── 06_py_pre_ad_[xxxx].ir +├── 06_py_pre_ad.dat +├── 06_py_pre_ad.dot +├── 07_pipeline_split_[xxxx].ir +├── 07_pipeline_split.dat +├── 07_pipeline_split.dot +├── 08_optimize_[xxxx].ir +├── 08_optimize.dat +├── 08_optimize.dot +├── 09_py_opt_[xxxx].ir +├── 09_py_opt.dat +├── 09_py_opt.dot +├── 10_validate_[xxxx].ir +├── 10_validate.dat +├── 10_validate.dot +├── 11_task_emit_[xxxx].ir +├── 11_task_emit.dat +├── 11_task_emit.dot +├── 12_execute_[xxxx].ir +├── 12_execute.dat +├── 12_execute.dot +... +``` + +## IR文件内容介绍 + +下面以一个简单的例子来说明IR文件的内容,执行以下一段训练代码: + +```python +import mindspore.context as context +import mindspore.nn as nn +from mindspore import Tensor +from mindspore import dtype as mstype + +context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") +context.set_context(save_graphs=True, save_graphs_path="./ir_files") + +class Net(nn.Cell): + def __init__(self): + super().__init__() + + def construct(self, x, y): + x = x + y + x = x * y + return x + +x = Tensor(3, mstype.float32) +y = Tensor(2, mstype.float32) +net = Net() +out = net(x, y) +print(out) +``` + +使用文本编辑软件(例如`vi`)打开执行完后输出的IR文件`12_execute_[xxxx].ir`,内容如下所示: + +```text + 1 #IR entry : @6_5_1_construct_wrapper.15 + 2 #attrs : + 3 check_set_strategy_valid_once_only : 1 + 4 #Total params : 2 + 5 + 6 %para1_x : + 7 %para2_y : + 8 + 9 #Total subgraph : 1 +10 +11 subgraph attr: +12 check_set_strategy_valid_once_only : 1 +13 subgraph @6_5_1_construct_wrapper.15() { +14 %0([CNode]8) = Add(%para1_x, %para2_y) primitive_attrs: {output_names: [output], input_names: [x, y]} +15 : (, ) -> () +16 # In file /home/workspace/mindspore/mindspore/ops/composite/multitype_ops/add_impl.py(129)/ return F.add(x, y)/ +17 # In file demo.py(14)/ x = x + y/ +18 %1([CNode]10) = Mul(%0, %para2_y) primitive_attrs: {output_names: [output], input_names: [x, y]} +19 : (, ) -> () +20 # In file /home/workspace/mindspore/mindspore/ops/composite/multitype_ops/mul_impl.py(48)/ return F.tensor_mul(x, y)/ +21 # In file demo.py(15)/ x = x * y/ +22 return(%1) +23 : () +24 } +``` + +以上内容可分为两个部分,第一部分为输入列表,第二部分为图结构。 其中第1行告诉了我们该网络的顶图名称`@6_5_1_construct_wrapper.15`,也就是入口图。 第4行告诉了我们该网络有多少个输入。 第6-7行为输入列表,遵循`%para[序号]_[name] : <[data_type]x[shape]>`的格式。 第9行告诉我们该网络解析出来的子图数量。 第11-24行为图结构,含有若干节点,即`CNode`。该示例中只有2个节点,分别为14行的`Add`和18行的`Mul`。 + +`CNode`的信息遵循如下格式,包含节点名称、属性、输入节点、输出信息、格式、源码解析调用栈等信息,由于ANF图为单向无环图,所以这里仅根据输入关系体现节点与节点的连接关系。源码解析调用栈则体现了`CNode`与脚本源码之间的关系,例如第20行由第21行解析而来,而第21行能对应到脚本的`x = x * y`。 + +```text +%[序号]([debug_name]) = [OpName]([arg], ...) primitive_attrs: {[key]: [value], ...} + : (<[输入data_type]x[输入shape]>, ...) -> (<[输出data_type]x[输出shape]>, ...) + # 源码解析调用栈 +``` + +> 需要注意的是经过编译器的若干优化处理后,节点可能经过了若干变幻(如算子拆分、算子融合等),节点的源码解析调用栈信息与脚本可能无法完全一一对应,这里仅作为辅助手段。 + ## 函数式语义 MindIR较传统计算图的一个重要特性是不仅可以表达算子之间的数据依赖,还可以表达丰富的函数式语义。 diff --git a/tutorials/training/source_zh_cn/advanced_use/custom_debugging_info.md b/tutorials/training/source_zh_cn/advanced_use/custom_debugging_info.md index 9ab7f20fb6..a3efa92aa7 100644 --- a/tutorials/training/source_zh_cn/advanced_use/custom_debugging_info.md +++ b/tutorials/training/source_zh_cn/advanced_use/custom_debugging_info.md @@ -10,12 +10,15 @@ - [MindSpore的Callback能力](#mindspore的callback能力) - [自定义Callback](#自定义callback) - [MindSpore metrics功能介绍](#mindspore-metrics功能介绍) - - [print算子功能介绍](#print算子功能介绍) + - [Print算子功能介绍](#print算子功能介绍) - [数据Dump功能介绍](#数据dump功能介绍) - - [同步Dump功能介绍](#同步dump功能介绍) - - [异步Dump功能介绍](#异步dump功能介绍) - - [Running Data Recorder](#Running-Data-Recorder) + - [同步Dump功能使用方法](#同步dump功能使用方法) + - [异步Dump功能使用方法](#异步dump功能使用方法) + - [Running Data Recorder](#running-data-recorder) - [使用方法](#使用方法) + - [通过配置文件配置RDR](#通过配置文件配置rdr) + - [通过环境变量配置RDR](#通过环境变量配置rdr) + - [异常处理](#异常处理) - [日志相关的环境变量和配置](#日志相关的环境变量和配置) @@ -262,136 +265,15 @@ Tensor(shape=[2, 2], dtype=Int32, value= ## 数据Dump功能介绍 -训练网络时,若训练结果和预期有偏差,可以通过数据Dump功能保存算子的输入输出进行调试。 +训练网络时,若训练结果和预期有偏差,可以通过数据Dump功能保存算子的输入输出进行调试。详细Dump功能介绍参考[Dump模式](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/dump_in_graph_mode.html#id4)。 ### 同步Dump功能使用方法 -同步Dump同时支持GPU和Ascend上的图模式,暂不支持PyNative模式。在Ascend上面开启Dump的时候,待Dump的算子会自动关闭内存复用。在网络占用内存不大的情况下,请优先使用同步Dump。若开启同步Dump后出现设备内存不足的报错,请使用下一节里面的异步Dump。 - -1. 创建配置文件`data_dump.json`。 - - JSON文件的名称和位置可以自定义设置。 - - ```json - { - "common_dump_settings": { - "dump_mode": 0, - "path": "/absolute_path", - "net_name": "ResNet50", - "iteration": 0, - "input_output": 0, - "kernels": ["Default/Conv-op12"], - "support_device": [0,1,2,3,4,5,6,7] - }, - "e2e_dump_settings": { - "enable": true, - "trans_flag": true - } - } - ``` - - - `dump_mode`:设置成0,表示Dump出该网络中的所有算子;设置成1,表示Dump`"kernels"`里面制定的算子。 - - `path`:Dump保存数据的绝对路径。 - - `net_name`:自定义的网络名称,例如:"ResNet50"。 - - `iteration`:指定需要Dump的迭代,若设置成0,表示Dump所有的迭代。 - - `input_output`:设置成0,表示Dump出算子的输入和算子的输出;设置成1,表示Dump出算子的输入;设置成2,表示Dump出算子的输出。该参数仅支持Ascend,GPU只能Dump算子的输出。 - - `kernels`:算子的名称列表。开启IR保存开关`context.set_context(save_graphs=True)`并执行用例,从生成的IR文件获取算子名称。例如,`device_target`为`Ascend`时,可以从`trace_code_graph_{graph_id}`中获取算子名称,`device_target`为`GPU`时,可以从`hwopt_pm_7_getitem_tuple.ir`中获取算子全称。详细说明可以参照教程:[借助IR图进行调试](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/dump_data_from_ir_files.html) - - `support_device`:支持的设备,默认设置成0到7即可;在分布式训练场景下,需要dump个别设备上的数据,可以只在`support_device`中指定需要Dump的设备Id。 - - `enable`:开启E2E Dump,如果同时开启同步Dump和异步Dump,那么只有同步Dump会生效。 - - `trans_flag`:开启格式转换。将设备上的数据格式转换成NCHW格式。 - -2. 指定Dump的json配置文件。 - - ```bash - export MINDSPORE_DUMP_CONFIG={Absolute path of data_dump.json} - ``` - - - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 - - 在分布式场景下,Dump环境变量需要调用`mindspore.communication.management.init`之前配置。 - -3. 执行用例Dump数据。 - - 可以在训练脚本中设置`context.set_context(reserve_class_name_in_scope=False)`,避免Dump文件名称过长导致Dump数据文件生成失败。 - -4. 解析Dump数据。 - - 同步Dump生成的数据文件是以`.bin`结尾的二进制文件,可以通过`numpy.fromfile`读取解析。 - - - Dump路径的命名规则为:`{path}/{net_name}/device_{device_id}/iteration_{iteration}/`。 - - Dump文件的命名规则为:`{算子名称}_{input_output_index}_{shape}_{data_type}_{format}.bin`。 - - 下面以一个简单网络的Dump为例,Dump生成的文件:`/absolute_path/ResNet50/device_0/iteration_0/Default--Add-op1_input_0_shape_1_3_3_4_Float32_DefaultFormat.bin`。 - 其中`Default--Add-op1`是算子名称,`input_0`是`{input_output_index}`,`shape_1_3_3_4`是`{shape}`,`Float32`是`{data_type}`,`DefaultFormat`是`{format}`。 +同步Dump功能使用参考[同步Dump操作步骤](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/dump_in_graph_mode.html#id6)。 ### 异步Dump功能使用方法 -异步Dump仅支持Ascend上的图模式,不支持PyNative模式。开启异步Dump的时候不会关闭内存复用。 - -1. 创建配置文件`data_dump.json`。 - - JSON文件的名称和位置可以自定义设置。 - - ```json - { - "common_dump_settings": { - "dump_mode": 0, - "path": "/absolute_path", - "net_name": "ResNet50", - "iteration": 0, - "input_output": 0, - "kernels": ["Default/Conv-op12"], - "support_device": [0,1,2,3,4,5,6,7] - }, - "async_dump_settings": { - "enable": true, - "op_debug_mode": 0 - } - } - ``` - - - `dump_mode`:设置成0,表示Dump出改网络中的所有算子;设置成1,表示Dump`"kernels"`里面指定的算子。 - - `path`:Dump保存数据的绝对路径。 - - `net_name`:自定义的网络名称,例如:"ResNet50"。 - - `iteration`:指定需要Dump的迭代。非数据下沉模式下,`iteration`需要设置成0,并且会Dump出每个迭代的数据。 - - `input_output`:设置成0,表示Dump出算子的输入和算子的输出;设置成1,表示Dump出算子的输入;设置成2,表示Dump出算子的输出。 - - `kernels`:算子的名称列表。开启IR保存开关`context.set_context(save_graphs=True)`并执行用例,从生成的`trace_code_graph_{graph_id}`IR文件中获取算子名称。`kernels`仅支持TBE算子、AiCPU算子、通信算子,若设置成通信算子的名称,将会Dump出通信算子的输入算子的数据。详细说明可以参照教程:[借助IR图进行调试](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/dump_data_from_ir_files.html) - - `support_device`:支持的设备,默认设置成0到7即可;在分布式训练场景下,需要dump个别设备上的数据,可以只在`support_device`中指定需要Dump的设备Id。 - - `enable`:开启异步Dump,如果同时开启同步Dump和异步Dump,那么只有同步Dump会生效。 - - `op_debug_mode`:该属性用于算子溢出调试,设置成0,表示不开启溢出;设置成1,表示开启AiCore溢出检测;设置成2,表示开启Atomic溢出检测;设置成3,表示开启全部溢出检测功能。在Dump数据的时候请设置成0,若设置成其他值,则只会Dump溢出算子的数据。 - -2. 设置数据Dump的环境变量。 - - ```bash - export MINDSPORE_DUMP_CONFIG={Absolute path of data_dump.json} - ``` - - - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 - - 在分布式场景下,Dump环境变量需要调用`mindspore.communication.management.init`之前配置。 - -3. 执行用例Dump数据。 - - 可以在训练脚本中设置`context.set_context(reserve_class_name_in_scope=False)`,避免Dump文件名称过长导致Dump数据文件生成失败。 - -4. 解析文件。 - - - Dump路径的命名规则为:`{path}/{device_id}/{net_name}_graph_{graph_id}/{graph_id}/{iteration}`。 - - Dump文件的命名规则为:`{op_type}.{op_name}.{task_id}.{timestamp}`。 - - 以一个简单网络的Dump结果为例:`Add.Default_Add-op1.2.161243956333802`,其中`Add`是`{op_type}`,`Default_Add-op1`是`{op_name}`,`2`是`{task_id}`,`161243956333802`是`{timestamp}`。 - - 使用run包中提供的`msaccucmp.pyc`解析Dump出来的文件。不同的环境上`msaccucmp.pyc`文件所在的路径可能不同,可以通过find命令进行查找: - - ```bash - find ${run包安装路径} -name "msaccucmp.pyc" - ``` - - 找到`msaccucmp.pyc`后,到`/absolute_path`目录下,运行如下命令解析Dump数据: - - ```bash - python ${msaccucmp.pyc的绝对路径} convert -d {原始的dump文件路径} -out {解析生成的文件路径} - ``` - - 若需要转换数据格式,可参考使用说明链接 。 +同步Dump功能使用参考[异步Dump操作步骤](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/dump_in_graph_mode#id11)。 ## Running Data Recorder diff --git a/tutorials/training/source_zh_cn/advanced_use/dump_data_from_ir_files.md b/tutorials/training/source_zh_cn/advanced_use/dump_data_from_ir_files.md deleted file mode 100644 index 1c0302ea40..0000000000 --- a/tutorials/training/source_zh_cn/advanced_use/dump_data_from_ir_files.md +++ /dev/null @@ -1,264 +0,0 @@ -# 借助IR图进行调试 - -`Linux` `Ascend` `GPU` `模型开发` `初级` `中级` `高级` - - - -- [借助IR图进行调试](#借助ir图进行调试) - - [概述](#概述) - - [生成IR文件](#生成ir文件) - - [IR文件内容介绍](#ir文件内容介绍) - - [从IR文件中Dump出想要的数据](#从ir文件中dump出想要的数据) - - - - - -## 概述 - -在图模式`context.set_context(mode=context.GRAPH_MODE)`下运行用MindSpore编写的模型时,若配置中设置了`context.set_context(save_graphs=True)`,运行时会输出一些图编译过程中生成的一些中间文件,我们称为IR文件,当前主要有三种格式的IR文件: - -- ir后缀结尾的IR文件:一种比较直观易懂的以文本格式描述模型结构的文件,可以直接用文本编辑软件查看。在下文中我们也将介绍此文件的查看方式。 -- dat后缀结尾的IR文件:一种相对于ir后缀结尾的文件格式定义更为严谨的描述模型结构的文件,包含的内容更为丰富,可以直接用文本编辑软件查看。 -- dot后缀结尾的IR文件:描述了不同节点间的拓扑关系,可以用[graphviz](http://graphviz.org)将此文件作为输入生成图片,方便用户直观地查看模型结构。对于算子比较多的模型,推荐使用可视化组件[MindInsight](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/dashboard.html#id5)对计算图进行可视化。 - -在本教程中,我们使用ModelZoo中的LeNet在Ascend环境上作为示范。相关的脚本可以在[ModelZoo/LeNet](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/lenet)找到。 - -## 生成IR文件 - -在`train.py`中,我们在`set_context`函数中添加如下代码,运行训练脚本时,MindSpore会自动将编译过程中产生的IR文件存放到指定路径。 - -```python -if __name__ == "__main__": - context.set_context(save_graphs=True, save_graphs_path="path/to/ir/files") -``` - - 在本教程中,我们运行的为单机版本的训练脚本。当运行的脚本使用多个计算设备时,MindSpore会为每一个计算设备生成一个独立的进程。因此我们建议用户在多卡版本的训练脚本中读取当前的计算设备id,从而为每个设备设置独立的`save_graphs_path`实现将每个设备的IR文件保存在不同的路径下。例如: - -```python -device_id = os.getenv("DEVICE_ID") -context.set_context(save_graphs=True, save_graphs_path="path/to/ir/files"+device_id) -``` - -执行训练命令后,在指定的目录生成如下文件。其中以数字下划线开头的IR文件是在ME编译图过程中输出的,`pipeline`各阶段分别会保存一次计算图。下面介绍比较重要的阶段,例如`parse`阶段会解析入口的`construct`函数;`symbol_resolve`阶段会递归解析入口函数直接或间接引用到的其他函数和对象;`abstract_specialize`阶段会做类型推导和`shape`推导;`optimize`阶段主要是进行和硬件无关的优化,自动微分与自动并行功能也是在该阶段展开;`validate`阶段会校验编译出来的计算图;`task_emit`阶段将计算图传给后端进一步处理;`execute`阶段会执行该计算图。 - -```bash -. -├── 00_parse_[xxxx].ir -├── 00_parse.dat -├── 00_parse.dot -├── 01_symbol_resolve_[xxxx].ir -├── 01_symbol_resolve.dat -├── 01_symbol_resolve.dot -├── 02_combine_like_graphs_[xxxx].ir -├── 02_combine_like_graphs.dat -├── 02_combine_like_graphs.dot -├── 03_inference_opt_prepare_[xxxx].ir -├── 03_inference_opt_prepare.dat -├── 03_inference_opt_prepare.dot -├── 04_abstract_specialize_[xxxx].ir -├── 04_abstract_specialize.dat -├── 04_abstract_specialize.dot -├── 05_inline_[xxxx].ir -├── 05_inline.dat -├── 05_inline.dot -├── 06_py_pre_ad_[xxxx].ir -├── 06_py_pre_ad.dat -├── 06_py_pre_ad.dot -├── 07_pipeline_split_[xxxx].ir -├── 07_pipeline_split.dat -├── 07_pipeline_split.dot -├── 08_optimize_[xxxx].ir -├── 08_optimize.dat -├── 08_optimize.dot -├── 09_py_opt_[xxxx].ir -├── 09_py_opt.dat -├── 09_py_opt.dot -├── 10_validate_[xxxx].ir -├── 10_validate.dat -├── 10_validate.dot -├── 11_task_emit_[xxxx].ir -├── 11_task_emit.dat -├── 11_task_emit.dot -├── 12_execute_[xxxx].ir -├── 12_execute.dat -├── 12_execute.dot -... -``` - -## IR文件内容介绍 - -下面以一个简单的例子来说明IR文件的内容。 - -```python -import mindspore.context as context -import mindspore.nn as nn -from mindspore import Tensor -from mindspore import dtype as mstype - -context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") -context.set_context(save_graphs=True, save_graphs_path="./ir_files") - -class Net(nn.Cell): - def __init__(self): - super().__init__() - - def construct(self, x, y): - x = x + y - x = x * y - return x - -x = Tensor(3, mstype.float32) -y = Tensor(2, mstype.float32) -net = Net() -out = net(x, y) -print(out) -``` - -使用文本编辑软件(例如vi)打开文件`12_execute_[xxxx].ir`,内容如下所示: - -```text - 1 #IR entry : @6_5_1_construct_wrapper.15 - 2 #attrs : - 3 check_set_strategy_valid_once_only : 1 - 4 #Total params : 2 - 5 - 6 %para1_x : - 7 %para2_y : - 8 - 9 #Total subgraph : 1 - 10 - 11 subgraph attr: - 12 check_set_strategy_valid_once_only : 1 - 13 subgraph @6_5_1_construct_wrapper.15() { - 14 %0([CNode]8) = Add(%para1_x, %para2_y) primitive_attrs: {output_names: [output], input_names: [x, y]} - 15 : (, ) -> () - 16 # In file /home/workspace/mindspore/mindspore/ops/composite/multitype_ops/add_impl.py(129)/ return F.add(x, y)/ - 17 # In file demo.py(14)/ x = x + y/ - 18 %1([CNode]10) = Mul(%0, %para2_y) primitive_attrs: {output_names: [output], input_names: [x, y]} - 19 : (, ) -> () - 20 # In file /home/workspace/mindspore/mindspore/ops/composite/multitype_ops/mul_impl.py(48)/ return F.tensor_mul(x, y)/ - 21 # In file demo.py(15)/ x = x * y/ - 22 return(%1) - 23 : () - 24 } -``` - -以上内容可分为两个部分,第一部分为输入列表,第二部分为图结构。 其中第1行告诉了我们该网络的顶图名称`@6_5_1_construct_wrapper.15`,也就是入口图。 第4行告诉了我们该网络有多少个输入。 第6-7行为输入列表,遵循`%para[序号]_[name] : <[data_type]x[shape]>`的格式。 第9行告诉我们该网络解析出来的子图数量。 第11-24行为图结构,含有若干节点,即`CNode`。该示例中只有2个节点,分别为14行的`Add`和18行的`Mul`。 - -`CNode`的信息遵循如下格式,包含节点名称、属性、输入节点、输出信息、格式、源码解析调用栈等信息,由于ANF图为单向无环图,所以这里仅根据输入关系体现节点与节点的连接关系。源码解析调用栈则体现了`CNode`与脚本源码之间的关系,例如第20行由第21行解析而来,而第21行能对应到脚本的`x = x * y`。 - -```text - %[序号]([debug_name]) = [OpName]([arg], ...) primitive_attrs: {[key]: [value], ...} - : (<[输入data_type]x[输入shape]>, ...) -> (<[输出data_type]x[输出shape]>, ...) - # 源码解析调用栈 -``` - -> 需要注意的是经过编译器的若干优化处理后,节点可能经过了若干变幻(如算子拆分、算子融合等),节点的源码解析调用栈信息与脚本可能无法完全一一对应,这里仅作为辅助手段。 - -## 从IR文件中Dump出想要的数据 - -下面的代码片段来自ModelZoo中LeNet示例中的`lenet.py`, 假设我们想要Dump出第一个卷积层也就是下述代码片段中的`x = self.conv1(x)`的数据。 - -```python -class LeNet5(nn.Cell): - def __init__(self, num_class=10, num_channel=1, include_top=True): - super(LeNet5, self).__init__() - self.conv1 = nn.Conv2d(num_channel, 6, 5, pad_mode='valid') - self.conv2 = nn.Conv2d(6, 16, 5, pad_mode='valid') - self.relu = nn.ReLU() - self.max_pool2d = nn.MaxPool2d(kernel_size=2, stride=2) - self.include_top = include_top - if self.include_top: - self.flatten = nn.Flatten() - self.fc1 = nn.Dense(16 * 5 * 5, 120, weight_init=Normal(0.02)) - self.fc2 = nn.Dense(120, 84, weight_init=Normal(0.02)) - self.fc3 = nn.Dense(84, num_class, weight_init=Normal(0.02)) - - - def construct(self, x): - x = self.conv1(x) - x = self.relu(x) - x = self.max_pool2d(x) - x = self.conv2(x) - x = self.relu(x) - x = self.max_pool2d(x) - if not self.include_top: - return x - x = self.flatten(x) - x = self.relu(self.fc1(x)) - x = self.relu(self.fc2(x)) - x = self.fc3(x) - return x -``` - -一般而言,后端的0图代表数据子图(若开启了数据下沉模式),1图代表主干网络,所以这里我们在Dump出来的`hwopt_d_end_graph_1_[xxxx].ir`文件中搜索`x = self.conv1(x)`,会得到4处结果,其中有3处为`Cast`和`TransData`。 越过该类精度转换、格式转换优化产生的`Cast`和`TransData`,我们最终定位到第213-221行,`%24(equivoutput) = Conv2D(%23, %19)...`,此处即对应网络中的`conv1`。从而在下方的信息中得到该算子在所编译的图中对应的op名(第216行的括号内,`Default/network-TrainOneStepWithLossScaleCell/network-WithLossCell/_backbone-LeNet5/conv1-Conv2d/Conv2D-op89`)。 - -```bash -... - 213 %24(equivoutput) = Conv2D(%23, %19) {instance name: conv2d} primitive_attrs: {pri_format: NC1HWC0, stride: (1, 1, 1, 1), pad: (0, 0, 0, 0), pad_mode: valid, out_channel: 6, mode: 1 , dilation: (1, 1, 1, 1), output_names: [output], group: 1, format: NCHW, visited: true, offset_a: 0, kernel_size: (5, 5), groups: 1, input_names: [x, w], pad_list: (0, 0, 0, 0), IsF eatureMapOutput: true, IsFeatureMapInputList: (0)} - 214 : (, ) -> () - 215 : (, ) -> () - 216 : (Default/network-TrainOneStepWithLossScaleCell/network-WithLossCell/_backbone-LeNet5/conv1-Conv2d/Conv2D-op89) - 217 # In file /home/workspace/mindspore/build/package/mindspore/nn/layer/conv.py(263)/ output = self.conv2d(x, self.weight)/ - 218 # In file /home/workspace/mindspore/model_zoo/official/cv/lenet/src/lenet.py(49)/ x = self.conv1(x)/ - 219 # In file /home/workspace/mindspore/build/package/mindspore/train/amp.py(101)/ out = self._backbone(data)/ - 220 # In file /home/workspace/mindspore/build/package/mindspore/nn/wrap/loss_scale.py(323)/ grads = self.grad(self.network, weights)(*inputs, scaling_sens_filled)/ - 221 # In file /home/workspace/mindspore/build/package/mindspore/train/dataset_helper.py(87)/ return self.network(*outputs)/ -... -``` - -得到算子的op名称之后,我们就可以执行Dump流程来保存算子的输入输出方便调试了。在这里我们介绍一种叫做同步Dump的方法。 - -1. 创建配置文件`data_dump.json`,该文件保存了需要Dump的算子信息,将我们在上一步中定位到的op名称复制到`kernels`键对应的列表内,关于该文件更多的信息,可以参考[自定义调试信息](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/custom_debugging_info.html#id5)。 - - ```json - { - "common_dump_settings": { - "dump_mode": 1, - "path": "/absolute_path", - "net_name": "LeNet", - "iteration": 0, - "input_output": 0, - "kernels": ["Default/network-TrainOneStepWithLossScaleCell/network-WithLossCell/_backbone-LeNet5/conv1-Conv2d/Conv2D-op89"], - "support_device": [0,1,2,3,4,5,6,7] - }, - "e2e_dump_settings": { - "enable": true, - "trans_flag": false - } - } - ``` - -2. 配置环境变量,指定配置文件的路径。 - - ```bash - export MINDSPORE_DUMP_CONFIG={Absolute path of data_dump.json} - ``` - -3. 执行用例Dump数据,在运行中MindSpore会Dump指定算子的输入输出数据到指定路径。 - - 在本例中,最后我们得到了如下文件,分别对应着该算子的输入和输出。 - - ```bash - . - ├── Default--network-TrainOneStepWithLossScaleCell--network-WithLossCell--_backbone-LeNet5--conv1-Conv2d--Conv2D-op89_input_0_shape_32_1_32_32_16_Float16_NC1HWC0.bin - ├── Default--network-TrainOneStepWithLossScaleCell--network-WithLossCell--_backbone-LeNet5--conv1-Conv2d--Conv2D-op89_input_1_shape_25_1_16_16_Float16_FracZ.bin - └── Default--network-TrainOneStepWithLossScaleCell--network-WithLossCell--_backbone-LeNet5--conv1-Conv2d--Conv2D-op89_output_0_shape_32_1_28_28_16_Float16_NC1HWC0.bin - ``` - -4. 解析Dump的数据。 - - 可以通过`numpy.fromfile`读取上一步生成的文件。读取后得到的`ndarray`即对应该算子的输入/输出。 - - ```python - import numpy - output = numpy.fromfile("Default--network-TrainOneStepWithLossScaleCell--network-WithLossCell--_backbone-LeNet5--conv1-Conv2d--Conv2D-op89_input_0_shape_32_1_32_32_16_Float16_NC1HWC0.bin") - print(output) - ``` - - 输出为: - - ```text - [1.17707155e-17 4.07526143e-17 5.84038559e-18 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] - ``` diff --git a/docs/programming_guide/source_zh_cn/dump.md b/tutorials/training/source_zh_cn/advanced_use/dump_in_graph_mode.md similarity index 53% rename from docs/programming_guide/source_zh_cn/dump.md rename to tutorials/training/source_zh_cn/advanced_use/dump_in_graph_mode.md index 200776d37d..238c3c9b78 100644 --- a/docs/programming_guide/source_zh_cn/dump.md +++ b/tutorials/training/source_zh_cn/advanced_use/dump_in_graph_mode.md @@ -1,32 +1,27 @@ -# 基于Dump功能对网络数据进行分析 +# 使用Dump功能在Graph模式调试 `Linux` `Ascend` `GPU` `模型调优` `中级` `高级` -- [基于Dump功能对网络数据进行分析](#基于dump功能对网络数据进行分析对比) +- [使用Dump功能在Graph模式调试](#使用dump功能在graph模式调试) - [概述](#概述) - - [使用场景](#使用场景) - - [整体流程](#整体流程) - - [ANF-IR介绍](#ANF-IR介绍) - - [IR文件获取](#IR文件获取) - - [使用IR文件进行调试](#使用IR文件进行调试) - - [Dump功能介绍](#dump功能介绍) - - [Dump模式](#dump模式) - - [同步Dump](#同步dump) - - [同步Dump操作步骤](#同步dump操作步骤) - - [同步Dump数据对象](#dump数据对象) - - [同步Dump数据格式介绍](#同步dump数据格式介绍) - - [同步Dump数据分析样例](#同步dump数据分析样例) - - [异步Dump](#异步dump) - - [异步Dump操作步骤](#异步dump操作步骤) - - [异步Dump数据对象](#dump数据对象) - - [异步Dump数据格式介绍](#异步dump数据格式介绍) - - [异步Dump数据格式样例](#异步dump数据格式样例) + - [适用场景](#适用场景) + - [Dump功能说明](#dump功能说明) + - [同步Dump](#同步dump) + - [同步Dump操作步骤](#同步dump操作步骤) + - [同步Dump数据对象目录](#同步dump数据对象目录) + - [同步Dump数据文件介绍](#同步dump数据文件介绍) + - [同步Dump数据分析样例](#同步dump数据分析样例) + - [异步Dump](#异步dump) + - [异步Dump操作步骤](#异步dump操作步骤) + - [异步Dump数据对象目录](#异步dump数据对象目录) + - [异步Dump数据文件介绍](#异步dump数据文件介绍) + - [异步Dump数据样例](#异步dump数据样例) -   + ## 概述 @@ -38,11 +33,11 @@ 本文针对静态图模式,介绍如何基于Dump功能对网络数据进行分析对比。 -### 使用场景 +### 适用场景 1. 静态图算子结果分析。 - 通过Dump功能获得的IR图可以了解脚本代码与执行算子的映射关系(详情见[使用IR文件进行调试](#使用ir文件进行调试))。结合执行算子的输入和输出数据,可以分析训练过程中可能存在的溢出、梯度爆炸与消失等问题,反向跟踪到脚本中可能存在问题的代码。 + 通过Dump功能获得的IR图,可以了解脚本代码与执行算子的映射关系(详情见[MindSpore IR简介](https://www.mindspore.cn/doc/note/zh-CN/master/design/mindspore/mindir.html#id2))。结合执行算子的输入和输出数据,可以分析训练过程中可能存在的溢出、梯度爆炸与消失等问题,反向跟踪到脚本中可能存在问题的代码。 2. 特征图分析。 @@ -52,41 +47,173 @@ 在将模型从第三方框架(TensorFlow、PyTorch)迁移到MindSpore的场景中,通过比对相同位置算子的输出数据,分析第三方框架和MindSpore对于同一模型的训练结果是否足够接近,来定位模型的精度问题。 -## 整体流程 +## Dump功能说明 + +MindSpore提供了同步Dump与异步Dump两种模式: + +- 同步Dump的机制是在网络训练过程中每个step执行结束后, Host侧发起Dump动作,从Device上拷贝算子地址里面的数据到Host,并保存文件。同步Dump会默认关闭算子间的内存复用,避免读到脏数据。 +- 异步Dump是专门针对Ascend整图下沉而开发的功能,可以一边执行算子一边dump数据,一个算子执行结束后立即dump数据,因此开启内存复用也可以生成正确的数据,但是相应的网络训练的速度会较慢。 + +不同模式所需要的配置文件和dump出来的数据格式不同: + +- 同步模式较异步模式会占用更多内存,但易用性更好。 +- 一般对于中小型网络(如ResNet)等,推荐优先使用同步Dump模式。在网络占用内存不大的情况下,请优先使用同步Dump。若开启同步Dump后,因为模型过大导致需要的内存超过系统限制,再使用异步Dump。 +- 在Ascend上开启同步Dump的时候,待Dump的算子会自动关闭内存复用。 +- 同步Dump目前支持Ascend和GPU上的图模式,暂不支持CPU和PyNative模式。 +- 异步Dump仅支持Ascend上的图模式,不支持PyNative模式。开启异步Dump的时候不会关闭内存复用。 + +Dump功能需要使用到最终执行图的IR文件,IR文件可以用`vi`命令查看。IR文件中包含了算子全名,和算子在计算图中输入和输出的依赖,也包含从算子到相应脚本代码的Trace信息: + +- 使用Dump功能将根据json配置文件里的配置自动生成最终执行图的IR文件,Dump功能的配置见[同步Dump操作步骤](#id6)和[异步Dump操作步骤](#id11),最终执行图IR文件命名和目录结构见[同步Dump数据对象目录](#id7)和[异步Dump数据对象目录](#id12)。 +- 也可以在运行MindSpore脚本时,配置`context.set_context(save_graphs=True, save_graphs_path=“xxx”)`,会在指定路径"xxx"下(默认为脚本执行目录)保存图编译过程中生成的一些中间文件(IR文件),通过这些IR文件可以查看分析整个计算图的变换优化过程。`set_context`的详情可参考[mindspore.context API](https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/mindspore.context.html#mindspore.context.set_context) 。 + +Dump整体过程: 1. 从脚本找到对应的算子 - 首先利用Dump功能获取相关的IR图文件,参考[IR文件获取](#ir文件获取)。然后通过图文件找到脚本中代码对应的算子,参考[使用IR文件进行调试](#使用ir文件进行调试)。 + 首先利用Dump功能获取相关的IR图文件,参考[如何保存IR](https://www.mindspore.cn/doc/note/zh-CN/master/design/mindspore/mindir.html#id5)。然后通过图文件找到脚本中代码对应的算子,参考[同步Dump数据分析样例](#id9)。 2. 从算子到Dump数据 - 在了解脚本和算子的映射关系后,可以确定想要分析的算子名称,从而找到算子对应的dump文件,参考[同步Dump数据对象](#同步dump数据对象)和[异步Dump数据对象](#异步dump数据对象)。 + 在了解脚本和算子的映射关系后,可以确定想要分析的算子名称,从而找到算子对应的dump文件,参考[同步Dump数据对象目录](#id7)和[异步Dump数据对象目录](#id12)。 3. 分析Dump数据 - 通过解析Dump数据,可以与其他第三方框架进行对比。同步Dump数据格式参考[同步Dump数据格式介绍](#同步dump数据格式介绍),异步Dump数据格式参考[异步Dump数据格式介绍](#异步dump数据格式介绍)。 + 通过解析Dump数据,可以与其他第三方框架进行对比。同步Dump数据格式参考[同步Dump数据文件介绍](#id8),异步Dump数据格式参考[异步Dump数据格文件介绍](#id13)。 + +## 同步Dump + +### 同步Dump操作步骤 + +1. 创建json格式的配置文件,JSON文件的名称和位置可以自定义设置。 + + ```json + { + "common_dump_settings": { + "dump_mode": 0, + "path": "/absolute_path", + "net_name": "ResNet50", + "iteration": 0, + "input_output": 0, + "kernels": ["Default/Conv-op12"], + "support_device": [0,1,2,3,4,5,6,7] + }, + "e2e_dump_settings": { + "enable": true, + "trans_flag": true + } + } + ``` + + - `dump_mode`:设置成0,表示Dump出该网络中的所有算子;设置成1,表示Dump`"kernels"`里面制定的算子。 + - `path`:Dump保存数据的绝对路径。 + - `net_name`:自定义的网络名称,例如:"ResNet50"。 + - `iteration`:指定需要Dump的迭代,若设置成0,表示Dump所有的迭代。 + - `input_output`:设置成0,表示Dump出算子的输入和算子的输出;设置成1,表示Dump出算子的输入;设置成2,表示Dump出算子的输出。该参数仅支持Ascend,GPU只能Dump算子的输出。 + - `kernels`:算子的名称列表。开启IR保存开关`context.set_context(save_graphs=True)`并执行用例,从生成的IR文件获取算子名称。例如,`device_target`为`Ascend`时,可以从`trace_code_graph_{graph_id}`中获取算子名称,`device_target`为`GPU`时,可以从`hwopt_pm_7_getitem_tuple.ir`中获取算子全称。详细说明可以参照教程:[如何保存IR](https://www.mindspore.cn/doc/note/zh-CN/master/design/mindspore/mindir.html#id5)。 + - `support_device`:支持的设备,默认设置成0到7即可;在分布式训练场景下,需要dump个别设备上的数据,可以只在`support_device`中指定需要Dump的设备Id。 + - `enable`:开启E2E Dump,如果同时开启同步Dump和异步Dump,那么只有同步Dump会生效。 + - `trans_flag`:开启格式转换。将设备上的数据格式转换成NCHW格式。若为`True`,则数据会以Host侧的4D格式(NCHW)格式保存;若为`False`,则保留Device侧的数据格式。 + +2. 设置Dump环境变量,指定Dump的json配置文件。 -## ANF-IR介绍 + ```bash + export MINDSPORE_DUMP_CONFIG=${xxx} + ``` -中间表示(IR)是程序编译过程中介于源语言和目标语言之间的程序表示,以方便编译器进行程序分析和优化,因此IR的设计需要考虑从源语言到目标语言的转换难度,同时考虑程序分析和优化的易用性和性能。 + 其中"xxx"为配置文件的绝对路径,如: -MindIR是一种基于图表示的函数式IR,其最核心的目的是服务于自动微分变换。自动微分采用的是基于函数式编程框架的变换方法,因此IR采用了接近于ANF函数式的语义。 + ```bash + export MINDSPORE_DUMP_CONFIG=/path/to/data_dump.json + ``` + + 注意: + + - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 + - 在分布式场景下,Dump环境变量需要调用`mindspore.communication.management.init`之前配置。 + +3. 启动网络训练脚本。 + + 训练启动后,若正确配置了`MINDSPORE_DUMP_CONFIG`环境变量,则会读取配置文件的内容,并按照Dump配置中指定的数据保存路径保存算子数据。 + 同步模式下,如果要Dump数据,必须采用非数据下沉模式(设置`model.train`或`DatasetHelper`中的`dataset_sink_mode`参数为`False`),以保证可以获取每个step的Dump数据。 + 若脚本中都不调用`model.train`或`DatasetHelper`,则默认为非数据下沉模式。使用Dump功能将自动生成最终执行图的IR文件。 -关于ANF-IR的具体介绍,可以参考[MindSpore IR 文法定义](https://www.mindspore.cn/doc/note/zh-CN/master/design/mindspore/mindir.html#id2) 。 + 可以在训练脚本中设置`context.set_context(reserve_class_name_in_scope=False)`,避免Dump文件名称过长导致Dump数据文件生成失败。 -### IR文件获取 +4. 解析Dump数据。 -使用Dump功能将自动生成最终执行图的IR文件,Dump功能的配置见[同步Dump操作步骤](#同步dump操作步骤)和[异步Dump操作步骤](#异步dump操作步骤),最终执行图IR文件命名和目录结构见[同步Dump数据对象](#同步dump数据对象)和[异步Dump数据对象](#异步dump数据对象)。 + 同步Dump生成的数据文件是以`.bin`结尾的二进制文件,可以通过`numpy.fromfile`读取解析。 -也可以在运行MindSpore脚本时,配置`context.set_context(save_graphs=True, save_graphs_path=“xxx”)`,会在指定路径"xxx"下(默认为脚本执行目录)保存图编译过程中生成的一些中间文件(IR文件),通过这些IR文件可以查看分析整个计算图的变换优化过程。 `set_context`的详情可参考[mindspore.context API](https://www.mindspore.cn/doc/api_python/zh-CN/master/mindspore/mindspore.context.html#mindspore.context.set_context) 。 + - Dump路径的命名规则为:`{path}/{net_name}/device_{device_id}/iteration_{iteration}/`。 + - Dump文件的命名规则为:`{算子名称}_{input_output_index}_{shape}_{data_type}_{format}.bin`。 -IR文件可以用`vi`命令查看。IR文件中包含了算子全名,和算子在计算图中输入和输出的依赖,也包含从算子到相应脚本代码的Trace信息。 + 下面以一个简单网络的Dump为例,Dump生成的文件:`/absolute_path/ResNet50/device_0/iteration_0/Default--Add-op1_input_0_shape_1_3_3_4_Float32_DefaultFormat.bin`。 + 其中`Default--Add-op1`是算子名称,`input_0`是`{input_output_index}`,`shape_1_3_3_4`是`{shape}`,`Float32`是`{data_type}`,`DefaultFormat`是`{format}`。 -### 使用IR文件进行调试 +### 同步Dump数据对象目录 -对于Ascend场景,在通过Dump功能将脚本对应的图保存到磁盘上后,会产生最终执行图`ms_output_trace_code_graph_{graph_id}.ir`。该文件中保存了对应的图中每个算子的堆栈信息,记录了算子对应的生成脚本 。 +启动训练后,同步Dump保存的数据对象包括最终执行图(`ms_output_trace_code_graph_{graph_id}.ir`文件)以及图中算子的输入和输出数据,数据目录结构如下所示: -以Alexnet脚本为例: +```text +{path}/ + |-- {net_name}/ + |-- {device_id}/ + |-- iteration_{iteration}/ + -- {op_name}_{input_output_index}_{shape}_{data_type}_{format}.bin + … + |-- graphs/ + ms_output_trace_code_graph_{graph_id}.pb + ms_output_trace_code_graph_{graph_id}.ir + |-- execution_order/ + ms_execution_order_graph_{graph_id}.csv + + |-- .metadata/ + data_dump.json +``` + +- `path`:`data_dump.json`配置文件中设置的绝对路径。 +- `net_name`:`data_dump.json`配置文件中设置的网络名称。 +- `device_id`:训练的卡号。 +- `graph_id`:训练的图标号。 +- `iteration`:训练的轮次。 +- `operator_name`:算子名称。 +- `input_output_index` :输入或输出标号,例如`output_0`表示该文件是该算子的第1个输出Tensor的数据。 +- `shape`: 张量维度信息。 +- `data_type`: 数据类型。 +- `format`: 数据格式。 + +### 同步Dump数据文件介绍 + +同步Dump生成的数据文件是后缀名为`.bin`的二进制文件,文件命名格式为: + +```text +{operator_name}_{input_output_index}_{shape}_{data_type}_{format}.bin +``` + +根据文件名提供的`Tensor`信息,可以用`numpy.fromfile`读取数据,并还原原始数据的`data_type`和`shape`。 + +同步Dump生成的最终执行图文件后缀名分别为`.pb`和`.ir`,文件命名格式为: + +```text +ms_output_trace_code_graph_{graph_id}.pb +ms_output_trace_code_graph_{graph_id}.ir +``` + +其中以`.ir`为后缀的文件可以通过`vi`命令打开查看。 + +同步Dump生成的节点执行序文件后缀名为`.csv`,文件命名格式为: + +```text +ms_execution_order_graph_{graph_id}.csv +``` + +`.metadata`记录了训练的原信息,其中`data_dump.json`保存了用户设置的dump配置。 + +### 同步Dump数据分析样例 + +对于Ascend场景,在通过Dump功能将脚本对应的图保存到磁盘上后,会产生最终执行图文件`ms_output_trace_code_graph_{graph_id}.ir`。该文件中保存了对应的图中每个算子的堆栈信息,记录了算子对应的生成脚本。 + +以[AlexNet脚本](https://gitee.com/mindspore/mindspore/blob/master/model_zoo/official/cv/alexnet/src/alexnet.py)为例 : ```python import mindspore.nn as nn @@ -154,126 +281,13 @@ class AlexNet(nn.Cell): return x ``` -若要定位第58行代码`x = self.conv3(x)`的问题,可以在该脚本生成的`ms_output_trace_code_graph_{graph_id}.ir`文件中搜索该行代码,可以找到多个相关算子。如[同步Dump数据格式介绍](#同步dump数据格式介绍)所示,`Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/Conv2D-op107`就是其中之一的算子。 - -后续可以参考[同步Dump数据对象](#同步dump数据对象),找到算子对应的dump文件。 - -## Dump功能介绍 - -### Dump模式 - -MindSpore提供了同步Dump与异步Dump两种模式。不同模式所需要的配置文件和dump出来的数据格式不同。 - -- 同步模式较异步模式会占用更多内存,但易用性更好。 - -- 一般对于中小型网络(如ResNet)等,推荐优先使用同步Dump模式。如果因为模型过大导致需要的内存超过系统限制,再使用异步Dump。 - -- 同步Dump目前支持Ascend和GPU,暂不支持CPU。 - -- 异步Dump目前仅支持Ascend。 - -### 同步Dump - -同步Dump的机制是在网络训练过程中每个step执行结束后, Host侧发起Dump动作,从Device上拷贝算子地址里面的数据到Host,并保存文件。同步Dump会默认关闭算子间的内存复用,避免读到脏数据。 - -#### 同步Dump操作步骤 - -1. 创建json格式的配置文件 - - 创建一个json格式的文件作为Dump的配置文件,如`data_dump.json`。 - 配置文件的内容规范介绍详见[同步Dump功能介绍](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/custom_debugging_info.html#id4) 。 - - 若配置文件中`trans_flag`为`True`,则数据会以Host侧的4D格式(NCHW)格式保存,若为`False`,则保留Device侧的数据格式。 - 若需要Dump全量或部分算子,则可以详见参考配置文件中的[dump_mode](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/custom_debugging_info.html#id4) 介绍。 - -2. 设置Dump环境变量 - - ```bash - export MINDSPORE_DUMP_CONFIG=${xxx} - ``` - - 其中"xxx"为配置文件的绝对路径,如: - - ```bash - export MINDSPORE_DUMP_CONFIG=/path/to/data_dump.json - ``` - -3. 启动训练 - - 训练启动后,若正确配置了`MINDSPORE_DUMP_CONFIG`环境变量,则会读取配置文件的内容,并按照Dump配置中指定的路径保存算子数据。 - 同步模式下,如果要Dump数据,必须采用非数据下沉模式(设置`model.train`或`DatasetHelper`中的`dataset_sink_mode`参数为`False`),以保证可以获取每个step的Dump数据。 - 若脚本中都不调用`model.train`或`DatasetHelper`,则默认为非数据下沉模式。使用Dump功能将自动生成最终执行图的IR文件。 - -### 同步Dump数据对象 - -同步Dump数据对象目录结构: - -```text -{path}/ - |-- {net_name}/ - |-- {device_id}/ - |-- iteration_{iteration}/ - -- {op_name}_{input_output_index}_{shape}_{data_type}_{format}.bin - … - |-- graphs/ - ms_output_trace_code_graph_{graph_id}.pb - ms_output_trace_code_graph_{graph_id}.ir - |-- execution_order/ - ms_execution_order_graph_{graph_id}.csv - - |-- .metadata/ - data_dump.json -``` - -- `path`:`data_dump.json`文件中设置的绝对路径。 -- `net_name`:`data_dump.json`文件中设置的网络名称。 -- `device_id`:训练的卡号。 -- `graph_id`:训练的图标号。 -- `iteration`:训练的轮次。 -- `operator_name`:算子名称。 -- `input_output_index` :输入或输出标号,例如`output_0`表示该文件是该算子的第1个输出Tensor的数据。 -- `shape`: 张量维度信息。 -- `data_type`: 数据类型。 -- `format`: 数据格式。 - -Dump功能保存数据的对象就是最终执行图以及图中算子的输入和输出数据。 - -#### 同步Dump数据格式介绍 - -同步Dump生成的数据文件是后缀名为`.bin`的二进制文件,文件命名格式为: - -```text -{operator_name}_{input_output_index}_{shape}_{data_type}_{format}.bin -``` - -根据文件名提供的`Tensor`信息,可以用`numpy.fromfile`读取数据,并还原原始数据的`data_type`和`shape`。 - -同步Dump生成的最终执行图文件后缀名分别为`.pb`和`.ir`,文件命名格式为: - -```text -ms_output_trace_code_graph_{graph_id}.pb -ms_output_trace_code_graph_{graph_id}.ir -``` - -其中以`.ir`为后缀的文件可以通过`vi`命令打开查看 - -同步Dump生成的节点执行序文件后缀名为`.csv`,文件命名格式为: - -```text -ms_execution_order_graph_{graph_id}.csv -``` - -`.metadata`记录了训练的原信息,其中`data_dump.json`保存了用户设置的dump配置。 - -#### 同步Dump数据分析样例 - -以[alexnet脚本为例](https://gitee.com/mindspore/mindspore/blob/master/model_zoo/official/cv/alexnet/src/alexnet.py) ,如果用户想查看脚本中第58行的代码: +如果用户想查看脚本中第58行的代码: ```python x = self.conv3(x) ``` -可以从最终执行图中查找到该行代码所对应的多个算子,如下所示: +执行完训练网络后,可以从最终执行图(`ms_output_trace_code_graph_{graph_id}.ir`文件)中查找到该行代码所对应的多个算子信息,文件内容如下所示: ```text %24(equivoutput) = Conv2D(%23, %21) {instance name: conv2d} primitive_attrs: {compile_info: , pri_format: NC1HWC0, stride: (1, 1, 1, 1), pad: (0, 0, 0, 0), pad_mod: same, out_channel: @@ -295,26 +309,26 @@ IsFeatureMapOutput: true, IsFeatureMapInputList: (0), pri_format: NC1HWC0} ... ``` -最终执行图中各行所表示的含义如下: +以上所示文件内容的各行所表示的含义如下: - 算子在Host侧(第一行)和Device侧(第二行,有些算子可能不存在)的输入输出情况。从执行图可知,该算子有两个输入(箭头左侧),一个输出(箭头右侧)。 -```text - : (, ) -> () - : (, ) -> () -``` + ```text + : (, ) -> () + : (, ) -> () + ``` - 算子名称。从执行图可知,该算子在最终执行图中的完整名称为`Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/Conv2D-op107`。 -```text - : (Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/Conv2D-op107) -``` + ```text + : (Default/network-WithLossCell/_backbone-AlexNet/conv3-Conv2d/Conv2D-op107) + ``` - 算子对应的训练脚本代码。通过搜索要查询的训练脚本代码,可以找到多个匹配的算子。 -```text - # In file {Absolute path of model_zoo}/official/cv/alexnet/src/alexnet.py(58)/ x = self.conv3(x)/ -``` + ```text + # In file {Absolute path of model_zoo}/official/cv/alexnet/src/alexnet.py(58)/ x = self.conv3(x)/ + ``` 通过算子名称和输入输出信息,可以查找到唯一对应的Tensor数据文件。比如,若要查看Conv2D-op107算子的第1个输出数据对应的Dump文件,可获取以下信息: @@ -322,7 +336,7 @@ IsFeatureMapOutput: true, IsFeatureMapInputList: (0), pri_format: NC1HWC0} - `input_output_index` :`output_0`表示该文件是该算子的第1个输出Tensor的数据。 -在Dump目录下搜索到相应的文件名: +在Dump保存的数据对象文件目录下搜索到相应的文件名: `Default--network-WithLossCell--_backbone-AlexNet--conv3-Conv2d--Conv2D-op107_output_0_shape_32_12_13_13_16_Float16_NC1HWC0.bin`。 从文件名中可以得知以下信息: @@ -348,27 +362,92 @@ numpy.reshape(array, (32,12,13,13,16)) 还原到原始shape数据。 -### 异步Dump +## 异步Dump 大型网络(如Bert Large)使用同步Dump时会导致内存溢出,MindSpore通过异步Dump提供了大型网络的调试能力。 -异步Dump是专门针对Ascend整图下沉而开发的功能,可以一边执行算子一边dump数据,一个算子执行结束后立即dump数据,因此开启内存复用也可以生成正确的数据,但是相应的网络训练的速度会较慢。 +### 异步Dump操作步骤 -#### 异步Dump操作步骤 +1. 创建配置文件`data_dump.json`。 -- 异步Dump的操作步骤与同步Dump的操作步骤一致,只有配置文件的内容和数据解析方式不同。 异步Dump的配置文件内容规范详见[异步Dump功能介绍](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/custom_debugging_info.html#id4) + JSON文件的名称和位置可以自定义设置。 -- 若需要dump全量或部分算子,则可以详见参考配置文件中的[dump_mode](https://www.mindspore.cn/tutorial/training/zh-CN/master/advanced_use/custom_debugging_info.html#id5) 介绍。 + ```json + { + "common_dump_settings": { + "dump_mode": 0, + "path": "/absolute_path", + "net_name": "ResNet50", + "iteration": 0, + "input_output": 0, + "kernels": ["Default/Conv-op12"], + "support_device": [0,1,2,3,4,5,6,7] + }, + "async_dump_settings": { + "enable": true, + "op_debug_mode": 0 + } + } + ``` -- 若开启数据下沉功能(设置`model.train`或`DatasetHelper`中的`dataset_sink_mode`参数为`True`),只能dump出配置文件里指定的一个step的数据(此时`iteration 0`表示第0个step),并保存到指定目录下。 + - `dump_mode`:设置成0,表示Dump出改网络中的所有算子;设置成1,表示Dump`"kernels"`里面指定的算子。 + - `path`:Dump保存数据的绝对路径。 + - `net_name`:自定义的网络名称,例如:"ResNet50"。 + - `iteration`:指定需要Dump的迭代。非数据下沉模式下,`iteration`需要设置成0,并且会Dump出每个迭代的数据。 + - `input_output`:设置成0,表示Dump出算子的输入和算子的输出;设置成1,表示Dump出算子的输入;设置成2,表示Dump出算子的输出。 + - `kernels`:算子的名称列表。开启IR保存开关`context.set_context(save_graphs=True)`并执行用例,从生成的`trace_code_graph_{graph_id}`IR文件中获取算子名称。`kernels`仅支持TBE算子、AiCPU算子、通信算子,若设置成通信算子的名称,将会Dump出通信算子的输入算子的数据。详细说明可以参照教程:[如何保存IR](https://www.mindspore.cn/doc/note/zh-CN/master/design/mindspore/mindir.html#id5)。 + - `support_device`:支持的设备,默认设置成0到7即可;在分布式训练场景下,需要dump个别设备上的数据,可以只在`support_device`中指定需要Dump的设备Id。 + - `enable`:开启异步Dump,如果同时开启同步Dump和异步Dump,那么只有同步Dump会生效。 + - `op_debug_mode`:该属性用于算子溢出调试,设置成0,表示不开启溢出;设置成1,表示开启AiCore溢出检测;设置成2,表示开启Atomic溢出检测;设置成3,表示开启全部溢出检测功能。在Dump数据的时候请设置成0,若设置成其他值,则只会Dump溢出算子的数据。 -- 若不开启数据下沉功能(设置`model.train`或`DatasetHelper`中的`dataset_sink_mode`参数为`False`),配置文档里`iteration`必须指定为0,所有step的数据都保存在一个目录中,无法支持多step的数据管理。此时建议只执行一次step的数据Dump(可以通过修改脚本只训练一个step)。 +2. 设置数据Dump的环境变量。 + + ```bash + export MINDSPORE_DUMP_CONFIG={Absolute path of data_dump.json} + ``` + + - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 + - 在分布式场景下,Dump环境变量需要调用`mindspore.communication.management.init`之前配置。 + +3. 执行用例Dump数据。 + + 可以在训练脚本中设置`context.set_context(reserve_class_name_in_scope=False)`,避免Dump文件名称过长导致Dump数据文件生成失败。 + +4. 解析Dump文件。 + + 1. 解读命名规则。 + + - Dump路径的命名规则为:`{path}/{device_id}/{net_name}_graph_{graph_id}/{graph_id}/{iteration}`。 + - Dump文件的命名规则为:`{op_type}.{op_name}.{task_id}.{timestamp}`。 + + 以一个简单网络的Dump结果为例:`Add.Default_Add-op1.2.161243956333802`,其中`Add`是`{op_type}`,`Default_Add-op1`是`{op_name}`,`2`是`{task_id}`,`161243956333802`是`{timestamp}`。 + 2. 使用run包中提供的`msaccucmp.pyc`解析Dump出来的文件。不同的环境上`msaccucmp.pyc`文件所在的路径可能不同,可以通过`find`命令进行查找: + + ```bash + find ${run_path} -name "msaccucmp.pyc" + ``` + + - `run_path`:run包的安装路径。 + + 3. 找到`msaccucmp.pyc`后,到`/absolute_path`目录下,运行如下命令解析Dump数据: + + ```bash + python ${The absolute path of msaccucmp.pyc} convert -d {file path of dump} -out {file path of output} + ``` + + 若需要转换数据格式,可参考使用说明链接 。 + +注意: + +- 若需要dump全量或部分算子,则可以修改json配置文件中的`dump_mode`选项为0或1。 +- 若开启数据下沉功能(设置`model.train`或`DatasetHelper`中的`dataset_sink_mode`参数为`True`),只能dump出配置文件里指定的一个step的数据(此时`iteration 0`表示第0个step),并保存到指定目录下。 +- 若不开启数据下沉功能(设置`model.train`或`DatasetHelper`中的`dataset_sink_mode`参数为`False`),配置文档里`iteration`必须指定为0,所有step的数据都保存在一个目录中,无法支持多step的数据管理。此时建议只执行一次step的数据Dump(可以通过修改脚本只训练一个step)。 - 使用Dump功能将自动生成最终执行图的IR文件。 -### 异步Dump数据对象 +### 异步Dump数据对象目录 -同步Dump数据对象目录结构: +异步Dump保存的数据对象包括了最终执行图(`ms_output_trace_code_graph_{graph_id}.ir`文件)以及图中算子的输入和输出数据,目录结构如下所示: ```text {path}/ @@ -398,11 +477,9 @@ numpy.reshape(array, (32,12,13,13,16)) - `taskid`:任务标号。 - `timestamp`:时间戳。 -Dump功能保存数据的对象就是最终执行图以及图中算子的输入和输出数据。 +### 异步Dump数据文件介绍 -#### 异步Dump数据格式介绍 - -异步Dump生成的原始数据文件是protobuf格式的文件,需要用到海思Run包中自带的数据解析工具进行解析,详见[使用文档](https://support.huaweicloud.com/tg-Inference-cann/atlasaccuracy_16_0014.html) 。 +启动训练后,异步Dump生成的原始数据文件是protobuf格式的文件,需要用到海思Run包中自带的数据解析工具进行解析,详见[使用文档](https://support.huaweicloud.com/tg-Inference-cann/atlasaccuracy_16_0014.html) 。 数据在Device侧的格式可能和Host侧计算图中的定义不同,异步Dump的数据格式为Device侧格式,如果想要转为Host侧格式,可以参考[使用文档](https://support.huaweicloud.com/tg-Inference-cann/atlasaccuracy_16_0013.html) 。 @@ -414,19 +491,19 @@ Dump功能保存数据的对象就是最终执行图以及图中算子的输入 如果`op_type`和`op_name`中出现了“.”、“/”、“\”、空格时,会转换为下划线表示。 -异步Dump生成的最终执行图文件和节点执行序文件命名规则与同步Dump相同 +异步Dump生成的最终执行图文件和节点执行序文件命名规则与同步Dump相同,可以参考[同步Dump数据文件介绍](#id7)。 -#### 异步Dump数据格式样例 +### 异步Dump数据样例 -通过异步Dump的功能,获取到算子的异步Dump的文件,如: +通过异步Dump的功能,获取到算子异步Dump生成的数据文件,如: ```text -dump_file: "BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_feature_map-YOLOv3_backblock0-YoloBlock_conv3-SequentialCell_1-BatchNorm2d_BNTrainingUpdate-op5489.137.1608983934774491" +BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_feature_map-YOLOv3_backblock0-YoloBlock_conv3-SequentialCell_1-BatchNorm2d_BNTrainingUpdate-op5489.137.1608983934774491 ``` 执行: -```text +```bash python3.7.5 msaccucmp.pyc convert -d BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_feature_map-YOLOv3_backblock0-YoloBlock_conv3-SequentialCell_1-BatchNorm2d_BNTrainingUpdate-op5489.137.1608983934774491 -out ./output -f NCHW -t npy ``` @@ -448,7 +525,7 @@ BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_f BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_feature_map-YOLOv3_backblock0-YoloBlock_conv3-SequentialCell_1-BatchNorm2d_BNTrainingUpdate-op5489.137.1608983934774491.output.4.1x1024x1x1.npy ``` -在文件名的末尾可以看到该文件是算子的第几个输入或输出,以及数据的维度信息。例如,通过第一个文件名 +在文件名的末尾可以看到该文件是算子的第几个输入或输出,以及数据的维度信息。例如,通过第一个`.npy`文件名 ```text BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_feature_map-YOLOv3_backblock0-YoloBlock_conv3-SequentialCell_1-BatchNorm2d_BNTrainingUpdate-op5489.137.1608983934774491.input.0.30x1024x17x17.npy @@ -461,4 +538,4 @@ BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_f ```python import numpy numpy.load("BNTrainingUpdate.Default_network-YoloWithLossCell_yolo_network-YOLOV3DarkNet53_feature_map-YOLOv3_backblock0-YoloBlock_conv3-SequentialCell_1-BatchNorm2d_BNTrainingUpdate-op5489.137.1608983934774491.input.0.30x1024x17x17.npy") -``` \ No newline at end of file +``` diff --git a/tutorials/training/source_zh_cn/index.rst b/tutorials/training/source_zh_cn/index.rst index f10a8a8b06..30a02f23e5 100644 --- a/tutorials/training/source_zh_cn/index.rst +++ b/tutorials/training/source_zh_cn/index.rst @@ -58,7 +58,7 @@ :hidden: advanced_use/debug_in_pynative_mode - advanced_use/dump_data_from_ir_files + advanced_use/dump_in_graph_mode advanced_use/custom_debugging_info advanced_use/visualization_tutorials advanced_use/enable_auto_augmentation -- Gitee From 09bc2c8039c28c5a5540c1c640d5a4eaf0d0524a Mon Sep 17 00:00:00 2001 From: liuchongming Date: Wed, 24 Mar 2021 19:37:14 +0800 Subject: [PATCH 11/11] Add security warning of model file. --- .../source_en/advanced_use/migrate_3rd_scripts_mindconverter.md | 1 + .../advanced_use/migrate_3rd_scripts_mindconverter.md | 1 + 2 files changed, 2 insertions(+) diff --git a/tutorials/training/source_en/advanced_use/migrate_3rd_scripts_mindconverter.md b/tutorials/training/source_en/advanced_use/migrate_3rd_scripts_mindconverter.md index 930600cb48..405141fb69 100644 --- a/tutorials/training/source_en/advanced_use/migrate_3rd_scripts_mindconverter.md +++ b/tutorials/training/source_en/advanced_use/migrate_3rd_scripts_mindconverter.md @@ -272,3 +272,4 @@ The example of weight map refers to that in **TensorFlow Model Scripts Conversio 3. This script conversion tool relies on operators which supported by MindConverter and MindSpore. Unsupported operators may not be successfully mapped to MindSpore operators. You can manually edit, or implement the mapping based on MindConverter, and contribute to our MindInsight repository. We appreciate your support for the MindSpore community. 4. MindConverter converts dynamic input shape to constant one based on `--shape` while using grpah based scheme, as a result, it is required that inputs' shape used to retrain or inference in MindSpore are the same as that used to convert using MindConverter. If the input shape has changed, please re-running MindConverter with new `--shape` or fixing shape related parameters in the old script. 5. MindSpore script, MindSpore checkpoint file and weight map file are saved in the same file folder path. +6. The security and consistency of the model file should be guaranteed by the user. diff --git a/tutorials/training/source_zh_cn/advanced_use/migrate_3rd_scripts_mindconverter.md b/tutorials/training/source_zh_cn/advanced_use/migrate_3rd_scripts_mindconverter.md index 2fe0b2ca1c..443519101c 100644 --- a/tutorials/training/source_zh_cn/advanced_use/migrate_3rd_scripts_mindconverter.md +++ b/tutorials/training/source_zh_cn/advanced_use/migrate_3rd_scripts_mindconverter.md @@ -272,3 +272,4 @@ mindconverter --model_file /home/user/xxx/model.onnx --shape 1,3,224,224 \ 3. 脚本转换工具本质上为算子驱动,对于MindConverter未维护的ONNX算子与MindSpore算子映射,将会出现相应的算子无法转换的问题,对于该类算子,用户可手动修改,或基于MindConverter实现映射关系,向MindInsight仓库贡献。 4. 在使用基于计算图的迁移时,MindConverter会根据`--shape`参数将模型输入的批次大小(batch size)、句子长度(sequence length)、图片尺寸(image shape)等尺寸相关参数固定下来,用户需要保证基于MindSpore重训练、推理时输入shape与转换时一致;若需要调整输入尺寸,请重新指定`--shape`进行转换或修改转换后脚本中涉及张量尺寸变更操作相应的操作数。 5. 脚本文件、权重文件和权重映射表输出于同一个目录下。 +6. 模型文件的安全性与一致性请用户自行保证。 -- Gitee