diff --git a/.jenkins/rules/codespell/codespell.allow b/.jenkins/rules/codespell/codespell.allow index 8fe88ddebfa4ef7b071ca0e0433fef45f9f70f73..346bbfd2bd95e35a6078c78a583d87628c206d18 100644 --- a/.jenkins/rules/codespell/codespell.allow +++ b/.jenkins/rules/codespell/codespell.allow @@ -17,4 +17,5 @@ mutiple allEdges statments SubreE -followings \ No newline at end of file +followings +Rouge \ No newline at end of file diff --git a/docs/golden_stick/docs/requirements.txt b/docs/golden_stick/docs/requirements.txt index 46904323e583b9e0318a9b7a0a7daa23b5e2b3e5..fb57d308d824183c89c4a5db15ff8f4a9ec7727f 100644 --- a/docs/golden_stick/docs/requirements.txt +++ b/docs/golden_stick/docs/requirements.txt @@ -6,3 +6,4 @@ numpy nbsphinx == 0.8.11 IPython jieba +pyyaml \ No newline at end of file diff --git a/docs/golden_stick/docs/source_en/conf.py b/docs/golden_stick/docs/source_en/conf.py index 239a4c9162c6483bb577b9510305f91978706856..c7658a4a45fc68d1f23ca6488c78f8a16ec4664e 100644 --- a/docs/golden_stick/docs/source_en/conf.py +++ b/docs/golden_stick/docs/source_en/conf.py @@ -14,11 +14,10 @@ import os import re import shutil import sys +import sphinx from sphinx.ext import autodoc as sphinx_autodoc import sphinx.ext.autosummary.generate as g -import mindspore_gs - # -- Project information ----------------------------------------------------- project = 'MindSpore' @@ -159,6 +158,25 @@ with open(autodoc_source_path, "r+", encoding="utf8") as f: exec(get_param_func_str, sphinx_autodoc.__dict__) exec(code_str, sphinx_autodoc.__dict__) +# Repair error content defined in mindspore. +try: + decorator_list = [("mindspore/common/dtype.py","restore error", + "# generate api by del decorator.\nclass QuantDtype():","@enum.unique\nclass QuantDtype(enum.Enum):")] + + base_path = os.path.dirname(os.path.dirname(sphinx.__file__)) + for i in decorator_list: + with open(os.path.join(base_path, os.path.normpath(i[0])), "r+", encoding="utf8") as f: + content = f.read() + if i[2] in content: + content = content.replace(i[2], i[3]) + f.seek(0) + f.truncate() + f.write(content) +except: + pass + +import mindspore_gs + # Copy source files of chinese python api from golden-stick repository. from sphinx.util import logging import shutil @@ -173,6 +191,11 @@ for root,dirs,files in os.walk(src_dir_api): os.remove(os.path.join(moment_dir,file)) shutil.copy(os.path.join(src_dir_api,file),os.path.join(moment_dir,file)) +if not os.path.exists(os.path.join(moment_dir, 'ptq/round_to_nearest.md')): + os.makedirs(os.path.join(moment_dir, 'ptq'), exist_ok=True) + shutil.copy(os.path.join(os.getenv("GS_PATH"), 'mindspore_gs/ptq/round_to_nearest/README_EN.md'), + os.path.join(moment_dir, 'ptq/round_to_nearest.md')) + # get params for add view source import json diff --git a/docs/golden_stick/docs/source_en/index.rst b/docs/golden_stick/docs/source_en/index.rst index 5693af3ab693a5c02bd041ce15402263226ecb61..630b0669fc900f752fbfcc005225a4200020eb18 100644 --- a/docs/golden_stick/docs/source_en/index.rst +++ b/docs/golden_stick/docs/source_en/index.rst @@ -50,7 +50,7 @@ General Process of Applying the MindSpore Golden Stick - **Optimize the network using the MindSpore Golden Stick:** In the original training process, after the original network is defined and before the network is trained, use the MindSpore Golden Stick to optimize the network structure. Generally, this step is implemented by calling the `apply` API of MindSpore Golden Stick. For details, see `Applying the SimQAT Algorithm `_ . - - **Register the MindSpore Golden Stick callback:** Register the callback of the MindSpore Golden Stick into the model to be trained. Generally, in this step, the `callback` function of MindSpore Golden Stick is called to obtain the corresponding callback object and `register the object into the model `_ . + - **Register the MindSpore Golden Stick callback:** Register the callback of the MindSpore Golden Stick into the model to be trained. Generally, in this step, the `callback` function of MindSpore Golden Stick is called to obtain the corresponding callback object and `register the object into the model `_ . 2. Deployment @@ -59,7 +59,7 @@ General Process of Applying the MindSpore Golden Stick .. note:: - For details about how to apply the MindSpore Golden Stick, see the detailed description and sample code in each algorithm section. - For details about the "ms.export" step in the process, see `Exporting MINDIR Model `_ . - - For details about the "MindSpore infer" step in the process, see `MindSpore Inference Runtime `_ . + - For details about the "MindSpore infer" step in the process, see `MindSpore Inference Runtime `_ . Roadmap --------------------------------------- diff --git a/docs/golden_stick/docs/source_en/pruner/scop.md b/docs/golden_stick/docs/source_en/pruner/scop.md index 00f440fc682d2c367273e316c400c67169b9989c..9407d9edf33a6ac5b437530528e1d1a9d049fb85 100644 --- a/docs/golden_stick/docs/source_en/pruner/scop.md +++ b/docs/golden_stick/docs/source_en/pruner/scop.md @@ -210,7 +210,7 @@ if __name__ == "__main__": export(network, inputs, file_name="ResNet_SCOP", file_format='MINDIR') ``` -After the pruned model is exported, [use MindSpore for inference](https://www.mindspore.cn/tutorials/experts/en/master/infer/inference.html). +After the pruned model is exported, [use MindSpore for inference](https://www.mindspore.cn/docs/en/master/model_infer/overview.html). ## Summary diff --git a/docs/golden_stick/docs/source_zh_cn/conf.py b/docs/golden_stick/docs/source_zh_cn/conf.py index 791d130a76d50fba3b3a0f16596177c7c1b71a31..5b04e764b8b58a9a9e518100d31f1051320cee9b 100644 --- a/docs/golden_stick/docs/source_zh_cn/conf.py +++ b/docs/golden_stick/docs/source_zh_cn/conf.py @@ -209,6 +209,20 @@ for root,dirs,files in os.walk(src_dir_api): os.remove(os.path.join(moment_dir,'quantization',file)) shutil.copy(os.path.join(root,file),os.path.join(moment_dir,'quantization',file)) copy_list.append(os.path.join(moment_dir,file)) + elif '/ptq' in root: + if not os.path.exists(os.path.join(moment_dir, 'ptq')): + os.makedirs(os.path.join(moment_dir, 'ptq')) + if os.path.exists(os.path.join(moment_dir,'ptq',file)): + os.remove(os.path.join(moment_dir,'ptq',file)) + shutil.copy(os.path.join(root,file),os.path.join(moment_dir,'ptq',file)) + copy_list.append(os.path.join(moment_dir,file)) + else: + if not os.path.exists('.' + root.split(copy_path)[-1]): + os.makedirs('.' + root.split(copy_path)[-1]) + if os.path.exists('.'+root.split(copy_path)[-1]+'/'+file): + os.remove('.'+root.split(copy_path)[-1]+'/'+file) + shutil.copy(os.path.join(root,file),'.'+root.split(copy_path)[-1]+'/'+file) + copy_list.append('.'+root.split(copy_path)[-1]+'/'+file) # add view import json @@ -260,8 +274,6 @@ for cur, _, files in os.walk(moment_dir): except Exception: print(f'打开{i}文件失败') -if not os.path.exists(os.path.join(moment_dir, 'ptq')): - os.makedirs(os.path.join(moment_dir, 'ptq')) if not os.path.exists(os.path.join(moment_dir, 'ptq/round_to_nearest.ipynb')): shutil.copy(os.path.join(os.getenv("GS_PATH"), 'mindspore_gs/ptq/round_to_nearest/README.ipynb'), os.path.join(moment_dir, 'ptq/round_to_nearest.ipynb')) diff --git a/docs/golden_stick/docs/source_zh_cn/index.rst b/docs/golden_stick/docs/source_zh_cn/index.rst index 4ea9019cea73c1d629042a16e25cca73c6048ec5..f76dd9a6f30fcd0a390ec1f20e982a763f4fceee 100644 --- a/docs/golden_stick/docs/source_zh_cn/index.rst +++ b/docs/golden_stick/docs/source_zh_cn/index.rst @@ -50,7 +50,7 @@ MindSpore Golden Stick除了提供丰富的模型压缩算法外,一个重要 - **应用MindSpore Golden Stick算法优化网络:** 在原训练流程中,在定义原始网络之后,网络训练之前,应用MindSpore Golden Stick算法优化网络结构。一般这个步骤是调用MindSpore Golden Stick的 `apply` 接口实现的,可以参考 `应用SimQAT算法 `_。 - - **注册MindSpore Golden Stick回调逻辑:** 将MindSpore Golden Stick算法的回调逻辑注册到要训练的model中。一般这个步骤是调用MindSpore Golden Stick的 `callback` 获取相应的callback对象, `注册到model `_ 中。 + - **注册MindSpore Golden Stick回调逻辑:** 将MindSpore Golden Stick算法的回调逻辑注册到要训练的model中。一般这个步骤是调用MindSpore Golden Stick的 `callback` 获取相应的callback对象, `注册到model `_ 中。 2. 部署阶段 @@ -59,7 +59,7 @@ MindSpore Golden Stick除了提供丰富的模型压缩算法外,一个重要 .. note:: - 应用MindSpore Golden Stick算法的细节,可以在每个算法章节中找到详细说明和示例代码。 - 流程中的"ms.export"步骤可以参考 `导出mindir格式文件 `_ 章节。 - - 流程中的"昇思推理优化工具和运行时"步骤可以参考 `昇思推理 `_ 章节。 + - 流程中的"昇思推理优化工具和运行时"步骤可以参考 `昇思推理 `_ 章节。 未来规划 ---------- diff --git a/docs/golden_stick/docs/source_zh_cn/pruner/scop.md b/docs/golden_stick/docs/source_zh_cn/pruner/scop.md index 4dee1f692d31af81df19450bd3f77a18f230521f..7906b4edf45871e9ba0ec0b8a8348285faa5353a 100644 --- a/docs/golden_stick/docs/source_zh_cn/pruner/scop.md +++ b/docs/golden_stick/docs/source_zh_cn/pruner/scop.md @@ -210,7 +210,7 @@ if __name__ == "__main__": export(network, inputs, file_name="ResNet_SCOP", file_format='MINDIR') ``` -导出剪枝模型后,请[使用MindSpore进行推理](https://www.mindspore.cn/tutorials/experts/zh-CN/master/infer/inference.html)。 +导出剪枝模型后,请[使用MindSpore进行推理](https://www.mindspore.cn/docs/zh-CN/master/model_infer/overview.html)。 ## 算法效果汇总 diff --git a/docs/hub/docs/source_en/loading_model_from_hub.md b/docs/hub/docs/source_en/loading_model_from_hub.md index 1ede36ac14f262af53d7ad35257a19250a7eb88b..85f964c30465760c86e3a291dff0e04caba23313 100644 --- a/docs/hub/docs/source_en/loading_model_from_hub.md +++ b/docs/hub/docs/source_en/loading_model_from_hub.md @@ -39,7 +39,7 @@ This document demonstrates the use of the models provided by MindSpore Hub for b ``` -3. After loading the model, you can use MindSpore to do inference. You can refer to [Multi-Platform Inference Overview](https://www.mindspore.cn/tutorials/experts/en/master/infer/inference.html). +3. After loading the model, you can use MindSpore to do inference. You can refer to [Multi-Platform Inference Overview](https://www.mindspore.cn/docs/en/master/model_infer/overview.html). ## For Transfer Training diff --git a/docs/hub/docs/source_zh_cn/loading_model_from_hub.md b/docs/hub/docs/source_zh_cn/loading_model_from_hub.md index 97342a05dd8715ff72aef2835fb5f4b4bbae8f1f..a33acfc7a41dba4536d5f676f99af52fbaf73562 100644 --- a/docs/hub/docs/source_zh_cn/loading_model_from_hub.md +++ b/docs/hub/docs/source_zh_cn/loading_model_from_hub.md @@ -39,7 +39,7 @@ ``` -3. 完成模型加载后,可以使用MindSpore进行推理,参考[推理模型总览](https://www.mindspore.cn/tutorials/experts/zh-CN/master/infer/inference.html)。 +3. 完成模型加载后,可以使用MindSpore进行推理,参考[推理模型总览](https://www.mindspore.cn/docs/zh-CN/master/model_infer/overview.html)。 ## 用于迁移学习 diff --git a/docs/lite/api/source_en/conf.py b/docs/lite/api/source_en/conf.py index bc3d52e468265a686cb34898a49e059efeb8122d..408e41a12c0d7928efab0d519b43b62841af0b91 100644 --- a/docs/lite/api/source_en/conf.py +++ b/docs/lite/api/source_en/conf.py @@ -368,6 +368,11 @@ des_sir = "../include" if os.path.exists(des_sir): shutil.rmtree(des_sir) +# 解压tar.gz包 +def extract_tar_gz(gz_file, extract_to): + with tarfile.open(gz_file, 'r:gz') as tar: + tar.extractall(path=extract_to) + lite_package_path=os.getenv("LITE_PACKAGE_PATH", "null") if lite_package_path == "null": print("LITE_PACKAGE_PATH: This environment variable does not exist") @@ -375,12 +380,8 @@ if lite_package_path == "null": quit() header_path = lite_package_path.split("/")[-1].split(".tar")[0] save_path = "../" -os.makedirs(save_path, exist_ok=True) -t = tarfile.open(lite_package_path) -names = t.getnames() -for name in names: - t.extract(name, save_path) -t.close() + +extract_tar_gz(lite_package_path, save_path) source_path = "../" + header_path + "/" source_runtime_include = os.path.join(source_path, "runtime/include") diff --git a/docs/lite/docs/source_en/quick_start/train_lenet.md b/docs/lite/docs/source_en/quick_start/train_lenet.md index c90d1ff2c22eb7808405534621c66675f3696281..e2e9e0506ad46bbd9f42ea288672f18c7ee429a0 100644 --- a/docs/lite/docs/source_en/quick_start/train_lenet.md +++ b/docs/lite/docs/source_en/quick_start/train_lenet.md @@ -214,7 +214,7 @@ train_lenet_cpp/ Whether it is an off-the-shelf prepared model, or a custom written model, the model needs to be exported to a `.mindir` file. Here we use the already-implemented [LeNet model](https://gitee.com/mindspore/models/tree/master/research/cv/lenet). -> This summary is exported using the MindSpore cloud side feature. For more information, please refer to [MindSpore Tutorial](https://www.mindspore.cn/tutorials/experts/en/master/index.html). +> This summary is exported using the MindSpore cloud side feature. For more information, please refer to [MindSpore Tutorial](https://www.mindspore.cn/tutorials/en/master/index.html). ```python import numpy as np diff --git a/docs/lite/docs/source_en/use/cloud_infer/converter_python.md b/docs/lite/docs/source_en/use/cloud_infer/converter_python.md index 4461f3cce3615400b94ec6df678c05d1d53a9f31..c357991db38c838149e9b7c42df013e01d922e0f 100644 --- a/docs/lite/docs/source_en/use/cloud_infer/converter_python.md +++ b/docs/lite/docs/source_en/use/cloud_infer/converter_python.md @@ -91,12 +91,19 @@ Detailed descriptions of the parameters and their correspondence to the paramete | save_type | ModelType | `--saveType=` | Required | Set the model type needs to be export. | ModelType.MINDIR | The MINDIR model uses the MindSpore Lite cloud-side inference installation package | | weight_fp16 | bool | `--fp16=` | Set whether the weights in float32 data format need to be stored in float16 data format during model serialization. | True, False | - | -> The encryption and decryption function only takes effect when `MSLITE_ENABLE_MODEL_ENCRYPTION=on` is set at [compile](https://www.mindspore.cn/lite/docs/en/master/use/cloud_infer/build.html) time and only supports Linux x86 platforms. `decrypt_key` and `encrypt_key` are string expressed in hexadecimal. For example, if encrypt_key is set as "30313233343637383939414243444546", the corresponding hexadecimal expression is '(b)0123456789ABCDEF' . Linux platform users can use the' xxd 'tool to convert the key expressed in bytes into hexadecimal expressions. -> `input_shape` is a attribute that the user may need to set in the following scenarios: +> - The encryption and decryption function only takes effect when `MSLITE_ENABLE_MODEL_ENCRYPTION=on` is set at [compile](https://www.mindspore.cn/lite/docs/en/master/use/cloud_infer/build.html) time and only supports Linux x86 platforms. `decrypt_key` and `encrypt_key` are string expressed in hexadecimal. For example, if encrypt_key is set as "30313233343637383939414243444546", the corresponding hexadecimal expression is '(b)0123456789ABCDEF' . Linux platform users can use the' xxd 'tool to convert the key expressed in bytes into hexadecimal expressions. > -> - Usage 1: The input of the model to be converted is dynamic shape, and the fixed-shape inference is prepared, then this attribute is set to fixed-shape. After setting, when inference about the model after the Converter, the default input shape is the same as this attribute setting, and no resize operation is needed. -> - Usage 2: Regardless of whether the original input of the model to be converted is a dynamic shape, use fixed-shape inference and want the performance of the model to be optimized as much as possible, then set this attribute to fixed-shape. After setting, the model structure will be further optimized, but the converted model may lose the characteristics of the dynamic shape (some operators strongly related to the shape will be fused). -> `optimize` is an attribute, it used to set the mode of optimization during the offline conversion. If this attribute is set to "none", no relevant graph optimization operations will be performed during the offline conversion phase of the model, and the relevant graph optimization operations will be performed during the execution of the inference phase. The advantage of this attribute is that the converted model can be deployed directly to any CPU/GPU/Ascend hardware backend since it is not optimized in a specific way, while the disadvantage is that the initialization time of the model increases during inference execution. If this attribute is set to "general", general optimization will be performed, such as constant folding and operator fusion (the converted model only supports CPU/GPU hardware backend, not Ascend backend). If this parameter is set to "gpu_oriented", the general optimization and extra optimization for GPU hardware will be performed (the converted model only supports GPU hardware backend). If this attribute is set to "ascend_oriented", the optimization for Ascend hardware will be performed (the converted model only supports Ascend hardware backend). +> - `input_shape` is a attribute that the user may need to set in the following scenarios: +> +> - Usage 1: The input of the model to be converted is dynamic shape, and the fixed-shape inference is prepared, then this attribute is set to fixed-shape. After setting, when inference about the model after the Converter, the default input shape is the same as this attribute setting, and no resize operation is needed. +> - Usage 2: Regardless of whether the original input of the model to be converted is a dynamic shape, use fixed-shape inference and want the performance of the model to be optimized as much as possible, then set this attribute to fixed-shape. After setting, the model structure will be further optimized, but the converted model may lose the characteristics of the dynamic shape (some operators strongly related to the shape will be fused). +> +> - `optimize` is an attribute, it used to set the mode of optimization during the offline conversion. +> +> - If this attribute is set to "none", no relevant graph optimization operations will be performed during the offline conversion phase of the model, and the relevant graph optimization operations will be performed during the execution of the inference phase. The advantage of this attribute is that the converted model can be deployed directly to any CPU/GPU/Ascend hardware backend since it is not optimized in a specific way, while the disadvantage is that the initialization time of the model increases during inference execution. +> - If this attribute is set to "general", general optimization will be performed, such as constant folding and operator fusion (the converted model only supports CPU/GPU hardware backend, not Ascend backend). +> - If this parameter is set to "gpu_oriented", the general optimization and extra optimization for GPU hardware will be performed (the converted model only supports GPU hardware backend). +> - If this attribute is set to "ascend_oriented", the optimization for Ascend hardware will be performed (the converted model only supports Ascend hardware backend). > ### Method of convert diff --git a/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_cpp.md b/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_cpp.md index 650922922e6b4e9357075df6ef63cb24c6cf6979..b45bca32f3c87b93915561f74fb83fb37998937c 100644 --- a/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_cpp.md +++ b/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_cpp.md @@ -4,7 +4,7 @@ ## Overview -For scenarios where large-scale neural network models have many parameters and cannot be fully loaded into a single device for inference, distributed inference can be performed using multiple devices. This tutorial describes how to perform MindSpore Lite cloud-side distributed inference using the [C++ interface](https://www.mindspore.cn/lite/api/en/master/index.html). Cloud-side distributed inference is roughly the same process as [Cloud-side single-card inference](https://www.mindspore.cn/lite/docs/en/master/use/cloud_infer/runtime_cpp.html) and can be cross-referenced. For the related contents of distributed inference, please refer to [MindSpore Distributed inference](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html#inference), and MindSpore Lite cloud-side distributed inference has more optimization for performance aspects. +For scenarios where large-scale neural network models have many parameters and cannot be fully loaded into a single device for inference, distributed inference can be performed using multiple devices. This tutorial describes how to perform MindSpore Lite cloud-side distributed inference using the [C++ interface](https://www.mindspore.cn/lite/api/en/master/index.html). Cloud-side distributed inference is roughly the same process as [Cloud-side single-card inference](https://www.mindspore.cn/lite/docs/en/master/use/cloud_infer/runtime_cpp.html) and can be cross-referenced. For the related contents of distributed inference, please refer to [MindSpore Distributed inference](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html#inference), and MindSpore Lite cloud-side distributed inference has more optimization for performance aspects. MindSpore Lite cloud-side distributed inference is only supported to run in Linux environment deployments with Atlas training series and Nvidia GPU as the supported device types. As shown in the figure below, the distributed inference is currently initiated by a multi-process approach, where each process corresponds to a `Rank` in the communication set, loading, compiling and executing the respective sliced model, with the same input data for each process. @@ -12,7 +12,7 @@ MindSpore Lite cloud-side distributed inference is only supported to run in Linu Each process consists of the following main steps: -1. Model reading: Slice and [export the distributed MindIR model](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore. The number of MindIR models is the same as the number of devices for loading to each device for inference. +1. Model reading: Slice and [export the distributed MindIR model](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore. The number of MindIR models is the same as the number of devices for loading to each device for inference. 2. Context creation and configuration: Create and configure the [Context](https://www.mindspore.cn/lite/api/en/master/generate/classmindspore_Context.html), and hold the distributed inference parameters to guide distributed model compilation and model execution. 3. Model loading and compilation: Use the [Model::Build](https://www.mindspore.cn/lite/api/en/master/generate/classmindspore_Model.html) interface for model loading and model compilation. The model loading phase parses the file cache into a runtime model. The model compilation phase optimizes the front-end computational graph into a high-performance back-end computational graph. The process is time-consuming and it is recommended to compile once and inference multiple times. 4. Model input data padding. @@ -24,7 +24,7 @@ Each process consists of the following main steps: 1. To download the cloud-side distributed inference C++ sample code, please select the device type: [Ascend](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/ascend_ge_distributed_cpp) or [GPU](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/gpu_trt_distributed_cpp). The directory will be referred to later as the example code directory. -2. Slice and [export the distributed MindIR model](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore and store it to the sample code directory. For a quick experience, you can download the two sliced Matmul model files [Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir), [Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir). +2. Slice and [export the distributed MindIR model](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore and store it to the sample code directory. For a quick experience, you can download the two sliced Matmul model files [Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir), [Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir). 3. For Ascend device type, generate the networking information file through hccl_tools.py as needed, store it in the sample code directory, and fill the path of the file into the configuration file `config_file.ini` in the sample code directory. diff --git a/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_python.md b/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_python.md index ac732e4d309b4537953f24d10f737aaa9bd1538c..a986898ed27bbd6364c69bec814b38b777bcb2f0 100644 --- a/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_python.md +++ b/docs/lite/docs/source_en/use/cloud_infer/runtime_distributed_python.md @@ -4,7 +4,7 @@ ## Overview -For scenarios where large-scale neural network models have many parameters and cannot be fully loaded into a single device for inference, distributed inference can be performed using multiple devices. This tutorial describes how to perform MindSpore Lite cloud-side distributed inference using the [Python interface](https://www.mindspore.cn/lite/api/en/master/mindspore_lite.html). Cloud-side distributed inference is roughly the same process as [Cloud-side single-card inference](https://www.mindspore.cn/lite/docs/en/master/use/cloud_infer/runtime_python.html) and can be cross-referenced. For the related contents of distributed inference, please refer to [MindSpore Distributed inference](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html#inference), and MindSpore Lite cloud-side distributed inference has more optimization for performance aspects. +For scenarios where large-scale neural network models have many parameters and cannot be fully loaded into a single device for inference, distributed inference can be performed using multiple devices. This tutorial describes how to perform MindSpore Lite cloud-side distributed inference using the [Python interface](https://www.mindspore.cn/lite/api/en/master/mindspore_lite.html). Cloud-side distributed inference is roughly the same process as [Cloud-side single-card inference](https://www.mindspore.cn/lite/docs/en/master/use/cloud_infer/runtime_python.html) and can be cross-referenced. For the related contents of distributed inference, please refer to [MindSpore Distributed inference](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html#inference), and MindSpore Lite cloud-side distributed inference has more optimization for performance aspects. MindSpore Lite cloud-side distributed inference is only supported to run in Linux environment deployments with Atlas training series and Nvidia GPU as the supported device types. As shown in the figure below, the distributed inference is currently initiated by a multi-process approach, where each process corresponds to a `Rank` in the communication set, loading, compiling and executing the respective sliced model, with the same input data for each process. @@ -12,7 +12,7 @@ MindSpore Lite cloud-side distributed inference is only supported to run in Linu Each process consists of the following main steps: -1. Model reading: Slice and [export the distributed MindIR model](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore. The number of MindIR models is the same as the number of devices for loading to each device for inference. +1. Model reading: Slice and [export the distributed MindIR model](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore. The number of MindIR models is the same as the number of devices for loading to each device for inference. 2. Context creation and configuration: Create and configure the [Context](https://www.mindspore.cn/lite/api/en/master/mindspore_lite/mindspore_lite.Context.html#mindspore_lite.Context), and hold the distributed inference parameters to guide distributed model compilation and model execution. 3. Model loading and compilation: Use the [Model.build_from_file](https://www.mindspore.cn/lite/api/en/master/mindspore_lite/mindspore_lite.Model.html#mindspore_lite.Model.build_from_file) interface for model loading and model compilation. The model loading phase parses the file cache into a runtime model. The model compilation phase optimizes the front-end computational graph into a high-performance back-end computational graph. The process is time-consuming and it is recommended to compile once and inference multiple times. 4. Model input data padding. @@ -24,7 +24,7 @@ Each process consists of the following main steps: 1. To download the cloud-side distributed inference python sample code, please select the device type: [Ascend](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/ascend_ge_distributed_cpp) or [GPU](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/gpu_trt_distributed_cpp). The directory will be referred to later as the example code directory. -2. Slice and [export the distributed MindIR model](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore and store it to the sample code directory. For a quick experience, you can download the two sliced Matmul model files [Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir), [Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir). +2. Slice and [export the distributed MindIR model](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html#exporting-mindir-files-in-the-distributed-scenario) via MindSpore and store it to the sample code directory. For a quick experience, you can download the two sliced Matmul model files [Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir), [Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir). 3. For Ascend device type, generate the networking information file through hccl_tools.py as needed, store it in the sample code directory, and fill the path of the file into the configuration file `config_file.ini` in the sample code directory. diff --git a/docs/lite/docs/source_en/use/converter_tool.md b/docs/lite/docs/source_en/use/converter_tool.md index 5b54bd9966c576884509d1accd42a81fc85d5f39..ea5e057d44ec6e97c40b3218d68598eb2f743508 100644 --- a/docs/lite/docs/source_en/use/converter_tool.md +++ b/docs/lite/docs/source_en/use/converter_tool.md @@ -70,7 +70,7 @@ The following describes the parameters in detail. | `--outputDataType=` | No | Set data type of output tensor of quantized model. Only valid for output tensor which has quantization parameters(scale and zero point). Keep same with the data type of output tensor of origin model by default. | FLOAT32, INT8, UINT8, DEFAULT | DEFAULT | - | | `--outputDataFormat=` | No | Set the output format of exported model. Only valid for 4-dimensional outputs. | NHWC, NCHW | - | - | | `--encryptKey=` | No | Set the key for exporting encrypted `ms` models. The key is expressed in hexadecimal. Only AES-GCM is supported, and the key length is only 16Byte. | - | - | - | -| `--encryption=` | No | Set whether to encrypt when exporting the `ms` model. Exporting encryption can protect the integrity of the model, but it will increase the runtime initialization time. | true, false | true | - | +| `--encryption=` | No | Set whether to encrypt when exporting the `ms` model. Exporting encryption can protect the integrity of the model, but it will increase the runtime initialization time. | true, false | false | - | | `--infer=` | No | Set whether to pre-inference when conversion is complete. | true, false | false | - | > - The parameter name and parameter value are separated by an equal sign (=) and no space is allowed between them. diff --git a/docs/lite/docs/source_en/use/downloads.md b/docs/lite/docs/source_en/use/downloads.md index 7cf7b52356479a18fd19a491e0411f5b9435f324..1eab782c4d69f590f6f2f39c472c57afcc8dd3d4 100644 --- a/docs/lite/docs/source_en/use/downloads.md +++ b/docs/lite/docs/source_en/use/downloads.md @@ -6,6 +6,28 @@ Welcome to MindSpore Lite. We provide functions such as model conversion, model The Linux-x86_64 and Linux-aarch64 target have been tested and verified on the Linux distribution versions Euleros2.0, Centos7.8 and Ubuntu18.04. +## 2.3.1 + +Inference runtime +| Module Name | Hardware Platform | Operating System | Download Links | SHA-256 | +| --- | --- | --- | --- | --- | +| Cloud-side inference runtime lib, inference jar package, benchmark tool, converter tool | CPU/GPU/Ascend | Linux-x86_64 | [mindspore-lite-2.3.1-linux-x64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python37/mindspore-lite-2.3.1-linux-x64.tar.gz) | df702ba03a8a6a94a482273a2be15f1098fcaffb92ba396533b6b0896aab2292 | +| Cloud-side inference runtime lib, inference jar package, benchmark tool, converter tool | CPU/Ascend | Linux-aarch64 | [mindspore-lite-2.3.1-linux-aarch64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python37/mindspore-lite-2.3.1-linux-aarch64.tar.gz) | 9ba19a675d61da90e0e4f28ad54d2750ea7dfbfbc7611f001f64d3bdf952aac5 | +| Inference/training runtime lib, inference/training aar package, Micro lib, benchmark tool | CPU/GPU | Android-aarch64 | [mindspore-lite-2.3.1-android-aarch64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/android/gpu/mindspore-lite-2.3.1-android-aarch64.tar.gz) | eb0c13158f06b8a17975380ad190c28882e86989895ed4193d7223d3904337b0 | +| Device-side inference/training runtime lib, inference/training jar package, Micro lib, benchmark tool, converter tool, cropper tool | CPU | Linux-x86_64 | [mindspore-lite-2.3.1-linux-x64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/mindspore-lite-2.3.1-linux-x64.tar.gz) | 26792aabebde4f3c9a7b779b9da9b9c7bb9b80d5411efc6571e1ef45f0839f83 | +| Device-side inference runtime lib, Micro lib, benchmark tool, converter tool | CPU | Linux-aarch64 | [mindspore-lite-2.3.1-linux-aarch64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/mindspore-lite-2.3.1-linux-aarch64.tar.gz) | 7eec6a578ac7c96f33e0bb026f1f9f974cafada03d1a060e3fb121dc09ccf243 | +| Inference runtime lib, Micro lib, benchmark tool, converter tool | CPU | Windows-x86_64 | [mindspore-lite-2.3.1-win-x64.zip](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/windows/mindspore-lite-2.3.1-win-x64.zip) | 67f5fbba85d5b0682e228928f4cae5f48e6d6f5320a2fb10291a792e52748d03 | + +Python API wheel package +| Module Name | Hardware Platform | Operating System | Python Version | Download Links | SHA-256 | +| --- | --- | --- | --- | --- | --- | +| Cloud-side inference runtime and converter | CPU/GPU/Ascend | Linux-x86_64 | Python3.8 | [mindspore_lite-2.3.1-cp38-cp38-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python38/mindspore_lite-2.3.1-cp38-cp38-linux_x86_64.whl) | 436b7afb77caeee217141cccf3a728f7b25c66f89255fc77b0801c261a4c19b5 | +| Cloud-side inference runtime and converter | CPU/Ascend | Linux-aarch64 | Python3.8 | [mindspore_lite-2.3.1-cp38-cp38-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python38/mindspore_lite-2.3.1-cp38-cp38-linux_aarch64.whl) | 0f69ec441f13e0fdba6ea71fe975a84b0ceaaef2c6162a9ce9c876ec674bbd5f | +| Cloud-side inference runtime and converter | CPU/GPU/Ascend | Linux-x86_64 | Python3.9 | [mindspore_lite-2.3.1-cp39-cp39-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python39/mindspore_lite-2.3.1-cp39-cp39-linux_x86_64.whl) | 13775d493c57cf7a804d9fb667c591e550620d6e633885cce61b5905ced0a624 | +| Cloud-side inference runtime and converter | CPU/Ascend | Linux-aarch64 | Python3.9 | [mindspore_lite-2.3.1-cp39-cp39-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python39/mindspore_lite-2.3.1-cp39-cp39-linux_aarch64.whl) | b6007fc1df2a47367d3734ad7b4112e8a80d46f31d8f57c90520cecc0848c790 | +| Cloud-side inference runtime and converter | CPU/GPU/Ascend | Linux-x86_64 | Python3.10 | [mindspore_lite-2.3.1-cp310-cp310-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python310/mindspore_lite-2.3.1-cp310-cp310-linux_x86_64.whl) | 04021504bf6c73c6284ba0bc75b2f49e04402cfc76c4d402f2d235231b456bf1 | +| Cloud-side inference runtime and converter | CPU/Ascend | Linux-aarch64 | Python3.10 | [mindspore_lite-2.3.1-cp310-cp310-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python310/mindspore_lite-2.3.1-cp310-cp310-linux_aarch64.whl) | 767068f587ac25924b4ba172f47ef9a2f9bab8c6e8cedc1f7115fa1239ddc7bf | + ## 2.3.0 Inference runtime diff --git a/docs/lite/docs/source_zh_cn/quick_start/train_lenet.md b/docs/lite/docs/source_zh_cn/quick_start/train_lenet.md index 62b572b552f5fd9ca1bea0bbc06efa1bde99402b..5085dcd88e59659bb0e10ff439fd2360ab5d6c77 100644 --- a/docs/lite/docs/source_zh_cn/quick_start/train_lenet.md +++ b/docs/lite/docs/source_zh_cn/quick_start/train_lenet.md @@ -214,7 +214,7 @@ train_lenet_cpp/ 首先我们需要基于MindSpore框架创建一个LeNet模型,本例中直接用MindSpore ModelZoo的现有[LeNet模型](https://gitee.com/mindspore/models/tree/master/research/cv/lenet)。 -> 本小结使用MindSpore云侧功能导出,更多信息请参考[MindSpore教程](https://www.mindspore.cn/tutorials/experts/zh-CN/master/index.html)。 +> 本小结使用MindSpore云侧功能导出,更多信息请参考[MindSpore教程](https://www.mindspore.cn/tutorials/zh-CN/master/index.html)。 ```python import numpy as np diff --git a/docs/lite/docs/source_zh_cn/use/cloud_infer/converter_python.md b/docs/lite/docs/source_zh_cn/use/cloud_infer/converter_python.md index 2884bb886da1bd8695a71b95cc306c3f0b66fe64..b8c567209dcd94e0b8872ed3f858393d97fff6ca 100644 --- a/docs/lite/docs/source_zh_cn/use/cloud_infer/converter_python.md +++ b/docs/lite/docs/source_zh_cn/use/cloud_infer/converter_python.md @@ -92,11 +92,18 @@ MindSpore Lite云侧推理的Python接口模型转换提供了多种属性设置 | weight_fp16 | bool | `--fp16=` | 设置在模型序列化时是否需要将float32数据格式的权重存储为float16数据格式。 | True、False | - | > - 加解密功能仅在[编译](https://www.mindspore.cn/lite/docs/zh-CN/master/use/cloud_infer/build.html) 时设置为 `MSLITE_ENABLE_MODEL_ENCRYPTION=on` 时生效,并且仅支持Linux x86平台。其中密钥为十六进制表示的字符串,如encrypt_key设置为"30313233343536373839414243444546",对应的十六进制表示为 `(b)0123456789ABCDEF` ,Linux平台用户可以使用 `xxd` 工具对字节表示的密钥进行十六进制表达转换。需要注意的是,加解密算法在1.7版本进行了更新,导致新版的Python接口不支持对1.6及其之前版本的MindSpore Lite加密导出的模型进行转换。 -> `input_shape` 在以下场景下,用户可能需要设置该属性: > -> - 用法1:待转换模型的输入是动态shape,准备采用固定shape推理,则设置该属性为固定shape。设置之后,在对Converter后的模型进行推理时,默认输入的shape与该属性设置一样,无需再进行resize操作。 -> - 用法2:无论待转换模型的原始输入是否为动态shape,准备采用固定shape推理,并希望模型的性能尽可能优化,则设置该属性为固定shape。设置之后,将对模型结构进一步优化,但转换后的模型可能会失去动态shape的特征(部分跟shape强相关的算子会被融合)。 -> - `optimize` 该属性是用来设定在离线转换的过程中需要完成哪些特定的优化。如果该属性设置为"none",那么在模型的离线转换阶段将不进行相关的图优化操作,相关的图优化操作将会在执行推理阶段完成。该属性的优点在于转换出来的模型由于没有经过特定的优化,可以直接部署到CPU/GPU/Ascend任意硬件后端;而带来的缺点是推理执行时模型的初始化时间增长。如果设置成"general",表示离线转换过程会完成通用优化,包括常量折叠,算子融合等(转换出的模型只支持CPU/GPU后端,不支持Ascend后端)。如果设置成"gpu_oriented",表示转换过程中会完成通用优化和针对GPU后端的额外优化(转换出来的模型只支持GPU后端)。如果设置成"ascend_oriented",表示转换过程中只完成针对Ascend后端的优化(转换出来的模型只支持Ascend后端)。 +> - `input_shape` 在以下场景下,用户可能需要设置该属性: +> +> - 用法1:待转换模型的输入是动态shape,准备采用固定shape推理,则设置该属性为固定shape。设置之后,在对Converter后的模型进行推理时,默认输入的shape与该属性设置一样,无需再进行resize操作。 +> - 用法2:无论待转换模型的原始输入是否为动态shape,准备采用固定shape推理,并希望模型的性能尽可能优化,则设置该属性为固定shape。设置之后,将对模型结构进一步优化,但转换后的模型可能会失去动态shape的特征(部分跟shape强相关的算子会被融合)。 +> +> - `optimize` 该属性是用来设定在离线转换的过程中需要完成哪些特定的优化。 +> +> - 如果该属性设置为"none",那么在模型的离线转换阶段将不进行相关的图优化操作,相关的图优化操作将会在执行推理阶段完成。该属性的优点在于转换出来的模型由于没有经过特定的优化,可以直接部署到CPU/GPU/Ascend任意硬件后端;而带来的缺点是推理执行时模型的初始化时间增长。 +> - 如果设置成"general",表示离线转换过程会完成通用优化,包括常量折叠,算子融合等(转换出的模型只支持CPU/GPU后端,不支持Ascend后端)。 +> - 如果设置成"gpu_oriented",表示转换过程中会完成通用优化和针对GPU后端的额外优化(转换出来的模型只支持GPU后端)。 +> - 如果设置成"ascend_oriented",表示转换过程中只完成针对Ascend后端的优化(转换出来的模型只支持Ascend后端)。 > ### convert方法 diff --git a/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_cpp.md b/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_cpp.md index ae4712290ccbc7835afe86c4be935561dd4dec1c..6bd8f139dc8eca19a5141ecc290d5899cf3d4b27 100644 --- a/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_cpp.md +++ b/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_cpp.md @@ -4,7 +4,7 @@ ## 概述 -针对大规模神经网络模型参数多、无法完全加载至单设备推理的场景,可利用多设备进行分布式推理。本教程介绍如何使用[C++接口](https://www.mindspore.cn/lite/api/zh-CN/master/index.html)执行MindSpore Lite云侧分布式推理。云侧分布式推理与[云侧单卡推理](https://www.mindspore.cn/lite/docs/zh-CN/master/use/cloud_infer/runtime_cpp.html)流程大致相同,可以相互参考。关于分布式推理的相关内容可参考[MindSpore分布式推理](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html#推理),相比之下,MindSpore Lite云侧分布式推理针对性能方面具有更多的优化。 +针对大规模神经网络模型参数多、无法完全加载至单设备推理的场景,可利用多设备进行分布式推理。本教程介绍如何使用[C++接口](https://www.mindspore.cn/lite/api/zh-CN/master/index.html)执行MindSpore Lite云侧分布式推理。云侧分布式推理与[云侧单卡推理](https://www.mindspore.cn/lite/docs/zh-CN/master/use/cloud_infer/runtime_cpp.html)流程大致相同,可以相互参考。关于分布式推理的相关内容可参考[MindSpore分布式推理](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html#推理),相比之下,MindSpore Lite云侧分布式推理针对性能方面具有更多的优化。 MindSpore Lite云侧分布式推理仅支持在Linux环境部署运行,支持的设备类型为Atlas训练系列产品和Nvidia GPU。如下图所示,当前通过多进程方式启动分布式推理,每个进程对应通信集合中的一个`Rank`,对各自已切分的模型进行加载、编译与执行,每个进程输入数据相同。 @@ -12,7 +12,7 @@ MindSpore Lite云侧分布式推理仅支持在Linux环境部署运行,支持 每个进程主要包括以下步骤: -1. 模型读取:通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html#分布式场景导出mindir文件),MindIR模型数量与设备数相同,用于加载到各个设备进行推理。 +1. 模型读取:通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html#分布式场景导出mindir文件),MindIR模型数量与设备数相同,用于加载到各个设备进行推理。 2. 上下文创建与配置:创建并配置上下文[Context](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#context),保存分布式推理参数,用于指导分布式模型编译和模型执行。 3. 模型加载与编译:使用[Model::Build](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#build-2)接口进行模型加载和模型编译。模型加载阶段将文件缓存解析成运行时的模型。模型编译阶段将前端计算图优化为高性能后端计算图,该过程耗时较长,建议一次编译,多次推理。 4. 模型输入数据填充。 @@ -24,7 +24,7 @@ MindSpore Lite云侧分布式推理仅支持在Linux环境部署运行,支持 1. 下载云侧分布式推理C++示例代码,请选择设备类型:[Ascend](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/ascend_ge_distributed_cpp)或[GPU](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/gpu_trt_distributed_cpp)。后文将该目录称为示例代码目录。 -2. 通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html#分布式场景导出mindir文件),将其存放至示例代码目录。如需快速体验,可下载已切分的两个Matmul模型文件[Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir)、[Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir)。 +2. 通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html#分布式场景导出mindir文件),将其存放至示例代码目录。如需快速体验,可下载已切分的两个Matmul模型文件[Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir)、[Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir)。 3. 对于Ascend设备类型,通过hccl_tools.py按照需要生成组网信息文件,存放至示例代码目录,并将该文件路径填入示例代码目录下配置文件 `config_file.ini` 中。 diff --git a/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_python.md b/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_python.md index df62aad6eda00ec2d706d65640cf8df396623e4b..bcbdaa368b030787a11d559b242031181396eb05 100644 --- a/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_python.md +++ b/docs/lite/docs/source_zh_cn/use/cloud_infer/runtime_distributed_python.md @@ -4,7 +4,7 @@ ## 概述 -针对大规模神经网络模型参数多、无法完全加载至单设备推理的场景,可利用多设备进行分布式推理。本教程介绍如何使用[Python接口](https://www.mindspore.cn/lite/api/zh-CN/master/mindspore_lite.html)执行MindSpore Lite云侧分布式推理。云侧分布式推理与[云侧单卡推理](https://www.mindspore.cn/lite/docs/zh-CN/master/use/cloud_infer/runtime_python.html)流程大致相同,可以相互参考。关于分布式推理的相关内容可参考[MindSpore分布式推理](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html#推理),相比之下,MindSpore Lite云侧分布式推理针对性能方面具有更多的优化。 +针对大规模神经网络模型参数多、无法完全加载至单设备推理的场景,可利用多设备进行分布式推理。本教程介绍如何使用[Python接口](https://www.mindspore.cn/lite/api/zh-CN/master/mindspore_lite.html)执行MindSpore Lite云侧分布式推理。云侧分布式推理与[云侧单卡推理](https://www.mindspore.cn/lite/docs/zh-CN/master/use/cloud_infer/runtime_python.html)流程大致相同,可以相互参考。关于分布式推理的相关内容可参考[MindSpore分布式推理](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html#推理),相比之下,MindSpore Lite云侧分布式推理针对性能方面具有更多的优化。 MindSpore Lite云侧分布式推理仅支持在Linux环境部署运行,支持的设备类型为Atlas训练系列产品和Nvidia GPU。如下图所示,当前通过多进程方式启动分布式推理,每个进程对应通信集合中的一个`Rank`,对各自已切分的模型进行加载、编译与执行,每个进程输入数据相同。 @@ -12,7 +12,7 @@ MindSpore Lite云侧分布式推理仅支持在Linux环境部署运行,支持 每个进程主要包括以下步骤: -1. 模型读取:通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html#分布式场景导出mindir文件),MindIR模型数量与设备数相同,用于加载到各个设备进行推理。 +1. 模型读取:通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html#分布式场景导出mindir文件),MindIR模型数量与设备数相同,用于加载到各个设备进行推理。 2. 上下文创建与配置:创建并配置上下文[Context](https://www.mindspore.cn/lite/api/zh-CN/master/mindspore_lite/mindspore_lite.Context.html#mindspore_lite.Context),保存分布式推理参数,用于指导分布式模型编译和模型执行。 3. 模型加载与编译:使用[Model.build_from_file](https://www.mindspore.cn/lite/api/zh-CN/master/mindspore_lite/mindspore_lite.Model.html#mindspore_lite.Model.build_from_file)接口进行模型加载和模型编译。模型加载阶段将文件缓存解析成运行时的模型。模型编译阶段将前端计算图优化为高性能后端计算图,该过程耗时较长,建议一次编译,多次推理。 4. 模型输入数据填充。 @@ -24,7 +24,7 @@ MindSpore Lite云侧分布式推理仅支持在Linux环境部署运行,支持 1. 下载云侧分布式推理python示例代码,请选择设备类型:[Ascend](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/ascend_ge_distributed_python)或[GPU](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/cloud_infer/gpu_trt_distributed_python)。后文将该目录称为示例代码目录。 -2. 通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html#分布式场景导出mindir文件),将其存放至示例代码目录。如需快速体验,可下载已切分的两个Matmul模型文件[Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir)、[Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir)。 +2. 通过MindSpore切分并[导出分布式MindIR模型](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html#分布式场景导出mindir文件),将其存放至示例代码目录。如需快速体验,可下载已切分的两个Matmul模型文件[Matmul0.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul0.mindir)、[Matmul1.mindir](https://download.mindspore.cn/model_zoo/official/lite/quick_start/Matmul1.mindir)。 3. 对于Ascend设备类型,通过hccl_tools.py按照需要生成组网信息文件,存放至示例代码目录,并将该文件路径填入示例代码目录下配置文件 `config_file.ini` 中。 diff --git a/docs/lite/docs/source_zh_cn/use/converter_tool.md b/docs/lite/docs/source_zh_cn/use/converter_tool.md index 05b7aba03aff0e603d247fc34a6eee0ad6011509..b69b3b568c3b8e9a6918f0bf601b06ccedd4b9ed 100644 --- a/docs/lite/docs/source_zh_cn/use/converter_tool.md +++ b/docs/lite/docs/source_zh_cn/use/converter_tool.md @@ -68,7 +68,7 @@ MindSpore Lite模型转换工具提供了多种参数设置,用户可根据需 | `--outputDataType=` | 否 | 设定量化模型输出tensor的data type。仅当模型输出tensor的量化参数(scale和zero point)齐备时有效。默认与原始模型输出tensor的data type保持一致。 | FLOAT32、INT8、UINT8、DEFAULT | DEFAULT | - | | `--outputDataFormat=` | 否 | 设定导出模型的输出format,只对四维输出有效。 | NHWC、NCHW | - | - | | `--encryptKey=` | 否 | 设定导出加密`ms`模型的密钥,密钥用十六进制表示。仅支持 AES-GCM,密钥长度仅支持16Byte。 | - | - | - | -| `--encryption=` | 否 | 设定导出`ms`模型时是否加密,导出加密可保护模型完整性,但会增加运行时初始化时间。 | true、false | true | - | +| `--encryption=` | 否 | 设定导出`ms`模型时是否加密,导出加密可保护模型完整性,但会增加运行时初始化时间。 | true、false | false | - | | `--infer=` | 否 | 设定是否在转换完成时进行预推理。 | true、false | false | - | > - 参数名和参数值之间用等号连接,中间不能有空格。 diff --git a/docs/lite/docs/source_zh_cn/use/downloads.md b/docs/lite/docs/source_zh_cn/use/downloads.md index c56fefedc69e26dbdeba43124b413eeae7505a47..d917d2c70b12f7f967a26e71671d35d7a38d79a2 100644 --- a/docs/lite/docs/source_zh_cn/use/downloads.md +++ b/docs/lite/docs/source_zh_cn/use/downloads.md @@ -6,6 +6,27 @@ 其中Linux-x86_64、Linux-aarch64的包已在Linux发行版Euleros2.0、Centos7.8、Ubuntu18.04版本上经过测试验证。 +## 2.3.1 + +| 组件 | 硬件平台 | 操作系统 | 链接 | SHA-256 | +| --- | --- | --- | --- | --- | +| 云侧推理runtime库、推理jar包、benchmark工具、converter工具 | CPU/GPU/Ascend | Linux-x86_64 | [mindspore-lite-2.3.1-linux-x64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python37/mindspore-lite-2.3.1-linux-x64.tar.gz) | df702ba03a8a6a94a482273a2be15f1098fcaffb92ba396533b6b0896aab2292 | +| 云侧推理runtime库、推理jar包、benchmark工具、converter工具 | CPU/Ascend | Linux-aarch64 | [mindspore-lite-2.3.1-linux-aarch64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python37/mindspore-lite-2.3.1-linux-aarch64.tar.gz) | 9ba19a675d61da90e0e4f28ad54d2750ea7dfbfbc7611f001f64d3bdf952aac5 | +| 推理和训练runtime库、推理和训练aar包、Micro库、benchmark工具 | CPU/GPU | Android-aarch64 | [mindspore-lite-2.3.1-android-aarch64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/android/gpu/mindspore-lite-2.3.1-android-aarch64.tar.gz) | eb0c13158f06b8a17975380ad190c28882e86989895ed4193d7223d3904337b0 | +| 端侧推理和训练runtime库、推理和训练jar包、Micro库、benchmark工具、converter工具、cropper工具 | CPU | Linux-x86_64 | [mindspore-lite-2.3.1-linux-x64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/mindspore-lite-2.3.1-linux-x64.tar.gz) | 26792aabebde4f3c9a7b779b9da9b9c7bb9b80d5411efc6571e1ef45f0839f83 | +| 端侧推理runtime库、Micro库、benchmark工具、converter工具 | CPU | Linux-aarch64 | [mindspore-lite-2.3.1-linux-aarch64.tar.gz](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/mindspore-lite-2.3.1-linux-aarch64.tar.gz) | 7eec6a578ac7c96f33e0bb026f1f9f974cafada03d1a060e3fb121dc09ccf243 | +| 推理runtime库、Micro库、benchmark工具、converter工具 | CPU | Windows-x86_64 | [mindspore-lite-2.3.1-win-x64.zip](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/windows/mindspore-lite-2.3.1-win-x64.zip) | 67f5fbba85d5b0682e228928f4cae5f48e6d6f5320a2fb10291a792e52748d03 | + +Python 接口 Wheel安装包 +| 组件 | 硬件平台 | 操作系统 | Python版本 | 链接 | SHA-256 | +| --- | --- | --- | --- | --- | --- | +| 云侧推理runtime及converter | CPU/GPU/Ascend | Linux-x86_64 | Python3.8 | [mindspore_lite-2.3.1-cp38-cp38-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python38/mindspore_lite-2.3.1-cp38-cp38-linux_x86_64.whl) | 436b7afb77caeee217141cccf3a728f7b25c66f89255fc77b0801c261a4c19b5 | +| 云侧推理runtime及converter | CPU/Ascend | Linux-aarch64 | Python3.8 | [mindspore_lite-2.3.1-cp38-cp38-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python38/mindspore_lite-2.3.1-cp38-cp38-linux_aarch64.whl) | 0f69ec441f13e0fdba6ea71fe975a84b0ceaaef2c6162a9ce9c876ec674bbd5f | +| 云侧推理runtime及converter | CPU/GPU/Ascend | Linux-x86_64 | Python3.9 | [mindspore_lite-2.3.1-cp39-cp39-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python39/mindspore_lite-2.3.1-cp39-cp39-linux_x86_64.whl) | 13775d493c57cf7a804d9fb667c591e550620d6e633885cce61b5905ced0a624 | +| 云侧推理runtime及converter | CPU/Ascend | Linux-aarch64 | Python3.9 | [mindspore_lite-2.3.1-cp39-cp39-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python39/mindspore_lite-2.3.1-cp39-cp39-linux_aarch64.whl) | b6007fc1df2a47367d3734ad7b4112e8a80d46f31d8f57c90520cecc0848c790 | +| 云侧推理runtime及converter | CPU/GPU/Ascend | Linux-x86_64 | Python3.10 | [mindspore_lite-2.3.1-cp310-cp310-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/x86_64/cloud_fusion/python310/mindspore_lite-2.3.1-cp310-cp310-linux_x86_64.whl) | 04021504bf6c73c6284ba0bc75b2f49e04402cfc76c4d402f2d235231b456bf1 | +| 云侧推理runtime及converter | CPU/Ascend | Linux-aarch64 | Python3.10 | [mindspore_lite-2.3.1-cp310-cp310-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/lite/release/linux/aarch64/cloud_fusion/python310/mindspore_lite-2.3.1-cp310-cp310-linux_aarch64.whl) | 767068f587ac25924b4ba172f47ef9a2f9bab8c6e8cedc1f7115fa1239ddc7bf | + ## 2.3.0 | 组件 | 硬件平台 | 操作系统 | 链接 | SHA-256 | diff --git a/docs/mindchemistry/docs/_ext/myautosummary.py b/docs/mindchemistry/docs/_ext/myautosummary.py index 326d0bdf5afc9051ad32a7fec42073ab6909357b..c8e37cee88a02d93840901f25518ada7fc7cc869 100644 --- a/docs/mindchemistry/docs/_ext/myautosummary.py +++ b/docs/mindchemistry/docs/_ext/myautosummary.py @@ -1,9 +1,8 @@ """Customized autosummary directives for sphinx.""" - -import importlib -import inspect import os import re +import inspect +import importlib from typing import List, Tuple from docutils.nodes import Node from sphinx.locale import __ @@ -225,7 +224,6 @@ class MsNoteAutoSummary(MsAutosummary): env_sum = piece[10:] return env_sum - class MsPlatformAutoSummary(MsAutosummary): """ Inherited from MsAutosummary. Add a third column about `Supported Platforms` to the table. diff --git a/docs/mindchemistry/docs/_ext/overwriteautosummary_generate.txt b/docs/mindchemistry/docs/_ext/overwriteautosummary_generate.txt index b6d35fed4e09d66d21301d3673c8d53f361de327..4b0a1b1dd2b410ecab971b13da9993c90d65ef0d 100644 --- a/docs/mindchemistry/docs/_ext/overwriteautosummary_generate.txt +++ b/docs/mindchemistry/docs/_ext/overwriteautosummary_generate.txt @@ -73,10 +73,10 @@ class DummyApplication: self.config.add('autosummary_ignore_module_all', True, 'env', bool) self.config.add('docs_branch', '', True, None) self.config.add('branch', '', True, None) - self.config.add('cst_module_name', [], True, None) + self.config.add('cst_module_name', '', True, None) self.config.add('copy_repo', '', True, None) self.config.add('giturl', '', True, None) - self.config.add('repo_whl', [], True, None) + self.config.add('repo_whl', '', True, None) self.config.init_values() def emit_firstresult(self, *args: Any) -> None: @@ -470,22 +470,13 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None, logger.warning(name) py_source_rel = '' - if app.config.cst_module_name[0] in name: - re_view = f"\n.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/{app.config.docs_branch}/" + \ - f"resource/_static/logo_source_en.svg\n :target: " + app.config.giturl + \ - f"{app.config.copy_repo}/blob/{app.config.branch}/" + app.config.repo_whl[0] + \ - py_source_rel.split(app.config.cst_module_name[0])[-1] + '\n :alt: View Source On Gitee\n\n' - - if re_view not in content and py_source_rel: - content = re.sub('([=]{5,})\n', r'\1\n' + re_view, content, 1) - elif app.config.cst_module_name[1] in name: - re_view = f"\n.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/{app.config.docs_branch}/" + \ - f"resource/_static/logo_source_en.svg\n :target: " + app.config.giturl + \ - f"{app.config.copy_repo}/blob/{app.config.branch}/" + app.config.repo_whl[1] + \ - py_source_rel.split(app.config.cst_module_name[1])[-1] + '\n :alt: View Source On Gitee\n\n' - - if re_view not in content and py_source_rel: - content = re.sub('([=]{5,})\n', r'\1\n' + re_view, content, 1) + re_view = f"\n.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/{app.config.docs_branch}/" + \ + f"resource/_static/logo_source_en.svg\n :target: " + app.config.giturl + \ + f"{app.config.copy_repo}/blob/{app.config.branch}/" + app.config.repo_whl + \ + py_source_rel.split(app.config.cst_module_name)[-1] + '\n :alt: View Source On Gitee\n\n' + + if re_view not in content and py_source_rel: + content = re.sub('([=]{5,})\n', r'\1\n' + re_view, content, 1) filename = os.path.join(path, filename_map.get(name, name) + suffix) if os.path.isfile(filename): with open(filename, encoding=encoding) as f: diff --git a/docs/mindchemistry/docs/source_en/conf.py b/docs/mindchemistry/docs/source_en/conf.py index 2849e91835d6e2033e01c9857e9254fe488514d2..f25e79e4e811e4539c7225c3d3bcec49ee545b19 100644 --- a/docs/mindchemistry/docs/source_en/conf.py +++ b/docs/mindchemistry/docs/source_en/conf.py @@ -49,6 +49,7 @@ extensions = [ 'sphinx.ext.napoleon', 'sphinx.ext.viewcode', 'myst_parser', + 'nbsphinx', 'sphinx.ext.mathjax', 'IPython.sphinxext.ipython_console_highlighting' ] @@ -142,40 +143,21 @@ with open(autodoc_source_path, "r+", encoding="utf8") as f: exec(get_param_func_str, sphinx_autodoc.__dict__) exec(code_str, sphinx_autodoc.__dict__) -# Repair error content defined in mindsponge. -try: - decorator_list = [("sponge/optimizer/updater.py","del decorator", - "@opt_init_args_register","# generate api by del decorator.")] - - base_path = os.path.dirname(os.path.dirname(sphinx.__file__)) - for i in decorator_list: - with open(os.path.join(base_path, os.path.normpath(i[0])), "r+", encoding="utf8") as f: - content = f.read() - if i[2] in content: - content = content.replace(i[2], i[3]) - f.seek(0) - f.truncate() - f.write(content) -except: - pass - # Copy source files of chinese python api from mindscience repository. from sphinx.util import logging logger = logging.getLogger(__name__) -src_dir_msg = os.path.join(os.getenv("MSC_PATH"), 'MindSPONGE/docs/api/api_python_en') - -present_path = os.path.dirname(__file__) +src_dir_mc = os.path.join(os.getenv("MSC_PATH"), 'docs/api_python_en/mindchemistry') -for i in os.listdir(src_dir_msg): - if os.path.isfile(os.path.join(src_dir_msg,i)): +for i in os.listdir(src_dir_mc): + if os.path.isfile(os.path.join(src_dir_mc,i)): if os.path.exists('./'+i): os.remove('./'+i) - shutil.copy(os.path.join(src_dir_msg,i),'./'+i) + shutil.copy(os.path.join(src_dir_mc,i),'./'+i) else: if os.path.exists('./'+i): shutil.rmtree('./'+i) - shutil.copytree(os.path.join(src_dir_msg,i),'./'+i) + shutil.copytree(os.path.join(src_dir_mc,i),'./'+i) # get params for add view source import json @@ -197,11 +179,11 @@ else: branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == copy_repo][0] docs_branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == 'tutorials'][0] -cst_module_name = ['mindsponge', 'sponge'] -repo_whl = ['MindSPONGE/src/mindsponge', 'MindSPONGE/src/sponge'] +cst_module_name = 'mindchemistry' +repo_whl = 'MindChemistry/mindchemistry' giturl = 'https://gitee.com/mindspore/' -import mindsponge +import mindchemistry sys.path.append(os.path.abspath('../../../../resource/sphinx_ext')) # import anchor_mod @@ -213,20 +195,19 @@ import search_code sys.path.append(os.path.abspath('../../../../resource/custom_directives')) from custom_directives import IncludeCodeDirective -from myautosummary import MsPlatformAutoSummary, MsNoteAutoSummary +from myautosummary import MsPlatformAutoSummary def setup(app): app.add_directive('msplatformautosummary', MsPlatformAutoSummary) - app.add_directive('msnoteautosummary', MsNoteAutoSummary) app.add_directive('includecode', IncludeCodeDirective) app.add_config_value('docs_branch', '', True) app.add_config_value('branch', '', True) - app.add_config_value('cst_module_name', [], True) + app.add_config_value('cst_module_name', '', True) app.add_config_value('copy_repo', '', True) app.add_config_value('giturl', '', True) - app.add_config_value('repo_whl', [], True) + app.add_config_value('repo_whl', '', True) -src_release = os.path.join(os.getenv("MSC_PATH"), 'MindSPONGE/RELEASE.md') +src_release = os.path.join(os.getenv("MSC_PATH"), 'MindChemistry/RELEASE.md') des_release = "./RELEASE.md" with open(src_release, "r", encoding="utf-8") as f: data = f.read() @@ -234,7 +215,6 @@ if len(re.findall("\n## (.*?)\n",data)) > 1: content = re.findall("(## [\s\S\n]*?)\n## ", data) else: content = re.findall("(## [\s\S\n]*)", data) -#result = content[0].replace('# MindSPONGE', '#', 1) with open(des_release, "w", encoding="utf-8") as p: p.write("# Release Notes"+"\n\n") p.write(content[0]) \ No newline at end of file diff --git a/docs/mindchemistry/docs/source_en/index.rst b/docs/mindchemistry/docs/source_en/index.rst index d553a9a4422b87f06ff6b3abd46ccbf3922f5640..fb4041459d13f27deaca5e3d2009182d6ca89577 100644 --- a/docs/mindchemistry/docs/source_en/index.rst +++ b/docs/mindchemistry/docs/source_en/index.rst @@ -236,13 +236,15 @@ arXiv:2209.11807v1 [cs.LG] 23 sep 2022. .. toctree:: :maxdepth: 1 :caption: Quick Start + :hidden: - quick_start/quick_start + quick_start/quick_start .. toctree:: :glob: :maxdepth: 1 :caption: User Guide + :hidden: user/molecular_generation user/molecular_prediction @@ -250,6 +252,7 @@ arXiv:2209.11807v1 [cs.LG] 23 sep 2022. .. toctree:: :maxdepth: 1 :caption: API References + :hidden: mindchemistry.cell mindchemistry.e3 @@ -260,5 +263,6 @@ arXiv:2209.11807v1 [cs.LG] 23 sep 2022. :glob: :maxdepth: 1 :caption: RELEASE NOTES + :hidden: RELEASE \ No newline at end of file diff --git a/docs/mindchemistry/docs/source_en/user/molecular_generation.md b/docs/mindchemistry/docs/source_en/user/molecular_generation.md index 4101bab373b9061a5a733d9995ab613d71944250..69d8a7b22e29d3cb83ed742f42e3e3caff6c6d16 100644 --- a/docs/mindchemistry/docs/source_en/user/molecular_generation.md +++ b/docs/mindchemistry/docs/source_en/user/molecular_generation.md @@ -1,8 +1,8 @@ # Molecular Generation -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindchemistry/docs/source_zh_cn/user/molecular_generation.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindchemistry/docs/source_zh_cn/user/molecular_generation.md) -Molecular generation, using deep learning generation models to predict and generate components in the particle system. We have integrated a method based on active learning for high entropy alloy design [1], designing high entropy alloy components with extremely low thermal expansion coefficients. In the active learning process, first, candidate high entropy alloy components are generated based on AI models, and the candidate components are screened based on predictive models and thermodynamic calculations to predict the thermal expansion coefficient. Finally, researchers need to determine the final high entropy alloy components based on experimental verification. +Molecular generation, using deep learning generation models to predict and generate components in the particle system. We have integrated a method based on active learning for high entropy alloy design, designing high entropy alloy components with extremely low thermal expansion coefficients. In the active learning process, first, candidate high entropy alloy components are generated based on AI models, and the candidate components are screened based on predictive models and thermodynamic calculations to predict the thermal expansion coefficient. Finally, researchers need to determine the final high entropy alloy components based on experimental verification. ## Supported Networks diff --git a/docs/mindchemistry/docs/source_en/user/molecular_prediction.md b/docs/mindchemistry/docs/source_en/user/molecular_prediction.md index 353a3f3b3b2bcd7ef897f168d7cf16cb5401cbbc..799661edb6ed855bbee394ee82133f3119bf73cf 100644 --- a/docs/mindchemistry/docs/source_en/user/molecular_prediction.md +++ b/docs/mindchemistry/docs/source_en/user/molecular_prediction.md @@ -1,8 +1,8 @@ # Molecular Prediction -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindchemistry/docs/source_zh_cn/user/molecular_prediction.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindchemistry/docs/source_zh_cn/user/molecular_prediction.md) -Molecular property prediction, predicting various properties in different particle systems through deep learning networks. We integrated the NequIP model [2] and Allegro model [3] to construct a graph structure description based on the position and number of atoms in the molecular system. Using equivariant calculations and graph neural networks, we calculated the energy of the molecular system. +Molecular property prediction, predicting various properties in different particle systems through deep learning networks. We integrated the NequIP model and Allegro model to construct a graph structure description based on the position and number of atoms in the molecular system. Using equivariant calculations and graph neural networks, we calculated the energy of the molecular system. Density Functional Theory Hamiltonian Prediction. We integrate the DeephE3nn model, an equivariant neural network based on E3, to predict a Hamiltonian by using the structure of atoms. Prediction of crystalline material properties. We integrate the Matformer model based on graph neural networks and Transformer architectures, for predicting various properties of crystalline materials. diff --git a/docs/mindchemistry/docs/source_zh_cn/conf.py b/docs/mindchemistry/docs/source_zh_cn/conf.py index 7676433f4588269ce81a437121e4336bc5b257a8..0dc9ffb3bb558b78c90aeca9357843b92fdc1012 100644 --- a/docs/mindchemistry/docs/source_zh_cn/conf.py +++ b/docs/mindchemistry/docs/source_zh_cn/conf.py @@ -49,6 +49,7 @@ extensions = [ 'sphinx.ext.napoleon', 'sphinx.ext.viewcode', 'myst_parser', + 'nbsphinx', 'sphinx.ext.mathjax', 'IPython.sphinxext.ipython_console_highlighting' ] @@ -160,7 +161,7 @@ with open(autodoc_source_path, "r+", encoding="utf8") as f: from sphinx.util import logging logger = logging.getLogger(__name__) -copy_path = 'MindSPONGE/docs/api/api_python' +copy_path = 'docs/api_python/mindchemistry' src_dir = os.path.join(os.getenv("MSC_PATH"), copy_path) copy_list = [] @@ -229,25 +230,24 @@ for cur, _, files in os.walk(present_path): except Exception: print(f'打开{i}文件失败') -import mindsponge +import mindchemistry sys.path.append(os.path.abspath('../../../../resource/search')) import search_code sys.path.append(os.path.abspath('../../../../resource/custom_directives')) from custom_directives import IncludeCodeDirective -from myautosummary import MsPlatformAutoSummary, MsNoteAutoSummary, MsCnPlatformAutoSummary +from myautosummary import MsPlatformAutoSummary, MsCnPlatformAutoSummary rst_files = set([i.replace('.rst', '') for i in glob.glob('./**/*.rst', recursive=True)]) def setup(app): app.add_directive('msplatformautosummary', MsPlatformAutoSummary) - app.add_directive('msnoteautosummary', MsNoteAutoSummary) app.add_directive('mscnplatformautosummary', MsCnPlatformAutoSummary) app.add_directive('includecode', IncludeCodeDirective) app.add_config_value('rst_files', set(), False) -src_release = os.path.join(os.getenv("MSC_PATH"), 'MindSPONGE/RELEASE_CN.md') +src_release = os.path.join(os.getenv("MSC_PATH"), 'MindChemistry/RELEASE_CN.md') des_release = "./RELEASE.md" with open(src_release, "r", encoding="utf-8") as f: data = f.read() diff --git a/docs/mindchemistry/docs/source_zh_cn/index.rst b/docs/mindchemistry/docs/source_zh_cn/index.rst index 06cfc583cb9195acbe38c156b94f04a8244d23e0..532661d79cd3deab84c55194788b49e198120980 100644 --- a/docs/mindchemistry/docs/source_zh_cn/index.rst +++ b/docs/mindchemistry/docs/source_zh_cn/index.rst @@ -175,13 +175,15 @@ arXiv:2209.11807v1 [cs.LG] 23 sep 2022. .. toctree:: :maxdepth: 1 :caption: 快速入门 + :hidden: - quick_start/quick_start + quick_start/quick_start .. toctree:: :glob: :maxdepth: 1 :caption: 使用者指南 + :hidden: user/molecular_generation user/molecular_prediction @@ -189,6 +191,7 @@ arXiv:2209.11807v1 [cs.LG] 23 sep 2022. .. toctree:: :maxdepth: 1 :caption: API参考 + :hidden: mindchemistry.cell mindchemistry.e3 @@ -199,5 +202,6 @@ arXiv:2209.11807v1 [cs.LG] 23 sep 2022. :glob: :maxdepth: 1 :caption: RELEASE NOTES + :hidden: RELEASE \ No newline at end of file diff --git a/docs/mindchemistry/docs/source_zh_cn/user/molecular_generation.md b/docs/mindchemistry/docs/source_zh_cn/user/molecular_generation.md index 70572f5e936206b78dd379016186e65a3a191c92..28a0e275c8a535b25e235ac9413bf1c7ee8ee330 100644 --- a/docs/mindchemistry/docs/source_zh_cn/user/molecular_generation.md +++ b/docs/mindchemistry/docs/source_zh_cn/user/molecular_generation.md @@ -2,7 +2,7 @@ [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindchemistry/docs/source_zh_cn/user/molecular_generation.md) -分子生成,通过深度学习的生成模型去预测并生成粒子体系中的组成. 我们集成了基于主动学习进行高熵合金设计的方法[1],设计热膨胀系数极低的高熵合金组分。在主动学习流程中,首先基于AI模型生成候选的高熵合金组分,并基于预测模型和热动力学计算预测热膨胀系数对候选组分进行筛选,最终需要研究者基于实验验证确定最终的高熵合金组分。 +分子生成,通过深度学习的生成模型去预测并生成粒子体系中的组成. 我们集成了基于主动学习进行高熵合金设计的方法,设计热膨胀系数极低的高熵合金组分。在主动学习流程中,首先基于AI模型生成候选的高熵合金组分,并基于预测模型和热动力学计算预测热膨胀系数对候选组分进行筛选,最终需要研究者基于实验验证确定最终的高熵合金组分。 ## 已支持网络 diff --git a/docs/mindchemistry/docs/source_zh_cn/user/molecular_prediction.md b/docs/mindchemistry/docs/source_zh_cn/user/molecular_prediction.md index 0149ae42f68c3bcdd579d297d2867e9fecf95c9f..62c874e801cacecd0cdccc29d56f797ebee2d7fd 100644 --- a/docs/mindchemistry/docs/source_zh_cn/user/molecular_prediction.md +++ b/docs/mindchemistry/docs/source_zh_cn/user/molecular_prediction.md @@ -2,7 +2,7 @@ [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindchemistry/docs/source_zh_cn/user/molecular_prediction.md) -分子性质预测,通过深度学习网络预测不同粒子体系中的各种性质. 我们集成了NequIP模型[2]、Allegro模型[3],根据分子体系中各原子的位置与原子数信息构建图结构描述,基于等变计算与图神经网络,计算出分子体系能量。 +分子性质预测,通过深度学习网络预测不同粒子体系中的各种性质. 我们集成了NequIP模型、Allegro模型,根据分子体系中各原子的位置与原子数信息构建图结构描述,基于等变计算与图神经网络,计算出分子体系能量。 密度泛函理论哈密顿量预测。我们集成了DeephE3nn模型,基于E3的等变神经网络,利用原子的结构去预测其的哈密顿量。 晶体材料性质预测。我们集成了Matformer模型,基于图神经网络和Transformer架构的模型,用于预测晶体材料的各种性质。 diff --git a/docs/mindearth/docs/requirements.txt b/docs/mindearth/docs/requirements.txt index f5ddc521080c312d8b9183f4ec8f7ab44186e930..d0e9823ca3f3b89d6ef24e72e44ecd381eed6786 100644 --- a/docs/mindearth/docs/requirements.txt +++ b/docs/mindearth/docs/requirements.txt @@ -6,4 +6,5 @@ numpy nbsphinx == 0.8.11 IPython jieba -mistune == 2.0.4 \ No newline at end of file +mistune == 2.0.4 +h5py diff --git a/docs/mindearth/docs/source_en/medium-range/FourCastNet.ipynb b/docs/mindearth/docs/source_en/medium-range/FourCastNet.ipynb index 9d64908f86f3c1f69d01191f1d901d513a8496bf..372dc7e288bd023c0895d9ec2f5cc411a7c5ebde 100644 --- a/docs/mindearth/docs/source_en/medium-range/FourCastNet.ipynb +++ b/docs/mindearth/docs/source_en/medium-range/FourCastNet.ipynb @@ -137,7 +137,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "You can get parameters of model, data and optimizer from [FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/FourCastNet.yaml)." + "You can get parameters of model, data and optimizer from [FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/configs/FourCastNet.yaml)." ] }, { @@ -182,7 +182,7 @@ "\n", "Download the statistic, training and validation dataset from [dataset](https://download.mindspore.cn/mindscience/mindearth/dataset/WeatherBench_1.4_69/) to `./dataset`.\n", "\n", - "Modify the parameter of `root_dir` in the [FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/FourCastNet.yaml), which sets the directory for dataset.\n", + "Modify the parameter of `root_dir` in the [FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/configs/FourCastNet.yaml), which sets the directory for dataset.\n", "\n", "The `./dataset` is hosted with the following directory structure:\n", "\n", diff --git a/docs/mindearth/docs/source_en/medium-range/vit_kno.ipynb b/docs/mindearth/docs/source_en/medium-range/vit_kno.ipynb index 5934e2e31ed9733242a7a8c72cf1a5e2d220e6ab..d271821ee5c518b698688020a549065cb048f5a0 100644 --- a/docs/mindearth/docs/source_en/medium-range/vit_kno.ipynb +++ b/docs/mindearth/docs/source_en/medium-range/vit_kno.ipynb @@ -83,7 +83,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "You can get parameters of model, data and optimizer from [vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/vit_kno.yaml)." + "You can get parameters of model, data and optimizer from [vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/configs/vit_kno_1.4.yaml)." ] }, { @@ -120,7 +120,7 @@ "\n", "Download the statistic, training and validation dataset from [dataset](https://download.mindspore.cn/mindscience/mindearth/dataset/WeatherBench_1.4_69/) to `./dataset`.\n", "\n", - "Modify the parameter of `root_dir` in the [vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/vit_kno.yaml), which set the directory for dataset.\n", + "Modify the parameter of `root_dir` in the [vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/configs/vit_kno_1.4.yaml), which set the directory for dataset.\n", "\n", "The `./dataset` is hosted with the following directory structure:\n", "\n", diff --git a/docs/mindearth/docs/source_zh_cn/medium-range/FourCastNet.ipynb b/docs/mindearth/docs/source_zh_cn/medium-range/FourCastNet.ipynb index cf654b35adf9b9b9d4e82fd2667434bd71f8bb5d..65979784adb5f1309e65c44929cd95f8472a31d6 100644 --- a/docs/mindearth/docs/source_zh_cn/medium-range/FourCastNet.ipynb +++ b/docs/mindearth/docs/source_zh_cn/medium-range/FourCastNet.ipynb @@ -137,7 +137,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "model、data和optimizer的参数可以通过加载yaml文件获取([FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/FourCastNet.yaml))。" + "model、data和optimizer的参数可以通过加载yaml文件获取([FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/configs/FourCastNet.yaml))。" ] }, { @@ -182,7 +182,7 @@ "\n", "在[dataset](https://download.mindspore.cn/mindscience/mindearth/dataset/WeatherBench_1.4_69/)路径下,下载正则化参数、训练数据集验证数据集到 `./dataset`目录。\n", "\n", - "修改[FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/FourCastNet.yaml)配置文件中的`root_dir`参数,该参数设置了数据集的路径。\n", + "修改[FourCastNet.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/fourcastnet/configs/FourCastNet.yaml)配置文件中的`root_dir`参数,该参数设置了数据集的路径。\n", "\n", "`./dataset`中的目录结构如下所示:\n", "\n", diff --git a/docs/mindearth/docs/source_zh_cn/medium-range/vit_kno.ipynb b/docs/mindearth/docs/source_zh_cn/medium-range/vit_kno.ipynb index e14b5dc2e68b43f5c14838f8c21c86a2b909002e..77e431ca5e716597e70624cbea931eb7a00a89e1 100644 --- a/docs/mindearth/docs/source_zh_cn/medium-range/vit_kno.ipynb +++ b/docs/mindearth/docs/source_zh_cn/medium-range/vit_kno.ipynb @@ -83,7 +83,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "model、data和optimizer的参数可以通过加载yaml文件获取([vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/vit_kno.yaml))。" + "model、data和optimizer的参数可以通过加载yaml文件获取([vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/configs/vit_kno_1.4.yaml))。" ] }, { @@ -119,7 +119,7 @@ "\n", "在[dataset](https://download.mindspore.cn/mindscience/mindearth/dataset/WeatherBench_1.4_69/)路径下,下载正则化参数、训练数据集、验证数据集到 `./dataset`目录。\n", "\n", - "修改[vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/vit_kno.yaml)配置文件中的`root_dir`参数,该参数设置了数据集的路径。\n", + "修改[vit_kno.yaml](https://gitee.com/mindspore/mindscience/blob/master/MindEarth/applications/medium-range/koopman_vit/configs/vit_kno_1.4.yaml)配置文件中的`root_dir`参数,该参数设置了数据集的路径。\n", "\n", "`./dataset`中的目录结构如下所示:\n", "\n", diff --git a/docs/mindformers/docs/Makefile b/docs/mindformers/docs/Makefile deleted file mode 100644 index 1eff8952707bdfa503c8d60c1e9a903053170ba2..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build -SOURCEDIR = source_zh_cn -BUILDDIR = build_zh_cn - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/mindformers/docs/_ext/overwriteautosummary_generate.txt b/docs/mindformers/docs/_ext/overwriteautosummary_generate.txt deleted file mode 100644 index 4b0a1b1dd2b410ecab971b13da9993c90d65ef0d..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/_ext/overwriteautosummary_generate.txt +++ /dev/null @@ -1,707 +0,0 @@ -""" - sphinx.ext.autosummary.generate - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Usable as a library or script to generate automatic RST source files for - items referred to in autosummary:: directives. - - Each generated RST file contains a single auto*:: directive which - extracts the docstring of the referred item. - - Example Makefile rule:: - - generate: - sphinx-autogen -o source/generated source/*.rst - - :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -import argparse -import importlib -import inspect -import locale -import os -import pkgutil -import pydoc -import re -import sys -import warnings -from gettext import NullTranslations -from os import path -from typing import Any, Dict, List, NamedTuple, Sequence, Set, Tuple, Type, Union - -from jinja2 import TemplateNotFound -from jinja2.sandbox import SandboxedEnvironment - -import sphinx.locale -from sphinx import __display_version__, package_dir -from sphinx.application import Sphinx -from sphinx.builders import Builder -from sphinx.config import Config -from sphinx.deprecation import RemovedInSphinx50Warning -from sphinx.ext.autodoc import Documenter -from sphinx.ext.autodoc.importer import import_module -from sphinx.ext.autosummary import (ImportExceptionGroup, get_documenter, import_by_name, - import_ivar_by_name) -from sphinx.locale import __ -from sphinx.pycode import ModuleAnalyzer, PycodeError -from sphinx.registry import SphinxComponentRegistry -from sphinx.util import logging, rst, split_full_qualified_name, get_full_modname -from sphinx.util.inspect import getall, safe_getattr -from sphinx.util.osutil import ensuredir -from sphinx.util.template import SphinxTemplateLoader - -logger = logging.getLogger(__name__) - - -class DummyApplication: - """Dummy Application class for sphinx-autogen command.""" - - def __init__(self, translator: NullTranslations) -> None: - self.config = Config() - self.registry = SphinxComponentRegistry() - self.messagelog: List[str] = [] - self.srcdir = "/" - self.translator = translator - self.verbosity = 0 - self._warncount = 0 - self.warningiserror = False - - self.config.add('autosummary_context', {}, True, None) - self.config.add('autosummary_filename_map', {}, True, None) - self.config.add('autosummary_ignore_module_all', True, 'env', bool) - self.config.add('docs_branch', '', True, None) - self.config.add('branch', '', True, None) - self.config.add('cst_module_name', '', True, None) - self.config.add('copy_repo', '', True, None) - self.config.add('giturl', '', True, None) - self.config.add('repo_whl', '', True, None) - self.config.init_values() - - def emit_firstresult(self, *args: Any) -> None: - pass - - -class AutosummaryEntry(NamedTuple): - name: str - path: str - template: str - recursive: bool - - -def setup_documenters(app: Any) -> None: - from sphinx.ext.autodoc import (AttributeDocumenter, ClassDocumenter, DataDocumenter, - DecoratorDocumenter, ExceptionDocumenter, - FunctionDocumenter, MethodDocumenter, ModuleDocumenter, - NewTypeAttributeDocumenter, NewTypeDataDocumenter, - PropertyDocumenter) - documenters: List[Type[Documenter]] = [ - ModuleDocumenter, ClassDocumenter, ExceptionDocumenter, DataDocumenter, - FunctionDocumenter, MethodDocumenter, NewTypeAttributeDocumenter, - NewTypeDataDocumenter, AttributeDocumenter, DecoratorDocumenter, PropertyDocumenter, - ] - for documenter in documenters: - app.registry.add_documenter(documenter.objtype, documenter) - - -def _simple_info(msg: str) -> None: - warnings.warn('_simple_info() is deprecated.', - RemovedInSphinx50Warning, stacklevel=2) - print(msg) - - -def _simple_warn(msg: str) -> None: - warnings.warn('_simple_warn() is deprecated.', - RemovedInSphinx50Warning, stacklevel=2) - print('WARNING: ' + msg, file=sys.stderr) - - -def _underline(title: str, line: str = '=') -> str: - if '\n' in title: - raise ValueError('Can only underline single lines') - return title + '\n' + line * len(title) - - -class AutosummaryRenderer: - """A helper class for rendering.""" - - def __init__(self, app: Union[Builder, Sphinx], template_dir: str = None) -> None: - if isinstance(app, Builder): - warnings.warn('The first argument for AutosummaryRenderer has been ' - 'changed to Sphinx object', - RemovedInSphinx50Warning, stacklevel=2) - if template_dir: - warnings.warn('template_dir argument for AutosummaryRenderer is deprecated.', - RemovedInSphinx50Warning, stacklevel=2) - - system_templates_path = [os.path.join(package_dir, 'ext', 'autosummary', 'templates')] - loader = SphinxTemplateLoader(app.srcdir, app.config.templates_path, - system_templates_path) - - self.env = SandboxedEnvironment(loader=loader) - self.env.filters['escape'] = rst.escape - self.env.filters['e'] = rst.escape - self.env.filters['underline'] = _underline - - if isinstance(app, (Sphinx, DummyApplication)): - if app.translator: - self.env.add_extension("jinja2.ext.i18n") - self.env.install_gettext_translations(app.translator) - elif isinstance(app, Builder): - if app.app.translator: - self.env.add_extension("jinja2.ext.i18n") - self.env.install_gettext_translations(app.app.translator) - - def exists(self, template_name: str) -> bool: - """Check if template file exists.""" - warnings.warn('AutosummaryRenderer.exists() is deprecated.', - RemovedInSphinx50Warning, stacklevel=2) - try: - self.env.get_template(template_name) - return True - except TemplateNotFound: - return False - - def render(self, template_name: str, context: Dict) -> str: - """Render a template file.""" - try: - template = self.env.get_template(template_name) - except TemplateNotFound: - try: - # objtype is given as template_name - template = self.env.get_template('autosummary/%s.rst' % template_name) - except TemplateNotFound: - # fallback to base.rst - template = self.env.get_template('autosummary/base.rst') - - return template.render(context) - - -# -- Generating output --------------------------------------------------------- - - -class ModuleScanner: - def __init__(self, app: Any, obj: Any) -> None: - self.app = app - self.object = obj - - def get_object_type(self, name: str, value: Any) -> str: - return get_documenter(self.app, value, self.object).objtype - - def is_skipped(self, name: str, value: Any, objtype: str) -> bool: - try: - return self.app.emit_firstresult('autodoc-skip-member', objtype, - name, value, False, {}) - except Exception as exc: - logger.warning(__('autosummary: failed to determine %r to be documented, ' - 'the following exception was raised:\n%s'), - name, exc, type='autosummary') - return False - - def scan(self, imported_members: bool) -> List[str]: - members = [] - for name in members_of(self.object, self.app.config): - try: - value = safe_getattr(self.object, name) - except AttributeError: - value = None - - objtype = self.get_object_type(name, value) - if self.is_skipped(name, value, objtype): - continue - - try: - if inspect.ismodule(value): - imported = True - elif safe_getattr(value, '__module__') != self.object.__name__: - imported = True - else: - imported = False - except AttributeError: - imported = False - - respect_module_all = not self.app.config.autosummary_ignore_module_all - if imported_members: - # list all members up - members.append(name) - elif imported is False: - # list not-imported members - members.append(name) - elif '__all__' in dir(self.object) and respect_module_all: - # list members that have __all__ set - members.append(name) - - return members - - -def members_of(obj: Any, conf: Config) -> Sequence[str]: - """Get the members of ``obj``, possibly ignoring the ``__all__`` module attribute - - Follows the ``conf.autosummary_ignore_module_all`` setting.""" - - if conf.autosummary_ignore_module_all: - return dir(obj) - else: - return getall(obj) or dir(obj) - - -def generate_autosummary_content(name: str, obj: Any, parent: Any, - template: AutosummaryRenderer, template_name: str, - imported_members: bool, app: Any, - recursive: bool, context: Dict, - modname: str = None, qualname: str = None) -> str: - doc = get_documenter(app, obj, parent) - - def skip_member(obj: Any, name: str, objtype: str) -> bool: - try: - return app.emit_firstresult('autodoc-skip-member', objtype, name, - obj, False, {}) - except Exception as exc: - logger.warning(__('autosummary: failed to determine %r to be documented, ' - 'the following exception was raised:\n%s'), - name, exc, type='autosummary') - return False - - def get_class_members(obj: Any) -> Dict[str, Any]: - members = sphinx.ext.autodoc.get_class_members(obj, [qualname], safe_getattr) - return {name: member.object for name, member in members.items()} - - def get_module_members(obj: Any) -> Dict[str, Any]: - members = {} - for name in members_of(obj, app.config): - try: - members[name] = safe_getattr(obj, name) - except AttributeError: - continue - return members - - def get_all_members(obj: Any) -> Dict[str, Any]: - if doc.objtype == "module": - return get_module_members(obj) - elif doc.objtype == "class": - return get_class_members(obj) - return {} - - def get_members(obj: Any, types: Set[str], include_public: List[str] = [], - imported: bool = True) -> Tuple[List[str], List[str]]: - items: List[str] = [] - public: List[str] = [] - - all_members = get_all_members(obj) - for name, value in all_members.items(): - documenter = get_documenter(app, value, obj) - if documenter.objtype in types: - # skip imported members if expected - if imported or getattr(value, '__module__', None) == obj.__name__: - skipped = skip_member(value, name, documenter.objtype) - if skipped is True: - pass - elif skipped is False: - # show the member forcedly - items.append(name) - public.append(name) - else: - items.append(name) - if name in include_public or not name.startswith('_'): - # considers member as public - public.append(name) - return public, items - - def get_module_attrs(members: Any) -> Tuple[List[str], List[str]]: - """Find module attributes with docstrings.""" - attrs, public = [], [] - try: - analyzer = ModuleAnalyzer.for_module(name) - attr_docs = analyzer.find_attr_docs() - for namespace, attr_name in attr_docs: - if namespace == '' and attr_name in members: - attrs.append(attr_name) - if not attr_name.startswith('_'): - public.append(attr_name) - except PycodeError: - pass # give up if ModuleAnalyzer fails to parse code - return public, attrs - - def get_modules(obj: Any) -> Tuple[List[str], List[str]]: - items: List[str] = [] - for _, modname, _ispkg in pkgutil.iter_modules(obj.__path__): - fullname = name + '.' + modname - try: - module = import_module(fullname) - if module and hasattr(module, '__sphinx_mock__'): - continue - except ImportError: - pass - - items.append(fullname) - public = [x for x in items if not x.split('.')[-1].startswith('_')] - return public, items - - ns: Dict[str, Any] = {} - ns.update(context) - - if doc.objtype == 'module': - scanner = ModuleScanner(app, obj) - ns['members'] = scanner.scan(imported_members) - ns['functions'], ns['all_functions'] = \ - get_members(obj, {'function'}, imported=imported_members) - ns['classes'], ns['all_classes'] = \ - get_members(obj, {'class'}, imported=imported_members) - ns['exceptions'], ns['all_exceptions'] = \ - get_members(obj, {'exception'}, imported=imported_members) - ns['attributes'], ns['all_attributes'] = \ - get_module_attrs(ns['members']) - ispackage = hasattr(obj, '__path__') - if ispackage and recursive: - ns['modules'], ns['all_modules'] = get_modules(obj) - elif doc.objtype == 'class': - ns['members'] = dir(obj) - ns['inherited_members'] = \ - set(dir(obj)) - set(obj.__dict__.keys()) - ns['methods'], ns['all_methods'] = \ - get_members(obj, {'method'}, ['__init__']) - ns['attributes'], ns['all_attributes'] = \ - get_members(obj, {'attribute', 'property'}) - - if modname is None or qualname is None: - modname, qualname = split_full_qualified_name(name) - - if doc.objtype in ('method', 'attribute', 'property'): - ns['class'] = qualname.rsplit(".", 1)[0] - - if doc.objtype in ('class',): - shortname = qualname - else: - shortname = qualname.rsplit(".", 1)[-1] - - ns['fullname'] = name - ns['module'] = modname - ns['objname'] = qualname - ns['name'] = shortname - - ns['objtype'] = doc.objtype - ns['underline'] = len(name) * '=' - - if template_name: - return template.render(template_name, ns) - else: - return template.render(doc.objtype, ns) - - -def generate_autosummary_docs(sources: List[str], output_dir: str = None, - suffix: str = '.rst', base_path: str = None, - builder: Builder = None, template_dir: str = None, - imported_members: bool = False, app: Any = None, - overwrite: bool = True, encoding: str = 'utf-8') -> None: - - if builder: - warnings.warn('builder argument for generate_autosummary_docs() is deprecated.', - RemovedInSphinx50Warning, stacklevel=2) - - if template_dir: - warnings.warn('template_dir argument for generate_autosummary_docs() is deprecated.', - RemovedInSphinx50Warning, stacklevel=2) - - showed_sources = list(sorted(sources)) - if len(showed_sources) > 20: - showed_sources = showed_sources[:10] + ['...'] + showed_sources[-10:] - logger.info(__('[autosummary] generating autosummary for: %s') % - ', '.join(showed_sources)) - - if output_dir: - logger.info(__('[autosummary] writing to %s') % output_dir) - - if base_path is not None: - sources = [os.path.join(base_path, filename) for filename in sources] - - template = AutosummaryRenderer(app) - - # read - items = find_autosummary_in_files(sources) - - # keep track of new files - new_files = [] - - if app: - filename_map = app.config.autosummary_filename_map - else: - filename_map = {} - - # write - for entry in sorted(set(items), key=str): - if entry.path is None: - # The corresponding autosummary:: directive did not have - # a :toctree: option - continue - - path = output_dir or os.path.abspath(entry.path) - ensuredir(path) - - try: - name, obj, parent, modname = import_by_name(entry.name, grouped_exception=True) - qualname = name.replace(modname + ".", "") - except ImportExceptionGroup as exc: - try: - # try to import as an instance attribute - name, obj, parent, modname = import_ivar_by_name(entry.name) - qualname = name.replace(modname + ".", "") - except ImportError as exc2: - if exc2.__cause__: - exceptions: List[BaseException] = exc.exceptions + [exc2.__cause__] - else: - exceptions = exc.exceptions + [exc2] - - errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exceptions)) - logger.warning(__('[autosummary] failed to import %s.\nPossible hints:\n%s'), - entry.name, '\n'.join(errors)) - continue - - context: Dict[str, Any] = {} - if app: - context.update(app.config.autosummary_context) - - content = generate_autosummary_content(name, obj, parent, template, entry.template, - imported_members, app, entry.recursive, context, - modname, qualname) - try: - py_source_rel = get_full_modname(modname, qualname).replace('.', '/') + '.py' - except: - logger.warning(name) - py_source_rel = '' - - re_view = f"\n.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/{app.config.docs_branch}/" + \ - f"resource/_static/logo_source_en.svg\n :target: " + app.config.giturl + \ - f"{app.config.copy_repo}/blob/{app.config.branch}/" + app.config.repo_whl + \ - py_source_rel.split(app.config.cst_module_name)[-1] + '\n :alt: View Source On Gitee\n\n' - - if re_view not in content and py_source_rel: - content = re.sub('([=]{5,})\n', r'\1\n' + re_view, content, 1) - filename = os.path.join(path, filename_map.get(name, name) + suffix) - if os.path.isfile(filename): - with open(filename, encoding=encoding) as f: - old_content = f.read() - - if content == old_content: - continue - elif overwrite: # content has changed - with open(filename, 'w', encoding=encoding) as f: - f.write(content) - new_files.append(filename) - else: - with open(filename, 'w', encoding=encoding) as f: - f.write(content) - new_files.append(filename) - - # descend recursively to new files - if new_files: - generate_autosummary_docs(new_files, output_dir=output_dir, - suffix=suffix, base_path=base_path, - builder=builder, template_dir=template_dir, - imported_members=imported_members, app=app, - overwrite=overwrite) - - -# -- Finding documented entries in files --------------------------------------- - -def find_autosummary_in_files(filenames: List[str]) -> List[AutosummaryEntry]: - """Find out what items are documented in source/*.rst. - - See `find_autosummary_in_lines`. - """ - documented: List[AutosummaryEntry] = [] - for filename in filenames: - with open(filename, encoding='utf-8', errors='ignore') as f: - lines = f.read().splitlines() - documented.extend(find_autosummary_in_lines(lines, filename=filename)) - return documented - - -def find_autosummary_in_docstring(name: str, module: str = None, filename: str = None - ) -> List[AutosummaryEntry]: - """Find out what items are documented in the given object's docstring. - - See `find_autosummary_in_lines`. - """ - if module: - warnings.warn('module argument for find_autosummary_in_docstring() is deprecated.', - RemovedInSphinx50Warning, stacklevel=2) - - try: - real_name, obj, parent, modname = import_by_name(name, grouped_exception=True) - lines = pydoc.getdoc(obj).splitlines() - return find_autosummary_in_lines(lines, module=name, filename=filename) - except AttributeError: - pass - except ImportExceptionGroup as exc: - errors = list(set("* %s: %s" % (type(e).__name__, e) for e in exc.exceptions)) - print('Failed to import %s.\nPossible hints:\n%s' % (name, '\n'.join(errors))) - except SystemExit: - print("Failed to import '%s'; the module executes module level " - "statement and it might call sys.exit()." % name) - return [] - - -def find_autosummary_in_lines(lines: List[str], module: str = None, filename: str = None - ) -> List[AutosummaryEntry]: - """Find out what items appear in autosummary:: directives in the - given lines. - - Returns a list of (name, toctree, template) where *name* is a name - of an object and *toctree* the :toctree: path of the corresponding - autosummary directive (relative to the root of the file name), and - *template* the value of the :template: option. *toctree* and - *template* ``None`` if the directive does not have the - corresponding options set. - """ - autosummary_re = re.compile(r'^(\s*)\.\.\s+(ms[a-z]*)?autosummary::\s*') - automodule_re = re.compile( - r'^\s*\.\.\s+automodule::\s*([A-Za-z0-9_.]+)\s*$') - module_re = re.compile( - r'^\s*\.\.\s+(current)?module::\s*([a-zA-Z0-9_.]+)\s*$') - autosummary_item_re = re.compile(r'^\s+(~?[_a-zA-Z][a-zA-Z0-9_.]*)\s*.*?') - recursive_arg_re = re.compile(r'^\s+:recursive:\s*$') - toctree_arg_re = re.compile(r'^\s+:toctree:\s*(.*?)\s*$') - template_arg_re = re.compile(r'^\s+:template:\s*(.*?)\s*$') - - documented: List[AutosummaryEntry] = [] - - recursive = False - toctree: str = None - template = None - current_module = module - in_autosummary = False - base_indent = "" - - for line in lines: - if in_autosummary: - m = recursive_arg_re.match(line) - if m: - recursive = True - continue - - m = toctree_arg_re.match(line) - if m: - toctree = m.group(1) - if filename: - toctree = os.path.join(os.path.dirname(filename), - toctree) - continue - - m = template_arg_re.match(line) - if m: - template = m.group(1).strip() - continue - - if line.strip().startswith(':'): - continue # skip options - - m = autosummary_item_re.match(line) - if m: - name = m.group(1).strip() - if name.startswith('~'): - name = name[1:] - if current_module and \ - not name.startswith(current_module + '.'): - name = "%s.%s" % (current_module, name) - documented.append(AutosummaryEntry(name, toctree, template, recursive)) - continue - - if not line.strip() or line.startswith(base_indent + " "): - continue - - in_autosummary = False - - m = autosummary_re.match(line) - if m: - in_autosummary = True - base_indent = m.group(1) - recursive = False - toctree = None - template = None - continue - - m = automodule_re.search(line) - if m: - current_module = m.group(1).strip() - # recurse into the automodule docstring - documented.extend(find_autosummary_in_docstring( - current_module, filename=filename)) - continue - - m = module_re.match(line) - if m: - current_module = m.group(2) - continue - - return documented - - -def get_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - usage='%(prog)s [OPTIONS] ...', - epilog=__('For more information, visit .'), - description=__(""" -Generate ReStructuredText using autosummary directives. - -sphinx-autogen is a frontend to sphinx.ext.autosummary.generate. It generates -the reStructuredText files from the autosummary directives contained in the -given input files. - -The format of the autosummary directive is documented in the -``sphinx.ext.autosummary`` Python module and can be read using:: - - pydoc sphinx.ext.autosummary -""")) - - parser.add_argument('--version', action='version', dest='show_version', - version='%%(prog)s %s' % __display_version__) - - parser.add_argument('source_file', nargs='+', - help=__('source files to generate rST files for')) - - parser.add_argument('-o', '--output-dir', action='store', - dest='output_dir', - help=__('directory to place all output in')) - parser.add_argument('-s', '--suffix', action='store', dest='suffix', - default='rst', - help=__('default suffix for files (default: ' - '%(default)s)')) - parser.add_argument('-t', '--templates', action='store', dest='templates', - default=None, - help=__('custom template directory (default: ' - '%(default)s)')) - parser.add_argument('-i', '--imported-members', action='store_true', - dest='imported_members', default=False, - help=__('document imported members (default: ' - '%(default)s)')) - parser.add_argument('-a', '--respect-module-all', action='store_true', - dest='respect_module_all', default=False, - help=__('document exactly the members in module __all__ attribute. ' - '(default: %(default)s)')) - - return parser - - -def main(argv: List[str] = sys.argv[1:]) -> None: - sphinx.locale.setlocale(locale.LC_ALL, '') - sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx') - translator, _ = sphinx.locale.init([], None) - - app = DummyApplication(translator) - logging.setup(app, sys.stdout, sys.stderr) # type: ignore - setup_documenters(app) - args = get_parser().parse_args(argv) - - if args.templates: - app.config.templates_path.append(path.abspath(args.templates)) - app.config.autosummary_ignore_module_all = not args.respect_module_all # type: ignore - - generate_autosummary_docs(args.source_file, args.output_dir, - '.' + args.suffix, - imported_members=args.imported_members, - app=app) - - -if __name__ == '__main__': - main() diff --git a/docs/mindformers/docs/_ext/overwriteobjectiondirective.txt b/docs/mindformers/docs/_ext/overwriteobjectiondirective.txt deleted file mode 100644 index 8a58bf71191f77ca22097ea9de244c9df5c3d4fb..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/_ext/overwriteobjectiondirective.txt +++ /dev/null @@ -1,368 +0,0 @@ -""" - sphinx.directives - ~~~~~~~~~~~~~~~~~ - - Handlers for additional ReST directives. - - :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -import re -import inspect -import importlib -from typing import TYPE_CHECKING, Any, Dict, Generic, List, Tuple, TypeVar, cast - -from docutils import nodes -from docutils.nodes import Node -from docutils.parsers.rst import directives, roles - -from sphinx import addnodes -from sphinx.addnodes import desc_signature -from sphinx.deprecation import RemovedInSphinx50Warning, deprecated_alias -from sphinx.util import docutils, logging -from sphinx.util.docfields import DocFieldTransformer, Field, TypedField -from sphinx.util.docutils import SphinxDirective -from sphinx.util.typing import OptionSpec - -if TYPE_CHECKING: - from sphinx.application import Sphinx - - -# RE to strip backslash escapes -nl_escape_re = re.compile(r'\\\n') -strip_backslash_re = re.compile(r'\\(.)') - -T = TypeVar('T') -logger = logging.getLogger(__name__) - -def optional_int(argument: str) -> int: - """ - Check for an integer argument or None value; raise ``ValueError`` if not. - """ - if argument is None: - return None - else: - value = int(argument) - if value < 0: - raise ValueError('negative value; must be positive or zero') - return value - -def get_api(fullname): - try: - module_name, api_name= ".".join(fullname.split('.')[:-1]), fullname.split('.')[-1] - module_import = importlib.import_module(module_name) - except ModuleNotFoundError: - module_name, api_name = ".".join(fullname.split('.')[:-2]), ".".join(fullname.split('.')[-2:]) - module_import = importlib.import_module(module_name) - api = eval(f"module_import.{api_name}") - return api - -def get_example(name: str): - try: - api_doc = inspect.getdoc(get_api(name)) - example_str = re.findall(r'Examples:\n([\w\W]*?)(\n\n|$)', api_doc) - if not example_str: - return [] - example_str = re.sub(r'\n\s+', r'\n', example_str[0][0]) - example_str = example_str.strip() - example_list = example_str.split('\n') - return ["", "**样例:**", ""] + example_list + [""] - except: - return [] - -def get_platforms(name: str): - try: - api_doc = inspect.getdoc(get_api(name)) - example_str = re.findall(r'Supported Platforms:\n\s+(.*?)\n\n', api_doc) - if not example_str: - example_str_leak = re.findall(r'Supported Platforms:\n\s+(.*)', api_doc) - if example_str_leak: - example_str = example_str_leak[0].strip() - example_list = example_str.split('\n') - example_list = [' ' + example_list[0]] - return ["", "支持平台:"] + example_list + [""] - return [] - example_str = example_str[0].strip() - example_list = example_str.split('\n') - example_list = [' ' + example_list[0]] - return ["", "支持平台:"] + example_list + [""] - except: - return [] - -class ObjectDescription(SphinxDirective, Generic[T]): - """ - Directive to describe a class, function or similar object. Not used - directly, but subclassed (in domain-specific directives) to add custom - behavior. - """ - - has_content = True - required_arguments = 1 - optional_arguments = 0 - final_argument_whitespace = True - option_spec: OptionSpec = { - 'noindex': directives.flag, - } # type: Dict[str, DirectiveOption] - - # types of doc fields that this directive handles, see sphinx.util.docfields - doc_field_types: List[Field] = [] - domain: str = None - objtype: str = None - indexnode: addnodes.index = None - - # Warning: this might be removed in future version. Don't touch this from extensions. - _doc_field_type_map = {} # type: Dict[str, Tuple[Field, bool]] - - def get_field_type_map(self) -> Dict[str, Tuple[Field, bool]]: - if self._doc_field_type_map == {}: - self._doc_field_type_map = {} - for field in self.doc_field_types: - for name in field.names: - self._doc_field_type_map[name] = (field, False) - - if field.is_typed: - typed_field = cast(TypedField, field) - for name in typed_field.typenames: - self._doc_field_type_map[name] = (field, True) - - return self._doc_field_type_map - - def get_signatures(self) -> List[str]: - """ - Retrieve the signatures to document from the directive arguments. By - default, signatures are given as arguments, one per line. - - Backslash-escaping of newlines is supported. - """ - lines = nl_escape_re.sub('', self.arguments[0]).split('\n') - if self.config.strip_signature_backslash: - # remove backslashes to support (dummy) escapes; helps Vim highlighting - return [strip_backslash_re.sub(r'\1', line.strip()) for line in lines] - else: - return [line.strip() for line in lines] - - def handle_signature(self, sig: str, signode: desc_signature) -> Any: - """ - Parse the signature *sig* into individual nodes and append them to - *signode*. If ValueError is raised, parsing is aborted and the whole - *sig* is put into a single desc_name node. - - The return value should be a value that identifies the object. It is - passed to :meth:`add_target_and_index()` unchanged, and otherwise only - used to skip duplicates. - """ - raise ValueError - - def add_target_and_index(self, name: Any, sig: str, signode: desc_signature) -> None: - """ - Add cross-reference IDs and entries to self.indexnode, if applicable. - - *name* is whatever :meth:`handle_signature()` returned. - """ - return # do nothing by default - - def before_content(self) -> None: - """ - Called before parsing content. Used to set information about the current - directive context on the build environment. - """ - pass - - def transform_content(self, contentnode: addnodes.desc_content) -> None: - """ - Called after creating the content through nested parsing, - but before the ``object-description-transform`` event is emitted, - and before the info-fields are transformed. - Can be used to manipulate the content. - """ - pass - - def after_content(self) -> None: - """ - Called after parsing content. Used to reset information about the - current directive context on the build environment. - """ - pass - - def check_class_end(self, content): - for i in content: - if not i.startswith('.. include::') and i != "\n" and i != "": - return False - return True - - def extend_items(self, rst_file, start_num, num): - ls = [] - for i in range(1, num+1): - ls.append((rst_file, start_num+i)) - return ls - - def run(self) -> List[Node]: - """ - Main directive entry function, called by docutils upon encountering the - directive. - - This directive is meant to be quite easily subclassable, so it delegates - to several additional methods. What it does: - - * find out if called as a domain-specific directive, set self.domain - * create a `desc` node to fit all description inside - * parse standard options, currently `noindex` - * create an index node if needed as self.indexnode - * parse all given signatures (as returned by self.get_signatures()) - using self.handle_signature(), which should either return a name - or raise ValueError - * add index entries using self.add_target_and_index() - * parse the content and handle doc fields in it - """ - if ':' in self.name: - self.domain, self.objtype = self.name.split(':', 1) - else: - self.domain, self.objtype = '', self.name - self.indexnode = addnodes.index(entries=[]) - - node = addnodes.desc() - node.document = self.state.document - node['domain'] = self.domain - # 'desctype' is a backwards compatible attribute - node['objtype'] = node['desctype'] = self.objtype - node['noindex'] = noindex = ('noindex' in self.options) - if self.domain: - node['classes'].append(self.domain) - node['classes'].append(node['objtype']) - - self.names: List[T] = [] - signatures = self.get_signatures() - for sig in signatures: - # add a signature node for each signature in the current unit - # and add a reference target for it - signode = addnodes.desc_signature(sig, '') - self.set_source_info(signode) - node.append(signode) - try: - # name can also be a tuple, e.g. (classname, objname); - # this is strictly domain-specific (i.e. no assumptions may - # be made in this base class) - name = self.handle_signature(sig, signode) - except ValueError: - # signature parsing failed - signode.clear() - signode += addnodes.desc_name(sig, sig) - continue # we don't want an index entry here - if name not in self.names: - self.names.append(name) - if not noindex: - # only add target and index entry if this is the first - # description of the object with this name in this desc block - self.add_target_and_index(name, sig, signode) - - contentnode = addnodes.desc_content() - node.append(contentnode) - if self.names: - # needed for association of version{added,changed} directives - self.env.temp_data['object'] = self.names[0] - self.before_content() - try: - example = get_example(self.names[0][0]) - platforms = get_platforms(self.names[0][0]) - except Exception as e: - example = '' - platforms = '' - logger.warning(f'Error API names in {self.arguments[0]}.') - logger.warning(f'{e}') - extra = platforms + example - if extra: - if self.objtype == "method": - self.content.data.extend(extra) - else: - index_num = 0 - for num, i in enumerate(self.content.data): - if i.startswith('.. py:method::') or self.check_class_end(self.content.data[num:]): - index_num = num - break - if index_num: - count = len(self.content.data) - for i in extra: - self.content.data.insert(index_num-count, i) - else: - self.content.data.extend(extra) - try: - self.content.items.extend(self.extend_items(self.content.items[0][0], self.content.items[-1][1], len(extra))) - except Exception as e: - logger.warning(f'{e}') - self.state.nested_parse(self.content, self.content_offset, contentnode) - self.transform_content(contentnode) - self.env.app.emit('object-description-transform', - self.domain, self.objtype, contentnode) - DocFieldTransformer(self).transform_all(contentnode) - self.env.temp_data['object'] = None - self.after_content() - return [self.indexnode, node] - - -class DefaultRole(SphinxDirective): - """ - Set the default interpreted text role. Overridden from docutils. - """ - - optional_arguments = 1 - final_argument_whitespace = False - - def run(self) -> List[Node]: - if not self.arguments: - docutils.unregister_role('') - return [] - role_name = self.arguments[0] - role, messages = roles.role(role_name, self.state_machine.language, - self.lineno, self.state.reporter) - if role: - docutils.register_role('', role) - self.env.temp_data['default_role'] = role_name - else: - literal_block = nodes.literal_block(self.block_text, self.block_text) - reporter = self.state.reporter - error = reporter.error('Unknown interpreted text role "%s".' % role_name, - literal_block, line=self.lineno) - messages += [error] - - return cast(List[nodes.Node], messages) - - -class DefaultDomain(SphinxDirective): - """ - Directive to (re-)set the default domain for this source file. - """ - - has_content = False - required_arguments = 1 - optional_arguments = 0 - final_argument_whitespace = False - option_spec = {} # type: Dict - - def run(self) -> List[Node]: - domain_name = self.arguments[0].lower() - # if domain_name not in env.domains: - # # try searching by label - # for domain in env.domains.values(): - # if domain.label.lower() == domain_name: - # domain_name = domain.name - # break - self.env.temp_data['default_domain'] = self.env.domains.get(domain_name) - return [] - -def setup(app: "Sphinx") -> Dict[str, Any]: - app.add_config_value("strip_signature_backslash", False, 'env') - directives.register_directive('default-role', DefaultRole) - directives.register_directive('default-domain', DefaultDomain) - directives.register_directive('describe', ObjectDescription) - # new, more consistent, name - directives.register_directive('object', ObjectDescription) - - app.add_event('object-description-transform') - - return { - 'version': 'builtin', - 'parallel_read_safe': True, - 'parallel_write_safe': True, - } - diff --git a/docs/mindformers/docs/_ext/overwriteviewcode.txt b/docs/mindformers/docs/_ext/overwriteviewcode.txt deleted file mode 100644 index 172780ec56b3ed90e7b0add617257a618cf38ee0..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/_ext/overwriteviewcode.txt +++ /dev/null @@ -1,378 +0,0 @@ -""" - sphinx.ext.viewcode - ~~~~~~~~~~~~~~~~~~~ - - Add links to module code in Python object descriptions. - - :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -import posixpath -import traceback -import warnings -from os import path -from typing import Any, Dict, Generator, Iterable, Optional, Set, Tuple, cast - -from docutils import nodes -from docutils.nodes import Element, Node - -import sphinx -from sphinx import addnodes -from sphinx.application import Sphinx -from sphinx.builders import Builder -from sphinx.builders.html import StandaloneHTMLBuilder -from sphinx.deprecation import RemovedInSphinx50Warning -from sphinx.environment import BuildEnvironment -from sphinx.locale import _, __ -from sphinx.pycode import ModuleAnalyzer -from sphinx.transforms.post_transforms import SphinxPostTransform -from sphinx.util import get_full_modname, logging, status_iterator -from sphinx.util.nodes import make_refnode - - -logger = logging.getLogger(__name__) - - -OUTPUT_DIRNAME = '_modules' - - -class viewcode_anchor(Element): - """Node for viewcode anchors. - - This node will be processed in the resolving phase. - For viewcode supported builders, they will be all converted to the anchors. - For not supported builders, they will be removed. - """ - - -def _get_full_modname(app: Sphinx, modname: str, attribute: str) -> Optional[str]: - try: - return get_full_modname(modname, attribute) - except AttributeError: - # sphinx.ext.viewcode can't follow class instance attribute - # then AttributeError logging output only verbose mode. - logger.verbose('Didn\'t find %s in %s', attribute, modname) - return None - except Exception as e: - # sphinx.ext.viewcode follow python domain directives. - # because of that, if there are no real modules exists that specified - # by py:function or other directives, viewcode emits a lot of warnings. - # It should be displayed only verbose mode. - logger.verbose(traceback.format_exc().rstrip()) - logger.verbose('viewcode can\'t import %s, failed with error "%s"', modname, e) - return None - - -def is_supported_builder(builder: Builder) -> bool: - if builder.format != 'html': - return False - elif builder.name == 'singlehtml': - return False - elif builder.name.startswith('epub') and not builder.config.viewcode_enable_epub: - return False - else: - return True - - -def doctree_read(app: Sphinx, doctree: Node) -> None: - env = app.builder.env - if not hasattr(env, '_viewcode_modules'): - env._viewcode_modules = {} # type: ignore - - def has_tag(modname: str, fullname: str, docname: str, refname: str) -> bool: - entry = env._viewcode_modules.get(modname, None) # type: ignore - if entry is False: - return False - - code_tags = app.emit_firstresult('viewcode-find-source', modname) - if code_tags is None: - try: - analyzer = ModuleAnalyzer.for_module(modname) - analyzer.find_tags() - except Exception: - env._viewcode_modules[modname] = False # type: ignore - return False - - code = analyzer.code - tags = analyzer.tags - else: - code, tags = code_tags - - if entry is None or entry[0] != code: - entry = code, tags, {}, refname - env._viewcode_modules[modname] = entry # type: ignore - _, tags, used, _ = entry - if fullname in tags: - used[fullname] = docname - return True - - return False - - for objnode in list(doctree.findall(addnodes.desc)): - if objnode.get('domain') != 'py': - continue - names: Set[str] = set() - for signode in objnode: - if not isinstance(signode, addnodes.desc_signature): - continue - modname = signode.get('module') - fullname = signode.get('fullname') - try: - if fullname and modname==None: - if fullname.split('.')[-1].lower() == fullname.split('.')[-1] and fullname.split('.')[-2].lower() != fullname.split('.')[-2]: - modname = '.'.join(fullname.split('.')[:-2]) - fullname = '.'.join(fullname.split('.')[-2:]) - else: - modname = '.'.join(fullname.split('.')[:-1]) - fullname = fullname.split('.')[-1] - fullname_new = fullname - except Exception: - logger.warning(f'error_modename:{modname}') - logger.warning(f'error_fullname:{fullname}') - refname = modname - if env.config.viewcode_follow_imported_members: - new_modname = app.emit_firstresult( - 'viewcode-follow-imported', modname, fullname, - ) - if not new_modname: - new_modname = _get_full_modname(app, modname, fullname) - modname = new_modname - # logger.warning(f'new_modename:{modname}') - if not modname: - continue - # fullname = signode.get('fullname') - # if fullname and modname==None: - fullname = fullname_new - if not has_tag(modname, fullname, env.docname, refname): - continue - if fullname in names: - # only one link per name, please - continue - names.add(fullname) - pagename = posixpath.join(OUTPUT_DIRNAME, modname.replace('.', '/')) - signode += viewcode_anchor(reftarget=pagename, refid=fullname, refdoc=env.docname) - - -def env_merge_info(app: Sphinx, env: BuildEnvironment, docnames: Iterable[str], - other: BuildEnvironment) -> None: - if not hasattr(other, '_viewcode_modules'): - return - # create a _viewcode_modules dict on the main environment - if not hasattr(env, '_viewcode_modules'): - env._viewcode_modules = {} # type: ignore - # now merge in the information from the subprocess - for modname, entry in other._viewcode_modules.items(): # type: ignore - if modname not in env._viewcode_modules: # type: ignore - env._viewcode_modules[modname] = entry # type: ignore - else: - if env._viewcode_modules[modname]: # type: ignore - used = env._viewcode_modules[modname][2] # type: ignore - for fullname, docname in entry[2].items(): - if fullname not in used: - used[fullname] = docname - - -def env_purge_doc(app: Sphinx, env: BuildEnvironment, docname: str) -> None: - modules = getattr(env, '_viewcode_modules', {}) - - for modname, entry in list(modules.items()): - if entry is False: - continue - - code, tags, used, refname = entry - for fullname in list(used): - if used[fullname] == docname: - used.pop(fullname) - - if len(used) == 0: - modules.pop(modname) - - -class ViewcodeAnchorTransform(SphinxPostTransform): - """Convert or remove viewcode_anchor nodes depends on builder.""" - default_priority = 100 - - def run(self, **kwargs: Any) -> None: - if is_supported_builder(self.app.builder): - self.convert_viewcode_anchors() - else: - self.remove_viewcode_anchors() - - def convert_viewcode_anchors(self) -> None: - for node in self.document.findall(viewcode_anchor): - anchor = nodes.inline('', _('[源代码]'), classes=['viewcode-link']) - refnode = make_refnode(self.app.builder, node['refdoc'], node['reftarget'], - node['refid'], anchor) - node.replace_self(refnode) - - def remove_viewcode_anchors(self) -> None: - for node in list(self.document.findall(viewcode_anchor)): - node.parent.remove(node) - - -def missing_reference(app: Sphinx, env: BuildEnvironment, node: Element, contnode: Node - ) -> Optional[Node]: - # resolve our "viewcode" reference nodes -- they need special treatment - if node['reftype'] == 'viewcode': - warnings.warn('viewcode extension is no longer use pending_xref node. ' - 'Please update your extension.', RemovedInSphinx50Warning) - return make_refnode(app.builder, node['refdoc'], node['reftarget'], - node['refid'], contnode) - - return None - - -def get_module_filename(app: Sphinx, modname: str) -> Optional[str]: - """Get module filename for *modname*.""" - source_info = app.emit_firstresult('viewcode-find-source', modname) - if source_info: - return None - else: - try: - filename, source = ModuleAnalyzer.get_module_source(modname) - return filename - except Exception: - return None - - -def should_generate_module_page(app: Sphinx, modname: str) -> bool: - """Check generation of module page is needed.""" - module_filename = get_module_filename(app, modname) - if module_filename is None: - # Always (re-)generate module page when module filename is not found. - return True - - builder = cast(StandaloneHTMLBuilder, app.builder) - basename = modname.replace('.', '/') + builder.out_suffix - page_filename = path.join(app.outdir, '_modules/', basename) - - try: - if path.getmtime(module_filename) <= path.getmtime(page_filename): - # generation is not needed if the HTML page is newer than module file. - return False - except IOError: - pass - - return True - - -def collect_pages(app: Sphinx) -> Generator[Tuple[str, Dict[str, Any], str], None, None]: - env = app.builder.env - if not hasattr(env, '_viewcode_modules'): - return - if not is_supported_builder(app.builder): - return - highlighter = app.builder.highlighter # type: ignore - urito = app.builder.get_relative_uri - - modnames = set(env._viewcode_modules) # type: ignore - - for modname, entry in status_iterator( - sorted(env._viewcode_modules.items()), # type: ignore - __('highlighting module code... '), "blue", - len(env._viewcode_modules), # type: ignore - app.verbosity, lambda x: x[0]): - if not entry: - continue - if not should_generate_module_page(app, modname): - continue - - code, tags, used, refname = entry - # construct a page name for the highlighted source - pagename = posixpath.join(OUTPUT_DIRNAME, modname.replace('.', '/')) - # highlight the source using the builder's highlighter - if env.config.highlight_language in ('python3', 'default', 'none'): - lexer = env.config.highlight_language - else: - lexer = 'python' - highlighted = highlighter.highlight_block(code, lexer, linenos=False) - # split the code into lines - lines = highlighted.splitlines() - # split off wrap markup from the first line of the actual code - before, after = lines[0].split('
')
-        lines[0:1] = [before + '
', after]
-        # nothing to do for the last line; it always starts with 
anyway - # now that we have code lines (starting at index 1), insert anchors for - # the collected tags (HACK: this only works if the tag boundaries are - # properly nested!) - maxindex = len(lines) - 1 - for name, docname in used.items(): - type, start, end = tags[name] - backlink = urito(pagename, docname) + '#' + refname + '.' + name - lines[start] = ( - '
%s' % (name, backlink, _('[文档]')) + - lines[start]) - lines[min(end, maxindex)] += '
' - # try to find parents (for submodules) - parents = [] - parent = modname - while '.' in parent: - parent = parent.rsplit('.', 1)[0] - if parent in modnames: - parents.append({ - 'link': urito(pagename, - posixpath.join(OUTPUT_DIRNAME, parent.replace('.', '/'))), - 'title': parent}) - parents.append({'link': urito(pagename, posixpath.join(OUTPUT_DIRNAME, 'index')), - 'title': _('Module code')}) - parents.reverse() - # putting it all together - context = { - 'parents': parents, - 'title': modname, - 'body': (_('

Source code for %s

') % modname + - '\n'.join(lines)), - } - yield (pagename, context, 'page.html') - - if not modnames: - return - - html = ['\n'] - # the stack logic is needed for using nested lists for submodules - stack = [''] - for modname in sorted(modnames): - if modname.startswith(stack[-1]): - stack.append(modname + '.') - html.append('
    ') - else: - stack.pop() - while not modname.startswith(stack[-1]): - stack.pop() - html.append('
') - stack.append(modname + '.') - html.append('
  • %s
  • \n' % ( - urito(posixpath.join(OUTPUT_DIRNAME, 'index'), - posixpath.join(OUTPUT_DIRNAME, modname.replace('.', '/'))), - modname)) - html.append('' * (len(stack) - 1)) - context = { - 'title': _('Overview: module code'), - 'body': (_('

    All modules for which code is available

    ') + - ''.join(html)), - } - - yield (posixpath.join(OUTPUT_DIRNAME, 'index'), context, 'page.html') - - -def setup(app: Sphinx) -> Dict[str, Any]: - app.add_config_value('viewcode_import', None, False) - app.add_config_value('viewcode_enable_epub', False, False) - app.add_config_value('viewcode_follow_imported_members', True, False) - app.connect('doctree-read', doctree_read) - app.connect('env-merge-info', env_merge_info) - app.connect('env-purge-doc', env_purge_doc) - app.connect('html-collect-pages', collect_pages) - app.connect('missing-reference', missing_reference) - # app.add_config_value('viewcode_include_modules', [], 'env') - # app.add_config_value('viewcode_exclude_modules', [], 'env') - app.add_event('viewcode-find-source') - app.add_event('viewcode-follow-imported') - app.add_post_transform(ViewcodeAnchorTransform) - return { - 'version': sphinx.__display_version__, - 'env_version': 1, - 'parallel_read_safe': True - } diff --git a/docs/mindformers/docs/requirements.txt b/docs/mindformers/docs/requirements.txt deleted file mode 100644 index a1b6a69f6dbd9c6f78710f56889e14f0e85b27f4..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -sphinx == 4.4.0 -docutils == 0.17.1 -myst-parser == 0.18.1 -sphinx_rtd_theme == 1.0.0 -numpy -IPython -jieba diff --git a/docs/mindformers/docs/source_en/advanced_interface.md b/docs/mindformers/docs/source_en/advanced_interface.md deleted file mode 100644 index 1dc3d7f2cdfb916e4ac0c7a3a648f0eca27082e1..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/advanced_interface.md +++ /dev/null @@ -1,7 +0,0 @@ -# High-Level Interface Guide - -## AutoClass - -## Pipeline - -## Trainer \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/aicc.md b/docs/mindformers/docs/source_en/aicc.md deleted file mode 100644 index c571195d89634e6f88537cd9caa5f951ef276a04..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/aicc.md +++ /dev/null @@ -1 +0,0 @@ -# AICC Guide diff --git a/docs/mindformers/docs/source_en/api_register.md b/docs/mindformers/docs/source_en/api_register.md deleted file mode 100644 index 035ea3c7f9d9a557ad37e93e82bcd302f369461c..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/api_register.md +++ /dev/null @@ -1,5 +0,0 @@ -# Introduction to API Registration Mechanism - -## API Component Registration Mechanism - -## API Component Build Mechanisms \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/api_startup.md b/docs/mindformers/docs/source_en/api_startup.md deleted file mode 100644 index 08e60b8cda63b2c8c8bf355b919724c17d4025cd..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/api_startup.md +++ /dev/null @@ -1 +0,0 @@ -# Calling API Startup diff --git a/docs/mindformers/docs/source_en/conf.py b/docs/mindformers/docs/source_en/conf.py deleted file mode 100644 index dd9f30bec3b7ffdc217f1eb1e14e9387b412b085..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/conf.py +++ /dev/null @@ -1,175 +0,0 @@ -# Configuration file for the Sphinx documentation builder. -# -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -import os -import shutil -import IPython -import re -import sys -import sphinx.ext.autosummary.generate as g -from sphinx.ext import autodoc as sphinx_autodoc - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = 'MindSpore' -author = 'MindSpore' - -# The full version, including alpha/beta/rc tags -release = 'master' - - -# -- General configuration --------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -myst_enable_extensions = ["dollarmath", "amsmath"] - - -myst_heading_anchors = 5 -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'myst_parser', - 'sphinx.ext.mathjax', - 'IPython.sphinxext.ipython_console_highlighting' -] - -source_suffix = { - '.rst': 'restructuredtext', - '.md': 'markdown', -} - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. -mathjax_path = 'https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/mathjax/MathJax-3.2.2/es5/tex-mml-chtml.js' - -mathjax_options = { - 'async':'async' -} - -smartquotes_action = 'De' - -exclude_patterns = [] - -pygments_style = 'sphinx' - -autodoc_inherit_docstrings = False - -# -- Options for HTML output ------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -html_theme = 'sphinx_rtd_theme' - -import sphinx_rtd_theme -layout_target = os.path.join(os.path.dirname(sphinx_rtd_theme.__file__), 'layout.html') -layout_src = '../../../../resource/_static/layout.html' -if os.path.exists(layout_target): - os.remove(layout_target) -shutil.copy(layout_src, layout_target) - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - 'python': ('https://docs.python.org/', '../../../../resource/python_objects.inv'), - 'numpy': ('https://docs.scipy.org/doc/numpy/', '../../../../resource/numpy_objects.inv'), -} - -# overwriteautosummary_generate add view source for api and more autosummary class availably. -# with open('../_ext/overwriteautosummary_generate.txt', 'r', encoding="utf8") as f: -# exec(f.read(), g.__dict__) - -# Modify default signatures for autodoc. -autodoc_source_path = os.path.abspath(sphinx_autodoc.__file__) -autodoc_source_re = re.compile(r'stringify_signature\(.*?\)') -get_param_func_str = r"""\ -import re -import inspect as inspect_ - -def get_param_func(func): - try: - source_code = inspect_.getsource(func) - if func.__doc__: - source_code = source_code.replace(func.__doc__, '') - all_params_str = re.findall(r"def [\w_\d\-]+\(([\S\s]*?)(\):|\) ->.*?:)", source_code) - all_params = re.sub("(self|cls)(,|, )?", '', all_params_str[0][0].replace("\n", "").replace("'", "\"")) - return all_params - except: - return '' - -def get_obj(obj): - if isinstance(obj, type): - return obj.__init__ - - return obj -""" - -with open(autodoc_source_path, "r+", encoding="utf8") as f: - code_str = f.read() - code_str = autodoc_source_re.sub('"(" + get_param_func(get_obj(self.object)) + ")"', code_str, count=0) - exec(get_param_func_str, sphinx_autodoc.__dict__) - exec(code_str, sphinx_autodoc.__dict__) - -# get params for add view source -# import json - -# if os.path.exists('../../../../tools/generate_html/version.json'): -# with open('../../../../tools/generate_html/version.json', 'r+', encoding='utf-8') as f: -# version_inf = json.load(f) -# elif os.path.exists('../../../../tools/generate_html/daily_dev.json'): -# with open('../../../../tools/generate_html/daily_dev.json', 'r+', encoding='utf-8') as f: -# version_inf = json.load(f) -# elif os.path.exists('../../../../tools/generate_html/daily.json'): -# with open('../../../../tools/generate_html/daily.json', 'r+', encoding='utf-8') as f: -# version_inf = json.load(f) - -# if os.getenv("MI_PATH").split('/')[-1]: -# copy_repo = os.getenv("MI_PATH").split('/')[-1] -# else: -# copy_repo = os.getenv("MI_PATH").split('/')[-2] - -# branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == copy_repo][0] -# docs_branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == 'tutorials'][0] -# cst_module_name = 'mindformers' -# repo_whl = 'mindformers' -# giturl = 'https://gitee.com/mindspore/' - -sys.path.append(os.path.abspath('../../../../resource/sphinx_ext')) -# import anchor_mod -import nbsphinx_mod - -sys.path.append(os.path.abspath('../../../../resource/search')) -import search_code - -sys.path.append(os.path.abspath('../../../../resource/custom_directives')) -from custom_directives import IncludeCodeDirective - -def setup(app): - app.add_directive('includecode', IncludeCodeDirective) - # app.add_config_value('docs_branch', '', True) - # app.add_config_value('branch', '', True) - # app.add_config_value('cst_module_name', '', True) - # app.add_config_value('copy_repo', '', True) - # app.add_config_value('giturl', '', True) - # app.add_config_value('repo_whl', '', True) - diff --git a/docs/mindformers/docs/source_en/configuration.md b/docs/mindformers/docs/source_en/configuration.md deleted file mode 100644 index bbee8bb8a78bb60a5eb30f4cedb4687a2a02ca65..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/configuration.md +++ /dev/null @@ -1 +0,0 @@ -# Configuration File Description diff --git a/docs/mindformers/docs/source_en/contribution_guide.md b/docs/mindformers/docs/source_en/contribution_guide.md deleted file mode 100644 index ffe6d1e12b6022f463b239146b9f228517ada51e..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/contribution_guide.md +++ /dev/null @@ -1 +0,0 @@ -# MindFormers Contribution Guide \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/data_process.md b/docs/mindformers/docs/source_en/data_process.md deleted file mode 100644 index 0f2795ea65890236d4643656a27e2febbca56a49..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/data_process.md +++ /dev/null @@ -1 +0,0 @@ -# Data Processing diff --git a/docs/mindformers/docs/source_en/env_variable.md b/docs/mindformers/docs/source_en/env_variable.md deleted file mode 100644 index c9c1a91278b3358f79f9273b7f53598153f5e04f..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/env_variable.md +++ /dev/null @@ -1 +0,0 @@ -# Description of Environment Variables diff --git a/docs/mindformers/docs/source_en/evaluation.md b/docs/mindformers/docs/source_en/evaluation.md deleted file mode 100644 index a203c1b76ed3064a81fadc1caa5f35df22e2c546..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/evaluation.md +++ /dev/null @@ -1,3 +0,0 @@ -# Evaluation - -## Evaluation While Training diff --git a/docs/mindformers/docs/source_en/faq_advanced_interface.md b/docs/mindformers/docs/source_en/faq_advanced_interface.md deleted file mode 100644 index 2c8ddb02b03c6081a116f71f8b3ef2354e3ea8f1..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/faq_advanced_interface.md +++ /dev/null @@ -1 +0,0 @@ -# High-Level Interface \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/faq_configuration.md b/docs/mindformers/docs/source_en/faq_configuration.md deleted file mode 100644 index ae5bd7859655b58a1dfb85409c93d8069bb51b14..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/faq_configuration.md +++ /dev/null @@ -1 +0,0 @@ -# Configuration File \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/fine_tuning.md b/docs/mindformers/docs/source_en/fine_tuning.md deleted file mode 100644 index e7e02717dead3e416faa14c011f8160206aaf240..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/fine_tuning.md +++ /dev/null @@ -1,3 +0,0 @@ -# Fine-Tuning - -## Low-Parameter Fine-Tuning diff --git a/docs/mindformers/docs/source_en/inference.md b/docs/mindformers/docs/source_en/inference.md deleted file mode 100644 index ed26c0c74a4c0dc0a32f63aa6575baf5186ad372..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/inference.md +++ /dev/null @@ -1,5 +0,0 @@ -# Inference - -## Text-Generation Inference - -## Chat Web \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/installation.md b/docs/mindformers/docs/source_en/installation.md deleted file mode 100644 index d5ab63396222a29b4379bbd6775c6e3415747f76..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/installation.md +++ /dev/null @@ -1 +0,0 @@ -# Installing MindFormers \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/large_model.md b/docs/mindformers/docs/source_en/large_model.md deleted file mode 100644 index 1c04350865194c41f7278030e914941d9c23d25e..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/large_model.md +++ /dev/null @@ -1,7 +0,0 @@ -# Large Model Development Guide - -## GPT2 Implementation from the Beginning - -## A New Example of Model Migration - -*To-be Added* \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/model.md b/docs/mindformers/docs/source_en/model.md deleted file mode 100644 index e77ff28cef699ea5736cf873523e99c429b76c1d..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/model.md +++ /dev/null @@ -1 +0,0 @@ -# MindFormers Model Library diff --git a/docs/mindformers/docs/source_en/overview.md b/docs/mindformers/docs/source_en/overview.md deleted file mode 100644 index 4bba659ebc1667a0853e5ba4a7e0c1b32100a3f1..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/overview.md +++ /dev/null @@ -1 +0,0 @@ -# Overview \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/performance_tuning.md b/docs/mindformers/docs/source_en/performance_tuning.md deleted file mode 100644 index 4701299addb049c74ceb4a6d082c8dee5f392dcf..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/performance_tuning.md +++ /dev/null @@ -1 +0,0 @@ -# Performance Tuning \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/precision_tuning.md b/docs/mindformers/docs/source_en/precision_tuning.md deleted file mode 100644 index 1e7951ab669dea0ffeb5813747ec6925b1d35051..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/precision_tuning.md +++ /dev/null @@ -1 +0,0 @@ -# Precision Tuning \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/source_code_startup.md b/docs/mindformers/docs/source_en/source_code_startup.md deleted file mode 100644 index 3e08f409202ed20c098baa698be995eb415b9a25..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/source_code_startup.md +++ /dev/null @@ -1 +0,0 @@ -# Calling Source Code Startup \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/training.md b/docs/mindformers/docs/source_en/training.md deleted file mode 100644 index 3e3ad225cfdbd09dcac20af45ee08f252c27ebd2..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/training.md +++ /dev/null @@ -1,31 +0,0 @@ -# Training - -## Breakpoint Training - -### Introduction - -### Usage - -## Distributed Parallel - -### Auto-parallel - -## Pipeline Parallel Load Configuration - -## Recalculating and Selecting Recalculating Configuration - -## Training Optimization Algorithms - -### Gradient Accumulation - -### Gradient Clipping - -### Token Distribution - -### Flash Attention - -### Adaption Loss Scaling - -### Lazy Inline - -### MoE Expert Optimization \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/weight_process.md b/docs/mindformers/docs/source_en/weight_process.md deleted file mode 100644 index 9e2c11c89f6364c8a0d176d729c66c3f292082d6..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_en/weight_process.md +++ /dev/null @@ -1,7 +0,0 @@ -# Weight Processing - -## Offline Weight Conversion - -## Automatic Weight Conversion - -## Lora Weight Combination \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/advanced_interface.md b/docs/mindformers/docs/source_zh_cn/advanced_interface.md deleted file mode 100644 index 20a45174ecf555f36728fedbeea5a7c3658d831e..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/advanced_interface.md +++ /dev/null @@ -1,13 +0,0 @@ -# 高阶接口使用指南 - -## AutoClass - -*Mindformers提供ModelConfig、Model、Tokenzier、Processor的自动实例化功能,对应接口AutoConfig、AutoModel、AutoTokenizer、AutoProcessor* - -## Pipeline - -*MindFormers提供计pipeline推理接口,用户可以通过该接口快速体验不同任务下大模型的在线推理服务* - -## Trainer - -*MindFormers提供计Trainer接口,用户可以通过该接口快速使用预置任务和模型的训练、微调、评估、推理能力* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/aicc.md b/docs/mindformers/docs/source_zh_cn/aicc.md deleted file mode 100644 index 3b6077b38d194f7c3c2e9d1adf1e6701a88343f8..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/aicc.md +++ /dev/null @@ -1,6 +0,0 @@ -# AICC使用指南 - -*该部分主要包含两部分内容:* - -*1. 准备工作,主要涉及模型相关内容准备、存储对象服务准备以及镜像准备等* -*2. 拉起训练流程的介绍,主要涉及任务配置、各种训练方式启动以及权重切分、模型调试等* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/api_register.md b/docs/mindformers/docs/source_zh_cn/api_register.md deleted file mode 100644 index a75b5846bbfc7a3b269553417f1382ac13f2a8f6..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/api_register.md +++ /dev/null @@ -1,9 +0,0 @@ -# API注册机制介绍 - -## API组件注册机制 - -*介绍MIndFormers中各种API的注册机制以及使用示例,开发者可以通过该方式将模块进行注册,方便其他用户使用高阶接口进行调用,可注册模块类型包括'trainer'、'pipeline'、'dataset'等* - -## API组件Build机制 - -*介绍MIndFormers中的build功能,并提供了相关案例,通过build接口可以将经过注册的模块进行实例化,对应模块使用build_trainer、build_pipeline、build_dataset等* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/api_startup.md b/docs/mindformers/docs/source_zh_cn/api_startup.md deleted file mode 100644 index 962fbb6879153b10b3f77f36363fa955089a8408..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/api_startup.md +++ /dev/null @@ -1,3 +0,0 @@ -# 调用API启动 - -*介绍MindFormers支持的高阶接口,并提供了相关示例,包括Trainer、pipeline以及AutoClass快速入门* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/conf.py b/docs/mindformers/docs/source_zh_cn/conf.py deleted file mode 100644 index fcaa847ec4ee188fa4aca215a620b4daccdae32e..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/conf.py +++ /dev/null @@ -1,155 +0,0 @@ -# Configuration file for the Sphinx documentation builder. -# -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -import os -import IPython -import re -import sys - -# from sphinx import directives -# with open('../_ext/overwriteobjectiondirective.txt', 'r') as f: -# exec(f.read(), directives.__dict__) - -# from sphinx.ext import viewcode -# with open('../_ext/overwriteviewcode.txt', 'r', encoding="utf8") as f: -# exec(f.read(), viewcode.__dict__) - -from docutils import statemachine - -with open(statemachine.__file__, 'r') as g: - code = g.read().replace("assert len(self.data) == len(self.items), 'data mismatch'", "#assert len(self.data) == len(self.items), 'data mismatch'") - exec(code, statemachine.__dict__) - -from sphinx.ext import autodoc as sphinx_autodoc - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = 'MindSpore' -author = 'MindSpore' - -# The full version, including alpha/beta/rc tags -release = 'master' - - -# -- General configuration --------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -myst_enable_extensions = ["dollarmath", "amsmath"] - - -myst_heading_anchors = 5 -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'myst_parser', - 'sphinx.ext.mathjax', - 'IPython.sphinxext.ipython_console_highlighting' -] - -source_suffix = { - '.rst': 'restructuredtext', - '.md': 'markdown', -} - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. -mathjax_path = 'https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/mathjax/MathJax-3.2.2/es5/tex-mml-chtml.js' - -mathjax_options = { - 'async':'async' -} - -smartquotes_action = 'De' - -exclude_patterns = [] - -pygments_style = 'sphinx' - -autodoc_inherit_docstrings = False - -# -- Options for HTML output ------------------------------------------------- - -# Reconstruction of sphinx auto generated document translation. -language = 'zh_CN' -locale_dirs = ['../../../../resource/locale/'] -gettext_compact = False - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -html_theme = 'sphinx_rtd_theme' - -html_search_language = 'zh' - -html_search_options = {'dict': '../../../resource/jieba.txt'} - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - 'python': ('https://docs.python.org/', '../../../../resource/python_objects.inv'), - 'numpy': ('https://docs.scipy.org/doc/numpy/', '../../../../resource/numpy_objects.inv'), -} - -sys.path.append(os.path.abspath('../../../../resource/sphinx_ext')) -# import anchor_mod -import nbsphinx_mod - -# Modify default signatures for autodoc. -autodoc_source_path = os.path.abspath(sphinx_autodoc.__file__) -autodoc_source_re = re.compile(r'stringify_signature\(.*?\)') -get_param_func_str = r"""\ -import re -import inspect as inspect_ - -def get_param_func(func): - try: - source_code = inspect_.getsource(func) - if func.__doc__: - source_code = source_code.replace(func.__doc__, '') - all_params_str = re.findall(r"def [\w_\d\-]+\(([\S\s]*?)(\):|\) ->.*?:)", source_code) - all_params = re.sub("(self|cls)(,|, )?", '', all_params_str[0][0].replace("\n", "").replace("'", "\"")) - return all_params - except: - return '' - -def get_obj(obj): - if isinstance(obj, type): - return obj.__init__ - - return obj -""" - -with open(autodoc_source_path, "r+", encoding="utf8") as f: - code_str = f.read() - code_str = autodoc_source_re.sub('"(" + get_param_func(get_obj(self.object)) + ")"', code_str, count=0) - exec(get_param_func_str, sphinx_autodoc.__dict__) - exec(code_str, sphinx_autodoc.__dict__) - -sys.path.append(os.path.abspath('../../../../resource/search')) -import search_code - -sys.path.append(os.path.abspath('../../../../resource/custom_directives')) -from custom_directives import IncludeCodeDirective - -def setup(app): - app.add_directive('includecode', IncludeCodeDirective) diff --git a/docs/mindformers/docs/source_zh_cn/configuration.md b/docs/mindformers/docs/source_zh_cn/configuration.md deleted file mode 100644 index a98b62bca4bf65402c7fa7c5b24951ec9267ac9c..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/configuration.md +++ /dev/null @@ -1,5 +0,0 @@ -# 配置文件说明 - -*1. 介绍MindFormers中配置文件以及各关键字的含义,以及其对应的相关功能* - -*2. 主要介绍MindFormersConfig类,该类用于模型配置加载* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/contribution_guide.md b/docs/mindformers/docs/source_zh_cn/contribution_guide.md deleted file mode 100644 index 6e1ed29899e1cd8ecce59450d6e1dfc2f840a717..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/contribution_guide.md +++ /dev/null @@ -1 +0,0 @@ -# MindFormers贡献指南 \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/data_process.md b/docs/mindformers/docs/source_zh_cn/data_process.md deleted file mode 100644 index 653999580763f63c0e34b3196f515ab589366e28..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/data_process.md +++ /dev/null @@ -1,3 +0,0 @@ -# 数据处理 - -*内容待补充* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/env_variable.md b/docs/mindformers/docs/source_zh_cn/env_variable.md deleted file mode 100644 index f87b3faa63a6f98eafd14f38d0cb72222d911bb4..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/env_variable.md +++ /dev/null @@ -1,3 +0,0 @@ -# 环境变量说明 - -*介绍与MindFormers相关系统环境变量的功能,并提供MindSpore相关环境变量的链接* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/evaluation.md b/docs/mindformers/docs/source_zh_cn/evaluation.md deleted file mode 100644 index 32680d685a1c3ae41c4ab167e37c17b1e4906643..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/evaluation.md +++ /dev/null @@ -1,5 +0,0 @@ -# 评估 - -## 边训边评估 - -*目前分布式训练和推理需要权重和分布式策略匹配,因此Mindformers提供权重转换功能在训练过程中进行评估的流程方法,以及run_mindformer、Trainer启用使用说明* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/faq_advanced_interface.md b/docs/mindformers/docs/source_zh_cn/faq_advanced_interface.md deleted file mode 100644 index bf91b16eb517de9a773cea2c3c40d63fdf5cf3ee..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/faq_advanced_interface.md +++ /dev/null @@ -1 +0,0 @@ -# 高阶接口 \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/faq_configuration.md b/docs/mindformers/docs/source_zh_cn/faq_configuration.md deleted file mode 100644 index 050731aea792a41e621f4143bc7e786f0c713ebd..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/faq_configuration.md +++ /dev/null @@ -1 +0,0 @@ -# 配置文件 \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/fine_tuning.md b/docs/mindformers/docs/source_zh_cn/fine_tuning.md deleted file mode 100644 index 487d8ce3c948d22b8e2da503eedc443f959fa6d1..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/fine_tuning.md +++ /dev/null @@ -1,5 +0,0 @@ -# 微调特性 - -## 低参微调 - -*MindPet是属于Mindspore领域的微调算法套件,该部分提供了Lora和P-Tuning v2的使用示例* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/index.rst b/docs/mindformers/docs/source_zh_cn/index.rst deleted file mode 100644 index 81304353f678560973779fc580ecd1589e616c19..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/index.rst +++ /dev/null @@ -1,77 +0,0 @@ -MindFormers文档 -============================ - -*1. 介绍MindFormers的主要功能和特点* - -*2. 展示所有文档的目录* - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 开始 - - overview - model - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 安装 - - installation - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 快速入门 - - source_code_startup - api_startup - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 实践指南 - - env_variable - configuration - api_register - advanced_interface - large_model - aicc - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 特性说明 - - data_process - weight_process - training - fine_tuning - inference - evaluation - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 调试调优 - - precision_tuning - performance_tuning - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: API参考 - - *列举说明MindFormers中所有对外接口及说明* - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: FAQ - - faq_configuration - faq_advanced_interface - contribution_guide \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/inference.md b/docs/mindformers/docs/source_zh_cn/inference.md deleted file mode 100644 index c3db8b40698500ceadc1dc61290b7c3e54bf3a81..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/inference.md +++ /dev/null @@ -1,9 +0,0 @@ -# 推理特性 - -## 文本生成推理 - -*Mindformers支持多种文本生成推理方式,该部分提供了相关使用说明,主要包括增量推理、Batch推理、流式推理以及分布式推理* - -## Chat Web - -*Mindformers支持通过网页应用进行推理对话的功能,当前支持启动单卡和多卡服务,该部分提供了详细的使用案例来帮助用户实现大模型服务化* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/installation.md b/docs/mindformers/docs/source_zh_cn/installation.md deleted file mode 100644 index e8f5c30844f80d5f8e2270714698bc9ecf8a8330..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/installation.md +++ /dev/null @@ -1,5 +0,0 @@ -# 安装MindFormers - -*1. 版本配套:介绍MindFormers的软硬件配套版本,当前主要配套内容包括硬件型号、MindFormers、MindPet、MindSpore、CANN、驱动固件、镜像链接等* - -*2. 安装方式:提供MindFormers安装方式,当前支持Linux源码编译方式安装* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/large_model.md b/docs/mindformers/docs/source_zh_cn/large_model.md deleted file mode 100644 index 4594ada2f76d4a332826c04b4adf533287fa39c6..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/large_model.md +++ /dev/null @@ -1,9 +0,0 @@ -# 大模型开发指南 - -## GPT2从头开始实现 - -*介绍如何从零开始开发一个自定义大预言模型,这里以GPT2为例介绍了模型构建及注册、数据集构建及注册、Task构建与注册以及模型训练和推理实现* - -## 新的模型迁移示例 - -*待添加* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/model.md b/docs/mindformers/docs/source_zh_cn/model.md deleted file mode 100644 index fa12d5144c8d17c29ca033a07c8d89c8d3ed5899..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/model.md +++ /dev/null @@ -1,5 +0,0 @@ -# MindFormers模型库 - -*1. 根据模型所支持的不同任务类型,通过表格列出模型评估相关内容(包括模型性能),主要包括模型名称、模型规模、数据集、评估指标、评估得分以及配置文件* - -*2. LLM大模型能力支持一览,通过表格列出模型对各种特性的适配情况,可以通过点击模型名链接到模型文档,主要特性包括低参微调、边训边评、Flash Attention、并行推理、流式推理等* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/overview.md b/docs/mindformers/docs/source_zh_cn/overview.md deleted file mode 100644 index fcdc997a89e2e9cb1044c7a1e4dde7100a857a19..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/overview.md +++ /dev/null @@ -1,3 +0,0 @@ -# MindFormers概览 - -*MindFormers整体架构图,对架构图中各模块进行总体说明* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/performance_tuning.md b/docs/mindformers/docs/source_zh_cn/performance_tuning.md deleted file mode 100644 index 46d15b2644f9f2a7d72c90d3729614f4be0b64a1..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/performance_tuning.md +++ /dev/null @@ -1 +0,0 @@ -# 性能调优 \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/precision_tuning.md b/docs/mindformers/docs/source_zh_cn/precision_tuning.md deleted file mode 100644 index 799b03558e3eef58fff011ec36c9c4d27f52c695..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/precision_tuning.md +++ /dev/null @@ -1 +0,0 @@ -# 精度调优 \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/source_code_startup.md b/docs/mindformers/docs/source_zh_cn/source_code_startup.md deleted file mode 100644 index 33fd746f915165d67b0b5fb2be4503f695ad53e5..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/source_code_startup.md +++ /dev/null @@ -1,3 +0,0 @@ -# 调用源码启动 - -*需要拉取MindFormers仓库代码,介绍MindFormers通过MindSpore原生msrun分布式启动特性开发的模型训推脚本,使用该脚本可以快速拉起单机多卡、多机多卡等任务* \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/training.md b/docs/mindformers/docs/source_zh_cn/training.md deleted file mode 100644 index 45ccdcd5d8a846551d8ef787195c86c6273f25f9..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/training.md +++ /dev/null @@ -1,45 +0,0 @@ -# 训练特性 - -## 断点续训 - -### 介绍 - -*Mindformers支持step级断点续训,在训练过程中如果遇到意外情况导致训练中断,可以使用断点续训的方式恢复之前的状态继续训练* - -### 使用 - -*介绍断点续训在脚本、Trainer高阶接口等场景中的使用,并提供了使用案例* - -## 分布式并行 - -*分布式并行介绍及使用说明* - -### 自动并行 - -*该特性为实验特性,介绍了当前版本支持的自动并行算法以及使用说明* - -## 流水线并行的负载配置 - -*Mindformers提供流水线并行负载配置介绍和使用说明* - -## 重计算与选择重计算配置 - -*Mindformers重计算配置介绍和使用说明* - -## 训练优化算法 - -*主要介绍了特性的功能以及如何通过配置文件在模型中使能特性* - -### 梯度累积 - -### 梯度裁剪 - -### Token分布 - -### Flash Attention - -### Adaption loss scaling - -### Lazy Inline - -### MoE冷热门专家优化 \ No newline at end of file diff --git a/docs/mindformers/docs/source_zh_cn/weight_process.md b/docs/mindformers/docs/source_zh_cn/weight_process.md deleted file mode 100644 index 80d17de4ebbdeabb5c3de21de00f2ef6d7df6196..0000000000000000000000000000000000000000 --- a/docs/mindformers/docs/source_zh_cn/weight_process.md +++ /dev/null @@ -1,13 +0,0 @@ -# 权重处理 - -## 离线权重转换 - -*介绍了离线转换方式,可通过脚本以及高阶接口使用* - -## 自动权重转换 - -*介绍了自动转换功能相关参数和适用场景,并提供了多个使用案例,用户在使用过程中遇到与权重相关的问题都可参考案例进行解决* - -## Lora权重合并 - -*介绍了低参微调的原理和使用说明,通常在进行低参微调后需要将微调参数和模型预训练参数进行合并* \ No newline at end of file diff --git a/docs/mindinsight/docs/source_en/accuracy_optimization.md b/docs/mindinsight/docs/source_en/accuracy_optimization.md index 210ea304974e263f4747a9489683a62ab297aa72..1ae07e49c9695cf408e2199c6b6c254de48fe706 100644 --- a/docs/mindinsight/docs/source_en/accuracy_optimization.md +++ b/docs/mindinsight/docs/source_en/accuracy_optimization.md @@ -103,7 +103,7 @@ The causes of accuracy problems can be classified into hyperparameter problems, 2. The MindSpore constructor constraint is not complied with during graph construction. - The graph construction does not comply with the MindSpore construct constraints. That is, the network in graph mode does not comply with the constraints declared in the MindSpore static graph syntax support. For example, MindSpore does not support the backward computation of functions with key-value pair parameters. For details about complete constraints, see [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). + The graph construction does not comply with the MindSpore construct constraints. That is, the network in graph mode does not comply with the constraints declared in the MindSpore static graph syntax support. For example, MindSpore does not support the backward computation of functions with key-value pair parameters. For details about complete constraints, see [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). - Computational Graph Structure Problems @@ -581,13 +581,13 @@ For details about visualized data analysis during training, see [Viewing Dashboa ### Data Problem Handling -Perform operations such as standardization, normalization, and channel conversion on data. For image data processing, add images with random view and rotation. For details about data shuffle, batch, and multiplication, see [Processing Data](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html), [Data Argumentation](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html), and [Auto Augmentation](https://www.mindspore.cn/tutorials/experts/en/master/dataset/augment.html). +Perform operations such as standardization, normalization, and channel conversion on data. For image data processing, add images with random view and rotation. For details about data shuffle, batch, and multiplication, see [Processing and Loading Data](https://www.mindspore.cn/docs/en/master/model_train/index.html). > For details about how to apply the data augmentation operation to a custom dataset, see the [mindspore.dataset.GeneratorDataset.map](https://www.mindspore.cn/docs/en/master/api_python/dataset/dataset_method/operation/mindspore.dataset.Dataset.map.html#mindspore.dataset.Dataset.map) API. ### Hyperparameter Problem Handling -Hyperparameters in AI training include the global learning rate, epoch, and batch. For details about how to set the dynamic learning rate, see [Optimization Algorithm of Learning Rate](https://mindspore.cn/tutorials/zh-CN/master/advanced/modules/optimizer.html). +Hyperparameters in AI training include the global learning rate, epoch, and batch. For details about how to set the dynamic learning rate, see [Optimization Algorithm of Learning Rate](https://mindspore.cn/docs/zh-CN/master/model_train/custom_program/optimizer.html). ### Model Structure Problem Handling diff --git a/docs/mindinsight/docs/source_en/accuracy_problem_preliminary_location.md b/docs/mindinsight/docs/source_en/accuracy_problem_preliminary_location.md index 74b56fdac0aa956a6f864c81b2fd88712247aa1c..da19f0997bab5c2ba74a109f424212159073066c 100644 --- a/docs/mindinsight/docs/source_en/accuracy_problem_preliminary_location.md +++ b/docs/mindinsight/docs/source_en/accuracy_problem_preliminary_location.md @@ -341,13 +341,13 @@ When you run a script on the Ascend backend or use the mixed precision function, #### mp.01 Overflow occurs during training Check method: -When the [mixed precision](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html) or the Ascend AI processor is used for training, you are advised to check whether overflow occurs. +When the [mixed precision](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html) or the Ascend AI processor is used for training, you are advised to check whether overflow occurs. After the overflow problem is found, find and analyze the first overflow node. (For Ascend overflow data, find the node with the smallest timestamp based on the timestamp in the file name. For GPU overflow data, find the first node in the execution sequence.) Determine the overflow cause based on the input and output data of the API. The common solutions to the overflow problem are as follows: -1. Enable dynamic loss scale or set a proper static loss scale value. For details, see [LossScale](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html). Note that when the static loss scale in the GPU scenario is directly used for Ascend training, unexpected frequent overflow may occur, affecting convergence. After the loss scale is enabled, you may need to perform multiple experiments to adjust the init_loss_scale (initial value), scale_factor, and scale_window of loss scale until there are few floating-point overflows during training. +1. Enable dynamic loss scale or set a proper static loss scale value. For details, see [LossScale](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html). Note that when the static loss scale in the GPU scenario is directly used for Ascend training, unexpected frequent overflow may occur, affecting convergence. After the loss scale is enabled, you may need to perform multiple experiments to adjust the init_loss_scale (initial value), scale_factor, and scale_window of loss scale until there are few floating-point overflows during training. 2. If the overflow problem has a key impact on the accuracy and cannot be avoided, change the corresponding API to the FP32 API (the performance may be greatly affected after the adjustment). Conclusion: @@ -358,7 +358,7 @@ Enter here. Check method: -When [mixed precision](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html) is used. You can use the default parameter values of DynamicLossScaleManager or FixedLossScaleManager for training. If there are too many overflow steps and the final accuracy is affected, adjust the value of loss_scale based on the overflow phenomenon. If gradient overflow occurs, decrease the value of loss_scale (by dividing the original value of loss_scale by 2). If gradient underflow occurs, increase the value of loss_scale (by multiplying the original value of loss_scale by 2). In most cases, training on the Ascend AI processor is performed with mixed precision. The computation feature of the Ascend AI processor is different from that of the GPU mixed precision. Therefore, you may need to adjust the value of the LossScaleManager hyperparameter to a value different from that on the GPU based on the training result to ensure the precision. +When [mixed precision](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html) is used. You can use the default parameter values of DynamicLossScaleManager or FixedLossScaleManager for training. If there are too many overflow steps and the final accuracy is affected, adjust the value of loss_scale based on the overflow phenomenon. If gradient overflow occurs, decrease the value of loss_scale (by dividing the original value of loss_scale by 2). If gradient underflow occurs, increase the value of loss_scale (by multiplying the original value of loss_scale by 2). In most cases, training on the Ascend AI processor is performed with mixed precision. The computation feature of the Ascend AI processor is different from that of the GPU mixed precision. Therefore, you may need to adjust the value of the LossScaleManager hyperparameter to a value different from that on the GPU based on the training result to ensure the precision. Conclusion: @@ -368,7 +368,7 @@ Enter here. Check method: -Gradient clip forcibly adjusts the gradient to a smaller value when the gradient is greater than a threshold. Gradient clip has a good effect on the gradient explosion problem in RNNs. If both [loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html) and gradient clip are used, perform this check. Check the code to ensure that the application object of gradient clip is the original gradient value obtained by dividing the loss scale. +Gradient clip forcibly adjusts the gradient to a smaller value when the gradient is greater than a threshold. Gradient clip has a good effect on the gradient explosion problem in RNNs. If both [loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html) and gradient clip are used, perform this check. Check the code to ensure that the application object of gradient clip is the original gradient value obtained by dividing the loss scale. Conclusion: @@ -378,7 +378,7 @@ Enter here. Check method: -Gradient penalty is a technique that adds a gradient to a cost function to constrain the gradient length. If both [loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html) and gradient penalty are used, perform this check. Check whether the entered gradient is a gradient without loss scale when computing the gradient penalty item. For example, a gradient substituted for the loss scale may be first divided by the loss scale, and then is used to compute the gradient penalty item. +Gradient penalty is a technique that adds a gradient to a cost function to constrain the gradient length. If both [loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html) and gradient penalty are used, perform this check. Check whether the entered gradient is a gradient without loss scale when computing the gradient penalty item. For example, a gradient substituted for the loss scale may be first divided by the loss scale, and then is used to compute the gradient penalty item. Conclusion: diff --git a/docs/mindinsight/docs/source_en/conf.py b/docs/mindinsight/docs/source_en/conf.py index 7f5dd91377ac65d3c48a3bb3da310da7b56c5402..43eb0c1dc51b7fc9a998b28a5ae31c2da2c1a21c 100644 --- a/docs/mindinsight/docs/source_en/conf.py +++ b/docs/mindinsight/docs/source_en/conf.py @@ -18,8 +18,6 @@ import sys import sphinx.ext.autosummary.generate as g from sphinx.ext import autodoc as sphinx_autodoc -import mindinsight - # -- Project information ----------------------------------------------------- project = 'MindSpore' diff --git a/docs/mindinsight/docs/source_en/index.rst b/docs/mindinsight/docs/source_en/index.rst index aecf52d87f54ab8da31ebaca89afb00ffa0e2340..cdb38023cc3a4c2c6f98c8ae704da594ef93eea9 100644 --- a/docs/mindinsight/docs/source_en/index.rst +++ b/docs/mindinsight/docs/source_en/index.rst @@ -85,6 +85,7 @@ Using MindSpore Insight to Analyze the Model Performance graph_visual_design tensor_visual_design profiler_design + profiler_files_description faq .. toctree:: diff --git a/docs/mindinsight/docs/source_en/performance_optimization.md b/docs/mindinsight/docs/source_en/performance_optimization.md index 89b3f8981c65c9f9dd4966db4adb736f797b7999..41c6dda7d719af486874c7d58c4988b4d95d288d 100644 --- a/docs/mindinsight/docs/source_en/performance_optimization.md +++ b/docs/mindinsight/docs/source_en/performance_optimization.md @@ -43,7 +43,7 @@ By observing the `queue relationship between operators` in the Data Processing t *Figure 3: Data Preparation Details -- Data Processing* -We can refer to [Optimizing the Data Processing](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html ) to adjust dataset operations to improve dataset performance. +We can refer to [Optimizing the Data Processing](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html ) to adjust dataset operations to improve dataset performance. We find that the num_parallel_workers parameter of map operation is 1(default value) by observing the code part of data processing in ResNet50, and code is shown below: @@ -95,7 +95,7 @@ Open the details page of Operator Time Consumption Ranking, and we find that Mat *Figure 6: Finding operators that can be optimized via the details page of Operator Time Consumption Ranking* -For Operator Time Consumption optimization, usually float16 type with the less computating amount can be used to improve operator performance if there is no difference in accuracy between float16 and float32 type. We can refer to [Enabling Mixed Precision](https://www.mindspore.cn/tutorials/en/master/advanced/mixed_precision.html) to improve operators performance. +For Operator Time Consumption optimization, usually float16 type with the less computating amount can be used to improve operator performance if there is no difference in accuracy between float16 and float32 type. We can refer to [Enabling Mixed Precision](https://www.mindspore.cn/tutorials/en/master/beginner/mixed_precision.html) to improve operators performance. Optimization code is shown below: diff --git a/docs/mindinsight/docs/source_en/performance_profiling_gpu.md b/docs/mindinsight/docs/source_en/performance_profiling_gpu.md index 729eadc1cca01a07afd0b8eabee32f7d0e110047..b2bd3f1949325cb7bccb6759f960b0e45d9ce936 100644 --- a/docs/mindinsight/docs/source_en/performance_profiling_gpu.md +++ b/docs/mindinsight/docs/source_en/performance_profiling_gpu.md @@ -74,7 +74,7 @@ There are two ways to collect neural network performance data. You can enable Pr - `timeline_limit`(int, optional) - Set the maximum storage size of the timeline file (unit M). When using this parameter, op_time must be set to true. Default value: 500. - `data_process`(bool, optional) - Indicates whether to collect data to prepare performance data. Default value: true. - `op_time` (bool, optional) - Whether to collect operators performance data. Default value: true. - - `profile_framework`(str, optional) - Whether to collect host memory and time, it must be one of ["all", "time", "memory", null]. Default: "all". + - `profile_framework`(str, optional) - Whether to collect host time, it must be one of ["all", "time", null]. Default: null. ## Launching MindSpore Insight diff --git a/docs/mindinsight/docs/source_en/performance_tuning_guide.md b/docs/mindinsight/docs/source_en/performance_tuning_guide.md index f973a64aa7e62852a94ef6c1f84d0e5ed7977681..e10f6d5dad50b6604aa088e3d1f44b7da6725446 100644 --- a/docs/mindinsight/docs/source_en/performance_tuning_guide.md +++ b/docs/mindinsight/docs/source_en/performance_tuning_guide.md @@ -58,7 +58,7 @@ Step 1:Please jump to the `step interval` tab on the `data preparation details - If there is no time-consuming customized logic in the script, it indicates that sending data from host to device is time-consuming, please feedback to the [MindSpore Community](https://gitee.com/mindspore/mindspore/issues). -Step 2:Please jump to the `data processing` tab on the `data preparation details` page, observe the inter-operator queue, and determine which operation has a performance bottleneck in the data processing. Principles of judgment can be found in the [Performance Profiling](https://www.mindspore.cn/mindinsight/docs/en/master/performance_profiling_ascend.html#data-preparation-performance-analysis) page. Users can reference [Optimizing the Data Processing](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html) and try to optimize the data processing performance. +Step 2:Please jump to the `data processing` tab on the `data preparation details` page, observe the inter-operator queue, and determine which operation has a performance bottleneck in the data processing. Principles of judgment can be found in the [Performance Profiling](https://www.mindspore.cn/mindinsight/docs/en/master/performance_profiling_ascend.html#data-preparation-performance-analysis) page. Users can reference [Optimizing the Data Processing](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html) and try to optimize the data processing performance. #### Data Sinking Mode @@ -69,7 +69,7 @@ Step 1:Please jump to the `step interval` tab on the `data preparation details Step 2: See how the size curve changes in the host queue. If none of the size in the queue is 0, it indicates that the process by which training data is sent from host to device is a performance bottleneck, please feedback to the [MindSpore Community](https://gitee.com/mindspore/mindspore/issues). Otherwise it indicates that the data processing process is the performance bottleneck, please refer to Step 3 to continue to locate which operation of data processing has performance problems. -Step 3:Please jump to the `data processing` tab on the `data preparation details` page, observe the inter-operator queue, and determine which operation has a performance bottleneck in the data processing. Principles of judgment can be found in the [Performance Profiling](https://www.mindspore.cn/mindinsight/docs/en/master/performance_profiling_ascend.html#data-preparation-performance-analysis) page. Users can reference [Optimizing the Data Processing](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html) and try to optimize the data processing performance. +Step 3:Please jump to the `data processing` tab on the `data preparation details` page, observe the inter-operator queue, and determine which operation has a performance bottleneck in the data processing. Principles of judgment can be found in the [Performance Profiling](https://www.mindspore.cn/mindinsight/docs/en/master/performance_profiling_ascend.html#data-preparation-performance-analysis) page. Users can reference [Optimizing the Data Processing](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html) and try to optimize the data processing performance. ### Long Forward And Backward Propagation @@ -125,7 +125,7 @@ Step 2:Observe the forward and backward propagation in the cluster step trace Step 3: Observe the step tail in the cluster step trace page - Users should make sure if the step tail of one device is much longer than others first. If it is, it usually caused by slow node in the cluster. Users can refer to Step 1 and Step 2 to find the slow node. -- If the step tail of all devices are essentially the same, and the phase is time-consuming, it is usually due to the long time taken by the AllReduce collective communication operators. Users can try to modify the all_reduce_fusion_config parameter to optimize the performance, and change [AllReduce Fusion Sharding Strategy](https://mindspore.cn/tutorials/experts/en/master/parallel/overview.html) to reduce the time spent in this phase. +- If the step tail of all devices are essentially the same, and the phase is time-consuming, it is usually due to the long time taken by the AllReduce collective communication operators. Users can try to modify the all_reduce_fusion_config parameter to optimize the performance, and change [AllReduce Fusion Sharding Strategy](https://mindspore.cn/docs/en/master/model_train/parallel/overview.html) to reduce the time spent in this phase. ### Model Parallel @@ -143,7 +143,7 @@ Please refer to step 2 of [Data Parallel](#data-parallel). Step 3: Observe the pure communication time in the cluster step trace page On the premise of confirming that there is no slow node through step 1 and step 2, the pure communication time of each card in the cluster should be basically the same. If this phase takes a short time, it means that the communication time caused by re-distribution of operators is very short, and users do not need to consider optimizing the parallel strategy. Otherwise, users need to focus on analyzing whether the parallel strategy can be optimized. -Users need to have a certain understanding of the principle of model parallelism before continue to analyse. Please refer to [Distributed Training](https://www.mindspore.cn/tutorials/experts/en/master/parallel/overview.html) for the basic principles. The following steps are only to assist users in rationality analysis. Whether the parallel strategy has room for optimization and how to optimize it need users to make a judgment after specific analysis of their respective networks. +Users need to have a certain understanding of the principle of model parallelism before continue to analyse. Please refer to [Distributed Training](https://www.mindspore.cn/docs/en/master/model_train/parallel/overview.html) for the basic principles. The following steps are only to assist users in rationality analysis. Whether the parallel strategy has room for optimization and how to optimize it need users to make a judgment after specific analysis of their respective networks. - If this stage takes a long time, the user can choose any one of the devices and observe its timeline. In the timeline, MindSpore Insight marks the pure communication time, refer to `Pure Communication Op` below. diff --git a/docs/mindinsight/docs/source_en/profiler_files_description.md b/docs/mindinsight/docs/source_en/profiler_files_description.md new file mode 100644 index 0000000000000000000000000000000000000000..9f729f47c4db4342dca4bcbba7b0b2c26389dece --- /dev/null +++ b/docs/mindinsight/docs/source_en/profiler_files_description.md @@ -0,0 +1,91 @@ +# Performance Data in the Profiler Directory + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindinsight/docs/source_en/profiler_files_description.md) + +The profiler directory includes some csv, json, and txt files, which contain performance data such as operator execution time, memory usage, and communication during model computation to help users analyze performance bottlenecks. The fields in some of the csv and txt files are explained below. The contents of the files mainly include information about the time consumed by the device-side operators (AI Core operator and AI CPU operator), and the information about the memory occupied at the operator level and the memory occupied at the application level. + +## aicore_intermediate_*_detail.csv File Descriptions + +The aicore_intermediate_\*_detail.csv file contains statistical AI Core operator information based on the contents of output_timeline_data_\*.txt and framework_raw_\*.csv. Refer to the following table for descriptions of the fields in the file: + +| Field Names | Descriptions | +|----------------------------|----------------------------| +|full_kernel_name |Full name of the device-side execution kernel operator| +|task_duration |Operator execution time| +|execution_frequency |Frequency of operator execution| +|task_type |Task types for the operator| + +## aicore_intermediate_*_type.csv File Descriptions + +The aicore_intermediate_\*_type.csv file includes statistical information about the specific types of AI Core operators based on the contents of output_timeline_data_\*.txt and framework_raw_\*.csv. Refer to the following table for descriptions of the fields in the file: + +| Field Names | Descriptions | +|------------------------------|------------------------| +| kernel_type | AI Core operator types| +| task_time | Operator execution time| +| execution_frequency | Frequency of operator execution| +| percent | Percentage of time taken of this operator type over the total time taken of all operators| + +## aicpu_intermediate_*.csv File Descriptions + +The aicpu_intermediate_\*.csv file contains time taken information of the AI CPU operators. Refer to the following table for descriptions of the fields in the file: + +| Field Names | Descriptions | +|------------------------------|------------------------| +| serial_num | AI CPU operator number| +| kernel_type | AI CPU operator type| +| total_time | Operator time taken, which is equal to the sum of the downstream time taken and the execution time taken| +| dispatch_time | downstream time taken| +| execution_time | execution time taken| +| run_start | Start time of operator execution| +| run_end | End time of operator execution| + +## flops_*.txt File Descriptions + +The flops_\*.txt file contains information about the number of floating-point computations for the device-side operator, the number of floating-point computations per second, and so on. Refer to the following table for descriptions of the fields in the file: + +| Field Names | Descriptions | +|------------------------------|------------------------| +| full_kernel_name | Full name of the device-side execution kernel operator| +| MFLOPs(10^6 cube) | The number of floating-point calculations (10^6 cube)| +| GFLOPS(10^9 cube) | The number of floating-point calculations per second(10^9 cube)| +| MFLOPs(10^6 vector) | The number of floating-point calculations(10^6 vector)| +| GFLOPS(10^9 vector) | The number of floating-point calculations per second(10^9 vector)| + +## output_timeline_data_*.txt File Descriptions + +The output_timeline_data_\*.txt file contains information about the time taken of the device-side operator. Refer to the following table for descriptions of the fields in the file: + +| Field Names | Descriptions | +|------------------------------|------------------------| +| kernel_name | Full name of the device-side execution kernel operator| +| stream_id | Stream ID of the operator| +| start_time | Start time of operator execution(us)| +| duration | operator execution time (ms)| + +## cpu_ms_memory_record_*.txt File Descriptions + +The cpu_ms_memory_record_\*.txt file contains information about application-level memory usage. Refer to the following table for descriptions of the fields in the file: + +| Field Names | Descriptions | +|------------------------------|------------------------| +| Timestamp | Moment of memory event(ns)| +| Total Allocated | Total memory allocation(Byte)| +| Total Reserved | Total memory reservation(Byte)| +| Total Active | Total memory requested by streams in MindSpore(Byte)| + +## operator_memory_*.csv File Descriptions + +The operator_memory_\*.csv file contains information about operator-level memory usage. Refer to the following table for descriptions of the fields in the file: + +| Field Names | Descriptions | +|------------------------------|------------------------| +| Name | Memory Consumption Tensor Name| +| Size | Size of memory occupied(KB)| +| Allocation Time | Tensor memory allocation time(us)| +| Duration | Tensor memory occupation time(us)| +| Allocation Total Allocated | Total memory allocation at operator memory allocation(MB)| +| Allocation Total Reserved | Total memory occupation at operator memory allocation(MB)| +| Release Total Allocated | Total memory allocation at operator memory release(MB)| +| Release Total Reserved | Total memory occupation at operator memory release(MB)| +| Device | device type| diff --git a/docs/mindinsight/docs/source_en/profiling/profiling_host_time.txt b/docs/mindinsight/docs/source_en/profiling/profiling_host_time.txt index 9d212663636bd97aee4e4a89ebc65b233fe2310e..016bce225d6d75709744b677ba36f80bd845c0d8 100644 --- a/docs/mindinsight/docs/source_en/profiling/profiling_host_time.txt +++ b/docs/mindinsight/docs/source_en/profiling/profiling_host_time.txt @@ -1,4 +1,4 @@ Host Side Time Consumption Analysis ------------------------------------- -If the Host side time collection function is enabled, the Host side time-consuming of each stage can be saved in the specified directory after the training is completed. For example, when a Profiler is specified with ``output_ Path="/XXX/profiler_output"`` , the file containing time consumption data on the Host side will be saved in the "/XXX/profiler_output/profile/host_info" directory. The file is in json format and with the prefix ``"timeline_"``, and suffix rank_id. The host side time-consuming file can be viewed by `` chrome://tracing `` . You can use W/S/A/D to zoom in, out, move left, and right to view time consuming information. \ No newline at end of file +If the Host side time collection function is enabled, you can view the time consumption in ascend_timeline_display_[rank_id].json after the traing finished and use `` chrome://tracing `` to display. You can use W/S/A/D to zoom in, out, move left, and right to view time consuming information. \ No newline at end of file diff --git a/docs/mindinsight/docs/source_en/profiling/profiling_offline.txt b/docs/mindinsight/docs/source_en/profiling/profiling_offline.txt index aba3b51d26fbb034bb06154736cd254fc3dab9fb..760c35ece21e54ace3334fb1f8daf2b6fc063973 100644 --- a/docs/mindinsight/docs/source_en/profiling/profiling_offline.txt +++ b/docs/mindinsight/docs/source_en/profiling/profiling_offline.txt @@ -40,3 +40,119 @@ If an exception occurs in above code during the training process, resulting in t After offline parsing, you can view the profiling data in the directory `/path/to/profiler_data/profile` . + +Directory Structure +~~~~~~~~~~~~~~~~~~~~ + +An example of the performance data catalog structure is shown below: + +.. code:: + + └──── profiler + ├──── container + ├──── FRAMEWORK // Raw data collected on the frame side + │ └──── op_range_* + ├──── PROF_{number}_{timestamp}_{string} // msprof performance data + │ ├──── analyse + │ ├──── device_* + │ ├──── host + │ ├──── mindstudio_profiler_log + │ └──── mindstudio_profiler_output + ├──── rank_* // Memory-related raw data + │ ├──── memory_block.csv + │ └──── task.csv + ├──── rank-*_{timestamp}_ascend_ms // MindStudio Insight Visualization Deliverables + │ ├──── ASCEND_PROFILER_OUTPUT // Performance data collected by the MindSpore Profiler interface + │ ├──── profiler_info_*.json + │ └──── profiler_metadata.json // To record user-defined meta data, call the add_metadata or add_metadata_json interface to generate the file + ├──── aicore_intermediate_*_detail.csv + ├──── aicore_intermediate_*_type.csv + ├──── aicpu_intermediate_*.csv + ├──── ascend_cluster_analyse_model-{mode}_{stage_num}_{rank_size}_*.csv + ├──── ascend_timeline_display_*.json + ├──── ascend_timeline_summary_*.json + ├──── cpu_framework_*.txt // Heterogeneous scenario generation + ├──── cpu_ms_memory_record_*.txt + ├──── cpu_op_detail_info_*.csv // Heterogeneous scenario generation + ├──── cpu_op_execute_timestamp_*.txt // Heterogeneous scenario generation + ├──── cpu_op_type_info_*.csv // Heterogeneous scenario generation + ├──── dataset_iterator_profiling_*.txt // Data non-sinking scenario generation + ├──── device_queue_profiling_*.txt // Data sinking scenario generation + ├──── dynamic_shape_info_*.json + ├──── flops_*.txt + ├──── flops_summary_*.json + ├──── framework_raw_*.csv + ├──── hccl_raw_*.csv // Configure the profiler (profiler_communication=True) to generate + ├──── minddata_aicpu_*.json // Data sinking scenario generation + ├──── minddata_cpu_utilization_*.json + ├──── minddata_pipeline_raw_*.csv + ├──── minddata_pipeline_summary_*.csv + ├──── minddata_pipeline_summary_*.json + ├──── operator_memory_*.csv + ├──── output_timeline_data_*.txt + ├──── parallel_strategy_*.json + ├──── pipeline_profiling_*.json + ├──── profiler_info_*.json + ├──── step_trace_point_info_*.json + └──── step_trace_raw_*_detail_time.csv + └──── dataset_*.csv + +- \* represents rank id + +Performance Data File Description +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +PROF_{number}_{timestamp}_{string} directory is the performance data collected by CANN Profiling, which is mainly stored in mindstudio_profiler_output. The data introduction can be referred to `Performance data file description `_. + +The profiler directory contains three types of files, csv, json, and txt, which cover performance data in terms of operator execution time, memory usage, communication, etc. The file descriptions are shown in the following table. For detailed descriptions of some files, refer to `Performance data `_. + +============================================== ============================================================================== +File Names Descriptions +============================================== ============================================================================== +step_trace_point_info_*.json Information about the operator corresponding to the step node (only mode=GRAPH,export GRAPH_OP_RUM=0) +step_trace_raw_*_detail_time.csv Time information for the nodes of each STEP (only mode=GRAPH,export GRAPH_OP_RUM=0) + +dynamic_shape_info_*.json Operator information under dynamic shape + +pipeline_profiling_*.json MindSpore data processing to capture intermediate files of falling disks for MindInsight visualization +minddata_pipeline_raw_*.csv MindSpore data processing to capture intermediate files of falling disks for MindInsight visualization +minddata_pipeline_summary_*.csv MindSpore data processing to capture intermediate files of falling disks for MindInsight visualization +minddata_pipeline_summary_*.json MindSpore data processing to capture intermediate files of falling disks for MindInsight visualization +framework_raw_*.csv Information about AI Core operators in MindSpore data processing +device_queue_profiling_*.txt MindSpore data processing to capture intermediate files of falling disks for MindInsight visualization (data sinking scenarios only) +minddata_aicpu_*.txt Performance data for AI CPU operators in MindSpore data processing (data sinking scenarios only) +dataset_iterator_profiling_*.txt MindSpore data processing to capture intermediate files of falling disks for MindInsight visualization (data non-sinking scenarios only) + +aicore_intermediate_*_detail.csv AI Core operator data +aicore_intermediate_*_type.csv AI Core operator calling counts and time taken statistics +aicpu_intermediate_*.csv Time taken data after AI CPU operator information parsing +flops_*.txt Record the number of floating-point calculations (FLOPs), floating-point calculations per second (FLOPS) for AI Core operators +flops_summary_*.json Record total FLOPs for all operators, average FLOPs for all operators, average FLOPS_Utilization + +ascend_timeline_display_*.json timeline visualization file for MindStudio Insight visualization +ascend_timeline_summary_*.json timeline statistics +output_timeline_data_*.txt Operator timeline data, only if AI Core operator data exists + +cpu_ms_memory_record_*.txt Raw files for memory profiling +operator_memory_*.csv Operator-level memory information + +minddata_cpu_utilization_*.json CPU utilization rate + +cpu_op_detail_info_*.csv CPU operator time taken data (mode=GRAPH only) +cpu_op_type_info_*.csv Class-specific CPU operator time taken statistics (mode=GRAPH only) +cpu_op_execute_timestamp_*.txt CPU operator execution start time and time taken (mode=GRAPH only) +cpu_framework_*.txt CPU operator time taken in heterogeneous scenarios (mode=GRAPH only) + +ascend_cluster_analyse_model-xxx.csv Data related to computation and communication, etc. in model-parallel or pipeline-parallel modes (mode=GRAPH only) + +hccl_raw_*.csv Card-based communication time and communication wait time (mode=GRAPH only) + +parallel_strategy_*.json Operator parallel strategy to capture falling disk intermediate files for MindInsight visualization + +profiler_info_*.json Profiler Configuration and other info + +dataset_*.csv The time consuming of various stages of data processing module +============================================== ============================================================================== + +- \* represents rank id +- The complete name of ascend_cluster_analyse_model-xxx_*.csv should be ascend_cluster_analyse_model-{mode}_{stage_num}_{rank_size}_{rank_id}.csv, such as ascend_cluster_analyse_model-parallel_1_8_0.csv diff --git a/docs/mindinsight/docs/source_en/profiling/profiling_resoure.txt b/docs/mindinsight/docs/source_en/profiling/profiling_resoure.txt index 798aef6bbcfb4df79c26aca0873a963acf76e846..c613f69f87ad656183145e06bc450684b2ee09f5 100644 --- a/docs/mindinsight/docs/source_en/profiling/profiling_resoure.txt +++ b/docs/mindinsight/docs/source_en/profiling/profiling_resoure.txt @@ -128,20 +128,3 @@ detailed information from ``Memory Usage``, including: :alt: memory_graphics.png *Figure:Memory Statistics* - -Host side memory usage -~~~~~~~~~~~~~~~~~~~~~~~~~ - -If the host side memory collection function is enabled, the memory usage can be saved in the specified directory after the training is completed. For example, when a Profiler is specified with ``output_ Path="/XXX/profiler_output"`` , the file containing host side memory data will be saved in the "/XXX/profiler_output/profile/host_info" directory. The file is in csv format and with prefix ``"host_memory_"`` and suffix rank_id. The meaning of the header is as follows: - -- tid: The thread ID of the current thread when collecting host side memory. -- pid: The process ID of the current process when collecting host side memory. -- parent_pid: The process ID of the current process's Parent process when collecting the host side memory. -- module_name: Name of the module that collects host side memory, one or more event may be included in a module. -- event: The event name which collected the host side memory, one or more stage may be included in a event. -- stage: The stage name which collected the host side memory. -- level: 0 means used by framework developers, and 1 means used by users(algorithm engineers). -- start_end: The mark for the start or end of the stage, where 0 represents the start mark, 1 represents the end mark, and 2 represents an indistinguishable start or end. -- custom_info: The component customization information used by framework developers to locate performance issues, possibly empty. -- memory_usage: Host-side memory usage in kB, and 0 means no memory data is collected at the current stage. -- time_stamp: Time stamp in us. diff --git a/docs/mindinsight/docs/source_en/profiling/profiling_training.txt b/docs/mindinsight/docs/source_en/profiling/profiling_training.txt index e889d45516ecd4163650b18d6097b20e3f145692..087f4a7542eee1c17551447ba6093c001560da46 100644 --- a/docs/mindinsight/docs/source_en/profiling/profiling_training.txt +++ b/docs/mindinsight/docs/source_en/profiling/profiling_training.txt @@ -207,4 +207,4 @@ Note: - `parallel_strategy` (bool, optional) - Indicates whether to collect parallel policy performance data. Default value: true. -- `profile_framework` (str, optional) - Whether to collect host memory and time, it must be one of ["all", "time", "memory", null]. Default: "all". +- `profile_framework` (str, optional) - Whether to collect host time, it must be one of ["all", "time", null]. Default: null. diff --git a/docs/mindinsight/docs/source_zh_cn/accuracy_optimization.md b/docs/mindinsight/docs/source_zh_cn/accuracy_optimization.md index 67b3825010f7e541a09e6754b88d82c0d0e4dae1..31af427420a5e9cca73209148968bd83c6240cab 100644 --- a/docs/mindinsight/docs/source_zh_cn/accuracy_optimization.md +++ b/docs/mindinsight/docs/source_zh_cn/accuracy_optimization.md @@ -103,7 +103,7 @@ 2. 构图时未遵循MindSpore construct约束。 - 构图未遵循mindspore construct约束,是指图模式下的网络未遵循MindSpore静态图语法支持中声明的约束。例如,MindSpore目前不支持对带键值对参数的函数求反向。完整约束请见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)。 + 构图未遵循mindspore construct约束,是指图模式下的网络未遵循MindSpore静态图语法支持中声明的约束。例如,MindSpore目前不支持对带键值对参数的函数求反向。完整约束请见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)。 - 计算图结构问题 @@ -583,13 +583,13 @@ Xie, Z., Sato, I., & Sugiyama, M. (2020). A Diffusion Theory For Deep Learning D ### 数据问题处理 -对数据进行标准化、归一化、通道转换等操作,在图片数据处理上,增加随机视野图片,随机旋转度图片等,另外数据混洗、batch和数据倍增等操作,可参考[数据处理](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset.html)、[数据增强](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset.html)和[自动数据增强](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/augment.html)。 +对数据进行标准化、归一化、通道转换等操作,在图片数据处理上,增加随机视野图片,随机旋转度图片等,另外数据混洗、batch和数据倍增等操作,可参考[数据加载与处理](https://www.mindspore.cn/docs/zh-CN/master/model_train/index.html)。 > 如何将数据增强增强操作应用到自定义数据集中,可以参考[mindspore.dataset.GeneratorDataset.map](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/dataset_method/operation/mindspore.dataset.Dataset.map.html#mindspore.dataset.Dataset.map) API。 ### 超参问题处理 -AI训练中的超参包含全局学习率,epoch和batch等,如果需要设置动态学习率超参时,可参考资料:[学习率的优化算法](https://mindspore.cn/tutorials/zh-CN/master/advanced/modules/optimizer.html#学习率)。 +AI训练中的超参包含全局学习率,epoch和batch等,如果需要设置动态学习率超参时,可参考资料:[学习率的优化算法](https://mindspore.cn/docs/zh-CN/master/model_train/custom_program/optimizer.html#学习率)。 ### 模型结构问题处理 diff --git a/docs/mindinsight/docs/source_zh_cn/accuracy_problem_preliminary_location.md b/docs/mindinsight/docs/source_zh_cn/accuracy_problem_preliminary_location.md index ab441343e9dbcdde1b8ad435345790ae6f9812db..96e6b6a990243bcf2d1f0705540def33035daf0c 100644 --- a/docs/mindinsight/docs/source_zh_cn/accuracy_problem_preliminary_location.md +++ b/docs/mindinsight/docs/source_zh_cn/accuracy_problem_preliminary_location.md @@ -341,13 +341,13 @@ MindSpore API同其它框架的API存在一定差异。有标杆脚本的情况 #### mp.01 训练中存在溢出问题 检查方法: -当使用[混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html)训练,或者是使用Ascend AI处理器训练时,建议检查是否存在溢出问题。 +当使用[混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html)训练,或者是使用Ascend AI处理器训练时,建议检查是否存在溢出问题。 发现溢出问题后,应首先找到并分析第一个出现溢出的节点(对于Ascend的溢出数据,可以按文件名中的时间戳,找时间戳最小的一个;对于GPU上的溢出,只要找执行序中最靠前的一个),结合API的输入输出数据确定溢出原因。 出现溢出问题后常见的解决措施如下: -1. 使能动态loss scale功能,或者是合理设置静态loss scale的值,请参考[LossScale](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html#损失缩放)。需要注意的是,直接将GPU场景中的静态loss scale用于Ascend上的训练时,可能会导致不期望的频繁溢出,影响收敛。loss scale使能后,可能需要多次实验以调整loss scale的初始值init_loss_scale、调整比例scale_factor、调整窗口scale_window等参数,直到训练中浮点溢出非常少,请参考[DynamicLossScaleManager](https://www.mindspore.cn/docs/zh-CN/master/api_python/amp/mindspore.amp.DynamicLossScaleManager.html)以了解这些参数的含义。 +1. 使能动态loss scale功能,或者是合理设置静态loss scale的值,请参考[LossScale](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html#损失缩放)。需要注意的是,直接将GPU场景中的静态loss scale用于Ascend上的训练时,可能会导致不期望的频繁溢出,影响收敛。loss scale使能后,可能需要多次实验以调整loss scale的初始值init_loss_scale、调整比例scale_factor、调整窗口scale_window等参数,直到训练中浮点溢出非常少,请参考[DynamicLossScaleManager](https://www.mindspore.cn/docs/zh-CN/master/api_python/amp/mindspore.amp.DynamicLossScaleManager.html)以了解这些参数的含义。 2. 溢出问题对精度有关键影响且无法规避的,将相应的API调整为FP32 API(调整后可能对性能有较大影响)。 检查结论: @@ -358,7 +358,7 @@ MindSpore API同其它框架的API存在一定差异。有标杆脚本的情况 检查方法: -在使用[混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html)时,一般应确认使能了[DynamicLossScaleManager](https://www.mindspore.cn/docs/zh-CN/master/api_python/amp/mindspore.amp.DynamicLossScaleManager.html)或[FixedLossScaleManager](https://www.mindspore.cn/docs/zh-CN/master/api_python/amp/mindspore.amp.FixedLossScaleManager.html),推荐优先使用DynamicLossScaleManager。可以先使用DynamicLossScaleManager或FixedLossScaleManager的默认参数值进行训练,若产生溢出的迭代过多,影响最终精度时,应根据主要的溢出现象,针对性调整loss_scale的值。当主要溢出现象为梯度上溢时,应减小loss_scale的值(可以尝试将原loss_scale值除以2);当主要溢出现象为梯度下溢时,应增大loss_scale的值(可以尝试将原loss_scale值乘以2)。对于Ascend AI处理器上的训练,其在大部分情况下为混合精度训练。由于Ascend AI处理器计算特性与GPU混合精度计算特性存在差异,LossScaleManager超参也可能需要根据训练情况调整为与GPU上不同的值以保证精度。 +在使用[混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html)时,一般应确认使能了[DynamicLossScaleManager](https://www.mindspore.cn/docs/zh-CN/master/api_python/amp/mindspore.amp.DynamicLossScaleManager.html)或[FixedLossScaleManager](https://www.mindspore.cn/docs/zh-CN/master/api_python/amp/mindspore.amp.FixedLossScaleManager.html),推荐优先使用DynamicLossScaleManager。可以先使用DynamicLossScaleManager或FixedLossScaleManager的默认参数值进行训练,若产生溢出的迭代过多,影响最终精度时,应根据主要的溢出现象,针对性调整loss_scale的值。当主要溢出现象为梯度上溢时,应减小loss_scale的值(可以尝试将原loss_scale值除以2);当主要溢出现象为梯度下溢时,应增大loss_scale的值(可以尝试将原loss_scale值乘以2)。对于Ascend AI处理器上的训练,其在大部分情况下为混合精度训练。由于Ascend AI处理器计算特性与GPU混合精度计算特性存在差异,LossScaleManager超参也可能需要根据训练情况调整为与GPU上不同的值以保证精度。 检查结论: @@ -368,7 +368,7 @@ MindSpore API同其它框架的API存在一定差异。有标杆脚本的情况 检查方法: -梯度裁剪(gradient clip)是指当梯度大于某个阈值时,强制调整梯度使其变小的技术。梯度裁剪对RNN网络中的梯度爆炸问题有较好的效果。如果同时使用了[loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html#损失缩放)和梯度裁剪,需要进行本检查。请对照代码检查确认梯度裁剪的应用对象是除以loss scale后得到的原始梯度值。 +梯度裁剪(gradient clip)是指当梯度大于某个阈值时,强制调整梯度使其变小的技术。梯度裁剪对RNN网络中的梯度爆炸问题有较好的效果。如果同时使用了[loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html#损失缩放)和梯度裁剪,需要进行本检查。请对照代码检查确认梯度裁剪的应用对象是除以loss scale后得到的原始梯度值。 检查结论: @@ -378,7 +378,7 @@ MindSpore API同其它框架的API存在一定差异。有标杆脚本的情况 检查方法: -梯度惩罚是指将梯度添加到代价函数中,约束梯度长度的技术。如果同时使用了[loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html)和梯度惩罚(gradient penalty),需要进行本检查。检查确认计算梯度惩罚项时,输入的梯度为无loss scale的梯度。例如,可以先将代用loss scale的梯度除以loss scale,再用来计算梯度惩罚项。 +梯度惩罚是指将梯度添加到代价函数中,约束梯度长度的技术。如果同时使用了[loss scale](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html)和梯度惩罚(gradient penalty),需要进行本检查。检查确认计算梯度惩罚项时,输入的梯度为无loss scale的梯度。例如,可以先将代用loss scale的梯度除以loss scale,再用来计算梯度惩罚项。 检查结论: diff --git a/docs/mindinsight/docs/source_zh_cn/conf.py b/docs/mindinsight/docs/source_zh_cn/conf.py index 5ff324ae28eceb77afe1dee5bdfd62b9cebe305f..78fdfeb0033478f1acf77f05ee0e227793bedd88 100644 --- a/docs/mindinsight/docs/source_zh_cn/conf.py +++ b/docs/mindinsight/docs/source_zh_cn/conf.py @@ -31,8 +31,6 @@ with open(statemachine.__file__, 'r') as g: from sphinx.ext import autodoc as sphinx_autodoc -import mindinsight - # -- Project information ----------------------------------------------------- project = 'MindSpore' @@ -165,17 +163,17 @@ copy_list = [] present_path = os.path.dirname(__file__) -for i in os.listdir(src_dir): - if os.path.isfile(os.path.join(src_dir,i)): - if os.path.exists('./'+i): - os.remove('./'+i) - shutil.copy(os.path.join(src_dir,i),'./'+i) - copy_list.append(os.path.join(present_path,i)) - else: - if os.path.exists('./'+i): - shutil.rmtree('./'+i) - shutil.copytree(os.path.join(src_dir,i),'./'+i) - copy_list.append(os.path.join(present_path,i)) +# for i in os.listdir(src_dir): +# if os.path.isfile(os.path.join(src_dir,i)): +# if os.path.exists('./'+i): +# os.remove('./'+i) +# shutil.copy(os.path.join(src_dir,i),'./'+i) +# copy_list.append(os.path.join(present_path,i)) +# else: +# if os.path.exists('./'+i): +# shutil.rmtree('./'+i) +# shutil.copytree(os.path.join(src_dir,i),'./'+i) +# copy_list.append(os.path.join(present_path,i)) # add view import json diff --git a/docs/mindinsight/docs/source_zh_cn/index.rst b/docs/mindinsight/docs/source_zh_cn/index.rst index 2492925d151339edbf86045627cdb78172705b92..6c0d152e0264baacfb820f9896125c9ea0eb04d8 100644 --- a/docs/mindinsight/docs/source_zh_cn/index.rst +++ b/docs/mindinsight/docs/source_zh_cn/index.rst @@ -85,6 +85,7 @@ MindSpore Insight包括以下内容: graph_visual_design tensor_visual_design profiler_design + profiler_files_description faq .. toctree:: diff --git a/docs/mindinsight/docs/source_zh_cn/performance_optimization.md b/docs/mindinsight/docs/source_zh_cn/performance_optimization.md index 76fa82f7c0bfa27d98fa6efab791e290d516c59e..a961939ece364c537455871f372d78610be304ca 100644 --- a/docs/mindinsight/docs/source_zh_cn/performance_optimization.md +++ b/docs/mindinsight/docs/source_zh_cn/performance_optimization.md @@ -41,7 +41,7 @@ Profiler的功能介绍及使用说明请参见教程: *图3:数据准备详情页面——数据处理* -针对数据处理操作的性能优化,可以参考[数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html)页面。 +针对数据处理操作的性能优化,可以参考[数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html)页面。 查看ResNet50网络中数据处理的代码部分,发现map操作的num_parallel_workers参数没有设置,默认为1,代码如下: ```python @@ -91,7 +91,7 @@ data_set = data_set.map(operations=trans, input_columns="image", num_parallel_wo *图6:通过算子耗时详情页面寻找可优化算子* -对于算子耗时优化,在float16和float32格式精度无明显差别的前提下,通常可使用计算量更小的float16格式來提高性能,参考[使能混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html )页面。 +对于算子耗时优化,在float16和float32格式精度无明显差别的前提下,通常可使用计算量更小的float16格式來提高性能,参考[使能混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html )页面。 优化参考代码如下: diff --git a/docs/mindinsight/docs/source_zh_cn/performance_profiling_gpu.md b/docs/mindinsight/docs/source_zh_cn/performance_profiling_gpu.md index 3a33b0ea6ca5f54eb7930a4ed18c4c1458a75c95..2dec246c24c250b5f4d89ac23f37a653c98e4f5c 100644 --- a/docs/mindinsight/docs/source_zh_cn/performance_profiling_gpu.md +++ b/docs/mindinsight/docs/source_zh_cn/performance_profiling_gpu.md @@ -80,7 +80,7 @@ - `timeline_limit`(int, 可选) - 设置限制timeline文件存储上限大小(单位M)。使用此参数时,op_time必须设置成true,默认值:500。 - `data_process`(bool, 可选)- 表示是否收集数据准备性能数据,默认值:true。 - `op_time`(bool, 可选)- 表示是否收集算子性能数据,默认值:true。 - - `profile_framework`(str, 可选)- 是否需要收集Host侧的内存和时间,可选参数为["all", "time", "memory", null]。默认值:"all"。 + - `profile_framework`(str, 可选)- 是否需要收集Host侧的时间,可选参数为["all", "time", null]。默认值:null。 ## 启动MindSpore Insight diff --git a/docs/mindinsight/docs/source_zh_cn/performance_tuning_guide.md b/docs/mindinsight/docs/source_zh_cn/performance_tuning_guide.md index e332d93e4c7beefbb78bd3f58fea3d6b165a0be3..c4031d246d39be262394a88c1c2ec40c1bd3b944 100644 --- a/docs/mindinsight/docs/source_zh_cn/performance_tuning_guide.md +++ b/docs/mindinsight/docs/source_zh_cn/performance_tuning_guide.md @@ -58,7 +58,7 @@ MindSpore Insight在性能调优的单卡页面为用户提供了`迭代轨迹` - 若用户脚本中不存在耗时的自定义逻辑,说明框架将数据从Host侧发送到Device侧耗时较长,请到[MindSpore社区](https://gitee.com/mindspore/mindspore/issues) 进行反馈。 -步骤2:跳转到`数据准备详情`页的`数据处理`标签页,观察算子间队列,确定数据处理具体哪个操作存在性能瓶颈。判断原则请见[性能调试](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling_ascend.html#数据准备性能分析) 页面的`数据处理pipeline分析`部分。找到存在性能问题的操作后,可参考[数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html) 页面尝试提高数据处理操作的性能。 +步骤2:跳转到`数据准备详情`页的`数据处理`标签页,观察算子间队列,确定数据处理具体哪个操作存在性能瓶颈。判断原则请见[性能调试](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling_ascend.html#数据准备性能分析) 页面的`数据处理pipeline分析`部分。找到存在性能问题的操作后,可参考[数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html) 页面尝试提高数据处理操作的性能。 #### 数据下沉模式 @@ -69,7 +69,7 @@ MindSpore Insight在性能调优的单卡页面为用户提供了`迭代轨迹` 步骤2:查看主机队列Size曲线的变化情况。若该队列Size都不是0,说明训练数据从Host发往Device的流程为性能瓶颈点,请到[MindSpore社区](https://gitee.com/mindspore/mindspore/issues) 反馈;否则说明数据处理流程是性能瓶颈点,请参照步骤3继续定位数据处理哪个操作存在性能问题。 -步骤3:跳转到`数据准备详情页的数据处理标签页`观察算子间队列,确定数据处理具体哪个操作存在性能瓶颈。判断原则请见[性能调试](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling_ascend.html#数据准备性能分析) 页面的`数据处理pipeline分析`部分。找到存在性能问题的操作后,可参考[数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html) 页面尝试提高数据处理操作的性能。 +步骤3:跳转到`数据准备详情页的数据处理标签页`观察算子间队列,确定数据处理具体哪个操作存在性能瓶颈。判断原则请见[性能调试](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling_ascend.html#数据准备性能分析) 页面的`数据处理pipeline分析`部分。找到存在性能问题的操作后,可参考[数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html) 页面尝试提高数据处理操作的性能。 ### 前反向耗时长 @@ -125,7 +125,7 @@ MindSpore Insight在性能调优的单卡页面为用户提供了`迭代轨迹` 步骤3:观察集群页面的迭代拖尾耗时 - 观察是否有某张卡的迭代拖尾耗时明显比其它卡长,通常该情况是由于集群中存在慢节点导致,用户可参考步骤1和步骤2确定是否有慢节点并修复。 -- 若所有卡的迭代拖尾耗时基本相同,且该阶段耗时较长,通常是由于AllReduce集合通信算子耗时长导致。用户可尝试通过修改all_reduce_fusion_config参数,改变[AllReduce融合切分策略](https://mindspore.cn/tutorials/experts/zh-CN/master/parallel/overview.html) 降低该阶段的耗时。 +- 若所有卡的迭代拖尾耗时基本相同,且该阶段耗时较长,通常是由于AllReduce集合通信算子耗时长导致。用户可尝试通过修改all_reduce_fusion_config参数,改变[AllReduce融合切分策略](https://mindspore.cn/docs/zh-CN/master/model_train/parallel/overview.html) 降低该阶段的耗时。 ### 模型并行 @@ -143,7 +143,7 @@ MindSpore Insight在性能调优的单卡页面为用户提供了`迭代轨迹` 步骤3:观察集群页面的纯通信时间 在通过步骤1和步骤2确认没有慢节点的前提下,集群中各卡的纯通信时间应该基本相同。如果该阶段耗时较短,说明由于算子重排布导致的通信时间对性能的影响较小,用户无需考虑对算子切分策略进行优化。否则,用户需要重点分析算子的切分策略是否可以优化。 -在参考如下步骤继续分析前,用户需要对模型并行原理有一定的了解,请参考[分布式训练](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/overview.html)了解其基本原理,如下步骤只是辅助用户进行合理性分析,算子切分策略是否有优化空间、如何优化需要用户了解模型并行原理后,结合各自的网络具体分析进行判断。 +在参考如下步骤继续分析前,用户需要对模型并行原理有一定的了解,请参考[分布式训练](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/overview.html)了解其基本原理,如下步骤只是辅助用户进行合理性分析,算子切分策略是否有优化空间、如何优化需要用户了解模型并行原理后,结合各自的网络具体分析进行判断。 - 若该阶段耗时较长,用户可任意选其中的一张卡,观察其时间线。在时间线中,MindSpore Insight对纯通信时间做了标记,参考下图中的`Pure Communication Op`: diff --git a/docs/mindinsight/docs/source_zh_cn/profiler_files_description.md b/docs/mindinsight/docs/source_zh_cn/profiler_files_description.md new file mode 100644 index 0000000000000000000000000000000000000000..92af0cdbaae2844c7911dedf3fde2269fc44859e --- /dev/null +++ b/docs/mindinsight/docs/source_zh_cn/profiler_files_description.md @@ -0,0 +1,91 @@ +# profiler目录下的性能数据 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindinsight/docs/source_zh_cn/profiler_files_description.md) + +profiler目录下包括一些csv、json、txt文件,这些文件包含了模型计算过程中算子执行时间、内存占用、通信等性能数据,帮助用户分析性能瓶颈。下面对部分csv、txt文件中的字段进行说明,文件内容主要包括device侧算子(AI Core算子和AI CPU算子)耗时的信息、算子级内存和应用级内存占用的信息。 + +## aicore_intermediate_*_detail.csv文件说明 + +aicore_intermediate_\*_detail.csv文件包含基于output_timeline_data_\*.txt和framework_raw_\*.csv中的内容,统计AI Core算子信息。文件中的字段说明参考下表: + +| 字段名 | 字段说明 | +|----------------------------|----------------------------| +|full_kernel_name |device侧执行kernel算子全名| +|task_duration |算子执行用时| +|execution_frequency |算子执行频次| +|task_type |算子的任务类型| + +## aicore_intermediate_*_type.csv文件说明 + +aicore_intermediate_\*_type.csv文件包括基于output_timeline_data_\*.txt和framework_raw_\*.csv中的内容,统计AI Core算子具体类型的信息。文件中的字段说明参考下表: + +| 字段名 | 字段说明 | +|------------------------------|------------------------| +| kernel_type | AI Core算子类型| +| task_time | 该类型算子总用时| +| execution_frequency | 该类型算子执行频次| +| percent | 该算子类型的用时的占所有算子总用时的百分比| + +## aicpu_intermediate_*.csv文件说明 + +aicpu_intermediate_\*.csv文件包含AI CPU算子的耗时信息。文件中的字段说明参考下表: + +| 字段名 | 字段说明 | +|------------------------------|------------------------| +| serial_num | AI CPU算子序号| +| kernel_type | AI CPU算子类型| +| total_time | 算子耗时,等于下发耗时和执行耗时之和| +| dispatch_time | 下发耗时| +| execution_time | 执行耗时| +| run_start | 算子执行起始时间| +| run_end | 算子执行结束时间| + +## flops_*.txt文件说明 + +flops_\*.txt文件包含device侧算子的浮点计算次数、每秒浮点计算次数等信息。文件中的字段说明参考下表: + +| 字段名 | 字段说明 | +|------------------------------|------------------------| +| full_kernel_name | device侧执行kernel算子全名| +| MFLOPs(10^6 cube) | 浮点计算次数(10^6 cube)| +| GFLOPS(10^9 cube) | 每秒浮点计算次数(10^9 cube)| +| MFLOPs(10^6 vector) | 浮点计算次数(10^6 vector)| +| GFLOPS(10^9 vector) | 每秒浮点计算次数(10^9 vector)| + +## output_timeline_data_*.txt文件说明 + +output_timeline_data_\*.txt文件包括device侧算子的耗时信息。文件中的字段说明参考下表: + +| 字段名 | 字段说明 | +|------------------------------|------------------------| +| kernel_name | device侧执行kernel算子全名| +| stream_id | 算子所处Stream ID| +| start_time | 算子执行开始时间(us)| +| duration | 算子执行用时(ms)| + +## cpu_ms_memory_record_*.txt文件说明 + +cpu_ms_memory_record_\*.txt文件包含应用级内存占用的信息。文件中的字段说明参考下表: + +| 字段名 | 字段说明 | +|------------------------------|------------------------| +| Timestamp | 内存事件发生时刻(ns)| +| Total Allocated | 内存分配总额(Byte)| +| Total Reserved | 内存预留总额(Byte)| +| Total Active | MindSpore中的流申请的总内存(Byte)| + +## operator_memory_*.csv文件说明 + +operator_memory_\*.csv文件包含算子级内存占用的信息。文件中的字段说明参考下表: + +| 字段名 | 字段说明 | +|------------------------------|------------------------| +| Name | 内存占用Tensor名| +| Size | 占用内存大小(KB)| +| Allocation Time | Tensor内存分配时间(us)| +| Duration | Tensor内存占用时间(us)| +| Allocation Total Allocated | 算子内存分配时的内存分配总额(MB)| +| Allocation Total Reserved | 算子内存分配时的内存占用总额(MB)| +| Release Total Allocated | 算子内存释放时的内存分配总额(MB)| +| Release Total Reserved | 算子内存释放时的内存占用总额(MB)| +| Device | device类型| \ No newline at end of file diff --git a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_host_time.txt b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_host_time.txt index a91ddd3c2ae9cd535d52ed8f8a1f9b4104b13920..1ee5bff021792477cb643b2e96dafbc6e40fd98e 100644 --- a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_host_time.txt +++ b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_host_time.txt @@ -1,4 +1,4 @@ Host侧耗时分析 -------------- -如果开启了Host侧时间收集功能,在训练结束后可以在指定目录下查看各阶段的Host侧耗时情况。例如,Profiler实例化时,指定output_path="/XXX/profiler_output",Host侧耗时数据会保存在"/XXX/profiler_output/profiler/host_info"目录下,文件格式为json,前缀为timeline\_,后缀为rank_id。Host侧耗时文件可以用 ``chrome://tracing`` 来展示。可以使用W/S/A/D来放大、缩小、左移、右移地查看耗时信息。 +如果开启了Host侧时间收集功能,在训练结束后可以在ascend_timeline_display_[rank_id].json下查看耗时信息。可以用 ``chrome://tracing`` 来展示。可以使用W/S/A/D来放大、缩小、左移、右移地查看耗时信息。 diff --git a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_offline.txt b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_offline.txt index 3cac37bf798e51b6643213688dd97b582294d67e..3baf9af5ba2ebeb6f7e4788191bb98026dce44b4 100644 --- a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_offline.txt +++ b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_offline.txt @@ -38,4 +38,120 @@ Profiler.offline_analyse(path='/path/to/profiler_data') -离线解析之后,就可以在/path/to/profiler_data/profiler目录查看性能数据了。 \ No newline at end of file +离线解析之后,就可以在/path/to/profiler_data/profiler目录查看性能数据了。 + +目录结构 +~~~~~~~~~~~~ + +性能数据目录结构示例如下: + +.. code:: + + └──── profiler + ├──── container + ├──── FRAMEWORK // 框架侧采集的原始数据 + │ └──── op_range_* + ├──── PROF_{数字}_{时间戳}_{字符串} // msprof性能数据 + │ ├──── analyse + │ ├──── device_* + │ ├──── host + │ ├──── mindstudio_profiler_log + │ └──── mindstudio_profiler_output + ├──── rank_* // 内存相关的原始数据 + │ ├──── memory_block.csv + │ └──── task.csv + ├──── rank-*_{时间戳}_ascend_ms // MindStudio Insight可视化交付件 + │ ├──── ASCEND_PROFILER_OUTPUT // MindSpore Profiler接口采集的性能数据 + │ ├──── profiler_info_*.json + │ └──── profiler_metadata.json // 记录用户自定义的meta数据,调用add_metadata或add_metadata_json接口生成该文件 + ├──── aicore_intermediate_*_detail.csv + ├──── aicore_intermediate_*_type.csv + ├──── aicpu_intermediate_*.csv + ├──── ascend_cluster_analyse_model-{mode}_{stage_num}_{rank_size}_*.csv + ├──── ascend_timeline_display_*.json + ├──── ascend_timeline_summary_*.json + ├──── cpu_framework_*.txt // 异构场景生成 + ├──── cpu_ms_memory_record_*.txt + ├──── cpu_op_detail_info_*.csv // 异构场景生成 + ├──── cpu_op_execute_timestamp_*.txt // 异构场景生成 + ├──── cpu_op_type_info_*.csv // 异构场景生成 + ├──── dataset_iterator_profiling_*.txt // 数据非下沉场景生成 + ├──── device_queue_profiling_*.txt // 数据下沉场景生成 + ├──── dynamic_shape_info_*.json + ├──── flops_*.txt + ├──── flops_summary_*.json + ├──── framework_raw_*.csv + ├──── hccl_raw_*.csv // 配置profiler(profiler_communication=True)生成 + ├──── minddata_aicpu_*.json // 数据下沉场景生成 + ├──── minddata_cpu_utilization_*.json + ├──── minddata_pipeline_raw_*.csv + ├──── minddata_pipeline_summary_*.csv + ├──── minddata_pipeline_summary_*.json + ├──── operator_memory_*.csv + ├──── output_timeline_data_*.txt + ├──── parallel_strategy_*.json + ├──── pipeline_profiling_*.json + ├──── profiler_info_*.json + ├──── step_trace_point_info_*.json + └──── step_trace_raw_*_detail_time.csv + └──── dataset_*.csv + +- \* 代表rank id + +性能数据文件描述 +~~~~~~~~~~~~~~~~~~ + +PROF_{数字}_{时间戳}_{字符串}目录下为CANN Profiling采集的性能数据,主要保存在mindstudio_profiler_output中,数据介绍可参考 `性能数据文件说明 `_。 + +profiler目录下包含csv、json、txt三类文件,覆盖了算子执行时间、内存占用、通信等方面的性能数据,文件说明见下表。部分文件的详细说明参考 `性能数据 `_。 + +============================================== ============================================================================== +文件名 说明 +============================================== ============================================================================== +step_trace_point_info_*.json step节点对应的算子信息(仅mode=GRAPH,export GRAPH_OP_RUM=0) +step_trace_raw_*_detail_time.csv 每个step的节点的时间信息(仅mode=GRAPH,export GRAPH_OP_RUM=0) + +dynamic_shape_info_*.json 动态shape下算子信息 + +pipeline_profiling_*.json MindSpore数据处理,采集落盘的中间文件,用于MindInsight可视化 +minddata_pipeline_raw_*.csv MindSpore数据处理,采集落盘的中间文件,用于MindInsight可视化 +minddata_pipeline_summary_*.csv MindSpore数据处理,采集落盘的中间文件,用于MindInsight可视化 +minddata_pipeline_summary_*.json MindSpore数据处理,采集落盘的中间文件,用于MindInsight可视化 +framework_raw_*.csv MindSpore数据处理中AI Core算子的信息 +device_queue_profiling_*.txt MindSpore数据处理,采集落盘的中间文件,用于MindInsight可视化(仅数据下沉场景) +minddata_aicpu_*.txt MindSpore数据处理中AI CPU算子的性能数据(仅数据下沉场景) +dataset_iterator_profiling_*.txt MindSpore数据处理,采集落盘的中间文件,用于MindInsight可视化(仅数据非下沉场景) + +aicore_intermediate_*_detail.csv AI Core算子数据 +aicore_intermediate_*_type.csv AI Core算子调用次数和耗时统计 +aicpu_intermediate_*.csv AI CPU算子信息解析后耗时数据 +flops_*.txt 记录AI Core算子的浮点计算次数(FLOPs)、每秒的浮点计算次数(FLOPS) +flops_summary_*.json 记录所有算子的总的FLOPs、所有算子的平均FLOPs、平均的FLOPS_Utilization + +ascend_timeline_display_*.json timeline可视化文件,用于MindStudio Insight可视化 +ascend_timeline_summary_*.json timeline统计数据 +output_timeline_data_*.txt 算子timeline数据,只有AI Core算子数据存在时才有 + +cpu_ms_memory_record_*.txt 内存profiling的原始文件 +operator_memory_*.csv 算子级内存信息 + +minddata_cpu_utilization_*.json CPU利用率 + +cpu_op_detail_info_*.csv CPU算子耗时数据(仅mode=GRAPH) +cpu_op_type_info_*.csv 具体类别CPU算子耗时统计(仅mode=GRAPH) +cpu_op_execute_timestamp_*.txt CPU算子执行起始时间与耗时(仅mode=GRAPH) +cpu_framework_*.txt 异构场景下CPU算子耗时(仅mode=GRAPH) + +ascend_cluster_analyse_model-xxx.csv 在模型并行或pipeline并行模式下,计算和通信等相关数据(仅mode=GRAPH) + +hccl_raw_*.csv 基于卡的通信时间和通信等待时间(仅mode=GRAPH) + +parallel_strategy_*.json 算子并行策略,采集落盘中间文件,用于MindInsight可视化 + +profiler_info_*.json Profiler配置等info信息 + +dataset_*.csv 数据处理模块各阶段执行耗时 +============================================== ============================================================================== + +- \* 表示rank id +- ascend_cluster_analyse_model-xxx_*.csv完整的文件名应该是ascend_cluster_analyse_model-{mode}_{stage_num}_{rank_size}_{rank_id}.csv,比如ascend_cluster_analyse_model-parallel_1_8_0.csv \ No newline at end of file diff --git a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_resoure.txt b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_resoure.txt index faf74f1e8795f66efa1f47c766ff9406b66ed8d6..10b657d58bfd55fd73a06853ea930c260efa0c5e 100644 --- a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_resoure.txt +++ b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_resoure.txt @@ -78,20 +78,3 @@ CPU利用率常用场景: *图:内存使用折线图* -Host侧内存使用情况 -~~~~~~~~~~~~~~~~~~ - -如果开启了Host侧内存收集功能,在训练结束后可以在指定目录下查看内存使用情况。例如,Profiler实例化时,指定output_path="/XXX/profiler_output",Host侧内存数据会保存在"/XXX/profiler_output/profiler/host_info"目录下,文件格式为csv,前缀为host_memory\_,后缀为rank_id。表头的含义如下: - -- tid:收集Host侧内存时当前线程的线程号。 -- pid:收集Host侧内存时当前进程的进程号。 -- parent_pid:收集Host侧内存时当前进程的父进程的进程号。 -- module_name:收集Host侧内存的组件名,一个组件包含一个或多个event。 -- event:收集Host侧内存的事件名,一个event包含一个或多个stage。 -- stage:收集Host侧内存的阶段名。 -- level:0表示框架开发者使用,1表示用户(算法工程师)使用。 -- start_end:stage开始或结束的标记,0表示开始标记,1表示结束标记,2表示不区分开始或结束。 -- custom_info:框架开发者用于定位性能问题的组件自定义信息,可能为空。 -- memory_usage:Host侧内存占用,单位为kB,0表示当前阶段没有收集内存数据。 -- time_stamp:时间戳,单位为us。 - diff --git a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_training.txt b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_training.txt index ed6950153d91fdfdee4a09f7208f85af20e91501..3ded68f654096adb192ae891cc882e30ceabbb94 100644 --- a/docs/mindinsight/docs/source_zh_cn/profiling/profiling_training.txt +++ b/docs/mindinsight/docs/source_zh_cn/profiling/profiling_training.txt @@ -206,4 +206,4 @@ - `parallel_strategy` (bool, 可选) - 表示是否收集并行策略性能数据,默认值:true。 -- `profile_framework` (str, 可选) - 是否需要收集Host侧的内存和时间,可选参数为["all", "time", "memory", null]。默认值:"all"。 +- `profile_framework` (str, 可选) - 是否需要收集Host侧的内存和时间,可选参数为["all", "time", null]。默认值:"all"。 diff --git a/docs/mindspore/Makefile b/docs/mindspore/Makefile index 738c74e790e5eb839a0d6e668d68c5cfd8f296b6..195e0a1b02b53ca88892d3827fa7aeefdecd3dad 100644 --- a/docs/mindspore/Makefile +++ b/docs/mindspore/Makefile @@ -19,9 +19,10 @@ help: %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -EXTRADIR = $(SOURCEDIR)/api_python +# EXTRADIR = $(SOURCEDIR)/api_python +# -rm -rf $(BUILDDIR)/* $(EXTRADIR)/* .PHONY: clean clean: - -rm -rf $(BUILDDIR)/* $(EXTRADIR)/* + -rm -rf $(BUILDDIR)/* diff --git a/docs/mindspore/_ext/generate_ops_mint_rst.py b/docs/mindspore/_ext/generate_ops_mint_rst.py index 19dab59353fba16809a4bab08015b1d9050374b4..710743e3d51e1e80ec2ed4b46d0fde905f0e2cf4 100644 --- a/docs/mindspore/_ext/generate_ops_mint_rst.py +++ b/docs/mindspore/_ext/generate_ops_mint_rst.py @@ -29,7 +29,11 @@ def generate_ops_mint_rst(repo_path, ops_path, mint_path, pr_need='all'): modulename += '.functional' mint_ops_dict[modulename] = [] # pylint: disable=eval-used - reg_all = eval(f"{modulename}.__all__") + try: + reg_all = eval(f"{modulename}.__all__") + except AttributeError as e: + print(f'模块名有误:{e}') + continue one_p = re.findall(r'from mindspore\.(ops|nn).*?(? None: @@ -474,6 +474,7 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None, py_source_rel = get_full_modname(modname, qualname).replace('.', '/') + '.py' except: py_source_rel = '' + # 自动生成的ops模块单独处理 if 'mindspore/ops/auto_generate/' in py_source_rel: name1 = name @@ -515,10 +516,13 @@ def generate_autosummary_docs(sources: List[str], output_dir: str = None, content = re.sub('([=]{5,})\n', r'\1\n' + re_view, content, 1) elif py_source_rel: + if not os.path.exists(os.path.join(app.config.repo_path, app.config.repo_whl, py_source_rel)): + py_source_rel = py_source_rel.replace('.py', '/__init__.py') + re_view = f"\n.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/{app.config.docs_branch}/" + \ f"resource/_static/logo_source_en.svg\n :target: " + app.config.giturl + \ f"{app.config.copy_repo}/blob/{app.config.branch}/" + app.config.repo_whl + \ - py_source_rel.split(app.config.cst_module_name)[-1] + '\n :alt: View Source On Gitee\n\n' + py_source_rel + '\n :alt: View Source On Gitee\n\n' if re_view not in content: content = re.sub('([=]{5,})\n', r'\1\n' + re_view, content, 1) diff --git a/docs/mindspore/source_en/api_python/index.rst b/docs/mindspore/source_en/api_python/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..01d63824d1ffd9cd13cdee89de4356596e6a74a8 --- /dev/null +++ b/docs/mindspore/source_en/api_python/index.rst @@ -0,0 +1,29 @@ +API +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + mindspore + mindspore.nn + mindspore.ops + mindspore.ops.primitive + mindspore.mint + mindspore.amp + mindspore.train + mindspore.communication + mindspore.communication.comm_func + mindspore.common.initializer + mindspore.hal + mindspore.dataset + mindspore.dataset.transforms + mindspore.mindrecord + mindspore.nn.probability + mindspore.rewrite + mindspore.multiprocessing + mindspore.boost + mindspore.numpy + mindspore.scipy + mindspore.experimental + ../note/env_var_list diff --git a/docs/mindspore/source_en/conf.py b/docs/mindspore/source_en/conf.py index fe0027923f3bf40aa91ab97aa542e362b74adc5e..c3a76983b3664b6c7a5a07e9d235f37959735c54 100644 --- a/docs/mindspore/source_en/conf.py +++ b/docs/mindspore/source_en/conf.py @@ -256,9 +256,15 @@ src_dir_en = os.path.join(repo_path, copy_path) des_sir = "./api_python" def copy_source(sourcedir, des_sir): - if os.path.exists(des_sir): - shutil.rmtree(des_sir) - shutil.copytree(sourcedir, des_sir) + for i in os.listdir(sourcedir): + if os.path.isfile(os.path.join(sourcedir, i)): + if os.path.exists(os.path.join(des_sir, i)): + os.remove(os.path.join(des_sir, i)) + shutil.copy(os.path.join(sourcedir, i), os.path.join(des_sir, i)) + else: + if os.path.exists(os.path.join(des_sir, i)): + shutil.rmtree(os.path.join(des_sir, i)) + shutil.copytree(os.path.join(sourcedir, i), os.path.join(des_sir, i)) copy_source(src_dir_en, des_sir) @@ -327,19 +333,18 @@ else: branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == copy_repo][0] docs_branch = [version_inf[i]['branch'] for i in range(len(version_inf)) if version_inf[i]['name'] == 'tutorials'][0] -cst_module_name = 'mindspore' -repo_whl = 'mindspore/python/mindspore' +repo_whl = 'mindspore/python/' giturl = 'https://gitee.com/mindspore/' -ops_yaml = 'mindspore/core/ops/ops_def/doc/' +ops_yaml = 'mindspore/ops/op_def/yaml/doc/' try: - ops_yaml_list = [i for i in os.listdir(os.path.join(repo_path, 'mindspore/core/ops/ops_def/doc')) if i.endswith('_doc.yaml') and '_grad' not in i] + ops_yaml_list = [i for i in os.listdir(os.path.join(repo_path, 'mindspore/ops/op_def/yaml/doc')) if i.endswith('_doc.yaml') and '_grad' not in i] except: ops_yaml_list = [] func_name_dict = {} -for i in os.listdir(os.path.join(repo_path, 'mindspore/core/ops/ops_def')): +for i in os.listdir(os.path.join(repo_path, 'mindspore/ops/op_def/yaml')): if i.endswith('_op.yaml') and '_grad' not in i: - with open(os.path.join(repo_path, 'mindspore/core/ops/ops_def', i), 'r+', encoding='utf-8') as f: + with open(os.path.join(repo_path, 'mindspore/ops/op_def/yaml', i), 'r+', encoding='utf-8') as f: op_content = f.read() if re.findall('function:\n\s+?name: (.*)', op_content): func_name_dict[re.findall('function:\n\s+?name: (.*)', op_content)[0]] = i.replace('_op.yaml', '') @@ -373,7 +378,6 @@ def setup(app): app.add_js_file('js/mermaid-9.3.0.js') app.add_config_value('docs_branch', '', True) app.add_config_value('branch', '', True) - app.add_config_value('cst_module_name', '', True) app.add_config_value('copy_repo', '', True) app.add_config_value('giturl', '', True) app.add_config_value('repo_whl', '', True) @@ -382,6 +386,7 @@ def setup(app): app.add_config_value('primi_auto', [], True) app.add_config_value('func_name_dict', {}, True) app.add_config_value('mint_sum', [], True) + app.add_config_value('repo_path', '', True) # Copy images from mindspore repo. import imghdr @@ -425,7 +430,6 @@ release_source = f'[![View Source On Gitee](https://mindspore-website.obs.cn-nor with open(src_release, "r", encoding="utf-8") as f: data = f.read() if len(re.findall("\n## (.*?)\n",data)) > 1: - data = re.sub("\n## MindSpore 2.3.0 [\s\S\n]*?\n## ", "\n## ", data) content = regex.findall("(\n## MindSpore [^L][\s\S\n]*?)\n## ", data, overlapped=True) repo_version = re.findall("\n## MindSpore ([0-9]+?\.[0-9]+?)\.([0-9]+?)[ -]", content[0])[0] content_new = '' diff --git a/docs/mindspore/source_en/design/distributed_training_design.md b/docs/mindspore/source_en/design/distributed_training_design.md index 4102db353059858480e88c0eabe753bdd911eff0..e6cba6a1045bee44040a6d299016753943c82470 100644 --- a/docs/mindspore/source_en/design/distributed_training_design.md +++ b/docs/mindspore/source_en/design/distributed_training_design.md @@ -94,9 +94,9 @@ This subsection describes how the `ParallelMode.SEMI_AUTO_PARALLEL` semi-automat Semi-automatic parallelism supports the automatic mixing of multiple parallel modes, respectively: - **Operator-level parallelism**: Operator parallelism takes the operators in a neural network and slices the input tensor to multiple devices for computation. In this way, data samples and model parameters can be distributed among different devices to train large-scale deep learning models and use cluster resources for parallel computing to improve the overall speed. The user can set the shard strategy for each operator, and the framework will model the slice of each operator and its input tensor according to the shard strategy of the operator to maintain mathematical equivalence. This approach can effectively reduce the load on individual devices and improve computational efficiency, and is suitable for training large-scale deep neural networks. For more details, please refer to [operator-level parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/operator_parallel.html). + **Operator-level parallelism**: Operator parallelism takes the operators in a neural network and slices the input tensor to multiple devices for computation. In this way, data samples and model parameters can be distributed among different devices to train large-scale deep learning models and use cluster resources for parallel computing to improve the overall speed. The user can set the shard strategy for each operator, and the framework will model the slice of each operator and its input tensor according to the shard strategy of the operator to maintain mathematical equivalence. This approach can effectively reduce the load on individual devices and improve computational efficiency, and is suitable for training large-scale deep neural networks. For more details, please refer to [operator-level parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/operator_parallel.html). - **Pipeline parallism**: When the number of cluster devices is large, if only operator parallelism is used, communication is required over the communication domain of the entire cluster, which may make communication inefficient and thus reduce the overall performance. The pipeline parallelism can slice the neural network structure into multiple stages, and each stage is running in a part of the device, which limits the communication domain of the collective communication to this part of the device, while the inter-stage uses point-to-point communication. The advantages of pipeline parallelism are: improving communication efficiency, and easily handling neural network structures stacked by layers. The disadvantage is that some nodes may be idle at the same time. Foe detailed information, refer to [pipeline parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/pipeline_parallel.html). + **Pipeline parallism**: When the number of cluster devices is large, if only operator parallelism is used, communication is required over the communication domain of the entire cluster, which may make communication inefficient and thus reduce the overall performance. The pipeline parallelism can slice the neural network structure into multiple stages, and each stage is running in a part of the device, which limits the communication domain of the collective communication to this part of the device, while the inter-stage uses point-to-point communication. The advantages of pipeline parallelism are: improving communication efficiency, and easily handling neural network structures stacked by layers. The disadvantage is that some nodes may be idle at the same time. Foe detailed information, refer to [pipeline parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/pipeline_parallel.html). **MoE parallism**: MoE is to distribute the experts to different workers and each worker takes on different batches of training data. For the non-MoE layer, expert parallelism is the same as data parallelism. In the MoE layer, the tokens in the sequence are sent to the workers corresponding to their matching experts via all-to-all communication. After completing the computation of the corresponding expert, it is then re-passed back to the original worker by all-to-all and organized into the original sequence for computation of the next layer. Since MoE models usually have a large number of experts, the expert parallelism increases more with the size of the model than the model parallelism. @@ -106,7 +106,7 @@ This subsection describes how the `ParallelMode.SEMI_AUTO_PARALLEL` semi-automat ![multi-copy Parallelism](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/design/images/multi_copy.png) - **Optimizer Parallelism**: When training in data parallelism or operator parallelism, the same copy of the model parameters may exist on multiple devices, which allows the optimizer to have redundant computations across multiple devices when updating that weight. In this case, the computation of the optimizer can be spread over multiple devices by optimizer parallelism. Its advantages are: reducing static memory consumption, and the amount of computation within the optimizer. The disadvantages are: increasing communication overhead. For detailed information, refer to [Optimizer Parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/optimizer_parallel.html). + **Optimizer Parallelism**: When training in data parallelism or operator parallelism, the same copy of the model parameters may exist on multiple devices, which allows the optimizer to have redundant computations across multiple devices when updating that weight. In this case, the computation of the optimizer can be spread over multiple devices by optimizer parallelism. Its advantages are: reducing static memory consumption, and the amount of computation within the optimizer. The disadvantages are: increasing communication overhead. For detailed information, refer to [Optimizer Parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/optimizer_parallel.html). ### Semi-automatic Parallel Code @@ -143,11 +143,11 @@ In fact, the hybrid parallel strategy generation module is responsible for findi Fully automatic parallelism is very difficult to implement, and MindSpore divides the provided strategy generation algorithm into L1 level and L2 level according to the degree of user intervention required (here we assume that the manually configured full graph strategy SEMI_AUTO is L0 level, and the scheme that does not require user participation is L3 level). -The strategy generation algorithm at the L1 level is called Strategy Broadcast (Sharding Propagation). In this mode, the user only needs to manually define the strategies for a few key operators, and the strategies for the remaining operators in the computational graph are automatically generated by the algorithm. Because the strategy of the key operator has been defined, the cost model of the algorithm mainly describes the redistribution cost between the operators, and the optimization objective is to minimize the redistribution cost of the whole graph. Because the main operator strategy has been defined, which is equivalent to a compressed search space, the search time of this scheme is shorter and its strategy performance depends on the definition of the key operator strategy, so it still requires the user to have the ability to analyze the defined strategy. Refer to [Sharding Propagation](https://www.mindspore.cn/tutorials/experts/en/master/parallel/sharding_propagation.html) for detailed information. +The strategy generation algorithm at the L1 level is called Strategy Broadcast (Sharding Propagation). In this mode, the user only needs to manually define the strategies for a few key operators, and the strategies for the remaining operators in the computational graph are automatically generated by the algorithm. Because the strategy of the key operator has been defined, the cost model of the algorithm mainly describes the redistribution cost between the operators, and the optimization objective is to minimize the redistribution cost of the whole graph. Because the main operator strategy has been defined, which is equivalent to a compressed search space, the search time of this scheme is shorter and its strategy performance depends on the definition of the key operator strategy, so it still requires the user to have the ability to analyze the defined strategy. Refer to [Sharding Propagation](https://www.mindspore.cn/docs/en/master/model_train/parallel/sharding_propagation.html) for detailed information. There are two types of L2-level strategy generation algorithms, Dynamic Programming and Symbolic Automatic Parallel Planner (SAPP for short). Both methods have their advantages and disadvantages. The dynamic programming algorithm is able to search for the optimal strategy inscribed by the cost model, but it takes longer time to search for parallel strategies for huge networks. The SAPP algorithm is able to generate optimal strategies instantaneously for huge networks and large-scale cuts. The core idea of the dynamic programming algorithm is to build a cost model of the full graph, including computation cost and communication cost, to describe the absolute time delay in the distributed training process, and to compress the search time using equivalent methods such as edge elimination and point elimination, but the search space actually grows exponentially with the number of devices and operators, so it is not efficient for large clusters with large models. -SAPP is modeled based on the parallelism principle by creating an abstract machine to describe the hardware cluster topology and optimizing the cost model by symbolic simplification. Its cost model compares not the predicted absolute latency, but the relative cost of different parallel strategies, so it can greatly compress the search space and guarantee minute search times for 100-card clusters. Refer to [Distributed Parallel Training Mode](https://www.mindspore.cn/tutorials/experts/en/master/parallel/overview.html) +SAPP is modeled based on the parallelism principle by creating an abstract machine to describe the hardware cluster topology and optimizing the cost model by symbolic simplification. Its cost model compares not the predicted absolute latency, but the relative cost of different parallel strategies, so it can greatly compress the search space and guarantee minute search times for 100-card clusters. Refer to [Distributed Parallel Training Mode](https://www.mindspore.cn/docs/en/master/model_train/parallel/overview.html) Sharding Propagation and SAPP currently support manual definition of Pipeline + automatic operator parallelism, and can be used in conjunction with optimizations such as recomputation, optimizer parallelism, etc. Dynamic Programming algorithms only support automatic operator parallelism. @@ -362,7 +362,7 @@ When the EmbeddingTable reaches T level and the single machine memory cannot be ![heterogeneous-heter-ps](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/design/images/heter-ps.png) -Parameter Server encapsulates heterogeneous processes, and users only need to configure parameters to use PS. For the detailed configuration process, refer to [Parameter Server training process](https://www.mindspore.cn/tutorials/experts/en/master/parallel/parameter_server_training.html). +Parameter Server encapsulates heterogeneous processes, and users only need to configure parameters to use PS. For the detailed configuration process, refer to [Parameter Server training process](https://www.mindspore.cn/docs/en/master/model_train/parallel/parameter_server_training.html). In addition, the process of using PS is also available in the wide&deep network and can be found at: . diff --git a/docs/mindspore/source_en/design/dynamic_graph_and_static_graph.md b/docs/mindspore/source_en/design/dynamic_graph_and_static_graph.md index d5ad99cb2df3b8520118c2c1afa4491d0d962eb0..e64ca99a76f9e173b22e5c1e228f97b266393a2e 100644 --- a/docs/mindspore/source_en/design/dynamic_graph_and_static_graph.md +++ b/docs/mindspore/source_en/design/dynamic_graph_and_static_graph.md @@ -163,189 +163,4 @@ Similarly for the input y derivation, the same procedure can be used for the der ### Control Flow in PyNative Mode -In the PyNative mode, scripts are executed according to the Python syntax, so in MindSpore, there is no special treatment for the control flow syntax, which is directly expanded and executed according to the Python syntax, and automatic differentiation is performed on the expanded execution operator. For example, for a for loop, the statements in the for loop are continuously executed under PyNative and automatic differentiation is performed on the operators according to the specific number of loops. - -## Dynamic and Static Unification - -### Overview - -The industry currently supports both dynamic and static graph modes. Dynamic graphs are executed by interpretation, with dynamic syntax affinity and flexible expression, and static graphs are executed by using jit compilation optimization, more inclined to static syntax and more restrictions in syntax. For dynamic and static graph modes, firstly MindSpore unifies the API expression, uses the same API in both modes, secondly, unifies the underlying differential mechanism of dynamic and static graphs. - -### Interconversion of Dynamic and Static Graphs - -In MindSpore, we can switch the execution between using dynamic or static graphs by controlling the mode input parameters. For example: - -```python -ms.set_context(mode=ms.PYNATIVE_MODE) -``` - -Since there are restrictions on Python syntax under static graphs, switching from dynamic to static graphs requires compliance with the syntax restrictions of static graphs in order to execute correctly by using static graphs. For more syntax restrictions for static graphs, refer to [Static Graph Syntax Restrictions](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -### Combination of Static and Dynamic Graphs - -MindSpore supports mixed execution by using static compilation under dynamic graphs. The function objects that need to be executed with static graphs by using jit modification, and in this way you can achieve mixed execution of dynamic and static graphs. For more use of jit, refer to [jit documentation](https://www.mindspore.cn/tutorials/en/master/beginner/accelerate_with_static_graph.html#decorator-based-startup-method). - -For example: - -```python -import numpy as np -import mindspore as ms -import mindspore.nn as nn - -class AddMulMul(nn.Cell): - def __init__(self): - super(AddMulMul, self).__init__() - self.param = ms.Parameter(ms.Tensor(0.5, ms.float32)) - - @ms.jit - def construct(self, x): - x = x + x - x = x * self.param - x = x * x - return x - -class CellCallSingleCell(nn.Cell): - def __init__(self): - super(CellCallSingleCell, self).__init__() - self.conv = nn.Conv2d(1, 2, kernel_size=2, stride=1, padding=0, weight_init="ones", pad_mode="valid") - self.bn = nn.BatchNorm2d(2, momentum=0.99, eps=0.00001, gamma_init="ones") - self.relu = nn.ReLU() - self.add_mul_mul = AddMulMul() - - def construct(self, x): - x = self.conv(x) - x = self.bn(x) - x = self.add_mul_mul(x) - x = self.relu(x) - return x - -ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") -inputs = ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32)) -net = CellCallSingleCell() -out = net(inputs) -print(out) -``` - -```text -[[[[15.99984]] - - [[15.99984]]]] -``` - -### Static Graph Syntax Enhancement - -In the MindSpore static graph mode, users need to follow MindSpore [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html) when writing programs, and there are constraints on the use of syntax. In dynamic graph mode, Python script code will be executed according to Python syntax, and users can use any Python syntax. It can be seen that the syntax constraints of static and dynamic graphs are different. - -JIT Fallback considers the unification of static and dynamic graphs from the perspective of static graphs. When an unsupported syntax is found during compilation, the syntax is Fallback to the Python interpreter for interpretation execution. Through the JIT Fallback feature, static graphs can support as much dynamic graph syntax as possible, so that static graphs provide a syntax experience close to dynamic graphs, so as to achieve dynamic and static unity. - -In the graph mode scenario, the MindSpore framework will report an error when it encounters unsupported syntax or symbols during graph compilation, mostly in the type inference stage. In the graph compilation stage, the Python source code written by the user is parsed, and then subsequent static analysis, type derivation, optimization and other steps are performed. Therefore, the JIT Fallback feature needs to be pre-detected for unsupported syntax. Common unsupported syntax mainly includes: calling methods of third-party libraries, calling class names to create objects, calling unsupported Python built-in functions, etc. Interpret execution of unsupported syntax Fallback to the Python interpreter. Since the graph mode uses [MindSpore IR (MindIR)](https://www.mindspore.cn/docs/en/master/design/all_scenarios.html#mindspore-ir-mindir), it is necessary to convert the statement executed by the interpretation to the intermediate representation and record the information required by the interpreter. - -The following mainly introduces the static graph syntax supported using the JIT Fallback extension. The default value of the JIT syntax support level option jit_syntax_level is 'LAX', extending the static graph syntax with the ability of JIT Fallback. - -#### Calling the Third-party Libraries - -Complete support for third-party libraries such as NumPy and SciPy. The static graph mode supports many third-party library data types such as np.ndarray and their operation operations, supports obtaining properties and methods that call third-party libraries, and supports interacting with third-party libraries such as NumPy through methods such as Tensor's asnumpy(). In other words, users can call MindSpore's own interface and operator in static graph mode, or directly call the interface of the three-party library, or use them together. - -- Supporting data types of third-party libraries (such as NumPy and SciPy), allowing calling and returning objects of third-party libraries. -- Supporting calling methods of third-party libraries. -- Supporting creating Tensor instances by using the data types of the third-party library NumPy. -- The assignment of subscripts for data types in third-party libraries is not currently supported. - -For more usage, please refer to the [Calling the Third-party Libraries](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#calling-the-third-party-libraries) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -#### Supporting the Use of Custom Classes - -Custom classes that do not use '@jit_class' decorations and do not inherit 'nn. Cell`。 Through the JIT Fallback technical solution, static graph mode allows creating and referencing instances of custom classes, can directly obtain and call properties and methods of custom class instances, and allows modifying properties(Inplace operations). - -For more usage, please refer to the [Supporting the Use of Custom Classes](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#supporting-the-use-of-custom-classes) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -#### Basic Operators Support More Data Types - -In the syntax of graph mode, the following basic operators in the list are overloaded: ['+', '-', '*', '/', '//', '%', '**', '<<', '>>', '&', '|', '^', 'not', '==', '!=', '<', '>', '<=', '>=', 'in', 'not in', 'y=x[0]']. For more details, please refer to [Operators](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/operators.html). When getting unsupported input type, those operators need to use extended static graph syntax to support, and make the output consistent with the output in the pynative mode. - -For more usage, please refer to the [Basic Operators Support More Data Type](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#basic-operators-support-more-data-type) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -#### Base Type - -Use the JIT Fallback feature to extend support for Python's native data types 'List', 'Dictionary', 'None'. For more usage, please refer to the [Base Type](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#base-type) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -##### Supporting List Inplace Modification Operations - -- Support for getting the original `List` object from a global variable. -- Inplace operations on input `List` objects are not supported. -- Support for in-place modification of some `List` built-in functions. - -##### Supporting the High-Level Usage of Dictionary - -- Supporting Top Graph Return Dictionary. -- Supporting Dictionary Index Value Retrieval and Assignment. - -##### Supporting the Usage of None - -`None` is a special value in Python that represents null and can be assigned to any variable. Functions that do not have a return value statement are considered to return `None`. At the same time, `None` is also supported as the input parameter or return value of the top graph or subgraph. Support `None` as a subscript of a slice as input to `List`, `Tuple`, `Dictionary`. - -#### Built-in Functions Support More Data Types - -Extend the support for built-in functions. Python built-in functions perfectly support more input types, such as third-party library data types. More support for built-in functions can be found in the [Python built-in functions](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/python_builtin_functions.html) section. - -#### Supporting Control Flow - -In order to improve the support of Python standard syntax, realize dynamic and static unification, and extend the support for more data types in the use of control flow statements. Control flow statements refer to flow control statements such as 'if', 'for', and 'while'. Theoretically, by extending the supported syntax, it is also supported in control flow scenarios. For more usage, please refer to [Supporting Control Flow](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#supporting-control-flow) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -#### Supporting Property Setting and Modification - -More types of inplace operations are supported. The previous version only supported value modification of the Parameter type through the Inplace operator, and in the static graph mode of MindSpore version 2.1, the properties of custom classes, Cell subclasses, and jit_class classes were supported. In addition to supporting changing the properties of class self and global variables, it also supports inplace operations such as extend(), reverse(), insert(), pop() of the List type. For more usage, please refer to the [Supporting Property Setting and Modification](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#supporting-property-setting-and-modification) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -- Set and modify properties of custom class objects and third-party types. -- Make changes to the Cell's self object. -- Set and modify Cell objects and jit_class objects in the static graph. - -#### Supporting Derivation - -The static graph syntax supported by JIT Fallback also supports its use in derivation. For more usage, please refer to the [Supporting Derivation](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#supporting-derivation) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -#### Annotation Type - -For the syntax supported by the runtime extensions, nodes are generated that cannot be derived by type and are called `Any` types. Since the type cannot derive the correct type at compile time, this `Any` will be operated with a default maximum precision 'Float64' to prevent loss of precision. To optimize performance, it is recommended to minimize the generation of `Any` types. When the user knows exactly what type of statement will be generated through the extension, it is recommended to use `Annotation @jit.typing:` to specify the corresponding Python statement type, thereby determining the type of the interpretation node and avoiding the generation of `Any` types. For more usage, please refer to the [Annotation Type](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#annotation-type) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). - -#### Instructions for Use - -When using the static graph extension support syntax, note the following points: - -1. In order to match the support capability of the dynamic graph. That is, it must be within the scope of dynamic graph syntax, including but not limited to data types. - -2. When extending the static graph syntax, more syntax is supported, but the execution performance may be affected and is not optimal. - -3. When extending the static graph syntax, more syntax is supported, and the ability to import and export cannot be used with MindIR due to use Python. - -4. It is not currently supported that the repeated definition of global variables with the same name across Python files, and these global variables are used in the network. - -### Conversion Technique from Dynamic Graph to Static Graph - -MindSpore provides PIJit, a feature that directly converts a user's dynamic graph code into a static graph without code changes. This feature balances performance and ease of use, removes the cost of switching between static and dynamic modes, and truly unifies static and dynamic modes. It is based on the analysis of Python bytecode, and captures the execution flow of Python graphs. Subgraphs that can be run as static graphs are run as static graphs, and subgraphs that are not supported by Python syntax are run as dynamic graphs, and at the same time, by modifying and adjusting the bytecode to link the static graphs, it achieves the mixed execution of static and dynamic modes. In order to meet the premise of ease of use, improve performance. - -#### PIJit Includes the Following Features - -- 1. Graph Capture: Pre-processing of bytecode, dynamically tracking the execution of the interpretation, recognizing MindSpore accessible graph operations, and providing split graph to ensure the correctness of function (bytecode) functionality. -- 2. Bytecode Support: Currently supports Python 3.7, Python 3.8, Python 3.9 and Python 3.10 version bytecode. -- 3. Graph Optimization: Optimize the bytecode generated in the graph, including branch cropping, bytecode filtering, function bytecode inlining, constant folding and other functions. -- 4. Exception Capture Mechanism: support for with, try-except syntax. -- 5. Support loop processing: implement features such as graph capture and split graph by simulating the operation stack of bytecode. -- 6. UD Analysis: The method of user-def chain analysis of variables solves the problem that some parameter types cannot be used as the return value of static graphs (Function, Bool, None), and reduces the useless parameters, improves the execution efficiency of the graphs, and reduces the copying of data. -- 7. Side effect analysis and processing: to make up for the disadvantage of side effect processing of static graphs. According to different scenarios, collect and record the variables and byte codes that generate side effects, and supplement the processing of side effects outside the static graphs on the basis of guaranteeing the semantics of the program. -- 8. Guard: The Guard records the conditions that need to be met by the inputs for the subgraph/optimization to enter, and checks if the inputs are suitable for the corresponding subgraph optimization. -- 9. Cache:The graph management caches the subgraph/optimization and Guard correspondences. -- 10. Dynamic Shape and Symbolic Shape: Use input_signature to support Dynamic Shape and Symbolic Shape for Tensor/Tensor List/Tensor Tuple as input prompts. Simultaneously supports automatic recognition of Dynamic Shape after multiple runs. -- 11. Compiling by trace: Supports operator and other type derivations during tracking and bytecode analysis processes. -- 12. Automatic mixed precision: Supports the automatic mixed precision capability of the native mindspore.nn.Cell. - -#### Usage - -def jit(fn=None, input_signature=None, hash_args=None, jit_config=None, mode="PIJit"): - -The original Jit function uses mode="PSJit", the new feature PIJit uses mode="PIJit", jit_config passes a dictionary of parameters that can provide some optimization and debugging options. For example: print_after_all can print the bytecode of the graph and split graph information, loop_unrolling can provide loop unrolling function, enable_dynamic_shape apply dynamic shape. - -#### Limitations - -- It is not supported to run a function with decoration @jit(mode=\"PIJit\") in static graph mode, in which case the decoration @jit(mode=\"PIJit\") is considered invalid. -- Calls to functions with decoration @jit(mode=\"PIJit\") inside functions decorated with @jit(mode=\"PIJit\") are not supported, and the decorated @jit(mode=\"PIJit\") is considered invalid. \ No newline at end of file +In the PyNative mode, scripts are executed according to the Python syntax, so in MindSpore, there is no special treatment for the control flow syntax, which is directly expanded and executed according to the Python syntax, and automatic differentiation is performed on the expanded execution operator. For example, for a for loop, the statements in the for loop are continuously executed under PyNative and automatic differentiation is performed on the operators according to the specific number of loops. \ No newline at end of file diff --git a/docs/mindspore/source_en/design/index.rst b/docs/mindspore/source_en/design/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..77f5eec977b8314f32b7f14a27cb5f35cc4b2d1b --- /dev/null +++ b/docs/mindspore/source_en/design/index.rst @@ -0,0 +1,18 @@ +Design Concept +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + tensor_view + programming_paradigm + dynamic_graph_and_static_graph + distributed_training_design + data_engine + all_scenarios + graph_fusion_engine + pluggable_device + official_models + glossary diff --git a/docs/mindspore/source_en/note/official_models.md b/docs/mindspore/source_en/design/official_models.md similarity index 99% rename from docs/mindspore/source_en/note/official_models.md rename to docs/mindspore/source_en/design/official_models.md index b450394111538940c2d9e8d0ed70d9e0d44d6a84..73d830b0a5dbe3822500814fd90f6c6d2abbc914 100644 --- a/docs/mindspore/source_en/note/official_models.md +++ b/docs/mindspore/source_en/design/official_models.md @@ -1,6 +1,6 @@ # Official Models -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/official_models.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/design/official_models.md) ## Domain Suite and Extension Packages @@ -334,4 +334,4 @@ | Computational Fluid Dynamics | [PDE-Net](https://arxiv.org/abs/1710.09668) | [Link](https://gitee.com/mindspore/mindscience/blob/master/MindFlow/applications/data_mechanism_fusion/pde_net/README.md#) | ✅ | ✅ | | Computational Fluid Dynamics | [hfm](https://www.science.org/doi/abs/10.1126/science.aaw4741) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/hfm/README.md) | ✅ | ✅ | | Computational Fluid Dynamics | [label_free_dnn_surrogate](https://www.sciencedirect.com/science/article/pii/S004578251930622X) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/label_free_dnn_surrogate/README.md) | ✅ | ✅ | -| Computational Fluid Dynamics | [nsf_nets](https://www.sciencedirect.com/science/article/pii/S0021999120307257) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/nsf_nets/README.md) | ✅ | ✅ | +| Computational Fluid Dynamics | [nsf_nets](https://www.sciencedirect.com/science/article/pii/S0021999120307257) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/nsf_nets/README.md) | ✅ | ✅ | \ No newline at end of file diff --git a/docs/mindspore/source_en/faq/data_processing.md b/docs/mindspore/source_en/faq/data_processing.md index abf788e9b84a60f48f47f4098515f3040e6641cd..206e4b97b365f682f93d009d9d8fdfbd9262c264 100644 --- a/docs/mindspore/source_en/faq/data_processing.md +++ b/docs/mindspore/source_en/faq/data_processing.md @@ -38,7 +38,7 @@ A: You can refer to the following steps to reduce CPU consumption (mainly due to ## Q:  Why there is no difference between the parameter `shuffle` in `GeneratorDataset`, and `shuffle=True` and `shuffle=False` when the task is run? -A: If `shuffle` is enabled, the input `Dataset` must support random access (for example, the user-defined `Dataset` has the `getitem` method). If data is returned in `yeild` mode in the user-defined `Dataset`, random access is not supported. For details, see section [Loading Dataset Overview](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html) in the tutorial. +A: If `shuffle` is enabled, the input `Dataset` must support random access (for example, the user-defined `Dataset` has the `getitem` method). If data is returned in `yeild` mode in the user-defined `Dataset`, random access is not supported. For details, see section [GeneratorDataset example](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html).
    @@ -160,9 +160,7 @@ A: You can refer to the usage of YOLOv3 which contains the resizing of different A: [build_seg_data.py](https://gitee.com/mindspore/models/blob/master/research/cv/FCN8s/src/data/build_seg_data.py) is the script of MindRecords generated by the dataset. You can directly use or adapt it to your dataset. Alternatively, you can use `GeneratorDataset` to customize the dataset loading if you want to implement the dataset reading by yourself. -[GenratorDataset example](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html) - -[GeneratorDataset API description](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html#mindspore.dataset.GeneratorDataset) +[GeneratorDataset example](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html)
    @@ -191,7 +189,7 @@ ds.GeneratorDataset(..., num_shards=8, shard_id=7, ...) A: The data schema can be defined as follows:`cv_schema_json = {"label": {"type": "int32", "shape": [-1]}, "data": {"type": "bytes"}}` Note: A label is an array of the numpy type, where label values 1, 1, 0, 1, 0, 1 are stored. These label values correspond to the same data, that is, the binary value of the same image. -For details, see [Converting Dataset to MindRecord](https://www.mindspore.cn/tutorials/en/master/advanced/dataset/record.html#converting-dataset-to-mindrecord). +For details, see [Converting Dataset to MindRecord](https://www.mindspore.cn/docs/en/master/model_train/dataset/record.html#Converting-Dataset-to-Record-Format).
    @@ -203,7 +201,7 @@ A: The MNIST gray scale image dataset is used for MindSpore training. Therefore, ## Q: Can you introduce the data processing framework in MindSpore? -A: MindSpore Dataset module makes it easy for users to define data preprocessing pipelines and transform samples efficiently with multiprocessing or multithreading. MindSpore Dataset also provides variable APIs for users to load and process datasets, more introduction please refer to [MindSpore Dataset](https://mindspore.cn/docs/en/master/api_python/mindspore.dataset.html#introduction-to-data-processing-pipeline). If you want to further study the performance optimization of dataset pipeline, please read [Optimizing Data Processing](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html). +A: MindSpore Dataset module makes it easy for users to define data preprocessing pipelines and transform samples efficiently with multiprocessing or multithreading. MindSpore Dataset also provides variable APIs for users to load and process datasets, more introduction please refer to [MindSpore Dataset](https://mindspore.cn/docs/en/master/api_python/mindspore.dataset.html#introduction-to-data-processing-pipeline). If you want to further study the performance optimization of dataset pipeline, please read [Optimizing Data Processing](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html).
    @@ -314,7 +312,7 @@ dataset3 = dataset2.map(***) ## Q: What is the API corresponding to DataLoader in MindSpore? -A: If the DataLoader is considered as an API for receiving user-defined datasets, the GeneratorDataset in the MindSpore data processing API is similar to that in the DataLoader and can receive user-defined datasets. For details about how to use the GeneratorDataset, see the [Loading Dataset Overview](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html), and for details about the differences, see the [API Mapping](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html). +A: If the DataLoader is considered as an API for receiving user-defined datasets, the GeneratorDataset in the MindSpore data processing API is similar to that in the DataLoader and can receive user-defined datasets. For details about how to use the GeneratorDataset, see the [GeneratorDataset example](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html), and for details about the differences, see the [API Mapping](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html).
    @@ -500,7 +498,7 @@ A: When using the data sinking mode (where `data preprocessing` -> `sending queu 2022-05-09-11:36:01.893.412 -> 2022-05-09-11:36:02.006.771 ``` - Improvement method: View the time difference between the last item of `push_end_time` and GetNext error reporting time. If the default GetNext timeout is exceeded (default: 1900s, and can be modified through `mindspore.set_context(op_timeout=xx)`), it indicates poor data preprocessing performance. Please refer to [Optimizing the Data Processing](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html) to improve data preprocessing performance. + Improvement method: View the time difference between the last item of `push_end_time` and GetNext error reporting time. If the default GetNext timeout is exceeded (default: 1900s, and can be modified through `mindspore.set_context(op_timeout=xx)`), it indicates poor data preprocessing performance. Please refer to [Optimizing the Data Processing](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html) to improve data preprocessing performance. 4. When the log output is similar to the following, it indicates that data preprocessing has generated 182 batches of data and the 183st batch of data is being sent to the device. And the `device_queue` shows that there is sufficient data cache on the device side. @@ -550,7 +548,7 @@ A: When using the data sinking mode (where `data preprocessing` -> `sending queu 2022-05-09-14:31:04.064.571 -> ``` - Improvement method: Please refer to [Optimizing the Data Processing](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html) to improve data preprocessing performance. + Improvement method: Please refer to [Optimizing the Data Processing](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html) to improve data preprocessing performance.
    diff --git a/docs/mindspore/source_en/faq/distributed_parallel.md b/docs/mindspore/source_en/faq/distributed_parallel.md index 92f2b4c8459fb55a447fa0d0c63dd2c7c7ba7081..5bedba494b3da30c7b6b69c42d6d409c11989763 100644 --- a/docs/mindspore/source_en/faq/distributed_parallel.md +++ b/docs/mindspore/source_en/faq/distributed_parallel.md @@ -49,7 +49,7 @@ Solution: Manually `kill` the training process and then restart the training tas [CRITICAL] DISTRIBUTED [mindspore/ccsrc/distributed/cluster/cluster_context.cc:130] InitNodeRole] Role name is invalid... ``` -A: In the case where the user does not start the process using `mpirun` but still calls the `init()` method, MindSpore requires the user to configure several environment variables and verify according to training and [dynamic cluster startup methods](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html). If without configuring, MindSpore may display the above error message. Therefore, it is suggested that only when performing distributed training, `mindspore.communication.init` is called, and in the case of not using `mpirun`, it is configured the correct environment variables according to the documentation to start distributed training. +A: In the case where the user does not start the process using `mpirun` but still calls the `init()` method, MindSpore requires the user to configure several environment variables and verify according to training and [dynamic cluster startup methods](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html). If without configuring, MindSpore may display the above error message. Therefore, it is suggested that only when performing distributed training, `mindspore.communication.init` is called, and in the case of not using `mpirun`, it is configured the correct environment variables according to the documentation to start distributed training.
    diff --git a/docs/mindspore/source_en/faq/feature_advice.md b/docs/mindspore/source_en/faq/feature_advice.md index 66c248511afcfdf50e4a89b75cadbd7564452a24..2b660b7f1b96cb0556fced3cbf5938ae4d657dcd 100644 --- a/docs/mindspore/source_en/faq/feature_advice.md +++ b/docs/mindspore/source_en/faq/feature_advice.md @@ -50,7 +50,7 @@ A: The formats of `ckpt` of MindSpore and `ckpt`of TensorFlow are not generic. ## Q: How do I use models trained by MindSpore on Atlas 200/300/500 inference product? Can they be converted to models used by HiLens Kit? -A: Yes. HiLens Kit uses Atlas 200/300/500 inference product as the inference core. Therefore, the two questions are essentially the same, which both need to convert as OM model. Atlas 200/300/500 inference product requires a dedicated OM model. Use MindSpore to export the ONNX and convert it into an OM model supported by Atlas 200/300/500 inference product. For details, see [Multi-platform Inference](https://www.mindspore.cn/tutorials/experts/en/master/infer/inference.html). +A: Yes. HiLens Kit uses Atlas 200/300/500 inference product as the inference core. Therefore, the two questions are essentially the same, which both need to convert as OM model. Atlas 200/300/500 inference product requires a dedicated OM model. Use MindSpore to export the ONNX and convert it into an OM model supported by Atlas 200/300/500 inference product. For details, see [Multi-platform Inference](https://www.mindspore.cn/docs/en/master/model_infer/overview.html).
    diff --git a/docs/mindspore/source_en/faq/implement_problem.md b/docs/mindspore/source_en/faq/implement_problem.md index 3773da55ae7c89bd053abb9109539aa472465a37..1d6c86e949ac8c3a60ccce393e432410938f5311 100644 --- a/docs/mindspore/source_en/faq/implement_problem.md +++ b/docs/mindspore/source_en/faq/implement_problem.md @@ -243,7 +243,7 @@ print(network.layers) ## Q: When MindSpore is used for model training, there are four input parameters for `CTCLoss`: `inputs`, `labels_indices`, `labels_values`, and `sequence_length`. How do I use `CTCLoss` for model training? -A: The `dataset` received by the defined `model.train` API can consist of multiple pieces of data, for example, (`data1`, `data2`, `data3`, ...). Therefore, the `dataset` can contain `inputs`, `labels_indices`, `labels_values`, and `sequence_length` information. You only need to define the dataset in the corresponding format and transfer it to `model.train`. For details, see [Data Processing API](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html). +A: The `dataset` received by the defined `model.train` API can consist of multiple pieces of data, for example, (`data1`, `data2`, `data3`, ...). Therefore, the `dataset` can contain `inputs`, `labels_indices`, `labels_values`, and `sequence_length` information. You only need to define the dataset in the corresponding format and transfer it to `model.train`. For details, see [Data Processing API](https://www.mindspore.cn/docs/en/master/model_train/index.html).
    diff --git a/docs/mindspore/source_en/faq/index.rst b/docs/mindspore/source_en/faq/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..28cebf75fdf7ce3972e1d9ce88c564e7737a0dd8 --- /dev/null +++ b/docs/mindspore/source_en/faq/index.rst @@ -0,0 +1,17 @@ +FAQ +======== + +.. toctree:: + :glob: + :maxdepth: 1 + + installation + data_processing + implement_problem + network_compilation + operators_compile + performance_tuning + precision_tuning + distributed_parallel + inference + feature_advice diff --git a/docs/mindspore/source_en/faq/network_compilation.md b/docs/mindspore/source_en/faq/network_compilation.md index 0ff52e0e592b2ea50dedfb40a54e88150933263d..248d677c4380d310ce46332e08472fe2a80304b4 100644 --- a/docs/mindspore/source_en/faq/network_compilation.md +++ b/docs/mindspore/source_en/faq/network_compilation.md @@ -4,7 +4,7 @@ ## Q: What is the set of syntaxes supported by static graph mode? -A: Static graph mode can support a subset of common Python syntax to support the construction and training of neural networks. Some Python syntax is not supported yet. For more detailed supported syntax set, please refer to [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). In order to facilitate users to choose whether to extend the static graph syntax, the static graph mode provides JIT syntax support level options. For some network scenarios, it is recommended to use basic syntax (nn/ops, etc.) rather than extended syntax (such as numpy third-party library). In addition, it is recommended to use [Advanced Programming Techniques with Static Graphs](https://www.mindspore.cn/tutorials/en/master/advanced/static_graph_expert_programming.html) to optimize compilation performance. +A: Static graph mode can support a subset of common Python syntax to support the construction and training of neural networks. Some Python syntax is not supported yet. For more detailed supported syntax set, please refer to [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). In order to facilitate users to choose whether to extend the static graph syntax, the static graph mode provides JIT syntax support level options. For some network scenarios, it is recommended to use basic syntax (nn/ops, etc.) rather than extended syntax (such as numpy third-party library). In addition, it is recommended to use [Advanced Programming Techniques with Static Graphs](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html) to optimize compilation performance.
    @@ -531,7 +531,7 @@ net = Net() out = net(Tensor(x)) ``` -3) If a function decorated with a @jit decorator is called in a custom class, an error will be reported. In this scenario, it is recommended to add @jit_class decorators to custom classes in the network and avoid the JIT Fallback feature. For more use of custom classes, please refer to [Supporting the Use of Custom Classes](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#supporting-the-use-of-custom-classes). The use of jit_class decorators can be referred to [Use jit_class](https://www.mindspore.cn/tutorials/en/master/advanced/static_graph_expert_programming.html#using-jit-class). +3) If a function decorated with a @jit decorator is called in a custom class, an error will be reported. In this scenario, it is recommended to add @jit_class decorators to custom classes in the network and avoid the JIT Fallback feature. For more use of custom classes, please refer to [Supporting the Use of Custom Classes](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#supporting-the-use-of-custom-classes). The use of jit_class decorators can be referred to [Use jit_class](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html#using-jit-class). ```python import mindspore as ms @@ -772,7 +772,7 @@ A: The following scenarios will trigger recompilation: ## Q: How to determine how many graphs there are in static graph mode? When will the subgraph be divided? What is the impact of multiple subgraphs? How to avoid multiple subgraphs? -A: 1. The number of subgraphs can be obtained by viewing the IR file and searching for "Total subgraphs". For how to view and analyze IR files, please refer to [MindSpore IR Introduction](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/mindir.html) +A: 1. The number of subgraphs can be obtained by viewing the IR file and searching for "Total subgraphs". For how to view and analyze IR files, please refer to [MindSpore IR Introduction](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindir.html) 2. Subgraph segmentation in static graph mode is common in control flow scenarios, such as if/while. In addition to manual writing by users, the control flow syntax within the MindSpore may also lead to dividing into multiple subgraphs. diff --git a/docs/mindspore/source_en/faq/operators_compile.md b/docs/mindspore/source_en/faq/operators_compile.md index fc46055f9880a101b8e88d6bb5c85f0569dd9dae..b7c594c546cf5606c8b10fca710fa5e83074e288 100644 --- a/docs/mindspore/source_en/faq/operators_compile.md +++ b/docs/mindspore/source_en/faq/operators_compile.md @@ -59,7 +59,7 @@ In MindSpore, you can manually initialize the weight corresponding to the `paddi ## Q: When the `Tile` operator in operations executes `__infer__`, the `value` is `None`. Why is the value lost? -A: The `multiples input` of the `Tile` operator must be a constant (The value cannot directly or indirectly come from the input of the graph). Otherwise, the `None` data will be obtained during graph composition because the graph input is transferred only during graph execution and the input data cannot be obtained during graph composition. For the detailed imformation, refer to [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). +A: The `multiples input` of the `Tile` operator must be a constant (The value cannot directly or indirectly come from the input of the graph). Otherwise, the `None` data will be obtained during graph composition because the graph input is transferred only during graph execution and the input data cannot be obtained during graph composition. For the detailed imformation, refer to [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html).
    @@ -71,7 +71,7 @@ A: TBE (Tensor Boost Engine) operator is Huawei's self-developed Ascend operator ## Q: Has MindSpore implemented the anti-pooling operation similar to `nn.MaxUnpool2d`? -A: Currently, MindSpore does not provide anti-pooling APIs but you can customize the operator to implement the operation. For details, refer to [Customize Operators](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom.html). +A: Currently, MindSpore does not provide anti-pooling APIs but you can customize the operator to implement the operation. For details, refer to [Customize Operators](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom.html).
    diff --git a/docs/mindspore/source_en/index.rst b/docs/mindspore/source_en/index.rst index d72e6fb6ad1329cc3629963dab27ce21d3fc3354..68151e237a658cd21b391aa716fc39d84e1ea33f 100644 --- a/docs/mindspore/source_en/index.rst +++ b/docs/mindspore/source_en/index.rst @@ -1,270 +1,16 @@ -.. MindSpore documentation master file, created by - sphinx-quickstart on Thu Mar 24 11:00:00 2022. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - MindSpore Documentation ======================= .. toctree:: :glob: :maxdepth: 1 - :caption: Design - :hidden: - - design/overview - design/tensor_view - design/programming_paradigm - design/dynamic_graph_and_static_graph - design/dynamic_shape - design/distributed_training_design - design/data_engine - design/all_scenarios - design/graph_fusion_engine - design/pluggable_device - design/glossary - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: Models - :hidden: - - note/official_models - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: API - :hidden: - - api_python/mindspore - api_python/mindspore.nn - api_python/mindspore.ops - api_python/mindspore.ops.primitive - api_python/mindspore.mint - api_python/mindspore.amp - api_python/mindspore.train - api_python/mindspore.communication - api_python/mindspore.communication.comm_func - api_python/mindspore.common.initializer - api_python/mindspore.hal - api_python/mindspore.dataset - api_python/mindspore.dataset.transforms - api_python/mindspore.mindrecord - api_python/mindspore.nn.probability - api_python/mindspore.rewrite - api_python/mindspore.multiprocessing - api_python/mindspore.boost - api_python/mindspore.numpy - api_python/mindspore.scipy - api_python/mindspore.experimental - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: API Mapping - :hidden: - - note/api_mapping/pytorch_api_mapping - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: Migration Guide - :titlesonly: - :hidden: - - migration_guide/overview - migration_guide/enveriment_preparation - migration_guide/analysis_and_preparation - migration_guide/model_development/model_development - migration_guide/debug_and_tune - migration_guide/sample_code - migration_guide/faq - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: Syntax Support - :hidden: - - note/static_graph_syntax_support - note/static_graph_syntax/operators - note/static_graph_syntax/statements - note/static_graph_syntax/python_builtin_functions - note/index_support - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: Environment Variables - :hidden: - - note/env_var_list - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: FAQ - :hidden: - - faq/installation - faq/data_processing - faq/implement_problem - faq/network_compilation - faq/operators_compile - faq/performance_tuning - faq/precision_tuning - faq/distributed_parallel - faq/inference - faq/feature_advice - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: RELEASE NOTES - :hidden: + design/index + model_train/index + model_infer/index + migration_guide/index + mindformers/index + api_python/index + orange_pi/index + faq/index RELEASE - -.. raw:: html - - diff --git a/docs/mindspore/source_en/migration_guide/analysis_and_preparation.md b/docs/mindspore/source_en/migration_guide/analysis_and_preparation.md index 79b93fc50479ab98317dc525fa414efaa7fd5a53..7ef56ee49fbbfb94733a5eae6503ec7edf48c59a 100644 --- a/docs/mindspore/source_en/migration_guide/analysis_and_preparation.md +++ b/docs/mindspore/source_en/migration_guide/analysis_and_preparation.md @@ -99,11 +99,11 @@ See [TroubleShooter application scenarios](https://gitee.com/mindspore/toolkits/ MindSpore provides Dump function, used to model training in the graph and operator input and output data saved to disk files, generally used for network migration complex problem location (eg: operator overflow, etc). It can be dumped out of the operator level data. -For getting Dump data, refer to: [Synchronous Dump Step](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html#synchronous-dump-step) and [Asynchronous Dump Step](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html#asynchronous-dump-step). +For getting Dump data, refer to: [Synchronous Dump Step](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html#dump-step) and [Asynchronous Dump Step](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html##dump-step-1). -For analyzig Dump data, refer to: [Synchronous Dump Data Analysis Sample](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html#synchronous-dump-data-analysis-sample) and [Asynchronous Dump Data Analysis Sample](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html#asynchronous-dump-data-analysis-sample) +For analyzig Dump data, refer to: [Synchronous Dump Data Analysis Sample](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html#data-analysis-sample) and [Asynchronous Dump Data Analysis Sample](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html#data-analysis-sample-1) -See [Dump](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html) for details. +See [Dump](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html) for details. ### Performance Issues @@ -133,7 +133,7 @@ Currently, there are two execution modes of a mainstream deep learning framework - In dynamic graph mode, the program is executed line by line according to the code writing sequence. In the forward execution process, the backward execution graph is dynamically generated according to the backward propagation principle. In this mode, the compiler delivers the operators in the neural network to the device one by one for computing, facilitating users to build and debug the neural network model. -### [Calling the Custom Class](https://www.mindspore.cn/tutorials/en/master/advanced/static_graph_expert_programming.html#using-jit-class) +### [Calling the Custom Class](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html#using-jit-class) In static graph mode, you can use `jit_class` to modify a custom class. You can create and call an instance of the custom class, and obtain its attributes and methods. @@ -143,15 +143,15 @@ In static graph mode, you can use `jit_class` to modify a custom class. You can Automatic differentiation can calculate a derivative value of a derivative function at a certain point, which is a generalization of backward propagation algorithms. The main problem solved by automatic differential is to decompose a complex mathematical operation into a series of simple basic operations. This function shields a large number of derivative details and processes from users, greatly reducing the threshold for using the framework. -### [Mixed Precision](https://www.mindspore.cn/tutorials/en/master/advanced/mixed_precision.html) +### [Mixed Precision](https://www.mindspore.cn/tutorials/en/master/beginner/mixed_precision.html) Generally, when a neural network model is trained, the default data type is FP32. In recent years, to accelerate training time, reduce memory occupied during network training, and store a trained model with same precision, more and more mixed-precision training methods are proposed in the industry. The mixed-precision training herein means that both single precision (FP32) and half precision (FP16) are used in a training process. -### [Auto Augmentation](https://www.mindspore.cn/tutorials/experts/en/master/dataset/augment.html) +### [Auto Augmentation](https://www.mindspore.cn/docs/en/master/model_train/dataset/augment.html) MindSpore not only allows you to customize data augmentation, but also provides an automatic data augmentation mode to automatically perform data augmentation on images based on specific policies. -### [Gradient Accumulation](https://www.mindspore.cn/tutorials/experts/en/master/optimize/gradient_accumulation.html) +### [Gradient Accumulation](https://www.mindspore.cn/docs/en/master/model_train/train_process/optimize/gradient_accumulation.html) Gradient accumulation is a method of splitting data samples for training neural networks into several small batches by batch and then calculating the batches in sequence. The purpose is to solve the out of memory (OOM) problem that the neural network cannot be trained or the network model cannot be loaded due to insufficient memory. diff --git a/docs/mindspore/source_en/migration_guide/debug_and_tune.md b/docs/mindspore/source_en/migration_guide/debug_and_tune.md index a29a3307870f30e597b877442df1ceabc3c1ff86..97a2550d804b94996971c8ac74729346f768f349 100644 --- a/docs/mindspore/source_en/migration_guide/debug_and_tune.md +++ b/docs/mindspore/source_en/migration_guide/debug_and_tune.md @@ -1,8 +1,8 @@ -# Debugging and Tuning +# Debug and Tune [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/migration_guide/debug_and_tune.md) -## Debugging Tools +## FAQs and Solutions - The following common problems may be encountered during the accuracy commissioning phase: - The first loss and the benchmark are not aligned: @@ -11,16 +11,8 @@ The problem is mainly caused by the network reverse. This can be done with the help of [TroubleShooter comparing MindSpore to PyTorch ckpt/pth](https://gitee.com/mindspore/toolkits/blob/master/troubleshooter/docs/migrator.md#%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF2%E6%AF%94%E5%AF%B9mindspore%E4%B8%8Epytorch%E7%9A%84ckptpth) to check the results of the network reverse update by comparing the values of the corresponding parameters of ckpt and pth. - Loss appears NAN/INF: [TroubleShooter obtains INF/NAN value throw points](https://gitee.com/mindspore/toolkits/blob/master/troubleshooter/docs/tracker.md#%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF2%E8%8E%B7%E5%8F%96infnan%E5%80%BC%E6%8A%9B%E5%87%BA%E7%82%B9) is used to identify the first location in the network where a NAN or INF appears. - Overflow operator detection is also available via the [Dump](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html) tool. -- The following common problems may be encountered during the performance debugging phase: - - The first step is time-consuming - This phase mainly completes operations such as graph conversion, graph fusion, graph optimization, etc, which is the process of generating executable models. Refer to [How to Optimize Compilation Performance](https://www.mindspore.cn/tutorials/en/master/advanced/static_graph_expert_programming.html#how-to-optimize-compilation-performance). - - Iteration gap is time-consuming - Most of the time consumption in this phase comes from data acquisition, see [Data Processing Performance Optimization](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html). - - Forward and reverse computation is time-consuming - This phase mainly executes the forward and reverse operators in the network and carries the main computational work of an iteration. Information such as operator time consumption during training can be recorded to a file via [Profiler](https://www.mindspore.cn/mindinsight/docs/en/master/performance_profiling.html). The performance data provides the performance data of the framework host execution and operator execution, which can also be viewed and analyzed by users through the [MindInsight](https://www.mindspore.cn/mindinsight/docs/en/master/index.html) visualization interface, helping users to debug neural network performance more efficiently. - - Iteration trailing is time-consuming - This phase is time consuming, which may be caused by the collection communication, and you can set the fusion policy to optimize. Refer to [all_reduce_fusion_config set allreduce fusion policy](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.set_auto_parallel_context.html). + Overflow operator detection is also available via the [Dump](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html) tool. + - The following common problems may be encountered during the graphics debugging phase: - Malloc device memory failed: MindSpore failed to request memory on the device side, the original memory is that the device is occupied by other processes, you can check the running processes by ps -ef | grep "python". @@ -32,9 +24,9 @@ ### Function Debugging During network migration, you are advised to use the PyNative mode for debugging. In PyNative mode, you can perform debugging, and log printing is user-friendly. After the debugging is complete, the graph mode is used. The graph mode is more user-friendly in execution performance. You can also find some problems in network compilation. For example, gradient truncation caused by third-party operators. -For details, see [Error Analysis](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/error_scenario_analysis.html). +For details, see [Error Analysis](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/error_scenario_analysis.html). -### Accuracy Debugging +### Precision Tuning The accuracy debugging process is as follows: @@ -201,7 +193,7 @@ After the inference verification is complete, the basic model, data processing, model = Model(network=train_net) ``` -- Check whether overflow occurs. When loss scale is added, overflow detection is added by default to monitor the overflow result. If overflow occurs continuously, you are advised to use the [dump data](https://mindspore.cn/tutorials/experts/en/master/debug/dump.html) of MindSpore Insight to check why overflow occurs. +- Check whether overflow occurs. When loss scale is added, overflow detection is added by default to monitor the overflow result. If overflow occurs continuously, you are advised to use the [dump data](https://mindspore.cn/docs/en/master/model_train/debug/dump.html) of MindSpore Insight to check why overflow occurs. ```python import numpy as np @@ -290,7 +282,7 @@ If you find an operator with poor performance, you are advised to contact [MindS The mixed precision training method accelerates the deep neural network training process by mixing the single-precision floating-point data format and the half-precision floating-point data format without compromising the network accuracy. Mixed precision training can accelerate the computing process, reduce memory usage and retrieval, and enable a larger model or batch size to be trained on specific hardware. - For details, see [Mixed Precision Tutorial](https://www.mindspore.cn/tutorials/en/master/advanced/mixed_precision.html). + For details, see [Mixed Precision Tutorial](https://www.mindspore.cn/tutorials/en/master/beginner/mixed_precision.html). - Enabling Graph Kernel Fusion @@ -343,4 +335,4 @@ When the data processing speed is slow, the empty queue is gradually consumed fr For details about data performance problems, see [Data Preparation Performance Analysis](https://www.mindspore.cn/mindinsight/docs/en/master/performance_profiling_ascend.html#data-preparation-performance-analysis) of MindSpore Insight. This describes common data performance problems and solutions. -For more performance debugging methods, see [Performance Optimization](https://www.mindspore.cn/tutorials/experts/en/master/optimize/execution_opt.html). +For more performance debugging methods, see [Performance Optimization](https://www.mindspore.cn/docs/en/master/model_train/train_process/train_optimize.html). diff --git a/docs/mindspore/source_en/migration_guide/faq.rst b/docs/mindspore/source_en/migration_guide/faq.rst index 7589232697060f10f8a8fc1b4113e0df60c9a5f2..8b67f12c1c72fa80fad69469967f6a6a8a27cd86 100644 --- a/docs/mindspore/source_en/migration_guide/faq.rst +++ b/docs/mindspore/source_en/migration_guide/faq.rst @@ -67,35 +67,35 @@ MindSpore provides a `FAQ `_ . + A: Observe the error stack information and locate the error code block from the error stack information, add a print or debugging point near the block of code where the error occurred, to further debugging. For details, please refer to `Data Processing Debugging Method 1 `_ . **Q: How to test the each data processing operator in the map operation if data-enhanced map operation error is reported?** - A: Map operation can be debugged through the execution of individual operators or through data pipeline debugging mode. For details, please refer to `Data Processing Debugging Method 2 `_ . + A: Map operation can be debugged through the execution of individual operators or through data pipeline debugging mode. For details, please refer to `Data Processing Debugging Method 2 `_ . **Q: While training, we will get very many WARNINGs suggesting that our dataset performance is slow, how should we handle this?** - A: It is possible to iterate through the dataset individually and see the processing time for each piece of data to determine how well the dataset is performing. For details, please refer to `Data Processing Debugging Method 3 `_ . + A: It is possible to iterate through the dataset individually and see the processing time for each piece of data to determine how well the dataset is performing. For details, please refer to `Data Processing Debugging Method 3 `_ . **Q: In the process of processing data, if abnormal result values are generated due to computational errors, numerical overflow, etc., resulting in operator computation overflow and weight update anomalies during network training, how should we troubleshoot them?** - A: Turn off shuffling and fix random seeds to ensure reproductivity, and then use tools such as NumPy to quickly verify the results. For details, please refer to `Data Processing Debugging Method 4 `_ . + A: Turn off shuffling and fix random seeds to ensure reproductivity, and then use tools such as NumPy to quickly verify the results. For details, please refer to `Data Processing Debugging Method 4 `_ . - For more common data processing problems, please refer to `Analyzing Common Data Processing Problems `_ , and for differences in data processing during migration, please refer to `Data Pre-Processing Differences Between MindSpore And PyTorch `_ . + For more common data processing problems, please refer to `Analyzing Common Data Processing Problems `_ , and for differences in data processing during migration, please refer to `Data Pre-Processing Differences Between MindSpore And PyTorch `_ . - Gradient Derivation **Q: How can I implement the backward computation of an operator?** - A: MindSpore provides an automated interface for gradient derivation, a feature that shields the user from a great deal of the details and process of derivation. However, if there are some special scenarios where the user needs to manually control the calculation of its backward computation, the user can also define its backward computation through the Cell.bprop interface. For details, please refer to `Customize Cell reverse `_ . + A: MindSpore provides an automated interface for gradient derivation, a feature that shields the user from a great deal of the details and process of derivation. However, if there are some special scenarios where the user needs to manually control the calculation of its backward computation, the user can also define its backward computation through the Cell.bprop interface. For details, please refer to `Customize Cell reverse `_ . **Q: How to deal with training instability due to gradient overflow?** - A: Network overflows are usually manifested as loss Nan/INF, the loss suddenly becomes very large. MindSpore provides `dump data `_ to get the information about the overflow operator information. When there is gradient underflow in the network, we can use loss scale to support gradient derivation. For details, please refer to `loss scale `_; When the network has gradient explosion, you can consider adding gradient trimming. For details, please refer to `gradient cropping `_ . + A: Network overflows are usually manifested as loss Nan/INF, the loss suddenly becomes very large. MindSpore provides `dump data `_ to get the information about the overflow operator information. When there is gradient underflow in the network, we can use loss scale to support gradient derivation. For details, please refer to `loss scale `_; When the network has gradient explosion, you can consider adding gradient trimming. For details, please refer to `gradient cropping `_ . - Debugging and Tuning @@ -134,11 +134,14 @@ MindSpore provides a `FAQ `_. - For more debugging and tuning FAQs, please refer to `Tuning FAQs and Solutions `_ . + For more debugging and tuning FAQs, please refer to + `Function Debugging `_, + `Precision Tuning `_, + `Performance Tuning `_ . **Q: During model training, the first step takes a long time, how to optimize it?** - A: During the model training process, the first step contains the network compilation time. If you want to optimize the performance of the first step, you can analyze whether the model compilation can be optimized. For details, please refer to `Static graph network compilation performance optimization `_. + A: During the model training process, the first step contains the network compilation time. If you want to optimize the performance of the first step, you can analyze whether the model compilation can be optimized. For details, please refer to `Static graph network compilation performance optimization `_. **Q: The non-first step takes a long time during model training, how to optimize it?** @@ -176,7 +179,7 @@ MindSpore provides a `FAQ `_ for details. + See `Static diagram syntax support `_ for details. **Q: What can I do if the error is reported during training: RuntimeError: "Launch kernel failed, name:Default/... What to do" ?** @@ -190,7 +193,7 @@ MindSpore provides a `FAQ `_. + Meanwhile, when the compilation of computational graphs reports errors, it will automatically save the file analyze_failed.ir, which can help to analyze the location of the error code. For more details, please refer to `Static Graph Mode Error Analysis `_. **Q: Out Of Memory error is reported during Graph mode static graph training, what should I do?** @@ -200,6 +203,6 @@ MindSpore provides a `FAQ `_ . + For more details, please refer to `Analysis of the problem of insufficient resources `_ . See `Execution Issues `_ for more tuning FAQs. diff --git a/docs/mindspore/source_en/migration_guide/index.rst b/docs/mindspore/source_en/migration_guide/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..c7cbd2659cceb358de46e67077f3c5a96a480e0c --- /dev/null +++ b/docs/mindspore/source_en/migration_guide/index.rst @@ -0,0 +1,14 @@ +Model Migration +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + enveriment_preparation + analysis_and_preparation + model_development/model_development + debug_and_tune + sample_code + reference diff --git a/docs/mindspore/source_en/migration_guide/migrator_with_tools.md b/docs/mindspore/source_en/migration_guide/migrator_with_tools.md index bee5fc887ca373efc9f3aa05f3708290201d6b53..78e7022cc790f9d83c30ec6cd44c7c618e81a8d0 100644 --- a/docs/mindspore/source_en/migration_guide/migrator_with_tools.md +++ b/docs/mindspore/source_en/migration_guide/migrator_with_tools.md @@ -17,7 +17,7 @@ This guide describes how to apply various migration-related tools to improve the | [MindSpore Dev Toolkit](https://www.mindspore.cn/devtoolkit/docs/en/master/index.html) | MindSpore Dev Toolkit is a development kit supporting the cross-platform Python IDE plug-in developed by MindSpore, and provides functions such as Project creation, intelligent supplement, API search, and Document search. | With capabilities such as API search, it is possible to improve the efficiency of users network migration development. | | [TroubleShooter](https://gitee.com/mindspore/toolkits/tree/master/troubleshooter) | TroubleShooter is a MindSpore web development debugging toolkit designed to provide convenient, easy-to-use debugging capabilities. | Network debugging toolset (e.g., network weight migration, accuracy comparison, code tracing, error reporting analysis, execution tracking and other functions) to help users improve migration debugging efficiency. | | [Profiler](https://www.mindspore.cn/mindinsight/docs/en/master/performance_profiling.html) | Profiler can record information such as operator time consumption during the training process into a file, which can be viewed and analyzed by the user through a visual interface, helping the user to debug neural network performance more efficiently. | After the network migration, if the execution performance is not good, you can use Profiler to analyze the performance. Profiler provides Profiler analysis of the host execution of the framework, as well as the execution of the operator. | -| [Dump](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html) | The Dump function is provided to save the graphs from model training and the input and output data of the operators to a disk file. | Generally used for network migration complex problem localization (eg: operator overflow, etc.) and can dump out the operator-level data. | +| [Dump](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html) | The Dump function is provided to save the graphs from model training and the input and output data of the operators to a disk file. | Generally used for network migration complex problem localization (eg: operator overflow, etc.) and can dump out the operator-level data. | ## Examples of Network Migration Tool Applications diff --git a/docs/mindspore/source_en/migration_guide/missing_api_processing_policy.md b/docs/mindspore/source_en/migration_guide/missing_api_processing_policy.md index d9c543e025fc0381e0d44c1a660a20498a345d66..25b45b001ca6f6a47fe8bc9b0eac50e4dd710cad 100644 --- a/docs/mindspore/source_en/migration_guide/missing_api_processing_policy.md +++ b/docs/mindspore/source_en/migration_guide/missing_api_processing_policy.md @@ -234,7 +234,7 @@ The final error is less than 1e-5, which is a reasonable accuracy error. ## 3. Customize operators -When existing APIs cannot be used for packaging, or the performance of cell encapsulation is poor, you need to customize operators. For details, see [Custom Operators](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom.html). +When existing APIs cannot be used for packaging, or the performance of cell encapsulation is poor, you need to customize operators. For details, see [Custom Operators](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom.html). In addition to migrating APIs, you can also use the `aot` development mode of the `Custom` operator to call the PyTorch Aten operator for quick verification. For details, see [Using Third-party Operator Libraries Based on Customized Interfaces](https://www.mindspore.cn/docs/en/master/migration_guide/use_third_party_op.html). diff --git a/docs/mindspore/source_en/migration_guide/model_development/dataset.md b/docs/mindspore/source_en/migration_guide/model_development/dataset.md index 158c24c3284aeb39901aa9da2cb90fd35fc01a6e..500fd4ab9370f33a1009f5854bae862aeef6a210 100644 --- a/docs/mindspore/source_en/migration_guide/model_development/dataset.md +++ b/docs/mindspore/source_en/migration_guide/model_development/dataset.md @@ -6,11 +6,11 @@ This chapter focuses on considerations related to data processing in network mig [Data Processing](https://www.mindspore.cn/tutorials/en/master/beginner/dataset.html) -[Auto Augmentation](https://www.mindspore.cn/tutorials/experts/en/master/dataset/augment.html) +[Auto Augmentation](https://www.mindspore.cn/docs/en/master/model_train/dataset/augment.html) -[Lightweight Data Processing](https://mindspore.cn/tutorials/en/master/advanced/dataset/eager.html) +[Lightweight Data Processing](https://mindspore.cn/docs/en/master/model_train/dataset/eager.html) -[Optimizing the Data Processing](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html) +[Optimizing the Data Processing](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html) ## Comparison of Data Processing Differences @@ -19,7 +19,7 @@ The basic process of data construction in MindSpore and PyTorch mainly includes ### Processing Common Datasets MindSpore provides [interfaces](https://www.mindspore.cn/docs/en/master/api_python/mindspore.dataset.html) for loading common datasets from many different domains. -In addition to the above commonly used datasets in the industry, MindSpore has also developed MindRecord data format to cope with efficient reading, mega data storage and reading scenarios, and you can refer to [MindRecord](https://www.mindspore.cn/tutorials/en/master/advanced/dataset/record.html) . Since this article is to introduce similar APIs and the differences in the writing style, so we have selected one of the more classic dataset APIs as an example of migration comparison. For other dataset interface differences, please refer to the [torchaudio](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html#torchaudio), [torchtext](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html#torchtext), [torchvision](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html#torchvision) modules of PyTorch and MindSpore API mapping table. +In addition to the above commonly used datasets in the industry, MindSpore has also developed MindRecord data format to cope with efficient reading, mega data storage and reading scenarios, and you can refer to [MindRecord](https://www.mindspore.cn/docs/en/master/model_train/dataset/record.html) . Since this article is to introduce similar APIs and the differences in the writing style, so we have selected one of the more classic dataset APIs as an example of migration comparison. For other dataset interface differences, please refer to the [torchaudio](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html#torchaudio), [torchtext](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html#torchtext), [torchvision](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html#torchvision) modules of PyTorch and MindSpore API mapping table. Here is an example of FashionMnistDataset. The following figure shows how to use the PyTorch API (left part), and how to use the MindSpore API (right part). The main reading process is: use FashionMnist API to load the source dataset, then use transforms to transform the data content, and finally according to the batch operation on the dataset. The key parts of the code on both sides are marked with color boxes. diff --git a/docs/mindspore/source_en/migration_guide/model_development/gradient.md b/docs/mindspore/source_en/migration_guide/model_development/gradient.md index 0f93e71c305e96169a5b635a1c4974a1cfd16b0b..30b41d9a609a1a602750c79f43292fec6de49e0a 100644 --- a/docs/mindspore/source_en/migration_guide/model_development/gradient.md +++ b/docs/mindspore/source_en/migration_guide/model_development/gradient.md @@ -358,7 +358,7 @@ MindSpore does not require this function. MindSpore is an automatic differentiat ## Automatic Differentiation Interfaces After the forward network is constructed, MindSpore provides an interface to [automatic differentiation](https://mindspore.cn/tutorials/en/master/beginner/autograd.html) to calculate the gradient results of the model. -In the tutorial of [automatic derivation](https://mindspore.cn/tutorials/en/master/advanced/derivation.html), some descriptions of various gradient calculation scenarios are given. +In the tutorial of [automatic derivation](https://mindspore.cn/docs/en/master/model_train/train_process/derivation.html), some descriptions of various gradient calculation scenarios are given. ### mindspore.grad @@ -642,7 +642,7 @@ Since the gradient overflow may be encountered in the process of finding the gra > On Ascend, because operators such as Conv, Sort, and TopK can only be float16, and MatMul is preferably float16 due to performance issues, it is recommended that loss scale operations be used as standard for network training. [List of operators on Ascend only support float16][https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html#4-training-accuracy]. > -> The overflow can obtain overflow operator information via MindSpore Insight [dump data](https://mindspore.cn/tutorials/experts/en/master/debug/dump.html). +> The overflow can obtain overflow operator information via MindSpore Insight [dump data](https://mindspore.cn/docs/en/master/model_train/debug/dump.html). > > General overflow manifests itself as loss Nan/INF, loss suddenly becomes large, etc. @@ -708,4 +708,4 @@ grad = ops.clip_by_global_norm(grad) Gradient accumulation is a way that data samples of a kind of training neural network is split into several small Batches by Batch, and then calculated in order to solve the OOM (Out Of Memory) problem that due to the lack of memory, resulting in too large Batch size, the neural network can not be trained or the network model is too large to load. -For detailed, refer to [Gradient Accumulation](https://www.mindspore.cn/tutorials/experts/en/master/optimize/gradient_accumulation.html). +For detailed, refer to [Gradient Accumulation](https://www.mindspore.cn/docs/en/master/model_train/train_process/optimize/gradient_accumulation.html). diff --git a/docs/mindspore/source_en/migration_guide/model_development/learning_rate_and_optimizer.md b/docs/mindspore/source_en/migration_guide/model_development/learning_rate_and_optimizer.md index d5486e710a97887b16773e4f2d42f31e95deeb91..c4f04efac7b39ed8bbde778c1b4e35ef4fae9e2a 100644 --- a/docs/mindspore/source_en/migration_guide/model_development/learning_rate_and_optimizer.md +++ b/docs/mindspore/source_en/migration_guide/model_development/learning_rate_and_optimizer.md @@ -2,7 +2,7 @@ [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/migration_guide/model_development/learning_rate_and_optimizer.md) -Before reading this chapter, please read the official MindSpore tutorial [Optimizer](https://mindspore.cn/tutorials/en/master/advanced/modules/optimizer.html). +Before reading this chapter, please read the official MindSpore tutorial [Optimizer](https://mindspore.cn/docs/en/master/model_train/custom_program/optimizer.html). Here is an introduction to some special ways of using MindSpore optimizer and the principle of learning rate decay strategy. diff --git a/docs/mindspore/source_en/migration_guide/model_development/loss_function.md b/docs/mindspore/source_en/migration_guide/model_development/loss_function.md index c7725e51c7c16d8f1bba32846080d7314165c1a6..5af2e17b05bbe6df6e893b8c0dfbdb1751a9481d 100644 --- a/docs/mindspore/source_en/migration_guide/model_development/loss_function.md +++ b/docs/mindspore/source_en/migration_guide/model_development/loss_function.md @@ -2,7 +2,7 @@ [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/migration_guide/model_development/loss_function.md) -Before reading this chapter, please read the MindSpore official website tutorial first[Loss Function](https://www.mindspore.cn/tutorials/en/master/advanced/modules/loss.html). +Before reading this chapter, please read the MindSpore official website tutorial first[Loss Function](https://www.mindspore.cn/docs/en/master/model_train/custom_program/loss.html). The MindSpore official website tutorial on loss functions explains built-in, custom, and multi label loss functions, as well as guidance on their use in model training. Here is a list of differences in functionality and interface between MindSpore's loss function and PyTorch's loss function. diff --git a/docs/mindspore/source_en/migration_guide/model_development/model_and_cell.md b/docs/mindspore/source_en/migration_guide/model_development/model_and_cell.md index a481bb6e425bb3440cad58f04bc7fd8131608444..84528bb3fbda7a115e913b1e3b0154c30ee0f71b 100644 --- a/docs/mindspore/source_en/migration_guide/model_development/model_and_cell.md +++ b/docs/mindspore/source_en/migration_guide/model_development/model_and_cell.md @@ -10,7 +10,7 @@ The basic logic of PyTorch and MindSpore is shown below: It can be seen that PyTorch and MindSpore generally require network definition, forward computation, backward computation, and gradient update steps in the implementation process. -- Network definition: In the network definition, the desired forward network, loss function, and optimizer are generally defined. To define the forward network in Net(), PyTorch network inherits from nn.Module; similarly, MindSpore network inherits from nn.Cell. In MindSpore, the loss function and optimizers can be customized in addition to using those provided in MindSpore. You can refer to [Model Module Customization](https://mindspore.cn/tutorials/en/master/advanced/modules.html). Interfaces such as functional/nn can be used to splice the required forward networks, loss functions and optimizers. +- Network definition: In the network definition, the desired forward network, loss function, and optimizer are generally defined. To define the forward network in Net(), PyTorch network inherits from nn.Module; similarly, MindSpore network inherits from nn.Cell. In MindSpore, the loss function and optimizers can be customized in addition to using those provided in MindSpore. You can refer to [Model Module Customization](https://mindspore.cn/docs/en/master/model_train/index.html). Interfaces such as functional/nn can be used to splice the required forward networks, loss functions and optimizers. - Forward computation: Run the instantiated network to get the logit, and use the logit and target as inputs to calculate the loss. It should be noted that if the forward function has more than one output, you need to pay attention to the effect of more than one output on the result when calculating the backward function. @@ -538,9 +538,9 @@ x = initializer(Uniform(), [1, 2, 3], mindspore.float32) ##### Customizing Initialization Parameters -Generally, the high-level API encapsulated by MindSpore initializes parameters by default. Sometimes, the initialization distribution is inconsistent with the required initialization and PyTorch initialization. In this case, you need to customize initialization. [Initializing Network Arguments](https://mindspore.cn/tutorials/en/master/advanced/modules/initializer.html#customized-parameter-initialization) describes a method of initializing parameters during using API attributes. This section describes a method of initializing parameters by using Cell. +Generally, the high-level API encapsulated by MindSpore initializes parameters by default. Sometimes, the initialization distribution is inconsistent with the required initialization and PyTorch initialization. In this case, you need to customize initialization. [Initializing Network Arguments](https://mindspore.cn/docs/en/master/model_train/custom_program/initializer.html#customized-parameter-initialization) describes a method of initializing parameters during using API attributes. This section describes a method of initializing parameters by using Cell. -For details about the parameters, see [Network Parameters](https://mindspore.cn/tutorials/zh-CN/master/advanced/modules/initializer.html). This section uses `Cell` as an example to describe how to obtain all parameters in `Cell` and how to initialize the parameters in `Cell`. +For details about the parameters, see [Network Parameters](https://mindspore.cn/docs/zh-CN/master/model_train/custom_program/initializer.html). This section uses `Cell` as an example to describe how to obtain all parameters in `Cell` and how to initialize the parameters in `Cell`. > Note that the method described in this section cannot be performed in `construct`. To change the value of a parameter on the network, use [assign](https://www.mindspore.cn/docs/en/master/api_python/ops/mindspore.ops.assign.html). @@ -766,7 +766,7 @@ For `Cell`, MindSpore provides two image modes: `GRAPH_MODE` (static image) and The **inference** behavior of the model in `PyNative` mode is the same as that of common Python code. However, during training, **once a tensor is converted into NumPy for other operations, the gradient of the network is truncated, which is equivalent to detach of PyTorch**. -When `GRAPH_MODE` is used, syntax restrictions usually occur. In this case, graph compilation needs to be performed on the Python code. However, MindSpore does not support the complete Python syntax set. Therefore, there are some restrictions on compiling the `construct` function. For details about the restrictions, see [MindSpore Static Graph Syntax](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html). +When `GRAPH_MODE` is used, syntax restrictions usually occur. In this case, graph compilation needs to be performed on the Python code. However, MindSpore does not support the complete Python syntax set. Therefore, there are some restrictions on compiling the `construct` function. For details about the restrictions, see [MindSpore Static Graph Syntax](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). Compared with the detailed syntax description, the common restrictions are as follows: @@ -881,7 +881,7 @@ dx (Tensor(shape=[2, 5], dtype=Float32, value= [0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 0.00000000e+000]]),) ``` -Now, let's see how to [customize backward network construction](https://www.mindspore.cn/tutorials/en/master/advanced/modules/layer.html#custom-cell-reverse). +Now, let's see how to [customize backward network construction](https://www.mindspore.cn/docs/en/master/model_train/custom_program/network_custom.html#custom-cell-reverse). ```python import numpy as np diff --git a/docs/mindspore/source_en/migration_guide/model_development/model_development.rst b/docs/mindspore/source_en/migration_guide/model_development/model_development.rst index 1d2aefcd928817f6706f41871252e7e2e3c99e4b..9eba48d15a70200c0ff5a092f869dcfbf1776a28 100644 --- a/docs/mindspore/source_en/migration_guide/model_development/model_development.rst +++ b/docs/mindspore/source_en/migration_guide/model_development/model_development.rst @@ -49,7 +49,7 @@ The training process of the whole network consists of 5 modules: details and procedures and greatly reduces the threshold of framework. When you need to customize the gradient, MindSpore also provides - `interface `__ + `interface `__ to freely implement the gradient calculation. - Optimizer: used to calculate and update network parameters during @@ -199,7 +199,7 @@ for the following situations: precision. 4. In Ascend environment, Conv, Sort and TopK can only be float16, and add `loss - scale `__ + scale `__ to avoid overflow. 5. In the Ascend environment, operators with the stride property such as Conv and Pooling have rules about the length of the stride, which diff --git a/docs/mindspore/source_en/migration_guide/model_development/training_and_evaluation.md b/docs/mindspore/source_en/migration_guide/model_development/training_and_evaluation.md index 145036d98bfcbe08acf24c04b9580541174a397b..863af6711411a8593ab145906ebe6769ead35a50 100644 --- a/docs/mindspore/source_en/migration_guide/model_development/training_and_evaluation.md +++ b/docs/mindspore/source_en/migration_guide/model_development/training_and_evaluation.md @@ -336,8 +336,8 @@ mpirun --allow-run-as-root -n $RANK_SIZE python ../train.py --config_path=$CONFI If on the GPU, you can set which cards to use by `export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7`. Specifying the card number is not currently supported on Ascend. -Please refer to [Distributed Case](https://www.mindspore.cn/tutorials/experts/en/master/parallel/distributed_case.html) for more details. +Please refer to [Distributed Case](https://www.mindspore.cn/docs/en/master/model_train/parallel/distributed_case.html) for more details. ## Offline Inference -In addition to the possibility of online inference, MindSpore provides many offline inference methods for different environments. Please refer to [Model Inference](https://www.mindspore.cn/tutorials/experts/en/master/infer/inference.html) for details. +In addition to the possibility of online inference, MindSpore provides many offline inference methods for different environments. Please refer to [Model Inference](https://www.mindspore.cn/docs/en/master/model_infer/overview.html) for details. diff --git a/docs/mindspore/source_en/migration_guide/overview.md b/docs/mindspore/source_en/migration_guide/overview.md index 06b55db12a7d595b990ddd19dcb9c0f408c20f14..18f1f24fa9aad621e991ead9f9b4054207f6d624 100644 --- a/docs/mindspore/source_en/migration_guide/overview.md +++ b/docs/mindspore/source_en/migration_guide/overview.md @@ -13,24 +13,28 @@ E-.-text2(AI Platform ModelArts) B-->|Step 2|F(Model Analysis and Preparation) F-.-text3(Reproducing algorithm, analyzing API compliance using MindSpore Dev Toolkit and analyzing function compliance.) B-->|Step 3|G(Network Constructing Comparison) -G-->I(Dataset) -I-.-text4(Aligning the process of dataset loading, augmentation and reading) -G-->J(Network Constructing) -J-.-text5(Aligning the network) -G-->N(Loss Function) -N-.-text6(Aligning the loss function) -G-->K(Learning Rate and Optimizer) -K-.-text7(Aligning the optimizer and learning rate strategy) -G-->L(Gradient) -L-.-text8(Aligning the reverse gradients) -G-->M(Training and Evaluation Process) -M-.-text9(Aligning the process of training and evaluation) -B-->|Step 4|H(Debug and Tuning) -H-.-text10(Aligning from three aspects: function, precision and performance) +G-->K(Dataset) +K-.-text4(Aligning the process of dataset loading, augmentation and reading) +G-->L(Network Constructing) +L-.-text5(Aligning the network) +G-->P(Loss Function) +P-.-text6(Aligning the loss function) +G-->M(Learning Rate and Optimizer) +M-.-text7(Aligning the optimizer and learning rate strategy) +G-->N(Gradient) +N-.-text8(Aligning the reverse gradients) +G-->O(Training and Evaluation Process) +O-.-text9(Aligning the process of training and evaluation) +B-->|Step 4|H(Function Debugging) +H-.-text10(Functional alignment) +B-->|Step 5|I(Precision Tuning) +I-.-text11(Precision alignment) +B-->|Step 6|J(Performance Tuning) +J-.-text12(Performance Alignment) A-->C(A Migration Sample) -C-.-text11(The network migration sample, taking ResNet50 as an example.) +C-.-text13(The network migration sample, taking ResNet50 as an example.) A-->D(FAQs) -D-.-text12(Provides the frequently-asked questions and corresponding solutions in migration process.) +D-.-text14(Provides the frequently-asked questions and corresponding solutions in migration process.) click C "https://www.mindspore.cn/docs/en/master/migration_guide/sample_code.html" click D "https://www.mindspore.cn/docs/en/master/migration_guide/faq.html" @@ -38,12 +42,14 @@ click D "https://www.mindspore.cn/docs/en/master/migration_guide/faq.html" click E "https://www.mindspore.cn/docs/en/master/migration_guide/enveriment_preparation.html" click F "https://www.mindspore.cn/docs/en/master/migration_guide/analysis_and_preparation.html" click G "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/model_development.html" -click H "https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html" +click H "https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html#function-debugging" +click I "https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html#precision-tuning" +click J "https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html#performance-tuning" -click I "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/dataset.html" -click J "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/model_and_cell.html" -click K "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/learning_rate_and_optimizer.html" -click L "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/gradient.html" -click M "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/training_and_evaluation.html" -click N "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/loss_function.html" +click K "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/dataset.html" +click L "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/model_and_cell.html" +click M "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/learning_rate_and_optimizer.html" +click N "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/gradient.html" +click O "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/training_and_evaluation.html" +click P "https://www.mindspore.cn/docs/en/master/migration_guide/model_development/loss_function.html" ``` diff --git a/docs/mindspore/source_en/migration_guide/reference.rst b/docs/mindspore/source_en/migration_guide/reference.rst new file mode 100644 index 0000000000000000000000000000000000000000..1e750186a3b14910870cb641fd8a7456123861c5 --- /dev/null +++ b/docs/mindspore/source_en/migration_guide/reference.rst @@ -0,0 +1,9 @@ +Reference +========== + +.. toctree:: + :maxdepth: 1 + + ../note/api_mapping/pytorch_api_mapping + migrator_with_tools + faq diff --git a/docs/mindspore/source_en/migration_guide/reproducing_algorithm.md b/docs/mindspore/source_en/migration_guide/reproducing_algorithm.md index 9fec762d47ce921701297f645c4911ae80d7e9bf..54aadf2af497b19ea62c04e24b324d0fae8e5778 100644 --- a/docs/mindspore/source_en/migration_guide/reproducing_algorithm.md +++ b/docs/mindspore/source_en/migration_guide/reproducing_algorithm.md @@ -82,4 +82,7 @@ After obtaining the reference code, you need to reproduce the accuracy of the re - Obtain the loss decrease trend to check whether the training convergence trend on MindSpore is normal. - Obtain the parameter file for conversion and inference verification. For details, see [Inference and Training Process](https://www.mindspore.cn/docs/en/master/migration_guide/model_development/training_and_evaluation.html). - - Obtain the performance baseline for performance tuning. For details, see [Debugging and Tuning](https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html). + - Obtain the performance baseline for performance tuning. For details, see + [Function Debugging](https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html#function-debugging), + [Precision Tuning](https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html#precision-tuning), + [Performance Tuning](https://www.mindspore.cn/docs/en/master/migration_guide/debug_and_tune.html#performance-tuning). diff --git a/docs/mindspore/source_en/migration_guide/sample_code.md b/docs/mindspore/source_en/migration_guide/sample_code.md index 53ec2dfd0219fb786f8741082e070b7c0f9f6078..268bee07589226956a17a3aee34fc9d60e2bce66 100644 --- a/docs/mindspore/source_en/migration_guide/sample_code.md +++ b/docs/mindspore/source_en/migration_guide/sample_code.md @@ -1081,7 +1081,7 @@ MindSpore has three methods to use mixed precision: 1. Use `Cast` to convert the network input `cast` into `float16` and the loss input `cast` into `float32`. 2. Use the `to_float` method of `Cell`. For details, see [Network Construction](https://www.mindspore.cn/docs/en/master/migration_guide/model_development/model_and_cell.html). -3. Use the `amp_level` interface of the `Model` to perform mixed precision. For details, see [Automatic Mixed-Precision](https://www.mindspore.cn/tutorials/en/master/advanced/mixed_precision.html#automatic-mix-precision). +3. Use the `amp_level` interface of the `Model` to perform mixed precision. For details, see [Automatic Mixed-Precision](https://www.mindspore.cn/tutorials/en/master/beginner/mixed_precision.html#automatic-mix-precision). Use the third method to set `amp_level` in `Model` to `O3` and check the profiler result. @@ -1102,7 +1102,7 @@ If most of the data queues are empty, you need to optimize the data performance. ![resnet_profiler12](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/migration_guide/images/resnet_profiler12.png) -In the queue of each data processing operation, the last operator and the `batch` operator are empty for a long time. In this case, you can increase the degree of parallelism of the `batch` operator. For details, see [Data Processing Performance Tuning](https://www.mindspore.cn/tutorials/experts/en/master/dataset/optimize.html). +In the queue of each data processing operation, the last operator and the `batch` operator are empty for a long time. In this case, you can increase the degree of parallelism of the `batch` operator. For details, see [Data Processing Performance Tuning](https://www.mindspore.cn/docs/en/master/model_train/dataset/optimize.html). The code required for ResNet migration can be obtained from [code](https://gitee.com/mindspore/docs/tree/master/docs/mindspore/source_zh_cn/migration_guide/code). diff --git a/docs/mindspore/source_en/migration_guide/sparsity.md b/docs/mindspore/source_en/migration_guide/sparsity.md index 99ff138dfc6bc1ff23fcca10bdf14bef9462b382..a54b2fec9eb2f5fa4d932bf264ee7b684e840a2c 100644 --- a/docs/mindspore/source_en/migration_guide/sparsity.md +++ b/docs/mindspore/source_en/migration_guide/sparsity.md @@ -7,4 +7,4 @@ A [sparse tensor](https://matteding.github.io/2019/04/25/sparse-matrices/) is a In some scenarios (such as recommendation systems, molecular dynamics, graph neural networks), the data is sparse. If you use common dense tensors to represent the data, you may introduce many unnecessary calculations, storage, and communication costs. In this case, it is better to use sparse tensor to represent the data. MindSpore now supports the most commonly used [CSR and COO data formats](https://www.mindspore.cn/tutorials/en/master/beginner/tensor.html#sparse-tensor). Currently, only a limited number of sparse operators are supported, and most sparse features are restricted. In this case, you are advised to check whether the corresponding operator supports sparse computing. If the operator does not support sparse computing, convert it into a common operator. -After the operator is converted into a dense operator, the video memory used increases. Therefore, the batch size implemented by referring to may not be used for training. In this case, you can use [Gradient Accumulation](https://www.mindspore.cn/tutorials/experts/en/master/optimize/gradient_accumulation.html) to simulate large batch training. +After the operator is converted into a dense operator, the video memory used increases. Therefore, the batch size implemented by referring to may not be used for training. In this case, you can use [Gradient Accumulation](https://www.mindspore.cn/docs/en/master/model_train/train_process/optimize/gradient_accumulation.html) to simulate large batch training. diff --git a/docs/mindspore/source_en/migration_guide/use_third_party_op.md b/docs/mindspore/source_en/migration_guide/use_third_party_op.md index 898681e98e1f28203156ed85c51a583ef2ec771a..dd857c4930384ddcf00b6d2250b9afe386b18daa 100644 --- a/docs/mindspore/source_en/migration_guide/use_third_party_op.md +++ b/docs/mindspore/source_en/migration_guide/use_third_party_op.md @@ -6,7 +6,7 @@ When lacking of the built-in operators during developing a network, you can use the primitive in [Custom](https://www.mindspore.cn/docs/en/master/api_python/ops/mindspore.ops.Custom.html#mindspore-ops-custom) to easily and quickly define and use different types of customized operators. -Developers can choose different customized operator development methods according to their needs. For details, please refer to the [Usage Guide](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom.html) of Custom operator. +Developers can choose different customized operator development methods according to their needs. For details, please refer to the [Usage Guide](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom.html) of Custom operator. One of the development methods for customized operators, the `aot` method, has its own special use. The `aot` can call the corresponding `cpp`/`cuda` functions by loading a pre-compiled `so`. Therefore. When a third-party library provides `API`, a `cpp`/`cuda` function, you can try to call its function interface in `so`, which is described below by taking `Aten` library in PyTorch as an example. diff --git a/docs/mindspore/source_en/mindformers/appendix/conf_files.md b/docs/mindspore/source_en/mindformers/appendix/conf_files.md new file mode 100644 index 0000000000000000000000000000000000000000..7c9bcfdba9f0c38ee3a94105142cbbeca5b94a49 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/appendix/conf_files.md @@ -0,0 +1,3 @@ +# Configuration File Descriptions + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/appendix/conf_files.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/appendix/env_variables.md b/docs/mindspore/source_en/mindformers/appendix/env_variables.md new file mode 100644 index 0000000000000000000000000000000000000000..6b84228909d62cec43a78582e1af78d19fc3be4b --- /dev/null +++ b/docs/mindspore/source_en/mindformers/appendix/env_variables.md @@ -0,0 +1,3 @@ +# Environment Variable Descriptions + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/appendix/env_variables.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/faq/func_related.md b/docs/mindspore/source_en/mindformers/faq/func_related.md new file mode 100644 index 0000000000000000000000000000000000000000..fb33e04fe1e25313d4618cee8c9fb24818d6e7ac --- /dev/null +++ b/docs/mindspore/source_en/mindformers/faq/func_related.md @@ -0,0 +1,3 @@ +# Function_releated + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/faq/func_related.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/faq/mindformers_contribution.md b/docs/mindspore/source_en/mindformers/faq/mindformers_contribution.md new file mode 100644 index 0000000000000000000000000000000000000000..9b50b7578ef8d8384aba955ecd52cb6900c59fc0 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/faq/mindformers_contribution.md @@ -0,0 +1,3 @@ +# MindFormers Contribution Guidelines + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/faq/mindformers_contribution.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/faq/model_related.md b/docs/mindspore/source_en/mindformers/faq/model_related.md new file mode 100644 index 0000000000000000000000000000000000000000..708c85a9642d9be81603f091227a118aae7e5eab --- /dev/null +++ b/docs/mindspore/source_en/mindformers/faq/model_related.md @@ -0,0 +1,3 @@ +# Model-Releated + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/faq/model_related.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/faq/openmind_contribution.md b/docs/mindspore/source_en/mindformers/faq/openmind_contribution.md new file mode 100644 index 0000000000000000000000000000000000000000..c13d7c14219f8a4c053e39315b13031a9ec9baa0 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/faq/openmind_contribution.md @@ -0,0 +1,3 @@ +# openMind Contribution Guidelines + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/faq/openmind_contribution.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/function/dataset.md b/docs/mindspore/source_en/mindformers/function/dataset.md new file mode 100644 index 0000000000000000000000000000000000000000..085bd22419caf34f4874203e942b395cc97616d9 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/function/dataset.md @@ -0,0 +1,3 @@ +# Dataset + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/function/dataset.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/function/distributed_parallel.md b/docs/mindspore/source_en/mindformers/function/distributed_parallel.md new file mode 100644 index 0000000000000000000000000000000000000000..f718468cd296f167b6122ba6473088ab60c2d50e --- /dev/null +++ b/docs/mindspore/source_en/mindformers/function/distributed_parallel.md @@ -0,0 +1,3 @@ +# Distributed Parallel + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/function/distributed_parallel.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/function/res_training.md b/docs/mindspore/source_en/mindformers/function/res_training.md new file mode 100644 index 0000000000000000000000000000000000000000..08134087b76c39be8f80aacaf157baf9e16cdd3c --- /dev/null +++ b/docs/mindspore/source_en/mindformers/function/res_training.md @@ -0,0 +1,3 @@ +# Resumable Training After Breakpoint + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/function/res_training.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/function/weight_conversion.md b/docs/mindspore/source_en/mindformers/function/weight_conversion.md new file mode 100644 index 0000000000000000000000000000000000000000..7fb46c4d580b2bfd85a263ed00746abd9952c950 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/function/weight_conversion.md @@ -0,0 +1,3 @@ +# Weight Conversion + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/function/weight_conversion.md) \ No newline at end of file diff --git a/docs/mindformers/docs/source_en/index.rst b/docs/mindspore/source_en/mindformers/index.rst similarity index 32% rename from docs/mindformers/docs/source_en/index.rst rename to docs/mindspore/source_en/mindformers/index.rst index 7843352b78878880d1fbae0be69a84fcbab9cd22..e26a9e2e97136944cf0089afe64000e23aec687c 100644 --- a/docs/mindformers/docs/source_en/index.rst +++ b/docs/mindspore/source_en/mindformers/index.rst @@ -1,77 +1,74 @@ -MindFormers -============================ - -*1. 介绍MindFormers的主要功能和特点* - -*2. 展示所有文档的目录* +Large Model Development +=========================== .. toctree:: :glob: :maxdepth: 1 - :caption: Beginner + :caption: Start - overview - model + start/overview + start/models .. toctree:: :glob: :maxdepth: 1 - :caption: Install + :caption: Quick Start - installation + quick_start/install + quick_start/source_code_start .. toctree:: :glob: :maxdepth: 1 - :caption: Quick Start + :caption: Usage Tutorials - source_code_startup - api_startup + usage/dev_migration + usage/pre_training + usage/sft_tuning + usage/lora_tuning + usage/evaluation + usage/inference + usage/mindie_deployment + usage/quantization .. toctree:: :glob: :maxdepth: 1 - :caption: Practice Guide + :caption: Function Description - env_variable - configuration - api_register - advanced_interface - large_model - aicc + function/weight_conversion + function/distributed_parallel + function/dataset + function/res_training .. toctree:: :glob: :maxdepth: 1 - :caption: Characteristics + :caption: Precision Optimization - data_process - weight_process - training - fine_tuning - inference - evaluation + acc_optimize .. toctree:: :glob: :maxdepth: 1 - :caption: Debugging and Tuning + :caption: Performance Optimization - precision_tuning - performance_tuning + perf_optimize .. toctree:: :glob: :maxdepth: 1 - :caption: API + :caption: Appendix - *列举说明MindFormers中所有对外接口及说明* + appendix/env_variables + appendix/conf_files .. toctree:: :glob: :maxdepth: 1 :caption: FAQ - faq_configuration - faq_advanced_interface - contribution_guide \ No newline at end of file + faq/model_related + faq/func_related + faq/mindformers_contribution + faq/openmind_contribution \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/quick_start/install.md b/docs/mindspore/source_en/mindformers/quick_start/install.md new file mode 100644 index 0000000000000000000000000000000000000000..87b4bc56db1f1b7ba2040eae7d51dc0ab2439313 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/quick_start/install.md @@ -0,0 +1,3 @@ +# Installation + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/quick_start/install.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/quick_start/source_code_start.md b/docs/mindspore/source_en/mindformers/quick_start/source_code_start.md new file mode 100644 index 0000000000000000000000000000000000000000..bdcefc5f33d1bde85287c9861dbb4f76f8fb863c --- /dev/null +++ b/docs/mindspore/source_en/mindformers/quick_start/source_code_start.md @@ -0,0 +1,3 @@ +# Calling Source Code to Start + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/quick_start/source_code_start.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/start/models.md b/docs/mindspore/source_en/mindformers/start/models.md new file mode 100644 index 0000000000000000000000000000000000000000..920f56e47f17fc81e7ab69e962067c9f125ac96f --- /dev/null +++ b/docs/mindspore/source_en/mindformers/start/models.md @@ -0,0 +1,3 @@ +# Models + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/start/models.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/start/overview.md b/docs/mindspore/source_en/mindformers/start/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..51142848a0800b4c3db280eef402df99739768de --- /dev/null +++ b/docs/mindspore/source_en/mindformers/start/overview.md @@ -0,0 +1,3 @@ +# Overview + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/start/overview.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/dev_migration.md b/docs/mindspore/source_en/mindformers/usage/dev_migration.md new file mode 100644 index 0000000000000000000000000000000000000000..2bbc0d45cb5a22f1c8548974aca6db2c5076e652 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/dev_migration.md @@ -0,0 +1,3 @@ +# Development Migration + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/dev_migration.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/evaluation.md b/docs/mindspore/source_en/mindformers/usage/evaluation.md new file mode 100644 index 0000000000000000000000000000000000000000..7713fca9f040cc60407e27a5931965d5989a73a0 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/evaluation.md @@ -0,0 +1,3 @@ +# Evaluation + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/evaluation.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/inference.md b/docs/mindspore/source_en/mindformers/usage/inference.md new file mode 100644 index 0000000000000000000000000000000000000000..2b3297fd6b6ff6907dae42d345c2c507170e69ce --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/inference.md @@ -0,0 +1,3 @@ +# Inference + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/inference.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/lora_tuning.md b/docs/mindspore/source_en/mindformers/usage/lora_tuning.md new file mode 100644 index 0000000000000000000000000000000000000000..6b517c487601da8f79df08397974f06c9d883fc0 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/lora_tuning.md @@ -0,0 +1,3 @@ +# LoRA Low Parameter Fine-Tuning + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/lora_tuning.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/mindie_deployment.md b/docs/mindspore/source_en/mindformers/usage/mindie_deployment.md new file mode 100644 index 0000000000000000000000000000000000000000..54b4d26560b8594d2d0d06f3450298f5320e18a8 --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/mindie_deployment.md @@ -0,0 +1,3 @@ +# MindIE Service Deployment + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/mindie_deployment.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/pre_training.md b/docs/mindspore/source_en/mindformers/usage/pre_training.md new file mode 100644 index 0000000000000000000000000000000000000000..8ac0b4e3de55edea369a6950d19b3ac7beec377e --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/pre_training.md @@ -0,0 +1,3 @@ +# Pre-training + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/pre_training.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/quantization.md b/docs/mindspore/source_en/mindformers/usage/quantization.md new file mode 100644 index 0000000000000000000000000000000000000000..259b39b15fb2451502b4ad76b89c2533d5ab0eaf --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/quantization.md @@ -0,0 +1,3 @@ +# Quantization + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/quantization.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/mindformers/usage/sft_tuning.md b/docs/mindspore/source_en/mindformers/usage/sft_tuning.md new file mode 100644 index 0000000000000000000000000000000000000000..dbe8b8cff456600ead62d31b3ae160fd6cfe472e --- /dev/null +++ b/docs/mindspore/source_en/mindformers/usage/sft_tuning.md @@ -0,0 +1,3 @@ +# SFT-Tuning + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/mindformers/usage/sft_tuning.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/model_infer/index.rst b/docs/mindspore/source_en/model_infer/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..a72214031695ecf6d82f457ff0248d75e36c2032 --- /dev/null +++ b/docs/mindspore/source_en/model_infer/index.rst @@ -0,0 +1,10 @@ +Model Inference +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + llm_infer + llm_lite diff --git a/docs/mindspore/source_en/model_infer/llm_infer.rst b/docs/mindspore/source_en/model_infer/llm_infer.rst new file mode 100644 index 0000000000000000000000000000000000000000..fc423b2de28a55270da43c3ba8c3dde7f8118203 --- /dev/null +++ b/docs/mindspore/source_en/model_infer/llm_infer.rst @@ -0,0 +1,8 @@ +LLM Inference +============== + +.. toctree:: + :glob: + :maxdepth: 1 + + model_compression diff --git a/docs/mindspore/source_en/model_infer/llm_lite.md b/docs/mindspore/source_en/model_infer/llm_lite.md new file mode 100644 index 0000000000000000000000000000000000000000..f088b5ce24d592a0b1f0218ade55852e9af6e8bf --- /dev/null +++ b/docs/mindspore/source_en/model_infer/llm_lite.md @@ -0,0 +1,3 @@ +# Device-side Inference + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_infer/llm_lite.md) diff --git a/tutorials/experts/source_en/infer/model_compression.md b/docs/mindspore/source_en/model_infer/model_compression.md similarity index 97% rename from tutorials/experts/source_en/infer/model_compression.md rename to docs/mindspore/source_en/model_infer/model_compression.md index 3b20253f9eb567e56a82a4144f74fff19de222fb..c280f13d3445ceedd7b8caa80b08ace1593cabf8 100644 --- a/tutorials/experts/source_en/infer/model_compression.md +++ b/docs/mindspore/source_en/model_infer/model_compression.md @@ -1,6 +1,6 @@ # Model Compression -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/infer/model_compression.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_infer/model_compression.md) ## Overview diff --git a/tutorials/experts/source_en/infer/inference.md b/docs/mindspore/source_en/model_infer/overview.md similarity index 98% rename from tutorials/experts/source_en/infer/inference.md rename to docs/mindspore/source_en/model_infer/overview.md index c98433d1037ba4ff51a16bcc417b6fb0030b118d..baa2a2a5dc0b0b4db74af12809f0a18125d03c26 100644 --- a/tutorials/experts/source_en/infer/inference.md +++ b/docs/mindspore/source_en/model_infer/overview.md @@ -1,6 +1,6 @@ # Inference Model Overview -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/infer/inference.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_infer/overview.md) MindSpore can execute inference tasks on different hardware platforms based on trained models. diff --git a/docs/mindspore/source_en/model_train/custom_program/fusion_pass.md b/docs/mindspore/source_en/model_train/custom_program/fusion_pass.md new file mode 100644 index 0000000000000000000000000000000000000000..b4ef80007960d492d49c81cf7931ccc0ab3c68b0 --- /dev/null +++ b/docs/mindspore/source_en/model_train/custom_program/fusion_pass.md @@ -0,0 +1,3 @@ +# Custom Fusion Pass + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/fusion_pass.md) diff --git a/tutorials/source_en/advanced/modules/layer.md b/docs/mindspore/source_en/model_train/custom_program/hook_program.md similarity index 51% rename from tutorials/source_en/advanced/modules/layer.md rename to docs/mindspore/source_en/model_train/custom_program/hook_program.md index d388741ff7e380f82285432516a02d7533bba8a8..7548eae9a2bc1a2003376c1856c4a581de789a21 100644 --- a/tutorials/source_en/advanced/modules/layer.md +++ b/docs/mindspore/source_en/model_train/custom_program/hook_program.md @@ -1,306 +1,12 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/modules/layer.md) +# Hook Programming -# Cell and Parameter - -Cell, as the basic unit of neural network construction, corresponds to the concept of neural network layer, and the abstract encapsulation of Tensor computation operation can represent the neural network structure more accurately and clearly. In addition to the basic Tensor computation flow definition, the neural network layer contains functions such as parameter management and state management. Parameter is the core of neural network training and is usually used as an internal member variable of the neural network layer. In this section, we systematically introduce parameters, neural network layers and their related usage. - -## Parameter - -Parameter is a special class of Tensor, which is a variable whose value can be updated during model training. MindSpore provides the `mindspore.Parameter` class for Parameter construction. In order to distinguish between Parameter for different purposes, two different categories of Parameter are defined below. In order to distinguish between Parameter for different purposes, two different categories of Parameter are defined below: - -- Trainable parameter. Tensor that is updated after the gradient is obtained according to the backward propagation algorithm during model training, and `required_grad` needs to be set to `True`. -- Untrainable parameters. Tensor that does not participate in backward propagation needs to update values (e.g. `mean` and `var` variables in BatchNorm), when `requires_grad` needs to be set to `False`. - -> Parameter is set to `required_grad=True` by default. - -We construct a simple fully-connected layer as follows: - -```python -import numpy as np -import mindspore -from mindspore import nn -from mindspore import ops -from mindspore import Tensor, Parameter - -class Network(nn.Cell): - def __init__(self): - super().__init__() - self.w = Parameter(Tensor(np.random.randn(5, 3), mindspore.float32), name='w') # weight - self.b = Parameter(Tensor(np.random.randn(3,), mindspore.float32), name='b') # bias - - def construct(self, x): - z = ops.matmul(x, self.w) + self.b - return z - -net = Network() -``` - -In the `__init__` method of `Cell`, we define two parameters `w` and `b` and configure `name` for namespace management. Use `self.attr` in the `construct` method to call directly to participate in Tensor operations. - -### Obtaining Parameter - -After constructing the neural network layer by using Cell+Parameter, we can use various methods to obtain the Parameter managed by Cell. - -#### Obtaining a Single Parameter - -To get a particular parameter individually, just call a member variable of a Python class directly. - -```python -print(net.b.asnumpy()) -``` - -```text -[-1.2192779 -0.36789745 0.0946381 ] -``` - -#### Obtaining a Trainable Parameter - -Trainable parameters can be obtained by using the `Cell.trainable_params` method, and this interface is usually called when configuring the optimizer. - -```python -print(net.trainable_params()) -``` - -```text -[Parameter (name=w, shape=(5, 3), dtype=Float32, requires_grad=True), Parameter (name=b, shape=(3,), dtype=Float32, requires_grad=True)] -``` - -#### Obtaining All Parameters - -Use the `Cell.get_parameters()` method to get all parameters, at which point a Python iterator will be returned. - -```python -print(type(net.get_parameters())) -``` - -```text - -``` - -Or you can call `Cell.parameters_and_names` to return the parameter names and parameters. - -```python -for name, param in net.parameters_and_names(): - print(f"{name}:\n{param.asnumpy()}") -``` - -```text -w: -[[ 4.15680408e-02 -1.20311625e-01 5.02573885e-02] - [ 1.22175144e-04 -1.34980649e-01 1.17642188e+00] - [ 7.57667869e-02 -1.74758151e-01 -5.19092619e-01] - [-1.67846107e+00 3.27240258e-01 -2.06452996e-01] - [ 5.72323874e-02 -8.27963874e-02 5.94243526e-01]] -b: -[-1.2192779 -0.36789745 0.0946381 ] -``` - -### Modifying the Parameter - -#### Modifying Parameter Values Directly - -Parameter is a special kind of Tensor, so its value can be modified by using the Tensor index modification. - -```python -net.b[0] = 1. -print(net.b.asnumpy()) -``` - -```text -[ 1. -0.36789745 0.0946381 ] -``` - -#### Overriding the Modified Parameter Values - -The `Parameter.set_data` method can be called to override the Parameter by using a Tensor with the same Shape. This method is commonly used for [Cell traversal initialization](https://www.mindspore.cn/tutorials/en/master/advanced/modules/initializer.html) by using Initializer. - -```python -net.b.set_data(Tensor([3, 4, 5])) -print(net.b.asnumpy()) -``` - -```text -[3. 4. 5.] -``` - -#### Modifying Parameter Values During Runtime - -The main role of parameters is to update their values during model training, which involves parameter modification during runtime after backward propagation to obtain gradients, or when untrainable parameters need to be updated. Due to the compiled design of MindSpore's [Accelerating with Static Graphs](https://www.mindspore.cn/tutorials/en/master/beginner/accelerate_with_static_graph.html), it is necessary at this point to use the `mindspore.ops.assign` interface to assign parameters. This method is commonly used in [Custom Optimizer](https://www.mindspore.cn/tutorials/en/master/advanced/modules/optimizer.html) scenarios. The following is a simple sample modification of parameter values during runtime: - -```python -import mindspore as ms - -@ms.jit -def modify_parameter(): - b_hat = ms.Tensor([7, 8, 9]) - ops.assign(net.b, b_hat) - return True - -modify_parameter() -print(net.b.asnumpy()) -``` - -```text -[7. 8. 9.] -``` - -### Parameter Tuple - -ParameterTuple, variable tuple, used to store multiple Parameter, is inherited from tuple tuples, and provides cloning function. - -The following example provides the ParameterTuple creation method: - -```python -from mindspore.common.initializer import initializer -from mindspore import ParameterTuple -# Creation -x = Parameter(default_input=ms.Tensor(np.arange(2 * 3).reshape((2, 3))), name="x") -y = Parameter(default_input=initializer('ones', [1, 2, 3], ms.float32), name='y') -z = Parameter(default_input=2.0, name='z') -params = ParameterTuple((x, y, z)) - -# Clone from params and change the name to "params_copy" -params_copy = params.clone("params_copy") - -print(params) -print(params_copy) -``` - -```text -(Parameter (name=x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=z, shape=(), dtype=Float32, requires_grad=True)) -(Parameter (name=params_copy.x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=params_copy.y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=params_copy.z, shape=(), dtype=Float32, requires_grad=True)) -``` - -## Cell Training State Change - -Some Tensor operations in neural networks do not behave the same during training and inference, e.g., `nn.Dropout` performs random dropout during training but not during inference, and `nn.BatchNorm` requires updating the `mean` and `var` variables during training and fixing their values unchanged during inference. So we can set the state of the neural network through the `Cell.set_train` interface. - -When `set_train` is set to True, the neural network state is `train`, and the default value of `set_train` interface is `True`: - -```python -net.set_train() -print(net.phase) -``` - -```text -train -``` - -When `set_train` is set to False, the neural network state is `predict`: - -```python -net.set_train(False) -print(net.phase) -``` - -```text -predict -``` - -## Custom Neural Network Layers - -Normally, the neural network layer interface and function interface provided by MindSpore can meet the model construction requirements, but since the AI field is constantly updating, it is possible to encounter new network structures without built-in modules. At this point, we can customize the neural network layer through the function interface provided by MindSpore, Primitive operator, and can use the `Cell.bprop` method to customize the reverse. The following are the details of each of the three customization methods. - -### Constructing Neural Network Layers by Using the Function Interface - -MindSpore provides a large number of basic function interfaces, which can be used to construct complex Tensor operations, encapsulated as neural network layers. The following is an example of `Threshold` with the following equation: - -$$ -y =\begin{cases} - x, &\text{ if } x > \text{threshold} \\ - \text{value}, &\text{ otherwise } - \end{cases} -$$ - -It can be seen that `Threshold` determines whether the value of the Tensor is greater than the `threshold` value, keeps the value whose judgment result is `True`, and replaces the value whose judgment result is `False`. Therefore, the corresponding implementation is as follows: - -```python -class Threshold(nn.Cell): - def __init__(self, threshold, value): - super().__init__() - self.threshold = threshold - self.value = value - - def construct(self, inputs): - cond = ops.gt(inputs, self.threshold) - value = ops.fill(inputs.dtype, inputs.shape, self.value) - return ops.select(cond, inputs, value) -``` - -Here `ops.gt`, `ops.fill`, and `ops.select` are used to implement judgment and replacement respectively. The following custom `Threshold` layer is implemented: - -```python -m = Threshold(0.1, 20) -inputs = mindspore.Tensor([0.1, 0.2, 0.3], mindspore.float32) -m(inputs) -``` - -```text -Tensor(shape=[3], dtype=Float32, value= [ 2.00000000e+01, 2.00000003e-01, 3.00000012e-01]) -``` - -It can be seen that `inputs[0] = threshold`, so it is replaced with `20`. - -### Custom Cell Reverse - -In special scenarios, we not only need to customize the forward logic of the neural network layer, but also want to manually control the computation of its reverse, which we can define through the `Cell.bprop` interface. The function will be used in scenarios such as new neural network structure design and backward propagation speed optimization. In the following, we take `Dropout2d` as an example to introduce custom Cell reverse. - -```python -class Dropout2d(nn.Cell): - def __init__(self, keep_prob): - super().__init__() - self.keep_prob = keep_prob - self.dropout2d = ops.Dropout2D(keep_prob) - - def construct(self, x): - return self.dropout2d(x) - - def bprop(self, x, out, dout): - _, mask = out - dy, _ = dout - if self.keep_prob != 0: - dy = dy * (1 / self.keep_prob) - dy = mask.astype(mindspore.float32) * dy - return (dy.astype(x.dtype), ) - -dropout_2d = Dropout2d(0.8) -dropout_2d.bprop_debug = True -``` - -The `bprop` method has three separate input parameters: - -- *x*: Forward input. When there are multiple forward inputs, the same number of inputs are required. -- *out*: Forward input. -- *dout*: When backward propagation is performed, the current Cell executes the previous reverse result. - -Generally we need to calculate the reverse result according to the reverse derivative formula based on the forward output and the reverse result of the front layer, and return it. The reverse calculation of `Dropout2d` requires masking the reverse result of the front layer based on the `mask` matrix of the forward output, and then scaling according to `keep_prob`. The final implementation can get the correct calculation result. - -When customizing the reverse direction of a Cell, it supports extended writing in PyNative mode and can differentiate the weights inside the Cell. The specific columns are as follows: - -```python -class NetWithParam(nn.Cell): - def __init__(self): - super(NetWithParam, self).__init__() - self.w = Parameter(Tensor(np.array([2.0], dtype=np.float32)), name='weight') - self.internal_params = [self.w] - - def construct(self, x): - output = self.w * x - return output - - def bprop(self, *args): - return (self.w * args[-1],), {self.w: args[0] * args[-1]} -``` - -`bprop` method supports *args as an input parameter, and the last data in the args array, `args[-1]` is the gradient returned to the cell. Set the weight of differentiation through `self.internal_params`, and return a tuple and a dictionary in the `bprop` function. Return the tuple corresponding to the input gradient, as well as the dictionary corresponding to the gradient with key as the weight and value as the weight. - -## Hook Function +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/hook_program.md) Debugging deep learning networks is a big task for every practitioner in the field of deep learning. Since the deep learning network hides the input and output data as well as the inverse gradient of the intermediate layer operators, only the gradient of the network input data (feature quantity and weight) is provided, resulting in the inability to accurately sense the data changes of the intermediate layer operators, which reduces the debugging efficiency. In order to facilitate users to debug the deep learning network accurately and quickly, MindSpore designes Hook function in dynamic graph mode. **Using Hook function can capture the input and output data of intermediate layer operators as well as the reverse gradient**. -Currently, four forms of Hook functions are provided in dynamic graph mode: HookBackward operator and register_forward_pre_hook, register_forward_hook, register_backward_hook functions registered on Cell objects. +Currently, five forms of Hook functions are provided in dynamic graph mode: HookBackward operator and register_forward_pre_hook, register_forward_hook, register_backward_pre_hook, register_backward_hook functions registered on Cell objects. -### HookBackward Operator +## HookBackward Operator HookBackward implements the Hook function in the form of an operator. The user initializes a HookBackward operator and places it at the location in the deep learning network where the gradient needs to be captured. In the forward execution of the network, the HookBackward operator outputs the input data as is without any modification. When the network back propagates the gradient, the Hook function registered on HookBackward will capture the gradient back propagated to this point. The user can customize the operation on the gradient in the Hook function, such as printing the gradient, or returning a new gradient. @@ -337,7 +43,7 @@ output: (Tensor(shape=[], dtype=Float32, value= 4), Tensor(shape=[], dtype=Float For more descriptions of the HookBackward operator, refer to the [API documentation](https://mindspore.cn/docs/en/master/api_python/ops/mindspore.ops.HookBackward.html). -### register_forward_pre_hook Function in Cell Object +## register_forward_pre_hook Function in Cell Object The user can use the `register_forward_pre_hook` function on the Cell object to register a custom Hook function to capture data that is passed to that Cell object. This function does not work in static graph mode and inside functions modified with `@jit`. The `register_forward_pre_hook` function takes the Hook function as an input and returns a `handle` object that corresponds to the Hook function. The user can remove the corresponding Hook function by calling the `remove()` function of the `handle` object. Each call to the `register_forward_pre_hook` function returns a different `handle` object. Hook functions should be defined in the following way. @@ -441,7 +147,7 @@ To avoid running failure when scripts switch to graph mode, it is not recommende For more information about the `register_forward_pre_hook` function of the Cell object, refer to the [API documentation](https://mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_forward_pre_hook). -### register_forward_hook Function of Cell Object +## register_forward_hook Function of Cell Object The user can use the `register_forward_hook` function on the Cell object to register a custom Hook function that captures the data passed forward to the Cell object and the output data of the Cell object. This function does not work in static graph mode and inside functions modified with `@jit`. The `register_forward_hook` function takes the Hook function as an input and returns a `handle` object that corresponds to the Hook function. The user can remove the corresponding Hook function by calling the `remove()` function of the `handle` object. Each call to the `register_forward_hook` function returns a different `handle` object. Hook functions should be defined in the following way. @@ -506,21 +212,86 @@ To avoid running failure when the script switches to graph mode, it is not recom For more information about the `register_forward_hook` function of the Cell object, please refer to the [API documentation](https://mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_forward_hook). -### register_backward_hook Function of Cell Object +## register_backward_pre_hook Function of Cell Object + +The user can use the `register_backward_pre_hook` function on the Cell object to register a custom Hook function that captures the gradient associated with the Cell object when the network is back propagated. This function does not work in graph mode or inside functions modified with `@jit`. The `register_backward_pre_hook` function takes the Hook function as an input and returns a `handle` object that corresponds to the Hook function. The user can remove the corresponding Hook function by calling the `remove()` function of the `handle` object. Each call to the `register_backward_pre_hook` function will return a different `handle` object. + +Unlike the custom Hook function used by the HookBackward operator, the inputs of the Hook function used by `register_backward_pre_hook` contains `cell`, which represents the information of the Cell object, the gradient passed to the Cell object in reverse of the Cell object. + +The sample code is as follows: + +```python +def backward_hook_pre_function(cell, grad_output): + print(grad_output) +``` + +Here `cell` is the information of the Cell object, `grad_output` is the gradient passed to the Cell object when the network is back-propagated. Therefore, the user can use the `register_backward_pre_hook` function to capture the backward input gradients of a particular Cell object in the network. The user can customize the operations on the gradient in the Hook function, such as viewing, printing the gradient, or returning the new input gradient. If you need to return the new input gradient in the Hook function, the return value must be in the form of `tuple`. + +The sample code is as follows: + +```python +import numpy as np +import mindspore as ms +import mindspore.nn as nn + +ms.set_context(mode=ms.PYNATIVE_MODE) + +def backward_hook_pre_function(cell, grad_output): + print(grad_output) + +class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.conv = nn.Conv2d(1, 2, kernel_size=2, stride=1, padding=0, weight_init="ones", pad_mode="valid") + self.bn = nn.BatchNorm2d(2, momentum=0.99, eps=0.00001, gamma_init="ones") + self.handle = self.bn.register_backward_pre_hook(backward_hook_pre_function) + self.relu = nn.ReLU() + + def construct(self, x): + x = self.conv(x) + x = self.bn(x) + x = self.relu(x) + return x + +net = Net() +grad_net = ms.grad(net) +output = grad_net(ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32))) +print(output) +net.handle.remove() +output = grad_net(ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32))) +print("-------------\n", output) +``` + +```text +(Tensor(shape=[1, 2, 1, 1], dtype=Float32, value= +[[[[ 1.00000000e+00]], + [[ 1.00000000e+00]]]]),) +[[[[1.99999 1.99999] + [1.99999 1.99999]]]] +------------- + [[[[1.99999 1.99999] + [1.99999 1.99999]]]] +``` + +To avoid running failure when the scripts switch to graph mode, it is not recommended to call the `register_backward_pre_hook` function and the `remove()` function of the `handle` object in the `construct` function of the Cell object. In PyNative mode, if the `register_backward_pre_hook` function is called in the `construct` function of the Cell object, the Cell object will register a new Hook function every time it runs. + +For more information about the `register_backward_pre_hook` function of the Cell object, please refer to the [API documentation](https://mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_backward_pre_hook). + +## register_backward_hook Function of Cell Object The user can use the `register_backward_hook` function on the Cell object to register a custom Hook function that captures the gradient associated with the Cell object when the network is back propagated. This function does not work in graph mode or inside functions modified with `@jit`. The `register_backward_hook` function takes the Hook function as an input and returns a `handle` object that corresponds to the Hook function. The user can remove the corresponding Hook function by calling the `remove()` function of the `handle` object. Each call to the `register_backward_hook` function will return a different `handle` object. -Unlike the custom Hook function used by the HookBackward operator, the inputs of the Hook function used by `register_backward_hook` contains `cell_id`, which represents the name and id information of the Cell object, the gradient passed to the Cell object in reverse, and the gradient of the reverse output of the Cell object. +Unlike the custom Hook function used by the HookBackward operator, the inputs of the Hook function used by `register_backward_hook` contains `cell`, which represents the information of the Cell object, the gradient passed to the Cell object in reverse, and the gradient of the reverse output of the Cell object. The sample code is as follows: ```python -def backward_hook_function(cell_id, grad_input, grad_output): +def backward_hook_function(cell, grad_input, grad_output): print(grad_input) print(grad_output) ``` -Here `cell_id` is the name and the ID information of the Cell object, `grad_input` is the gradient passed to the Cell object when the network is back-propagated, which corresponds to the reverse output gradient of the next operator in the forward process. `grad_output` is the gradient of the reverse output of the Cell object. Therefore, the user can use the `register_backward_hook` function to capture the backward input and backward output gradients of a particular Cell object in the network. The user can customize the operations on the gradient in the Hook function, such as viewing, printing the gradient, or returning the new output gradient. If you need to return the new output gradient in the Hook function, the return value must be in the form of `tuple`. +Here `cell` is the information of the Cell object, `grad_input` is the gradient of the reverse output of the Cell object. `grad_output` is the gradient passed to the Cell object when the network is back-propagated, which corresponds to the reverse output gradient of the next operator in the forward process. Therefore, the user can use the `register_backward_hook` function to capture the backward input and backward output gradients of a particular Cell object in the network. The user can customize the operations on the gradient in the Hook function, such as viewing, printing the gradient, or returning the new output gradient. If you need to return the new output gradient in the Hook function, the return value must be in the form of `tuple`. The sample code is as follows: @@ -531,7 +302,7 @@ import mindspore.nn as nn ms.set_context(mode=ms.PYNATIVE_MODE) -def backward_hook_function(cell_id, grad_input, grad_output): +def backward_hook_function(cell, grad_input, grad_output): print(grad_input) print(grad_output) @@ -572,7 +343,13 @@ print("-------------\n", output) [1.99999 1.99999]]]] ``` -When the `register_backward_hook` function and the `register_forward_pre_hook` function, and the `register_forward_hook` function act on the same Cell object at the same time, if the `register_forward_pre_hook` and the `register_forward_hook` functions add other operators for data processing, these new operators will participate in the forward calculation of the data before or after the execution of the Cell object, but the backward gradient of these new operators is not captured by the `register_backward_hook` function. The Hook function registered in `register_backward_hook` only captures the input and output gradients of the original Cell object. +To avoid running failure when the scripts switch to graph mode, it is not recommended to call the `register_backward_hook` function and the `remove()` function of the `handle` object in the `construct` function of the Cell object. In PyNative mode, if the `register_backward_hook` function is called in the `construct` function of the Cell object, the Cell object will register a new Hook function every time it runs. + +For more information about the `register_backward_hook` function of the Cell object, please refer to the [API documentation](https://mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_backward_hook). + +## Using the multiple hook function of Cell Object + +When the `register_backward_pre_hook` function, the `register_backward_hook` function, the `register_forward_pre_hook` function, and the `register_forward_hook` function act on the same Cell object at the same time, if the `register_forward_pre_hook` and the `register_forward_hook` functions add other operators for data processing, these new operators will participate in the forward calculation of the data before or after the execution of the Cell object, but the backward gradient of these new operators is not captured by the `register_backward_pre_hook` function or the `register_backward_hook` function. The Hook function registered in `register_backward_pre_hook` only captures the input gradients of the original Cell object. The Hook function registered in `register_backward_hook` only captures the input and output gradients of the original Cell object. The sample code is as follows: @@ -594,7 +371,10 @@ def forward_hook_fn(cell, inputs, outputs): outputs = outputs + outputs return outputs -def backward_hook_fn(cell_id, grad_input, grad_output): +def backward_pre_hook_fn(cell, grad_output): + print("grad input: ", grad_output) + +def backward_hook_fn(cell, grad_input, grad_output): print("grad input: ", grad_input) print("grad output: ", grad_output) @@ -604,7 +384,8 @@ class Net(nn.Cell): self.relu = nn.ReLU() self.handle = self.relu.register_forward_pre_hook(forward_pre_hook_fn) self.handle2 = self.relu.register_forward_hook(forward_hook_fn) - self.handle3 = self.relu.register_backward_hook(backward_hook_fn) + self.handle3 = self.relu.register_backward_pre_hook(backward_pre_hook_fn) + self.handle4 = self.relu.register_backward_hook(backward_hook_fn) def construct(self, x, y): x = x + y @@ -621,13 +402,10 @@ print(gradient) forward inputs: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),) forward inputs: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),) forward outputs: [2.] +grad input: (Tensor(shape=[1], dtype=Float32, value= [ 1.00000000e+00]),) grad input: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),) grad output: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),) (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]), Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00])) ``` -Here `grad_input` is the gradient passed to `self.relu` when the gradient is back-propagated, not the gradient of the new `Add` operator in the `forward_hook_fn` function. Here `grad_output` is the reverse output gradient of the `self.relu` when the gradient is back-propagated, not the reverse output gradient of the new `Add` operator in the `forward_pre_hook_fn` function. The `register_forward_pre_hook` and `register_forward_hook` functions work before and after the execution of the Cell object and do not affect the gradient capture range of the reverse Hook function on the Cell object. - -To avoid running failure when the scripts switch to graph mode, it is not recommended to call the `register_backward_hook` function and the `remove()` function of the `handle` object in the `construct` function of the Cell object. In PyNative mode, if the `register_backward_hook` function is called in the `construct` function of the Cell object, the Cell object will register a new Hook function every time it runs. - -For more information about the `register_backward_hook` function of the Cell object, please refer to the [API documentation](https://mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_backward_hook). +Here `grad_output` is the gradient passed to `self.relu` when the gradient is back-propagated, not the gradient of the new `Add` operator in the `forward_hook_fn` function. Here `grad_input` is the reverse output gradient of the `self.relu` when the gradient is back-propagated, not the reverse output gradient of the new `Add` operator in the `forward_pre_hook_fn` function. The `register_forward_pre_hook` and `register_forward_hook` functions work before and after the execution of the Cell object and do not affect the gradient capture range of the reverse Hook function on the Cell object. diff --git a/tutorials/source_en/advanced/modules/initializer.md b/docs/mindspore/source_en/model_train/custom_program/initializer.md similarity index 96% rename from tutorials/source_en/advanced/modules/initializer.md rename to docs/mindspore/source_en/model_train/custom_program/initializer.md index 1f058dad09995c5220f16991f507dd5dfab2185c..9c9dfe6c51e335299891a28691b764ec3efe4335 100644 --- a/tutorials/source_en/advanced/modules/initializer.md +++ b/docs/mindspore/source_en/model_train/custom_program/initializer.md @@ -1,6 +1,6 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/modules/initializer.md) +# Custom Parameter Initialization -# Parameter Initialization +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/initializer.md) ## Initializing with Built-In Parameters diff --git a/docs/mindspore/source_en/model_train/custom_program/layer.md b/docs/mindspore/source_en/model_train/custom_program/layer.md new file mode 100644 index 0000000000000000000000000000000000000000..19660a338852280c359b1b5b635a5cc316d2ca82 --- /dev/null +++ b/docs/mindspore/source_en/model_train/custom_program/layer.md @@ -0,0 +1,198 @@ +# Cell and Parameter + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/layer.md) + +Cell, as the basic unit of neural network construction, corresponds to the concept of neural network layer, and the abstract encapsulation of Tensor computation operation can represent the neural network structure more accurately and clearly. In addition to the basic Tensor computation flow definition, the neural network layer contains functions such as parameter management and state management. Parameter is the core of neural network training and is usually used as an internal member variable of the neural network layer. In this section, we systematically introduce parameters, neural network layers and their related usage. + +## Parameter + +Parameter is a special class of Tensor, which is a variable whose value can be updated during model training. MindSpore provides the `mindspore.Parameter` class for Parameter construction. In order to distinguish between Parameter for different purposes, two different categories of Parameter are defined below. In order to distinguish between Parameter for different purposes, two different categories of Parameter are defined below: + +- Trainable parameter. Tensor that is updated after the gradient is obtained according to the backward propagation algorithm during model training, and `required_grad` needs to be set to `True`. +- Untrainable parameters. Tensor that does not participate in backward propagation needs to update values (e.g. `mean` and `var` variables in BatchNorm), when `requires_grad` needs to be set to `False`. + +> Parameter is set to `required_grad=True` by default. + +We construct a simple fully-connected layer as follows: + +```python +import numpy as np +import mindspore +from mindspore import nn +from mindspore import ops +from mindspore import Tensor, Parameter + +class Network(nn.Cell): + def __init__(self): + super().__init__() + self.w = Parameter(Tensor(np.random.randn(5, 3), mindspore.float32), name='w') # weight + self.b = Parameter(Tensor(np.random.randn(3,), mindspore.float32), name='b') # bias + + def construct(self, x): + z = ops.matmul(x, self.w) + self.b + return z + +net = Network() +``` + +In the `__init__` method of `Cell`, we define two parameters `w` and `b` and configure `name` for namespace management. Use `self.attr` in the `construct` method to call directly to participate in Tensor operations. + +### Obtaining Parameter + +After constructing the neural network layer by using Cell+Parameter, we can use various methods to obtain the Parameter managed by Cell. + +#### Obtaining a Single Parameter + +To get a particular parameter individually, just call a member variable of a Python class directly. + +```python +print(net.b.asnumpy()) +``` + +```text +[-1.2192779 -0.36789745 0.0946381 ] +``` + +#### Obtaining a Trainable Parameter + +Trainable parameters can be obtained by using the `Cell.trainable_params` method, and this interface is usually called when configuring the optimizer. + +```python +print(net.trainable_params()) +``` + +```text +[Parameter (name=w, shape=(5, 3), dtype=Float32, requires_grad=True), Parameter (name=b, shape=(3,), dtype=Float32, requires_grad=True)] +``` + +#### Obtaining All Parameters + +Use the `Cell.get_parameters()` method to get all parameters, at which point a Python iterator will be returned. + +```python +print(type(net.get_parameters())) +``` + +```text + +``` + +Or you can call `Cell.parameters_and_names` to return the parameter names and parameters. + +```python +for name, param in net.parameters_and_names(): + print(f"{name}:\n{param.asnumpy()}") +``` + +```text +w: +[[ 4.15680408e-02 -1.20311625e-01 5.02573885e-02] + [ 1.22175144e-04 -1.34980649e-01 1.17642188e+00] + [ 7.57667869e-02 -1.74758151e-01 -5.19092619e-01] + [-1.67846107e+00 3.27240258e-01 -2.06452996e-01] + [ 5.72323874e-02 -8.27963874e-02 5.94243526e-01]] +b: +[-1.2192779 -0.36789745 0.0946381 ] +``` + +### Modifying the Parameter + +#### Modifying Parameter Values Directly + +Parameter is a special kind of Tensor, so its value can be modified by using the Tensor index modification. + +```python +net.b[0] = 1. +print(net.b.asnumpy()) +``` + +```text +[ 1. -0.36789745 0.0946381 ] +``` + +#### Overriding the Modified Parameter Values + +The `Parameter.set_data` method can be called to override the Parameter by using a Tensor with the same Shape. This method is commonly used for [Cell traversal initialization](https://www.mindspore.cn/docs/en/master/model_train/custom_program/initializer.html) by using Initializer. + +```python +net.b.set_data(Tensor([3, 4, 5])) +print(net.b.asnumpy()) +``` + +```text +[3. 4. 5.] +``` + +#### Modifying Parameter Values During Runtime + +The main role of parameters is to update their values during model training, which involves parameter modification during runtime after backward propagation to obtain gradients, or when untrainable parameters need to be updated. Due to the compiled design of MindSpore's [Accelerating with Static Graphs](https://www.mindspore.cn/tutorials/en/master/beginner/accelerate_with_static_graph.html), it is necessary at this point to use the `mindspore.ops.assign` interface to assign parameters. This method is commonly used in [Custom Optimizer](https://www.mindspore.cn/docs/en/master/model_train/custom_program/optimizer.html) scenarios. The following is a simple sample modification of parameter values during runtime: + +```python +import mindspore as ms + +@ms.jit +def modify_parameter(): + b_hat = ms.Tensor([7, 8, 9]) + ops.assign(net.b, b_hat) + return True + +modify_parameter() +print(net.b.asnumpy()) +``` + +```text +[7. 8. 9.] +``` + +### Parameter Tuple + +ParameterTuple, variable tuple, used to store multiple Parameter, is inherited from tuple tuples, and provides cloning function. + +The following example provides the ParameterTuple creation method: + +```python +from mindspore.common.initializer import initializer +from mindspore import ParameterTuple +# Creation +x = Parameter(default_input=ms.Tensor(np.arange(2 * 3).reshape((2, 3))), name="x") +y = Parameter(default_input=initializer('ones', [1, 2, 3], ms.float32), name='y') +z = Parameter(default_input=2.0, name='z') +params = ParameterTuple((x, y, z)) + +# Clone from params and change the name to "params_copy" +params_copy = params.clone("params_copy") + +print(params) +print(params_copy) +``` + +```text +(Parameter (name=x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=z, shape=(), dtype=Float32, requires_grad=True)) +(Parameter (name=params_copy.x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=params_copy.y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=params_copy.z, shape=(), dtype=Float32, requires_grad=True)) +``` + +## Cell Training State Change + +Some Tensor operations in neural networks do not behave the same during training and inference, e.g., `nn.Dropout` performs random dropout during training but not during inference, and `nn.BatchNorm` requires updating the `mean` and `var` variables during training and fixing their values unchanged during inference. So we can set the state of the neural network through the `Cell.set_train` interface. + +When `set_train` is set to True, the neural network state is `train`, and the default value of `set_train` interface is `True`: + +```python +net.set_train() +print(net.phase) +``` + +```text +train +``` + +When `set_train` is set to False, the neural network state is `predict`: + +```python +net.set_train(False) +print(net.phase) +``` + +```text +predict +``` diff --git a/tutorials/source_en/advanced/modules/loss.md b/docs/mindspore/source_en/model_train/custom_program/loss.md similarity index 98% rename from tutorials/source_en/advanced/modules/loss.md rename to docs/mindspore/source_en/model_train/custom_program/loss.md index 0bb2565e1b2e9e86782f70b3c6f5b1cb2c982cce..a730240839d5cfc8aeee1cd8ead1a4fbe106bdb1 100644 --- a/tutorials/source_en/advanced/modules/loss.md +++ b/docs/mindspore/source_en/model_train/custom_program/loss.md @@ -1,6 +1,6 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/modules/loss.md) +# Custom Loss Function -# Loss Function +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/loss.md) A loss function is also called objective function and is used to measure the difference between a predicted value and an actual value. @@ -8,7 +8,7 @@ In deep learning, model training is a process of reducing the loss function valu The `mindspore.nn` module provides many [general loss functions](https://www.mindspore.cn/docs/en/master/api_python/mindspore.nn.html#loss-function), but these functions cannot meet all requirements. In many cases, you need to customize the required loss functions. The following describes how to customize loss functions. -![lossfun.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/modules/images/loss_function.png) +![lossfun.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/custom_program/images/loss_function.png) ## Built-in Loss Functions diff --git a/docs/mindspore/source_en/model_train/custom_program/network_custom.md b/docs/mindspore/source_en/model_train/custom_program/network_custom.md new file mode 100644 index 0000000000000000000000000000000000000000..5ea5ce7432520d937d13ca26a028fb51ab68cc5c --- /dev/null +++ b/docs/mindspore/source_en/model_train/custom_program/network_custom.md @@ -0,0 +1,98 @@ +# Custom Neural Network Layers + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/network_custom.md) + +Normally, the neural network layer interface and function interface provided by MindSpore can meet the model construction requirements, but since the AI field is constantly updating, it is possible to encounter new network structures without built-in modules. At this point, we can customize the neural network layer through the function interface provided by MindSpore, Primitive operator, and can use the `Cell.bprop` method to customize the reverse. The following are the details of each of the three customization methods. + +## Constructing Neural Network Layers by Using the Function Interface + +MindSpore provides a large number of basic function interfaces, which can be used to construct complex Tensor operations, encapsulated as neural network layers. The following is an example of `Threshold` with the following equation: + +$$ +y =\begin{cases} + x, &\text{ if } x > \text{threshold} \\ + \text{value}, &\text{ otherwise } + \end{cases} +$$ + +It can be seen that `Threshold` determines whether the value of the Tensor is greater than the `threshold` value, keeps the value whose judgment result is `True`, and replaces the value whose judgment result is `False`. Therefore, the corresponding implementation is as follows: + +```python +class Threshold(nn.Cell): + def __init__(self, threshold, value): + super().__init__() + self.threshold = threshold + self.value = value + + def construct(self, inputs): + cond = ops.gt(inputs, self.threshold) + value = ops.fill(inputs.dtype, inputs.shape, self.value) + return ops.select(cond, inputs, value) +``` + +Here `ops.gt`, `ops.fill`, and `ops.select` are used to implement judgment and replacement respectively. The following custom `Threshold` layer is implemented: + +```python +m = Threshold(0.1, 20) +inputs = mindspore.Tensor([0.1, 0.2, 0.3], mindspore.float32) +m(inputs) +``` + +```text +Tensor(shape=[3], dtype=Float32, value= [ 2.00000000e+01, 2.00000003e-01, 3.00000012e-01]) +``` + +It can be seen that `inputs[0] = threshold`, so it is replaced with `20`. + +## Custom Cell Reverse + +In special scenarios, we not only need to customize the forward logic of the neural network layer, but also want to manually control the computation of its reverse, which we can define through the `Cell.bprop` interface. The function will be used in scenarios such as new neural network structure design and backward propagation speed optimization. In the following, we take `Dropout2d` as an example to introduce custom Cell reverse. + +```python +class Dropout2d(nn.Cell): + def __init__(self, keep_prob): + super().__init__() + self.keep_prob = keep_prob + self.dropout2d = ops.Dropout2D(keep_prob) + + def construct(self, x): + return self.dropout2d(x) + + def bprop(self, x, out, dout): + _, mask = out + dy, _ = dout + if self.keep_prob != 0: + dy = dy * (1 / self.keep_prob) + dy = mask.astype(mindspore.float32) * dy + return (dy.astype(x.dtype), ) + +dropout_2d = Dropout2d(0.8) +dropout_2d.bprop_debug = True +``` + +The `bprop` method has three separate input parameters: + +- *x*: Forward input. When there are multiple forward inputs, the same number of inputs are required. +- *out*: Forward input. +- *dout*: When backward propagation is performed, the current Cell executes the previous reverse result. + +Generally we need to calculate the reverse result according to the reverse derivative formula based on the forward output and the reverse result of the front layer, and return it. The reverse calculation of `Dropout2d` requires masking the reverse result of the front layer based on the `mask` matrix of the forward output, and then scaling according to `keep_prob`. The final implementation can get the correct calculation result. + +When customizing the reverse direction of a Cell, it supports extended writing in PyNative mode and can differentiate the weights inside the Cell. The specific columns are as follows: + +```python +class NetWithParam(nn.Cell): + def __init__(self): + super(NetWithParam, self).__init__() + self.w = Parameter(Tensor(np.array([2.0], dtype=np.float32)), name='weight') + self.internal_params = [self.w] + + def construct(self, x): + output = self.w * x + return output + + def bprop(self, *args): + return (self.w * args[-1],), {self.w: args[0] * args[-1]} +``` + +`bprop` method supports *args as an input parameter, and the last data in the args array, `args[-1]` is the gradient returned to the cell. Set the weight of differentiation through `self.internal_params`, and return a tuple and a dictionary in the `bprop` function. Return the tuple corresponding to the input gradient, as well as the dictionary corresponding to the gradient with key as the weight and value as the weight. diff --git a/docs/mindspore/source_en/model_train/custom_program/op_custom.rst b/docs/mindspore/source_en/model_train/custom_program/op_custom.rst new file mode 100644 index 0000000000000000000000000000000000000000..8e8529b5697f299ce546085e46726fb336aa0268 --- /dev/null +++ b/docs/mindspore/source_en/model_train/custom_program/op_custom.rst @@ -0,0 +1,12 @@ +Custom Operators +================= + +.. toctree:: + :glob: + :maxdepth: 1 + + operation/op_custom + operation/ms_kernel + operation/op_custom_adv + operation/op_custom_aot + operation/op_custom_ascendc \ No newline at end of file diff --git a/tutorials/experts/source_en/operation/ms_kernel.md b/docs/mindspore/source_en/model_train/custom_program/operation/ms_kernel.md similarity index 99% rename from tutorials/experts/source_en/operation/ms_kernel.md rename to docs/mindspore/source_en/model_train/custom_program/operation/ms_kernel.md index 12647a9caa5d84cbc73200e54cf75c0ed02d2a53..c0ffeb4b5122b4f3317f8d0a1b8dad4899b6e750 100644 --- a/tutorials/experts/source_en/operation/ms_kernel.md +++ b/docs/mindspore/source_en/model_train/custom_program/operation/ms_kernel.md @@ -1,6 +1,6 @@ # MindSpore Hybrid Syntax Specification -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/operation/ms_kernel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/operation/ms_kernel.md) ## Overview diff --git a/tutorials/experts/source_en/operation/op_custom.md b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom.md similarity index 94% rename from tutorials/experts/source_en/operation/op_custom.md rename to docs/mindspore/source_en/model_train/custom_program/operation/op_custom.md index fa12a8ebeef72f68c4bb174f670bf546dfcef1cf..28a123db71c5447aed744c33c2059caae895aaf8 100644 --- a/tutorials/experts/source_en/operation/op_custom.md +++ b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom.md @@ -1,6 +1,6 @@ # Custom Operators (Custom-based) -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/operation/op_custom.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/operation/op_custom.md) ## Overview @@ -139,10 +139,10 @@ JIT (Just In Time) refers to operators compiled directly by the framework during A custom operator of Hybrid type is the default defined type of a custom operator. By using a custom operator of the Hybrid type, users can describe the operator calculation logic in Python-like syntax without paying attention to the engineering details defined by the operator for the MindSpore framework, allowing the user to focus on the algorithm itself. -Custom operators of Hybrid type use [MindSpore Hybrid DSL](https://www.mindspore.cn/tutorials/experts/en/master/operation/ms_kernel.html#syntax-specification) to describe the implementation of the calculation logic inside the operator. Functions defined with MindSpore Hybrid DSL can be parsed by the [AKG Operator Compiler](https://gitee.com/mindspore/akg) for JIT compilation to generate efficient operators for use in training reasoning for large-scale models. At the same time, the function defined by MindSpore Hybrid DSL can be called directly as a `numpy` function, which is convenient for users to debug and flexibly switch to [pyfunc type custom operator](#the-introduction-to-custom-operator-an-example), so that when developed, custom operator expressions are reused for multiple modes, multiple platforms and multiple scenes. +Custom operators of Hybrid type use [MindSpore Hybrid DSL](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/ms_kernel.html#syntax-specification) to describe the implementation of the calculation logic inside the operator. Functions defined with MindSpore Hybrid DSL can be parsed by the [AKG Operator Compiler](https://gitee.com/mindspore/akg) for JIT compilation to generate efficient operators for use in training reasoning for large-scale models. At the same time, the function defined by MindSpore Hybrid DSL can be called directly as a `numpy` function, which is convenient for users to debug and flexibly switch to [pyfunc type custom operator](#the-introduction-to-custom-operator-an-example), so that when developed, custom operator expressions are reused for multiple modes, multiple platforms and multiple scenes. The following example (test_custom_hybrid.py) shows how to write a custom operator of the hybrid type. The operator computes the sum of two tensors. -Notice that custom operators of Hybrid type use the source to source transformation method to connect the graph compiler and the operator compiler. Users can use the keywords of MindSpore Hybrid DSL directly in the script, such as `output_tensor` below, without importing any Python modules. For more information about the keywords, refer to [MindSpore Hybrid DSL Keywords](https://www.mindspore.cn/tutorials/experts/en/master/operation/ms_kernel.html#keywords). +Notice that custom operators of Hybrid type use the source to source transformation method to connect the graph compiler and the operator compiler. Users can use the keywords of MindSpore Hybrid DSL directly in the script, such as `output_tensor` below, without importing any Python modules. For more information about the keywords, refer to [MindSpore Hybrid DSL Keywords](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/ms_kernel.html#keywords). ```python import numpy as np @@ -198,7 +198,7 @@ The custom operator of akg type uses the [MindSpore AKG](https://gitee.com/minds Operator output shape and data type inference can be realized by defining Python functions to describe the inference logic of operator output shape and data type. -If the operator contains attributes or only supports specific input and output data types or data formats, operator information needs to be registered, and for how to generate operator information, see [Registering the Operator Information](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom_adv.html#registering-the-operator-information). If the operator information is not registered, when operator selection and mapping are made in the backend, the operator information is derived from the input of the current operator. +If the operator contains attributes or only supports specific input and output data types or data formats, operator information needs to be registered, and for how to generate operator information, see [Registering the Operator Information](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom_adv.html#registering-the-operator-information). If the operator information is not registered, when operator selection and mapping are made in the backend, the operator information is derived from the input of the current operator. The following is an example of the development process of a custom operator of type akg in test_custom_akg.py, where the custom operator implements the addition of two input tensors. @@ -252,7 +252,7 @@ For more complete examples of akg-type custom operators, see the [use cases](htt ## AOT-Compiled Custom Operator -AOT type of customized operator means that the user compiles the operator into a binary file beforehand and then accesses the network. Usually, users optimize their implementations using programming languages such as C/C++/CUDA and compile their operators as dynamic libraries to accelerate MindSpore networks. As a result, users can perform ultimate optimization on their operators and leverage the performance of the corresponding backend hardware. Here, we will introduce some basic knowledge about AOT type custom operators. For more advanced usage and functionality of AOT type custom operators, please refer to [Advanced Usage of AOT Type Custom Operators](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom_aot.html). +AOT type of customized operator means that the user compiles the operator into a binary file beforehand and then accesses the network. Usually, users optimize their implementations using programming languages such as C/C++/CUDA and compile their operators as dynamic libraries to accelerate MindSpore networks. As a result, users can perform ultimate optimization on their operators and leverage the performance of the corresponding backend hardware. Here, we will introduce some basic knowledge about AOT type custom operators. For more advanced usage and functionality of AOT type custom operators, please refer to [Advanced Usage of AOT Type Custom Operators](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom_aot.html). ### Defining Custom Operator of aot Type @@ -279,7 +279,7 @@ In the Python script, the format for the `func` input in `Custom` is `Path_To_Fu Operator output shape and data type inference can be realized by defining Python functions to describe the inference logic. -If the operator only supports some specific input and output data types, the operator information needs to be registered. For the creation of operator information, please refer to [Registering the Operator Information](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom_adv.html#registering-the-operator-information). +If the operator only supports some specific input and output data types, the operator information needs to be registered. For the creation of operator information, please refer to [Registering the Operator Information](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom_adv.html#registering-the-operator-information). The following examples introduce the development process of aot type custom operator on GPU platform and CPU platform, where the custom operator implements the function of adding two input tensors. @@ -452,7 +452,7 @@ The custom operator of julia type uses Julia to describe the internal calculatio Operator output shape and data type inference can be realized by defining Python functions to describe the inference logic of the operator output shape and the data type. -If the custom operator only supports specific input and output data types, you need to define the operator information. For the creation of operator information, please refer to [Registering the Operator Information](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom_adv.html#registering-the-operator-information). +If the custom operator only supports specific input and output data types, you need to define the operator information. For the creation of operator information, please refer to [Registering the Operator Information](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom_adv.html#registering-the-operator-information). Takes the function of adding two input tensors as an example to introduce how to define a custom operator of julia type. diff --git a/tutorials/experts/source_en/operation/op_custom_adv.md b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_adv.md similarity index 97% rename from tutorials/experts/source_en/operation/op_custom_adv.md rename to docs/mindspore/source_en/model_train/custom_program/operation/op_custom_adv.md index 7c9200c5d3eba55b266355cd43580a6ee5200f2a..bdfb5c162492c3bc67869aefdab35dbe2a2841e6 100644 --- a/tutorials/experts/source_en/operation/op_custom_adv.md +++ b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_adv.md @@ -1,6 +1,6 @@ # Custom Operator Registration -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/operation/op_custom_adv.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_adv.md) ## Registering the Operator Information diff --git a/tutorials/experts/source_en/operation/op_custom_aot.md b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_aot.md similarity index 99% rename from tutorials/experts/source_en/operation/op_custom_aot.md rename to docs/mindspore/source_en/model_train/custom_program/operation/op_custom_aot.md index f9df8c429679db6ef775f03d3867a331e4dba409..7487dc0b86c93f1eabd202c9648c9d947e6f2ece 100644 --- a/tutorials/experts/source_en/operation/op_custom_aot.md +++ b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_aot.md @@ -1,12 +1,12 @@ # Advanced Usage of aot-type Custom Operators -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/operation/op_custom_aot.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_aot.md) ## Overview aot-type custom operators use a pre-compilation approach, which requires developers to write the source code files for the corresponding function based on a specific interface, and compile the source code files in advance into a dynamic link library. Then, during network runtime, the framework will automatically call and execute the function in the dynamic link library. -aot-type custom operators support CUDA language for GPU platforms and C and C++ languages for CPU platforms. For basic knowledge of developing aot-type custom operators, please refer to [basic tutorial](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom.html#defining-custom-operator-of-aot-type). +aot-type custom operators support CUDA language for GPU platforms and C and C++ languages for CPU platforms. For basic knowledge of developing aot-type custom operators, please refer to [basic tutorial](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom.html#defining-custom-operator-of-aot-type). In this tutorial, we will demonstrate advanced features of aot-type custom operators, including: diff --git a/tutorials/experts/source_en/operation/op_custom_ascendc.md b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_ascendc.md similarity index 98% rename from tutorials/experts/source_en/operation/op_custom_ascendc.md rename to docs/mindspore/source_en/model_train/custom_program/operation/op_custom_ascendc.md index bb5c2de5086195983c291fd2dd7a46f0d58d6329..26e36e0dd88f632095a4b75a8cf6bd0abedc451e 100644 --- a/tutorials/experts/source_en/operation/op_custom_ascendc.md +++ b/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_ascendc.md @@ -1,7 +1,6 @@ - # Ascend C Custom Operator Development and Usage -[![View Source File](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/operation/op_custom_ascendc.md) +[![View Source File](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/operation/op_custom_ascendc.md) ## Overview @@ -192,8 +191,8 @@ net = CustomNet() ### Further Reading -- **Custom Operator Registration**: For more information on custom operator registration and the writing of backward functions, please refer to [Custom Operator Registration](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom_adv.html). -- **AOT Custom Operators**: For the implementation of C++ shape inference functions and advanced usage of AOT type custom operators, please refer to [Advanced Usage of AOT Type Custom Operators](https://www.mindspore.cn/tutorials/experts/en/master/operation/op_custom_aot.html). +- **Custom Operator Registration**: For more information on custom operator registration and the writing of backward functions, please refer to [Custom Operator Registration](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom_adv.html). +- **AOT Custom Operators**: For the implementation of C++ shape inference functions and advanced usage of AOT type custom operators, please refer to [Advanced Usage of AOT Type Custom Operators](https://www.mindspore.cn/docs/en/master/model_train/custom_program/operation/op_custom_aot.html). ## Common Issues diff --git a/tutorials/source_en/advanced/modules/optimizer.md b/docs/mindspore/source_en/model_train/custom_program/optimizer.md similarity index 98% rename from tutorials/source_en/advanced/modules/optimizer.md rename to docs/mindspore/source_en/model_train/custom_program/optimizer.md index 5e085a7c8c77e9ba5b60ec2f9f7dd90a16803b20..7a6e9fda9a09e78bb1491c4d144c5b0b750ac7e0 100644 --- a/tutorials/source_en/advanced/modules/optimizer.md +++ b/docs/mindspore/source_en/model_train/custom_program/optimizer.md @@ -1,12 +1,12 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/modules/optimizer.md) +# Custom Optimizer -# Optimizer +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/optimizer.md) During model training, the optimizer is used to update network parameters. A proper optimizer can effectively reduce the training time and improve model performance. The most basic optimizer is the stochastic gradient descent (SGD) algorithm. Many optimizers are improved based on the SGD to achieve the target function to converge to the global optimal point more quickly and effectively. The `nn` module in MindSpore provides common optimizers, such as `nn.SGD`, `nn.Adam`, and `nn.Momentum`. The following describes how to configure the optimizer provided by MindSpore and how to customize the optimizer. -![learningrate.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/modules/images/learning_rate.png) +![learningrate.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/custom_program/images/learning_rate.png) > For details about the optimizer provided by MindSpore, see [Optimizer API](https://www.mindspore.cn/docs/en/master/api_python/mindspore.nn.html#optimizer). diff --git a/docs/mindspore/source_en/model_train/custom_program/overview.md b/docs/mindspore/source_en/model_train/custom_program/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..66dc2b5b15c6078a27d77bbe2afba5d75e8c3c8a --- /dev/null +++ b/docs/mindspore/source_en/model_train/custom_program/overview.md @@ -0,0 +1,3 @@ +# Overview of Custom Higher-Order Programming + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/custom_program/overview.md) diff --git a/tutorials/experts/source_en/dataset/augment.md b/docs/mindspore/source_en/model_train/dataset/augment.md similarity index 98% rename from tutorials/experts/source_en/dataset/augment.md rename to docs/mindspore/source_en/model_train/dataset/augment.md index ba91e9e96f5aedbd410c1ae506c6a6404a0d15d5..fcb2fe439faf73315d81b34766cc43051af2fe2c 100644 --- a/tutorials/experts/source_en/dataset/augment.md +++ b/docs/mindspore/source_en/model_train/dataset/augment.md @@ -1,6 +1,6 @@ # Auto Augmentation -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/dataset/augment.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/augment.md) MindSpore not only allows you to customize data augmentation, but also provides an auto augmentation method to automatically perform data augmentation on images based on specific policies. @@ -350,7 +350,7 @@ Users can use the `RandomSelectSubpolicy` interface of the `mindspore.dataset.vi > For a better demonstration of the effect, only 5 images are loaded here, and no `shuffle` operation is performed when reading, nor `Normalize` and `HWC2CHW` operations are performed when automatic data augmentation is performed. -![augment](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/dataset/images/auto_augmentation.png) +![augment](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/auto_augmentation.png) The running result can be seen that the augmentation effect of each image in the batch, the vertical direction represents 5 images of 1 batch, and the horizontal direction represents 5 batches. diff --git a/tutorials/experts/source_en/dataset/cache.md b/docs/mindspore/source_en/model_train/dataset/cache.md similarity index 99% rename from tutorials/experts/source_en/dataset/cache.md rename to docs/mindspore/source_en/model_train/dataset/cache.md index 97f8f7045b49d5e7df7bb7b2bd4258df3a1b42d0..6f6269dbc857ab59565e69248c99d8cae8298880 100644 --- a/tutorials/experts/source_en/dataset/cache.md +++ b/docs/mindspore/source_en/model_train/dataset/cache.md @@ -1,6 +1,6 @@ # Single-Node Data Cache -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/dataset/cache.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/cache.md) If you need to repeatedly access remote datasets or load datasets from disks, you can use the single-node cache to cache datasets in the local memory to accelerate dataset loading. diff --git a/tutorials/experts/source_en/dataset/dataset_autotune.md b/docs/mindspore/source_en/model_train/dataset/dataset_autotune.md similarity index 96% rename from tutorials/experts/source_en/dataset/dataset_autotune.md rename to docs/mindspore/source_en/model_train/dataset/dataset_autotune.md index 32b628a10fec95de297ee9644e342cdfef00538e..2cdd01cd1dc60417a2299ac1679a6257bff753f6 100644 --- a/tutorials/experts/source_en/dataset/dataset_autotune.md +++ b/docs/mindspore/source_en/model_train/dataset/dataset_autotune.md @@ -1,6 +1,6 @@ # Dataset AutoTune for Dataset Pipeline -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/dataset/dataset_autotune.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/dataset_autotune.md) ## Overview @@ -57,7 +57,7 @@ print("tuning interval:", ds.config.get_autotune_interval()) ## Constraints - Both Dataset Profiling and Dataset AutoTune cannot be enabled concurrently, since Profiling's additional processing interferes with Dataset AutoTune's optimization processing. If both of them are enabled at the same time, a warning message will prompt the user to check whether there is a mistake. Do ensure Profiling is disabled when using Dataset AutoTune. -- [Offload for Dataset](https://www.mindspore.cn/tutorials/experts/en/master/dataset/dataset_offload.html) and Dataset AutoTune can be enabled simultaneously. If any dataset node has been offloaded for hardware acceleration, the more efficient dataset pipeline configuration file will not be stored and a warning will be logged, because the dataset pipeline that is actually running is not the predefined one. +- [Offload for Dataset](https://www.mindspore.cn/docs/en/master/model_train/dataset/dataset_offload.html) and Dataset AutoTune can be enabled simultaneously. If any dataset node has been offloaded for hardware acceleration, the more efficient dataset pipeline configuration file will not be stored and a warning will be logged, because the dataset pipeline that is actually running is not the predefined one. - If the Dataset pipeline consists of a node that does not support deserialization (e.g. user-defined Python functions, GeneratorDataset), any attempt to deserialize the saved and improved dataset pipeline configuration file will report an error. In this case, it is recommended to manually modify the dataset pipeline script based on the contents of the tuning configuration file to achieve the purpose of a more efficient dataset pipeline. - In the distributed training scenario, `set_enable_autotune()` must be called after cluster communication has been initialized (mindspore.communication.management.init()), otherwise AutoTune can only detect device with id 0 and create only one tuned file (the number of expected tuned files equal to the number of devices). See the following example: diff --git a/tutorials/experts/source_en/dataset/dataset_offload.md b/docs/mindspore/source_en/model_train/dataset/dataset_offload.md similarity index 98% rename from tutorials/experts/source_en/dataset/dataset_offload.md rename to docs/mindspore/source_en/model_train/dataset/dataset_offload.md index 94e7b6a08bd329bb052919547db1084ac9568224..dee3d7c17181003ce908d3e2f0a17bc7cb13bcb9 100644 --- a/tutorials/experts/source_en/dataset/dataset_offload.md +++ b/docs/mindspore/source_en/model_train/dataset/dataset_offload.md @@ -1,6 +1,6 @@ # Enabling Heterogeneous Acceleration for Data -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/dataset/dataset_offload.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/dataset_offload.md) ## Overview diff --git a/tutorials/source_en/advanced/dataset/eager.md b/docs/mindspore/source_en/model_train/dataset/eager.md similarity index 98% rename from tutorials/source_en/advanced/dataset/eager.md rename to docs/mindspore/source_en/model_train/dataset/eager.md index 624c497068f5f00fa2701cec4e159583d444d4ea..b2b0121610e5c57cca09196c09b83414d1e102c8 100644 --- a/tutorials/source_en/advanced/dataset/eager.md +++ b/docs/mindspore/source_en/model_train/dataset/eager.md @@ -1,4 +1,4 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/dataset/eager.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/eager.md) # Lightweight Data Processing diff --git a/tutorials/experts/source_en/dataset/images/auto_augmentation.png b/docs/mindspore/source_en/model_train/dataset/images/auto_augmentation.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/auto_augmentation.png rename to docs/mindspore/source_en/model_train/dataset/images/auto_augmentation.png diff --git a/tutorials/experts/source_en/dataset/images/autotune.png b/docs/mindspore/source_en/model_train/dataset/images/autotune.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/autotune.png rename to docs/mindspore/source_en/model_train/dataset/images/autotune.png diff --git a/tutorials/experts/source_en/dataset/images/cache_dataset.png b/docs/mindspore/source_en/model_train/dataset/images/cache_dataset.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/cache_dataset.png rename to docs/mindspore/source_en/model_train/dataset/images/cache_dataset.png diff --git a/tutorials/experts/source_en/dataset/images/cache_pipeline_en.eddx b/docs/mindspore/source_en/model_train/dataset/images/cache_pipeline_en.eddx similarity index 100% rename from tutorials/experts/source_en/dataset/images/cache_pipeline_en.eddx rename to docs/mindspore/source_en/model_train/dataset/images/cache_pipeline_en.eddx diff --git a/tutorials/experts/source_en/dataset/images/cache_processed_data.png b/docs/mindspore/source_en/model_train/dataset/images/cache_processed_data.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/cache_processed_data.png rename to docs/mindspore/source_en/model_train/dataset/images/cache_processed_data.png diff --git a/tutorials/experts/source_en/dataset/images/compose.png b/docs/mindspore/source_en/model_train/dataset/images/compose.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/compose.png rename to docs/mindspore/source_en/model_train/dataset/images/compose.png diff --git a/tutorials/source_en/advanced/dataset/images/data_conversion_concept.png b/docs/mindspore/source_en/model_train/dataset/images/data_conversion_concept.png similarity index 100% rename from tutorials/source_en/advanced/dataset/images/data_conversion_concept.png rename to docs/mindspore/source_en/model_train/dataset/images/data_conversion_concept.png diff --git a/tutorials/experts/source_en/dataset/images/data_conversion_concept.pptx b/docs/mindspore/source_en/model_train/dataset/images/data_conversion_concept.pptx similarity index 100% rename from tutorials/experts/source_en/dataset/images/data_conversion_concept.pptx rename to docs/mindspore/source_en/model_train/dataset/images/data_conversion_concept.pptx diff --git a/tutorials/experts/source_en/dataset/images/data_enhancement_performance_scheme.eddx b/docs/mindspore/source_en/model_train/dataset/images/data_enhancement_performance_scheme.eddx similarity index 100% rename from tutorials/experts/source_en/dataset/images/data_enhancement_performance_scheme.eddx rename to docs/mindspore/source_en/model_train/dataset/images/data_enhancement_performance_scheme.eddx diff --git a/tutorials/experts/source_en/dataset/images/data_enhancement_performance_scheme.png b/docs/mindspore/source_en/model_train/dataset/images/data_enhancement_performance_scheme.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/data_enhancement_performance_scheme.png rename to docs/mindspore/source_en/model_train/dataset/images/data_enhancement_performance_scheme.png diff --git a/tutorials/experts/source_en/dataset/images/data_loading_performance_scheme.png b/docs/mindspore/source_en/model_train/dataset/images/data_loading_performance_scheme.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/data_loading_performance_scheme.png rename to docs/mindspore/source_en/model_train/dataset/images/data_loading_performance_scheme.png diff --git a/tutorials/source_en/advanced/dataset/images/eager_mode.png b/docs/mindspore/source_en/model_train/dataset/images/eager_mode.png similarity index 100% rename from tutorials/source_en/advanced/dataset/images/eager_mode.png rename to docs/mindspore/source_en/model_train/dataset/images/eager_mode.png diff --git a/tutorials/source_en/advanced/dataset/images/eager_mode_en.jpeg b/docs/mindspore/source_en/model_train/dataset/images/eager_mode_en.jpeg similarity index 100% rename from tutorials/source_en/advanced/dataset/images/eager_mode_en.jpeg rename to docs/mindspore/source_en/model_train/dataset/images/eager_mode_en.jpeg diff --git a/tutorials/experts/source_en/dataset/images/map.eddx b/docs/mindspore/source_en/model_train/dataset/images/map.eddx similarity index 100% rename from tutorials/experts/source_en/dataset/images/map.eddx rename to docs/mindspore/source_en/model_train/dataset/images/map.eddx diff --git a/tutorials/source_en/advanced/dataset/images/mindrecord.png b/docs/mindspore/source_en/model_train/dataset/images/mindrecord.png similarity index 100% rename from tutorials/source_en/advanced/dataset/images/mindrecord.png rename to docs/mindspore/source_en/model_train/dataset/images/mindrecord.png diff --git a/tutorials/experts/source_en/dataset/images/mindrecord.pptx b/docs/mindspore/source_en/model_train/dataset/images/mindrecord.pptx similarity index 100% rename from tutorials/experts/source_en/dataset/images/mindrecord.pptx rename to docs/mindspore/source_en/model_train/dataset/images/mindrecord.pptx diff --git a/tutorials/experts/source_en/dataset/images/offload_process.PNG b/docs/mindspore/source_en/model_train/dataset/images/offload_process.PNG similarity index 100% rename from tutorials/experts/source_en/dataset/images/offload_process.PNG rename to docs/mindspore/source_en/model_train/dataset/images/offload_process.PNG diff --git a/tutorials/experts/source_en/dataset/images/operation_fusion.png b/docs/mindspore/source_en/model_train/dataset/images/operation_fusion.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/operation_fusion.png rename to docs/mindspore/source_en/model_train/dataset/images/operation_fusion.png diff --git a/tutorials/source_en/advanced/dataset/images/output_5_1.png b/docs/mindspore/source_en/model_train/dataset/images/output_5_1.png similarity index 100% rename from tutorials/source_en/advanced/dataset/images/output_5_1.png rename to docs/mindspore/source_en/model_train/dataset/images/output_5_1.png diff --git a/tutorials/source_en/advanced/dataset/images/output_7_1.png b/docs/mindspore/source_en/model_train/dataset/images/output_7_1.png similarity index 100% rename from tutorials/source_en/advanced/dataset/images/output_7_1.png rename to docs/mindspore/source_en/model_train/dataset/images/output_7_1.png diff --git a/tutorials/source_en/advanced/dataset/images/output_9_1.png b/docs/mindspore/source_en/model_train/dataset/images/output_9_1.png similarity index 100% rename from tutorials/source_en/advanced/dataset/images/output_9_1.png rename to docs/mindspore/source_en/model_train/dataset/images/output_9_1.png diff --git a/tutorials/experts/source_en/dataset/images/pipeline.png b/docs/mindspore/source_en/model_train/dataset/images/pipeline.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/pipeline.png rename to docs/mindspore/source_en/model_train/dataset/images/pipeline.png diff --git a/tutorials/source_en/advanced/dataset/images/pipeline_mode_en.jpeg b/docs/mindspore/source_en/model_train/dataset/images/pipeline_mode_en.jpeg similarity index 100% rename from tutorials/source_en/advanced/dataset/images/pipeline_mode_en.jpeg rename to docs/mindspore/source_en/model_train/dataset/images/pipeline_mode_en.jpeg diff --git a/tutorials/experts/source_en/dataset/images/shuffle_performance_scheme.png b/docs/mindspore/source_en/model_train/dataset/images/shuffle_performance_scheme.png similarity index 100% rename from tutorials/experts/source_en/dataset/images/shuffle_performance_scheme.png rename to docs/mindspore/source_en/model_train/dataset/images/shuffle_performance_scheme.png diff --git a/tutorials/experts/source_en/dataset/optimize.ipynb b/docs/mindspore/source_en/model_train/dataset/optimize.ipynb similarity index 97% rename from tutorials/experts/source_en/dataset/optimize.ipynb rename to docs/mindspore/source_en/model_train/dataset/optimize.ipynb index 1bfe3d2944b78cfe88e1b467671023880c9f1662..942e898315344cb8cd36e90ad8b3bad2eaa91bd6 100644 --- a/tutorials/experts/source_en/dataset/optimize.ipynb +++ b/docs/mindspore/source_en/model_train/dataset/optimize.ipynb @@ -7,7 +7,7 @@ "source": [ "# Optimizing the Data Processing\n", "\n", - "[![Download Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook_en.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/en/dataset/mindspore_optimize.ipynb) [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/dataset/optimize.ipynb)" + "[![Download Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook_en.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/en/model_train/dataset/mindspore_optimize.ipynb) [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/optimize.ipynb)" ] }, { @@ -23,7 +23,7 @@ "id": "4ff7dd16", "metadata": {}, "source": [ - "![pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/dataset/images/pipeline.png)" + "![pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/pipeline.png)" ] }, { @@ -111,7 +111,7 @@ "id": "05a69c00", "metadata": {}, "source": [ - "![data-loading-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/dataset/images/data_loading_performance_scheme.png)" + "![data-loading-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/data_loading_performance_scheme.png)" ] }, { @@ -122,14 +122,14 @@ "Suggestions on data loading performance optimization are as follows:\n", "\n", "- For commonly used datasets that have already provided loading interfaces, it is preferred to use the dataset loading interface provided by MindSpore to load, which can obtain better loading performance. For details, see [Built-in Dataset Loading Interfaces](https://www.mindspore.cn/docs/en/master/api_python/mindspore.dataset.html). If the performance cannot meet the requirements, use the multi-thread concurrency solution, i.e., adjust the parameter `num_parallel_workers`(default: 8) of the dataset interface to achieve a better performance.\n", - "- For a dataset format that is not supported, it is recommended to convert the dataset to the MindRecord data format before loading it using the `MindDataset` class (Please refer to the [API](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.MindDataset.html) for detailed use). For detailed contents, please refer to [Converting Dataset to MindRecord](https://www.mindspore.cn/tutorials/en/master/advanced/dataset/record.html). If the performance cannot meet the requirements, use the multi-thread concurrency solution, i.e., adjust the parameter `num_parallel_workers`(default: 8) of the dataset interface to achieve a better performance.\n", + "- For a dataset format that is not supported, it is recommended to convert the dataset to the MindRecord data format before loading it using the `MindDataset` class (Please refer to the [API](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.MindDataset.html) for detailed use). For detailed contents, please refer to [Converting Dataset to MindRecord](https://www.mindspore.cn/docs/en/master/model_train/dataset/record.html). If the performance cannot meet the requirements, use the multi-thread concurrency solution, i.e., adjust the parameter `num_parallel_workers`(default: 8) of the dataset interface to achieve a better performance.\n", "- For dataset formats that are not supported, the user-defined `GeneratorDataset` class is preferred for implementing fast algorithm verification (Please refer to the [API](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html) for detailed use). If the performance cannot meet the requirements, the multi-process / multi-thread concurrency solution can be used. For example:\n", "\n", " 1. Increase the parameter `num_parallel_workers`(default: 8) of the dataset interface to improve concurrency;\n", " 2. Set the parameter `python_multiprocessing`(default: True) of the dataset interface to True / False to enable multi-process / multi-thread concurrency mode. The multi-process mode achieves better performance in CPU-bound tasks, and multi-thread mode is better in IO bound tasks;\n", "\n", " **Note**: If you set `python_multiprocessing=True`(default: True) and `num_parallel_workers>1`(default: 1), which indicates that the multi-process mode is started for data load acceleration. At this time, as the dataset iterates, the memory consumption of the subprocess will gradually increase, mainly because the subprocess of the user-defined dataset obtains the member variables from the main process in the Copy On Write way. Example: If you define a dataset with `__init__` function which contains a large number of member variable data (for example, a very large file name list is loaded during the dataset construction) and uses the multi-process mode, which may cause the problem of OOM (the estimated total memory usage is: `(num_parallel_workers+1) * size of the parent process` ). The simplest solution is to replace python objects (such as list/dict/int/float/string) with non referenced data types (such as Pandas, Numpy or PyArrow objects) for member variables, or load less meta data in member variables, or configure `python_multiprocessing=False` using multi-threading mode.\n", - " 3. If there is `Using shared memory queue, but rowsize is larger than allocated memory ...` log prompt, then increace the parameter `max_rowsize`(default: 6M) of dataset interface to improve the efficiency of data transfer between processes.\n", + " 3. If there is `Using shared memory queue, but rowsize is larger than allocated memory ...` log prompt, then increase the parameter `max_rowsize` of dataset interface or set it to `None` to improve the efficiency of data transfer between processes.\n", "\n", "Based on the preceding suggestions of data loading performance optimization, this experience uses the built-in dataset load operation `Cifar10Dataset` class (Please refer to the [API](https://www.mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.Cifar10Dataset.html) for detailed use), the `MindDataset` class after data conversion, and uses the `GeneratorDataset` class to load data. The sample code is displayed as follows:\n", "\n", @@ -313,7 +313,7 @@ "id": "7c126623", "metadata": {}, "source": [ - "![shuffle-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/dataset/images/shuffle_performance_scheme.png)" + "![shuffle-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/shuffle_performance_scheme.png)" ] }, { @@ -475,7 +475,7 @@ "id": "2729405a", "metadata": {}, "source": [ - "![data-enhancement-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/dataset/images/data_enhancement_performance_scheme.png)" + "![data-enhancement-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/data_enhancement_performance_scheme.png)" ] }, { @@ -491,11 +491,11 @@ " 2. use fusion operator\n", " If the cpu usage is too high (For example: single-machine multi-card training), better performance can be achieved by using the fusion operation (aggregating the functions of two or more operations into one operation) to reduce the CPU consumption. You can make it effective by configuring the environment variable `export OPTIMIZE=true`. Examples of fusion are as follows:\n", "\n", - " ![operation-fusion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/dataset/images/operation_fusion.png)\n", + " ![operation-fusion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/operation_fusion.png)\n", " 3. use compose operator\n", " If the cpu usage is too high (For example: single-machine multi-card training), receive multiple augmentation operations through one map operation (these operations will be applied in order) to reduce CPU contention and achieve better performance. Examples are as follows:\n", "\n", - " ![compose](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/dataset/images/compose.png)" + " ![compose](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/compose.png)" ] }, { @@ -506,7 +506,7 @@ "- If the user-defined Python functions are used to perform data augmentation and the performance still cannot meet the requirements, refer to follow steps to improve. Or if the performance still cannot be improved, in this case, optimize the user-defined Python code.\n", " 1. Increase the parameter `num_parallel_workers`(default: 8) of the `map` interface to improve concurrency;\n", " 2. Set the parameter `python_multiprocessing`(default: True) of the `map` interface to True / False to enable multi-process / multi-thread concurrency mode. The multi-process mode achieves better performance in CPU-bound tasks, and multi-thread mode is better in IO bound tasks;\n", - " 3. If there is `Using shared memory queue, but rowsize is larger than allocated memory ...` log prompt, then increace the parameter `max_rowsize`(default: 6M) of `map` interface to improve the efficiency of data transfer between processes.\n", + " 3. If there is `Using shared memory queue, but rowsize is larger than allocated memory ...` log prompt, then increase the parameter `max_rowsize` of `map` interface or set it to `None` to improve the efficiency of data transfer between processes.\n", "\n", "Based on the preceding suggestions of data augmentation performance optimization, the C++ implemented operations and user-defined Python functions are used to perform data augmentation. The code is displayed as follows:\n", "\n", @@ -613,7 +613,7 @@ "- If `per_batch_map` is also configured, the recommended configuration is as follows:\n", " 1. Increase the parameter `num_parallel_workers`(default: 8) of the `batch` interface to improve concurrency;\n", " 2. Set the parameter `python_multiprocessing`(default: True) of the `batch` interface to True / False to enable multi-process / multi-thread concurrency mode. The multi-process mode achieves better performance in CPU-bound tasks, and multi-thread mode is better in IO bound tasks;\n", - " 3. If there is `Using shared memory queue, but rowsize is larger than allocated memory ...` log prompt, then increace the parameter `max_rowsize`(default: 6M) of `batch` interface to improve the efficiency of data transfer between processes." + " 3. If there is `Using shared memory queue, but rowsize is larger than allocated memory ...` log prompt, then increase the parameter `max_rowsize` of `batch` interface or set it to `None` to improve the efficiency of data transfer between processes." ] }, { @@ -629,7 +629,7 @@ "\n", " The data loading process involves frequent disk operations, and the performance of disk reading and writing directly affects the speed of data loading. Solid State Drive (SSD) is recommended for storing large datasets when the dataset is large. SSDs generally have higher read and write speeds than ordinary disks, reducing the impact of I/O operations on data processing performance.\n", "\n", - " In general, the loaded data will be cached into the operating system's page cache, which reduces the overhead of subsequent reads to a certain extent and accelerates the data loading speed of subsequent Epochs. Users can also manually cache the augmented data through the [single-node caching](https://www.mindspore.cn/tutorials/experts/en/master/dataset/cache.html) technology provided by MindSpore, avoiding duplicate data loading and data augmentation.\n", + " In general, the loaded data will be cached into the operating system's page cache, which reduces the overhead of subsequent reads to a certain extent and accelerates the data loading speed of subsequent Epochs. Users can also manually cache the augmented data through the [single-node caching](https://www.mindspore.cn/docs/en/master/model_train/dataset/cache.html) technology provided by MindSpore, avoiding duplicate data loading and data augmentation.\n", "\n", "2. NUMA architecture\n", "\n", @@ -708,7 +708,7 @@ "source": [ "## Dataset AutoTune for Dataset Pipeline\n", "\n", - "MindSpore provides a tool named Dataset AutoTune for optimizing dataset.The Dataset AutoTune can automatically tune Dataset pipelines to improve performance. The detailed usage please refer to [Dataset AutoTune for Dataset Pipeline](https://www.mindspore.cn/tutorials/experts/en/master/dataset/dataset_autotune.html)." + "MindSpore provides a tool named Dataset AutoTune for optimizing dataset.The Dataset AutoTune can automatically tune Dataset pipelines to improve performance. The detailed usage please refer to [Dataset AutoTune for Dataset Pipeline](https://www.mindspore.cn/docs/en/master/model_train/dataset/dataset_autotune.html)." ] }, { @@ -718,7 +718,7 @@ "source": [ "## Enabling Heterogeneous Acceleration for Data\n", "\n", - "MindSpore provides a computing load balancing technology which can distribute the MindSpore Tensor computing to different heterogeneous hardware. On one hand, it balances the computing overhead between different hardware, on the other hand, it uses the advantages of heterogeneous hardware to accelerate the computing. For the detailed usage, please refer to [Enabling Heterogeneous Acceleration for Data](https://www.mindspore.cn/tutorials/experts/en/master/dataset/dataset_offload.html)." + "MindSpore provides a computing load balancing technology which can distribute the MindSpore Tensor computing to different heterogeneous hardware. On one hand, it balances the computing overhead between different hardware, on the other hand, it uses the advantages of heterogeneous hardware to accelerate the computing. For the detailed usage, please refer to [Enabling Heterogeneous Acceleration for Data](https://www.mindspore.cn/docs/en/master/model_train/dataset/dataset_offload.html)." ] } ], diff --git a/docs/mindspore/source_en/model_train/dataset/overview.md b/docs/mindspore/source_en/model_train/dataset/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..4c390ad40aab3db1b0042cc276353f7a4b97a789 --- /dev/null +++ b/docs/mindspore/source_en/model_train/dataset/overview.md @@ -0,0 +1,3 @@ +# Data Processing Overview + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/overview.md) diff --git a/tutorials/source_en/advanced/dataset/python_objects.md b/docs/mindspore/source_en/model_train/dataset/python_objects.md similarity index 95% rename from tutorials/source_en/advanced/dataset/python_objects.md rename to docs/mindspore/source_en/model_train/dataset/python_objects.md index c11fe678091c37c7f29cdfce8f58a04a366a1157..0d0a7ff136a9debb2d3e8ddeb1e49b22670585f5 100644 --- a/tutorials/source_en/advanced/dataset/python_objects.md +++ b/docs/mindspore/source_en/model_train/dataset/python_objects.md @@ -1,4 +1,4 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/dataset/python_objects.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/python_objects.md) # Supporting Python Objects in Dataset Pipeline @@ -214,7 +214,7 @@ Output: In the model training/inference scenario, there are the following constraints when obtaining `dict` data from the data pipeline. -- In [data sink mode](https://mindspore.cn/tutorials/experts/en/master/optimize/execution_opt.html#data-sinking), since the data sink channel currently cannot support dictionary type data, sending dictionary type data to it will cause errors. Therefore, it is suggested to consider turning off the data sink mode (`dataset_sink_mode=False`), or expanding dictionary type data into list or tuple type data at the last data processing node, for example: +- In [data sink mode](https://www.mindspore.cn/docs/en/master/model_train/train_process/train_optimize.html#sinking-mode), since the data sink channel currently cannot support dictionary type data, sending dictionary type data to it will cause errors. Therefore, it is suggested to consider turning off the data sink mode (`dataset_sink_mode=False`), or expanding dictionary type data into list or tuple type data at the last data processing node, for example: ```python import numpy as np diff --git a/tutorials/source_en/advanced/dataset/record.ipynb b/docs/mindspore/source_en/model_train/dataset/record.ipynb similarity index 96% rename from tutorials/source_en/advanced/dataset/record.ipynb rename to docs/mindspore/source_en/model_train/dataset/record.ipynb index 43ca31b885470dff1ed14f1b8623766e8ee0ee91..bcbb137956c385531d6a8f25673dd266531e3d12 100644 --- a/tutorials/source_en/advanced/dataset/record.ipynb +++ b/docs/mindspore/source_en/model_train/dataset/record.ipynb @@ -5,7 +5,7 @@ "id": "f6392a05", "metadata": {}, "source": [ - "[![Download Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook_en.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/en/advanced/dataset/mindspore_record.ipynb) [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/dataset/record.ipynb)\n", + "[![Download Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook_en.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/en/model_train/dataset/mindspore_record.ipynb) [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/record.ipynb)\n", "\n", "# Converting Dataset to MindRecord" ] @@ -17,7 +17,7 @@ "source": [ "In MindSpore, the dataset used to train the network model can be converted into MindSpore-specific format data (MindSpore Record format), making it easier to save and load data. The goal is to normalize the user's dataset and further enable the reading of the data through the MindDataset interface and use it during the training process.\n", "\n", - "![conversion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_en/advanced/dataset/images/data_conversion_concept.png)\n", + "![conversion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/data_conversion_concept.png)\n", "\n", "In addition, the performance of MindSpore in some scenarios is optimized, and using the MindSpore Record data format can reduce disk IO and network IO overhead, which results in a better user experience.\n", "\n", @@ -38,7 +38,7 @@ "id": "1c420641", "metadata": {}, "source": [ - "![mindrecord](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_en/advanced/dataset/images/mindrecord.png)" + "![mindrecord](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/dataset/images/mindrecord.png)" ] }, { diff --git a/tutorials/source_en/advanced/dataset/sampler.md b/docs/mindspore/source_en/model_train/dataset/sampler.md similarity index 98% rename from tutorials/source_en/advanced/dataset/sampler.md rename to docs/mindspore/source_en/model_train/dataset/sampler.md index 8a12ead4c31420e853ccde6725657da060b79577..4570e9a6bfeeb782cae30f32b303635686e3873a 100644 --- a/tutorials/source_en/advanced/dataset/sampler.md +++ b/docs/mindspore/source_en/model_train/dataset/sampler.md @@ -1,4 +1,4 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/dataset/sampler.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/dataset/sampler.md) # Data Sampling @@ -12,7 +12,7 @@ MindSpore provides multiple samplers, such as `RandomSampler`, `WeightedRandomSa The following uses the CIFAR-10 dataset as an example to describe how to use several common MindSpore samplers. -![cifar10](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/dataset/images/cifar10.jpg) +![cifar10](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/cifar10.jpg) > The sample code in this section relies on `matplotlib`, which can be installed with the command `pip install matplotlib`. If the code is run in Notebook, you need to restart the kernel after the installation to execute the subsequent code. diff --git a/tutorials/experts/source_en/debug/aoe.md b/docs/mindspore/source_en/model_train/debug/aoe.md similarity index 96% rename from tutorials/experts/source_en/debug/aoe.md rename to docs/mindspore/source_en/model_train/debug/aoe.md index d58ed5544835a41eb1c122d954b5989589afb3c0..621226e9eff900750a60bdd0702d6c63d402fdc3 100644 --- a/tutorials/experts/source_en/debug/aoe.md +++ b/docs/mindspore/source_en/model_train/debug/aoe.md @@ -1,6 +1,6 @@ # Ascend Optimization Engine (AOE) -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/debug/aoe.md)   +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/aoe.md)   ## Overview diff --git a/docs/mindspore/source_en/model_train/debug/debug_tools.rst b/docs/mindspore/source_en/model_train/debug/debug_tools.rst new file mode 100644 index 0000000000000000000000000000000000000000..4e485fa6a9f3efeaa6a5541110d9be8921389503 --- /dev/null +++ b/docs/mindspore/source_en/model_train/debug/debug_tools.rst @@ -0,0 +1,10 @@ +Debugging Toolset +================= + +.. toctree:: + :maxdepth: 1 + + dump + rdr + fault_recover + sdc \ No newline at end of file diff --git a/tutorials/experts/source_en/debug/dump.md b/docs/mindspore/source_en/model_train/debug/dump.md similarity index 91% rename from tutorials/experts/source_en/debug/dump.md rename to docs/mindspore/source_en/model_train/debug/dump.md index dcf324ab718e6cd683d40ffd5ead059df513005a..e88a93e686e27e858309143c2ce90d14cb36f02b 100644 --- a/tutorials/experts/source_en/debug/dump.md +++ b/docs/mindspore/source_en/model_train/debug/dump.md @@ -1,13 +1,13 @@ # Using Dump in the Graph Mode -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/debug/dump.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/dump.md) -The input and output of the operator can be saved for debugging through the data dump when the training result deviates from the expectation. - -- For dynamic graph mode, the forward process can utilize Python's native execution capabilities, allowing users to view and record the corresponding inputs and outputs during the execution of the network script. The JIT and backward processes, which are part of graph compilation, can use synchronous dump functionality to save the input and output data of operators to disk files. +In order to analyze the training process, the user needs to perceive the input and output data of the operators during the training process. - For the static graph mode, MindSpore provides the Dump function to save the graph and the input and output data of the operator during model training to a disk file. +- For dynamic graph mode, the forward process can utilize Python's native execution capabilities, allowing users to view and record the corresponding inputs and outputs during the execution of the network script. The JIT and backward processes, which are part of graph compilation, can use synchronous dump functionality to save the input and output data of operators to disk files. + MindSpore provides two Dump modes: - Synchronous Dump: After the operator is dispatched, the Host side performs stream synchronization, initiates data copying from the Device side, and saves it to a file. @@ -15,10 +15,10 @@ MindSpore provides two Dump modes: > Different modes require different configuration files, and the generated data formats also differ: > -> - For GPU/CPU backends and Ascend backend with compilation levels O0/O1, it is recommended to use [synchronous dump](#synchronous-dump). For details, refer to [synchronous dump step](#synchronous-dump-step). For Ascend backend with compilation level O2, it is recommended to use [asynchronous dump](#asynchronous-dump). For details, refer to [asynchronous dump step](#asynchronous-dump-step). +> - For GPU/CPU backends and Ascend backend with compilation levels O0/O1, it is recommended to use [synchronous dump](#synchronous-dump). For details, refer to [synchronous dump step](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html#dump-step). For Ascend backend with compilation level O2, it is recommended to use [asynchronous dump](#asynchronous-dump). For details, refer to [asynchronous dump step](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html#dump-step-1). > - Currently, Dump does not support heterogeneous training. If Dump is enabled in a heterogeneous training scenario, the generated Dump data object directory may not match the expected directory structure. -The support for Synchronous Dump on Ascend backend is shown in the table below (GPU/CPU backend refers to the `O0/O1`) +The support for Synchronous Dump on Ascend backend is shown in the table below (GPU/CPU backend refers to the `O0/O1`). @@ -167,7 +167,7 @@ The support for Asynchronous Dump on Ascend backend is shown in the table below ### Dump Step -1. Create a configuration file in json format , and the name and location of the JSON file can be customized. +1. Create a configuration file in json format, and the name and location of the JSON file can be customized. ```json { @@ -199,8 +199,8 @@ The support for Asynchronous Dump on Ascend backend is shown in the table below - `saved_data`: Specify what data is to be dumped, type is string. Use "tensor" to indicate complete tensor data Dumped, use "statistic" to dump tensor statistics, use "full" to dump both tensor data and statistics. Synchronous statistics dump is only supported on GPU and Ascend. Using "statistic" or "full" on CPU will result in exception. Default setting is "tensor". Statistic dump is only supported when "op_debug_mode" is set to `0`. - `input_output`: 0: dump input and output of kernel, 1:dump input of kernel, 2:dump output of kernel. Only input of kernel can be saved when "op_debug_mode" is set to `4`. - `kernels`: This item can be configured in three formats: - 1. List of operator names. Turn on the IR save switch `set_context(save_graphs=2)` and execute the network to obtain the operator name from the generated `trace_code_graph_{graph_id}`IR file. For details, please refer to [Saving IR](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/mindir.html#saving-ir). - Note that whether setting `set_context(save_graphs=2)` may cause the different IDs of the same operator, so when dump specified operators, keep this setting unchanged after obtaining the operator name. Or you can obtain the operator names from the file `ms_output_trace_code_graph_{graph_id}.ir` saved by Dump. Refer to [Synchronous Dump Data Object Directory](#synchronous-dump-data-object-directory). + 1. List of operator names. Turn on the IR save switch `set_context(save_graphs=2)` and execute the network to obtain the operator name from the generated `trace_code_graph_{graph_id}`IR file. For details, please refer to [Saving IR](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindir.html#saving-ir). + Note that whether setting `set_context(save_graphs=2)` may cause the different IDs of the same operator, so when dump specified operators, keep this setting unchanged after obtaining the operator name. Or you can obtain the operator names from the file `ms_output_trace_code_graph_{graph_id}.ir` saved by Dump. Refer to [Synchronous Dump Data Object Directory](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html#introduction-to-data-object-directory-and-data-file). 2. You can also specify an operator type. When there is no operator scope information or operator id information in the string, the background considers it as an operator type, such as "conv". The matching rule of operator type is: when the operator name contains an operator type string, the matching is considered successful (case insensitive). For example, "conv" can match operators "Conv2D-op1234" and "Conv3D-op1221". 3. Regular expressions are supported. When the string conforms to the format of "name-regex(xxx)", it would be considered a regular expression. For example, "name-regex(Default/.+)" can match all operators with names starting with "Default/". - `support_device`: Supported devices, default setting is `[0,1,2,3,4,5,6,7]`. You can specify specific device ids to dump specific device data. This configuration parameter is invalid on the CPU, because there is no concept of device on the CPU, but it is still need to reserve this parameter in the json file. @@ -225,7 +225,7 @@ The support for Asynchronous Dump on Ascend backend is shown in the table below - `enable`: When set to true, enable Synchronous Dump. When set to false, asynchronous dump will be used on Ascend and synchronous dump will still be used on GPU. - `trans_flag`: Enable trans flag. Transform the device data format into NCHW. If it is `True`, the data will be saved in the 4D format (NCHW) format on the Host side; if it is `False`, the data format on the Device side will be retained. Default: `True`. - `stat_calc_mode`: Select the backend for statistical calculations. Options are "host" and "device". Choosing "device" enables device computation of statistics, currently only effective on Ascend, and supports only min/max/avg/l2norm statistics. - - `sample_mode`: Setting it to 0 means the sample dump function is not enabled. Enable the sample dump function in graph compilation with optimization level O0. This field is effective only when "op_debug_mode" is set to `0`, sample dump cannot be enabled in other scene. + - `sample_mode`: Setting it to 0 means the sample dump function is not enabled. Enable the sample dump function in graph compilation with optimization level O0 or O1. This field is effective only when "op_debug_mode" is set to `0`, sample dump cannot be enabled in other scene. - `sample_num`: Used to control the size of sample in sample dump. The default value is 100. 2. Set Dump environment variable. @@ -252,8 +252,8 @@ The support for Asynchronous Dump on Ascend backend is shown in the table below Note: - - Set the environment variables before executing the training script. Setting environment variables during training will not take effect. - - Dump environment variables need to be configured before calling `mindspore.communication.init`. + - Set the environment variables before executing the training script. Setting environment variables during training will not take effect. + - Dump environment variables need to be configured before calling `mindspore.communication.init`. 3. Execute the training script to dump data. @@ -261,9 +261,9 @@ The support for Asynchronous Dump on Ascend backend is shown in the table below In synchronous mode, if you want to dump data in GPU environment, you must use the non-data sink mode (set the `dataset_sink_mode` parameter in `model.train` or `DatasetHelper` to `False`) to ensure that you can get the dump data of each step. If `model.train` or `DatasetHelper` is not called in the script, the default is non-data sinking mode. Using the Dump function will automatically generate the IR file of the final execution graph. - You can set `set_context(reserve_class_name_in_scope=False)` in your training script to avoid dump failure because of file name is too long. + You can set `set_context(reserve_class_name_in_scope=False)` in your training script to avoid dump failure because of file name is too long. -4. Read and parse synchronous dump data through `numpy.load`, refer to [Introduction to Synchronous Dump Data File](#introduction-to-synchronous-dump-data-file). +4. Read and parse synchronous dump data through `numpy.load`, refer to [Introduction to Synchronous Dump Data File](#introduction-to-data-object-directory-and-data-file). ### Introduction to Data Object Directory and Data File @@ -522,7 +522,7 @@ MindSpore provides debugging capabilities for large networks through asynchronou } ``` - - `op_debug_mode`: This attribute is used for operator overflow debugging. 0: disable overflow check function; 3: enable overflow check function; 4: enable the lightweight exception dump function (this feature only takes effect when using ACL dump). Set it to 0 when Dump data is processed. If it is not set to 0, only the data of the overflow operator or exception operator will be dumped. + - `op_debug_mode`: This attribute is used for operator overflow debugging. 0: disable overflow check function; 3: enable overflow check function; 4: enable the lightweight exception dump function. Set it to 0 when Dump data is processed. If it is not set to 0, only the data of the overflow operator or exception operator will be dumped. - `dump_mode`: 0: all operator data in the network dumped out; 1: dump kernels data in kernels list. When overflow detection is enabled, the setting of this field becomes invalid, and Dump only saves the data of the overflow node. Specified data dump is supported only when "dump_mode' is set to `0`. - `path`: The absolute path to save Dump data. When the graph compilation level is O0, MindSpore will create a new subdirectory for each step in the path directory. - `net_name`: The customized net name: "ResNet50". @@ -550,7 +550,7 @@ MindSpore provides debugging capabilities for large networks through asynchronou This field is optional, with default values of ["max", "min", "l2norm"]. - - `file_format`: Dump file type. It can be either `npy` and `bin`. `npy`: data will be dumped in npy files as host format. `bin`: data will be dumped in protobuf file as device format and need to be transformed to parse using the provided data analysis tool. Please refer to [Asynchronous Dump Data Analysis Sample](#asynchronous-dump-data-analysis-sample) for details. The default value is `bin`. + - `file_format`: Dump file type. It can be either `npy` and `bin`. `npy`: data will be dumped in npy files as host format. `bin`: data will be dumped in protobuf file as device format and need to be transformed to parse using the provided data analysis tool. Please refer to [Asynchronous Dump Data Analysis Sample](#data-analysis-sample-1) for details. The default value is `bin`. 2. Set Dump environment variable. @@ -573,7 +573,7 @@ MindSpore provides debugging capabilities for large networks through asynchronou You can set `set_context(reserve_class_name_in_scope=False)` in your training script to avoid dump failure because of file name is too long. -4. Refer to [Asynchronous Dump Data Analysis Sample](#asynchronous-dump-data-analysis-sample) to analyze the Dump data file. +4. Refer to [Asynchronous Dump Data Analysis Sample](#data-analysis-sample-1) to analyze the Dump data file. > - If you need to dump all or part of the operator, you can modify the `dump_mode` option in the json configuration file to 0 or 1. > - Due to the slow Dump speed, enabling Dump in large model scenarios can extend the communication interval between different cards, leading to communication operator timeouts. This issue can be resolved by adjusting the timeout duration for the communication operators. For the Ascend backend, you can set the HCCL_EXEC_TIMEOUT environment variable. For detailed instructions, please refer to the [Ascend CANN documentation](https://www.hiascend.com/document/detail/zh/canncommercial/80RC1/apiref/envvar/envref_07_0072.html). @@ -587,12 +587,14 @@ When the graph compilation level is not O0 or O1, the Dump directory structure i - {step_id}/ - {time}/ - {device_id}/ - - {model_id}/ - - {iteration_id}/ - statistic.csv - {op_type}.{op_name}.{task_id}.{stream_id}.{timestamp} - Opdebug.Node_OpDebug.{task_id}.{stream_id}.{timestamp} - mapping.csv + - {model_name}/ + - {model_id}/ + - {iteration_id}/ + statistic.csv + {op_type}.{op_name}.{task_id}.{stream_id}.{timestamp} + Opdebug.Node_OpDebug.{task_id}.{stream_id}.{timestamp} + mapping.csv + acl_dump_{device_id}.json ``` When the graph compilation level is O0 or O1, the Dump directory structure is as follows. In this scenario, the dump files for aclop and aclnn operators will be saved in {device_id} directory, and the dump files for communication operators such as "ResuceSum" will be saved in {iteration_id} directory: @@ -613,6 +615,7 @@ When the graph compilation level is O0 or O1, the Dump directory structure is as {op_type}.{op_name}.{task_id}.{stream_id}.{timestamp} //aclop ops {op_name}.{op_type}.{task_id}.{stream_id}.{timestamp} //aclnn ops mapping.csv + acl_dump_{device_id}.json ``` - `path`: the absolute path set in the `data_dump.json` configuration file. @@ -628,6 +631,8 @@ When the graph compilation level is O0 or O1, the Dump directory structure is as - `timestamp`: the time stamp. - `step_id`: user side training step id. +The `acl_damp_{device_id}.json` file in the {path} directory is an intermediate file generated by asynchronous dump during interface calls, and generally does not need to be paid attention to. + The overflow file (file `Opdebug.Node_OpDebug.{task_id}.{stream_id}.{timestamp}`) is only saved when overflow dump is enabled and overflow is detected. If set `file_format` to `npy`, the operator file will be saved as a npy format file, and the overflow file will be saved as a json format file. The file naming formats are: @@ -655,13 +660,9 @@ Take the Conv2D-op12 of AlexNet network as an example: `Conv2D.Default_network-W If ".", "/", "\", and spaces appear in `op_type` and `op_name`, they will be converted to underscores. -The original data file generated by dump can also be parsed by using the data parsing tool DumpParser of MindSpore Insight. Please refer to [DumpParser Introduction](https://gitee.com/mindspore/mindinsight/blob/master/mindinsight/parser/README.md#) for the usage of DumpParser. The data format parsed by MindSpore Insight is exactly the same as that of synchronous dump. - -If setting `file_format` to `npy`, the naming convention of data files generated by asynchronous dump is the same as those of synchronous dump. Please refer to [Introduction to Synchronous Dump Data File](#introduction-to-synchronous-dump-data-file). The overflow file generated by overflow detection is in the `json` format, and the content analysis of the overflow file can refer to the [Analyzing the Data File of an Overflow/Underflow Operator](https://www.hiascend.com/document/detail/en/CANNCommunityEdition/600alphaX/infacldevg/aclcppdevg/aclcppdevg_000160.html) . - -The `saved_data` option only takes effect when `file_format` is "npy". If `saved_data` is "statistic" or "full", tensor statistics will be dumped in `statistic.csv`. When `saved_data` is "tensor" or "full", full tensor data will be dumped in `{op_type}.{op_name}.{task_id}.{stream_id}.{timestamp}.{input_output_index}.{slot}.{format}.npy`. The format of the statistic file will be the same as that of synchonous dump. Please refer to [Introduction to Synchronous Dump Data File](#introduction-to-synchronous-dump-data-file). +If setting `file_format` to `npy`, the naming convention of data files generated by asynchronous dump is the same as those of synchronous dump. Please refer to [Introduction to Synchronous Dump Data File](#introduction-to-data-object-directory-and-data-file). The overflow file generated by overflow detection is in the `json` format, and the content analysis of the overflow file can refer to the [Analyzing the Data File of an Overflow/Underflow Operator](https://www.hiascend.com/document/detail/en/CANNCommunityEdition/600alphaX/infacldevg/aclcppdevg/aclcppdevg_000160.html) . -The constant dump file, final execution graph file and execution order file naming rules generated by asynchronous Dump are the same as that of synchronous Dump. You can refer to [Introduction to Synchronous Dump Data File](#introduction-to-synchronous-dump-data-file). +The `saved_data` option only takes effect when `file_format` is "npy". If `saved_data` is "statistic" or "full", tensor statistics will be dumped in `statistic.csv`. When `saved_data` is "tensor" or "full", full tensor data will be dumped in `{op_type}.{op_name}.{task_id}.{stream_id}.{timestamp}.{input_output_index}.{slot}.{format}.npy`. The format of the statistic file will be the same as that of synchonous dump. Please refer to [Introduction to Synchronous Dump Data File](#introduction-to-data-object-directory-and-data-file). ### Data Analysis Sample @@ -728,13 +729,13 @@ Through the asynchronous Dump function, the data files generated by the operator In some special scenarios, the GE dump mode can be applied under development guidance. -To enable GE dump, set the environment variable MINDSPORE_DUMP_CONFIG and ENABLE_MS_GE_DUMP to 1. This mode applies only to the scenario where the compilation level of the graph is O2. The format of the configuration file is the same as that of the acl dump configuration file. The op_debug_mode field cannot be set to 4. Other parameters are the same as those of the acl dump configuration file. +To enable GE dump, set the environment variable MINDSPORE_DUMP_CONFIG and ENABLE_MS_GE_DUMP to 1. This mode applies only to the scenario where the compilation level of the graph is O2. The format of the configuration file is the same as that of the asynchronous dump configuration file. The op_debug_mode field cannot be set to 4. Other parameters are the same as those of the asynchronous dump configuration file. ```bash export ENABLE_MS_GE_DUMP=1 ``` -When GE dump is enabled, and the graph compilation level is O2, the Dump directory structure of the graph pattern is as follows: +The GE Dump directory structure is as follows: ```text {path}/ @@ -749,7 +750,7 @@ When GE dump is enabled, and the graph compilation level is O2, the Dump directo mapping.csv ``` -Among them, the meanings of `path`, `time`, `device_id`, `model_name`, `model_id`, `iteration_id`, `op_type`, `op_name`, `task_id`, `stream_id`, and `timestamp` are the same as those of ACL dump. +Among them, the meanings of `path`, `time`, `device_id`, `model_name`, `model_id`, `iteration_id`, `op_type`, `op_name`, `task_id`, `stream_id`, and `timestamp` are the same as those of asynchronous dump. This method will be abandoned in the future and is not recommended for use. @@ -759,4 +760,4 @@ This method will be abandoned in the future and is not recommended for use. - Dump only supports saving data with type of bool, int, int8, in16, int32, int64, uint, uint8, uint16, uint32, uint64, float, float16, float32, float64, bfloat16, double, complex64 and complex128. - Complex64 and complex128 only support saving as npy files, not as statistics information. - The Print operator has an input parameter with type of string, which is not a data type supported by Dump. Therefore, when the Print operator is included in the script, there will be an error log, which will not affect the saving data of other types. -- When ACL dump is enabled, lite exception dump is not supported by using set_context(ascend_config={"exception_dump": "2"), while full exception dump is supported by using set_context(ascend_config={"exception_dump": "1"). +- When asynchronous dump is enabled, lite exception dump is not supported by using set_context(ascend_config={"exception_dump": "2"), while full exception dump is supported by using set_context(ascend_config={"exception_dump": "1"). diff --git a/tutorials/source_en/advanced/error_analysis.rst b/docs/mindspore/source_en/model_train/debug/error_analysis.rst similarity index 95% rename from tutorials/source_en/advanced/error_analysis.rst rename to docs/mindspore/source_en/model_train/debug/error_analysis.rst index 07798416257a34f134d96d86bd5be8b72e253a0c..b2ffb433859e496b1b496129b7aa66a03384bbfa 100644 --- a/tutorials/source_en/advanced/error_analysis.rst +++ b/docs/mindspore/source_en/model_train/debug/error_analysis.rst @@ -2,7 +2,7 @@ Error Reporting Analysis ========================= .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/error_analysis.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/error_analysis.rst :alt: View Source on Gitee .. toctree:: @@ -53,7 +53,7 @@ Understanding the meaning of error description information plays an important ro MindSpore error messages are processed by using Python Traceback processing, including Python stack information, error types and error descriptions, error messages related to networkdevelopers, and error messages related to framework developers. As shown in the following figure: -.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/images/graph_errmsg.png +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/debug/images/graph_errmsg.png - Python stack information: @@ -83,7 +83,7 @@ The general process of MindSpore network training is data loading and processing 3) Analyze the location where the error is reported based on the Python call stack and the error information. In dynamic graph mode, it is easier to determine the location of the code error. In the static graph mode, you need to analyze the location of the error report according to the error message "The Traceback of Net Construct Code" part of the error message. 4) Based on possible error problem scenarios and types, hypothesize the possible causes of the error problem. -Please refer to error analysis for details on how to perform `error analysis `_ based on different scenarios. +Please refer to error analysis for details on how to perform `error analysis `_ based on different scenarios. Error Search ^^^^^^^^^^^^^ @@ -205,8 +205,8 @@ Network execution debugging is the corresponding debugging capability provided b | | | | | +---------------------------+------------------------------------------+-------------------------------------------------------------------------------------------------------------+-------------------------------------------------------+ | | metrics | When the training is finished, | `MindSpore metrics function | -| | | metrics can be used to evaluate the training results. | introduction `_ | +---------------------------+------------------------------------------+-------------------------------------------------------------------------------------------------------------+-------------------------------------------------------+ | | print\_ interface | The print\_ interface prints out the Tensor or | `print\_ interface introduction `_ | | | | | | +---------------------------+------------------------------------------+-------------------------------------------------------------------------------------------------------------+-------------------------------------------------------+ -| | Intermediate file saving | Used to save the intermediate files generated | `Reading IR `_ | +---------------------------+------------------------------------------+-------------------------------------------------------------------------------------------------------------+-------------------------------------------------------+ | | Data Dump | When training the network, if the training result deviates from the expectation, | `Dump function debugging `_ | +| | | the operator input and output data are saved for debugging by the Du mp function. | docs/en/master/model_train/debug/dump.html>`_ | +---------------------------+------------------------------------------+-------------------------------------------------------------------------------------------------------------+-------------------------------------------------------+ | Execution control | Callback | Users can use callback functions to perform specific actions | `Callback mechanism `_ | +---------------------------+------------------------------------------+-------------------------------------------------------------------------------------------------------------+-------------------------------------------------------+ | | Hook | The Hook function in pynative mode captures the input and output data | `Hook function `_ | +| | | and the backward gradient of the middle layer operator. | docs/en/master/model_train/custom_program/ | +| | | Four forms of Hook functions are available: | hook_program.html>`_ | | | | HookBackward operator and register_forward_pre_hook, register_forward_hook, | | | | | and register_backward_hook functions | | | | | registered on the Cell object. | | @@ -255,11 +255,11 @@ MindSpore provides framework developers with rich debugging tools. Debugging fea +-------------------------+--------------------------+---------------------------------------------------------------+-------------------------------------------------------+ | Data records | RDR | Running Data Recorder (RDR) provides the ability | `Running Data Recorder | | | | to record framework execution status data | `_ | +| | | while the training program is running. | docs/en/master/model_train/debug/rdr.html>`_ | | | | It can also save key frame state data, such as IR, | | | | | graph execution order, | | +-------------------------+--------------------------+---------------------------------------------------------------+-------------------------------------------------------+ | Specialized control | Memory reuse | Configure memory reuse on and off for troubleshooting | `Memory Reuse `_ | +-------------------------+--------------------------+---------------------------------------------------------------+-------------------------------------------------------+ diff --git a/tutorials/source_en/advanced/error_analysis/cann_error_cases.md b/docs/mindspore/source_en/model_train/debug/error_analysis/cann_error_cases.md similarity index 99% rename from tutorials/source_en/advanced/error_analysis/cann_error_cases.md rename to docs/mindspore/source_en/model_train/debug/error_analysis/cann_error_cases.md index c85e598acf0438d2219c8f37c57211fea3e028a1..9a30c1d93cce45c6f7076aee7b822aab37d15162 100644 --- a/tutorials/source_en/advanced/error_analysis/cann_error_cases.md +++ b/docs/mindspore/source_en/model_train/debug/error_analysis/cann_error_cases.md @@ -1,6 +1,6 @@ # CANN Common Error Analysis -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/error_analysis/cann_error_cases.md)   +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/error_analysis/cann_error_cases.md)   This article focuses on the handling of common CANN errors by users. When encountering CANN errors, MindSpore logs may not be sufficient to analyze the related errors. You can print CANN logs to better analyze the errors by setting the following two environment variables: diff --git a/tutorials/source_en/advanced/error_analysis/error_scenario_analysis.md b/docs/mindspore/source_en/model_train/debug/error_analysis/error_scenario_analysis.md similarity index 88% rename from tutorials/source_en/advanced/error_analysis/error_scenario_analysis.md rename to docs/mindspore/source_en/model_train/debug/error_analysis/error_scenario_analysis.md index 333e7b8c8b643154746cc35ccdec1fd04717478a..e2540a341e744fb3b06663262143327c77c0c33f 100644 --- a/tutorials/source_en/advanced/error_analysis/error_scenario_analysis.md +++ b/docs/mindspore/source_en/model_train/debug/error_analysis/error_scenario_analysis.md @@ -1,6 +1,6 @@ # Error Analysis -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/error_analysis/error_scenario_analysis.md)   +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/error_analysis/error_scenario_analysis.md)   As mentioned before, error analysis refers to analyzing and inferring possible error causes based on the obtained network and framework information (such as error messages and network code). @@ -10,7 +10,7 @@ During error analysis, the first step is to identify the scenario where the erro When an error is reported during data processing, check whether C++ error messages are contained as shown in Figure 1. Typically, the name of the data processing operation using the C++ language is the same as that using Python. Therefore, you can determine the data processing operation that reports the error based on the error message and locate the error in the Python code. -![minddata-errmsg](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/error_analysis/images/minddata_errmsg.png) +![minddata-errmsg](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/minddata_errmsg.png) *Figure 1* @@ -20,9 +20,9 @@ Data loading and processing has three phases: data preparation, data loading, an | Error Type| Error Description| Case Analysis| |-------------|---------|---| -| Data preparation error| The dataset is faulty, involving a path or MindRecord file problem.| [Error Case](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/minddata_debug.html)| -| Data loading error| Incorrect resource configuration, customized loading method, or iterator usage in the data loading phase.| [Error Case](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/minddata_debug.html)| -| Data augmentation error| Unmatched data format/size, high resource usage, or multi-thread suspension.| [Error Case](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/minddata_debug.html)| +| Data preparation error| The dataset is faulty, involving a path or MindRecord file problem.| [Error Case](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/minddata_debug.html)| +| Data loading error| Incorrect resource configuration, customized loading method, or iterator usage in the data loading phase.| [Error Case](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/minddata_debug.html)| +| Data augmentation error| Unmatched data format/size, high resource usage, or multi-thread suspension.| [Error Case](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/minddata_debug.html)| ## Network Construction and Training Error Analysis @@ -32,11 +32,11 @@ The following table lists common network construction and training errors. | Error Type | Error Description| Case Analysis| | - | - | - | -| Incorrect context configuration| An error occurs when the system configures the context.| [Error Analysis](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/mindrt_debug.html)| -| Syntax error | Python syntax errors and MindSpore static graph syntax errors, such as unsupported control flow syntax and tensor slicing errors| [Error Analysis](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/mindrt_debug.html)| -| Operator build error | The operator parameter value, type, or shape does not meet the requirements, or the operator function is restricted.| [Error Analysis](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/mindrt_debug.html)| -| Operator execution error | Input data exceptions, operator implementation errors, function restrictions, resource restrictions, etc.| [Error Analysis](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/mindrt_debug.html)| -| Insufficient resources | The device memory is insufficient, the number of function call stacks exceeds the threshold, and the number of flow resources exceeds the threshold.| [Error Analysis](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/mindrt_debug.html)| +| Incorrect context configuration| An error occurs when the system configures the context.| [Error Analysis](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindrt_debug.html)| +| Syntax error | Python syntax errors and MindSpore static graph syntax errors, such as unsupported control flow syntax and tensor slicing errors| [Error Analysis](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindrt_debug.html)| +| Operator build error | The operator parameter value, type, or shape does not meet the requirements, or the operator function is restricted.| [Error Analysis](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindrt_debug.html)| +| Operator execution error | Input data exceptions, operator implementation errors, function restrictions, resource restrictions, etc.| [Error Analysis](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindrt_debug.html)| +| Insufficient resources | The device memory is insufficient, the number of function call stacks exceeds the threshold, and the number of flow resources exceeds the threshold.| [Error Analysis](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindrt_debug.html)| ### Error Analysis of the Dynamic Graph Mode @@ -44,7 +44,7 @@ In dynamic graph mode, the program is executed line by line according to the cod Generally, the error message may contain `WARNING` logs. During error analysis, analyze the error message following Traceback first. -![pynative-errmsg](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/error_analysis/images/pynative_errmsg.png) +![pynative-errmsg](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/pynative_errmsg.png) *Figure 2* @@ -58,7 +58,7 @@ In dynamic graph mode, common network construction and training errors are found In static graph mode, MindSpore builds the network structure into a computational graph, and then performs the computation operations involved in the graph. Therefore, errors reported in static graph mode include computational graph build errors and computational graph execution errors. Figure 3 shows the error message reported during computational graph build. When an error occurs, the `analyze_failed.ir` file is automatically saved to help analyze the location of the error code. -![graph-errmsg](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/images/graph_errmsg.png) +![graph-errmsg](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/debug/images/graph_errmsg.png) *Figure 3* @@ -69,9 +69,9 @@ Check whether the error is caused by graph build or graph execution based on the - If the error is reported during computational graph build, analyze the cause and location of the failure based on the error description and the `analyze_failed.ir` file automatically saved when the error occurs. - If the error is reported during computational graph execution, the error may be caused by insufficient resources or improper operator execution. You need to further distinguish the error based on the error message. If the error is reported during operator execution, locate the operator, use the dump function to save the input data of the operator, and analyze the cause of the error based on the input data. -For details about how to analyze and infer the failure cause, see the analysis methods described in [`analyze_failed.ir`](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/mindir.html#how-to-derive-the-cause-of-the-failure-based-on-the-analyze-fail-ir-file-analysis-graph). +For details about how to analyze and infer the failure cause, see the analysis methods described in [`analyze_failed.ir`](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/mindir.html#how-to-derive-the-cause-of-the-failure-based-on-the-analyze-fail-ir-file-analysis-graph). -For details about how to use Dump to save the operator input data, see [Dump Function Debugging](https://www.mindspore.cn/tutorials/experts/en/master/debug/dump.html). +For details about how to use Dump to save the operator input data, see [Dump Function Debugging](https://www.mindspore.cn/docs/en/master/model_train/debug/dump.html). ## Distributed Parallel Error Analysis @@ -274,11 +274,11 @@ Among the 4-bit error codes, 0000~8999 are user-class errors and 9000~9999 are i | Common Error Types | Error Description | Case Analysis | | - | - | - | -| AICORE Operator Compilation Problem | AICORE Operator Error During Compilation | [AICORE Operator Compilation Problem](https://www.mindspore.cn/tutorials/en/master/advanced/error_analysis/cann_error_cases.html#aicore-operator-compilation-problem)| -| AICORE Operator Execution Problem | AICORE Operator Error During Execution| [AICORE Operator Execution Problem](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/cann_error_cases.html#aicore-operator-execution-problem) | -| AICPU Operator Execution Problem | AICPU Operator Error During Execution | [AICPU Operator Execution Problem](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/cann_error_cases.html#aicpu-operator-execution-problem) | -| runtime FAQ | Including input data exceptions, operator implementation errors, functional limitations, resource limitations, etc. | [runtime FAQ](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/cann_error_cases.html#runtime-faq) | -| HCCL & HCCP FAQ | Common communication problems during multi-machine multi-card training, including socket build timeout, notify wait timeout, ranktable configuration error, etc. | [HCCL & HCCP FAQ](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/cann_error_cases.html#hccl-hccp-faq) | -| profiling FAQ | Errors when running profiling for performance tuning | [profiling FAQ](https://mindspore.cn/tutorials/en/master/advanced/error_analysis/cann_error_cases.html#profiling-faq) | +| AICORE Operator Compilation Problem | AICORE Operator Error During Compilation | [AICORE Operator Compilation Problem](https://www.mindspore.cn/docs/en/master/model_train/debug/error_analysis/cann_error_cases.html#aicore-operator-compilation-problem)| +| AICORE Operator Execution Problem | AICORE Operator Error During Execution| [AICORE Operator Execution Problem](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/cann_error_cases.html#aicore-operator-execution-problem) | +| AICPU Operator Execution Problem | AICPU Operator Error During Execution | [AICPU Operator Execution Problem](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/cann_error_cases.html#aicpu-operator-execution-problem) | +| runtime FAQ | Including input data exceptions, operator implementation errors, functional limitations, resource limitations, etc. | [runtime FAQ](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/cann_error_cases.html#runtime-faq) | +| HCCL & HCCP FAQ | Common communication problems during multi-machine multi-card training, including socket build timeout, notify wait timeout, ranktable configuration error, etc. | [HCCL & HCCP FAQ](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/cann_error_cases.html#hccl-hccp-faq) | +| profiling FAQ | Errors when running profiling for performance tuning | [profiling FAQ](https://mindspore.cn/docs/en/master/model_train/debug/error_analysis/cann_error_cases.html#profiling-faq) | For more information about CANN errors, refer to the [Ascend CANN Developer Documentation](https://www.hiascend.com/document/moreVersion/zh/CANNCommunityEdition/) to check the troubleshooting section of the corresponding CANN version. diff --git a/tutorials/source_en/advanced/error_analysis/images/dot_to_png.png b/docs/mindspore/source_en/model_train/debug/error_analysis/images/dot_to_png.png similarity index 100% rename from tutorials/source_en/advanced/error_analysis/images/dot_to_png.png rename to docs/mindspore/source_en/model_train/debug/error_analysis/images/dot_to_png.png diff --git a/tutorials/source_en/advanced/error_analysis/minddata_debug.md b/docs/mindspore/source_en/model_train/debug/error_analysis/minddata_debug.md similarity index 99% rename from tutorials/source_en/advanced/error_analysis/minddata_debug.md rename to docs/mindspore/source_en/model_train/debug/error_analysis/minddata_debug.md index 3083d378ecf7fb182d2ddca6cc335e658e6f06ec..a916317210a8fb5dfa1fc1a34f2fc95ae79d9ccb 100644 --- a/tutorials/source_en/advanced/error_analysis/minddata_debug.md +++ b/docs/mindspore/source_en/model_train/debug/error_analysis/minddata_debug.md @@ -1,6 +1,6 @@ # Data Processing Debugging Methods and Common Errors Analysis -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/error_analysis/minddata_debug.md)   +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/error_analysis/minddata_debug.md)   ## Data Processing Debugging Methods diff --git a/tutorials/source_en/advanced/error_analysis/mindir.md b/docs/mindspore/source_en/model_train/debug/error_analysis/mindir.md similarity index 99% rename from tutorials/source_en/advanced/error_analysis/mindir.md rename to docs/mindspore/source_en/model_train/debug/error_analysis/mindir.md index 1f15f5569d054c3054b6049ac6469c10f49ccb9b..e7a43b559a96b7498030e752a705a5d3c615d19f 100644 --- a/tutorials/source_en/advanced/error_analysis/mindir.md +++ b/docs/mindspore/source_en/model_train/debug/error_analysis/mindir.md @@ -1,6 +1,6 @@ # IR File Analysis -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/error_analysis/mindir.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/error_analysis/mindir.md) ## Overview diff --git a/tutorials/source_en/advanced/error_analysis/mindrt_debug.md b/docs/mindspore/source_en/model_train/debug/error_analysis/mindrt_debug.md similarity index 98% rename from tutorials/source_en/advanced/error_analysis/mindrt_debug.md rename to docs/mindspore/source_en/model_train/debug/error_analysis/mindrt_debug.md index 046a08210042afb6f7b52801c7bf633b30a0c72b..ef7d981521f1351dfe8159f2ccc3b8f3d77c5c57 100644 --- a/tutorials/source_en/advanced/error_analysis/mindrt_debug.md +++ b/docs/mindspore/source_en/model_train/debug/error_analysis/mindrt_debug.md @@ -1,6 +1,6 @@ # Network Construction and Training Error Analysis -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/error_analysis/mindrt_debug.md)   +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/error_analysis/mindrt_debug.md)   The following lists the common network construction and training errors in static graph mode. diff --git a/tutorials/experts/source_en/debug/fault_recover.md b/docs/mindspore/source_en/model_train/debug/fault_recover.md similarity index 98% rename from tutorials/experts/source_en/debug/fault_recover.md rename to docs/mindspore/source_en/model_train/debug/fault_recover.md index ee68c8b0db6ac05744a05ad603cee1826bccb0be..d89929b1db4a801a043f8e8ff678d44deb71c217 100644 --- a/tutorials/experts/source_en/debug/fault_recover.md +++ b/docs/mindspore/source_en/model_train/debug/fault_recover.md @@ -1,6 +1,6 @@ # Fault Recovery -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/debug/fault_recover.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/fault_recover.md) ## Overview diff --git a/tutorials/experts/source_en/optimize/graph_fusion_engine.md b/docs/mindspore/source_en/model_train/debug/graph_fusion_engine.md similarity index 97% rename from tutorials/experts/source_en/optimize/graph_fusion_engine.md rename to docs/mindspore/source_en/model_train/debug/graph_fusion_engine.md index 8a3a00a00020475c3330a65285d13bac51205def..02087affbb6ffd78ed4b7162a9be36c6c52ed16e 100644 --- a/tutorials/experts/source_en/optimize/graph_fusion_engine.md +++ b/docs/mindspore/source_en/model_train/debug/graph_fusion_engine.md @@ -1,6 +1,6 @@ # Enabling Graph Kernel Fusion -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/optimize/graph_fusion_engine.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/graph_fusion_engine.md) ## Introduction diff --git a/tutorials/experts/source_zh_cn/optimize/images/data-and-graph-sink.eddx b/docs/mindspore/source_en/model_train/debug/images/data-and-graph-sink.eddx similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/data-and-graph-sink.eddx rename to docs/mindspore/source_en/model_train/debug/images/data-and-graph-sink.eddx diff --git a/tutorials/experts/source_en/optimize/images/graph_kernel_example_custom_op.png b/docs/mindspore/source_en/model_train/debug/images/graph_kernel_example_custom_op.png similarity index 100% rename from tutorials/experts/source_en/optimize/images/graph_kernel_example_custom_op.png rename to docs/mindspore/source_en/model_train/debug/images/graph_kernel_example_custom_op.png diff --git a/tutorials/experts/source_en/optimize/images/graph_kernel_example_fuse_basic.png b/docs/mindspore/source_en/model_train/debug/images/graph_kernel_example_fuse_basic.png similarity index 100% rename from tutorials/experts/source_en/optimize/images/graph_kernel_example_fuse_basic.png rename to docs/mindspore/source_en/model_train/debug/images/graph_kernel_example_fuse_basic.png diff --git a/tutorials/experts/source_en/optimize/mem_reuse.md b/docs/mindspore/source_en/model_train/debug/mem_reuse.md similarity index 90% rename from tutorials/experts/source_en/optimize/mem_reuse.md rename to docs/mindspore/source_en/model_train/debug/mem_reuse.md index 760ce39cbdbbaaa60efb992e9a8cd1ca7ae936a4..546d47caf5b6ade6f1a5b6a1f4acaaa5068b7e37 100644 --- a/tutorials/experts/source_en/optimize/mem_reuse.md +++ b/docs/mindspore/source_en/model_train/debug/mem_reuse.md @@ -1,6 +1,6 @@ # Memory Reuse -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/optimize/mem_reuse.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/mem_reuse.md) ## Overview diff --git a/docs/mindspore/source_en/model_train/debug/opt_tools.rst b/docs/mindspore/source_en/model_train/debug/opt_tools.rst new file mode 100644 index 0000000000000000000000000000000000000000..9934ebfe8d32892fb1c21ba8ebbc1e905bed3411 --- /dev/null +++ b/docs/mindspore/source_en/model_train/debug/opt_tools.rst @@ -0,0 +1,9 @@ +Tuning Toolset +================== + +.. toctree:: + :maxdepth: 1 + + graph_fusion_engine + mem_reuse + aoe \ No newline at end of file diff --git a/docs/mindspore/source_en/model_train/debug/overview.md b/docs/mindspore/source_en/model_train/debug/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..e5f2a02b299928aaa295c601a952f4cd5e189187 --- /dev/null +++ b/docs/mindspore/source_en/model_train/debug/overview.md @@ -0,0 +1,3 @@ +# Overview of Debugging and Tuning + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/overview.md) diff --git a/tutorials/experts/source_en/debug/rdr.md b/docs/mindspore/source_en/model_train/debug/rdr.md similarity index 96% rename from tutorials/experts/source_en/debug/rdr.md rename to docs/mindspore/source_en/model_train/debug/rdr.md index 6ebd5082611572bb05fb781e75b7c4c890b5fa65..d00b6ae926c48b59f79a731319df7ddb7d3159c4 100644 --- a/tutorials/experts/source_en/debug/rdr.md +++ b/docs/mindspore/source_en/model_train/debug/rdr.md @@ -1,6 +1,6 @@ # Running Data Recorder -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/debug/rdr.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/rdr.md) ## Overview diff --git a/tutorials/experts/source_en/debug/sdc.md b/docs/mindspore/source_en/model_train/debug/sdc.md similarity index 98% rename from tutorials/experts/source_en/debug/sdc.md rename to docs/mindspore/source_en/model_train/debug/sdc.md index be1d457af531500476e463789df04c9a56d911e9..c046dfff5d966d190037ba6a5ada9b3dce57f396 100644 --- a/tutorials/experts/source_en/debug/sdc.md +++ b/docs/mindspore/source_en/model_train/debug/sdc.md @@ -1,6 +1,6 @@ # Feature Value Detection -[![View Source File](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/debug/sdc.md) +[![View Source File](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/debug/sdc.md) ## Overview diff --git a/tutorials/experts/source_en/index.rst b/docs/mindspore/source_en/model_train/index.rst similarity index 34% rename from tutorials/experts/source_en/index.rst rename to docs/mindspore/source_en/model_train/index.rst index 86db53df9a156b31b92a6358058c2cd35b8686e1..7fd872592be2e154f851a8553304b0f56a33c415 100644 --- a/tutorials/experts/source_en/index.rst +++ b/docs/mindspore/source_en/model_train/index.rst @@ -1,92 +1,86 @@ -.. MindSpore documentation master file, created by - sphinx-quickstart on Thu Mar 24 11:00:00 2022. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -For Experts -========================= +Model Building and Training +================================= .. toctree:: :glob: :maxdepth: 1 - :caption: Distributed Parallel - :titlesonly: + :caption: Programming Forms - parallel/overview - parallel/startup_method - parallel/data_parallel - parallel/semi_auto_parallel - parallel/auto_parallel - parallel/manual_parallel - parallel/parameter_server_training - parallel/model_save_load - parallel/recover - parallel/optimize_technique - parallel/others - parallel/distributed_case - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: Custom Operator - - operation/op_custom - operation/ms_kernel - operation/op_custom_adv - operation/op_custom_aot - operation/op_custom_ascendc + program_form/overview + program_form/pynative + program_form/static_graph + program_form/jit + program_form/interface + program_form/index_support .. toctree:: :glob: :maxdepth: 1 - :caption: Performance Optimization - - Profiling↗ - optimize/execution_opt - optimize/graph_fusion_engine - optimize/mem_reuse + :caption: Custom High-order Programming + + custom_program/overview + custom_program/layer + custom_program/op_custom + custom_program/initializer + custom_program/loss + custom_program/optimizer + custom_program/fusion_pass + custom_program/network_custom + custom_program/hook_program .. toctree:: :glob: :maxdepth: 1 - :caption: Algorithm Optimization + :caption: Data Loading and Processing - optimize/gradient_accumulation - optimize/thor + dataset/overview + dataset/sampler + dataset/record + dataset/eager + dataset/python_objects + dataset/augment + dataset/cache + dataset/optimize .. toctree:: :glob: :maxdepth: 1 - :caption: High-level Functional Programming + :caption: Training Process - vmap/vmap - func_programming/Jacobians_Hessians - func_programming/per_sample_gradients + train_process/overview + train_process/model + train_process/dynamic_shape + train_process/train_optimize + train_process/func_programming + train_process/derivation + train_process/algorithm_optimize .. toctree:: :glob: :maxdepth: 1 - :caption: Data Processing + :caption: Distributed Parallelism - dataset/augment - dataset/cache - dataset/optimize + parallel/overview + parallel/startup_method + parallel/data_parallel + parallel/semi_auto_parallel + parallel/auto_parallel + parallel/manual_parallel + parallel/parameter_server_training + parallel/model_save_load + parallel/recover + parallel/optimize_technique + parallel/others + parallel/distributed_case .. toctree:: :glob: :maxdepth: 1 - :caption: Model Inference - - infer/inference - infer/model_compression + :caption: Dubugging and Tuning -.. toctree:: - :glob: - :maxdepth: 1 - :caption: Complex Problem Debugging + debug/overview + debug/error_analysis + debug/debug_tools + debug/opt_tools + Error Map↗ - debug/dump - debug/aoe - debug/rdr - debug/fault_recover - debug/sdc \ No newline at end of file diff --git a/tutorials/experts/source_en/parallel/advanced_operator_parallel.md b/docs/mindspore/source_en/model_train/parallel/advanced_operator_parallel.md similarity index 84% rename from tutorials/experts/source_en/parallel/advanced_operator_parallel.md rename to docs/mindspore/source_en/model_train/parallel/advanced_operator_parallel.md index 3a098f829ce35d52cb996e8d5c907f9ffaf9eebd..02dbe7712c58e783cba53640a748ea652a30bc14 100644 --- a/tutorials/experts/source_en/parallel/advanced_operator_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/advanced_operator_parallel.md @@ -1,24 +1,24 @@ # Higher-order Operator-level Parallelism -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/advanced_operator_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/advanced_operator_parallel.md) ## Overview -[Operator-level Parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/operator_parallel.html) is a commonly used parallelism technique in large model training inference, which can slice the tensor across multiple cards and effectively reduce GPU memory on a single card. MindSpore is configured for operator-level parallelism by describing tensor slicing in tuples for each input of the operator through mindspore.ops.Primitive.shard() interface, which is easy to configure for most scenarios. Accordingly, this type of slicing only describes the tensor slicing but shields the tensor layout on the device rank from the users, and thus expresses a limited mapping between tensor slicing and device ranking, which cannot support slicing for some more complex scenarios. Therefore, this tutorial will introduce an operator-level parallel configuration method of the open device layout description. +[Operator-level Parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/operator_parallel.html) is a commonly used parallelism technique in large model training inference, which can slice the tensor across multiple cards and effectively reduce GPU memory on a single card. MindSpore is configured for operator-level parallelism by describing tensor slicing in tuples for each input of the operator through mindspore.ops.Primitive.shard() interface, which is easy to configure for most scenarios. Accordingly, this type of slicing only describes the tensor slicing but shields the tensor layout on the device rank from the users, and thus expresses a limited mapping between tensor slicing and device ranking, which cannot support slicing for some more complex scenarios. Therefore, this tutorial will introduce an operator-level parallel configuration method of the open device layout description. > Hardware platforms supported for advanced operator-level parallel models include Ascend, GPUs, and need to be run in Graph mode. ## Background -[Operator-level Parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/operator_parallel.html) describes MindSpore basic slicing logic for tensors, but cannot express all the slicing scenarios. For a 2D tensor "[[a0, a1, a2, a3], [a4, a5, a6, a7]]", the tensor layout is shown below: +[Operator-level Parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/operator_parallel.html) describes MindSpore basic slicing logic for tensors, but cannot express all the slicing scenarios. For a 2D tensor "[[a0, a1, a2, a3], [a4, a5, a6, a7]]", the tensor layout is shown below: -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/advanced_operator_parallel_view1.PNG) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/advanced_operator_parallel_view1.PNG) *Figure: Schematic of 2D tensor arrangement* It can be seen that the 0-axis of the tensor, e.g. "[a0, a1, a2, a3]" slices to the discontinuous card "[Rank0, Rank4, Rank2, Rank6]" and the tensor is sliced according to strategy=(2, 4), the arrangement should be as follows: -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/advanced_operator_parallel_view2.PNG) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/advanced_operator_parallel_view2.PNG) *Figure: Schematic of a 2D tensor arranged according to a sharding strategy* @@ -43,7 +43,7 @@ a_strategy = layout("mp", ("sp", "dp")) Notice that the "[a0, a1, a2, a3]" of the tensor a is sliced twice to the "sp" and "mp" axes of the device, so that the result comes out as: -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/advanced_operator_parallel_view1.PNG) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/advanced_operator_parallel_view1.PNG) The following is exemplified by a concrete example in which the user computes a two-dimensional matrix multiplication over 8 cards: `Y = (X * W)` , where the devices are organized according to `2 * 2 * 2`, and the cut of X coincides with the cut of the tensor a described above: @@ -237,4 +237,4 @@ epoch: 0, step: 90, loss is 0.7807965 ... ``` -Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). \ No newline at end of file +Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). \ No newline at end of file diff --git a/tutorials/experts/source_en/parallel/auto_parallel.rst b/docs/mindspore/source_en/model_train/parallel/auto_parallel.rst similarity index 90% rename from tutorials/experts/source_en/parallel/auto_parallel.rst rename to docs/mindspore/source_en/model_train/parallel/auto_parallel.rst index 7ca0baccf59ab85b3467d1aa23f6313e003b8b22..2d2d3c3cd8b9b4f7795a3a57ed15368ae120a305 100644 --- a/tutorials/experts/source_en/parallel/auto_parallel.rst +++ b/docs/mindspore/source_en/model_train/parallel/auto_parallel.rst @@ -2,7 +2,7 @@ Automatic Parallel ======================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/auto_parallel.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/auto_parallel.rst :alt: View Source on Gitee .. toctree:: @@ -14,8 +14,8 @@ Automatic Parallel The auto-parallel mode allows the user to automatically build the cost model and find a parallel strategy with shorter training time without paying attention to the strategy configuration. Currently MindSpore supports the following two different auto-parallel schemes: -- `Sharding Strategy Propagation Algorithm `_: propagation of parallel strategy from operators configured with parallel strategy to operators not configured. When propagating, the algorithm tries to pick the strategy that triggers the least amount of tensor rearranging communication. -- `Double Recursive Strategy Search Algorithm `_: Its cost model based on symbolic operations can be freely adapted to different accelerator clusters, and can generate optimal strategy fast for huge networks and large-scale multi-card slicing. +- `Sharding Strategy Propagation Algorithm `_: propagation of parallel strategy from operators configured with parallel strategy to operators not configured. When propagating, the algorithm tries to pick the strategy that triggers the least amount of tensor rearranging communication. +- `Double Recursive Strategy Search Algorithm `_: Its cost model based on symbolic operations can be freely adapted to different accelerator clusters, and can generate optimal strategy fast for huge networks and large-scale multi-card slicing. Auto-parallel algorithm is the strategy search algorithm based on the operator-level model parallel, and to understand the principles, it is first necessary to understand the basic concepts in MindSpore operator-level parallel: distributed operators, tensor arranging, and tensor rearranging. Operator-level parallel is an implementation of Single Program Multiple Data (SPMD). The same program is executed on different data slices. MindSpore converts a stand-alone version of a program into a parallel version. The conversion is fine-grained, replacing each operator in the stand-alone version of the program with a distributed operator, while ensuring that the replacement is mathematically equivalent. diff --git a/tutorials/experts/source_en/parallel/comm_fusion.md b/docs/mindspore/source_en/model_train/parallel/comm_fusion.md similarity index 98% rename from tutorials/experts/source_en/parallel/comm_fusion.md rename to docs/mindspore/source_en/model_train/parallel/comm_fusion.md index 1ed2cc20a04cc5745940dfadc3cb217928a22628..d01cc7b2fb35286ee3664cc87ac4b0f8496425d1 100644 --- a/tutorials/experts/source_en/parallel/comm_fusion.md +++ b/docs/mindspore/source_en/model_train/parallel/comm_fusion.md @@ -1,6 +1,6 @@ # Distributed Training Communication Fusion -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/comm_fusion.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/comm_fusion.md) ## Overview @@ -33,7 +33,7 @@ The whole process of distributed training can be roughly divided into two proces As shown in the figure below, each node backs up the complete neural network model and uses the local dataset partition to train a mini-batch for forward and backward computation. The gradient obtained from the backward computation is synchronized across the nodes, and the training of the next mini-batch continues after synchronization, and so on, until the accuracy/loss reaches a threshold, or a certain number of epochs are trained. It can be seen that computation and communication alternate in the distributed training process. Work has been done on how to do pipelining of interdependent computation and transmission to reduce the percentage of cross-node data synchronization in the overall training duration [5][6], which will not be repeated here. -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/data_parallel.png) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/data_parallel.png) ### The Necessity of Communication Fusion diff --git a/tutorials/experts/source_en/parallel/comm_subgraph.md b/docs/mindspore/source_en/model_train/parallel/comm_subgraph.md similarity index 98% rename from tutorials/experts/source_en/parallel/comm_subgraph.md rename to docs/mindspore/source_en/model_train/parallel/comm_subgraph.md index 768679e4d97cb3cd869128062b166a712aa28cc8..f6022502eb9d2aed5693c068d0cc67d442d044be 100644 --- a/tutorials/experts/source_en/parallel/comm_subgraph.md +++ b/docs/mindspore/source_en/model_train/parallel/comm_subgraph.md @@ -1,6 +1,6 @@ # Communication Subgraph Extraction and Reuse -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/comm_subgraph.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/comm_subgraph.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/data_parallel.md b/docs/mindspore/source_en/model_train/parallel/data_parallel.md similarity index 98% rename from tutorials/experts/source_en/parallel/data_parallel.md rename to docs/mindspore/source_en/model_train/parallel/data_parallel.md index e215edec03ecdb9711e8bf96ffaa4e4698067be2..12dca669e4151f1e8b705c06ade20317eb2a53d3 100644 --- a/tutorials/experts/source_en/parallel/data_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/data_parallel.md @@ -1,6 +1,6 @@ # Data Parallel -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/data_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/data_parallel.md) ## Overview @@ -210,4 +210,4 @@ epoch: 0 step: 30, loss is 2.2938071 ... ``` -Other startup methods such as dynamic network and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). +Other startup methods such as dynamic network and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). diff --git a/tutorials/experts/source_en/parallel/dataset_slice.md b/docs/mindspore/source_en/model_train/parallel/dataset_slice.md similarity index 98% rename from tutorials/experts/source_en/parallel/dataset_slice.md rename to docs/mindspore/source_en/model_train/parallel/dataset_slice.md index 7dc99e3969a49e8db1b4623d4c3854547e2d108c..c59ac105ed8718d253f8c6bd6d7fdb597eec47c8 100644 --- a/tutorials/experts/source_en/parallel/dataset_slice.md +++ b/docs/mindspore/source_en/model_train/parallel/dataset_slice.md @@ -1,6 +1,6 @@ # Dataset Slicing -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/dataset_slice.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/dataset_slice.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/disaster_recover.md b/docs/mindspore/source_en/model_train/parallel/disaster_recover.md similarity index 96% rename from tutorials/experts/source_en/parallel/disaster_recover.md rename to docs/mindspore/source_en/model_train/parallel/disaster_recover.md index df9a9541d14eee997c000ee2a7ca8294d426093c..0c2824643a80cf56b5950ee8d782807911e9ed9a 100644 --- a/tutorials/experts/source_en/parallel/disaster_recover.md +++ b/docs/mindspore/source_en/model_train/parallel/disaster_recover.md @@ -1,6 +1,6 @@ # Disaster Recovery in Dynamic Cluster Scenarios -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/disaster_recover.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/disaster_recover.md) ## Overview @@ -10,7 +10,7 @@ Specifically, in the graph mode, the data sink mode is used for training, and th > Disaster recovery in dynamic cluster scenarios only supports GPUs and needs to run in Graph mode. -For more detailed instructions, see dynamic cluster environment variables in the [dynamic cluster environment variables](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dynamic_cluster.html). +For more detailed instructions, see dynamic cluster environment variables in the [dynamic cluster environment variables](https://www.mindspore.cn/docs/en/master/model_train/parallel/dynamic_cluster.html). ## Operation Practice @@ -35,7 +35,7 @@ The directory structure is as follows: ### Network Structure -The network structure and dataset loading is consistent with the example in [Dynamic Cluster Startup Method](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dynamic_cluster.html). +The network structure and dataset loading is consistent with the example in [Dynamic Cluster Startup Method](https://www.mindspore.cn/docs/en/master/model_train/parallel/dynamic_cluster.html). ### Defining the Training Process diff --git a/tutorials/experts/source_en/parallel/distributed_case.rst b/docs/mindspore/source_en/model_train/parallel/distributed_case.rst similarity index 71% rename from tutorials/experts/source_en/parallel/distributed_case.rst rename to docs/mindspore/source_en/model_train/parallel/distributed_case.rst index 4e951b0c155c2bb0b3d3534eabe8ff0b57f5af33..b25e00a35d2c1e095a83b64f0bc728c68b9a9308 100644 --- a/tutorials/experts/source_en/parallel/distributed_case.rst +++ b/docs/mindspore/source_en/model_train/parallel/distributed_case.rst @@ -2,7 +2,7 @@ Distributed High-Level Configuration Case ========================================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/distributed_case.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/distributed_case.rst :alt: View Source on Gitee .. toctree:: diff --git a/tutorials/experts/source_en/parallel/distributed_gradient_accumulation.md b/docs/mindspore/source_en/model_train/parallel/distributed_gradient_accumulation.md similarity index 97% rename from tutorials/experts/source_en/parallel/distributed_gradient_accumulation.md rename to docs/mindspore/source_en/model_train/parallel/distributed_gradient_accumulation.md index 990512f3b60e6609954884eaa0972e4d1b4f33cc..57068fa606cf7acc95bc35de8b5759e2a39b0f63 100644 --- a/tutorials/experts/source_en/parallel/distributed_gradient_accumulation.md +++ b/docs/mindspore/source_en/model_train/parallel/distributed_gradient_accumulation.md @@ -1,6 +1,6 @@ # Gradient Accumulation -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/distributed_gradient_accumulation.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/distributed_gradient_accumulation.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/distributed_graph_partition.md b/docs/mindspore/source_en/model_train/parallel/distributed_graph_partition.md similarity index 96% rename from tutorials/experts/source_en/parallel/distributed_graph_partition.md rename to docs/mindspore/source_en/model_train/parallel/distributed_graph_partition.md index 2168213de7343e5a56a3213230aec9fbccfdcd65..0525e50f48fa67677d0ab105287a4c609916d4cf 100644 --- a/tutorials/experts/source_en/parallel/distributed_graph_partition.md +++ b/docs/mindspore/source_en/model_train/parallel/distributed_graph_partition.md @@ -1,6 +1,6 @@ # Distributed Graph Partition -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/distributed_graph_partition.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/distributed_graph_partition.md) ## Overview @@ -16,14 +16,14 @@ Related interfaces: ## Basic Principle -Distributed tasks need to be executed in a cluster. MindSpore reuses built-in [Dynamic Networking module](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dynamic_cluster.html) of MindSpore in order to have better scalability and reliability in distributed graph partition scenarios. +Distributed tasks need to be executed in a cluster. MindSpore reuses built-in [Dynamic Networking module](https://www.mindspore.cn/docs/en/master/model_train/parallel/dynamic_cluster.html) of MindSpore in order to have better scalability and reliability in distributed graph partition scenarios. For `distributed graph partition`, each process represents a compute node (called `Worker`), and the scheduling node (called `Scheduler`) started by the `dynamic networking` module mentioned above allows discovering each compute node and thus forming a compute cluster. After `dynamic networking`, MindSpore assigns `role` and `rank`, the `role` and `id` of each process, based on the user startup configuration, both of which form a unique `tag` for each process and are input to the Python layer API `place`. With the correspondence, the user can set process labels for any operator by calling the `place` interface, and the MindSpore graph compiler module processes it to slice the computed graph into multiple subgraphs for distribution to different processes for execution. For the detailed use, please refer to [Primitive.place](https://www.mindspore.cn/docs/en/master/api_python/ops/mindspore.ops.Primitive.html#mindspore.ops.Primitive.place) and [Cell.place](https://www.mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.place) interface document. As an example, the compute topology after distributed graph partition might be as follows: -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/distributed_graph_partition.png) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/distributed_graph_partition.png) As shown in the figure above, each `Worker` has a portion of subgraphs that have been sliced by the user, with their own weights and inputs, and each `Worker` interacts with each other through the built-in `Rpc communication operator` for data interaction. @@ -229,7 +229,7 @@ The above code trains first and then infers, where all processes are executed in #### Starting Scheduler and Worker Processes -Since multiple processes are started within a node, only one `Scheduler` process and multiple `Worker` processes need to be started via a Shell script. For the meaning of the environment variables in the script and their usage, refer to the [dynamic cluster environment variables](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dynamic_cluster.html). +Since multiple processes are started within a node, only one `Scheduler` process and multiple `Worker` processes need to be started via a Shell script. For the meaning of the environment variables in the script and their usage, refer to the [dynamic cluster environment variables](https://www.mindspore.cn/docs/en/master/model_train/parallel/dynamic_cluster.html). The run.sh execution script is as follows: diff --git a/tutorials/experts/source_en/parallel/dynamic_cluster.md b/docs/mindspore/source_en/model_train/parallel/dynamic_cluster.md similarity index 98% rename from tutorials/experts/source_en/parallel/dynamic_cluster.md rename to docs/mindspore/source_en/model_train/parallel/dynamic_cluster.md index fd7887304268f1e5124b8d0ad9b49595cdf45bab..97559984bf5faacb17b92daf7c78d3ff63d9ac84 100644 --- a/tutorials/experts/source_en/parallel/dynamic_cluster.md +++ b/docs/mindspore/source_en/model_train/parallel/dynamic_cluster.md @@ -1,12 +1,12 @@ # Dynamic Cluster Startup -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/dynamic_cluster.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/dynamic_cluster.md) ## Overview For reliability requirements during training, MindSpore provides **dynamic cluster** features that enable users to start Ascend/GPU/CPU distributed training tasks without relying on any third-party library (OpenMPI) and without any modification to the training script. We recommend users to use this startup method in preference. -The MindSpore **Dynamic Cluster** feature replaces the OpenMPI capability by **reusing the Parameter Server mode training architecture**, which can be found in the [Parameter Server Mode](https://mindspore.cn/tutorials/experts/en/master/parallel/parameter_server_training.html) training tutorial. +The MindSpore **Dynamic Cluster** feature replaces the OpenMPI capability by **reusing the Parameter Server mode training architecture**, which can be found in the [Parameter Server Mode](https://mindspore.cn/docs/en/master/model_train/parallel/parameter_server_training.html) training tutorial. The **Dynamic Cluster** feature starts multiple MindSpore training processes as `Workers`, and starts an additional `Scheduler` for cluster and disaster recovery, thus, distributed training can be achieved without the need for OpenMPI's message passing mechanism. The user only needs to make a few changes to the startup script to perform distributed training. @@ -30,7 +30,7 @@ The relevant environment variables:
    • MS_SCHED: represents the Scheduler process. A training task starts only one Scheduler, which is responsible for networking, disaster recovery, etc., and does not execute training code.
    • MS_WORKER: Represents the Worker process, which generally sets up the distributed training process for this role.
    • -
    • MS_PSERVER: represents the Parameter Server process. Only in Parameter Server mode this role is effective. Please refer to Parameter Server Mode.
    • +
    • MS_PSERVER: represents the Parameter Server process. Only in Parameter Server mode this role is effective. Please refer to Parameter Server Mode.
    @@ -412,7 +412,7 @@ That is, you can perform 2-machine 8-card distributed training tasks. ## Disaster Recovery -Dynamic cluster supports disaster recovery under data parallel. In a parallel training scenario with multi-card data, if a process quits abnormally, the training can be continued after pulling up the corresponding script of the corresponding process again, and the accuracy convergence will not be affected. Disaster recovery configuration and samples can be found in the [Disaster Recovery in Dynamic Cluster Scenarios](https://www.mindspore.cn/tutorials/experts/en/master/parallel/disaster_recover.html) tutorial. +Dynamic cluster supports disaster recovery under data parallel. In a parallel training scenario with multi-card data, if a process quits abnormally, the training can be continued after pulling up the corresponding script of the corresponding process again, and the accuracy convergence will not be affected. Disaster recovery configuration and samples can be found in the [Disaster Recovery in Dynamic Cluster Scenarios](https://www.mindspore.cn/docs/en/master/model_train/parallel/disaster_recover.html) tutorial. ## Security Authentication diff --git a/tutorials/experts/source_en/parallel/fault_recover.md b/docs/mindspore/source_en/model_train/parallel/fault_recover.md similarity index 95% rename from tutorials/experts/source_en/parallel/fault_recover.md rename to docs/mindspore/source_en/model_train/parallel/fault_recover.md index 8724564ae104077d41e97ec6bae740f43526b88d..4425e224bd5e16b6f5c7a4b73bedc0bf5105780d 100644 --- a/tutorials/experts/source_en/parallel/fault_recover.md +++ b/docs/mindspore/source_en/model_train/parallel/fault_recover.md @@ -1,6 +1,6 @@ # Fault Recovery Based on Redundant Information -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/fault_recover.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/fault_recover.md) ## Overview @@ -10,12 +10,12 @@ To solve this problem, one option is to aggregate the weights through the [AllGa However, for large models, the overhead of using aggregated preservation is too large for all kinds of resources, so this document presents a recovery scheme where each card only saves its own weight information. For large models, both data parallelism and model parallelism are often applied, and the devices divided by the dimensions of data parallelism, which hold exactly the same weight information, provide a redundant backup for large models. This document will also point out how to go about obtaining this redundant information. -For the relationship between the parallel strategy and the slicing division of the weights, the following mapping can be performed. For the concept of data parallelism, model parallelism, please refer to [Operator-level Parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/operator_parallel.html). For more information about optimizer parallelism, please refer to [Optimizer Parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/optimizer_parallel.html). +For the relationship between the parallel strategy and the slicing division of the weights, the following mapping can be performed. For the concept of data parallelism, model parallelism, please refer to [Operator-level Parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/operator_parallel.html). For more information about optimizer parallelism, please refer to [Optimizer Parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/optimizer_parallel.html). - Data parallelism + keep optimizer parallelism off: The ranks in the parallel communication domain hold the same weight slice. - Model parallism: The ranks in the parallel communication domain hold different weight slices. -Also, it should be noted that this document introduces the distributed faults recovery scheme, which needs to be used in [sink mode](https://www.mindspore.cn/tutorials/experts/en/master/optimize/execution_opt.html). +Also, it should be noted that this document introduces the distributed faults recovery scheme, which needs to be used in [sink mode](https://www.mindspore.cn/docs/en/master/model_train/train_process/train_optimize.html). Related environment variables: diff --git a/tutorials/experts/source_en/parallel/host_device_training.md b/docs/mindspore/source_en/model_train/parallel/host_device_training.md similarity index 96% rename from tutorials/experts/source_en/parallel/host_device_training.md rename to docs/mindspore/source_en/model_train/parallel/host_device_training.md index 52c7d32d7f3e611eca0ecb2e5dfd352b8d360cad..11d935f3c4c0e8a3bcacb4f7af0889c7655e13fb 100644 --- a/tutorials/experts/source_en/parallel/host_device_training.md +++ b/docs/mindspore/source_en/model_train/parallel/host_device_training.md @@ -1,6 +1,6 @@ # Host&Device Heterogeneous -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/host_device_training.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/host_device_training.md) ## Overview @@ -18,13 +18,13 @@ Related interfaces: Pipeline parallel and operator-level parallel are suitable for the model to have a large number of operators, and the parameters are more evenly distributed among the operators. What if the number of operators in the model is small, and the parameters are concentrated in only a few operators? Wide & Deep is an example of this, as shown in the image below. The Embedding table in Wide & Deep can be trained as a parameter of hundreds of GIGabytes or even a few terabytes. If it is executed on an accelerator (device), the number of accelerators required is huge, and the training cost is expensive. On the other hand, if you use accelerator computing, the training acceleration obtained is limited, and it will also trigger cross-server traffic, and the end-to-end training efficiency will not be very high. -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/host_device_image_0_zh.png) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/host_device_image_0_zh.png) *Figure: Part of the structure of the Wide & Deep model* A careful analysis of the special structure of the Wide & Deep model can be obtained: although the Embedding table has a huge amount of parameters, it participates in very little computation, and the Embedding table and its corresponding operator, the EmbeddingLookup operator, can be placed on the Host side, by using the CPU for calculation, and the rest of the operators are placed on the accelerator side. This can take advantage of the large amount of memory on the Host side and the fast computing of the accelerator side, while taking advantage of the high bandwidth of the Host to accelerator of the same server. The following diagram shows how Wide & Deep heterogeneous slicing works: -![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/host_device_image_1_zh.png) +![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/host_device_image_1_zh.png) *Figure: Wide & Deep Heterogeneous Approach* diff --git a/tutorials/experts/source_en/parallel/images/checkpoint_integrate_process.pptx b/docs/mindspore/source_en/model_train/parallel/images/checkpoint_integrate_process.pptx similarity index 100% rename from tutorials/experts/source_en/parallel/images/checkpoint_integrate_process.pptx rename to docs/mindspore/source_en/model_train/parallel/images/checkpoint_integrate_process.pptx diff --git a/tutorials/experts/source_en/parallel/images/comm_subgraph.png b/docs/mindspore/source_en/model_train/parallel/images/comm_subgraph.png similarity index 100% rename from tutorials/experts/source_en/parallel/images/comm_subgraph.png rename to docs/mindspore/source_en/model_train/parallel/images/comm_subgraph.png diff --git a/tutorials/experts/source_en/parallel/images/sharding_propagation.png b/docs/mindspore/source_en/model_train/parallel/images/sharding_propagation.png similarity index 100% rename from tutorials/experts/source_en/parallel/images/sharding_propagation.png rename to docs/mindspore/source_en/model_train/parallel/images/sharding_propagation.png diff --git a/tutorials/experts/source_en/parallel/images/sp_case1.png b/docs/mindspore/source_en/model_train/parallel/images/sp_case1.png similarity index 100% rename from tutorials/experts/source_en/parallel/images/sp_case1.png rename to docs/mindspore/source_en/model_train/parallel/images/sp_case1.png diff --git a/tutorials/experts/source_en/parallel/images/sp_case2.png b/docs/mindspore/source_en/model_train/parallel/images/sp_case2.png similarity index 100% rename from tutorials/experts/source_en/parallel/images/sp_case2.png rename to docs/mindspore/source_en/model_train/parallel/images/sp_case2.png diff --git a/tutorials/experts/source_en/parallel/images/sp_case3.png b/docs/mindspore/source_en/model_train/parallel/images/sp_case3.png similarity index 100% rename from tutorials/experts/source_en/parallel/images/sp_case3.png rename to docs/mindspore/source_en/model_train/parallel/images/sp_case3.png diff --git a/tutorials/experts/source_en/parallel/images/tensor_layout.png b/docs/mindspore/source_en/model_train/parallel/images/tensor_layout.png similarity index 100% rename from tutorials/experts/source_en/parallel/images/tensor_layout.png rename to docs/mindspore/source_en/model_train/parallel/images/tensor_layout.png diff --git a/tutorials/experts/source_en/parallel/manual_parallel.md b/docs/mindspore/source_en/model_train/parallel/manual_parallel.md similarity index 98% rename from tutorials/experts/source_en/parallel/manual_parallel.md rename to docs/mindspore/source_en/model_train/parallel/manual_parallel.md index d8c0a5f4797033e87bba39dcde1ce8cfc054de12..247718d7061647d741b036d5686d1ae153feaf1d 100644 --- a/tutorials/experts/source_en/parallel/manual_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/manual_parallel.md @@ -1,6 +1,6 @@ # Manually Parallelism -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/manual_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/manual_parallel.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/memory_offload.md b/docs/mindspore/source_en/model_train/parallel/memory_offload.md similarity index 98% rename from tutorials/experts/source_en/parallel/memory_offload.md rename to docs/mindspore/source_en/model_train/parallel/memory_offload.md index a14cf645fbab780f20aaca0b98ed970a510249b3..0ece65c318aafaeb17ff9356bd568780495b7fa6 100644 --- a/tutorials/experts/source_en/parallel/memory_offload.md +++ b/docs/mindspore/source_en/model_train/parallel/memory_offload.md @@ -1,6 +1,6 @@ # Heterogeneous Storage -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/memory_offload.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/memory_offload.md) ## Overview @@ -50,7 +50,7 @@ During training, the main stored data consists of parameters and intermediate re Through heterogeneous storage management, parameters or intermediate results that do not need to participate in computation temporarily can be copied to the memory of Host side or even hard disk storage during the training process, and then copied and restored to the device side when the data is needed to participate in computation. By the above means, the model size that can be trained by the same hardware device can be increased. -![image.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/memory_offload.png) +![image.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/memory_offload.png) ## Operation Practice diff --git a/tutorials/experts/source_en/parallel/model_loading.md b/docs/mindspore/source_en/model_train/parallel/model_loading.md similarity index 89% rename from tutorials/experts/source_en/parallel/model_loading.md rename to docs/mindspore/source_en/model_train/parallel/model_loading.md index 0b861d7e745b42b369454cdea2b4e50de001b56b..e7a415e9b607c8a1bb7f383b20f7267e3329178b 100644 --- a/tutorials/experts/source_en/parallel/model_loading.md +++ b/docs/mindspore/source_en/model_train/parallel/model_loading.md @@ -1,14 +1,14 @@ # Model Loading -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/model_loading.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/model_loading.md) ## Overview -Model loading under distribution mainly refers to distributed inference, i.e., the inference phase is performed using multi-card. If data parallel is used for training or model parameters are saved in merge, then each card holds full weights and each card infers about its own input data in the same way as [single-card inference](https://www.mindspore.cn/tutorials/experts/en/master/infer/inference.html#model-eval-model-validation). It should be noted that each card loads the same CheckPoint file for inference. +Model loading under distribution mainly refers to distributed inference, i.e., the inference phase is performed using multi-card. If data parallel is used for training or model parameters are saved in merge, then each card holds full weights and each card infers about its own input data in the same way as [single-card inference](https://www.mindspore.cn/docs/en/master/model_infer/overview.html#model-eval-model-validation). It should be noted that each card loads the same CheckPoint file for inference. This tutorial focuses on the process of saving slices of the model on each card during the multi-card training process, and reloading the model for inference according to the inference strategy in the inference phase using the multi-card format. For the problem that the number of parameters in the ultra-large-scale neural network model is too large and the model cannot be fully loaded into single card for inference, distributed inference can be performed using multiple cards. -> - When the model is very large and the [load_distributed_checkpoint](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.load_distributed_checkpoint.html) interface that is used in this tutorials has insufficient host memory, refer to the [model transformation](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_transformation.html#performing-compilation-on-the-target-network) section to perform compilation on the target network , and execute distributed checkpoint transformation. use the way that each card loads its own corresponding sliced checkpoint. -> - If pipeline distributed inference is used, pipeline parallel training must also be used during training, and the `device_num` and `pipeline_stages` used for pipeline parallel training and inference must be the same. For pipeline parallel inference, `micro_batch` is 1, there is no need to call `PipelineCell`, and each `stage` only needs to load the Checkpoint file for this `stage`. Refer to the [Pipeline Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/pipeline_parallel.html) training tutorial. +> - When the model is very large and the [load_distributed_checkpoint](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.load_distributed_checkpoint.html) interface that is used in this tutorials has insufficient host memory, refer to the [model transformation](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_transformation.html#performing-compilation-on-the-target-network) section to perform compilation on the target network , and execute distributed checkpoint transformation. use the way that each card loads its own corresponding sliced checkpoint. +> - If pipeline distributed inference is used, pipeline parallel training must also be used during training, and the `device_num` and `pipeline_stages` used for pipeline parallel training and inference must be the same. For pipeline parallel inference, `micro_batch` is 1, there is no need to call `PipelineCell`, and each `stage` only needs to load the Checkpoint file for this `stage`. Refer to the [Pipeline Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/pipeline_parallel.html) training tutorial. Related interfaces: @@ -46,7 +46,7 @@ The directory structure is as follows: `test_loading.py` is the script that defines the network structure and inference. `run_loading.sh` is the execution script. -The user first needs to follow the [Model Saving](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_saving.html) tutorial to perform the 8-card distributed training, which will generate Checkpoint file directory as well as the cut-point strategy file in the current path at the end of training: +The user first needs to follow the [Model Saving](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_saving.html) tutorial to perform the 8-card distributed training, which will generate Checkpoint file directory as well as the cut-point strategy file in the current path at the end of training: ```text src_checkpoints/ diff --git a/tutorials/experts/source_en/parallel/model_save_load.rst b/docs/mindspore/source_en/model_train/parallel/model_save_load.rst similarity index 59% rename from tutorials/experts/source_en/parallel/model_save_load.rst rename to docs/mindspore/source_en/model_train/parallel/model_save_load.rst index e0b56837312083185bea8257c642e0d466647587..f65e54f438aef5ce3b3b80969949e6bc7860faf9 100644 --- a/tutorials/experts/source_en/parallel/model_save_load.rst +++ b/docs/mindspore/source_en/model_train/parallel/model_save_load.rst @@ -2,7 +2,7 @@ Model Saving and Loading ========================= .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/model_save_load.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/model_save_load.rst :alt: View Source on Gitee .. toctree:: @@ -15,6 +15,6 @@ Model Saving and Loading Model saving in MindSpore can be categorized into merged and non-merged saving, and model loading can also be categorized into complete loading and sliced loading. If the distributed slicing strategy or cluster card is changed after loading, the saved checkpoint file needs to be model transformed. For details, please refer to: -- `Model Saving `_ -- `Model Loading `_ -- `Model Transformation `_ +- `Model Saving `_ +- `Model Loading `_ +- `Model Transformation `_ diff --git a/tutorials/experts/source_en/parallel/model_saving.md b/docs/mindspore/source_en/model_train/parallel/model_saving.md similarity index 98% rename from tutorials/experts/source_en/parallel/model_saving.md rename to docs/mindspore/source_en/model_train/parallel/model_saving.md index 0b10da9abda525c7e30da2070139a5fb975734ca..de6b0456f93ee0c2f676f9635a79b074c8532d3a 100644 --- a/tutorials/experts/source_en/parallel/model_saving.md +++ b/docs/mindspore/source_en/model_train/parallel/model_saving.md @@ -1,6 +1,6 @@ # Model Saving -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/model_saving.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/model_saving.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/model_transformation.md b/docs/mindspore/source_en/model_train/parallel/model_transformation.md similarity index 93% rename from tutorials/experts/source_en/parallel/model_transformation.md rename to docs/mindspore/source_en/model_train/parallel/model_transformation.md index 3daabb7acfdbc86972e0476cf3112014170ddb53..c08e60e0d8120bbe870149107c5619daa27a94f3 100644 --- a/tutorials/experts/source_en/parallel/model_transformation.md +++ b/docs/mindspore/source_en/model_train/parallel/model_transformation.md @@ -1,6 +1,6 @@ # Model Transformation -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/model_transformation.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/model_transformation.md) ## Overview @@ -85,7 +85,7 @@ The functions of each file are as follows: ### Saving the Distributed Model -First, follow the [Model Saving](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_saving.html) tutorial to perform 8-card distributed training with a parallel mode of `SEMI_AUTO_ PARALLEL` or `AUTO_PARALLEL`, while customizing the `strategy_ckpt_config` parameter by calling the `set_auto_parallel_context` interface to configure the model sharding strategy file storage path. After training for a period of time, call the `train.ModelCheckpoint` function of storage Checkpoint to store the distributed checkpoint. +First, follow the [Model Saving](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_saving.html) tutorial to perform 8-card distributed training with a parallel mode of `SEMI_AUTO_ PARALLEL` or `AUTO_PARALLEL`, while customizing the `strategy_ckpt_config` parameter by calling the `set_auto_parallel_context` interface to configure the model sharding strategy file storage path. After training for a period of time, call the `train.ModelCheckpoint` function of storage Checkpoint to store the distributed checkpoint. At the end of the training, the source Checkpoint file directory as well as the source sharding strategy file will be generated at the current path: @@ -409,8 +409,8 @@ In the case of an inference task, the results are saved in `log_output/1/rank.*/ ### Pipeline Parallel Model Transformation -[Pipelining Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/pipeline_parallel.html) is to slice a linear network to get multiple sub-networks, which are pipelined among multiple cards. Therefore, the sharding strategy file stored for each subgraph is inconsistent, and all the sharding strategies are aggregated together to get the complete slicing information of the network. -Therefore, for the dimension of pipeline parallel, compared to the transformation of other dimensions, it is necessary to perform an operation of aggregating the sharding strategy file before getting the aggregated sharding strategy file, and use this file as the strategy file on which the distributed Checkpoint transformation depends. In addition, there is no difference with the previous [Executing Distributed Checkpoint Transformation](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_transformation.html#executing-distributed-checkpoint-transformation). +[Pipelining Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/pipeline_parallel.html) is to slice a linear network to get multiple sub-networks, which are pipelined among multiple cards. Therefore, the sharding strategy file stored for each subgraph is inconsistent, and all the sharding strategies are aggregated together to get the complete slicing information of the network. +Therefore, for the dimension of pipeline parallel, compared to the transformation of other dimensions, it is necessary to perform an operation of aggregating the sharding strategy file before getting the aggregated sharding strategy file, and use this file as the strategy file on which the distributed Checkpoint transformation depends. In addition, there is no difference with the previous [Executing Distributed Checkpoint Transformation](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_transformation.html#executing-distributed-checkpoint-transformation). Related interfaces: @@ -418,7 +418,7 @@ Related interfaces: First, 8-card pipeline parallel training is executed, where pipeline parallel dimension is 2 and optimizer parallelism is turned on. -The training code is in [pipeline_train.py](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/model_saving_loading/pipeline_train.py). The network structure adds a pipeline parallel configuration based on the chapter [Model Saving](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_saving.html) with parallel dimension 2. +The training code is in [pipeline_train.py](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/model_saving_loading/pipeline_train.py). The network structure adds a pipeline parallel configuration based on the chapter [Model Saving](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_saving.html) with parallel dimension 2. The core code is: @@ -474,11 +474,11 @@ After execution, the source Checkpoint file directory and the source sharding st ... ``` -Refer to [Performing a compilation of the target network](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_transformation.html#performing-compilation-on-the-target-network) section, and similarly compile the target network in order to obtain the sharding strategy file for the target network. +Refer to [Performing a compilation of the target network](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_transformation.html#performing-compilation-on-the-target-network) section, and similarly compile the target network in order to obtain the sharding strategy file for the target network. The next step unfolds the distributed Checkpoint dimension transformation containing pipeline parallel dimensions, first merging the sharding strategy files obtained from pipline training using interface `merge_pipeline_strategys`, and then performing the distributed Checkpoint transformation using interface `transform_checkpoints` or `transform_checkpoint_by_rank`. -The example introduces an interface that uses `transform_checkpoints`, and the interface that uses `transform_checkpoint_by_rank`. Refer to [Executing Distributed Checkpoint Transformation](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_transformation.html#executing-distributed-checkpoint-transformation). +The example introduces an interface that uses `transform_checkpoints`, and the interface that uses `transform_checkpoint_by_rank`. Refer to [Executing Distributed Checkpoint Transformation](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_transformation.html#executing-distributed-checkpoint-transformation). ```python import mindspore as ms @@ -495,7 +495,7 @@ The example script execution command to transform the entire Checkpoint catalog bash run_retrain_pipeline_convert.sh ``` -After the transformation is completed, refer to [Loading the Transformed Checkpoint Files](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_transformation.html#loading-the-transformed-checkpoint-files) section to execute the distributed network without pipeline dimension. +After the transformation is completed, refer to [Loading the Transformed Checkpoint Files](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_transformation.html#loading-the-transformed-checkpoint-files) section to execute the distributed network without pipeline dimension. In the example, the script execution command for loading the transformed Checkpoint for second-stage fine-tuning training is: @@ -541,7 +541,7 @@ Taking the training network used in the first part of [pipeline parallel model t ... ``` -Refer to [performing compilation on the target network](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_transformation.html#performing-compilation-on-the-target-network) section. Compile the target network to obtain the strategy file of the target network. +Refer to [performing compilation on the target network](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_transformation.html#performing-compilation-on-the-target-network) section. Compile the target network to obtain the strategy file of the target network. In the training parallel stratey, the pipeline parallel dimensino is 2. The network will be divided into two subnetworks. The strategy files `src_strategy_0.ckpt` and `src_strategy_4.ckpt` are used for checkpoint transformation. Using `transform_checkpoints` interface for checkpoint transformation of a single subnetwork. diff --git a/tutorials/experts/source_en/parallel/mpirun.md b/docs/mindspore/source_en/model_train/parallel/mpirun.md similarity index 98% rename from tutorials/experts/source_en/parallel/mpirun.md rename to docs/mindspore/source_en/model_train/parallel/mpirun.md index 16718bd068ea5428ca9e4affba1abb01d8ce0954..04c2db3e34d06a4bd23d4b97223fa4aa6116e899 100644 --- a/tutorials/experts/source_en/parallel/mpirun.md +++ b/docs/mindspore/source_en/model_train/parallel/mpirun.md @@ -1,6 +1,6 @@ # mpirun Startup -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/mpirun.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/mpirun.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/ms_operator.md b/docs/mindspore/source_en/model_train/parallel/ms_operator.md similarity index 98% rename from tutorials/experts/source_en/parallel/ms_operator.md rename to docs/mindspore/source_en/model_train/parallel/ms_operator.md index 365de376e5f95ba146f9e75bd4a3abd77aedada6..3e45f2cbc22ea055bc99e793b2656e3695f438ca 100644 --- a/tutorials/experts/source_en/parallel/ms_operator.md +++ b/docs/mindspore/source_en/model_train/parallel/ms_operator.md @@ -1,6 +1,6 @@ # Performing Distributed Training on K8S Clusters -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/ms_operator.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/ms_operator.md) MindSpore Operator is a plugin that follows Kubernetes' Operator pattern (based on the CRD-Custom Resource Definition feature) and implements distributed training on Kubernetes. MindSpore Operator defines Scheduler, PS, worker three roles in CRD, and users can easily use MindSpore on K8S for distributed training through simple YAML file configuration. The code repository of mindSpore Operator is described in: [ms-operator](https://gitee.com/mindspore/ms-operator/). diff --git a/tutorials/experts/source_en/parallel/msrun_launcher.md b/docs/mindspore/source_en/model_train/parallel/msrun_launcher.md similarity index 96% rename from tutorials/experts/source_en/parallel/msrun_launcher.md rename to docs/mindspore/source_en/model_train/parallel/msrun_launcher.md index 3941ec251158d76ea0c927accb0c1533cf328dbc..a13466de0eac221328826d000b4c5eaa554ce4c8 100644 --- a/tutorials/experts/source_en/parallel/msrun_launcher.md +++ b/docs/mindspore/source_en/model_train/parallel/msrun_launcher.md @@ -1,10 +1,10 @@ # msrun Launching -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/msrun_launcher.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/msrun_launcher.md) ## Overview -`msrun` is an encapsulation of the [Dynamic Cluster](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dynamic_cluster.html) startup method. Users can use `msrun` to pull multi-process distributed tasks across nodes with a single command line instruction. Users can use `msrun` to pull up multi-process distributed tasks on each node with a single command line command, and there is no need to manually set [dynamic networking environment variables](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dynamic_cluster.html). `msrun` supports both `Ascend`, `GPU` and `CPU` backends. As with the `Dynamic Cluster` startup, `msrun` has no dependencies on third-party libraries and configuration files. +`msrun` is an encapsulation of the [Dynamic Cluster](https://www.mindspore.cn/docs/en/master/model_train/parallel/dynamic_cluster.html) startup method. Users can use `msrun` to pull multi-process distributed tasks across nodes with a single command line instruction. Users can use `msrun` to pull up multi-process distributed tasks on each node with a single command line command, and there is no need to manually set [dynamic networking environment variables](https://www.mindspore.cn/docs/en/master/model_train/parallel/dynamic_cluster.html). `msrun` supports both `Ascend`, `GPU` and `CPU` backends. As with the `Dynamic Cluster` startup, `msrun` has no dependencies on third-party libraries and configuration files. > - `msrun` is available after the user installs MindSpore, and the command `msrun --help` can be used to view the supported parameters. > - `msrun` supports `graph mode` as well as `PyNative mode`. diff --git a/tutorials/experts/source_en/parallel/multiple_copy.md b/docs/mindspore/source_en/model_train/parallel/multiple_copy.md similarity index 98% rename from tutorials/experts/source_en/parallel/multiple_copy.md rename to docs/mindspore/source_en/model_train/parallel/multiple_copy.md index 3ccdd78fbf2e7c5da3858bd95df285bb95630787..6a6d18f8fd6ae7e82609a10fc84c62f958f46288 100644 --- a/tutorials/experts/source_en/parallel/multiple_copy.md +++ b/docs/mindspore/source_en/model_train/parallel/multiple_copy.md @@ -1,6 +1,6 @@ # Multi-copy Parallel -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/multiple_copy.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/multiple_copy.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/multiple_mix.md b/docs/mindspore/source_en/model_train/parallel/multiple_mix.md similarity index 97% rename from tutorials/experts/source_en/parallel/multiple_mix.md rename to docs/mindspore/source_en/model_train/parallel/multiple_mix.md index 869f19f26628e9d112af26ffe7dabb5ebc43ede3..db4bf63dab14446d7917ab7cd64c656f45940b49 100644 --- a/tutorials/experts/source_en/parallel/multiple_mix.md +++ b/docs/mindspore/source_en/model_train/parallel/multiple_mix.md @@ -1,6 +1,6 @@ # Multi-dimensional Hybrid Parallel Case Based on Double Recursive Search -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/multiple_mix.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/multiple_mix.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/operator_parallel.md b/docs/mindspore/source_en/model_train/parallel/operator_parallel.md similarity index 98% rename from tutorials/experts/source_en/parallel/operator_parallel.md rename to docs/mindspore/source_en/model_train/parallel/operator_parallel.md index 94d33c21c2b3a6afb5d41bac3ce76b6203dcaa7f..1d7da32d867ca5755e6ecc5f03968867b0def0a6 100644 --- a/tutorials/experts/source_en/parallel/operator_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/operator_parallel.md @@ -1,6 +1,6 @@ # Operator-level Parallelism -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/operator_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/operator_parallel.md) ## Overview @@ -231,4 +231,4 @@ epoch: 0, step: 100, loss is 0.71934 ... ``` -Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). \ No newline at end of file +Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). \ No newline at end of file diff --git a/docs/mindspore/source_en/model_train/parallel/optimize_technique.rst b/docs/mindspore/source_en/model_train/parallel/optimize_technique.rst new file mode 100644 index 0000000000000000000000000000000000000000..dbde42567a88628ae9578ad28e3b0619bd72d8e1 --- /dev/null +++ b/docs/mindspore/source_en/model_train/parallel/optimize_technique.rst @@ -0,0 +1,43 @@ +Optimization Techniques +======================== + +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/optimize_technique.rst + :alt: View Source on Gitee + +.. toctree:: + :maxdepth: 1 + :hidden: + + strategy_select + split_technique + multiple_copy + distributed_gradient_accumulation + recompute + dataset_slice + host_device_training + memory_offload + comm_fusion + comm_subgraph + +Considering that in actual parallel training, there may be requirements for training performance, throughput or size, optimization can be considered in three ways: parallel strategy optimization, memory optimization and communication optimization + +- Parallel Strategy Optimization: parallel strategy optimization mainly includes the selection of parallel strategy, sharding technique under operator-level parallel, and multi-copy technique. + + - `Strategy Selection `_: Depending on the model size and data volume size, different parallel strategies can be selected to improve training efficiency and resource utilization. + - `Sharding Techniques `_: The sharding technique refers to the reduction of tensor rearranging to improve training efficiency by manually configuring the sharding strategy for certain key operators. + - `Multiply Copy `_: Multi-copy refers to splitting a training batch into multiple ones in an iterative step to concurrently communicate and compute the model in parallel and improve resource utilization. + +- Memory optimization: memory optimization includes gradient accumulation, recompute, dataset sharding, Host&Device heterogeneity and heterogeneous storage, with the main goal of saving memory space. + + - `Gradient Accumulation `_: Gradient Accumulation updates the parameters of a neural network by computing gradients on multiple MicroBatches and summing them up, then applying this accumulated gradient at once. In this way a small number of devices can also train large Batches, effectively minimizing memory spikes. + - `Recompute `_: Recomputation is a time-for-space technique that saves memory space by not saving the results of certain forward operator calculations, and when calculating the reverse operator, the forward results need to be used before recomputing the forward operator. + - `Dataset Sharding `_: When a dataset is too large individually or even cannot be loaded onto a single device, the data can be sliced for distributed training. Slicing the dataset with model parallel is an effective way to reduce the graphics memory usage. + - `Host&Device Heterogeneous `_: When the number of parameters exceeds the upper limit of Device memory, you can put some operators with large memory usage and small computation on the Host side, which can simultaneously utilize the characteristics of large memory on the Host side and fast computation on the Device side, and improve the utilization rate of the device. + - `Heterogeneous Storage `_: Heterogeneous storage can copy the parameters that are not needed temporarily or intermediate results to the memory or hard disk on the Host side, and then restore them to the Device side when needed, thus reducing the memory consumption. + +- Communication optimization: communication optimization includes communication fusion and communication subgraph extraction and multiplexing, and the main goal is to reduce communication delay and improve performance. + + - `Communication Fusion `_: Communication fusion can merge the communication operators of the same source and target nodes into a single communication process, avoiding the extra overhead caused by multiple communications. + - `Communication Subgraph Extraction and Multiplexing `_: By extracting communication subgraphs for communication operators and replacing the original communication operators, the communication time-consumption can be reduced and the model compilation time can be reduced at the same time. + diff --git a/tutorials/experts/source_en/parallel/optimizer_parallel.md b/docs/mindspore/source_en/model_train/parallel/optimizer_parallel.md similarity index 96% rename from tutorials/experts/source_en/parallel/optimizer_parallel.md rename to docs/mindspore/source_en/model_train/parallel/optimizer_parallel.md index 406d6512b803fde8cc4c80f3737ee58485b8e5cd..fe1a95354fa2d67c6bdd7368d1721170e6c6cac4 100644 --- a/tutorials/experts/source_en/parallel/optimizer_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/optimizer_parallel.md @@ -1,6 +1,6 @@ # Optimizer Parallel -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/optimizer_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/optimizer_parallel.md) ## Overview @@ -30,7 +30,7 @@ In a training iteration, the data parallelism introduces a communication operati If you want to implement parallel computing for the optimizer, there are two implementation ideas, weights grouping and weights sharding. One of the weights grouping is to do inter-layer division of the parameters and gradients within the optimizer, and the general training flow is shown in Figure 1. The parameters and gradients are grouped onto different cards to be updated, and then the updated weights are shared among devices through a communication broadcast operation. The memory and performance gains of the solution depend on the group with the largest proportion of parameters. When the parameters are divided evenly, the theoretical positive gains are N-1/N of optimizer runtime and dynamic memory, and N-1/N of memory size for optimizer state parameters, where N denotes the number of devices. And the negative gain introduced is the communication time that comes when sharing network weights. -![images](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/optimizer_parallel_image_0_zh.png) +![images](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/optimizer_parallel_image_0_zh.png) *Figure 1: Schematic diagram of the parameter grouping training process* @@ -38,7 +38,7 @@ Another way to implement parameter slicing is to do intra-layer division of para First, slice the weights in the network can further reduce static memory. However, this also requires performing the shared weight operation at the end of the iteration before the forward start of the next iteration, ensuring that the original tensor shape remains the same after going into the forward and backward operations. In addition, the main negative gain from the parallel operation of the optimizer is the communication time of the shared weights, which can bring a performance gain if we can reduce or hide it. One advantage of communication cross-iteration execution is that communication operations can be executed interleaved with the forward network by fusing the communication operators in appropriate groups, thus hiding the communication time consumption as much as possible. The communication time consumption is also related to the communication volume. For the network involving mixed precision, if we can use fp16 communication, the communication volume will be reduced by half compared to fp32. Combining the above characteristics, the implementation scheme of parameter slicing is shown in Figure 2. -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/optimizer_parallel_image_1_zh.png) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/optimizer_parallel_image_1_zh.png) *Figure 2: Schematic diagram of the parameter slicing training process* @@ -137,7 +137,7 @@ net.layer2.set_comm_fusion(1) net.layer3.set_comm_fusion(2) ``` -> Here communication fusion is configured for different layers in order to reduce the communication cost. Details can be found in [Communication Operator Fusion](https://www.mindspore.cn/tutorials/experts/en/master/parallel/comm_fusion.html). +> Here communication fusion is configured for different layers in order to reduce the communication cost. Details can be found in [Communication Operator Fusion](https://www.mindspore.cn/docs/en/master/model_train/parallel/comm_fusion.html). ### Training the Network @@ -209,7 +209,7 @@ epoch: 0, step: 100, loss is 0.6854114 ... ``` -Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). +Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). ## Advanced Interfaces diff --git a/tutorials/experts/source_en/parallel/others.rst b/docs/mindspore/source_en/model_train/parallel/others.rst similarity index 74% rename from tutorials/experts/source_en/parallel/others.rst rename to docs/mindspore/source_en/model_train/parallel/others.rst index 026c7d6e3621aa4b34a1b3742d5b1444bb36e5da..b120863aeff4e7ba7a3d3ed08b0f47e0a40011bb 100644 --- a/tutorials/experts/source_en/parallel/others.rst +++ b/docs/mindspore/source_en/model_train/parallel/others.rst @@ -2,7 +2,7 @@ Experimental Characteristics ============================= .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/others.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/others.rst :alt: View Source on Gitee .. toctree:: diff --git a/tutorials/experts/source_en/parallel/overview.md b/docs/mindspore/source_en/model_train/parallel/overview.md similarity index 78% rename from tutorials/experts/source_en/parallel/overview.md rename to docs/mindspore/source_en/model_train/parallel/overview.md index 8fbcc665510c2bfb6d329970c2ba77e60a6cf7df..fdb1401a9612afad5816235db007827d966522dd 100644 --- a/tutorials/experts/source_en/parallel/overview.md +++ b/docs/mindspore/source_en/model_train/parallel/overview.md @@ -1,6 +1,6 @@ # Distributed Parallelism Overview -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/overview.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/overview.md) In deep learning, as the size of the dataset and number of parameters grows, the time and hardware resources required for training will increase and eventually become a bottleneck that constrains training. Distributed parallel training, which can reduce the demand on hardware such as memory and computational performance, is an important optimization means to perform training. In addition, distributed parallel is important for large model training and inference, which provides powerful computational capabilities and performance advantages for handling large-scale data and complex models. @@ -15,51 +15,51 @@ MindSpore currently supports four startup methods: - **mpirun**: Start via the multi-process communication library OpenMPI, with Ascend/GPU support. - **rank table**: After configuring the rank_table table, Ascend is supported by start scripts and processes corresponding to the number of cards. -Refer to the [Distributed Parallel Startup Methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html) section for details. +Refer to the [Distributed Parallel Startup Methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html) section for details. ## Parallel Modes Currently MindSpore can take the following parallel mode, and you can choose according to your needs: -- **Data Parallel Mode**: In data parallel mode, the dataset can be split in sample dimensions and distributed to different cards. If your dataset is large and the model parameters scale is able to operate on a single card, you can choose this parallel model. Refer to the [Data Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/data_parallel.html) tutorial for more information. -- **Automatic Parallel Mode**: a distributed parallel mode that combines data parallel and operator-level model parallel. It can automatically build cost models, find the parallel strategy with shorter training time, and select the appropriate parallel mode for the user. If your dataset and model parameters are large in size, and you want to configure the parallel strategy automatically, you can choose this parallel model. Refer to the [Automatic Parallelism](https://www.mindspore.cn/tutorials/experts/en/master/parallel/auto_parallel.html) tutorial for more information. -- **Semi-Automatic Parallel Mode**: Compared with automatic parallel, this mode requires the user to manually configure a slice strategy for the operators to realize parallel. If your dataset and model parameters are large, and you are familiar with the structure of the model, and know which "key operators" are prone to become computational bottlenecks to configure the appropriate slice strategy for the "key operators" to achieve better performance, you can choose this mode. Parallel mode. This mode also allows you to manually configure optimizer parallel and pipeline parallel. Refer to the [Semi-Automatic Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/semi_auto_parallel.html) tutorial for more information. -- **Manual Parallel Mode**: In manual parallel mode, you can manually implement parallel communication of models in distributed systems by transferring data based on communication operators such as `AllReduce`, `AllGather`, `Broadcast` and other communication operators. You can refer to the [Manual Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/manual_parallel.html) tutorial for more information. -- **Parameter Server Mode**: parameter servers offer better flexibility and scalability than synchronized training methods. You can refer to the [Parameter Server](https://www.mindspore.cn/tutorials/experts/en/master/parallel/parameter_server_training.html) mode tutorial for more information. +- **Data Parallel Mode**: In data parallel mode, the dataset can be split in sample dimensions and distributed to different cards. If your dataset is large and the model parameters scale is able to operate on a single card, you can choose this parallel model. Refer to the [Data Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/data_parallel.html) tutorial for more information. +- **Automatic Parallel Mode**: a distributed parallel mode that combines data parallel and operator-level model parallel. It can automatically build cost models, find the parallel strategy with shorter training time, and select the appropriate parallel mode for the user. If your dataset and model parameters are large in size, and you want to configure the parallel strategy automatically, you can choose this parallel model. Refer to the [Automatic Parallelism](https://www.mindspore.cn/docs/en/master/model_train/parallel/auto_parallel.html) tutorial for more information. +- **Semi-Automatic Parallel Mode**: Compared with automatic parallel, this mode requires the user to manually configure a slice strategy for the operators to realize parallel. If your dataset and model parameters are large, and you are familiar with the structure of the model, and know which "key operators" are prone to become computational bottlenecks to configure the appropriate slice strategy for the "key operators" to achieve better performance, you can choose this mode. Parallel mode. This mode also allows you to manually configure optimizer parallel and pipeline parallel. Refer to the [Semi-Automatic Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/semi_auto_parallel.html) tutorial for more information. +- **Manual Parallel Mode**: In manual parallel mode, you can manually implement parallel communication of models in distributed systems by transferring data based on communication operators such as `AllReduce`, `AllGather`, `Broadcast` and other communication operators. You can refer to the [Manual Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/manual_parallel.html) tutorial for more information. +- **Parameter Server Mode**: parameter servers offer better flexibility and scalability than synchronized training methods. You can refer to the [Parameter Server](https://www.mindspore.cn/docs/en/master/model_train/parallel/parameter_server_training.html) mode tutorial for more information. ## Saving and Loading Models -Model saving can be categorized into merged and non-merged saving, which can be selected via the `integrated_save` parameter in `mindspore.save_checkpoint` or `mindspore.train.CheckpointConfig`. Model parameters are automatically aggregated and saved to the model file in merged save mode, while each card saves slices of the parameters on their respective cards in non-merged saving mode. You can refer to the [Model Saving](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_saving.html) tutorial for more information about model saving in each parallel mode. +Model saving can be categorized into merged and non-merged saving, which can be selected via the `integrated_save` parameter in `mindspore.save_checkpoint` or `mindspore.train.CheckpointConfig`. Model parameters are automatically aggregated and saved to the model file in merged save mode, while each card saves slices of the parameters on their respective cards in non-merged saving mode. You can refer to the [Model Saving](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_saving.html) tutorial for more information about model saving in each parallel mode. -Model loading can be categorized into full loading and slice loading. If the model file is saved with complete parameters, the model file can be loaded directly through the `load_checkpoint` interface. If the model file is a parameter-sliced file under multi-card, we need to consider whether the distributed slice strategy or cluster size has changed after loading. If the distributed slice strategy or cluster size remains unchanged, the corresponding parameter slice file for each card can be loaded via the `load_distributed_checkpoint` interface, which can be found in [model loading](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html) tutorial. +Model loading can be categorized into full loading and slice loading. If the model file is saved with complete parameters, the model file can be loaded directly through the `load_checkpoint` interface. If the model file is a parameter-sliced file under multi-card, we need to consider whether the distributed slice strategy or cluster size has changed after loading. If the distributed slice strategy or cluster size remains unchanged, the corresponding parameter slice file for each card can be loaded via the `load_distributed_checkpoint` interface, which can be found in [model loading](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html) tutorial. -In the case that the saved and loaded distributed slice strategy or cluster size changes, the Checkpoint file under distribution needs to be converted to adapt to the new distributed slice strategy or cluster size. You can refer to [Model Transformation](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_transformation.html) for more information. +In the case that the saved and loaded distributed slice strategy or cluster size changes, the Checkpoint file under distribution needs to be converted to adapt to the new distributed slice strategy or cluster size. You can refer to [Model Transformation](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_transformation.html) for more information. ## Fault Recovery During the distributed parallel training process, problems such as failures of computing nodes or communication interruptions may be encountered. MindSpore provides three recovery methods to ensure the stability and continuity of training: -- **Recovery based on full Checkpoint**:Before saving the Checkpoint file, the complete parameters of the model are aggregated by the AllGather operator, and the complete model parameter file is saved for each card, which can be loaded directly for recovery. Multiple checkpoints copies improve the fault tolerance of the model, but for large models, the aggregation process leads to excessive overhead of various resources. Refer to the [Model Loading](https://www.mindspore.cn/tutorials/experts/en/master/parallel/model_loading.html) tutorial for details. -- **Disaster Recovery in Dynamic Cluster Scenarios**: In dynamic cluster, if a process fails, the other processes will enter a waiting state, and the training task can be resumed by pulling up the fault process (only GPU hardware platforms are supported at present). Compared with other methods, this fault recovery method does not require restarting the cluster. For details, please refer to [Disaster Recovery in Dynamic Cluster Scenarios](https://www.mindspore.cn/tutorials/experts/en/master/parallel/disaster_recover.html) tutorial. -- **Recovery of redundant information based on parameter slicing**: In large model training, devices that are divided according to the dimension of data parallel have the same model parameters. According to this principle, these redundant parameter information can be utilized as a backup. When one node fails, another node utilizing the same parameters can recover the failed node. For details, please refer to the [Fault Recovery Based on Redundant Information](https://www.mindspore.cn/tutorials/experts/en/master/parallel/fault_recover.html) tutorial. +- **Recovery based on full Checkpoint**:Before saving the Checkpoint file, the complete parameters of the model are aggregated by the AllGather operator, and the complete model parameter file is saved for each card, which can be loaded directly for recovery. Multiple checkpoints copies improve the fault tolerance of the model, but for large models, the aggregation process leads to excessive overhead of various resources. Refer to the [Model Loading](https://www.mindspore.cn/docs/en/master/model_train/parallel/model_loading.html) tutorial for details. +- **Disaster Recovery in Dynamic Cluster Scenarios**: In dynamic cluster, if a process fails, the other processes will enter a waiting state, and the training task can be resumed by pulling up the fault process (only GPU hardware platforms are supported at present). Compared with other methods, this fault recovery method does not require restarting the cluster. For details, please refer to [Disaster Recovery in Dynamic Cluster Scenarios](https://www.mindspore.cn/docs/en/master/model_train/parallel/disaster_recover.html) tutorial. +- **Recovery of redundant information based on parameter slicing**: In large model training, devices that are divided according to the dimension of data parallel have the same model parameters. According to this principle, these redundant parameter information can be utilized as a backup. When one node fails, another node utilizing the same parameters can recover the failed node. For details, please refer to the [Fault Recovery Based on Redundant Information](https://www.mindspore.cn/docs/en/master/model_train/parallel/fault_recover.html) tutorial. ## Optimization Methods If there is a requirement on performance, throughput, or scale, or if you don't know how to choose a parallel strategy, consider the following optimization techniques: - **Parallel strategy optimization**: - - **Strategy Selection**: Depending on the size of your model and the amount of data, you can refer to the [Strategy Selection](https://www.mindspore.cn/tutorials/experts/en/master/parallel/strategy_select.html) tutorial to select different parallel strategies to improve training efficiency and resource utilization. - - **Slicing Techniques**: Slicing techniques are also key to achieving efficient parallel computation. In the [Slicing Techniques](https://www.mindspore.cn/tutorials/experts/en/master/parallel/split_technique.html) tutorial, you can learn how to apply a variety of slicing techniques to improve efficiency through concrete examples. - - **Multi-copy Parallel**: Under the existing single-copy mode, certain underlying operators cannot perform computation at the same time when communicating, which leads to resource waste. Multi-copy mode slicing the data into multiple copies in accordance with the batch size dimension can make one copy communicate while the other copy performs computational operations, which improves the resource utilization rate. For details, please refer to the [Multi-copy Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/multiple_copy.html) tutorial. + - **Strategy Selection**: Depending on the size of your model and the amount of data, you can refer to the [Strategy Selection](https://www.mindspore.cn/docs/en/master/model_train/parallel/strategy_select.html) tutorial to select different parallel strategies to improve training efficiency and resource utilization. + - **Slicing Techniques**: Slicing techniques are also key to achieving efficient parallel computation. In the [Slicing Techniques](https://www.mindspore.cn/docs/en/master/model_train/parallel/split_technique.html) tutorial, you can learn how to apply a variety of slicing techniques to improve efficiency through concrete examples. + - **Multi-copy Parallel**: Under the existing single-copy mode, certain underlying operators cannot perform computation at the same time when communicating, which leads to resource waste. Multi-copy mode slicing the data into multiple copies in accordance with the batch size dimension can make one copy communicate while the other copy performs computational operations, which improves the resource utilization rate. For details, please refer to the [Multi-copy Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/multiple_copy.html) tutorial. - **Memory optimization**: - - **Gradient Accumulation**: Gradient accumulation updates the parameters of a neural network by computing gradients over multiple MicroBatches and summing them up, then applying this accumulated gradient at once. In this way, a small number of devices can be trained on a large batch size, effectively minimizing memory spikes. For detailed information, refer to [Gradient Accumulation](https://www.mindspore.cn/tutorials/experts/en/master/parallel/distributed_gradient_accumulation.html) tutorial. - - **Recompute**: Recompute saves memory space by not saving the result of the forward operators. When calculating the backward operators, you need to use the forward result before recalculating the forward operators. For details, please refer to the [recompute](https://www.mindspore.cn/tutorials/experts/en/master/parallel/recompute.html) tutorial. - - **Dataset Slicing**: When a dataset is too large for a single piece of data, the data can be sliced for distributed training. Dataset slicing with model parallel is an effective way to reduce graphics memory usage. For details, please refer to the [dataset slicing](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dataset_slice.html) tutorial. - - **Host&Device Heterogeneous**: When the number of parameters exceeds the upper limit of Device memory, you can put some operators with large memory usage and small computation amount on the Host side, so that you can utilize the large memory on the Host side and the fast computation on the Device side at the same time, and improve the utilization rate of the device. For details, please refer to [Host&Device Heterogeneous](https://www.mindspore.cn/tutorials/experts/en/master/parallel/host_device_training.html) tutorial. - - **Heterogeneous Storage**: large models are currently limited by the size of the graphics memory, making it difficult to train on a single card. In large-scale distributed cluster training, with communication becoming more and more costly, boosting the graphics memory of a single machine and reducing communication can also improve training performance. Heterogeneous storage can copy the parameters or intermediate results that are not needed temporarily to the memory or hard disk on the Host side, and then restore them to the Device side when needed. For details, please refer to [Heterogeneous Storage](https://www.mindspore.cn/tutorials/experts/en/master/parallel/memory_offload.html) tutorial. + - **Gradient Accumulation**: Gradient accumulation updates the parameters of a neural network by computing gradients over multiple MicroBatches and summing them up, then applying this accumulated gradient at once. In this way, a small number of devices can be trained on a large batch size, effectively minimizing memory spikes. For detailed information, refer to [Gradient Accumulation](https://www.mindspore.cn/docs/en/master/model_train/parallel/distributed_gradient_accumulation.html) tutorial. + - **Recompute**: Recompute saves memory space by not saving the result of the forward operators. When calculating the backward operators, you need to use the forward result before recalculating the forward operators. For details, please refer to the [recompute](https://www.mindspore.cn/docs/en/master/model_train/parallel/recompute.html) tutorial. + - **Dataset Slicing**: When a dataset is too large for a single piece of data, the data can be sliced for distributed training. Dataset slicing with model parallel is an effective way to reduce graphics memory usage. For details, please refer to the [dataset slicing](https://www.mindspore.cn/docs/en/master/model_train/parallel/dataset_slice.html) tutorial. + - **Host&Device Heterogeneous**: When the number of parameters exceeds the upper limit of Device memory, you can put some operators with large memory usage and small computation amount on the Host side, so that you can utilize the large memory on the Host side and the fast computation on the Device side at the same time, and improve the utilization rate of the device. For details, please refer to [Host&Device Heterogeneous](https://www.mindspore.cn/docs/en/master/model_train/parallel/host_device_training.html) tutorial. + - **Heterogeneous Storage**: large models are currently limited by the size of the graphics memory, making it difficult to train on a single card. In large-scale distributed cluster training, with communication becoming more and more costly, boosting the graphics memory of a single machine and reducing communication can also improve training performance. Heterogeneous storage can copy the parameters or intermediate results that are not needed temporarily to the memory or hard disk on the Host side, and then restore them to the Device side when needed. For details, please refer to [Heterogeneous Storage](https://www.mindspore.cn/docs/en/master/model_train/parallel/memory_offload.html) tutorial. - **Communication Optimization**: - - **Communication fusion**: communication fusion can merge the communication operators of the same source and target nodes into a single communication process, avoiding the extra overhead of multiple communications. For details, please refer to [Communication Fusion](https://www.mindspore.cn/tutorials/experts/en/master/parallel/comm_fusion.html). - - **Communication Subgraph Extraction and Reuse**: By extracting communication subgraphs for communication operators and replacing the original communication operators, we can reduce the communication time consumption and also reduce the model compilation time. For details, please refer to [Communication Subgraph Extraction and Reuse](https://www.mindspore.cn/tutorials/experts/en/master/parallel/comm_subgraph.html). + - **Communication fusion**: communication fusion can merge the communication operators of the same source and target nodes into a single communication process, avoiding the extra overhead of multiple communications. For details, please refer to [Communication Fusion](https://www.mindspore.cn/docs/en/master/model_train/parallel/comm_fusion.html). + - **Communication Subgraph Extraction and Reuse**: By extracting communication subgraphs for communication operators and replacing the original communication operators, we can reduce the communication time consumption and also reduce the model compilation time. For details, please refer to [Communication Subgraph Extraction and Reuse](https://www.mindspore.cn/docs/en/master/model_train/parallel/comm_subgraph.html). ## Differences in Different Platforms @@ -71,14 +71,14 @@ In distributed training, different hardware platforms (Ascend, CPU or GPU) suppo - GPU supports msrun, dynamic cluster and mpirun startup. - CPU supports msrun and dynamic cluster startup. -For the detailed process, refer to [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). +For the detailed process, refer to [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). ### Differences in Parallel Methods - Ascend and GPUs support all methods of parallel, including data parallel, semi-automatic parallel, automatic parallel, and more. - CPU only supports data parallel. -For the detailed process, refer to [data parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/data_parallel.html), [semi-automatic parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/semi_auto_parallel.html), [auto-parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/auto_parallel.html). +For the detailed process, refer to [data parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/data_parallel.html), [semi-automatic parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/semi_auto_parallel.html), [auto-parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/auto_parallel.html). ### Differences in Optimization Feature Support @@ -86,5 +86,4 @@ For the detailed process, refer to [data parallel](https://www.mindspore.cn/tuto - GPU support optimization features other than communication subgraph extraction and multiplexing. - CPU does not support optimization features. -For the detailed process, refer to [optimization methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/optimize_technique.html). - +For the detailed process, refer to [optimization methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/optimize_technique.html). diff --git a/tutorials/experts/source_en/parallel/pangu_alpha.md b/docs/mindspore/source_en/model_train/parallel/pangu_alpha.md similarity index 98% rename from tutorials/experts/source_en/parallel/pangu_alpha.md rename to docs/mindspore/source_en/model_train/parallel/pangu_alpha.md index 6b81001559e1bc0df9e7f3ec7d3e7d07eb4d194d..a0ccac311475becde7a46c4639982582c0abcdd3 100644 --- a/tutorials/experts/source_en/parallel/pangu_alpha.md +++ b/docs/mindspore/source_en/model_train/parallel/pangu_alpha.md @@ -1,6 +1,6 @@ # PengCheng·PanGu Model Network Multi-dimension Hybrid Parallel Analysis -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/pangu_alpha.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/pangu_alpha.md) ## Overview @@ -118,7 +118,7 @@ class EmbeddingLayer(nn.Cell): The key difficulty in training large-scale Transformer networks is how to solve the computational and memory bottlenecks caused by the increasing number of layers, and it is especially important to choose a reasonable slicing. The main network of the PengCheng-PanGu model consists of multiple Decoders with the same structure but do not share weights, and the Decoder is composed of two parts, Self-Attention and FeedForward. The principle of slicing is to minimize the communication, and their slicing can be referred to the following figure: -![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/pangu_strategy.png) +![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/pangu_strategy.png) *Figure 6:parallel strategy of PanguAlpha(Source:[PanguAlpha Technical report](https://openi.pcl.ac.cn/PCL-Platform.Intelligence/PanGu-Alpha/src/branch/master/PANGU-%ce%b1.pdf))* diff --git a/tutorials/experts/source_en/parallel/parameter_server_training.md b/docs/mindspore/source_en/model_train/parallel/parameter_server_training.md similarity index 98% rename from tutorials/experts/source_en/parallel/parameter_server_training.md rename to docs/mindspore/source_en/model_train/parallel/parameter_server_training.md index d80b3a571d0f973e9c6d9138a861ab9027dd0a80..a4afefbcb69c48eb01a1d2bde52518ada3aec08f 100644 --- a/tutorials/experts/source_en/parallel/parameter_server_training.md +++ b/docs/mindspore/source_en/model_train/parallel/parameter_server_training.md @@ -1,6 +1,6 @@ # Parameter Server -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/parameter_server_training.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/parameter_server_training.md) ## Overview @@ -48,7 +48,7 @@ export MS_SCHED_PORT=XXXX # Scheduler port export MS_ROLE=MS_SCHED # The role of this process: MS_SCHED represents the scheduler, MS_WORKER represents the worker, MS_PSERVER represents the Server ``` -For more detailed instructions, see [dynamic cluster environment variables](https://www.mindspore.cn/tutorials/experts/en/master/parallel/dynamic_cluster.html). +For more detailed instructions, see [dynamic cluster environment variables](https://www.mindspore.cn/docs/en/master/model_train/parallel/dynamic_cluster.html). ## Practice diff --git a/tutorials/experts/source_en/parallel/pipeline_parallel.md b/docs/mindspore/source_en/model_train/parallel/pipeline_parallel.md similarity index 96% rename from tutorials/experts/source_en/parallel/pipeline_parallel.md rename to docs/mindspore/source_en/model_train/parallel/pipeline_parallel.md index e1a6246212d5277e74d5b124d4a7fac4bbf3838e..f17396e58074ac174920a4c7fb3f2ae8cdd9291a 100644 --- a/tutorials/experts/source_en/parallel/pipeline_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/pipeline_parallel.md @@ -1,6 +1,6 @@ # Pipeline Parallel -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/pipeline_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/pipeline_parallel.md) ## Overview @@ -22,7 +22,7 @@ Related interfaces: Pipeline parallel is the splitting of operators in a neural network into multiple stages, and then mapping the stages to different devices, so that different devices can compute different parts of the neural network. Pipeline parallel is suitable for graph structures where the model is linear. As shown in Figure 1, the network of 4 layers of MatMul is split into 4 stages and distributed to 4 devices. In forward calculations, each machine sends the result to the next machine through the communication operator after calculating the MatMul on the machine, and at the same time, the next machine receives (Receive) the MatMul result of the previous machine through the communication operator, and starts to calculate the MatMul on the machine; In reverse calculation, after the gradient of the last machine is calculated, the result is sent to the previous machine, and at the same time, the previous machine receives the gradient result of the last machine and begins to calculate the reverse of the current machine. -![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_0_zh.png) +![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_0_zh.png) *Figure 1: Schematic diagram of graph splitting in pipeline parallel* @@ -30,7 +30,7 @@ Pipeline parallel is the splitting of operators in a neural network into multipl Simply splitting the model onto multiple devices does not bring about a performance gain, because the linear structure of the model has only one device at work at a time, while other devices are waiting, resulting in a waste of resources. In order to improve efficiency, the pipeline parallel further divides the small batch (MiniBatch) into more fine-grained micro batches (MicroBatch), and adopts a pipeline execution sequence in the micro batch, so as to achieve the purpose of improving efficiency, as shown in Figure 2. The small batches are cut into 4 micro-batches, and the 4 micro-batches are executed on 4 groups to form a pipeline. The gradient aggregation of the micro-batch is used to update the parameters, where each device only stores and updates the parameters of the corresponding group. where the white ordinal number represents the index of the micro-batch. -![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_1_zh.png) +![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_1_zh.png) *Figure 2: Schematic diagram of a pipeline parallel execution timeline with MicroBatch* @@ -38,7 +38,7 @@ Simply splitting the model onto multiple devices does not bring about a performa In MindSpore's pipeline parallel implementation, the execution order has been adjusted for better memory management. As shown in Figure 3, the reverse of the MicroBatch numbered 0 is performed immediately after its forward execution, so that the memory of the intermediate result of the numbered 0 MicroBatch is freed earlier (compared to Figure 2), thus ensuring that the peak memory usage is lower than in the way of Figure 2. -![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_2_zh.png) +![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_2_zh.png) *Figure 3: MindSpore Pipeline Parallel Execution Timeline Diagram* @@ -46,7 +46,7 @@ In MindSpore's pipeline parallel implementation, the execution order has been ad In order to improve the efficiency of pipeline parallelism and reduce the proportion of bubbles, Megatron LM proposes a new pipeline parallel scheduling called "interleaved pipeline". Traditional pipeline parallelism typically places several consecutive model layers (such as Transformer layers) on a stage, as shown in Figure 3. In the scheduling of interleaved pipeline, each stage performs interleaved calculations on non-continuous model layers to further reduce the proportion of bubbles with more communication, as shown in Figure 4. For example, in traditional pipeline parallelism, each stage has 2 model layers, namely: stage 0 has layers 0 and 1, stage 1 has layers 2 and 3, stage 3 has layers 4 and 5, and stage 4 has layers 6 and 7, while in interleaved pipeline, stage 0 has layers 0 and 4, stage 1 has layers 1 and 5, stage 2 has layers 2 and 6, and stage 3 has layers 3 and 7. -![mpp2.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/megatron.png) +![mpp2.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/megatron.png) *Figure 4: Scheduler of Interleaved Pipeline* @@ -54,7 +54,7 @@ In order to improve the efficiency of pipeline parallelism and reduce the propor MindSpore has made memory optimization based on Megatron LM interleaved pipeline scheduling by moving some forward execution sequences back, as shown in Figure 5, which can accumulate less MicroBatch memory during memory peak hours. -![mpp2.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/mindspore.png) +![mpp2.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/mindspore.png) *Figure 5: MindSpore Scheduler of Interleaved Pipeline* @@ -272,7 +272,7 @@ Tensor(shape=[8, 512], dtype=Float32, value= [ 4.89746094e-01 3.56689453e-01 -4.90966797e-01 ... -3.30078125e-e01 -2.38525391e-01 7.33398438e-01]]) ``` -Other startup methods such as dynamic cluster and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). +Other startup methods such as dynamic cluster and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). ## Inference Operation Practices diff --git a/tutorials/experts/source_en/parallel/rank_table.md b/docs/mindspore/source_en/model_train/parallel/rank_table.md similarity index 99% rename from tutorials/experts/source_en/parallel/rank_table.md rename to docs/mindspore/source_en/model_train/parallel/rank_table.md index 6eabd279eafbe128cafcaa723b80ad69d03342a4..92c5f5cb2edee06b686ba04d58593ba6ae66b777 100644 --- a/tutorials/experts/source_en/parallel/rank_table.md +++ b/docs/mindspore/source_en/model_train/parallel/rank_table.md @@ -1,6 +1,6 @@ # rank table Startup -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/rank_table.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/rank_table.md) ## Overview diff --git a/tutorials/experts/source_en/parallel/recompute.md b/docs/mindspore/source_en/model_train/parallel/recompute.md similarity index 97% rename from tutorials/experts/source_en/parallel/recompute.md rename to docs/mindspore/source_en/model_train/parallel/recompute.md index 6d486d8642028f6e3bc95903c53f9a5e0f04228f..4d5017d8ea6538c930a6c99407a5093f41744367 100644 --- a/tutorials/experts/source_en/parallel/recompute.md +++ b/docs/mindspore/source_en/model_train/parallel/recompute.md @@ -1,6 +1,6 @@ # Recomputation -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/recompute.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/recompute.md) ## Overview @@ -24,7 +24,7 @@ In order to reduce memory peaks, the recompute technique can not save the comput The recompute function is implemented as a forward operator that is recomputed according to the user's specified needs, copies the same operator, outputs it to the reverse operator, and deletes the continuous edge relationship between the original forward operator and the reverse operator. In addition, we need to ensure that the copied operator only begins to be evaluated when the corresponding inverse part is computed, so we need to insert control dependencies to ensure the order in which the operators are executed. As shown in the following figure: -![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/recompute_image_0_zh.png) +![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/recompute_image_0_zh.png) *Figure: Forward and reverse diagram before and after the recompute function is enabled* @@ -32,7 +32,7 @@ For user convenience, MindSpore currently provides not only a recompute interfac Taking the GPT-3 model as an example, the policy is set to recalculate the cell corresponding to the layerer for each layer, and then the output operator of the layerer is set to non-recompute. The effect of recompute on the 72-layer GPT-3 network is shown in the following figure: -![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/parallel/images/recompute_image_1_zh.png) +![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/parallel/images/recompute_image_1_zh.png) *Figure: Comparison of GPT-3 memory usage before and after recalculation function is enabled* diff --git a/tutorials/experts/source_en/parallel/recover.rst b/docs/mindspore/source_en/model_train/parallel/recover.rst similarity index 43% rename from tutorials/experts/source_en/parallel/recover.rst rename to docs/mindspore/source_en/model_train/parallel/recover.rst index 2e6439b0740afecff0c2b7ecbd39e0ea7b5ddb5d..a0068150bec56fe1d3c00ba444baeaf2854b8378 100644 --- a/tutorials/experts/source_en/parallel/recover.rst +++ b/docs/mindspore/source_en/model_train/parallel/recover.rst @@ -2,7 +2,7 @@ Fault Recovery ============== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/recover.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/recover.rst :alt: View Source on Gitee .. toctree:: @@ -14,6 +14,6 @@ Fault Recovery During the distributed parallel training process, MindSpore has three recovery methods when encountering problems such as failures of compute nodes or communication interruptions: -- Model Reloading: During training, by configuring the parameters to be merged and saved, a complete model parameter file is saved for each card, which can be directly loaded for checkpoint recovery. See `Model loading `_ in Model saving and loading for details. -- `Disaster Recovery in Dynamic Cluster Scenarios `_: In the dynamic cluster startup scenario, if a process fails, the other processes will enter a waiting state, and the training task can be continued by pulling up the failed process without restarting the cluster (currently only supports GPU hardware platforms). -- `Fault Recovery Based on Redundant Information `_: In large model training, the devices divided according to the dimension of data parallelism have the same parameters of their models. According to this principle, these redundant parameter information can be utilized as a backup, and in case of one node failure, another node utilizing the same parameters can recover the failed node. +- Model Reloading: During training, by configuring the parameters to be merged and saved, a complete model parameter file is saved for each card, which can be directly loaded for checkpoint recovery. See `Model loading `_ in Model saving and loading for details. +- `Disaster Recovery in Dynamic Cluster Scenarios `_: In the dynamic cluster startup scenario, if a process fails, the other processes will enter a waiting state, and the training task can be continued by pulling up the failed process without restarting the cluster (currently only supports GPU hardware platforms). +- `Fault Recovery Based on Redundant Information `_: In large model training, the devices divided according to the dimension of data parallelism have the same parameters of their models. According to this principle, these redundant parameter information can be utilized as a backup, and in case of one node failure, another node utilizing the same parameters can recover the failed node. diff --git a/tutorials/experts/source_en/parallel/sapp.md b/docs/mindspore/source_en/model_train/parallel/sapp.md similarity index 98% rename from tutorials/experts/source_en/parallel/sapp.md rename to docs/mindspore/source_en/model_train/parallel/sapp.md index b63d35e7b430bdc73d1313d8d95eb0318df3295a..76d73bdc23be2219058ea4c7f492e9e8042fe455 100644 --- a/tutorials/experts/source_en/parallel/sapp.md +++ b/docs/mindspore/source_en/model_train/parallel/sapp.md @@ -1,6 +1,6 @@ # Double Recursive Strategy Search Algorithm -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/sapp.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/sapp.md) ## Overview @@ -239,4 +239,4 @@ In `xx_validate_xxx.ir`, you can see that the input and output tensor of each op For the first MatMul operator, its two inputs are sliced from the original (256, 784), (512, 784) into (64, 392), (512, 392), and after the transpose of the second input, the output of the operator is (64, 512). -Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). +Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). diff --git a/tutorials/experts/source_en/parallel/semi_auto_parallel.rst b/docs/mindspore/source_en/model_train/parallel/semi_auto_parallel.rst similarity index 30% rename from tutorials/experts/source_en/parallel/semi_auto_parallel.rst rename to docs/mindspore/source_en/model_train/parallel/semi_auto_parallel.rst index 18ad2d29d35188974f990a274501bf71dd5353f6..a6cd9784bfcf13bc46c050f2938eb524e78b8fd5 100644 --- a/tutorials/experts/source_en/parallel/semi_auto_parallel.rst +++ b/docs/mindspore/source_en/model_train/parallel/semi_auto_parallel.rst @@ -2,7 +2,7 @@ Semi-automatic Parallel =========================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/semi_auto_parallel.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/semi_auto_parallel.rst :alt: View Source on Gitee .. toctree:: @@ -16,7 +16,7 @@ Semi-automatic Parallel Semi-automatic parallel supports the automatic mixing of multiple parallel modes, including: -- `Operator-level parallel `_: Operator-level parallel refers to slicing the input tensor and model parameters into multiple devices for computation on an operator basis to improve overall speed. -- `Higher-order Operator-level Parallelism `_: Higher-order operator-level parallelism refers to operator-level parallelism that allows customized device layout with tensor layout for more complex sharding logic. -- `Optimizer parallel `_: Optimizer parallel reduces redundant computations on multiple devices for the same weight updates, spreading the computation over multiple devices. -- `Pipeline parallel `_: Pipeline parallel means that the model is sliced by layer, with each device processing only a certain part of the model. +- `Operator-level parallel `_: Operator-level parallel refers to slicing the input tensor and model parameters into multiple devices for computation on an operator basis to improve overall speed. +- `Higher-order Operator-level Parallelism `_: Higher-order operator-level parallelism refers to operator-level parallelism that allows customized device layout with tensor layout for more complex sharding logic. +- `Optimizer parallel `_: Optimizer parallel reduces redundant computations on multiple devices for the same weight updates, spreading the computation over multiple devices. +- `Pipeline parallel `_: Pipeline parallel means that the model is sliced by layer, with each device processing only a certain part of the model. diff --git a/tutorials/experts/source_en/parallel/shard_function_parallel.md b/docs/mindspore/source_en/model_train/parallel/shard_function_parallel.md similarity index 98% rename from tutorials/experts/source_en/parallel/shard_function_parallel.md rename to docs/mindspore/source_en/model_train/parallel/shard_function_parallel.md index f062718a818a85cceebd14a63f301d16712d8c7d..5020018a1aac8174d57dd68ed5e7c1d2ecd4d0dc 100644 --- a/tutorials/experts/source_en/parallel/shard_function_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/shard_function_parallel.md @@ -1,6 +1,6 @@ # Functional Operator Shading -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/shard_function_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/shard_function_parallel.md) ## Overview @@ -236,7 +236,7 @@ Distributed parallelism can be initiated by rank table when executing on Ascend > > That is, when started in this way, the communication generated by model parallelism within `shard` can only occur within `world group`, so the specified sharding strategy can currently only support slicing one dimension. -The above code needs to be configured with distributed variables before it can run. The Ascend environment needs to be configured with RANK_TABLE_FILE, RANK_ID, and DEVICE_ID. The configuration procedure can be found [here](https://www.mindspore.cn/tutorials/experts/en/master/parallel/rank_table.html). +The above code needs to be configured with distributed variables before it can run. The Ascend environment needs to be configured with RANK_TABLE_FILE, RANK_ID, and DEVICE_ID. The configuration procedure can be found [here](https://www.mindspore.cn/docs/en/master/model_train/parallel/rank_table.html). Ascend Distributed related environment variables are: diff --git a/tutorials/experts/source_en/parallel/sharding_propagation.md b/docs/mindspore/source_en/model_train/parallel/sharding_propagation.md similarity index 98% rename from tutorials/experts/source_en/parallel/sharding_propagation.md rename to docs/mindspore/source_en/model_train/parallel/sharding_propagation.md index 56b5cecae593e812a648fe7b0de0fc7cff1af35c..7c9befaa58ee772553bc0f3146d73681093bfb99 100644 --- a/tutorials/experts/source_en/parallel/sharding_propagation.md +++ b/docs/mindspore/source_en/model_train/parallel/sharding_propagation.md @@ -1,6 +1,6 @@ # Sharding Strategy Propagation Algorithm -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/sharding_propagation.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/sharding_propagation.md) ## Overview @@ -277,8 +277,8 @@ In `xx_validate_xxx.ir`, you can see that the input and output tensor of each op For the first MatMul operator, after its inputs are sliced according to the strategy ((2, 1), (1, 4)), the shapes of the first and second inputs are sliced into (128, 784), (784, 16) from the original (256, 784), (784, 64), respectively, and thus the output shape of (128, 16) is obtained. -Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/tutorials/experts/en/master/parallel/startup_method.html). +Other startup methods such as dynamic networking and `rank table` startup can be found in [startup methods](https://www.mindspore.cn/docs/en/master/model_train/parallel/startup_method.html). ### Empirical Principles on Configuring Sharding Strategies -Given a new model with numerous operators, from the user's perspective, a key problem is to determine which operators should be configured, with what sharding strategies. Since the goal of Sharding Propagation is to minimize Tensor Redistribution cost, instead of finding the global minima of end-to-end step time, it is crucial to configure proper sharding strategies for "key operators". There is no compulsory standard specifying which operators must be configured. However, based on our experience of training large models, there are indeed some principles guiding users to annotate shardings. We have summarized 3 empirical principles for reference, as detailed in [Split Technique](https://www.mindspore.cn/tutorials/experts/en/master/parallel/split_technique.html). +Given a new model with numerous operators, from the user's perspective, a key problem is to determine which operators should be configured, with what sharding strategies. Since the goal of Sharding Propagation is to minimize Tensor Redistribution cost, instead of finding the global minima of end-to-end step time, it is crucial to configure proper sharding strategies for "key operators". There is no compulsory standard specifying which operators must be configured. However, based on our experience of training large models, there are indeed some principles guiding users to annotate shardings. We have summarized 3 empirical principles for reference, as detailed in [Split Technique](https://www.mindspore.cn/docs/en/master/model_train/parallel/split_technique.html). diff --git a/tutorials/experts/source_en/parallel/split_technique.md b/docs/mindspore/source_en/model_train/parallel/split_technique.md similarity index 87% rename from tutorials/experts/source_en/parallel/split_technique.md rename to docs/mindspore/source_en/model_train/parallel/split_technique.md index 467b45d5de0e8a5297c7bd34530cd353037e29b2..1f24e554eaae26ae5f269845c3c7e759e8dc9bf4 100644 --- a/tutorials/experts/source_en/parallel/split_technique.md +++ b/docs/mindspore/source_en/model_train/parallel/split_technique.md @@ -1,6 +1,6 @@ # Sharding Techniques -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/split_technique.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/split_technique.md) ## Overview @@ -10,19 +10,19 @@ Given a new model, from the user's perspective, the key issue is to configure wh The sharding strategy for parameter weights is very important, especially for large models, as the memory consumption caused by parameter weights accounts for a large portion of the total memory consumption for model training. Therefore, operators involving weights usually need to explicitly configure the sharding strategy. In the two examples below, the Gather and MatMul operators involving weights are configured with sharding strategy, while the other operators are not. These correspond the data-parallel VocabEmbedding layer and hybrid-parallel FeedForward Layer in [mindformers](https://gitee.com/mindspore/mindformers/blob/master/mindformers/modules/transformer/transformer.py), respectively. -![sp_case1](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/parallel/images/sp_case1.png "Configuring Operators Involving Weights") +![sp_case1](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/parallel/images/sp_case1.png "Configuring Operators Involving Weights") ### Configuring Dimension-changing Operators The operators of deep learning frameworks can be broadly categorized into two types: operators that are semantically simple and dimension-preserving and operators that change the dimension of the input tensor. For dimension-preserving operators, the strategy propagation algorithm can propagate the sharding strategy more easily. However, for dimension-changing operators, explicitly configuring the sharding strategy is the only way to better express the user initial thoughts and avoid the strategy propagation algorithm from deriving the sharding strategy that is not expected by the user. In the example below, ReduceMean and MatMul are dimension-changing operators that are configured with sharding strategy. -![sp_case2](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/parallel/images/sp_case2.png "Configuring Dimension-changing Operators") +![sp_case2](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/parallel/images/sp_case2.png "Configuring Dimension-changing Operators") ### Configuring Boundary Operators that Change in Parallel Method For ResNet-like models, different parts of the model have different preferred parallel: the first half uses data parallel, and the second half uses model parallel for optimal iterative performance. This can be accomplished by configuring strategy for boundary operators that change in a parallel method. In the example below, the first MatMul is configured with a strategy for data parallel, which will propagate the strategy for data parallel forward to the first half of the model, while the second MatMul is configured with a strategy for model parallel, which will propagate the strategy for model parallel backward to the second half of the model. -![sp_case3](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_en/parallel/images/sp_case3.png "Configuring Boundary Operators that Change in Parallel Method") +![sp_case3](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/parallel/images/sp_case3.png "Configuring Boundary Operators that Change in Parallel Method") Users working with strategy propagation need to have some understanding not only of its propagation algorithm itself, but also of the parallelism of the model to be trained. If there exists a certain operator whose parallel strategy determined by the strategy propagation algorithm does not meet the user's expectations, that can always be solved by configuring an additional operator parallel strategy. In practice, for a new model, it does take several attempts to obtain an overall parallel configuration with better performance. diff --git a/tutorials/experts/source_en/parallel/startup_method.rst b/docs/mindspore/source_en/model_train/parallel/startup_method.rst similarity index 47% rename from tutorials/experts/source_en/parallel/startup_method.rst rename to docs/mindspore/source_en/model_train/parallel/startup_method.rst index 712320daed3b5012fbf70af1cdf5830aabf98234..a4016765adb4b032f49b60b6e898a9678992c9d5 100644 --- a/tutorials/experts/source_en/parallel/startup_method.rst +++ b/docs/mindspore/source_en/model_train/parallel/startup_method.rst @@ -2,7 +2,7 @@ Distributed Parallel Startup Methods ==================================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/startup_method.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/startup_method.rst :alt: View Source on Gitee .. toctree:: @@ -19,10 +19,10 @@ Startup Method Currently GPU, Ascend and CPU support multiple startup methods respectively, four of which are \ ``msrun``, dynamic cluster, \ ``mpirun`` and \ ``rank table``: -- `msrun `_: `msrun` is the capsulation of Dynamic cluster. It allows user to launch distributed jobs using one single command in each node. It could be used after MindSpore is installed. This method does not rely on third-party libraries and configuration files, has disaster recovery function, good security, and supports three hardware platforms. It is recommended that users prioritize the use of this startup method. -- `Dynamic cluster `_: dynamic cluster requires user to spawn multiple processes and export environment variables. It's the implementation of `msrun`. Use this method when running `Parameter Server` training mode. For other distributed jobs, `msrun` is recommended. -- `mpirun `_: this method relies on the open source library OpenMPI, and startup command is simple. Multi-machine need to ensure two-by-two password-free login. It is recommended for users who have experience in using OpenMPI to use this startup method. -- `rank table `_: this method requires the Ascend hardware platform and does not rely on third-party library. After manually configuring the rank_table file, you can start the parallel program via a script, and the script is consistent across multiple machines for easy batch deployment. +- `msrun `_: `msrun` is the capsulation of Dynamic cluster. It allows user to launch distributed jobs using one single command in each node. It could be used after MindSpore is installed. This method does not rely on third-party libraries and configuration files, has disaster recovery function, good security, and supports three hardware platforms. It is recommended that users prioritize the use of this startup method. +- `Dynamic cluster `_: dynamic cluster requires user to spawn multiple processes and export environment variables. It's the implementation of `msrun`. Use this method when running `Parameter Server` training mode. For other distributed jobs, `msrun` is recommended. +- `mpirun `_: this method relies on the open source library OpenMPI, and startup command is simple. Multi-machine need to ensure two-by-two password-free login. It is recommended for users who have experience in using OpenMPI to use this startup method. +- `rank table `_: this method requires the Ascend hardware platform and does not rely on third-party library. After manually configuring the rank_table file, you can start the parallel program via a script, and the script is consistent across multiple machines for easy batch deployment. .. warning:: `rank_table` method will be deprecated in MindSpore 2.4 version. diff --git a/tutorials/experts/source_en/parallel/strategy_select.md b/docs/mindspore/source_en/model_train/parallel/strategy_select.md similarity index 34% rename from tutorials/experts/source_en/parallel/strategy_select.md rename to docs/mindspore/source_en/model_train/parallel/strategy_select.md index 7f8f6cd90e72b11c890d7445ccf252ff8f80a18f..a0b70907046767ea0249fb7492caf35d9010c3b5 100644 --- a/tutorials/experts/source_en/parallel/strategy_select.md +++ b/docs/mindspore/source_en/model_train/parallel/strategy_select.md @@ -1,18 +1,18 @@ # Strategy Selection -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/strategy_select.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/strategy_select.md) ## Overview In distributed model training, for different model sizes and data volume sizes, different parallel strategies can be chosen to improve training efficiency and resource utilization. The following are the explanation and application of different parallel strategies: -1. [Data Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/data_parallel.html): Data parallel is the process of distributing different training samples to different devices (e.g., Ascend or GPUs) during the training process, with each device computing the gradient of its assigned sample. The parameters of the model are then updated by averaging or accumulating the gradients. Data parallel is suitable for situations where the amount of data is large and the number of model parameters is small enough to be loaded on a single device. Data parallel can speed up the training process by fully utilizing the computing power of multiple devices. +1. [Data Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/data_parallel.html): Data parallel is the process of distributing different training samples to different devices (e.g., Ascend or GPUs) during the training process, with each device computing the gradient of its assigned sample. The parameters of the model are then updated by averaging or accumulating the gradients. Data parallel is suitable for situations where the amount of data is large and the number of model parameters is small enough to be loaded on a single device. Data parallel can speed up the training process by fully utilizing the computing power of multiple devices. -2. [Operator-level Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/operator_parallel.html): Operator-level parallel means that the input tensor and model parameters are sliced into multiple devices for computation on an operator basis, with each device being responsible for computing a part of the model to improve overall speed. Operator-level parallel is subdivided into [semi-automatic parallel mode](https://www.mindspore.cn/tutorials/experts/en/master/parallel/semi_auto_parallel.html), which requires manual configuration of the sharding strategy, and [automatic parallel mode](https://www.mindspore.cn/tutorials/experts/en/master/parallel/semi_auto_parallel.html) that requires little or even no configuration of the sharding strategy. Operator-level parallel is suitable for cases where the model architecture is large and cannot be fully loaded into a single device memory. +2. [Operator-level Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/operator_parallel.html): Operator-level parallel means that the input tensor and model parameters are sliced into multiple devices for computation on an operator basis, with each device being responsible for computing a part of the model to improve overall speed. Operator-level parallel is subdivided into [semi-automatic parallel mode](https://www.mindspore.cn/docs/en/master/model_train/parallel/semi_auto_parallel.html), which requires manual configuration of the sharding strategy, and [automatic parallel mode](https://www.mindspore.cn/docs/en/master/model_train/parallel/semi_auto_parallel.html) that requires little or even no configuration of the sharding strategy. Operator-level parallel is suitable for cases where the model architecture is large and cannot be fully loaded into a single device memory. -3. [Optimizer Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/optimizer_parallel.html): Optimizer parallel can effectively reduce memory consumption and improve network performance on large-scale networks (e.g., Bert, GPT) by spreading the optimizer computation over cards with data parallel dimensions, and is recommended to be turned on for parallel training. +3. [Optimizer Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/optimizer_parallel.html): Optimizer parallel can effectively reduce memory consumption and improve network performance on large-scale networks (e.g., Bert, GPT) by spreading the optimizer computation over cards with data parallel dimensions, and is recommended to be turned on for parallel training. -4. [Pipeline Parallel](https://www.mindspore.cn/tutorials/experts/en/master/parallel/pipeline_parallel.html): Pipeline parallel divides the entire training process into multiple phases, with computations in each phase performed on a different device. Data flows between stages, similar to an assembly line. This strategy is applicable when the network model is large and cannot be loaded by a single card, and when the network can be more evenly divided into multiple phases of computation with longer computation times for each phase, thus maximizing overlapping computation and communication. +4. [Pipeline Parallel](https://www.mindspore.cn/docs/en/master/model_train/parallel/pipeline_parallel.html): Pipeline parallel divides the entire training process into multiple phases, with computations in each phase performed on a different device. Data flows between stages, similar to an assembly line. This strategy is applicable when the network model is large and cannot be loaded by a single card, and when the network can be more evenly divided into multiple phases of computation with longer computation times for each phase, thus maximizing overlapping computation and communication. The selection of an appropriate parallel strategy depends on the specific training task and resource allocation. Typically, the selection can be based on the following guidelines: diff --git a/tutorials/experts/source_en/parallel/support_dynamic_shape_in_parallel.md b/docs/mindspore/source_en/model_train/parallel/support_dynamic_shape_in_parallel.md similarity index 98% rename from tutorials/experts/source_en/parallel/support_dynamic_shape_in_parallel.md rename to docs/mindspore/source_en/model_train/parallel/support_dynamic_shape_in_parallel.md index 6c7b20ad175ba28c0d24676aa67b2cb9de1bf8ba..0a3ac2a283a60f26f64aad2b6107b251142db201 100644 --- a/tutorials/experts/source_en/parallel/support_dynamic_shape_in_parallel.md +++ b/docs/mindspore/source_en/model_train/parallel/support_dynamic_shape_in_parallel.md @@ -1,6 +1,6 @@ # Distributed Parallel Supports Dynamic Shape -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/parallel/support_dynamic_shape_in_parallel.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/support_dynamic_shape_in_parallel.md) ## Overview diff --git a/docs/mindspore/source_zh_cn/design/images/dynamic.png b/docs/mindspore/source_en/model_train/program_form/images/dynamic.png similarity index 100% rename from docs/mindspore/source_zh_cn/design/images/dynamic.png rename to docs/mindspore/source_en/model_train/program_form/images/dynamic.png diff --git a/docs/mindspore/source_en/note/index_support.md b/docs/mindspore/source_en/model_train/program_form/index_support.md similarity index 99% rename from docs/mindspore/source_en/note/index_support.md rename to docs/mindspore/source_en/model_train/program_form/index_support.md index a2feec93cf78022fecdebd80ea2fabf82b72a915..a4c3cb4ca8895551352618eca637b63f2b809a86 100644 --- a/docs/mindspore/source_en/note/index_support.md +++ b/docs/mindspore/source_en/model_train/program_form/index_support.md @@ -1,6 +1,6 @@ # Tensor Index Support -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/index_support.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/index_support.md) Single-level and multi-level Tensor indexing is supported on both PyNative and Graph mode. diff --git a/docs/mindspore/source_en/model_train/program_form/interface.md b/docs/mindspore/source_en/model_train/program_form/interface.md new file mode 100644 index 0000000000000000000000000000000000000000..46882ceead886b78aeb19588dac42dedd7a4ad1c --- /dev/null +++ b/docs/mindspore/source_en/model_train/program_form/interface.md @@ -0,0 +1,3 @@ +# Interface Forms + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/interface.md) diff --git a/docs/mindspore/source_en/model_train/program_form/jit.md b/docs/mindspore/source_en/model_train/program_form/jit.md new file mode 100644 index 0000000000000000000000000000000000000000..29f2eac2f16443b793c2e8728eba0ff86d498126 --- /dev/null +++ b/docs/mindspore/source_en/model_train/program_form/jit.md @@ -0,0 +1,188 @@ +# Dynamic and Static Conversion + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/jit.md) + +## Overview + +The industry currently supports both dynamic and static graph modes. Dynamic graphs are executed by interpretation, with dynamic syntax affinity and flexible expression, and static graphs are executed by using jit compilation optimization, more inclined to static syntax and more restrictions in syntax. For dynamic and static graph modes, firstly MindSpore unifies the API expression, uses the same API in both modes, secondly, unifies the underlying differential mechanism of dynamic and static graphs. + +![dynamic](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/program_form/images/dynamic.png) + +## Interconversion of Dynamic and Static Graphs + +In MindSpore, we can switch the execution between using dynamic or static graphs by controlling the mode input parameters. For example: + +```python +ms.set_context(mode=ms.PYNATIVE_MODE) +``` + +Since there are restrictions on Python syntax under static graphs, switching from dynamic to static graphs requires compliance with the syntax restrictions of static graphs in order to execute correctly by using static graphs. For more syntax restrictions for static graphs, refer to [Static Graph Syntax Restrictions](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +## Combination of Static and Dynamic Graphs + +MindSpore supports mixed execution by using static compilation under dynamic graphs. The function objects that need to be executed with static graphs by using jit modification, and in this way you can achieve mixed execution of dynamic and static graphs. For more use of jit, refer to [jit documentation](https://www.mindspore.cn/tutorials/en/master/beginner/accelerate_with_static_graph.html#decorator-based-startup-method). + +For example: + +```python +import numpy as np +import mindspore as ms +import mindspore.nn as nn + +class AddMulMul(nn.Cell): + def __init__(self): + super(AddMulMul, self).__init__() + self.param = ms.Parameter(ms.Tensor(0.5, ms.float32)) + + @ms.jit + def construct(self, x): + x = x + x + x = x * self.param + x = x * x + return x + +class CellCallSingleCell(nn.Cell): + def __init__(self): + super(CellCallSingleCell, self).__init__() + self.conv = nn.Conv2d(1, 2, kernel_size=2, stride=1, padding=0, weight_init="ones", pad_mode="valid") + self.bn = nn.BatchNorm2d(2, momentum=0.99, eps=0.00001, gamma_init="ones") + self.relu = nn.ReLU() + self.add_mul_mul = AddMulMul() + + def construct(self, x): + x = self.conv(x) + x = self.bn(x) + x = self.add_mul_mul(x) + x = self.relu(x) + return x + +ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") +inputs = ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32)) +net = CellCallSingleCell() +out = net(inputs) +print(out) +``` + +```text +[[[[15.99984]] + + [[15.99984]]]] +``` + +## Static Graph Syntax Enhancement + +In the MindSpore static graph mode, users need to follow MindSpore [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html) when writing programs, and there are constraints on the use of syntax. In dynamic graph mode, Python script code will be executed according to Python syntax, and users can use any Python syntax. It can be seen that the syntax constraints of static and dynamic graphs are different. + +JIT Fallback considers the unification of static and dynamic graphs from the perspective of static graphs. When an unsupported syntax is found during compilation, the syntax is Fallback to the Python interpreter for interpretation execution. Through the JIT Fallback feature, static graphs can support as much dynamic graph syntax as possible, so that static graphs provide a syntax experience close to dynamic graphs, so as to achieve dynamic and static unity. + +In the graph mode scenario, the MindSpore framework will report an error when it encounters unsupported syntax or symbols during graph compilation, mostly in the type inference stage. In the graph compilation stage, the Python source code written by the user is parsed, and then subsequent static analysis, type derivation, optimization and other steps are performed. Therefore, the JIT Fallback feature needs to be pre-detected for unsupported syntax. Common unsupported syntax mainly includes: calling methods of third-party libraries, calling class names to create objects, calling unsupported Python built-in functions, etc. Interpret execution of unsupported syntax Fallback to the Python interpreter. Since the graph mode uses [MindSpore IR (MindIR)](https://www.mindspore.cn/docs/en/master/design/all_scenarios.html#mindspore-ir-mindir), it is necessary to convert the statement executed by the interpretation to the intermediate representation and record the information required by the interpreter. + +The following mainly introduces the static graph syntax supported using the JIT Fallback extension. The default value of the JIT syntax support level option jit_syntax_level is 'LAX', extending the static graph syntax with the ability of JIT Fallback. + +### Calling the Third-party Libraries + +Complete support for third-party libraries such as NumPy and SciPy. The static graph mode supports many third-party library data types such as np.ndarray and their operation operations, supports obtaining properties and methods that call third-party libraries, and supports interacting with third-party libraries such as NumPy through methods such as Tensor's asnumpy(). In other words, users can call MindSpore's own interface and operator in static graph mode, or directly call the interface of the three-party library, or use them together. + +- Supporting data types of third-party libraries (such as NumPy and SciPy), allowing calling and returning objects of third-party libraries. +- Supporting calling methods of third-party libraries. +- Supporting creating Tensor instances by using the data types of the third-party library NumPy. +- The assignment of subscripts for data types in third-party libraries is not currently supported. + +For more usage, please refer to the [Calling the Third-party Libraries](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#calling-the-third-party-libraries-1) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +### Supporting the Use of Custom Classes + +Custom classes that do not use '@jit_class' decorations and do not inherit 'nn. Cell`. Through the JIT Fallback technical solution, static graph mode allows creating and referencing instances of custom classes, can directly obtain and call properties and methods of custom class instances, and allows modifying properties(Inplace operations). + +For more usage, please refer to the [Supporting the Use of Custom Classes](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#supporting-the-use-of-custom-classes) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +### Basic Operators Support More Data Types + +In the syntax of graph mode, the following basic operators in the list are overloaded: ['+', '-', '*', '/', '//', '%', '**', '<<', '>>', '&', '|', '^', 'not', '==', '!=', '<', '>', '<=', '>=', 'in', 'not in', 'y=x[0]']. For more details, please refer to [Operators](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph_syntax/operators.html). When getting unsupported input type, those operators need to use extended static graph syntax to support, and make the output consistent with the output in the pynative mode. + +For more usage, please refer to the [Basic Operators Support More Data Type](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#basic-operators-support-more-data-type) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +### Base Type + +Use the JIT Fallback feature to extend support for Python's native data types 'List', 'Dictionary', 'None'. For more usage, please refer to the [Base Type](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#base-type) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +#### Supporting List Inplace Modification Operations + +- Support for getting the original `List` object from a global variable. +- Inplace operations on input `List` objects are not supported. +- Support for in-place modification of some `List` built-in functions. + +#### Supporting the High-Level Usage of Dictionary + +- Supporting Top Graph Return Dictionary. +- Supporting Dictionary Index Value Retrieval and Assignment. + +#### Supporting the Usage of None + +`None` is a special value in Python that represents null and can be assigned to any variable. Functions that do not have a return value statement are considered to return `None`. At the same time, `None` is also supported as the input parameter or return value of the top graph or subgraph. Support `None` as a subscript of a slice as input to `List`, `Tuple`, `Dictionary`. + +### Built-in Functions Support More Data Types + +Extend the support for built-in functions. Python built-in functions perfectly support more input types, such as third-party library data types. More support for built-in functions can be found in the [Python built-in functions](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph_syntax/python_builtin_functions.html) section. + +### Supporting Control Flow + +In order to improve the support of Python standard syntax, realize dynamic and static unification, and extend the support for more data types in the use of control flow statements. Control flow statements refer to flow control statements such as 'if', 'for', and 'while'. Theoretically, by extending the supported syntax, it is also supported in control flow scenarios. For more usage, please refer to [Supporting Control Flow](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#supporting-control-flow) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +### Supporting Property Setting and Modification + +More types of inplace operations are supported. The previous version only supported value modification of the Parameter type through the Inplace operator, and in the static graph mode of MindSpore version 2.1, the properties of custom classes, Cell subclasses, and jit_class classes were supported. In addition to supporting changing the properties of class self and global variables, it also supports inplace operations such as extend(), reverse(), insert(), pop() of the List type. For more usage, please refer to the [Supporting Property Setting and Modification](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#supporting-property-setting-and-modification) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +- Set and modify properties of custom class objects and third-party types. +- Make changes to the Cell's self object. +- Set and modify Cell objects and jit_class objects in the static graph. + +### Supporting Derivation + +The static graph syntax supported by JIT Fallback also supports its use in derivation. For more usage, please refer to the [Supporting Derivation](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#supporting-derivation) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +### Annotation Type + +For the syntax supported by the runtime extensions, nodes are generated that cannot be derived by type and are called `Any` types. Since the type cannot derive the correct type at compile time, this `Any` will be operated with a default maximum precision 'Float64' to prevent loss of precision. To optimize performance, it is recommended to minimize the generation of `Any` types. When the user knows exactly what type of statement will be generated through the extension, it is recommended to use `Annotation @jit.typing:` to specify the corresponding Python statement type, thereby determining the type of the interpretation node and avoiding the generation of `Any` types. For more usage, please refer to the [Annotation Type](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#annotation-type) section in [Static Graph Syntax Support](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html). + +### Instructions for Use + +When using the static graph extension support syntax, note the following points: + +1. In order to match the support capability of the dynamic graph. That is, it must be within the scope of dynamic graph syntax, including but not limited to data types. + +2. When extending the static graph syntax, more syntax is supported, but the execution performance may be affected and is not optimal. + +3. When extending the static graph syntax, more syntax is supported, and the ability to import and export cannot be used with MindIR due to use Python. + +4. It is not currently supported that the repeated definition of global variables with the same name across Python files, and these global variables are used in the network. + +## Conversion Technique from Dynamic Graph to Static Graph + +MindSpore provides PIJit, a feature that directly converts a user's dynamic graph code into a static graph without code changes. This feature balances performance and ease of use, removes the cost of switching between static and dynamic modes, and truly unifies static and dynamic modes. It is based on the analysis of Python bytecode, and captures the execution flow of Python graphs. Subgraphs that can be run as static graphs are run as static graphs, and subgraphs that are not supported by Python syntax are run as dynamic graphs, and at the same time, by modifying and adjusting the bytecode to link the static graphs, it achieves the mixed execution of static and dynamic modes. In order to meet the premise of ease of use, improve performance. + +### PIJit Includes the Following Features + +- 1. Graph Capture: Pre-processing of bytecode, dynamically tracking the execution of the interpretation, recognizing MindSpore accessible graph operations, and providing split graph to ensure the correctness of function (bytecode) functionality. +- 2. Bytecode Support: Currently supports Python 3.7, Python 3.8, Python 3.9 and Python 3.10 version bytecode. +- 3. Graph Optimization: Optimize the bytecode generated in the graph, including branch cropping, bytecode filtering, function bytecode inlining, constant folding and other functions. +- 4. Exception Capture Mechanism: support for with, try-except syntax. +- 5. Support loop processing: implement features such as graph capture and split graph by simulating the operation stack of bytecode. +- 6. UD Analysis: The method of user-def chain analysis of variables solves the problem that some parameter types cannot be used as the return value of static graphs (Function, Bool, None), and reduces the useless parameters, improves the execution efficiency of the graphs, and reduces the copying of data. +- 7. Side effect analysis and processing: to make up for the disadvantage of side effect processing of static graphs. According to different scenarios, collect and record the variables and byte codes that generate side effects, and supplement the processing of side effects outside the static graphs on the basis of guaranteeing the semantics of the program. +- 8. Guard: The Guard records the conditions that need to be met by the inputs for the subgraph/optimization to enter, and checks if the inputs are suitable for the corresponding subgraph optimization. +- 9. Cache:The graph management caches the subgraph/optimization and Guard correspondences. +- 10. Dynamic Shape and Symbolic Shape: Use input_signature to support Dynamic Shape and Symbolic Shape for Tensor/Tensor List/Tensor Tuple as input prompts. Simultaneously supports automatic recognition of Dynamic Shape after multiple runs. +- 11. Compiling by trace: Supports operator and other type derivations during tracking and bytecode analysis processes. +- 12. Automatic mixed precision: Supports the automatic mixed precision capability of the native mindspore.nn.Cell. + +### Usage + +def jit(fn=None, input_signature=None, hash_args=None, jit_config=None, mode="PIJit"): + +The original Jit function uses mode="PSJit", the new feature PIJit uses mode="PIJit", jit_config passes a dictionary of parameters that can provide some optimization and debugging options. For example: print_after_all can print the bytecode of the graph and split graph information, loop_unrolling can provide loop unrolling function, enable_dynamic_shape apply dynamic shape. + +### Limitations + +- It is not supported to run a function with decoration @jit(mode=\"PIJit\") in static graph mode, in which case the decoration @jit(mode=\"PIJit\") is considered invalid. +- Calls to functions with decoration @jit(mode=\"PIJit\") inside functions decorated with @jit(mode=\"PIJit\") are not supported, and the decorated @jit(mode=\"PIJit\") is considered invalid. \ No newline at end of file diff --git a/docs/mindspore/source_en/model_train/program_form/overview.md b/docs/mindspore/source_en/model_train/program_form/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..de49835c27dc6ee2aeef49c8ed4a04dd1f2d0045 --- /dev/null +++ b/docs/mindspore/source_en/model_train/program_form/overview.md @@ -0,0 +1,3 @@ +# Programming Forms Overview + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/overview.md) \ No newline at end of file diff --git a/docs/mindspore/source_en/model_train/program_form/pynative.md b/docs/mindspore/source_en/model_train/program_form/pynative.md new file mode 100644 index 0000000000000000000000000000000000000000..bb1a4547c698cb0b9b534c2b61cafa8d2f5aec31 --- /dev/null +++ b/docs/mindspore/source_en/model_train/program_form/pynative.md @@ -0,0 +1,41 @@ +# Dynamic Graph Programming + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/pynative.md) + +In MindSpore, dynamic graph mode is also known as PyNative mode, which can be set to dynamic graph mode by `set_context(mode=PYNATIVE_MODE)`. In script development and network flow debugging, it is recommended to use dynamic graph mode for debugging, which supports the execution of single operators, common functions and networks, and separate gradient solving operations. + +In PyNative mode, users can use the full Python API. In addition, for using the API provided by MindSpore, the framework will execute the operations of the operator API on the corresponding hardware platform according to the hardware platform (Ascend, GPU, CPU) selected by the user and return the corresponding results. The overall execution process of the framework is as follows: + +![process](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/design/images/framework.png) + +Through the front-end Python API, call to the framework layer, and finally to the corresponding hardware devices to perform calculations. For example, to complete an addition + +```python +import numpy as np +import mindspore as ms +import mindspore.ops as ops + +ms.set_context(mode=ms.PYNATIVE_MODE, device_target="CPU") +x = ms.Tensor(np.ones([1, 3, 3, 4]).astype(np.float32)) +y = ms.Tensor(np.ones([1, 3, 3, 4]).astype(np.float32)) +output = ops.add(x, y) +print(output.asnumpy()) +``` + +```text +[[[[2. 2. 2. 2.] + [2. 2. 2. 2.] + [2. 2. 2. 2.]] + + [[2. 2. 2. 2.] + [2. 2. 2. 2.] + [2. 2. 2. 2.]] + + [[2. 2. 2. 2.] + [2. 2. 2. 2.] + [2. 2. 2. 2.]]]] +``` + +In this example, when the Python interface ops.add(x, y) is called, the Python interface call is called to the C++ layer of the framework via Pybind11, and converted to C++ call. Then the framework will select the corresponding hardware device according to the device_target set by the users, and execute the add operation on that hardware device. + +From the above principle, we can see that in PyNative mode, Python script code will be executed according to Python syntax, and the execution process involves MindSpore's API, which will be accelerated by executing on different hardware according to user settings. Therefore, in PyNative mode, users can use Python syntax and debugging methods at will, for example, you can use common IDEs such as PyCharm and VS Code to debug code. \ No newline at end of file diff --git a/docs/mindspore/source_en/model_train/program_form/static_graph.rst b/docs/mindspore/source_en/model_train/program_form/static_graph.rst new file mode 100644 index 0000000000000000000000000000000000000000..2bdeb744cd7b1646d00d9706d8a03a8a5af2f9af --- /dev/null +++ b/docs/mindspore/source_en/model_train/program_form/static_graph.rst @@ -0,0 +1,2155 @@ +Static Graph Programming +========================= + +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/static_graph.rst + :alt: View Source On Gitee + +.. toctree:: + :maxdepth: 1 + :hidden: + + static_graph_syntax/operators + static_graph_syntax/statements + static_graph_syntax/python_builtin_functions + static_graph_syntax/static_graph_expert_programming.ipynb + +Overview +-------- + +In graph mode, Python code is not executed by the Python interpreter.Instead, the code is compiled into a static computation graph, and then the static computation graph is executed. + +In static graph mode, MindSpore converts Python source code into +Intermediate Representation IR by means of source code conversion and +optimizes IR graphs on this basis, and finally executes the optimized +graphs on hardware devices. MindSpore uses a functional IR based on +graph representations, called MindIR. See `middle representation MindIR `_ for details . + +MindSpore static graph execution process actually consists of two steps, +corresponding to the Define and Run phases of the static graph, but in +practice, the user will not perceive these two phases when the +instantiated Cell object is called. MindSpore encapsulates both phases +in the Cell ``__call__`` method, so the actual calling process is: + +``model(inputs) = model.compile(inputs) + model.construct(inputs)``, +where ``model`` is the instantiated Cell object. + +There are two ways to use the Graph mode. The first way is to call the +``@jit`` decorator to modify a function or a class member method, and +then the decorated function or method will be compiled into a static +computation graph. For details about how to use ``jit``, click `jit API document +`_. +The second way is to set ``ms.set_context(mode=ms.GRAPH_MODE)``, then +write the code in the ``construct`` function of the ``Cell`` so that the +code in the ``construct`` function will be compiled into a static +computation graph. For details about the definition of ``Cell``, click +`Cell API document `_. + +Due to syntax parsing restrictions, the supported data types, syntax, +and related operations during graph building are not completely +consistent with the Python syntax. As a result, some usage is +restricted. Borrowing the traditional JIT compilation idea, considers +the unification of static and dynamic graphs from the perspective of +graph mode and extends the syntax capabilities of graph patterns. The +static graph provides a syntax experience close to that of the dynamic +graph, so as to realize the unity of dynamic and static. In order to +facilitate users to choose whether to extend the static graph syntax, +the JIT syntax support level option 'jit_syntax_level' is provided, and +its value must be in the range of [STRICT,LAX], and selecting 'STRICT' +is considered to use the basic syntax and do not extend the static graph +syntax. The default value is 'LAX', please refer to the `Extended +Syntaxes (LAX level) <#extended-syntaxes-lax-level>`_ section of this +article for more information. All backends are supported at all levels. + +- STRICT: Only basic syntaxes is supported, and execution performance + is optimal. Can be used for MindIR load and export. +- LAX: Supporting more complex syntaxes, compatible with all Python + syntax as much as possible. Cannot be used for MindIR load and export + due to some syntax that may not be able to be exported. + +The following describes the data types, syntax, and related operations +supported during static graph building. These rules apply only to graph +mode. + +Basic Syntaxes (STRICT Level) +----------------------------- + +Constants and Variables Within Static Graphs +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In static graphs, constants and variables are an important concept for +understanding static graph syntax, and many syntaxes support different +methods and degrees in the case of constant input and variable input. +Therefore, before introducing the specific syntax supported by static +graphs, this section first explains the concepts of constants and +variables in static graphs. + +In static graph mode, the operation of a program is divided into +compilation period and execution period. During compilation, the program +is compiled into an intermediate representation graph, and the program +does not actually execute, but statically parses the intermediate +representation through abstract deduction. This makes it impossible to +guarantee that we will get the values of all intermediate representation +nodes at compile time. Constants and variables are distinguished by +their true values in the compiler. + +- Constant: The amount of value that can be obtained during + compilation. +- Variable: The amount of value that cannot be obtained during + compilation. + +Constants Generate Scenes +^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Scalars, lists, and tuples entered as graph mode are constants + (without using the mutable interface). For example: + + .. code:: python + + from mindspore import Tensor, jit + + a = 1 + b = [Tensor([1]), Tensor([2])] + c = ["a", "b", "c"] + + @jit + def foo(a, b, c): + return a, b, c + + In the above code, enter ``a``, ``b``, ``c`` are constants. + +- The result of the constant operation is constant. For example: + + .. code:: python + + from mindspore import jit, Tensor + + @jit + def foo(): + a = 1 + b = "2" + c = Tensor([1, 2, 3]) + return a, b, c + + In the above code, enter ``a``, ``b``, ``c`` are constants. + +- Constant operations obtain a constant result. For example: + + .. code:: python + + from mindspore import jit, Tensor + + @jit + def foo(): + a = Tensor([1, 2, 3]) + b = Tensor([1, 1, 1]) + c = a + b + return c + + In the above code, ``a`` and ``b`` are constants of Tensor generated + in the graph mode, so the result of their calculation is also + constant. However, if one of them is a variable, its return value + will also be a variable. + +Variables Generate Scenes +^^^^^^^^^^^^^^^^^^^^^^^^^ + +- The return value of all mutable interfaces is a variable (whether + mutable is used outside the graph or inside the graph). For example: + + .. code:: python + + from mindspore import Tensor, jit + from mindspore import mutable + + a = mutable([Tensor([1]), Tensor([2])]) + + @jit + def foo(a): + b = mutable(Tensor([3])) + c = mutable((Tensor([1]), Tensor([2]))) + return a, b, c + + In the above code, ``a`` is generated by calling the mutable + interface outside the graph, ``b`` and ``c`` are generated by calling + the mutable interface inside the graph, and ``a``, ``b``, and ``c`` + are variables. + +- Tensors that are inputs to static graphs are variables. For example: + + .. code:: python + + from mindspore import Tensor, jit + + a = Tensor([1]) + b = (Tensor([1]), Tensor([2])) + + @jit + def foo(a, b): + return a, b + + In the above code, ``a`` is the Tensor input as the graph pattern, so + it is a variable. But ``b`` is a tuple that is input to the graph + schema, not a Tensor type, and even if its internal elements are + Tensor, ``b`` is a constant. + +- What is calculated by variables is the variable + + If a quantity is the output of an operator, then it is in most cases + constant. For example: + + .. code:: python + + from mindspore import Tensor, jit, ops + + a = Tensor([1]) + b = Tensor([2]) + + @jit + def foo(a, b): + c = a + b + return c + + In this case , ``c`` is the result of calculations of ``a`` and ``b`` + , and the inputs ``a`` and ``b`` used for the calculation are + variables , so ``c`` is also a variable. + +Data Types +~~~~~~~~~~ + +Built-in Python Data Types +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Currently, the following built-in ``Python`` data types are supported: +``Number``, ``String``, ``List``, ``Tuple``, and ``Dictionary``. + +Number +'''''' + +Supporting ``int``, ``float``, and ``bool``, but does not support +``complex`` numbers. + +``Number`` can be defined on the network. That is, the syntax ``y = 1``, +``y = 1.2``, and ``y = True`` are supported. + +When the data is a constant, the value of the data can be achieved at +compile time, the forcible conversion to ``Number`` is supported in the +network. The syntax ``y = int(x)``, ``y = float(x)``, and +``y = bool(x)`` are supported. When the data is a variable, i.e., you +can get the value only at runtime. It also supports data type conversion +using built-in functions `Python Built-in Functions `_ such as int(), float() and +bool(). For example: + +.. code:: python + + from mindspore import Tensor, jit + + @jit + def foo(x): + out1 = int(11.1) + out2 = int(Tensor([10])) + out3 = int(x.asnumpy()) + return out1, out2, out3 + + res = foo(Tensor(2)) + print("res[0]:", res[0]) + print("res[1]:", res[1]) + print("res[2]:", res[2]) + +The results are as follows: + +.. code:: text + + res[0]: 11 + res[1]: 10 + res[2]: 2 + +Supporting returning Number. For example: + +.. code:: python + + import mindspore as ms + + @ms.jit + def test_return_scalar(x, y): + return x + y + + res = test_return_scalar(ms.mutable(1), ms.mutable(2)) + print(res) + +The results are as follows: + +.. code:: text + + 3 + +String +'''''' + +``String`` can be constructed on the network, i.e., support for using +quotes (``'`` or ``"``) to create strings such as ``x = 'abcd'`` or +``y = "efgh"``. Convert constants to strings by means of ``str()``. +Support string concatenation, truncation, and the use of membership +operators (``in`` or ``not in``) to determine whether a string contains +the specified character. Support for formatting string output by +inserting a value into a string with the string format ``%s``. Support +for using the format string function ``str.format()`` in constant +scenarios. + +For example: + +.. code:: python + + from mindspore import jit + + @jit + def foo(): + var1 = 'Hello!' + var2 = "MindSpore" + var3 = str(123) + var4 = "{} is {}".format("string", var3) + return var1[0], var2[4:9], var1 + var2, var2 * 2, "H" in var1, "My name is %s!" % var2, var4 + + res = foo() + print("res:", res) + +The results are as follows: + +.. code:: text + + res: ('H', 'Spore', 'Hello!MindSpore', 'MindSporeMindSpore', True, 'My name is MindSpore!', 'string is 123') + +List +'''' + +When 'JIT_SYNTAX_LEVEL' is set to 'LAX', static graph mode can support +the inplace operation of some 'List' objects, see `Supporting List +Inplace Modification +Operations `_. + +The basic usage scenarios of 'List' are as follows: + +- The graph mode supports creating ``Lists`` in graph. + + Support creating ``List`` objects within graph mode, and the elements + of the ``List`` objects can contain any of the types supported by the + graph mode, as well as multiple levels of nesting. For example: + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def generate_list(): + a = [1, 2, 3, 4] + b = ["1", "2", "a"] + c = [ms.Tensor([1]), ms.Tensor([2])] + d = [a, b, c, (4, 5)] + return d + + The above sample code, all ``List`` objects can be created normally. + +- The graph mode supports returning ``List`` + + Before MindSpore version 2.0, ``List`` is converted to ``Tuple`` when + the graph mode returns a ``List`` object. In MindSpore version 2.0, + ``List`` objects can be returned. For example: + + .. code:: python + + import mindspore as ms + + @ms.jit + def list_func(): + a = [1, 2, 3, 4] + return a + + output = list_func() # output: [1, 2, 3, 4] + + In the same way that a ``List`` is created within a graph mode, the + graph mode returns a ``List`` object that can include any of the + types supported by the graph mode, as well as multiple levels of + nesting. + +- The graph mode supports obtaining ``List`` objects from global + variables + + .. code:: python + + import mindspore as ms + + global_list = [1, 2, 3, 4] + + @ms.jit + def list_func(): + global_list.reverse() + return global_list + + output = list_func() # output: [4, 3, 2, 1] + + It should be noted that the list returned in the following pattern in + the basic scenario is not the same object as the list of global + variables, and when 'JIT_SYNTAX_LEVEL' is set to 'LAX', the returned + object and the global object are unified objects. + +- Graph mode supports ``List`` as input + + The graph mode supports ``List`` as input to static graphs. The + elements of the ``List`` object used as input must be of an input + type supported by the graph mode, which also supports multiple levels + of nesting. + + .. code:: python + + import mindspore as ms + + list_input = [1, 2, 3, 4] + + @ms.jit + def list_func(x): + return x + + output = list_func(list_input) # output: [1, 2, 3, 4] + + It should be noted that when 'List' is input as a static graph, it is + always treated as a constant, regardless of the type of element + inside it. + +- Graph mode supports built-in methods for List + + The 'List' built-in method is described in detail below: + + - List Index Value + + Basic syntax: ``element = list_object[index]``. + + Basic semantics: Extract the element in the 'List' object in the + 'index' bit ('index' starts at 0). Supporting multi-level index + values. + + Index value 'index' supported types include 'int', 'Tensor', and + 'slice'. Among them, inputs of type 'int' and 'Tensor' can support + constants and variables, and 'slice' internal data must be + constants that can be determined at compile time. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + @ms.jit() + def list_getitem_func(): + x = [[1, 2], 3, 4] + a = x[0] + b = x[0][ms.Tensor([1])] + c = x[1:3:1] + return a, b, c + + a, b, c = list_getitem_func() + print('a:{}'.format(a)) + print('b:{}'.format(b)) + print('c:{}'.format(c)) + + The results are as follows: + + .. code:: text + + a:[1, 2] + b:2 + c:[3, 4] + + - List index assignment + + Basic syntax: ``list_object[index] = target_element``. + + Basic semantics: Assign the element in the 'List' object at bit + 'index' to 'target_element' ('index' starts at 0). Support for + multi-tier index assignment. + + Index value 'index' supported types include 'int', 'Tensor', and + 'slice'. Among them, inputs of type 'int' and 'Tensor' can support + constants and variables, and the internal data of 'slice' must be + constant that can be determined at compile time. + + The index assignment object 'target_element' supports all data + types supported by graph modes. + + Currently, the 'List' index assignment does not support the + inplace operation, and a new object will be generated after the + index is assigned. This operation will support the inplace + operation in the future. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_setitem_func(): + x = [[0, 1], 2, 3, 4] + x[1] = 10 + x[2] = "ok" + x[3] = (1, 2, 3) + x[0][1] = 88 + return x + + output = test_setitem_func() + print('output:{}'.format(output)) + + The results are as follows: + + .. code:: text + + output:[[0, 88], 10, 'ok', (1, 2, 3)] + + - List.append + + Basic syntax: ``list_object.append(target_element)``. + + Basic semantics: Append the element 'target_element' to the last + list_object' of the 'List' object. + + Currently, 'List.append' does not support the inplace operation, + and a new object will be generated after index assignment. This + operation will support the inplace operation in the future. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list(): + x = [1, 2, 3] + x.append(4) + return x + + x = test_list() + print('x:{}'.format(x)) + + The results are as follows: + + .. code:: text + + x:[1, 2, 3, 4] + + - List.clear + + Basic syntax: ``list_object.clear()``. + + Base semantics: Empty the elements contained in the 'List' object + 'list_object'. + + Currently, 'List.clear' does not support inplace, and a new object + will be generated after index assignment. This operation will + support inplace in the future. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_clear(): + x = [1, 3, 4] + x.clear() + return x + + x = test_list_clear() + print('x:{}'.format(x)) + + The results are as follows: + + .. code:: text + + x:[] + + - List.extend + + Basic syntax: ``list_object.extend(target)``. + + Basic semantics: Insert all elements inside the 'target' to the + end of the 'List' object 'list_object'. + + The supported types for 'target' are 'Tuple', 'List', and + 'Tensor'. Among them, if the 'target' type is 'Tensor', the + 'Tensor' will be converted to 'List' before inserting it. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_extend(): + x1 = [1, 2, 3] + x1.extend((4, "a")) + x2 = [1, 2, 3] + x2.extend(ms.Tensor([4, 5])) + return x1, x2 + + output1, output2 = test_list_extend() + print('output1:{}'.format(output1)) + print('output2:{}'.format(output2)) + + The results are as follows: + + .. code:: text + + output1:[1, 2, 3, 4, 'a'] + output2:[1, 2, 3, Tensor(shape=[1], dtype=Int64, value= [4]), Tensor(shape=[1], dtype=Int64, value= [5])] + + - List.pop + + Basic syntax: ``pop_element = list_object.pop(index=-1)``. + + Basic semantics: Remove the 'index' element of the 'List' object + 'list_object' from the 'list_object' and return the element. + + The 'index' requires that it must be a constant 'int', and when + 'list_object' has a length of 'list_obj_size', 'index' has a value + range of '[-list_obj_size,list_obj_size-1]'. 'index' is a negative + number representing the number of digits from back to front. When + no 'index' is entered, the default value is -1, i.e. the last + element is removed. + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_pop(): + x = [1, 2, 3] + b = x.pop() + return b, x + + pop_element, res_list = test_list_pop() + print('pop_element:{}'.format(pop_element)) + print('res_list:{}'.format(res_list)) + + The results are as follows: + + .. code:: text + + pop_element:3 + res_list:[1, 2] + + - List.reverse + + Basic syntax: ``list_object.reverse()``. + + Basic semantics: Reverse the order of the elements of the 'List' + object 'list_object'. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_reverse(): + x = [1, 2, 3] + x.reverse() + return x + + output = test_list_reverse() + print('output:{}'.format(output)) + + The results are as follows: + + .. code:: text + + output1:[3, 2, 1] + + - List.insert + + Basic syntax: ``list_object.insert(index, target_obj)``. + + Basic semantics: insert 'target_obj' into the 'index' bit of + 'list_object'. + + The 'index' requirement must be a constant 'int'. If the length of + 'list_object' is 'list_obj_size'. When 'index < -list_obj_size', + insert the first place in 'List'. When 'index >= list_obj_size', + insert at the end of 'List'. A negative 'index' represents the + number of digits from back to front. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_insert(): + x = [1, 2, 3] + x.insert(3, 4) + return x + + output = test_list_insert() + print('output:{}'.format(output)) + + The results are as follows: + + .. code:: text + + output:[1, 2, 3, 4] + +Tuple +''''' + +``Tuple`` can be constructed on the network, that is, the syntax +``y = (1, 2, 3)`` is supported. The elements of the tuple ``Tuple`` +cannot be modified, but indexed access to elements in the tuple +``Tuple`` is supported, and concatenated combinations of tuples are +supported. + +- Supported index values + + Support accessing elements in the tuple ``Tuple`` using square + brackets plus subscripted indexes. The index value can be ``int``, + ``slice``, ``Tensor``, and multi-level index value. That is, the + syntax ``data = tuple_x[index0][index1]...`` is supported. + + Restrictions on the index value ``Tensor`` are as follows: + + - ``Tuple`` stores ``Cell``. Each ``Cell`` must be defined before a + tuple is defined. The number of input parameters, input parameter + type, and input parameter ``shape`` of each ``Cell`` must be the + same. The number of outputs of each ``Cell`` must be the same. The + output type must be the same as the output ``shape``. + + - The index ``Tensor`` is a scalar ``Tensor`` whose ``dtype`` is + ``int32``. The value range is ``[-tuple_len, tuple_len)``, and + negative index is not supported in ``Ascend`` backend. + + - ``CPU``, ``GPU`` and ``Ascend`` backend is supported. + + An example of the ``int`` and ``slice`` indexes is as follows: + + .. code:: python + + import numpy as np + import mindspore as ms + + t = ms.Tensor(np.array([1, 2, 3])) + + @ms.jit() + def test_index(): + x = (1, (2, 3, 4), 3, 4, t) + y = x[1][1] + z = x[4] + m = x[1:4] + n = x[-4] + return y, z, m, n + + y, z, m, n = test_index() + print('y:{}'.format(y)) + print('z:{}'.format(z)) + print('m:{}'.format(m)) + print('n:{}'.format(n)) + + The results are as follows: + + .. code:: text + + y:3 + z:[1 2 3] + m:((2, 3, 4), 3, 4) + n:(2, 3, 4) + + An example of the ``Tensor`` index is as follows: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.relu = nn.ReLU() + self.softmax = nn.Softmax() + self.layers = (self.relu, self.softmax) + + def construct(self, x, index): + ret = self.layers[index](x) + return ret + + x = ms.Tensor([-1.0], ms.float32) + + net = Net() + ret = net(x, 0) + print('ret:{}'.format(ret)) + + The results are as follows: + + .. code:: text + + ret:[0.] + +- Support connection combinations + + Similar to the string ``String``, tuples support combining using + ``+`` and ``*`` to get a new tuple ``Tuple``, for example: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_index(): + x = (1, 2, 3) + y = (4, 5, 6) + return x + y, x * 2 + + out1, out2 = test_index() + print('out1:{}'.format(out1)) + print('out2:{}'.format(out2)) + + The results are as follows: + + .. code:: text + + out1:(1, 2, 3, 4, 5, 6) + out2:(1, 2, 3, 1, 2, 3) + +Dictionary +'''''''''' + +``Dictionary`` can be constructed on the network. Each key value +``key:value`` is separated by a colon ``:``, and each key value pair is +separated by a comma ``,``. The entire dictionary contains the key-value +pairs using curly braces ``{}``. That is, the syntax +``y = {"a": 1, "b": 2}`` is supported. + +The ``key`` is unique, and if there are multiple identical ``keys`` in +the dictionary, the duplicate ``keys`` are finalized with the last one +and the value ``value`` can be non-unique. The key ``key`` needs to be +guaranteed to be immutable. Currently, the ``key`` can be ``String``, +``Number``, constant ``Tensor``, or ``Tuple`` that contains these types. +The ``value`` can be ``Number``, ``Tuple``, ``Tensor``, ``List`` or +``Dictionary``. + +- Supported APIs + + ``keys``: extracts all ``key`` values from ``dict`` to form ``Tuple`` + and return it. + + ``values``: extracts all ``value`` values from ``dict`` to form + ``Tuple`` and return it. + + ``items``: extracts ``Tuple`` composed of each pair of ``value`` + values and ``key`` values in ``dict`` to form ``List`` and return it. + + ``get``: ``dict.get(key[, value])`` returns the ``value`` value + corresponding to the specified ``key``, if the specified ``key`` does + not exist, the default value ``None`` or the set default value + ``value`` is returned . + + ``clear``: removes all elements in ``dict``. + + ``has_key``: ``dict.has_key(key)`` determines whether the specified + ``key`` exists in ``dict``. + + ``update``: ``dict1.update(dict2)`` updates the elements in ``dict2`` + to ``dict1``. + + ``fromkeys``: ``dict.fromkeys(seq([, value]))`` is used to create a + new ``Dictionary``, using the elements in the sequence ``seq`` as the + ``key`` of the ``Dictionary``, and the ``value`` is initial value + corresponding to all ``key``. + + The example is as follows, where the 'x' and 'new_dict' in the return + value are a 'Dictionary', and the support is extended under the JIT + syntax support level option LAX in graph mode, for more advanced use + of Dictionary, please refer to the `Supporting the high-level usage + of Dictionary <#supporting-the-high-level-usage-of-dictionary>`_ + section of this article. + + .. code:: python + + import mindspore as ms + import numpy as np + + x = {"a": ms.Tensor(np.array([1, 2, 3])), "b": ms.Tensor(np.array([4, 5, 6])), "c": ms.Tensor(np.array([7, 8, 9]))} + + @ms.jit() + def test_dict(): + x_keys = x.keys() + x_values = x.values() + x_items = x.items() + value_a = x.get("a") + check_key = x.has_key("a") + y = {"a": ms.Tensor(np.array([0, 0, 0]))} + x.update(y) + new_dict = x.fromkeys("abcd", 123) + return x_keys, x_values, x_items, value_a, check_key, x, new_dict + + x_keys, x_values, x_items, value_a, check_key, new_x, new_dict = test_dict() + print('x_keys:{}'.format(x_keys)) + print('x_values:{}'.format(x_values)) + print('x_items:{}'.format(x_items)) + print('value_a:{}'.format(value_a)) + print('check_key:{}'.format(check_key)) + print('new_x:{}'.format(new_x)) + print('new_dict:{}'.format(new_dict)) + + The results are as follows: + + .. code:: text + + x_keys:('a', 'b', 'c') + x_values:(Tensor(shape=[3], dtype=Int64, value= [1, 2, 3]), Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])) + x_items:[('a', Tensor(shape=[3], dtype=Int64, value= [1, 2, 3])), ('b', Tensor(shape=[3], dtype=Int64, value= [4, 5, 6])), ('c', Tensor(shape=[3], dtype=Int64, value= [7, 8, 9]))] + value_a:[1 2 3] + check_key:True + new_x:{'a': Tensor(shape=[3], dtype=Int64, value= [0, 0, 0]), 'b': Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), 'c': Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])} + new_dict:{'a': 123, 'b': 123, 'c': 123, 'd': 123} + +MindSpore User-defined Data Types +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Currently, MindSpore supports the following user-defined data types: +``Tensor``, ``Primitive``, and ``Cell``. + +Tensor +'''''' + +For details of ``Tensor``, click `Tensor API +document `_. + +Supporting creating and using Tensor. The ways to create a ``Tensor`` +include using `tensor function interface `_ +and using the class 'ms.Tensor' interface. It is recommended to use the +former because users can specify the required dtype. The code case is as +follows. + +.. code:: python + + import mindspore as ms + import mindspore.nn as nn + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + + @ms.jit + def construct(self, x): + return ms.tensor(x.asnumpy(), dtype=ms.float32) + + ms.set_context(mode=ms.GRAPH_MODE) + net = Net() + x = ms.Tensor(1, dtype=ms.int32) + print(net(x)) + +The results are as follows: + +.. code:: text + + 1.0 + +Primitive +''''''''' + +Currently, ``Primitive`` and its subclass instances can be constructed +in construct. + +However, during call, the parameter can be specified only in position +parameter mode, and cannot be specified in the key-value pair mode. + +For example: + +.. code:: python + + import mindspore as ms + from mindspore import nn, ops, Tensor, set_context + import numpy as np + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + + def construct(self, x): + reduce_sum = ops.ReduceSum(True) #`Primitive` and its subclass instances can be constructed in construct. + ret = reduce_sum(x, axis=2) + return ret + + x = Tensor(np.random.randn(3, 4, 5, 6).astype(np.float32)) + net = Net() + ret = net(x) + print('ret.shape:{}'.format(ret.shape)) + +In the network defined above, the parameters of reduce_sum(x, axis=2) +cannot be specified in the key-value pair mode. The parameter can be +specified only in position parameter mode, that is, reduce_sum(x, 2). + +The error is reported as follows: + +.. code:: text + + ValueError: For 'ReduceSum', the second input type should be tensor or scalar, but got invalid abstract type:AbstractKeywordArg. + +Currently, the attributes and APIs related to ``Primitive`` and its +subclasses cannot be called on the network. + +For details about the defined ``Primitive``, click `Primitive API +document `_. + +Cell +'''' + +Currently, ``Cell`` and its subclass instances can be constructed on the +network. That is, the syntax ``cell = Cell(args...)`` is supported. + +However, during call, the parameter can be specified only in position +parameter mode, and cannot be specified in the key-value pair mode. That +is, the syntax ``cell = Cell(arg_name=value)`` is not supported. + +Currently, the attributes and APIs related to ``Cell`` and its +subclasses cannot be called on the network unless they are called +through ``self`` in ``construct`` of ``Cell``. + +For details about the definition of ``Cell``, click `Cell API +document `_. + +Parameter +''''''''' + +``Parameter`` is a variable tensor, indicating the parameters that need +to be updated during network training. + +For details about the definition of ``Parameter``, click `Parameter API +document `_. + +Operators +~~~~~~~~~ + +Arithmetic operators and assignment operators support the ``Number`` and +``Tensor`` operations, as well as the ``Tensor`` operations of different +``dtype``. For more details, please refer to +`Operators `_ + +Primaries +~~~~~~~~~ + +Primaries represent the most tightly bound operations of the language. + +Attribute References and Attribute Modification +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +An attribute reference is a primary followed by a period and a name. + +Using attribute references as l-values in Cell instances of MindSpore +requires the following requirements: + +- The modified attribute belongs to this ``cell`` object, i.e. it must + be ``self.xxx``. +- The attribute is initialized in Cell's '**init**' function and is of + type Parameter. + +When the JIT syntax support level option is 'LAX', can support attribute +modification in more situations, see `Support Attribute Setting and +Modification <#supporting-property-setting-and-modification>`_. + +Examples are as follows: + +.. code:: python + + import mindspore as ms + from mindspore import nn, set_context + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.weight = ms.Parameter(ms.Tensor(3, ms.float32), name="w") + self.m = 2 + + def construct(self, x, y): + self.weight = x # The conditions are met, they can be modified + # self.m = 3 # self.m is not of type Parameter and modification is prohibited + # y.weight = x # y is not self, modification is prohibited + return x + + net = Net() + ret = net(1, 2) + print('ret:{}'.format(ret)) + +The results are as follows: + +.. code:: text + + ret:1 + +Index Value +^^^^^^^^^^^ + +Index value of a sequence ``Tuple``, ``List``, ``Dictionary``, +``Tensor`` which called subscription in Python. + +Index value of ``Tuple`` refers to chapter `Tuple <#tuple>`_ of this +page. + +Index value of ``List`` refers to chapter `List <#list>`_ of this page. + +Index value of ``Dictionary`` refers to chapter +`Dictionary <#dictionary>`_ of this page. + +Index value of ``Tensor`` refers to `Tensor index value +document `_. + +Calls +^^^^^ + +A call calls a callable object (e.g., ``Cell`` or ``Primitive``) with a +possibly empty series of arguments. + +For example: + +.. code:: python + + import mindspore as ms + from mindspore import nn, ops, set_context + import numpy as np + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.matmul = ops.MatMul() + + def construct(self, x, y): + out = self.matmul(x, y) # A call of Primitive + return out + + x = ms.Tensor(np.ones(shape=[1, 3]), ms.float32) + y = ms.Tensor(np.ones(shape=[3, 4]), ms.float32) + net = Net() + ret = net(x, y) + print('ret:{}'.format(ret)) + +The results are as follows: + +.. code:: text + + ret:[[3. 3. 3. 3.]] + +Statements +~~~~~~~~~~ + +Currently supported Python statements include raise statement, assert +statement, pass statement, return statement, break statement, continue +statement, if statement, for statement, while statement, with statement, +list comprehension, generator expression and function definition +statement. For more details, please refer to +`Statements `_ + +Python Built-in Functions +~~~~~~~~~~~~~~~~~~~~~~~~~ + +Currently supported Python built-in functions include ``int``, +``float``, ``bool``, ``str``, ``list``, ``tuple``, ``getattr``, +``hasattr``, ``len``, ``isinstance``, ``all``, ``any``, ``round``, +``max``, ``min`` , ``sum``, ``abs``, ``partial``, ``map``, ``range``, +``enumerate``, ``super``, ``pow``, ``filter``. The use of built-in +functions in graph mode is similar to the corresponding Python built-in +functions. For more details, please refer to `Python Built-in Functions `_. + +Network Definition +~~~~~~~~~~~~~~~~~~ + +Network Input parameters +^^^^^^^^^^^^^^^^^^^^^^^^ + +While calculating gradient for outermost network, only ``Tensor`` input +could be calculated, input of other type will be ignored. + +The code example is shown below. Among the input parameter +``(x, y, z)`` of outermost network, ``x`` and ``z`` are ``Tensor`` type +but ``y`` is not. While ``grad_net`` calculating gradient of the input +parameters ``(x, y, z)`` for the network, gradient of ``y`` is +automatically ignored. Only gradients of ``x`` and ``z`` are calculated, +and ``(grad_x, grad_y)`` is returned. + +.. code:: python + + import numpy as np + import mindspore as ms + from mindspore import nn + + ms.set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + + def construct(self, x, y, z): + return x + y + z + + class GradNet(nn.Cell): + def __init__(self, net): + super(GradNet, self).__init__() + self.forward_net = net + + def construct(self, x, y, z): + return ms.grad(self.forward_net, grad_position=(0, 1, 2))(x, y, z) + + input_x = ms.Tensor([1]) + input_y = 2 + input_z = ms.Tensor([3]) + + net = Net() + grad_net = GradNet(net) + ret = grad_net(input_x, input_y, input_z) + print('ret:{}'.format(ret)) + +The results are as follows: + +.. code:: text + + ret:(Tensor(shape=[1], dtype=Int64, value= [1]), Tensor(shape=[1], dtype=Int64, value= [1])) + +Syntax Constraints of Basic Syntaxes +------------------------------------ + +The execution graph in graph mode is converted from source code, and not +all Python syntax can support it. The following describes some of the +syntax constraints that exist under the basic syntax. More network +compilation problems can be found in `Network +compilation `_. + +1. When an undefined class member is used in the ``construct`` function, + ``AttributeError`` exception will be thrown. For example: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + + def construct(self, x): + return x + self.y + + net = Net() + net(1) + + The error is reported as follows: + + .. code:: text + + AttributeError: External object has no attribute y + +2. Class methods modified by ``classmethod`` in ``nn.Cell`` are not + supported. For example: + + .. code:: python + + import mindspore as ms + + ms.set_context(mode=ms.GRAPH_MODE) + + class Net(ms.nn.Cell): + @classmethod + def func(cls, x, y): + return x + y + + def construct(self, x, y): + return self.func(x, y) + + net = Net() + out = net(ms.Tensor(1), ms.Tensor(2)) + print(out) + + The error is reported as follows: + + .. code:: text + + TypeError: The parameters number of the function is 3, but the number of provided arguments is 2. + +3. In graph mode, some Python syntax is difficult to convert to + `intermediate + MindIR `_ + in graph mode. For Python keywords, there are some keywords that are + not supported in graph mode: AsyncFunctionDef, Delete, AnnAssign, + AsyncFor, AsyncWith, Match, Try, Import, ImportFrom, Nonlocal, + NamedExpr, Set, SetComp, Await, Yield, YieldFrom, Starred. If the + relevant syntax is used in graph mode, an error message will alert + the user. + + If you use the Try statement, the following example is used: + + .. code:: python + + import mindspore as ms + + @ms.jit + def test_try_except(x, y): + global_out = 1 + try: + global_out = x / y + except ZeroDivisionError: + print("division by zero, y is zero.") + return global_out + + test_try_except_out = test_try_except(1, 0) + print("out:", test_try_except_out) + + The error is reported as follows: + + .. code:: text + + RuntimeError: Unsupported statement 'Try'. + +4. Benchmarking Python built-in data types, except for `Built-in Python + Data Types <#built-in-python-data-types>`_ supported in the current + graph mode, complex 'complex' and collection 'set' types are not + supported. Some high-level uses of the list 'list' and dictionary + 'dictionary' are not supported in the basic syntax scenario, and need + to be supported when the JIT syntax support level option + 'jit_syntax_level' is 'LAX', please refer to the `Extended Syntaxes + (LAX level) <#extended-syntaxes-lax-level>`_ section of this article + for more information. + +5. In the basic syntax scenario, in addition to the `Python Built-in + Functions `_ + supported in the current graph mode, there are still some built-in + functions that are not supported in graph mode. For example: + basestring, bin, bytearray, callable, chr, cmp, compile, delattr, + dir, divmod, eval, execfile, file, frozenset, hash, hex, id, input, + issubclass, iter, locals, long, memoryview, next, object, oct, open, + ord, property, raw_input, reduce, reload, repr, reverse, set, slice, + sorted, unichr, unicode, vars, xrange, \__import\_\_. + +6. Python provides a number of third-party libraries that usually need + to be called via import statements. In graph mode, when the JIT + syntax support level is 'STRICT', you cannot directly use third-party + libraries. If you need to use the data types of third-party libraries + in graph mode or call methods of third-party libraries, you need to + support them only if the JIT syntax support level option + 'jit_syntax_level' is 'LAX', please refer to the `Calling the + Third-party Libraries <#calling-the-third-party-libraries>`_ section + in `Extended Syntaxes (LAX level) <#extended-syntaxes-lax-level>`_ + of this article. + +7. In graph mode, the modification of the attributes of the class outside the graph is not perceived, that is, the modification of the attributes of the class outside the graph will not take effect. For example: + + .. code:: python + + import mindspore as ms + from mindspore import nn, ops, Tensor, context + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.len = 1 + + def construct(self, inputs): + x = inputs + self.len + return x + + context.set_context(mode=ms.GRAPH_MODE) + inputs = 2 + net = Net() + print("out1:", net(inputs)) + net.len = 2 + print("out2:", net(inputs)) + + The result of the output will not change: + + .. code:: text + + out1: 3 + out2: 3 + +Extended Syntaxes (LAX level) +----------------------------- + +The following mainly introduces the static graph syntax supported by the +current extension. + +Calling the Third-party Libraries +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- Third-party libraries. + + 1. Python built-in modules and Python standard libraries, such as + ``os``, ``sys``, ``math``, ``time`` and other modules. + + 2. Third-party code libraries. Their module paths are under the + ``site-packages`` directory of the Python installation directory, + which need to be installed first and then imported, such ``NumPy`` + and ``Scipy``. It should be noted that MindSpore suites such as + ``mindyolo`` and ``mindflow`` are not treated as third-party + libraries. For a detailed list, please refer to the + ``_modules_from_mindspore`` list of the + `parser `_ + file. + + 3. Modules specified by the environment variable + ``MS_JIT_IGNORE_MODULES``. In contrast, there is the environment + variable ``MS_JIT_MODULES``. For more details, please refer to + `Environment + Variables `_. + +- Supporting data types of third-party libraries, allowing calling and + returning objects of third-party libraries. + + The code example is as follows. + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + a = np.array([1, 2, 3]) + b = np.array([4, 5, 6]) + out = a + b + return out + + print(func()) + + The results are as follows: + + .. code:: text + + [5 7 9] + +- Supporting calling methods of third-party libraries. + + The code example is as follows. + + .. code:: python + + from scipy import linalg + import mindspore as ms + + @ms.jit + def func(): + x = [[1, 2], [3, 4]] + return linalg.qr(x) + + out = func() + print(out[0].shape) + + The results are as follows: + + .. code:: text + + (2, 2) + +- Supporting creating Tensor instances by using the data types of the + third-party library NumPy. + + The code example is as follows. + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + x = np.array([1, 2, 3]) + out = ms.Tensor(x) + 1 + return out + + print(func()) + + The results are as follows: + + .. code:: text + + [2, 3, 4] + +- The assignment of subscripts for data types in third-party libraries + is not currently supported. + + The code example is as follows. + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + x = np.array([1, 2, 3]) + x[0] += 1 + return ms.Tensor(x) + + res = func() + print("res: ", res) + + The error message is reported as follows: + + .. code:: text + + RuntimeError: For operation 'setitem', current input arguments types are . The 1-th argument type 'External' is not supported now. + +Supporting the Use of Custom Classes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Custom classes can be used in graph mode, and classes can be +instantiated and object properties and methods can be used. + +For example, where 'GetattrClass' is a user-defined class that does not +use the '@jit_class' decoration and does not inherit 'nn. Cell\`。 + +.. code:: python + + import mindspore as ms + + ms.set_context(mode=ms.GRAPH_MODE) + + class GetattrClass(): + def __init__(self): + self.attr1 = 99 + self.attr2 = 1 + + def method1(self, x): + return x + self.attr2 + + class GetattrClassNet(ms.nn.Cell): + def __init__(self): + super(GetattrClassNet, self).__init__() + self.cls = GetattrClass() + + def construct(self): + return self.cls.method1(self.cls.attr1) + + net = GetattrClassNet() + out = net() + assert out == 100 + +Basic Operators Support More Data Type +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In the syntax of graph mode, the following basic operators in the list +is overloaded: ['+', '-', +'\*','/','//','%','\*\*','<<','>>','&','\|','^', 'not', '==', '!=', '<', +'>', '<=', '>=', 'in', 'not in', 'y=x[0]']. For more details, please +refer to +`Operators `_. +When getting unsupported input type, those operators need to use +extended static graph syntax to support, and make the output consistent +with the output in the pynative mode. + +The code example is as follows. + +.. code:: python + + import mindspore as ms + import mindspore.nn as nn + from mindspore import Tensor + ms.set_context(mode=ms.GRAPH_MODE) + + class InnerClass(nn.Cell): + def construct(self, x, y): + return x.asnumpy() + y.asnumpy() + + net = InnerClass() + ret = net(Tensor([4, 5]), Tensor([1, 2])) + print(ret) + +The results are as follows: + +.. code:: text + + [5 7] + +In the example above, since the output of ``x.asnumpy()`` is +``numpy.ndarray`` and is an unsupported input type of ``+`` in the graph +mode, ``x.asnumpy() + y.asnumpy()`` will be supported by static graph +syntax. + +In another example: + +.. code:: python + + class InnerClass(nn.Cell): + def construct(self): + return (None, 1) in ((None, 1), 1, 2, 3) + + net = InnerClass() + print(net()) + +The results are as follows: + +.. code:: text + + True + +``tuple`` in ``tuple`` is an unsupported operation in original graph +mode,and will be supported by static graph syntax. + +Base Type +~~~~~~~~~ + +Use the JIT Fallback feature to extend support for Python's native data +types 'List', 'Dictionary', 'None'. + +Supporting List Inplace Modification Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The list 'List' and tuple 'Tuple' are the most basic sequential built-in +types in Python, and the core difference between 'List' and 'Tuple' is +that 'List' is an object that can be changed, while 'Tuple' cannot be +changed. This means that once 'Tuple' is created, it cannot be changed +without changing the object address. 'List', on the other hand, can +modify an object without changing its address through a series of +inplace operations. For example: + +.. code:: python + + a = [1, 2, 3, 4] + a_id = id(a) + a.append(5) + a_after_id = id(a) + assert a_id == a_after_id + +In the above example code, when you change the 'List' object through the +'append' inplace syntax, the address of the object is not changed. +'Tuple' does not support this kind of inplace. With 'JIT_SYNTAX_LEVEL' +set to 'LAX', static graph mode can support the inplace operation of +some 'List' objects. + +The specific usage scenarios are as follows: + +- Support for getting the original 'List' object from a global variable + + In the following example, the static graph gets the 'List' object, + performs the inplace operation 'list.reverse()' supported by graph + mode on the original object, and returns the original object. It can + be seen that the object returned by the graph mode has the same ID as + the original global variable object, that is, the two are the same + object. If 'JIT_SYNTAX_LEVEL' is set to the 'STRICT' option, the + returned 'List' object and the global object are two different + objects. + + .. code:: python + + import mindspore as ms + + global_list = [1, 2, 3, 4] + + @ms.jit + def list_func(): + global_list.reverse() + return global_list + + output = list_func() # output: [4, 3, 2, 1] + assert id(global_list) == id(output) + +- Inplace operations on input 'List' objects are not supported + + When List' is imported as a static graph, the 'List' object is copied + once, and subsequent calculations are performed using the copied + object, so it is not possible to perform an inplace operation on the + original input object. For example: + + .. code:: python + + import mindspore as ms + + list_input = [1, 2, 3, 4] + + @ms.jit + def list_func(x): + x.reverse() + return x + + output = list_func(list_input) # output: [4, 3, 2, 1] list_input: [1, 2, 3, 4] + assert id(output) != id(list_input) + + As shown in the above use case, the 'List' object cannot be inplaced + on the original object when input as a graph mode. The object + returned by the graph mode is different from the object ID entered. + +- Support for in-place modification of some 'List' built-in functions + + With 'JIT_SYNTAX_LEVEL' set to 'LAX', the graph mode section 'List' + built-in function supports inplace. In cases where 'JIT_SYNTAX_LEVEL' + is 'STRICT', none of the methods support the inplace operation. + + Currently, the built-in methods for 'List' in-place modification + supported by graph mode are 'extend', 'pop', 'reverse', and 'insert'. + The built-in methods 'append', 'clear' and index assignment do not + support in-place modification at the moment, and will be supported in + subsequent versions. + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + list_input = [1, 2, 3, 4] + + @ms.jit + def list_func(): + list_input.reverse() + return list_input + + output = list_func() # output: [4, 3, 2, 1] list_input: [4, 3, 2, 1] + assert id(output) == id(list_input) + +Supporting the High-Level Usage of Dictionary +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Support Top Graph Return Dictionary + + Examples are as follows: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_dict(): + x = {'a': 'a', 'b': 'b'} + y = x.get('a') + z = dict(y=y) + return z + + out = test_dict() + print("out:", out) + + The results are as follows: + + .. code:: text + + out:{'y': 'a'} + +- Support Dictionary Index Value Retrieval and Assignment + + Examples are as follows: + + .. code:: python + + import mindspore as ms + import numpy as np + + x = {"a": ms.Tensor(np.array([1, 2, 3])), "b": ms.Tensor(np.array([4, 5, 6])), "c": ms.Tensor(np.array([7, 8, 9]))} + + @ms.jit() + def test_dict(): + y = x["b"] + x["a"] = (2, 3, 4) + return x, y + + out1, out2 = test_dict() + print('out1:{}'.format(out1)) + print('out2:{}'.format(out2)) + + The results are as follows: + + .. code:: text + + out1:{'a': (2, 3, 4), 'b': Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), 'c': Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])} + out2:[4 5 6] + +Supporting the Usage of None +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +'None' is a special value in Python that represents null and can be +assigned to any variable. Functions that do not have a return value +statement are considered to return 'None'. At the same time, 'None' is +also supported as the input parameter or return value of the top graph +or subgraph. Support 'None' as a subscript of a slice as input to +'List', 'Tuple', 'Dictionary'. + +Examples are as follows: + +.. code:: python + + import mindspore as ms + + @ms.jit + def test_return_none(): + return 1, "a", None + + res = test_return_none() + print(res) + +The results are as follows: + +.. code:: text + + (1, 'a', None) + +For functions with no return value, the 'None' object is returned by +default. + +.. code:: python + + import mindspore as ms + + @ms.jit + def foo(): + x = 3 + print("x:", x) + + res = foo() + assert res is None + +As in the example below, 'None' is used as the default input parameter +for the top graph. + +.. code:: python + + import mindspore as ms + + @ms.jit + def foo(x, y=None): + if y is not None: + print("y:", y) + else: + print("y is None") + print("x:", x) + return y + + x = [1, 2] + res = foo(x) + assert res is None + +Built-in Functions Support More Data Types +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Extend the support for built-in functions. Python built-in functions +perfectly support more input types, such as third-party library data +types. + +For example, in the following example, 'x.asnumpy()' and 'np.ndarray' +are both types supported by extensions. More support for built-in +functions can be found in the `Python built-in functions `_ +section. + +.. code:: python + + import numpy as np + import mindspore as ms + import mindspore.nn as nn + + ms.set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def construct(self, x): + return isinstance(x.asnumpy(), np.ndarray) + + x = ms.Tensor(np.array([-1, 2, 4])) + net = Net() + out = net(x) + assert out + +Supporting Control Flow +~~~~~~~~~~~~~~~~~~~~~~~ + +In order to improve the support of Python standard syntax, realize +dynamic and static unification, and extend the support for more data +types in the use of control flow statements. Control flow statements +refer to flow control statements such as 'if', 'for', and 'while'. +Theoretically, by extending the supported syntax, it is also supported +in control flow scenarios. The code use cases are as follows: + +.. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + x = np.array(1) + if x <= 1: + x += 1 + return ms.Tensor(x) + + res = func() + print("res: ", res) + +The results are as follows: + +.. code:: text + + res: 2 + +Supporting Property Setting and Modification +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The specific usage scenarios are as follows: + +- Set and modify properties of custom class objects and third-party + types + +In graph mode, you can set and modify the properties of custom class +objects, such as: + +.. code:: python + + from mindspore import jit + + class AssignClass(): + def __init__(self): + self.x = 1 + + obj = AssignClass() + + @jit + def foo(): + obj.x = 100 + return + + foo() + print(f"obj.x is: {obj.x}") + +The results are as follows: + +.. code:: text + + obj.x is: 100 + +In graph mode, you can set and modify the properties of third-party +library objects, such as: + +.. code:: python + + from mindspore import jit + import numpy as np + + @jit + def foo(): + a = np.array([1, 2, 3, 4]) + a.shape = (2, 2) + return a.shape + + shape = foo() + print(f"shape is {shape}") + +The results are as follows: + +.. code:: text + + shape is (2, 2) + +- Make changes to the Cell's self object, for example: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.m = 2 + + def construct(self): + self.m = 3 + return + + net = Net() + net() + print(f"net.m is {net.m}") + + The results are as follows: + + .. code:: text + + net.m is 3 + + Note that the self object supports property modification and setting. + If no attribute is defined in '**init**', align the PYNATIVE mode, + and the graph mode also allows this attribute to be set. For example: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.m = 2 + + def construct(self): + self.m2 = 3 + return + + net = Net() + net() + +- Set and modify Cell objects and jit_class objects in the static graph + + Supporting property modification of objects jit_class graph mode, + such as: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context, jit_class + set_context(mode=ms.GRAPH_MODE) + + @jit_class + class InnerClass(): + def __init__(self): + self.x = 10 + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.inner = InnerClass() + + def construct(self): + self.inner.x = 100 + return + + net = Net() + net() + print(f"net.inner.x is {net.inner.x}") + + The results are as follows: + + .. code:: text + + net.inner.x is 100 + +Supporting Derivation +~~~~~~~~~~~~~~~~~~~~~ + +The static graph syntax supported by the extension also supports its use +in derivation, such as: + +.. code:: python + + import mindspore as ms + from mindspore import ops, set_context + set_context(mode=ms.GRAPH_MODE) + + @ms.jit + def dict_net(a): + x = {'a': a, 'b': 2} + return a, (x, (1, 2)) + + out = ops.grad(dict_net)(ms.Tensor([1])) + assert out == 2 + +Annotation Type +~~~~~~~~~~~~~~~ + +For syntax supported by the runtime extensions, nodes are generated that +cannot be derived by type, such as dynamically created Tensors, which +are called ``Any`` types. Because this type cannot be inferred correctly +at compile time, the ``Any`` type will be operated on with a default +maximum precision of float64 to prevent loss of precision. In order to +better optimize performance, it is necessary to reduce the generation of +``Any`` type data. When the user can clearly know the specific type that +will be generated by the extended syntax, we recommend using Annotation +to specify the corresponding Python statement type, thereby determining +the type of the interpretation node and avoiding the generation of +``Any`` type. + +For example, the difference between the +`Tensor `_ +class and the +`tensor `_ +interface lies in the use of the Annotation Type mechanism within the +tensor interface. When the dtype of the tensor function is determined, +the function uses Annotation to specify the output type, thereby +avoiding the generation of Any type. The use of ``Annotation Type`` only +requires adding a comment ``# @jit.typing: () -> tensor_type[float32]`` +above or after the corresponding Python statement, where +tensor_type[float32] after -> indicates the output type of the annotated +statement. + +The code example is as follows. + +.. code:: python + + import mindspore as ms + import mindspore.nn as nn + from mindspore import ops, Tensor + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.abs = ops.Abs() + + @ms.jit + def construct(self, x, y): + y1 = ms.tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) + y2 = ms.Tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) # @jit.typing: () -> tensor_type[float32] + y3 = Tensor(x.asnumpy() + y.asnumpy()) + y4 = Tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) + return self.abs(y1), self.abs(y2), self.abs(y3), self.abs(y4) + + ms.set_context(mode=ms.GRAPH_MODE) + net = Net() + x = ms.Tensor(-1, dtype=ms.int32) + y = ms.Tensor(-1, dtype=ms.float32) + y1, y2, y3, y4 = net(x, y) + + print(f"y1 value is {y1}, dtype is {y1.dtype}") + print(f"y2 value is {y2}, dtype is {y2.dtype}") + print(f"y3 value is {y3}, dtype is {y3.dtype}") + print(f"y4 value is {y4}, dtype is {y4.dtype}") + +The results are as follows: + +.. code:: text + + y1 value is 2.0, dtype is Float32 + y2 value is 2.0, dtype is Float32 + y3 value is 2.0, dtype is Float64 + y4 value is 2.0, dtype is Float64 + +In the above example, you can see the difference related to creating +'Tensor'. Due to the lack of Annotation indication in the Tensor class, +y3 and y4 cannot infer the correct type and can only perform operations +in the highest precision float64. For y2, the corresponding type for JIT +Fallback was specified through Annotation during Tensor creation, +allowing it to perform operations according to the specified type. y1 +created the Tensor using the tensor function interface and passed the +dtype parameter as an Annotation indication, avoiding the generation of +``Any`` type. + +Syntax Constraints of Extended Syntaxes +--------------------------------------- + +When using the static graph extension support syntax, note the following +points: + +1. In order to match the support capability of the dynamic graph. That + is, it must be within the scope of dynamic graph syntax, including + but not limited to data types. + +2. When extending the static graph syntax, more syntax is supported, but + the execution performance may be affected and is not optimal. + +3. When extending the static graph syntax, more syntax is supported, and + the ability to import and export cannot be used with MindIR due to + use Python. + +4. It is not currently supported that the repeated definition of global + variables with the same name across Python files, and these global + variables are used in the network. \ No newline at end of file diff --git a/docs/mindspore/source_en/note/static_graph_syntax/operators.md b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/operators.md similarity index 99% rename from docs/mindspore/source_en/note/static_graph_syntax/operators.md rename to docs/mindspore/source_en/model_train/program_form/static_graph_syntax/operators.md index 30fc7b7d70e8c9c7a87c7e264099dd6790613480..04faee4d65283a88e01fe85c97f378d2448fd8e4 100644 --- a/docs/mindspore/source_en/note/static_graph_syntax/operators.md +++ b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/operators.md @@ -1,6 +1,6 @@ # Static Graph Syntax - Operators -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/static_graph_syntax/operators.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/operators.md) Arithmetic operators and assignment operators support the `Number` and `Tensor` operations, as well as the `Tensor` operations of different `dtype`. diff --git a/docs/mindspore/source_en/note/static_graph_syntax/python_builtin_functions.md b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/python_builtin_functions.md similarity index 97% rename from docs/mindspore/source_en/note/static_graph_syntax/python_builtin_functions.md rename to docs/mindspore/source_en/model_train/program_form/static_graph_syntax/python_builtin_functions.md index f830247eb8beb8ef236460bc2e9eeb291b6105a5..6fc8237fc26a93e38bdd8c54f0d3647be8e64d84 100644 --- a/docs/mindspore/source_en/note/static_graph_syntax/python_builtin_functions.md +++ b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/python_builtin_functions.md @@ -1,6 +1,6 @@ # Static Graph Syntax - Python Built-in Functions -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/static_graph_syntax/python_builtin_functions.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/python_builtin_functions.md) Python built-in functions supported by the current static graph mode include: `int`, `float`, `bool`, `str`, `tuple`, `list`, `dict`, `getattr`, `hasattr`, `len`, `isinstance`, `all`, `any`, `round`, `max`, `min`, `sum`, `abs`, `map`, `zip` 、`range`、`enumerate`、`super`、`pow`、`print`、`filter`、`type`。 The use of built-in functions in graph mode is similar to the corresponding Python built-in functions. @@ -345,7 +345,7 @@ c: (1,) The attribute of object in graph mode may be different from that in pynative mode. It is suggested to use `default` input or call `hasattr` before using `getattr` to avoid AttributeError. -'getattr(x.asnumpy(), "shape", np.array([0, 1, 2, 3, 4]))' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#extended-syntaxes-lax-level) chapter. +'getattr(x.asnumpy(), "shape", np.array([0, 1, 2, 3, 4]))' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#extended-syntaxes-lax-level-3) chapter. ## hasattr @@ -396,7 +396,7 @@ b: False c: True ``` -'hasattr(Tensor(np.array([1, 2, 3, 4])).asnumpy(), "__len__")' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#extended-syntaxes-lax-level) chapter. +'hasattr(Tensor(np.array([1, 2, 3, 4])).asnumpy(), "__len__")' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#extended-syntaxes-lax-level-3) chapter. ## len @@ -451,7 +451,7 @@ n_len:4 w_len:4 ``` -'len(w.asnumpy())' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#extended-syntaxes-lax-level) chapter. +'len(w.asnumpy())' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#extended-syntaxes-lax-level-3) chapter. ## isinstance @@ -502,7 +502,7 @@ z_is_tensor:True w_is_ndarray:True ``` -'isinstance(w.asnumpy(), np.ndarray)' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#extended-syntaxes-lax-level) chapter. +'isinstance(w.asnumpy(), np.ndarray)' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#extended-syntaxes-lax-level-3) chapter. ## all @@ -561,7 +561,7 @@ h: True i: False ``` -'all(x.asnumpy())' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#extended-syntaxes-lax-level) chapter. +'all(x.asnumpy())' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#extended-syntaxes-lax-level-3) chapter. ## any @@ -861,7 +861,7 @@ b: 100.12 c: [1 2] ``` -'abs(Tensor([-1, 2]).asnumpy())' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#extended-syntaxes-lax-level) chapter. +'abs(Tensor([-1, 2]).asnumpy())' is a high-level usage, and more introduction can be found in the [Extended Syntaxes (LAX level)](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#extended-syntaxes-lax-level-3) chapter. ## map diff --git a/docs/mindspore/source_en/note/static_graph_syntax/statements.md b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/statements.md similarity index 98% rename from docs/mindspore/source_en/note/static_graph_syntax/statements.md rename to docs/mindspore/source_en/model_train/program_form/static_graph_syntax/statements.md index 0082386e7b405faa2c32b8403b8f44fdd78978fd..fda59cd989942f963a2bbbfdf217f8c179065dcf 100644 --- a/docs/mindspore/source_en/note/static_graph_syntax/statements.md +++ b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/statements.md @@ -1,6 +1,6 @@ # Static Graph Syntax - Python Statements -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/static_graph_syntax/statements.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/statements.md) ## Simple Statements @@ -651,7 +651,7 @@ Usage restrictions are the same as list comprehension, i.e., the use of multiple In graph mode, the `with` statement is supported with limitations. The `with` statement requires that the object must have two magic methods: `__enter__()` and `__exit__()`. -It is worth noting that the class used in the with statement needs to be decorated with a decorator@ms.jit_class or inherited from nn. Cell, and more on this can be found in [Calling the Custom Class](https://www.mindspore.cn/tutorials/en/master/advanced/static_graph_expert_programming.html#using-jit-class). +It is worth noting that the class used in the with statement needs to be decorated with a decorator@ms.jit_class or inherited from nn. Cell, and more on this can be found in [Calling the Custom Class](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html#using-jit-class). For example: diff --git a/tutorials/source_en/advanced/static_graph_expert_programming.md b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/static_graph_expert_programming.md similarity index 97% rename from tutorials/source_en/advanced/static_graph_expert_programming.md rename to docs/mindspore/source_en/model_train/program_form/static_graph_syntax/static_graph_expert_programming.md index dac463a7814a7a94803fc52cafb5307dc8e6cec2..a98b2873e28335102d2b2720d5160b288dff5a07 100644 --- a/tutorials/source_en/advanced/static_graph_expert_programming.md +++ b/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/static_graph_expert_programming.md @@ -1,6 +1,6 @@ # Advanced Programming Techniques for Static Graphs -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/static_graph_expert_programming.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/program_form/static_graph_syntax/static_graph_expert_programming.md) This chapter introduces some commonly used advanced programming techniques for static graph optimization, which can effectively improve the compilation efficiency as well as the execution efficiency of static graphs, and make the program run more stably. For a basic introduction to static graphs compilation, see [Accelerating with Static Graphs](https://www.mindspore.cn/tutorials/en/master/beginner/accelerate_with_static_graph.html). @@ -283,7 +283,7 @@ When a user defines a class in a network script, it can be written as a class in - a custom class - After defining a custom class, you can instantiate the class and call the attributes and methods of the class object. Please refer to [the Use of Custom Classes](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#supporting-the-use-of-custom-classes). Compared to `Cell` class definitions, custom classes are closer to the user habits of calling Python classes. The implementation of custom classes in static graph mode is different from `Cell`, for example, when calling a function method of a custom class object, the code in its function method will not be compiled into a static computational graph but will be interpreted and executed by the Python interpreter. + After defining a custom class, you can instantiate the class and call the attributes and methods of the class object. Please refer to [the Use of Custom Classes](https://www.mindspore.cn/docs/en/master/model_train/program_form/static_graph.html#supporting-the-use-of-custom-classes). Compared to `Cell` class definitions, custom classes are closer to the user habits of calling Python classes. The implementation of custom classes in static graph mode is different from `Cell`, for example, when calling a function method of a custom class object, the code in its function method will not be compiled into a static computational graph but will be interpreted and executed by the Python interpreter. - a class decorated by `@jit_class` @@ -564,7 +564,7 @@ select net cost time: 0.483151912689209 Usage scenario: When processing batch data without dependency and the related operator supports Vmap function, you can use Vmap to replace for loop to process batch data to optimize the execution performance (and also improve the compilation performance). -MindSpore already supports the Vmap feature. A detailed description of Vmap can be found in [Automatic Vectorization Vmap](https://www.mindspore.cn/tutorials/experts/en/master/vmap/vmap.html). +MindSpore already supports the Vmap feature. A detailed description of Vmap can be found in [Automatic Vectorization Vmap](https://www.mindspore.cn/docs/en/master/model_train/train_process/func_programming/vmap.html). A code sample that uses Vmap to replace a for loop to process batch data to optimize compilation performance is shown below: diff --git a/docs/mindspore/source_en/model_train/train_process/algorithm_optimize.rst b/docs/mindspore/source_en/model_train/train_process/algorithm_optimize.rst new file mode 100644 index 0000000000000000000000000000000000000000..697ec25aa96d0cf0e1403a72c78f79197d13a876 --- /dev/null +++ b/docs/mindspore/source_en/model_train/train_process/algorithm_optimize.rst @@ -0,0 +1,8 @@ +Algorithm Optimization +====================== + +.. toctree:: + :maxdepth: 1 + + optimize/gradient_accumulation + optimize/thor \ No newline at end of file diff --git a/tutorials/source_en/advanced/derivation.md b/docs/mindspore/source_en/model_train/train_process/derivation.md similarity index 98% rename from tutorials/source_en/advanced/derivation.md rename to docs/mindspore/source_en/model_train/train_process/derivation.md index 23a2e369e22c29a7a8c88be54d81b86a6186ed09..1f0a3ef520bc82dfa8c71431cd1bdaf0bdc97cfc 100644 --- a/tutorials/source_en/advanced/derivation.md +++ b/docs/mindspore/source_en/model_train/train_process/derivation.md @@ -1,6 +1,6 @@ # Advanced Automatic Differentiation -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/derivation.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/derivation.md) The `grad` and `value_and_grad` provided by the `mindspore.ops` module generate the gradients of the network model. `grad` computes the network gradient, and `value_and_grad` computes both the forward output and the gradient of the network. This article focuses on how to use the main functions of the `grad`, including first-order and second-order derivations, derivation of the input or network weights separately, returning auxiliary variables, and stopping calculating the gradient. diff --git a/docs/mindspore/source_en/design/dynamic_shape.md b/docs/mindspore/source_en/model_train/train_process/dynamic_shape.md similarity index 97% rename from docs/mindspore/source_en/design/dynamic_shape.md rename to docs/mindspore/source_en/model_train/train_process/dynamic_shape.md index 9d78d9648c533ce8e59e2bf0a63f9e8fe33e071b..8dd57973328adc214e0236ec73c3d74f70703e95 100644 --- a/docs/mindspore/source_en/design/dynamic_shape.md +++ b/docs/mindspore/source_en/model_train/train_process/dynamic_shape.md @@ -1,6 +1,6 @@ # Static Graph Dynamic Shape -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/design/dynamic_shape.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/dynamic_shape.md) ## Background @@ -63,7 +63,7 @@ Detailed instructions for using set_inputs can be found in the [Cell.set_inputs Detailed instructions for using input_signature can be found in the [mindspore.jit API Ducumentation](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.jit.html). -Distributed parallel scenarios on how to use dynamic shapes can be found in the [Distributed Parallel Support for Dynamic Shape Documentation](https://www.mindspore.cn/tutorials/experts/en/master/parallel/support_dynamic_shape_in_parallel.html). +Distributed parallel scenarios on how to use dynamic shapes can be found in the [Distributed Parallel Support for Dynamic Shape Documentation](https://www.mindspore.cn/docs/en/master/model_train/parallel/support_dynamic_shape_in_parallel.html). ## API Support diff --git a/docs/mindspore/source_en/model_train/train_process/func_programming.rst b/docs/mindspore/source_en/model_train/train_process/func_programming.rst new file mode 100644 index 0000000000000000000000000000000000000000..447dfd129a5f50dc735e2206dd75a34171bd6352 --- /dev/null +++ b/docs/mindspore/source_en/model_train/train_process/func_programming.rst @@ -0,0 +1,9 @@ +Higher Order Functional Programming +===================================== + +.. toctree:: + :maxdepth: 1 + + func_programming/vmap + func_programming/Jacobians_Hessians + func_programming/per_sample_gradients diff --git a/tutorials/experts/source_en/func_programming/Jacobians_Hessians.md b/docs/mindspore/source_en/model_train/train_process/func_programming/Jacobians_Hessians.md similarity index 98% rename from tutorials/experts/source_en/func_programming/Jacobians_Hessians.md rename to docs/mindspore/source_en/model_train/train_process/func_programming/Jacobians_Hessians.md index 6f05e6b78e02011aa4989eae74fc748167670796..ebe34b2d0703337dc38a9d3e0824fdfcb07a0862 100644 --- a/tutorials/experts/source_en/func_programming/Jacobians_Hessians.md +++ b/docs/mindspore/source_en/model_train/train_process/func_programming/Jacobians_Hessians.md @@ -1,6 +1,6 @@ # Computing Jacobian and Hessian Matrices Using Functional Transformations -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/func_programming/Jacobians_Hessians.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/func_programming/Jacobians_Hessians.md) ## Jacobian Matrices diff --git a/tutorials/experts/source_en/func_programming/per_sample_gradients.md b/docs/mindspore/source_en/model_train/train_process/func_programming/per_sample_gradients.md similarity index 97% rename from tutorials/experts/source_en/func_programming/per_sample_gradients.md rename to docs/mindspore/source_en/model_train/train_process/func_programming/per_sample_gradients.md index fc2f15b07dbeb2f1263dbfb22db46cae195f8a12..f1f8a53dc41b354d7b8fce7c473bb0286033fb10 100644 --- a/tutorials/experts/source_en/func_programming/per_sample_gradients.md +++ b/docs/mindspore/source_en/model_train/train_process/func_programming/per_sample_gradients.md @@ -1,6 +1,6 @@ # Per-sample-gradients -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/func_programming/per_sample_gradients.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/func_programming/per_sample_gradients.md) Calculating per-sample-gradients means calculating the gradient of each sample in a batch sample. When training a neural network, many deep learning frameworks calculate the gradients of the batch samples and use the gradients of the batch samples to update the network parameters. per-sample-gradients can help us to better improve the training of the model by more accurately calculating the effect of each sample on the network parameters when training the neural network. diff --git a/tutorials/experts/source_en/vmap/vmap.ipynb b/docs/mindspore/source_en/model_train/train_process/func_programming/vmap.ipynb similarity index 98% rename from tutorials/experts/source_en/vmap/vmap.ipynb rename to docs/mindspore/source_en/model_train/train_process/func_programming/vmap.ipynb index 0fcdbb9e66605e4f1732b23d56018fcc6ac5a7ab..26f950cba86e2978f6c0ef596de83f8339f61606 100644 --- a/tutorials/experts/source_en/vmap/vmap.ipynb +++ b/docs/mindspore/source_en/model_train/train_process/func_programming/vmap.ipynb @@ -6,7 +6,7 @@ "source": [ "# Automatic Vectorization (Vmap)\n", "\n", - "[![Download Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook_en.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/en/vmap/mindspore_vmap.ipynb) [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/vmap/vmap.ipynb)\n", + "[![Download Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook_en.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/en/model_train/train_process/func_programming/mindspore_vmap.ipynb) [![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/func_programming/vmap.ipynb)\n", "\n", "## Overview\n", "\n", diff --git a/tutorials/experts/source_en/optimize/images/image-data-sink.png b/docs/mindspore/source_en/model_train/train_process/images/image-data-sink.png similarity index 100% rename from tutorials/experts/source_en/optimize/images/image-data-sink.png rename to docs/mindspore/source_en/model_train/train_process/images/image-data-sink.png diff --git a/tutorials/experts/source_en/optimize/images/image-graph-sink.png b/docs/mindspore/source_en/model_train/train_process/images/image-graph-sink.png similarity index 100% rename from tutorials/experts/source_en/optimize/images/image-graph-sink.png rename to docs/mindspore/source_en/model_train/train_process/images/image-graph-sink.png diff --git a/tutorials/experts/source_en/optimize/images/image-loop-sink.png b/docs/mindspore/source_en/model_train/train_process/images/image-loop-sink.png similarity index 100% rename from tutorials/experts/source_en/optimize/images/image-loop-sink.png rename to docs/mindspore/source_en/model_train/train_process/images/image-loop-sink.png diff --git a/tutorials/experts/source_en/optimize/images/image-user-view.png b/docs/mindspore/source_en/model_train/train_process/images/image-user-view.png similarity index 100% rename from tutorials/experts/source_en/optimize/images/image-user-view.png rename to docs/mindspore/source_en/model_train/train_process/images/image-user-view.png diff --git a/tutorials/experts/source_en/optimize/images/image-without-sink.png b/docs/mindspore/source_en/model_train/train_process/images/image-without-sink.png similarity index 100% rename from tutorials/experts/source_en/optimize/images/image-without-sink.png rename to docs/mindspore/source_en/model_train/train_process/images/image-without-sink.png diff --git a/tutorials/source_en/advanced/model.rst b/docs/mindspore/source_en/model_train/train_process/model.rst similarity index 97% rename from tutorials/source_en/advanced/model.rst rename to docs/mindspore/source_en/model_train/train_process/model.rst index 02b5c39afc80c9406b1e8288bcf0e214ff0418bc..79ba7a5bafb4607b0cbd12333839b742a4fafdb1 100644 --- a/tutorials/source_en/advanced/model.rst +++ b/docs/mindspore/source_en/model_train/train_process/model.rst @@ -1,5 +1,5 @@ .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/model.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/model.rst :alt: View Source on Gitee Advanced Encapsulation: Model @@ -24,7 +24,7 @@ Without the help of ``Model``, it takes a long time to customize these functions The following describes MindSpore models and how to use ``Model`` for model training, evaluation, and inference. -.. figure:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_en/advanced/model/images/model.png +.. figure:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_en/model_train/train_process/model/images/model.png :alt: model .. code:: python diff --git a/tutorials/source_en/advanced/model/callback.md b/docs/mindspore/source_en/model_train/train_process/model/callback.md similarity index 99% rename from tutorials/source_en/advanced/model/callback.md rename to docs/mindspore/source_en/model_train/train_process/model/callback.md index a33c189a11b0c5239617a8bbb415a80554e53829..68a477bc943edcf2cc69921950a45f0378781786 100644 --- a/tutorials/source_en/advanced/model/callback.md +++ b/docs/mindspore/source_en/model_train/train_process/model/callback.md @@ -1,7 +1,7 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/model/callback.md) - # Callback Mechanism +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/model/callback.md) + During deep learning training, MindSpore provides the callback mechanism to promptly learn about the training status of the network model, observe the changes of network model parameters in real time, and implement customized operations during training. The callback mechanism is generally used in the network model training process `model.train`. The MindSpore `model` executes callback functions based on the sequence in the callback list. You can set different callback classes to implement functions executed during or after training. diff --git a/tutorials/source_en/advanced/model/images/model.png b/docs/mindspore/source_en/model_train/train_process/model/images/model.png similarity index 100% rename from tutorials/source_en/advanced/model/images/model.png rename to docs/mindspore/source_en/model_train/train_process/model/images/model.png diff --git a/tutorials/source_en/advanced/model/metric.md b/docs/mindspore/source_en/model_train/train_process/model/metric.md similarity index 98% rename from tutorials/source_en/advanced/model/metric.md rename to docs/mindspore/source_en/model_train/train_process/model/metric.md index 32d6f2d68c3f73b6a9f68f071603c450341bcc57..a5cb7d32bd0b353dc31fc3012f61f48361fb7650 100644 --- a/tutorials/source_en/advanced/model/metric.md +++ b/docs/mindspore/source_en/model_train/train_process/model/metric.md @@ -1,7 +1,7 @@ -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_en/advanced/model/metric.md) - # Evaluation Metrics +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/model/metric.md) + When a training task is complete, an evaluation function (Metric) is often required to evaluate the quality of a model. Different training tasks usually require different metric functions. For example, for a binary classification problem, common evaluation metrics include precision, recall, and the like. For a multiclass classification task, macro and micro may be used for evaluation. MindSpore provides evaluation functions for most common tasks, such as `Accuracy`、`Precision`、`MAE` and `MSE`. The evaluation functions provided by MindSpore cannot meet the requirements of all tasks. In most cases, you need to customize metrics for a specific task to evaluate the trained model. diff --git a/tutorials/experts/source_en/optimize/gradient_accumulation.md b/docs/mindspore/source_en/model_train/train_process/optimize/gradient_accumulation.md similarity index 98% rename from tutorials/experts/source_en/optimize/gradient_accumulation.md rename to docs/mindspore/source_en/model_train/train_process/optimize/gradient_accumulation.md index 16ff5a8f05be9de58a0575720ba2938b7abee948..648bdb1eb8969d278e4dc9dfc654f1000d4a971a 100644 --- a/tutorials/experts/source_en/optimize/gradient_accumulation.md +++ b/docs/mindspore/source_en/model_train/train_process/optimize/gradient_accumulation.md @@ -1,6 +1,6 @@ # Gradient Accumulation Algorithm -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/optimize/gradient_accumulation.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/optimize/gradient_accumulation.md) ## Overview @@ -38,7 +38,7 @@ $$\theta_{i}=\theta_{i-1}-lr * \sum_{i=0}^{N} grad_{i}$$ Eventually accumulating the gradient in the previous step yields the sum of the gradients of the same size as using the global Batche size. -![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/GradientAccumulation1.png) +![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/images/GradientAccumulation1.png) In the actual project, there are two points to pay attention to the tuning parameters and algorithms: diff --git a/tutorials/experts/source_en/optimize/thor.rst b/docs/mindspore/source_en/model_train/train_process/optimize/thor.rst similarity index 68% rename from tutorials/experts/source_en/optimize/thor.rst rename to docs/mindspore/source_en/model_train/train_process/optimize/thor.rst index ae1b6d700a2be6bd6f34ce68cae5f85ae4fce0e4..ea125f55fb63b34e3459b6babb0104cb753a6294 100644 --- a/tutorials/experts/source_en/optimize/thor.rst +++ b/docs/mindspore/source_en/model_train/train_process/optimize/thor.rst @@ -2,7 +2,7 @@ Second-order Optimization ========================= .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/optimize/thor.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/optimize/thor.rst :alt: View Source on Gitee .. toctree:: diff --git a/tutorials/experts/source_en/optimize/thor/intro.md b/docs/mindspore/source_en/model_train/train_process/optimize/thor/intro.md similarity index 93% rename from tutorials/experts/source_en/optimize/thor/intro.md rename to docs/mindspore/source_en/model_train/train_process/optimize/thor/intro.md index bc5ec397aac3c41e09ef4dc61f4e5ea55aa54399..35bc864ca73f60d8ad6b09470fddba08b9e02ab4 100644 --- a/tutorials/experts/source_en/optimize/thor/intro.md +++ b/docs/mindspore/source_en/model_train/train_process/optimize/thor/intro.md @@ -1,6 +1,6 @@ # Introduction to Second-order Optimizer THOR -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/optimize/thor/intro.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/optimize/thor/intro.md) The deep learning training process can be viewed as a loss function loss value decreasing process, and the right optimizer can make deep learning training time significantly reduced. Optimizers can be divided into first-order optimizers and second-order optimizers. The industry is still the mainstream use of the first-order optimizers, while the second-order optimizers is widely used because the single-step training time is too long. In recent years, there have been theoretical breakthroughs in applying the second-order optimization to deep learning training, and good results have been achieved. @@ -10,7 +10,7 @@ This article will introduce the background of the optimizers, and second-order o Suppose the training sample data set: $D = {(x_1,y_1),... ,(x_i,y_i),... ,(x_N,y_N)},x_i \in X,y_i\in Y$, the deep neural network model with parameter θ formulation is: $\hat{y} = f(x;\theta),x\in{X}$, the loss function defined between the model output and the true label y is: $L(y,\hat y),y \in Y$, the process of network parameter learning is the minimization the loss function: $\min\limits_{\theta}L(y,\hat{y})$. Given the dataset, model, and loss function, the deep learning training problem boils down to the optimization problem. The deep neural network training optimization problem has a huge parameter scale and requires a large amount of computation, making it difficult to compute an analytic solution. Therefore, the process is often compared to descending a mountain. As shown in Figure 1, how can a person find the fastest path down a mountain with limited sight distance while standing at the top? -![The process of deeplearning training](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/thor/images/deeplearning_train_process.png) +![The process of deeplearning training](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/deeplearning_train_process.png) *Figure 1 Simulation of Deep Learning Training Process* @@ -30,7 +30,7 @@ The second-order optimization algorithm uses the second-order derivative of the For example, the Newton method of second-order optimization algorithms is to fit a local surface at your current location with a quadratic surface, while the gradient descent method uses a plane to fit the current local surface. Usually, the quadratic surface will be better fitted than the plane, so the descent path chosen by the Newton method will be more consistent with the true optimal descent path. As shown in Figure 2, the left descent path indicates the descent curve of Newton method, and the right indicates the descent curve of the first-order gradient. The second-order algorithm can go to the destination faster than the first-order algorithm, thus accelerating the convergence. -![The different process of deeplearning training](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/thor/images/different_train_process.png) +![The different process of deeplearning training](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/different_train_process.png) *Figure 2 Descent Path of Different Optimizers* @@ -82,7 +82,7 @@ So how can we determine the matrix tiling dimension? The specific method is: 4. Based on the annotated matrix loss information and the normalized performance data graph, taking the ResNet50 as example, shown in Figure 3, the falling curve in the figure is the performance curve, and the rising curve indicates the matrix loss curve. The intersection point in the figure is 106, which is closest to 128, and finally the matrix slice dimension is determined to be 128. -![The split dimension of matrix](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/thor/images/split_dimension.png) +![The split dimension of matrix](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/split_dimension.png) *Figure 3 Schematic Diagram of Slice Dimension Determination* @@ -90,7 +90,7 @@ So how can we determine the matrix tiling dimension? The specific method is: Figure 4 shows the training line graph of THOR on ResNet50+ImageNet with a batchsize of 256 on first and second order, where train loss denotes training error, test accuracy denotes testing accuracy, epoch denotes the number of iterations, and wall-clock time denotes the time. The faster falling curve and the faster rising curve are the curves of this algorithm, and the other curve with more obvious gap is the training curve of momentum. -![The result of ResNet50](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/thor/images/thor_in_resnet.png) +![The result of ResNet50](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_in_resnet.png) *Figure 4 Results of THOR on ResNet50* @@ -98,12 +98,12 @@ THOR, THOR_stop, and THOR_NT in Figure 4 indicate ($w_1$,$w_2$)=(0.01,0), ($w_1$ THOR also tested the convergence results of ResNet50+ImageNet at different batchsize, and the results are shown in Figure 5 below, where Hardware denotes the hardware platform, Software is the used deep learning framework, Batch size is the number of images per training, Optimizer denotes the used optimizer, Time refers to the overall training time, and Accuracy is the final convergence accuracy. When the batchsize is 8192 and 256 Atlas training series blocks are used, it only takes 2.7 minutes for the accuracy to converge to 75.9%. -![The large batchsize result of ResNet50](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/thor/images/thor_largebs_in_resnet.png) +![The large batchsize result of ResNet50](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_largebs_in_resnet.png) *Figure 5 Results of THOR on ResNet50 at Large Batchsize* In BERT+WIkipedia, THOR also has a good performance effect. Taking the MLPerf as a standard, the accuracy reaches to 71.2%, and an end-to-end improvement of 30% is implemented compared to the first order. The results are shown in Figure 6. The horizontal coordinate in the figure indicates the training time, and the vertical coordinate indicates the test accuracy. The curve that rises faster is the training curve of THOR, and the other one is the training curve of Lamb. -![The result of BERT](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/thor/images/thor_in_bert.png) +![The result of BERT](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_in_bert.png) *Figure 6 Results of THOR on BERT* diff --git a/tutorials/experts/source_en/optimize/thor/resnet50.md b/docs/mindspore/source_en/model_train/train_process/optimize/thor/resnet50.md similarity index 96% rename from tutorials/experts/source_en/optimize/thor/resnet50.md rename to docs/mindspore/source_en/model_train/train_process/optimize/thor/resnet50.md index 7ed78d2d0377cef274e9798b46dee36a41f14c79..b56d19bca79750778505061fb61af3e4a98c7119 100644 --- a/tutorials/experts/source_en/optimize/thor/resnet50.md +++ b/docs/mindspore/source_en/model_train/train_process/optimize/thor/resnet50.md @@ -1,6 +1,6 @@ # Applying Second-Order Optimization Practices on the ResNet-50 Network -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/optimize/thor/resnet50.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/optimize/thor/resnet50.md) ## Overview @@ -70,11 +70,11 @@ The directory structure is as follows: #### Atlas Training Series -Refer to [rank table Startup](https://www.mindspore.cn/tutorials/experts/en/master/parallel/rank_table.html) for the configuration of distributed environment variables for the Atlas training series. +Refer to [rank table Startup](https://www.mindspore.cn/docs/en/master/model_train/parallel/rank_table.html) for the configuration of distributed environment variables for the Atlas training series. #### GPU -Refer to [mpirun Startup](https://www.mindspore.cn/tutorials/experts/en/master/parallel/mpirun.html) for the configuration of distributed environment variables for the GPU. +Refer to [mpirun Startup](https://www.mindspore.cn/docs/en/master/model_train/parallel/mpirun.html) for the configuration of distributed environment variables for the GPU. ## Loading and Processing the Datasets @@ -168,7 +168,7 @@ def create_dataset2(dataset_path, do_train, repeat_num=1, batch_size=32, target= return data_set ``` -> MindSpore supports a variety of data processing and augmentation operations, often in combination, as described in the [Data Processing](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html) and [Data Augmentation](https://www.mindspore.cn/tutorials/en/master/advanced/dataset.html) chapters. +> MindSpore supports a variety of data processing and augmentation operations, often in combination, as described in the [Processing and Loading Data](https://www.mindspore.cn/docs/en/master/model_train/index.html) chapters. ## Defining the Networks diff --git a/docs/mindspore/source_en/model_train/train_process/overview.md b/docs/mindspore/source_en/model_train/train_process/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..d1e2d976ea628b992e3633f473bb2e8d9dbc0c79 --- /dev/null +++ b/docs/mindspore/source_en/model_train/train_process/overview.md @@ -0,0 +1,3 @@ +# Training Process Overview + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/overview.md) diff --git a/tutorials/experts/source_en/optimize/execution_opt.md b/docs/mindspore/source_en/model_train/train_process/train_optimize.md similarity index 96% rename from tutorials/experts/source_en/optimize/execution_opt.md rename to docs/mindspore/source_en/model_train/train_process/train_optimize.md index 1d9b22c23dcd395edd7b68130786fb99e287785d..bb4f6253d4db351eba8bcc59e7d2974711cc9fea 100644 --- a/tutorials/experts/source_en/optimize/execution_opt.md +++ b/docs/mindspore/source_en/model_train/train_process/train_optimize.md @@ -1,8 +1,10 @@ -# Sinking Mode +# Optimizing Training Performance -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_en/optimize/execution_opt.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/train_process/train_optimize.md) -## Overview +## Sinking Mode + +### Overview The Ascend chip integrates computational units such as AICORE and AICPU. The AICORE is responsible for dense Tensor and Vector operations, while the AICPU is responsible for processing complex control logic. @@ -14,7 +16,7 @@ From the user's perspective, the process of network training is as follows: This tutorial introduces the principles and usage of data sink, graph sink and loop sink as an example of the execution flow of training. -## Data Sinking +### Data Sinking To improve the execution performance of the network, a dedicated chip is usually used to execute the operator. A chip corresponds to a Device, and the general interaction flow between Host and Device is as follows: @@ -30,7 +32,7 @@ Both GPU backend and Ascend backend support data sinking, and the Host-Device in Users can control whether to enable data sink through `dataset_sink_mode` of the [train](https://mindspore.cn/docs/en/master/api_python/train/mindspore.train.Model.html#mindspore.train.Model.train) interface. -## Graph Sinking +### Graph Sinking In general, each training iteration needs to issue and trigger the execution of each operator on the device, and Host and Device interact frequently. @@ -40,7 +42,7 @@ In order to reduce the interaction between Host and Device, the operators in the The GPU backend does not support graph sinking currently. When using the Ascend device, data sinking is turned on and the graph sinking is turned on at the same time. -## Loop Sinking +### Loop Sinking When data sinking and graph sinking are enabled, the computed results of each iteration are returned to Host, which determines whether it is necessary to move to the next iteration. To reduce the Device-Host interaction for each iteration, you can sink the loop judgment into the next iteration to the Device, so that the computation result is returned to the Host when all iterations are executed. The loop sinking Host-Device interaction flow is as follows: @@ -48,9 +50,9 @@ When data sinking and graph sinking are enabled, the computed results of each it The users control the number of sink iterations per epoch through the `dataset_sink_mode` and `sink_size` parameters of the [train](https://mindspore.cn/docs/zh-CN/master/api_python/train/mindspore.train.Model.html#mindspore.train.Model.train) interface, and the Device side executes `sink_size` iterations consecutively before returning to the Host. -## Usage +### Usage -### `Model.train` Implements Data Sinking +#### `Model.train` Implements Data Sinking `dataset_sink_mode`, the `train` interface parameter of `Model` can control whether the data is sunk. If `dataset_sink_mode` is True, it means data sinking, otherwise it is non-sunk. The so-called sink means that the data is sent directly to the Device through the channel. @@ -67,7 +69,7 @@ When using `LossMonitor`, `TimeMonitor` or other `Callback` interfaces, if `data > - The current CPU does not support data sinking. > - When set to GRAPH mode, the shape of each batch of data must be the same, while when set to PYNATIVE mode, the size of each batch of data is required to be the same. > - Since the traversal of the dataset by data sinking is continuous, non-continuous traversal is not currently supported. -> - If you get `fault kernel_name=GetNext`, `GetNext... task error` or `outputs = self.get_next()` and other similar errors, it is possible that some samples are too time-consuming to be processed during data processing, causing the network computation side to fail to get the data for a long time to report errors, when using data sinking mode. At this point, you can set `dataset_sink_mode` to False to verify again, or use `create_dict_iterator()` interface to loop the dataset separately. Refer to [data processing performance optimization](https://mindspore.cn/tutorials/experts/en/master/dataset/optimize.html) to tune the data processing to ensure high performance of data processing. +> - If you get `fault kernel_name=GetNext`, `GetNext... task error` or `outputs = self.get_next()` and other similar errors, it is possible that some samples are too time-consuming to be processed during data processing, causing the network computation side to fail to get the data for a long time to report errors, when using data sinking mode. At this point, you can set `dataset_sink_mode` to False to verify again, or use `create_dict_iterator()` interface to loop the dataset separately. Refer to [data processing performance optimization](https://mindspore.cn/docs/en/master/model_train/dataset/optimize.html) to tune the data processing to ensure high performance of data processing. Code samples are as follows: @@ -249,7 +251,7 @@ When dataset_sink_mode is set to True, the results are returned once per epoch. When dataset_sink_mode is False, the sink_size parameter setting is invalid. -### `data_sink` Implements Data Sinking +#### `data_sink` Implements Data Sinking In MindSpore functional programming paradigm, it is also possible to use the [data_sink interface](https://mindspore.cn/docs/en/master/api_python/mindspore/mindspore.data_sink.html) to bind the execution functions and datasets of the modes for data sinking. The meaning of the parameters is as follows: @@ -262,7 +264,7 @@ In MindSpore functional programming paradigm, it is also possible to use the [da > - The current CPU does not support data sinking. > - When set to GRAPH mode, the shape of each batch of data must be the same, while when set to PYNATIVE mode, the size of each batch of data is required to be the same. > - Since the traversal of the dataset by data sinking is continuous, non-continuous traversal is not currently supported. -> - If you get `fault kernel_name=GetNext`, `GetNext... task error` or `outputs = self.get_next()` and other similar errors, it is possible that some samples are too time-consuming to be processed during data processing, causing the network computation side to fail to get the data for a long time to report errors, when using data sinking mode. At this point, you can set `dataset_sink_mode` to False to verify again, or use `create_dict_iterator()` interface to loop the dataset separately. Refer to [data processing performance optimization](https://mindspore.cn/tutorials/experts/en/master/dataset/optimize.html) to tune the data processing to ensure high performance of data processing. +> - If you get `fault kernel_name=GetNext`, `GetNext... task error` or `outputs = self.get_next()` and other similar errors, it is possible that some samples are too time-consuming to be processed during data processing, causing the network computation side to fail to get the data for a long time to report errors, when using data sinking mode. At this point, you can set `dataset_sink_mode` to False to verify again, or use `create_dict_iterator()` interface to loop the dataset separately. Refer to [data processing performance optimization](https://mindspore.cn/docs/en/master/model_train/dataset/optimize.html) to tune the data processing to ensure high performance of data processing. The code samples are as follows: @@ -450,3 +452,5 @@ The code uses 3 calls to train 10 epochs separately. 3. Sink 10 epochs of data at a time, and return loss at the end of 10 epochs. No need to loop on Host side. Among the above methods, method 1 interacts with Device once at the end of each step, which is less efficient. Method 3 does not need to interact with Device during training and has the most efficient execution, but can only return the loss of the last step. + +## Co-optimization with Data Flow diff --git a/docs/mindspore/source_en/note/api_mapping/pytorch_diff/DataLoader.md b/docs/mindspore/source_en/note/api_mapping/pytorch_diff/DataLoader.md index 53a1456ad912b16370296780e62a91bd9dc93652..92825ae406789af4e1a8c89d783855a05d5917c4 100644 --- a/docs/mindspore/source_en/note/api_mapping/pytorch_diff/DataLoader.md +++ b/docs/mindspore/source_en/note/api_mapping/pytorch_diff/DataLoader.md @@ -20,7 +20,7 @@ For more information, see [torch.utils.data.DataLoader](https://pytorch.org/docs class mindspore.dataset.GeneratorDataset( source, column_names=None, column_types=None, schema=None, num_samples=None, num_parallel_workers=1, shuffle=None, sampler=None, - num_shards=None, shard_id=None, python_multiprocessing=True, max_rowsize=6) + num_shards=None, shard_id=None, python_multiprocessing=True, max_rowsize=None) ``` For more information, see [mindspore.dataset.GeneratorDataset](https://mindspore.cn/docs/en/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html#mindspore.dataset.GeneratorDataset)。 diff --git a/docs/mindspore/source_en/note/api_mapping/pytorch_diff/leaky_relu.md b/docs/mindspore/source_en/note/api_mapping/pytorch_diff/leaky_relu.md index 5a63b72a366a0c1783c8f36901cdcf751c5172af..4d81b9571f740a8b996428e87dd51e8a93045592 100644 --- a/docs/mindspore/source_en/note/api_mapping/pytorch_diff/leaky_relu.md +++ b/docs/mindspore/source_en/note/api_mapping/pytorch_diff/leaky_relu.md @@ -1,6 +1,6 @@ # Differences with torch.nn.functional.leaky_relu -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/leaky_relu.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/api_mapping/pytorch_diff/leaky_relu.md) ## torch.nn.functional.leaky_relu diff --git a/docs/mindspore/source_en/note/env_var_list.rst b/docs/mindspore/source_en/note/env_var_list.rst index 8e819ad8b91bf81b85149f7ca22f8bf87d50466e..c6e884586c631298df19431968cce7b3fb54ec09 100644 --- a/docs/mindspore/source_en/note/env_var_list.rst +++ b/docs/mindspore/source_en/note/env_var_list.rst @@ -59,7 +59,7 @@ Data Processing false: disables pipeline tree optimization. - -For more information, see `Single-Node Data Cache `_ and `Optimizing the Data Processing `_. +For more information, see `Single-Node Data Cache `_ and `Optimizing the Data Processing `_. Graph Compilation and Execution --------------------------------- @@ -84,14 +84,14 @@ Graph Compilation and Execution - Specify which modules in static graph mode require JIT static compilation, and their functions and methods will be compiled into static calculation graphs. - String - The module name, corresponding to the name of the imported top-level module. If there are more than one, separate them with commas. For example, `export MS_JIT_MODULES=mindflow,mindyolo`. - - By default, modules other than third-party libraries will be perform JIT static compilation, and MindSpore suites such as `mindflow` and `mindyolo` will not be treated as third-party libraries. See `Calling the Third-party Libraries `_ for more details. If there is a module similar to MindSpore suites, which contains `nn.Cell`, `@ms.jit` decorated functions or functions to be compiled into static calculation graphs, you can configure the environment variable, so that the module will be perform JIT static compilation instead of being treated as third-party library. + - By default, modules other than third-party libraries will be perform JIT static compilation, and MindSpore suites such as `mindflow` and `mindyolo` will not be treated as third-party libraries. See `Calling the Third-party Libraries `_ for more details. If there is a module similar to MindSpore suites, which contains `nn.Cell`, `@ms.jit` decorated functions or functions to be compiled into static calculation graphs, you can configure the environment variable, so that the module will be perform JIT static compilation instead of being treated as third-party library. * - MS_JIT_IGNORE_MODULES - Specify which modules are treated as third-party libraries in static graph mode without JIT static compilation. Their functions and methods will be interpreted and executed. - String - The module name, corresponding to the name of the imported top-level module. If there are more than one, separate them with commas. For example, `export MS_JIT_IGNORE_MODULES=numpy,scipy`. - Static graph mode can automatically recognize third-party libraries, and generally there is no need to set this environment variable for recognizable third-party libraries such as NumPy and Scipy. If `MS_JIT_IGNORE_MODULES` and `MS_JIT_MODULES` specify the same module name at the same time, the former takes effect and the latter does not. * - MS_DEV_FALLBACK_DUMP_NODE - - Print syntax expressions supported by `Static Graph Syntax Enhancement `_ in the code. + - Print syntax expressions supported by `Static Graph Syntax Enhancement `_ in the code. - Integer - 1: Enable printing. @@ -284,13 +284,13 @@ Dump Debugging - Value Range - Description * - MINDSPORE_DUMP_CONFIG - - Specify the path of the configuration file that the `cloud-side Dump `_ + - Specify the path of the configuration file that the `cloud-side Dump `_ or the `device-side Dump `_ depends on. - String - File path, which can be a relative path or an absolute path. - * - MS_DIAGNOSTIC_DATA_PATH - - When the `cloud-side Dump `_ is enabled, + - When the `cloud-side Dump `_ is enabled, if the `path` field is not set or set to an empty string in the Dump configuration file, then `$MS_DIAGNOSTIC_DATA_PATH` `/debug_dump is regarded as path. If the `path` field in configuration file is not empty, it is still used as the path to save Dump data. - String @@ -337,7 +337,7 @@ Dump Debugging - File path, which can be a relative path or an absolute path. - -For more information, see `Using Dump in the Graph Mode `_. +For more information, see `Using Dump in the Graph Mode `_. Distributed Parallel --------------------- @@ -392,7 +392,7 @@ Distributed Parallel MS_WORKER: represents the Worker process, which generally sets up the distributed training process for this role. - MS_PSERVER: represents the Parameter Server process, and this role is only valid in Parameter Server mode. Please refer to `Parameter Server mode `_ . + MS_PSERVER: represents the Parameter Server process, and this role is only valid in Parameter Server mode. Please refer to `Parameter Server mode `_ . - The Worker and Parameter Server processes register with the Scheduler process to complete the networking. * - MS_SCHED_HOST - Specifies the IP address of the Scheduler. @@ -494,7 +494,7 @@ Distributed Parallel delete_depend_list(List[string]): A list of operator names that need to be deleted. If the operator name does not exist or does not match the graph_id, the action of deleting the node will be invalid. -See `Dynamic Cluster `_ for more details about Dynamic Cluster. +See `Dynamic Cluster `_ for more details about Dynamic Cluster. Operators Compile ----------------- @@ -717,7 +717,7 @@ Log Note: glog does not support log file wrapping. If you need to control the log file occupation of disk space, you can use the log file management tool provided by the operating system, for example: logrotate for Linux. Please set the log environment variables before `import mindspore` . -For more detailed information about RDR, refer to `Running Data Recorder `_ . +For more detailed information about RDR, refer to `Running Data Recorder `_ . Feature Value Detection ------------------------------ @@ -757,7 +757,7 @@ Feature Value Detection By default, if this environment variable is not configured, `NPU_ASD_SIGMA_THRESH=100000,5000` - -For more information on feature value detection, see `Feature Value Detection `_. +For more information on feature value detection, see `Feature Value Detection `_. Third-party Library diff --git a/docs/mindspore/source_en/note/static_graph_syntax_support.md b/docs/mindspore/source_en/note/static_graph_syntax_support.md deleted file mode 100644 index 01cb31ff01d17a95380b6e3d6f9bac30ad977e7f..0000000000000000000000000000000000000000 --- a/docs/mindspore/source_en/note/static_graph_syntax_support.md +++ /dev/null @@ -1,1709 +0,0 @@ -# Static Graph Syntax Support - -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/static_graph_syntax_support.md) - -## Overview - -In graph mode, Python code is not executed by the Python interpreter. Instead, the code is compiled into a static computation graph, and then the static computation graph is executed. - -In static graph mode, MindSpore converts Python source code into Intermediate Representation IR by means of source code conversion and optimizes IR graphs on this basis, and finally executes the optimized graphs on hardware devices. MindSpore uses a functional IR based on graph representations, called MindIR. See [middle representation MindIR](https://www.mindspore.cn/docs/en/master/design/all_scenarios.html#mindspore-ir-mindir) for details . - -MindSpore static graph execution process actually consists of two steps, corresponding to the Define and Run phases of the static graph, but in practice, the user will not perceive these two phases when the instantiated Cell object is called. MindSpore encapsulates both phases in the Cell `__call__` method, so the actual calling process is: - -`model(inputs) = model.compile(inputs) + model.construct(inputs)`, where `model` is the instantiated Cell object. - -There are two ways to use the Graph mode. The first way is to call the `@jit` decorator to modify a function or a class member method, and then the decorated function or method will be compiled into a static computation graph. For details about how to use `jit`, click [jit API document](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.jit.html#mindspore.jit). The second way is to set `ms.set_context(mode=ms.GRAPH_MODE)`, then write the code in the `construct` function of the `Cell` so that the code in the `construct` function will be compiled into a static computation graph. For details about the definition of `Cell`, click [Cell API document](https://www.mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html). - -Due to syntax parsing restrictions, the supported data types, syntax, and related operations during graph building are not completely consistent with the Python syntax. As a result, some usage is restricted. Borrowing the traditional JIT compilation idea, considers the unification of static and dynamic graphs from the perspective of graph mode and extends the syntax capabilities of graph patterns. The static graph provides a syntax experience close to that of the dynamic graph, so as to realize the unity of dynamic and static. In order to facilitate users to choose whether to extend the static graph syntax, the JIT syntax support level option 'jit_syntax_level' is provided, and its value must be in the range of [STRICT,LAX], and selecting 'STRICT' is considered to use the basic syntax and do not extend the static graph syntax. The default value is 'LAX', please refer to the [Extended Syntaxes (LAX level)](#extended-syntaxes-lax-level) section of this article for more information. All backends are supported at all levels. - -- STRICT: Only basic syntaxes is supported, and execution performance is optimal. Can be used for MindIR load and export. -- LAX: Supporting more complex syntaxes, compatible with all Python syntax as much as possible. Cannot be used for MindIR load and export due to some syntax that may not be able to be exported. - -The following describes the data types, syntax, and related operations supported during static graph building. These rules apply only to graph mode. - -## Basic Syntaxes (STRICT Level) - -### Constants and Variables Within Static Graphs - -In static graphs, constants and variables are an important concept for understanding static graph syntax, and many syntaxes support different methods and degrees in the case of constant input and variable input. Therefore, before introducing the specific syntax supported by static graphs, this section first explains the concepts of constants and variables in static graphs. - -In static graph mode, the operation of a program is divided into compilation period and execution period. During compilation, the program is compiled into an intermediate representation graph, and the program does not actually execute, but statically parses the intermediate representation through abstract deduction. This makes it impossible to guarantee that we will get the values of all intermediate representation nodes at compile time. Constants and variables are distinguished by their true values in the compiler. - -- Constant: The amount of value that can be obtained during compilation. -- Variable: The amount of value that cannot be obtained during compilation. - -#### Constants Generate Scenes - -- Scalars, lists, and tuples entered as graph mode are constants (without using the mutable interface). For example: - - ```python - from mindspore import Tensor, jit - - a = 1 - b = [Tensor([1]), Tensor([2])] - c = ["a", "b", "c"] - - @jit - def foo(a, b, c): - return a, b, c - ``` - - In the above code, enter `a`, `b`, `c` are constants. - -- The result of the constant operation is constant. For example: - - ```python - from mindspore import jit, Tensor - - @jit - def foo(): - a = 1 - b = "2" - c = Tensor([1, 2, 3]) - return a, b, c - ``` - - In the above code, enter `a`, `b`, `c` are constants. - -- Constant operations obtain a constant result. For example: - - ```python - from mindspore import jit, Tensor - - @jit - def foo(): - a = Tensor([1, 2, 3]) - b = Tensor([1, 1, 1]) - c = a + b - return c - ``` - - In the above code, `a` and `b` are constants of Tensor generated in the graph mode, so the result of their calculation is also constant. However, if one of them is a variable, its return value will also be a variable. - -#### Variables Generate Scenes - -- The return value of all mutable interfaces is a variable (whether mutable is used outside the graph or inside the graph). For example: - - ```python - from mindspore import Tensor, jit - from mindspore import mutable - - a = mutable([Tensor([1]), Tensor([2])]) - - @jit - def foo(a): - b = mutable(Tensor([3])) - c = mutable((Tensor([1]), Tensor([2]))) - return a, b, c - ``` - - In the above code, `a` is generated by calling the mutable interface outside the graph, `b` and `c` are generated by calling the mutable interface inside the graph, and `a`, `b`, and `c` are variables. - -- Tensors that are inputs to static graphs are variables. For example: - - ```python - from mindspore import Tensor, jit - - a = Tensor([1]) - b = (Tensor([1]), Tensor([2])) - - @jit - def foo(a, b): - return a, b - ``` - - In the above code, `a` is the Tensor input as the graph pattern, so it is a variable. But `b` is a tuple that is input to the graph schema, not a Tensor type, and even if its internal elements are Tensor, `b` is a constant. - -- What is calculated by variables is the variable - - If a quantity is the output of an operator, then it is in most cases constant. For example: - - ```python - from mindspore import Tensor, jit, ops - - a = Tensor([1]) - b = Tensor([2]) - - @jit - def foo(a, b): - c = a + b - return c - ``` - - In this case , `c` is the result of calculations of `a` and `b` , and the inputs `a` and `b` used for the calculation are variables , so `c` is also a variable. - -### Data Types - -#### Built-in Python Data Types - -Currently, the following built-in `Python` data types are supported: `Number`, `String`, `List`, `Tuple`, and `Dictionary`. - -##### Number - -Supporting `int`, `float`, and `bool`, but does not support `complex` numbers. - -`Number` can be defined on the network. That is, the syntax `y = 1`, `y = 1.2`, and `y = True` are supported. - -When the data is a constant, the value of the data can be achieved at compile time, the forcible conversion to `Number` is supported in the network. The syntax `y = int(x)`, `y = float(x)`, and `y = bool(x)` are supported. -When the data is a variable, i.e., you can get the value only at runtime. It also supports data type conversion using built-in functions [Python Built-in Functions](#python-built-in-functions) such as int(), float() and bool(). For example: - -```python -from mindspore import Tensor, jit - -@jit -def foo(x): - out1 = int(11.1) - out2 = int(Tensor([10])) - out3 = int(x.asnumpy()) - return out1, out2, out3 - -res = foo(Tensor(2)) -print("res[0]:", res[0]) -print("res[1]:", res[1]) -print("res[2]:", res[2]) -``` - -The result is as follows: - -```text -res[0]: 11 -res[1]: 10 -res[2]: 2 -``` - -Supporting returning Number. For example: - -```python -import mindspore as ms - -@ms.jit -def test_return_scalar(x, y): - return x + y - -res = test_return_scalar(ms.mutable(1), ms.mutable(2)) -print(res) -``` - -```text -3 -``` - -##### String - -`String` can be constructed on the network, i.e., support for using quotes (`'` or `"`) to create strings such as `x = 'abcd'` or `y = "efgh"`. Convert constants to strings by means of `str()`. Support string concatenation, truncation, and the use of membership operators (`in` or `not in`) to determine whether a string contains the specified character. Support for formatting string output by inserting a value into a string with the string format `%s`. Support for using the format string function `str.format()` in constant scenarios. - -For example: - -```python -from mindspore import jit - -@jit -def foo(): - var1 = 'Hello!' - var2 = "MindSpore" - var3 = str(123) - var4 = "{} is {}".format("string", var3) - return var1[0], var2[4:9], var1 + var2, var2 * 2, "H" in var1, "My name is %s!" % var2, var4 - -res = foo() -print("res:", res) -``` - -The result is as follows: - -```text -res: ('H', 'Spore', 'Hello!MindSpore', 'MindSporeMindSpore', True, 'My name is MindSpore!', 'string is 123') -``` - -##### List - -When 'JIT_SYNTAX_LEVEL' is set to 'LAX', static graph mode can support the inplace operation of some 'List' objects, see [Supporting List Inplace Modification Operations](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax_support.html#supporting-list-inplace-modification-operations). - -The basic usage scenarios of 'List' are as follows: - -- The graph mode supports creating `Lists` in graph. - - Support creating `List` objects within graph mode, and the elements of the `List` objects can contain any of the types supported by the graph mode, as well as multiple levels of nesting. For example: - - ```python - import numpy as np - import mindspore as ms - - @ms.jit - def generate_list(): - a = [1, 2, 3, 4] - b = ["1", "2", "a"] - c = [ms.Tensor([1]), ms.Tensor([2])] - d = [a, b, c, (4, 5)] - return d - ``` - - The above sample code, all `List` objects can be created normally. - -- The graph mode supports returning `List` - - Before MindSpore version 2.0, `List` is converted to `Tuple` when the graph mode returns a `List` object. In MindSpore version 2.0, `List` objects can be returned. For example: - - ```python - import mindspore as ms - - @ms.jit - def list_func(): - a = [1, 2, 3, 4] - return a - - output = list_func() # output: [1, 2, 3, 4] - ``` - - In the same way that a `List` is created within a graph mode, the graph mode returns a `List` object that can include any of the types supported by the graph mode, as well as multiple levels of nesting. - -- The graph mode supports obtaining `List` objects from global variables - - ```python - import mindspore as ms - - global_list = [1, 2, 3, 4] - - @ms.jit - def list_func(): - global_list.reverse() - return global_list - - output = list_func() # output: [4, 3, 2, 1] - ``` - - It should be noted that the list returned in the following pattern in the basic scenario is not the same object as the list of global variables, and when 'JIT_SYNTAX_LEVEL' is set to 'LAX', the returned object and the global object are unified objects. - -- Graph mode supports `List` as input - - The graph mode supports `List` as input to static graphs. The elements of the `List` object used as input must be of an input type supported by the graph mode, which also supports multiple levels of nesting. - - ```python - import mindspore as ms - - list_input = [1, 2, 3, 4] - - @ms.jit - def list_func(x): - return x - - output = list_func(list_input) # output: [1, 2, 3, 4] - ``` - - It should be noted that when 'List' is input as a static graph, it is always treated as a constant, regardless of the type of element inside it. - -- Graph mode supports built-in methods for List - - The 'List' built-in method is described in detail below: - - - List Index Value - - Basic syntax: ```element = list_object[index]```. - - Basic semantics: Extract the element in the 'List' object in the 'index' bit ('index' starts at 0). Supporting multi-level index values. - - Index value 'index' supported types include 'int', 'Tensor', and 'slice'. Among them, inputs of type 'int' and 'Tensor' can support constants and variables, and 'slice' internal data must be constants that can be determined at compile time. - - Examples are as follows: - - ```python - import mindspore as ms - @ms.jit() - def list_getitem_func(): - x = [[1, 2], 3, 4] - a = x[0] - b = x[0][ms.Tensor([1])] - c = x[1:3:1] - return a, b, c - - a, b, c = list_getitem_func() - print('a:{}'.format(a)) - print('b:{}'.format(b)) - print('c:{}'.format(c)) - ``` - - The results are as follows: - - ```text - a:[1, 2] - b:2 - c:[3, 4] - ``` - - - List index assignment - - Basic syntax: ```list_object[index] = target_element```. - - Basic semantics: Assign the element in the 'List' object at bit 'index' to 'target_element' ('index' starts at 0). Support for multi-tier index assignment. - - Index value 'index' supported types include 'int', 'Tensor', and 'slice'. Among them, inputs of type 'int' and 'Tensor' can support constants and variables, and the internal data of 'slice' must be constant that can be determined at compile time. - - The index assignment object 'target_element' supports all data types supported by graph modes. - - Currently, the 'List' index assignment does not support the inplace operation, and a new object will be generated after the index is assigned. This operation will support the inplace operation in the future. - - Examples are as follows: - - ```python - import mindspore as ms - - @ms.jit() - def test_setitem_func(): - x = [[0, 1], 2, 3, 4] - x[1] = 10 - x[2] = "ok" - x[3] = (1, 2, 3) - x[0][1] = 88 - return x - - output = test_setitem_func() - print('output:{}'.format(output)) - ``` - - The results are as follows: - - ```text - output:[[0, 88], 10, 'ok', (1, 2, 3)] - ``` - - - List.append - - Basic syntax: ```list_object.append(target_element)```. - - Basic semantics: Append the element 'target_element' to the last list_object' of the 'List' object. - - Currently, 'List.append' does not support the inplace operation, and a new object will be generated after index assignment. This operation will support the inplace operation in the future. - - Examples are as follows: - - ```python - import mindspore as ms - - @ms.jit() - def test_list(): - x = [1, 2, 3] - x.append(4) - return x - - x = test_list() - print('x:{}'.format(x)) - ``` - - The results are as follows: - - ```text - x:[1, 2, 3, 4] - ``` - - - List.clear - - Basic syntax: ```list_object.clear()```. - - Base semantics: Empty the elements contained in the 'List' object 'list_object'. - - Currently, 'List.clear' does not support inplace, and a new object will be generated after index assignment. This operation will support inplace in the future. - - Examples are as follows: - - ```python - import mindspore as ms - - @ms.jit() - def test_list_clear(): - x = [1, 3, 4] - x.clear() - return x - - x = test_list_clear() - print('x:{}'.format(x)) - ``` - - The results are as follows: - - ```text - x:[] - ``` - - - List.extend - - Basic syntax: ```list_object.extend(target)```. - - Basic semantics: Insert all elements inside the 'target' to the end of the 'List' object 'list_object'. - - The supported types for 'target' are 'Tuple', 'List', and 'Tensor'. Among them, if the 'target' type is 'Tensor', the 'Tensor' will be converted to 'List' before inserting it. - - Examples are as follows: - - ```python - import mindspore as ms - - @ms.jit() - def test_list_extend(): - x1 = [1, 2, 3] - x1.extend((4, "a")) - x2 = [1, 2, 3] - x2.extend(ms.Tensor([4, 5])) - return x1, x2 - - output1, output2 = test_list_extend() - print('output1:{}'.format(output1)) - print('output2:{}'.format(output2)) - ``` - - The results are as follows: - - ```text - output1:[1, 2, 3, 4, 'a'] - output2:[1, 2, 3, Tensor(shape=[1], dtype=Int64, value= [4]), Tensor(shape=[1], dtype=Int64, value= [5])] - ``` - - - List.pop - - Basic syntax: ```pop_element = list_object.pop(index=-1)```. - - Basic semantics: Remove the 'index' element of the 'List' object 'list_object' from the 'list_object' and return the element. - - The 'index' requires that it must be a constant 'int', and when 'list_object' has a length of 'list_obj_size', 'index' has a value range of '[-list_obj_size,list_obj_size-1]'. 'index' is a negative number representing the number of digits from back to front. When no 'index' is entered, the default value is -1, i.e. the last element is removed. - - ```python - import mindspore as ms - - @ms.jit() - def test_list_pop(): - x = [1, 2, 3] - b = x.pop() - return b, x - - pop_element, res_list = test_list_pop() - print('pop_element:{}'.format(pop_element)) - print('res_list:{}'.format(res_list)) - ``` - - The results are as follows: - - ```text - pop_element:3 - res_list:[1, 2] - ``` - - - List.reverse - - Basic syntax: ```list_object.reverse()```. - - Basic semantics: Reverse the order of the elements of the 'List' object 'list_object'. - - Examples are as follows: - - ```python - import mindspore as ms - - @ms.jit() - def test_list_reverse(): - x = [1, 2, 3] - x.reverse() - return x - - output = test_list_reverse() - print('output:{}'.format(output)) - ``` - - The results are as follows: - - ```text - output1:[3, 2, 1] - ``` - - - List.insert - - Basic syntax: ```list_object.insert(index, target_obj)```. - - Basic semantics: insert 'target_obj' into the 'index' bit of 'list_object'. - - The 'index' requirement must be a constant 'int'. If the length of 'list_object' is 'list_obj_size'. When 'index < -list_obj_size', insert the first place in 'List'. When 'index >= list_obj_size', insert at the end of 'List'. A negative 'index' represents the number of digits from back to front. - - Examples are as follows: - - ```python - import mindspore as ms - - @ms.jit() - def test_list_insert(): - x = [1, 2, 3] - x.insert(3, 4) - return x - - output = test_list_insert() - print('output:{}'.format(output)) - ``` - - The results are as follows: - - ```text - output:[1, 2, 3, 4] - ``` - -##### Tuple - -`Tuple` can be constructed on the network, that is, the syntax `y = (1, 2, 3)` is supported. The elements of the tuple `Tuple` cannot be modified, but indexed access to elements in the tuple `Tuple` is supported, and concatenated combinations of tuples are supported. - -- Supported index values - - Support accessing elements in the tuple `Tuple` using square brackets plus subscripted indexes. The index value can be `int`, `slice`, `Tensor`, and multi-level index value. That is, the syntax `data = tuple_x[index0][index1]...` is supported. - - Restrictions on the index value `Tensor` are as follows: - - - `Tuple` stores `Cell`. Each `Cell` must be defined before a tuple is defined. The number of input parameters, input parameter type, and input parameter `shape` of each `Cell` must be the same. The number of outputs of each `Cell` must be the same. The output type must be the same as the output `shape`. - - - The index `Tensor` is a scalar `Tensor` whose `dtype` is `int32`. The value range is `[-tuple_len, tuple_len)`, and negative index is not supported in `Ascend` backend. - - - `CPU`, `GPU` and `Ascend` backend is supported. - - An example of the `int` and `slice` indexes is as follows: - - ```python - import numpy as np - import mindspore as ms - - t = ms.Tensor(np.array([1, 2, 3])) - - @ms.jit() - def test_index(): - x = (1, (2, 3, 4), 3, 4, t) - y = x[1][1] - z = x[4] - m = x[1:4] - n = x[-4] - return y, z, m, n - - y, z, m, n = test_index() - print('y:{}'.format(y)) - print('z:{}'.format(z)) - print('m:{}'.format(m)) - print('n:{}'.format(n)) - ``` - - The result is as follows: - - ```text - y:3 - z:[1 2 3] - m:((2, 3, 4), 3, 4) - n:(2, 3, 4) - ``` - - An example of the `Tensor` index is as follows: - - ```python - import mindspore as ms - from mindspore import nn, set_context - - set_context(mode=ms.GRAPH_MODE) - - class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - self.relu = nn.ReLU() - self.softmax = nn.Softmax() - self.layers = (self.relu, self.softmax) - - def construct(self, x, index): - ret = self.layers[index](x) - return ret - - x = ms.Tensor([-1.0], ms.float32) - - net = Net() - ret = net(x, 0) - print('ret:{}'.format(ret)) - ``` - - The result is as follows: - - ```text - ret:[0.] - ``` - -- Support connection combinations - - Similar to the string `String`, tuples support combining using `+` and `*` to get a new tuple `Tuple`, for example: - - ```python - import mindspore as ms - - @ms.jit() - def test_index(): - x = (1, 2, 3) - y = (4, 5, 6) - return x + y, x * 2 - - out1, out2 = test_index() - print('out1:{}'.format(out1)) - print('out2:{}'.format(out2)) - ``` - - The result is as follows: - - ```text - out1:(1, 2, 3, 4, 5, 6) - out2:(1, 2, 3, 1, 2, 3) - ``` - -##### Dictionary - -`Dictionary` can be constructed on the network. Each key value `key:value` is separated by a colon `:`, and each key value pair is separated by a comma `,`. The entire dictionary contains the key-value pairs using curly braces `{}`. That is, the syntax `y = {"a": 1, "b": 2}` is supported. - -The `key` is unique, and if there are multiple identical `keys` in the dictionary, the duplicate `keys` are finalized with the last one and the value `value` can be non-unique. The key `key` needs to be guaranteed to be immutable. Currently, the `key` can be `String`, `Number`, constant `Tensor`, or `Tuple` that contains these types. The `value` can be `Number`, `Tuple`, `Tensor`, `List` or `Dictionary`. - -- Supported APIs - - `keys`: extracts all `key` values from `dict` to form `Tuple` and return it. - - `values`: extracts all `value` values from `dict` to form `Tuple` and return it. - - `items`: extracts `Tuple` composed of each pair of `value` values and `key` values in `dict` to form `List` and return it. - - `get`: `dict.get(key[, value])` returns the `value` value corresponding to the specified `key`, if the specified `key` does not exist, the default value `None` or the set default value `value` is returned . - - `clear`: removes all elements in `dict`. - - `has_key`: `dict.has_key(key)` determines whether the specified `key` exists in `dict`. - - `update`: `dict1.update(dict2)` updates the elements in `dict2` to `dict1`. - - `fromkeys`: `dict.fromkeys(seq([, value]))` is used to create a new `Dictionary`, using the elements in the sequence `seq` as the `key` of the `Dictionary`, and the `value` is initial value corresponding to all `key`. - - The example is as follows, where the 'x' and 'new_dict' in the return value are a 'Dictionary', and the support is extended under the JIT syntax support level option LAX in graph mode, for more advanced use of Dictionary, please refer to the [Supporting the high-level usage of Dictionary](#supporting-the-high-level-usage-of-dictionary) section of this article. - - ```python - import mindspore as ms - import numpy as np - - x = {"a": ms.Tensor(np.array([1, 2, 3])), "b": ms.Tensor(np.array([4, 5, 6])), "c": ms.Tensor(np.array([7, 8, 9]))} - - @ms.jit() - def test_dict(): - x_keys = x.keys() - x_values = x.values() - x_items = x.items() - value_a = x.get("a") - check_key = x.has_key("a") - y = {"a": ms.Tensor(np.array([0, 0, 0]))} - x.update(y) - new_dict = x.fromkeys("abcd", 123) - return x_keys, x_values, x_items, value_a, check_key, x, new_dict - - x_keys, x_values, x_items, value_a, check_key, new_x, new_dict = test_dict() - print('x_keys:{}'.format(x_keys)) - print('x_values:{}'.format(x_values)) - print('x_items:{}'.format(x_items)) - print('value_a:{}'.format(value_a)) - print('check_key:{}'.format(check_key)) - print('new_x:{}'.format(new_x)) - print('new_dict:{}'.format(new_dict)) - ``` - - The result is as follows: - - ```text - x_keys:('a', 'b', 'c') - x_values:(Tensor(shape=[3], dtype=Int64, value= [1, 2, 3]), Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])) - x_items:[('a', Tensor(shape=[3], dtype=Int64, value= [1, 2, 3])), ('b', Tensor(shape=[3], dtype=Int64, value= [4, 5, 6])), ('c', Tensor(shape=[3], dtype=Int64, value= [7, 8, 9]))] - value_a:[1 2 3] - check_key:True - new_x:{'a': Tensor(shape=[3], dtype=Int64, value= [0, 0, 0]), 'b': Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), 'c': Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])} - new_dict:{'a': 123, 'b': 123, 'c': 123, 'd': 123} - ``` - -#### MindSpore User-defined Data Types - -Currently, MindSpore supports the following user-defined data types: `Tensor`, `Primitive`, and `Cell`. - -##### Tensor - -For details of `Tensor`, click [Tensor API document](https://mindspore.cn/docs/en/master/api_python/mindspore/mindspore.Tensor.html#mindspore-tensor). - -Supporting creating and using Tensor. The ways to create a `Tensor` include using [tensor function interface](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.tensor.html#mindspore.tensor) and using the class 'ms.Tensor' interface. It is recommended to use the former because users can specify the required dtype. The code case is as follows. - -```python -import mindspore as ms -import mindspore.nn as nn - -class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - - @ms.jit - def construct(self, x): - return ms.tensor(x.asnumpy(), dtype=ms.float32) - -ms.set_context(mode=ms.GRAPH_MODE) -net = Net() -x = ms.Tensor(1, dtype=ms.int32) -print(net(x)) -``` - -```text -1.0 -``` - -##### Primitive - -Currently, `Primitive` and its subclass instances can be constructed in construct. - -However, during call, the parameter can be specified only in position parameter mode, and cannot be specified in the key-value pair mode. - -For example: - -```python -import mindspore as ms -from mindspore import nn, ops, Tensor, set_context -import numpy as np - -set_context(mode=ms.GRAPH_MODE) - -class Net(nn.Cell): - def __init__(self): - super().__init__() - - def construct(self, x): - reduce_sum = ops.ReduceSum(True) #`Primitive` and its subclass instances can be constructed in construct. - ret = reduce_sum(x, axis=2) - return ret - -x = Tensor(np.random.randn(3, 4, 5, 6).astype(np.float32)) -net = Net() -ret = net(x) -print('ret.shape:{}'.format(ret.shape)) -``` - -In the network defined above, the parameters of reduce_sum(x, axis=2) cannot be specified in the key-value pair mode. The parameter can be specified only in position parameter mode, that is, reduce_sum(x, 2). - -The error is reported as follows: - -```text -TypeError: For Primitive[ReduceSum], only positional arguments as inputs are supported, but got AbstractKeywordArg(key: axis, value: AbstractScalar(type: Int64, Value: 2, Shape: NoShape)) -``` - -Currently, the attributes and APIs related to `Primitive` and its subclasses cannot be called on the network. - -For details about the defined `Primitive`, click [Primitive API document](https://www.mindspore.cn/docs/en/master/api_python/ops/mindspore.ops.Primitive.html#mindspore.ops.Primitive). - -##### Cell - -Currently, `Cell` and its subclass instances can be constructed on the network. That is, the syntax `cell = Cell(args...)` is supported. - -However, during call, the parameter can be specified only in position parameter mode, and cannot be specified in the key-value pair mode. That is, the syntax `cell = Cell(arg_name=value)` is not supported. - -Currently, the attributes and APIs related to `Cell` and its subclasses cannot be called on the network unless they are called through `self` in `construct` of `Cell`. - -For details about the definition of `Cell`, click [Cell API document](https://www.mindspore.cn/docs/en/master/api_python/nn/mindspore.nn.Cell.html). - -##### Parameter - -`Parameter` is a variable tensor, indicating the parameters that need to be updated during network training. - -For details about the definition of `Parameter`, click [Parameter API document](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.Parameter.html#mindspore.Parameter). - -### Operators - -Arithmetic operators and assignment operators support the `Number` and `Tensor` operations, as well as the `Tensor` operations of different `dtype`. For more details, please refer to [Operators](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/operators.html) - -### Primaries - -Primaries represent the most tightly bound operations of the language. - -#### Attribute References and Attribute Modification - -An attribute reference is a primary followed by a period and a name. - -Using attribute references as l-values in Cell instances of MindSpore requires the following requirements: - -- The modified attribute belongs to this `cell` object, i.e. it must be `self.xxx`. -- The attribute is initialized in Cell's '__init__' function and is of type Parameter. - -When the JIT syntax support level option is 'LAX', can support attribute modification in more situations, see [Support Attribute Setting and Modification](#supporting-property-setting-and-modification). - -Examples are as follows: - -```python -import mindspore as ms -from mindspore import nn, set_context - -set_context(mode=ms.GRAPH_MODE) - -class Net(nn.Cell): - def __init__(self): - super().__init__() - self.weight = ms.Parameter(ms.Tensor(3, ms.float32), name="w") - self.m = 2 - - def construct(self, x, y): - self.weight = x # The conditions are met, they can be modified - # self.m = 3 # self.m is not of type Parameter and modification is prohibited - # y.weight = x # y is not self, modification is prohibited - return x - -net = Net() -ret = net(1, 2) -print('ret:{}'.format(ret)) -``` - -The results are as follows: - -```text -ret:1 -``` - -#### Index Value - -Index value of a sequence `Tuple`, `List`, `Dictionary`, `Tensor` which called subscription in Python. - -Index value of `Tuple` refers to chapter [Tuple](#tuple) of this page. - -Index value of `List` refers to chapter [List](#list) of this page. - -Index value of `Dictionary` refers to chapter [Dictionary](#dictionary) of this page. - -Index value of `Tensor` refers to [Tensor index value document](https://www.mindspore.cn/docs/en/master/note/index_support.html#index-values). - -#### Calls - -A call calls a callable object (e.g., `Cell` or `Primitive`) with a possibly empty series of arguments. - -For example: - -```python -import mindspore as ms -from mindspore import nn, ops, set_context -import numpy as np - -set_context(mode=ms.GRAPH_MODE) - -class Net(nn.Cell): - def __init__(self): - super().__init__() - self.matmul = ops.MatMul() - - def construct(self, x, y): - out = self.matmul(x, y) # A call of Primitive - return out - -x = ms.Tensor(np.ones(shape=[1, 3]), ms.float32) -y = ms.Tensor(np.ones(shape=[3, 4]), ms.float32) -net = Net() -ret = net(x, y) -print('ret:{}'.format(ret)) -``` - -The result is as follows: - -```text -ret:[[3. 3. 3. 3.]] -``` - -### Statements - -Currently supported Python statements include raise statement, assert statement, pass statement, return statement, break statement, continue statement, if statement, for statement, while statement, with statement, list comprehension, generator expression and function definition statement. For more details, please refer to [Statements](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/statements.html) - -### Python Built-in Functions - -Currently supported Python built-in functions include `int`, `float`, `bool`, `str`, `list`, `tuple`, `getattr`, `hasattr`, `len`, `isinstance`, `all`, `any`, `round`, `max`, `min` , `sum`, `abs`, `partial`, `map`, `range`, `enumerate`, `super`, `pow`, `filter`. The use of built-in functions in graph mode is similar to the corresponding Python built-in functions. For more details, please refer to [Python Built-in Functions](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/python_builtin_functions.html). - -### Network Definition - -#### Network Input parameters - -While calculating gradient for outermost network, only `Tensor` input could be calculated, input of other type will be ignored. - -The code example is shown below. Among the input parameter `(x, y, z)` of outermost network, `x` and `z` are `Tensor` type but `y` is not. While `grad_net` calculating gradient of the input parameters `(x, y, z)` for the network, gradient of `y` is automatically ignored. Only gradients of `x` and `z` are calculated, and `(grad_x, grad_y)` is returned. - -```python -import numpy as np -import mindspore as ms -from mindspore import nn - -ms.set_context(mode=ms.GRAPH_MODE) - -class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - - def construct(self, x, y, z): - return x + y + z - -class GradNet(nn.Cell): - def __init__(self, net): - super(GradNet, self).__init__() - self.forward_net = net - - def construct(self, x, y, z): - return ms.grad(self.forward_net, grad_position=(0, 1, 2))(x, y, z) - -input_x = ms.Tensor([1]) -input_y = 2 -input_z = ms.Tensor([3]) - -net = Net() -grad_net = GradNet(net) -ret = grad_net(input_x, input_y, input_z) -print('ret:{}'.format(ret)) -``` - -The result is as follows: - -```text -ret:(Tensor(shape=[1], dtype=Int64, value= [1]), Tensor(shape=[1], dtype=Int64, value= [1])) -``` - -## Syntax Constraints of Basic Syntaxes - -The execution graph in graph mode is converted from source code, and not all Python syntax can support it. The following describes some of the syntax constraints that exist under the basic syntax. More network compilation problems can be found in [Network compilation](https://www.mindspore.cn/docs/en/master/faq/network_compilation.html). - -1. When an undefined class member is used in the `construct` function, `AttributeError` exception will be thrown. For example: - - ```python - import mindspore as ms - from mindspore import nn, set_context - - set_context(mode=ms.GRAPH_MODE) - - class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - - def construct(self, x): - return x + self.y - - net = Net() - net(1) - ``` - - The result is as follows: - - ```text - AttributeError: External object has no attribute y - ``` - -2. Class methods modified by `classmethod` in `nn.Cell` are not supported. For example: - - ```python - import mindspore as ms - - ms.set_context(mode=ms.GRAPH_MODE) - - class Net(ms.nn.Cell): - @classmethod - def func(cls, x, y): - return x + y - - def construct(self, x, y): - return self.func(x, y) - - net = Net() - out = net(ms.Tensor(1), ms.Tensor(2)) - print(out) - ``` - - The result is as follows: - - ```Text - TypeError: The parameters number of the function is 3, but the number of provided arguments is 2. - ``` - -3. In graph mode, some Python syntax is difficult to convert to [intermediate MindIR](https://www.mindspore.cn/docs/en/master/design/all_scenarios.html#mindspore-ir-mindir) in graph mode. For Python keywords, there are some keywords that are not supported in graph mode: AsyncFunctionDef, Delete, AnnAssign, AsyncFor, AsyncWith, Match, Try, Import, ImportFrom, Nonlocal, NamedExpr, Set, SetComp, Await, Yield, YieldFrom, Starred. If the relevant syntax is used in graph mode, an error message will alert the user. - - If you use the Try statement, the following example is used: - - ```python - import mindspore as ms - - @ms.jit - def test_try_except(x, y): - global_out = 1 - try: - global_out = x / y - except ZeroDivisionError: - print("division by zero, y is zero.") - return global_out - - test_try_except_out = test_try_except(1, 0) - print("out:", test_try_except_out) - ``` - - The result is as follows: - - ```Text - RuntimeError: Unsupported statement 'Try'. - ``` - -4. Benchmarking Python built-in data types, except for [Built-in Python Data Types](#built-in-python-data-types) supported in the current graph mode, complex 'complex' and collection 'set' types are not supported. Some high-level uses of the list 'list' and dictionary 'dictionary' are not supported in the basic syntax scenario, and need to be supported when the JIT syntax support level option 'jit_syntax_level' is 'LAX', please refer to the [Extended Syntaxes (LAX level)](#extended-syntaxes-lax-level) section of this article for more information. - -5. In the basic syntax scenario, in addition to the [Python Built-in Functions](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/python_builtin_functions.html) supported in the current graph mode, there are still some built-in functions that are not supported in graph mode. For example: basestring, bin, bytearray, callable, chr, cmp, compile, delattr, dir, divmod, eval, execfile, file, frozenset, hash, hex, id, input, issubclass, iter, locals, long, memoryview, next, object, oct, open, ord, property, raw_input, reduce, reload, repr, reverse, set, slice, sorted, unichr, unicode, vars, xrange, \_\_import\_\_. - -6. Python provides a number of third-party libraries that usually need to be called via import statements. In graph mode, when the JIT syntax support level is 'STRICT', you cannot directly use third-party libraries. If you need to use the data types of third-party libraries in graph mode or call methods of third-party libraries, you need to support them only if the JIT syntax support level option 'jit_syntax_level' is 'LAX', please refer to the [Calling the Third-party Libraries](#calling-the-third-party-libraries) section in [Extended Syntaxes (LAX level)](#extended-syntaxes-lax-level) of this article. - -7. In graph mode, the modification of the attributes of the class outside the graph is not perceived, that is, the modification of the attributes of the class outside the graph will not take effect. For example: - - ```python - import mindspore as ms - from mindspore import nn, ops, Tensor, context - - class Net(nn.Cell): - def __init__(self): - super().__init__() - self.len = 1 - - def construct(self, inputs): - x = inputs + self.len - return x - - context.set_context(mode=ms.GRAPH_MODE) - inputs = 2 - net = Net() - print("out1:", net(inputs)) - net.len = 2 - print("out2:", net(inputs)) - ``` - - The result of the output will not change: - - ```text - out1: 3 - out2: 3 - ``` - -## Extended Syntaxes (LAX level) - -The following mainly introduces the static graph syntax supported by the current extension. - -### Calling the Third-party Libraries - -- Third-party libraries. - - 1. Python built-in modules and Python standard libraries, such as `os`, `sys`, `math`, `time` and other modules. - - 2. Third-party code libraries. Their module paths are under the `site-packages` directory of the Python installation directory, which need to be installed first and then imported, such `NumPy` and `Scipy`. It should be noted that MindSpore suites such as `mindyolo` and `mindflow` are not treated as third-party libraries. For a detailed list, please refer to the `_modules_from_mindspore` list of the [parser](https://gitee.com/mindspore/mindspore/blob/master/mindspore/python/mindspore/_extends/parse/parser.py) file. - - 3. Modules specified by the environment variable `MS_JIT_IGNORE_MODULES`. In contrast, there is the environment variable `MS_JIT_MODULES`. For more details, please refer to [Environment Variables](https://www.mindspore.cn/docs/en/master/note/env_var_list.html). - -- Supporting data types of third-party libraries, allowing calling and returning objects of third-party libraries. - - The code example is as follows. - - ```python - import numpy as np - import mindspore as ms - - @ms.jit - def func(): - a = np.array([1, 2, 3]) - b = np.array([4, 5, 6]) - out = a + b - return out - - print(func()) - ``` - - The result is as follows: - - ```text - [5 7 9] - ``` - -- Supporting calling methods of third-party libraries. - - The code example is as follows. - - ```python - from scipy import linalg - import mindspore as ms - - @ms.jit - def func(): - x = [[1, 2], [3, 4]] - return linalg.qr(x) - - out = func() - print(out[0].shape) - ``` - - The result is as follows: - - ```text - (2, 2) - ``` - -- Supporting creating Tensor instances by using the data types of the third-party library NumPy. - - The code example is as follows. - - ```python - import numpy as np - import mindspore as ms - - @ms.jit - def func(): - x = np.array([1, 2, 3]) - out = ms.Tensor(x) + 1 - return out - - print(func()) - ``` - - The result is as follows: - - ```text - [2, 3, 4] - ``` - -- The assignment of subscripts for data types in third-party libraries is not currently supported. - - The code example is as follows. - - ```python - import numpy as np - import mindspore as ms - - @ms.jit - def func(): - x = np.array([1, 2, 3]) - x[0] += 1 - return ms.Tensor(x) - - res = func() - print("res: ", res) - ``` - - The error message is reported as follows: - - ```text - RuntimeError: For operation 'setitem', current input arguments types are . The 1-th argument type 'External' is not supported now. - ``` - -### Supporting the Use of Custom Classes - -Custom classes can be used in graph mode, and classes can be instantiated and object properties and methods can be used. - -For example, where 'GetattrClass' is a user-defined class that does not use the '@jit_class' decoration and does not inherit 'nn. Cell`。 - -```python -import mindspore as ms - -ms.set_context(mode=ms.GRAPH_MODE) - -class GetattrClass(): - def __init__(self): - self.attr1 = 99 - self.attr2 = 1 - - def method1(self, x): - return x + self.attr2 - -class GetattrClassNet(ms.nn.Cell): - def __init__(self): - super(GetattrClassNet, self).__init__() - self.cls = GetattrClass() - - def construct(self): - return self.cls.method1(self.cls.attr1) - -net = GetattrClassNet() -out = net() -assert out == 100 -``` - -### Basic Operators Support More Data Type - -In the syntax of graph mode, the following basic operators in the list is overloaded: ['+', '-', '*', '/', '//', '%', '**', '<<', '>>', '&', '|', '^', 'not', '==', '!=', '<', '>', '<=', '>=', 'in', 'not in', 'y=x[0]']. For more details, please refer to [Operators](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/operators.html). When getting unsupported input type, those operators need to use extended static graph syntax to support, and make the output consistent with the output in the pynative mode. - -The code example is as follows. - -```python -import mindspore as ms -import mindspore.nn as nn -from mindspore import Tensor -ms.set_context(mode=ms.GRAPH_MODE) - -class InnerClass(nn.Cell): - def construct(self, x, y): - return x.asnumpy() + y.asnumpy() - -net = InnerClass() -ret = net(Tensor([4, 5]), Tensor([1, 2])) -print(ret) -``` - -```text -[5 7] -``` - -In the example above, since the output of `x.asnumpy()` is `numpy.ndarray` and is an unsupported input type of `+` in the graph mode, `x.asnumpy() + y.asnumpy()` will be supported by static graph syntax. - -In another example: - -```python -class InnerClass(nn.Cell): - def construct(self): - return (None, 1) in ((None, 1), 1, 2, 3) - -net = InnerClass() -print(net()) -``` - -```text -True -``` - -`tuple` in `tuple` is an unsupported operation in original graph mode,and will be supported by static graph syntax. - -### Base Type - -Use the JIT Fallback feature to extend support for Python's native data types 'List', 'Dictionary', 'None'. - -#### Supporting List Inplace Modification Operations - -The list 'List' and tuple 'Tuple' are the most basic sequential built-in types in Python, and the core difference between 'List' and 'Tuple' is that 'List' is an object that can be changed, while 'Tuple' cannot be changed. This means that once 'Tuple' is created, it cannot be changed without changing the object address. 'List', on the other hand, can modify an object without changing its address through a series of inplace operations. For example: - -```python -a = [1, 2, 3, 4] -a_id = id(a) -a.append(5) -a_after_id = id(a) -assert a_id == a_after_id -``` - -In the above example code, when you change the 'List' object through the 'append' inplace syntax, the address of the object is not changed. 'Tuple' does not support this kind of inplace. With 'JIT_SYNTAX_LEVEL' set to 'LAX', static graph mode can support the inplace operation of some 'List' objects. - -The specific usage scenarios are as follows: - -- Support for getting the original 'List' object from a global variable - - In the following example, the static graph gets the 'List' object, performs the inplace operation 'list.reverse()' supported by graph mode on the original object, and returns the original object. It can be seen that the object returned by the graph mode has the same ID as the original global variable object, that is, the two are the same object. If 'JIT_SYNTAX_LEVEL' is set to the 'STRICT' option, the returned 'List' object and the global object are two different objects. - - ```python - import mindspore as ms - - global_list = [1, 2, 3, 4] - - @ms.jit - def list_func(): - global_list.reverse() - return global_list - - output = list_func() # output: [4, 3, 2, 1] - assert id(global_list) == id(output) - ``` - -- Inplace operations on input 'List' objects are not supported - - When List' is imported as a static graph, the 'List' object is copied once, and subsequent calculations are performed using the copied object, so it is not possible to perform an inplace operation on the original input object. For example: - - ```python - import mindspore as ms - - list_input = [1, 2, 3, 4] - - @ms.jit - def list_func(x): - x.reverse() - return x - - output = list_func(list_input) # output: [4, 3, 2, 1] list_input: [1, 2, 3, 4] - assert id(output) != id(list_input) - ``` - - As shown in the above use case, the 'List' object cannot be inplaced on the original object when input as a graph mode. The object returned by the graph mode is different from the object ID entered. - -- Support for in-place modification of some 'List' built-in functions - - With 'JIT_SYNTAX_LEVEL' set to 'LAX', the graph mode section 'List' built-in function supports inplace. In cases where 'JIT_SYNTAX_LEVEL' is 'STRICT', none of the methods support the inplace operation. - - Currently, the built-in methods for 'List' in-place modification supported by graph mode are 'extend', 'pop', 'reverse', and 'insert'. The built-in methods 'append', 'clear' and index assignment do not support in-place modification at the moment, and will be supported in subsequent versions. - - Examples are as follows: - - ```python - import mindspore as ms - - list_input = [1, 2, 3, 4] - - @ms.jit - def list_func(): - list_input.reverse() - return list_input - - output = list_func() # output: [4, 3, 2, 1] list_input: [4, 3, 2, 1] - assert id(output) == id(list_input) - ``` - -#### Supporting the High-Level Usage of Dictionary - -- Support Top Graph Return Dictionary - - Examples are as follows: - - ```python - import mindspore as ms - - @ms.jit() - def test_dict(): - x = {'a': 'a', 'b': 'b'} - y = x.get('a') - z = dict(y=y) - return z - - out = test_dict() - print("out:", out) - ``` - - The results are as follows: - - ```text - out:{'y': 'a'} - ``` - -- Support Dictionary Index Value Retrieval and Assignment - - Examples are as follows: - - ```python - import mindspore as ms - import numpy as np - - x = {"a": ms.Tensor(np.array([1, 2, 3])), "b": ms.Tensor(np.array([4, 5, 6])), "c": ms.Tensor(np.array([7, 8, 9]))} - - @ms.jit() - def test_dict(): - y = x["b"] - x["a"] = (2, 3, 4) - return x, y - - out1, out2 = test_dict() - print('out1:{}'.format(out1)) - print('out2:{}'.format(out2)) - ``` - - The results are as follows: - - ```text - out1:{'a': (2, 3, 4), 'b': Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), 'c': Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])} - out2:[4 5 6] - ``` - -#### Supporting the Usage of None - -'None' is a special value in Python that represents null and can be assigned to any variable. Functions that do not have a return value statement are considered to return 'None'. At the same time, 'None' is also supported as the input parameter or return value of the top graph or subgraph. Support 'None' as a subscript of a slice as input to 'List', 'Tuple', 'Dictionary'. - -Examples are as follows: - -```python -import mindspore as ms - -@ms.jit -def test_return_none(): - return 1, "a", None - -res = test_return_none() -print(res) -``` - -The results are as follows: - -```text -(1, 'a', None) -``` - -For functions with no return value, the 'None' object is returned by default. - -```python -import mindspore as ms - -@ms.jit -def foo(): - x = 3 - print("x:", x) - -res = foo() -assert res is None -``` - -As in the example below, 'None' is used as the default input parameter for the top graph. - -```python -import mindspore as ms - -@ms.jit -def foo(x, y=None): - if y is not None: - print("y:", y) - else: - print("y is None") - print("x:", x) - return y - -x = [1, 2] -res = foo(x) -assert res is None -``` - -### Built-in Functions Support More Data Types - -Extend the support for built-in functions. Python built-in functions perfectly support more input types, such as third-party library data types. - -For example, in the following example, 'x.asnumpy()' and 'np.ndarray' are both types supported by extensions. More support for built-in functions can be found in the [Python built-in functions](https://www.mindspore.cn/docs/en/master/note/static_graph_syntax/python_builtin_functions.html) section. - -```python -import numpy as np -import mindspore as ms -import mindspore.nn as nn - -ms.set_context(mode=ms.GRAPH_MODE) - -class Net(nn.Cell): - def construct(self, x): - return isinstance(x.asnumpy(), np.ndarray) - -x = ms.Tensor(np.array([-1, 2, 4])) -net = Net() -out = net(x) -assert out -``` - -### Supporting Control Flow - -In order to improve the support of Python standard syntax, realize dynamic and static unification, and extend the support for more data types in the use of control flow statements. Control flow statements refer to flow control statements such as 'if', 'for', and 'while'. Theoretically, by extending the supported syntax, it is also supported in control flow scenarios. The code use cases are as follows: - -```python -import numpy as np -import mindspore as ms - -@ms.jit -def func(): - x = np.array(1) - if x <= 1: - x += 1 - return ms.Tensor(x) - -res = func() -print("res: ", res) -``` - -The results are as follows: - -```text -res: 2 -``` - -### Supporting Property Setting and Modification - -The specific usage scenarios are as follows: - -- Set and modify properties of custom class objects and third-party types - -In graph mode, you can set and modify the properties of custom class objects, such as: - -```python -from mindspore import jit - -class AssignClass(): - def __init__(self): - self.x = 1 - -obj = AssignClass() - -@jit -def foo(): - obj.x = 100 - return - -foo() -print(f"obj.x is: {obj.x}") -``` - -The result is: - -```text -obj.x is: 100 -``` - -In graph mode, you can set and modify the properties of third-party library objects, such as: - -```python -from mindspore import jit -import numpy as np - -@jit -def foo(): - a = np.array([1, 2, 3, 4]) - a.shape = (2, 2) - return a.shape - -shape = foo() -print(f"shape is {shape}") -``` - -The result is: - -```text -shape is (2, 2) -``` - -- Make changes to the Cell's self object, for example: - - ```python - import mindspore as ms - from mindspore import nn, set_context - set_context(mode=ms.GRAPH_MODE) - - class Net(nn.Cell): - def __init__(self): - super().__init__() - self.m = 2 - - def construct(self): - self.m = 3 - return - - net = Net() - net() - print(f"net.m is {net.m}") - ``` - - The result is: - - ```text - net.m is 3 - ``` - - Note that the self object supports property modification and setting. If no attribute is defined in '__init__', align the PYNATIVE mode, and the graph mode also allows this attribute to be set. For example: - - ```python - import mindspore as ms - from mindspore import nn, set_context - set_context(mode=ms.GRAPH_MODE) - - class Net(nn.Cell): - def __init__(self): - super().__init__() - self.m = 2 - - def construct(self): - self.m2 = 3 - return - - net = Net() - net() - ``` - -- Set and modify Cell objects and jit_class objects in the static graph - - Supporting property modification of objects jit_class graph mode, such as: - - ```python - import mindspore as ms - from mindspore import nn, set_context, jit_class - set_context(mode=ms.GRAPH_MODE) - - @jit_class - class InnerClass(): - def __init__(self): - self.x = 10 - - class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - self.inner = InnerClass() - - def construct(self): - self.inner.x = 100 - return - - net = Net() - net() - print(f"net.inner.x is {net.inner.x}") - ``` - - The result is: - - ```text - net.inner.x is 100 - ``` - -### Supporting Derivation - -The static graph syntax supported by the extension also supports its use in derivation, such as: - -```python -import mindspore as ms -from mindspore import ops, set_context -set_context(mode=ms.GRAPH_MODE) - -@ms.jit -def dict_net(a): - x = {'a': a, 'b': 2} - return a, (x, (1, 2)) - -out = ops.grad(dict_net)(ms.Tensor([1])) -assert out == 2 -``` - -### Annotation Type - -For syntax supported by the runtime extensions, nodes are generated that cannot be derived by type, such as dynamically created Tensors, which are called `Any` types. Because this type cannot be inferred correctly at compile time, the `Any` type will be operated on with a default maximum precision of float64 to prevent loss of precision. In order to better optimize performance, it is necessary to reduce the generation of `Any` type data. When the user can clearly know the specific type that will be generated by the extended syntax, we recommend using Annotation to specify the corresponding Python statement type, thereby determining the type of the interpretation node and avoiding the generation of `Any` type. - -For example, the difference between the [Tensor](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.Tensor.html#mindspore.Tensor) class and the [tensor](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.tensor.html#mindspore.tensor) interface lies in the use of the Annotation Type mechanism within the tensor interface. When the dtype of the tensor function is determined, the function uses Annotation to specify the output type, thereby avoiding the generation of Any type. The use of `Annotation Type` only requires adding a comment `# @jit.typing: () -> tensor_type[float32]` above or after the corresponding Python statement, where tensor_type[float32] after -> indicates the output type of the annotated statement. - -The code example is as follows. - -```python -import mindspore as ms -import mindspore.nn as nn -from mindspore import ops, Tensor - -class Net(nn.Cell): - def __init__(self): - super(Net, self).__init__() - self.abs = ops.Abs() - - @ms.jit - def construct(self, x, y): - y1 = ms.tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) - y2 = ms.Tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) # @jit.typing: () -> tensor_type[float32] - y3 = Tensor(x.asnumpy() + y.asnumpy()) - y4 = Tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) - return self.abs(y1), self.abs(y2), self.abs(y3), self.abs(y4) - -ms.set_context(mode=ms.GRAPH_MODE) -net = Net() -x = ms.Tensor(-1, dtype=ms.int32) -y = ms.Tensor(-1, dtype=ms.float32) -y1, y2, y3, y4 = net(x, y) - -print(f"y1 value is {y1}, dtype is {y1.dtype}") -print(f"y2 value is {y2}, dtype is {y2.dtype}") -print(f"y3 value is {y3}, dtype is {y3.dtype}") -print(f"y4 value is {y4}, dtype is {y4.dtype}") -``` - -```text -y1 value is 2.0, dtype is Float32 -y2 value is 2.0, dtype is Float32 -y3 value is 2.0, dtype is Float64 -y4 value is 2.0, dtype is Float64 -``` - -In the above example, you can see the difference related to creating 'Tensor'. Due to the lack of Annotation indication in the Tensor class, y3 and y4 cannot infer the correct type and can only perform operations in the highest precision float64. -For y2, the corresponding type for JIT Fallback was specified through Annotation during Tensor creation, allowing it to perform operations according to the specified type. -y1 created the Tensor using the tensor function interface and passed the dtype parameter as an Annotation indication, avoiding the generation of `Any` type. - -## Syntax Constraints of Extended Syntaxes - -When using the static graph extension support syntax, note the following points: - -1. In order to match the support capability of the dynamic graph. That is, it must be within the scope of dynamic graph syntax, including but not limited to data types. - -2. When extending the static graph syntax, more syntax is supported, but the execution performance may be affected and is not optimal. - -3. When extending the static graph syntax, more syntax is supported, and the ability to import and export cannot be used with MindIR due to use Python. - -4. It is not currently supported that the repeated definition of global variables with the same name across Python files, and these global variables are used in the network. diff --git a/docs/mindspore/source_en/orange_pi/debug.md b/docs/mindspore/source_en/orange_pi/debug.md new file mode 100644 index 0000000000000000000000000000000000000000..0b9380e7f292924ac81f2cdb5ed5b15fedcf0fc2 --- /dev/null +++ b/docs/mindspore/source_en/orange_pi/debug.md @@ -0,0 +1,3 @@ +# Function Debugging + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/orange_pi/debug.md) diff --git a/docs/mindspore/source_en/orange_pi/index.rst b/docs/mindspore/source_en/orange_pi/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..8e491a8be3c33d6f1c799205c80232fccd35efeb --- /dev/null +++ b/docs/mindspore/source_en/orange_pi/index.rst @@ -0,0 +1,11 @@ +Orange Pi Development +=============================== + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + quick_start + debug + model_infer diff --git a/docs/mindspore/source_en/orange_pi/model_infer.md b/docs/mindspore/source_en/orange_pi/model_infer.md new file mode 100644 index 0000000000000000000000000000000000000000..4cd6654ce95b7a8c3255cdbb2e889ee4c0f9483f --- /dev/null +++ b/docs/mindspore/source_en/orange_pi/model_infer.md @@ -0,0 +1,7 @@ +# Model Inference + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/orange_pi/model_infer.md) + +## Online Inference + +## Offline Inference diff --git a/docs/mindspore/source_en/orange_pi/overview.md b/docs/mindspore/source_en/orange_pi/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..0382094319ce481e87adfcb4f063a94af2405d1e --- /dev/null +++ b/docs/mindspore/source_en/orange_pi/overview.md @@ -0,0 +1,3 @@ +# Orange Pi Overview + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/orange_pi/overview.md) diff --git a/docs/mindspore/source_en/orange_pi/quick_start.md b/docs/mindspore/source_en/orange_pi/quick_start.md new file mode 100644 index 0000000000000000000000000000000000000000..f1ac91db2e46d263f235046a0625241e45baf53d --- /dev/null +++ b/docs/mindspore/source_en/orange_pi/quick_start.md @@ -0,0 +1,9 @@ +# Quick-start + +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/orange_pi/quick_start.md) + +## Installation + +## Startup + +## Running diff --git a/docs/mindspore/source_zh_cn/api_python/index.rst b/docs/mindspore/source_zh_cn/api_python/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..30f3c0d4af0ee57945d59f697e3b11eee147ef0a --- /dev/null +++ b/docs/mindspore/source_zh_cn/api_python/index.rst @@ -0,0 +1,29 @@ +API 文档 +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + mindspore + mindspore.nn + mindspore.ops + mindspore.ops.primitive + mindspore.mint + mindspore.amp + mindspore.train + mindspore.communication + mindspore.communication.comm_func + mindspore.common.initializer + mindspore.hal + mindspore.dataset + mindspore.dataset.transforms + mindspore.mindrecord + mindspore.nn.probability + mindspore.rewrite + mindspore.multiprocessing + mindspore.boost + mindspore.numpy + mindspore.scipy + mindspore.experimental + ../note/env_var_list diff --git a/docs/mindspore/source_zh_cn/conf.py b/docs/mindspore/source_zh_cn/conf.py index fe9936af8cfc7b293d3076259cb7ac0e977da753..45899875a464bb1e97d731b399651d2685c57b93 100644 --- a/docs/mindspore/source_zh_cn/conf.py +++ b/docs/mindspore/source_zh_cn/conf.py @@ -241,11 +241,15 @@ src_dir = os.path.join(repo_path, copy_path) des_sir = "./api_python" def copy_source(sourcedir, des_sir): - if not exists(sourcedir): - logger.warning(f"不存在目录:{sourcedir}!") - if os.path.exists(des_sir): - shutil.rmtree(des_sir) - shutil.copytree(sourcedir, des_sir) + for i in os.listdir(sourcedir): + if os.path.isfile(os.path.join(sourcedir,i)): + if os.path.exists(os.path.join(des_sir, i)): + os.remove(os.path.join(des_sir, i)) + shutil.copy(os.path.join(sourcedir, i), os.path.join(des_sir, i)) + else: + if os.path.exists(os.path.join(des_sir, i)): + shutil.rmtree(os.path.join(des_sir, i)) + shutil.copytree(os.path.join(sourcedir, i), os.path.join(des_sir, i)) copy_source(src_dir, des_sir) @@ -253,6 +257,12 @@ probability_dir = './api_python/probability' if os.path.exists(probability_dir): shutil.rmtree(probability_dir) +if os.path.exists('./model_train/program_form/static_graph_syntax/static_graph_syntax_support.ipynb'): + os.remove('./model_train/program_form/static_graph_syntax/static_graph_syntax_support.ipynb') + +if os.path.exists('./model_train/train_process/model/model.ipynb'): + os.remove('./model_train/train_process/model/model.ipynb') + # 删除并获取ops下多余的接口文件名 white_list = ['mindspore.ops.comm_note.rst'] @@ -549,7 +559,6 @@ release_source = f'[![查看源文件](https://mindspore-website.obs.cn-north-4. with open(src_release, "r", encoding="utf-8") as f: data = f.read() if len(re.findall("\n## (.*?)\n",data)) > 1: - data = re.sub("\n## MindSpore 2.3.0 [\s\S\n]*?\n## ", "\n## ", data) content = regex.findall("(\n## MindSpore [^L][\s\S\n]*?)\n## ", data, overlapped=True) repo_version = re.findall("\n## MindSpore ([0-9]+?\.[0-9]+?)\.([0-9]+?)[ -]", content[0])[0] content_new = '' diff --git a/docs/mindspore/source_zh_cn/design/distributed_training_design.ipynb b/docs/mindspore/source_zh_cn/design/distributed_training_design.ipynb index bcf08739740bb65f19654f396229924fd6122c95..97a4150544f92c1b7c273f1e872ec317ae7fadfb 100644 --- a/docs/mindspore/source_zh_cn/design/distributed_training_design.ipynb +++ b/docs/mindspore/source_zh_cn/design/distributed_training_design.ipynb @@ -100,9 +100,9 @@ "\n", " 半自动并行支持多种并行模式的自动混合使用,分别有:\n", "\n", - " **算子级并行**:算子级并行以神经网络中的算子为单位,将输入张量切分到多个设备上进行计算。通过这种方式,可以实现数据样本和模型参数在不同设备之间的分配,从而训练大规模的深度学习模型,并利用集群资源进行并行计算,提高整体速度。用户可以设置每个算子的切分策略,框架会根据算子的切分策略对每个算子及其输入张量进行切分建模,以保持数学等价性。这种方法可以有效地减少单个设备的负载,提高计算效率,适用于大规模深度神经网络的训练。详情参考:[算子级并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/operator_parallel.html)\n", + " **算子级并行**:算子级并行以神经网络中的算子为单位,将输入张量切分到多个设备上进行计算。通过这种方式,可以实现数据样本和模型参数在不同设备之间的分配,从而训练大规模的深度学习模型,并利用集群资源进行并行计算,提高整体速度。用户可以设置每个算子的切分策略,框架会根据算子的切分策略对每个算子及其输入张量进行切分建模,以保持数学等价性。这种方法可以有效地减少单个设备的负载,提高计算效率,适用于大规模深度神经网络的训练。详情参考:[算子级并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/operator_parallel.html)\n", "\n", - " **流水线并行**:当集群设备数很多时,如果仅采用算子级并行的方式,则需要在整个集群的通信域上进行通信,这可能使得通信效率低,从而降低整体性能。而流水线并行能将神经网络结构切分成多个stage,每个stage跑在一部分设备内,将集合通信的通信域限定在这部分设备范围内,而stage间采用点对点通信。流水线并行的优点在于:能提升通信效率、能方便的处理按层堆叠的神经网络结构。缺点在于:同一时刻内,有些节点可能处于空闲状态。详情参考:[流水线并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/pipeline_parallel.html)\n", + " **流水线并行**:当集群设备数很多时,如果仅采用算子级并行的方式,则需要在整个集群的通信域上进行通信,这可能使得通信效率低,从而降低整体性能。而流水线并行能将神经网络结构切分成多个stage,每个stage跑在一部分设备内,将集合通信的通信域限定在这部分设备范围内,而stage间采用点对点通信。流水线并行的优点在于:能提升通信效率、能方便的处理按层堆叠的神经网络结构。缺点在于:同一时刻内,有些节点可能处于空闲状态。详情参考:[流水线并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/pipeline_parallel.html)\n", "\n", " **MoE并行**:MoE是将专家分布到不同的worker上,并且每个worker承担不同批次的训练数据。对于非MoE层来说,专家并行和数据并行一样。在MoE层中,序列中的token通过all-to-all通信被发送到它们相匹配的专家所对应的worker。在完成对应专家的计算后,再通过all-to-all重新传回到原来的worker,组织成原始序列,用于下一层的计算。由于MoE模型通常有大量的专家,专家并行度比模型并行度更能随模型规模的增大而增大。\n", "\n", @@ -112,7 +112,7 @@ "\n", " ![多副本并行](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/design/images/multi_copy.png)\n", "\n", - " **优化器并行**:在数据并行或算子级并行训练时,模型的参数可能在多个设备上存在同一份副本。这使得优化器在更新该权重之时,在多个设备间存在冗余计算。在此情况下,可以通过优化器并行将优化器的计算量分散到多个设备上。它的优点在于:能减少静态内存消耗、减少优化器内的计算量。缺点在于:增加了通信开销。详情参考:[优化器并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/optimizer_parallel.html)\n", + " **优化器并行**:在数据并行或算子级并行训练时,模型的参数可能在多个设备上存在同一份副本。这使得优化器在更新该权重之时,在多个设备间存在冗余计算。在此情况下,可以通过优化器并行将优化器的计算量分散到多个设备上。它的优点在于:能减少静态内存消耗、减少优化器内的计算量。缺点在于:增加了通信开销。详情参考:[优化器并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/optimizer_parallel.html)\n", "\n", "### 半自动并行代码\n", "\n", @@ -149,11 +149,11 @@ "\n", "全自动并行的实现难度非常大,MindSpore根据需要用户介入的程度,将提供的策略生成算法分成了L1级别和L2级别(此处我们假设手工配置全图策略SEMI_AUTO为L0级别,完全不需要用户参与的方案为L3级别)。\n", "\n", - "L1级别的策略生成算法叫做策略广播(Sharding Propagation),在该种模式下,用户仅需要手工定义几个关键算子的策略,计算图中其余算子的策略由算法自动生成。因为关键算子的策略已被定义,该算法的代价模型主要描述的算子之间的重排布代价(Redistribution Cost),优化目标为全图重排代价最小。因为已经定义了主要算子策略,相当于认为压缩了搜索空间,这种方案的搜索时间较短,其策略性能依赖于关键算子策略的定义,因此仍然要求用户具备分析定义策略的能力。详情参考:[切分策略传播](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/sharding_propagation.html)\n", + "L1级别的策略生成算法叫做策略广播(Sharding Propagation),在该种模式下,用户仅需要手工定义几个关键算子的策略,计算图中其余算子的策略由算法自动生成。因为关键算子的策略已被定义,该算法的代价模型主要描述的算子之间的重排布代价(Redistribution Cost),优化目标为全图重排代价最小。因为已经定义了主要算子策略,相当于认为压缩了搜索空间,这种方案的搜索时间较短,其策略性能依赖于关键算子策略的定义,因此仍然要求用户具备分析定义策略的能力。详情参考:[切分策略传播](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/sharding_propagation.html)\n", "\n", "L2级别的策略生成算法有两种,分别是动态规划算法(Dynamic Programming)和符号化自动策略生成(Symbolic Automatic Parallel Planner 缩写SAPP)。两种方法各有优劣,动态规划算法能够搜索出代价模型刻画的最优策略,但是在搜索巨大网络的并行策略时耗时较长。而SAPP算法能够对于巨大网络以及大规模切分瞬间生成最优策略。\n", "动态规划算法的核心思路是建立全图的代价模型,包括计算代价和通信代价,来描述分布式训练过程中的绝对时延,使用边消除和点消除等等价方法压缩搜索时间,但是搜索空间随着设备数和算子数的增加实际上是指数级增长的,因此对于大模型大集群来说效率不高。\n", - "SAPP基于并行原理建模,通过建立抽象机来描述硬件集群拓扑,通过符号化简优化代价模型。其代价模型比较的不是预估的绝对时延,而是不同并行策略的相对代价,因此能够大大压缩搜索空间,对于百卡集群能够保证分钟级的搜索时间。详情参考:[分布式并行总览](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/overview.html)\n", + "SAPP基于并行原理建模,通过建立抽象机来描述硬件集群拓扑,通过符号化简优化代价模型。其代价模型比较的不是预估的绝对时延,而是不同并行策略的相对代价,因此能够大大压缩搜索空间,对于百卡集群能够保证分钟级的搜索时间。详情参考:[分布式并行总览](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/overview.html)\n", "\n", "Sharding Propagation和SAPP目前支持手工定义Pipeline+自动算子级并行,且可与重计算、优化器并行等优化共同使用。Dynamic Programming算法仅支持算子级自动并行。\n", "\n", @@ -463,7 +463,7 @@ "\n", "![heterogeneous-heter-ps](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/design/images/heter-ps.png)\n", "\n", - "Parameter Server封装异构流程,用户只需配置参数使用PS即可,具体配置流程请参考[Parameter Server训练流程](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/parameter_server_training.html)。\n", + "Parameter Server封装异构流程,用户只需配置参数使用PS即可,具体配置流程请参考[Parameter Server训练流程](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/parameter_server_training.html)。\n", "\n", "此外,wide&deep网络中也有使用PS的流程,可参考:\n", "\n", diff --git a/docs/mindspore/source_zh_cn/design/dynamic_graph_and_static_graph.ipynb b/docs/mindspore/source_zh_cn/design/dynamic_graph_and_static_graph.ipynb index d66b99eb4fe1454074f4da76f23c24376a150d14..1dcc5ce01eedbc68a944575df49cb8a6b43da00b 100644 --- a/docs/mindspore/source_zh_cn/design/dynamic_graph_and_static_graph.ipynb +++ b/docs/mindspore/source_zh_cn/design/dynamic_graph_and_static_graph.ipynb @@ -243,233 +243,6 @@ "### PyNative模式下的控制流\n", "\n", "在PyNative模式下,脚本按照Python的语法执行,因此在MindSpore中,针对控制流语法并没有做特殊处理,直接按照Python的语法直接展开执行,进而对展开的执行算子进行自动微分的操作。例如,对于for循环,在PyNative下会根据具体的循环次数,不断的执行for循环中的语句,并对其算子进行自动微分的操作。\n", - "\n", - "## 动静统一\n", - "\n", - "### 概述\n", - "\n", - "当前在业界支持动态图和静态图两种模式,动态图通过解释执行,具有动态语法亲和性,表达灵活;静态图使用jit编译优化执行,偏静态语法,在语法上有较多限制。动态图和静态图的编译流程不一致,语法约束不一致。MindSpore针对动态图和静态图模式,首先统一API表达,在两种模式下使用相同的API;其次统一动态图和静态图的底层微分机制。\n", - "\n", - "![dynamic](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/design/images/dynamic.png)\n", - "\n", - "### 动态图和静态图互相转换\n", - "\n", - "在MindSpore中,我们可以通过控制模式输入参数来切换执行使用动态图还是静态图。例如:" - ], - "metadata": {} - }, - { - "cell_type": "code", - "execution_count": 5, - "source": [ - "ms.set_context(mode=ms.PYNATIVE_MODE)" - ], - "outputs": [], - "metadata": { - "ExecuteTime": { - "end_time": "2022-01-04T10:51:23.461198Z", - "start_time": "2022-01-04T10:51:23.447508Z" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "由于在静态图下,对于Python语法有所限制,因此从动态图切换成静态图时,需要符合静态图的语法限制,才能正确使用静态图来进行执行。更多静态图的语法限制可以参考[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)。\n", - "\n", - "### 动静结合\n", - "\n", - "MindSpore支持在动态图下使用静态编译的方式来进行混合执行,通过使用jit修饰需要用静态图来执行的函数对象,即可实现动态图和静态图的混合执行,更多jit的使用可参考[jit文档](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/accelerate_with_static_graph.html#基于装饰器的开启方式)。\n", - "\n", - "例如:" - ], - "metadata": {} - }, - { - "cell_type": "code", - "execution_count": 6, - "source": [ - "import numpy as np\n", - "import mindspore as ms\n", - "import mindspore.nn as nn\n", - "\n", - "class AddMulMul(nn.Cell):\n", - " def __init__(self):\n", - " super(AddMulMul, self).__init__()\n", - " self.param = ms.Parameter(ms.Tensor(0.5, ms.float32))\n", - "\n", - " @ms.jit\n", - " def construct(self, x):\n", - " x = x + x\n", - " x = x * self.param\n", - " x = x * x\n", - " return x\n", - "\n", - "class CellCallSingleCell(nn.Cell):\n", - " def __init__(self):\n", - " super(CellCallSingleCell, self).__init__()\n", - " self.conv = nn.Conv2d(1, 2, kernel_size=2, stride=1, padding=0, weight_init=\"ones\", pad_mode=\"valid\")\n", - " self.bn = nn.BatchNorm2d(2, momentum=0.99, eps=0.00001, gamma_init=\"ones\")\n", - " self.relu = nn.ReLU()\n", - " self.add_mul_mul = AddMulMul()\n", - "\n", - " def construct(self, x):\n", - " x = self.conv(x)\n", - " x = self.bn(x)\n", - " x = self.add_mul_mul(x)\n", - " x = self.relu(x)\n", - " return x\n", - "\n", - "ms.set_context(mode=ms.PYNATIVE_MODE, device_target=\"CPU\")\n", - "inputs = ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32))\n", - "net = CellCallSingleCell()\n", - "out = net(inputs)\n", - "print(out)" - ], - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[[[[15.99984]]\n", - "\n", - " [[15.99984]]]]\n" - ] - } - ], - "metadata": { - "ExecuteTime": { - "end_time": "2022-01-04T10:51:23.514919Z", - "start_time": "2022-01-04T10:51:23.462207Z" - } - } - }, - { - "cell_type": "markdown", - "source": [ - "### 静态图语法增强技术\n", - "\n", - "在MindSpore静态图模式下,用户编写程序时需要遵循MindSpore[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html),语法使用存在约束限制。而在动态图模式下,Python脚本代码会根据Python语法进行执行,用户可以使用任意Python语法。可以看出,静态图和动态图的语法约束限制是不同的。\n", - "\n", - "JIT Fallback是从静态图的角度出发考虑静态图和动态图的统一。在编译过程中发现不支持的语法时,将该语法Fallback到Python解释器进行解释执行。通过JIT Fallback特性,静态图可以支持尽量多的动态图语法,使得静态图提供接近动态图的语法使用体验,从而实现动静统一。\n", - "\n", - "在图模式场景下,MindSpore框架在图编译过程中遇到不支持语法或不支持符号时会报错,多数是在类型推导阶段。图编译阶段首先对用户编写的Python源码进行解析,然后执行后续的静态分析、类型推导、优化等步骤。因此,JIT Fallback特性需要预先检测不支持语法。常见的不支持语法主要包括:调用第三方库的方法、调用类名来创建对象、调用未支持的Python内置函数等。对不支持的语法Fallback到Python解释器进行解释执行。由于图模式采用[中间表示MindIR](https://www.mindspore.cn/docs/zh-CN/master/design/all_scenarios.html#中间表示mindir),需要将解释执行的语句转换到中间表示,记录下解释器需要的信息。\n", - "\n", - "下面主要介绍使用JIT Fallback扩展支持的静态图语法。JIT语法支持级别选项jit_syntax_level的默认值为`LAX`,即使用JIT Fallback的能力扩展静态图语法。\n", - "\n", - "#### 调用第三方库\n", - "\n", - "完善支持NumPy、SciPy等第三方库。静态图模式支持np.ndarray等众多第三方库数据类型及其运算操作,支持获取调用第三方库的属性和方法,并支持通过Tensor的asnumpy()等方法与NumPy等三方库进行交互处理。也就是说,用户可以在静态图模式下调用MindSpore自身接口和算子,或者直接调用三方库的接口,也可以把它们融合在一起使用。\n", - "\n", - "- 支持第三方库(如NumPy、SciPy等)的数据类型,允许调用和返回第三方库的对象。\n", - "- 支持调用第三方库的方法。\n", - "- 支持使用NumPy第三方库数据类型创建Tensor对象。\n", - "- 暂不支持对第三方库数据类型的下标索引赋值。\n", - "\n", - "更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[调用第三方库](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#调用第三方库)。\n", - "\n", - "#### 支持自定义类的使用\n", - "\n", - "用户自定义的类,没有使用`@jit_class`修饰,也没有继承`nn.Cell`。通过JIT Fallback技术方案,静态图模式下允许创建和引用自定义类的实例,可以支持直接获取和调用自定义类实例的属性和方法,并且允许修改属性(Inplace操作)。\n", - "\n", - "更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[支持自定义类的使用](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#支持自定义类的使用)。\n", - "\n", - "#### 基础运算符支持更多数据类型\n", - "\n", - "在静态图语法重载了以下运算符: ['+', '-', '*', '/', '//', '%', '**', '<<', '>>', '&', '|', '^', 'not', '==', '!=', '<', '>', '<=', '>=', 'in', 'not in', 'y=x[0]']。图模式重载的运算符详见[运算符](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/operators.html)。列表中的运算符在输入图模式中不支持的输入类型时将使用扩展静态图语法支持,并使输出结果与动态图模式下的输出结果一致。\n", - "\n", - "更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[基础运算符支持更多数据类型](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#基础运算符支持更多数据类型)。\n", - "\n", - "#### 基础类型\n", - "\n", - "扩展对Python原生数据类型`List`、`Dictionary`、`None`的支持。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[基础类型](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#基础类型)。\n", - "\n", - "##### 支持列表就地修改操作\n", - "\n", - "- 支持从全局变量中获取原`List`对象。\n", - "- 不支持对输入`List`对象进行inplace操作。\n", - "- 支持部分`List`内置函数的就地修改操作。\n", - "\n", - "##### 支持Dictionary的高阶用法\n", - "\n", - "- 支持顶图返回Dictionary。\n", - "- 支持Dictionary索引取值和赋值。\n", - "\n", - "##### 支持使用None\n", - "\n", - "`None`是Python中的一个特殊值,表示空,可以赋值给任何变量。对于没有返回值语句的函数认为返回`None`。同时也支持`None`作为顶图或者子图的入参或者返回值。支持`None`作为切片的下标,作为`List`、`Tuple`、`Dictionary`的输入。\n", - "\n", - "#### 内置函数支持更多数据类型\n", - "\n", - "扩展内置函数的支持范围。Python内置函数完善支持更多输入类型,例如第三方库数据类型。更多内置函数的支持情况可见[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/python_builtin_functions.html)章节。\n", - "\n", - "#### 支持控制流\n", - "\n", - "为了提高Python标准语法支持度,实现动静统一,扩展支持更多数据类型在控制流语句的使用。控制流语句是指`if`、`for`、`while`等流程控制语句。理论上,通过扩展支持的语法,在控制流场景中也支持。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[支持控制流](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#支持控制流)。\n", - "\n", - "#### 支持属性设置与修改\n", - "\n", - "支持更多类型的Inplace操作。之前版本只支持通过Inplace算子对Parameter类型进行值修改,在MindSpore2.1版本静态图模式下,支持了自定义类,Cell子类,jit_class类的属性修改。除了支持更改类self属性和全局变量的属性以外,也新增支持对List类型的extend()、reverse()、insert()、pop()等Inplace操作。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[支持属性设置与修改](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#支持属性设置与修改)。\n", - "\n", - "- 对自定义类对象以及第三方类型的属性进行设置与修改。\n", - "- 对Cell的self对象进行修改。\n", - "- 对静态图内的Cell对象以及jit_class对象进行设置与修改。\n", - "\n", - "#### 支持求导\n", - "\n", - "使用JIT Fallback支持的静态图语法,同样支持其在求导中使用。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[支持求导](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#支持求导)。\n", - "\n", - "#### Annotation Type\n", - "\n", - "对于运行时的JIT Fallback支持的语法,会产生一些无法被类型推导出的节点,这种类型称为`Any`类型。因为该类型无法在编译时推导出正确的类型,所以这种`Any`将会以一种默认最大精度`float64`进行运算,防止其精度丢失。为了能更好的优化相关性能,需要减少`Any`类型数据的产生。当用户可以明确知道当前通过扩展支持的语句会产生具体类型的时候,我们推荐使用`Annotation @jit.typing:`的方式进行指定对应Python语句类型,从而确定解释节点的类型避免`Any`类型的生成。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)中的[Annotation Type](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#annotation-type)。\n", - "\n", - "#### 使用须知\n", - "\n", - "在使用静态图JIT Fallback扩展支持语法时,请注意以下几点:\n", - "\n", - "1. 对标动态图的支持能力,即:须在动态图语法范围内,包括但不限于数据类型等。\n", - "\n", - "2. 在扩展静态图语法时,支持了更多的语法,但执行性能可能会受影响,不是最佳。\n", - "\n", - "3. 在扩展静态图语法时,支持了更多的语法,由于使用Python的能力,不能使用MindIR导入导出的能力。\n", - "\n", - "4. 暂不支持跨Python文件重复定义同名的全局变量,且这些全局变量在网络中会被用到。" - ], - "metadata": {}, - "attachments": {} - }, - { - "cell_type": "markdown", - "source": [ - "### 动态图转静态图技术\n", - "\n", - "MindSpore提供了一种在代码无需修改的情况下,直接将用户的动态图代码转换成静态图的功能——PIJit。该功能同时兼顾性能和易用性,去除动静模式切换的代价,真正做到动静统一。它基于Python字节码的分析,对Python的执行流进行图捕获,可以以静态图方式运行的子图便以静态图方式运行,Python语法不支持的子图便以动态图方式运行,同时通过修改调整字节码的方式链接静态图,达到动静混合执行。在满足易用性的前提下,尽可能地提高性能。\n", - "\n", - "#### PIJit包含以下功能\n", - "\n", - "- 1. 图捕获:对字节码预处理,动态跟踪解释执行,识别MindSpore可入图操作,提供裂图功能保证函数(字节码)功能的正确性。\n", - "- 2. 字节码支持:当前支持Python3.7、Python3.8、Python3.9和Python3.10的字节码。\n", - "- 3. 图优化:对图中生成的字节码进行优化,包括分支裁剪、字节码筛选、函数字节码内联、常量折叠等功能。\n", - "- 4. 异常捕获机制:支持with、try-except语法。\n", - "- 5. 支持循环处理:通过模拟字节码的操作栈实现图捕获、裂图等特性。\n", - "- 6. UD分析:通过变量的user-def链分析的方法,解决部分参数类型不能作为静态图的返回值问题(函数、Bool、None),同时减少无用的入参,提高图的执行效率,减少数据的拷贝。\n", - "- 7. 副作用分析处理:弥补静态图的副作用处理上的劣势,根据不同场景,收集记录产生副作用的变量及字节码,在保证程序语义的基础上,在静态图外补充副作用的处理。\n", - "- 8. 守护门禁:门禁(Guard)记录了子图/优化进入的输入需要满足的条件,检查输入是否适合对应的子图优化。\n", - "- 9. Cache:图管理(Cache)则缓存了子图/优化和门禁(Guard)对应关系。\n", - "- 10. Dynamic Shape和Symbolic Shape: 使用input_signature支持Tensor/Tensor List/Tensor Tuple的DynamicShape和SymblicShape作为输入提示。同时支持自动多次运行后,识别Dynamic Shape。\n", - "- 11. 即时跟踪编译: 在跟踪和字节码分析过程中,支持算子等类型推导。\n", - "- 12. 自动混合精度: 支持原生mindspore.nn.Cell的自动混合精度能力。\n", - "\n", - "#### 使用方式\n", - "\n", - "def jit(fn=None, input_signature=None, hash_args=None, jit_config=None, mode=\"PIJit\"):\n", - "\n", - "原Jit功能使用mode=\"PSJit\",新特性PIJit使用mode=\"PIJit\",jit_config传递一个参数字典,可以提供一些优化和调试选项。如:print_after_all可以打印入图的字节码和裂图信息,loop_unrolling可以提供循环展开功能,enable_dynamic_shape使能动态Shape。\n", - "\n", - "#### 使用限制\n", - "\n", - "- 不支持在静态图模式下,运行带装饰@jit(mode=\\\"PIJit\\\")的函数,此时该装饰@jit(mode=\\\"PIJit\\\")视为无效。\n", - "- 不支持在@jit(mode=\\\"PSJit\\\")装饰的函数内部调用带装饰@jit(mode=\\\"PIJit\\\")的函数,该装饰 @jit(mode=\\\"PIJit\\\")视为无效。\n", "\n" ], "metadata": {} diff --git a/docs/mindspore/source_zh_cn/design/dynamic_shape.md b/docs/mindspore/source_zh_cn/design/dynamic_shape.md deleted file mode 100644 index 41f0af158d0f261d9365d499440cae02fce41c70..0000000000000000000000000000000000000000 --- a/docs/mindspore/source_zh_cn/design/dynamic_shape.md +++ /dev/null @@ -1,71 +0,0 @@ -# 静态图动态shape - -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/design/dynamic_shape.md) - -## 背景介绍 - -动态shape是深度学习框架领域较为常见的一个研究课题,MindSpore针对动态shape也做了大量的探索与研究,并且基于研究成果初步支持了静态图模式下的动态shape能力。 - -本文主要针对MindSpore静态图动态shape作说明介绍,后文中动态shape均泛指静态图动态shape。 -动态shape需要解决的核心问题是输入数据尺寸变化时,如何做到一次编译多次执行。通过静态shape处理多尺寸数据与通过动态shape处理多尺寸数据的流程对比示意图如下: - -![image](./images/dynamic_shape/static_dynamic_shape_diff.png) - -如上图所示,当输入多种尺寸的数据时,静态shape会对每一种输入尺寸都进行一次编译,而动态shape只需要编译一次,因此动态shape相比静态shape节省了大量的编译耗时,因此能提升网络端到端执行性能。 - -## 符号引擎设计 - -虽然动态shape弥补了静态shape多次编译的不足,但是也带来了执行性能下降、无法进行并行切分、无法进行内存复用优化等新的挑战。MindSpore通过支持符号引擎能力,继承了静态shape -场景下的大部分并行切分能力和算子融合能力,并通过虚拟内存实现了内存的深度优化,实现动态shape执行性能和内存效率达到静态shape的90%左右。 - -动态shape通过符号shape来表达shape,例如存在两组输入数据为Tensor(shape=(8, 10))和Tensor(shape=(8, 100)),使用静态shape多次编译会产生Tensor(shape=(8, 10)) -和Tensor(shape=(8, 100))两种IR,动态shape产生Tensor(shape=(8, Any))一种IR,Any表示axis为动态,通过符号引擎shape可进一步将动态shape IR表示 -为Tensor(shape=(8, 10*s1))。符号shape通过符号运算来表达shape的推导过程,以实现在动态shape场景下用符号判断代替数值判断的能力。一次基于符号引擎推导动态shape的IR -的示例如下: - -![image](./images/dynamic_shape/symbol_engine.png) - -如图,符号引擎将输入结点的shape标记为`s1`, `s2`等,在算子shape推导时,将输出shape存为基于输入shape的表达式。例如:对于`40Mul`结点,它的输出shape不再是Any,而是`max(s1,s2)`;到`104BatchMatMul`结点,基于矩阵乘的约束,可以直接设定`s4 == s6`;对于`112Add`结点,因为`s5`和`s7`都是大于1的值,可以断定此结点不存在广播场景,从而判断出`s5`与`s7`相等。通过符号shape引擎,动态shape也具备了一定的shape判断能力,框架可以在此基础上完成更多计算图优化功能。 - -符号引擎的详细使用指导可参考[Symbol API文档](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.Symbol.html)。 - -## 使用方法 - -MindSpore通过set_inputs接口设置静态图输入Tensor对应的axis为动态,使能网络动态shape编译。 -例如,对两个矩阵进行相加,矩阵的大小变化的,此时我们希望矩阵相加对应的计算逻辑只编译一次,输入不同尺寸的矩阵进行计算时可以复用同一次编译过程。 -设置动态shape编译,如何指定对应axis为动态,可以使用符号引擎和set_inputs接口进行设置,mindspore.jit装饰器方式请使用input_signature参数进行设置。 -下述样例是一个通过动态shape实现多个不同尺寸的矩阵自身相加的示例: - -```python -import numpy as np -import mindspore as ms -from mindspore import nn, Tensor, Symbol - -class Net(nn.Cell): - def construct(self, x): - return x + x - -ms.context.set_context(mode=ms.context.GRAPH_MODE) -net = Net() -width = Symbol() -height = Symbol() -dyn_t = Tensor(shape=(width, height), dtype=ms.float32) -# Set Tensor shape dynamic -net.set_inputs(dyn_t) -# Execute with shape=(2 ,3) -input_x1 = Tensor(np.random.randn(2, 3), dtype=ms.float32) -out = net(input_x1) -# Execute with shape=(4, 5) -input_x2 = Tensor(np.random.randn(4, 5), dtype=ms.float32) -out = net(input_x2) -``` - -set_inputs详细使用指导可参考[Cell.set_inputs API文档](https://www.mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.set_inputs)。 - -input_signature详细使用指导可参考[mindspore.jit API文档](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.jit.html)。 - -分布式并行场景如何使用动态shape可参考[分布式并行支持动态shape文档](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/support_dynamic_shape_in_parallel.html)。 - -## 支持情况 - -MindSpore在当前版本仅有部分API可以支持动态shape编译执行,正在持续完善全量API的支持能力,当前阶段[mindspore.mint](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.mint.html)接口支持动态shape。 diff --git a/docs/mindspore/source_zh_cn/design/index.rst b/docs/mindspore/source_zh_cn/design/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..29601b70db3160a8b4598015a09486c56604503b --- /dev/null +++ b/docs/mindspore/source_zh_cn/design/index.rst @@ -0,0 +1,18 @@ +设计理念 +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + tensor_view + programming_paradigm + dynamic_graph_and_static_graph + distributed_training_design + data_engine + all_scenarios + graph_fusion_engine + pluggable_device + official_models + glossary \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/note/official_models.md b/docs/mindspore/source_zh_cn/design/official_models.md similarity index 99% rename from docs/mindspore/source_zh_cn/note/official_models.md rename to docs/mindspore/source_zh_cn/design/official_models.md index 7d899f33633009ac36bdc609944aebb9b5af93b0..95f1f99bf85440f227d6c198442cd190d9823d46 100644 --- a/docs/mindspore/source_zh_cn/note/official_models.md +++ b/docs/mindspore/source_zh_cn/design/official_models.md @@ -1,6 +1,6 @@ # 官方模型库 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/official_models.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/design/official_models.md) ## 领域套件与扩展包 @@ -334,4 +334,4 @@ | 计算流体 | [PDE-Net](https://arxiv.org/abs/1710.09668) | [Link](https://gitee.com/mindspore/mindscience/blob/master/MindFlow/applications/data_mechanism_fusion/pde_net/README_CN.md#) | ✅ | ✅ | | 计算流体 | [hfm](https://www.science.org/doi/abs/10.1126/science.aaw4741) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/hfm/README_CN.md) | ✅ | ✅ | | 计算流体 | [label_free_dnn_surrogate](https://www.sciencedirect.com/science/article/pii/S004578251930622X) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/label_free_dnn_surrogate/README_CN.md) | ✅ | ✅ | -| 计算流体 | [nsf_nets](https://www.sciencedirect.com/science/article/pii/S0021999120307257) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/nsf_nets/README_CN.md) | ✅ | ✅ | +| 计算流体 | [nsf_nets](https://www.sciencedirect.com/science/article/pii/S0021999120307257) | [Link](https://gitee.com/mindspore/mindscience/blob/master/SciAI/sciai/model/nsf_nets/README_CN.md) | ✅ | ✅ | \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/faq/data_processing.md b/docs/mindspore/source_zh_cn/faq/data_processing.md index 8b6bfd5aa4c4215f3abe6dfe33c9e64db6d48d40..44b37ae43cb5be9210394830b53afe910abceff9 100644 --- a/docs/mindspore/source_zh_cn/faq/data_processing.md +++ b/docs/mindspore/source_zh_cn/faq/data_processing.md @@ -38,7 +38,7 @@ A: 可以参考如下几个步骤来降低CPU占用,进一步提升性能, ## Q: 在`GeneratorDataset`中,看到有参数`shuffle`,在跑任务时发现`shuffle=True`和`shuffle=False`,两者没有区别,这是为什么? -A: 开启`shuffle`,需要传入的`Dataset`是支持随机访问的(例如自定义的`Dataset`有`getitem`方法),如果是在自定义的`Dataset`里面通过`yeild`方式返回回来的数据,是不支持随机访问的,具体可查看教程中的[自定义数据集](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/dataset.html#自定义数据集)章节。 +A: 开启`shuffle`,需要传入的`Dataset`是支持随机访问的(例如自定义的`Dataset`有`getitem`方法),如果是在自定义的`Dataset`里面通过`yeild`方式返回回来的数据,是不支持随机访问的,具体可查看[GeneratorDataset 示例](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html)章节。
    @@ -160,9 +160,7 @@ A: 你可以参考yolov3对于此场景的使用,里面有对于图像的不 A: [build_seg_data.py](https://gitee.com/mindspore/models/blob/master/research/cv/FCN8s/src/data/build_seg_data.py)是将数据集生成MindRecord的脚本,可以直接使用/适配下你的数据集。或者如果你想尝试自己实现数据集的读取,可以使用`GeneratorDataset`自定义数据集加载。 -[GenratorDataset 示例](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/dataset.html#自定义数据集) - -[GenratorDataset API说明](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html#mindspore.dataset.GeneratorDataset) +[GeneratorDataset 示例](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html)
    @@ -191,7 +189,7 @@ ds.GeneratorDataset(..., num_shards=8, shard_id=7, ...) A: 数据Schema可以按如下方式定义: `cv_schema_json = {"label": {"type": "int32", "shape": [-1]}, "data": {"type": "bytes"}}` 说明: label是一个数组,numpy类型,这里面可以存 1,1,0,1,0,1 这么多label值,这些label值对应同一个data,即: 同一个图像的二进制值。 -可以参考[将数据集转换为MindRecord](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset/record.html#转换成record格式)教程。 +可以参考[将数据集转换为MindRecord](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/record.html#转换成record格式)教程。
    @@ -203,7 +201,7 @@ A: 首先MindSpore训练使用的灰度图MNIST数据集。所以模型使用时 ## Q: MindSpore设计了专门用于数据处理的框架,有相关的设计和用法介绍? -A: MindSpore Dataset模块使得用户很简便地定义数据预处理Pipeline,并以高效(多进程/多线程)的方式处理数据集中样本,同时MindSpore Dataset也提供了多样化的API加载和处理数据集,详细介绍请参阅[数据处理Pipeline介绍](https://mindspore.cn/docs/zh-CN/master/api_python/mindspore.dataset.html#%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86pipeline%E4%BB%8B%E7%BB%8D)。如果想进一步对数据处理Pipeline进行性能调优,请参阅[数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html)。 +A: MindSpore Dataset模块使得用户很简便地定义数据预处理Pipeline,并以高效(多进程/多线程)的方式处理数据集中样本,同时MindSpore Dataset也提供了多样化的API加载和处理数据集,详细介绍请参阅[数据处理Pipeline介绍](https://mindspore.cn/docs/zh-CN/master/api_python/mindspore.dataset.html#%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86pipeline%E4%BB%8B%E7%BB%8D)。如果想进一步对数据处理Pipeline进行性能调优,请参阅[数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html)。
    @@ -315,7 +313,7 @@ dataset3 = dataset2.map(***) ## Q: MindSpore中和DataLoader对应的接口是什么? -A:如果将DataLoader考虑为接收自定义Dataset的API接口,MindSpore数据处理API中和Dataloader较为相似的是GeneratorDataset,可接收用户自定义的Dataset,具体使用方式参考[GeneratorDataset 文档](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/dataset.html#自定义数据集),差异对比也可查看[API算子映射表](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html)。 +A:如果将DataLoader考虑为接收自定义Dataset的API接口,MindSpore数据处理API中和Dataloader较为相似的是GeneratorDataset,可接收用户自定义的Dataset,具体使用方式参考[GeneratorDataset 示例](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html),差异对比也可查看[API算子映射表](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html)。
    @@ -497,7 +495,7 @@ A: 在使用数据下沉模式(此时 `数据预处理` -> `发送队列` -> ` 2022-05-09-11:36:01.893.412 -> 2022-05-09-11:36:02.006.771 ``` - 改进方法:查看最后一条 `push_end_time` 时间与GetNext报错时间,如果超过默认GetNext超时时间(默认:1900s,且可通过 `mindspore.set_context(op_timeout=xx)` 来进行修改),说明数据预处理性能差,可参考 [数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html) 对数据预处理部分进行优化。 + 改进方法:查看最后一条 `push_end_time` 时间与GetNext报错时间,如果超过默认GetNext超时时间(默认:1900s,且可通过 `mindspore.set_context(op_timeout=xx)` 来进行修改),说明数据预处理性能差,可参考 [数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html) 对数据预处理部分进行优化。 4. 当日志输出类似如下时,表示数据预处理产生了182条数据,正在向设备发送第183条数据,并且 `device_queue` 显示设备侧有充足的数据缓存。 @@ -547,7 +545,7 @@ A: 在使用数据下沉模式(此时 `数据预处理` -> `发送队列` -> ` 2022-05-09-14:31:04.064.571 -> ``` - 改进方法:可参考 [数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html) 对数据预处理部分进行优化。 + 改进方法:可参考 [数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html) 对数据预处理部分进行优化。
    diff --git a/docs/mindspore/source_zh_cn/faq/distributed_parallel.md b/docs/mindspore/source_zh_cn/faq/distributed_parallel.md index 1bd8ba180ae343457b34eb0c75cb53a492855944..6d8be054d4e1f6d43c40db60420d05dee2acc70b 100644 --- a/docs/mindspore/source_zh_cn/faq/distributed_parallel.md +++ b/docs/mindspore/source_zh_cn/faq/distributed_parallel.md @@ -49,7 +49,7 @@ A:此场景下,异常进程由于各种问题退出,其余进程由于GPU [CRITICAL] DISTRIBUTED [mindspore/ccsrc/distributed/cluster/cluster_context.cc:130] InitNodeRole] Role name is invalid... ``` -A:在用户不使用`mpirun`启动进程,但是依然调用了`init()`方法的情况下,MindSpore要求用户按照[动态组网启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)配置若干环境变量并进行校验,若没有配置,MindSpore会给出以上报错提示。因此建议只有在执行分布式训练时调用`mindspore.communication.init`,并在不使用`mpirun`的场景下,根据文档配置正确的环境变量以启动分布式训练。 +A:在用户不使用`mpirun`启动进程,但是依然调用了`init()`方法的情况下,MindSpore要求用户按照[动态组网启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)配置若干环境变量并进行校验,若没有配置,MindSpore会给出以上报错提示。因此建议只有在执行分布式训练时调用`mindspore.communication.init`,并在不使用`mpirun`的场景下,根据文档配置正确的环境变量以启动分布式训练。
    diff --git a/docs/mindspore/source_zh_cn/faq/implement_problem.md b/docs/mindspore/source_zh_cn/faq/implement_problem.md index 6a4221070ff37dd6e56d10cca8bad2b6f8e0a1a6..0f9a225580c44207bd053f004425ba7f50521327 100644 --- a/docs/mindspore/source_zh_cn/faq/implement_problem.md +++ b/docs/mindspore/source_zh_cn/faq/implement_problem.md @@ -243,7 +243,7 @@ print(network.layers) ## Q: 使用MindSpore进行模型训练时,`CTCLoss`的输入参数有四个: `inputs`、`labels_indices`、`labels_values`、`sequence_length`,如何使用`CTCLoss`进行训练? -A: 定义的`model.train`接口里接收的`dataset`可以是多个数据组成,形如(`data1`、`data2`、`data3`...),所以`dataset`是可以包含`inputs`、`labels_indices`、`labels_values`、`sequence_length`的信息的。只需要定义好相应形式的`dataset`,传入`model.train`里就可以。具体的可以了解下相应的[数据处理接口](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset.html)。 +A: 定义的`model.train`接口里接收的`dataset`可以是多个数据组成,形如(`data1`、`data2`、`data3`...),所以`dataset`是可以包含`inputs`、`labels_indices`、`labels_values`、`sequence_length`的信息的。只需要定义好相应形式的`dataset`,传入`model.train`里就可以。具体的可以了解下相应的[数据处理接口](https://www.mindspore.cn/docs/zh-CN/master/model_train/index.html)。
    diff --git a/docs/mindspore/source_zh_cn/faq/index.rst b/docs/mindspore/source_zh_cn/faq/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..28cebf75fdf7ce3972e1d9ce88c564e7737a0dd8 --- /dev/null +++ b/docs/mindspore/source_zh_cn/faq/index.rst @@ -0,0 +1,17 @@ +FAQ +======== + +.. toctree:: + :glob: + :maxdepth: 1 + + installation + data_processing + implement_problem + network_compilation + operators_compile + performance_tuning + precision_tuning + distributed_parallel + inference + feature_advice diff --git a/docs/mindspore/source_zh_cn/faq/network_compilation.md b/docs/mindspore/source_zh_cn/faq/network_compilation.md index e49d468cdf8028c41d85573c11fbc66066cacef5..7434032c3c1cf0512993af23b6cd3a4df3ee0690 100644 --- a/docs/mindspore/source_zh_cn/faq/network_compilation.md +++ b/docs/mindspore/source_zh_cn/faq/network_compilation.md @@ -4,7 +4,7 @@ ## Q: 静态图模式支持的语法集合是什么? -A: 静态图模式能够支持覆盖Python常用语法子集,以支持神经网络的构建和训练,部分Python语法暂不支持。具体支持的语法集合,请参考[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)。静态图模式提供了JIT语法支持级别选项,便于用户选择是否扩展静态图语法,对于一些网络场景,推荐使用基础语法(nn/ops等)而非扩展语法(例如numpy三方库)。此外,推荐使用 [静态图高级编程技巧](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/static_graph_expert_programming.html) 优化编译性能。 +A: 静态图模式能够支持覆盖Python常用语法子集,以支持神经网络的构建和训练,部分Python语法暂不支持。具体支持的语法集合,请参考[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)。静态图模式提供了JIT语法支持级别选项,便于用户选择是否扩展静态图语法,对于一些网络场景,推荐使用基础语法(nn/ops等)而非扩展语法(例如numpy三方库)。此外,推荐使用 [静态图高级编程技巧](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html) 优化编译性能。
    @@ -528,7 +528,7 @@ net = Net() out = net(Tensor(x)) ``` -3) 自定义类中调用了使用@jit装饰器修饰的函数,将会报错。这种场景建议将网络中的自定义类加上@jit_class装饰器,避免使用JIT Fallback特性。自定义类的更多使用可参考[自定义类的使用](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#支持自定义类的使用)。jit_class装饰器的使用可参考[使用jit_class](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/static_graph_expert_programming.html#使用jit-class)。 +3) 自定义类中调用了使用@jit装饰器修饰的函数,将会报错。这种场景建议将网络中的自定义类加上@jit_class装饰器,避免使用JIT Fallback特性。自定义类的更多使用可参考[自定义类的使用](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#支持自定义类的使用)。jit_class装饰器的使用可参考[使用jit_class](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html#使用jit-class)。 ```python import mindspore as ms @@ -769,7 +769,7 @@ A: 以下场景会触发重新编译: ## Q: 静态图模式如何判断有几张图?什么情况会切分子图?多子图有什么影响?如何避免出现多子图? -A: 1、子图数量可以通过查看IR文件并搜索"Total subgraphs"获取。关于如何查看分析IR文件,请参考 [IR文件分析](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindir.html)。 +A: 1、子图数量可以通过查看IR文件并搜索"Total subgraphs"获取。关于如何查看分析IR文件,请参考 [IR文件分析](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindir.html)。 2、图模式切分子图,常见于控制流场景,如if/while等。除了用户手动编写,MindSpore框架内部实现的控制流语法也可能会切分出多张子图。 diff --git a/docs/mindspore/source_zh_cn/faq/operators_compile.md b/docs/mindspore/source_zh_cn/faq/operators_compile.md index f8a1bee23b4bbc5a13e5d68d2ddfe34af958c2e3..0d5cff3fefc0dead1ef9d56ccd1fe1c161254af0 100644 --- a/docs/mindspore/source_zh_cn/faq/operators_compile.md +++ b/docs/mindspore/source_zh_cn/faq/operators_compile.md @@ -59,7 +59,7 @@ A: 在PyTorch中`padding_idx`的作用是将embedding矩阵中`padding_idx`位 ## Q: Operations中`Tile`算子执行到`__infer__`时`value`值为`None`,丢失了数值是怎么回事? A: `Tile`算子的`multiples input`必须是一个常量(该值不能直接或间接来自于图的输入)。否则构图的时候会拿到一个`None`的数据,因为图的输入是在图执行的时候才传下去的,构图的时候拿不到图的输入数据。 -相关的资料可以看[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)。 +相关的资料可以看[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)。
    @@ -71,7 +71,7 @@ A: TBE(Tensor Boost Engine)算子是华为自研的Ascend算子开发工具, ## Q: 请问MindSpore实现了反池化操作了吗?类似于`nn.MaxUnpool2d` 这个反池化操作? -A: 目前 MindSpore 还没有反池化相关的接口。用户可以通过自定义算子的方式自行开发算子,详情请见[自定义算子](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom.html)。 +A: 目前 MindSpore 还没有反池化相关的接口。用户可以通过自定义算子的方式自行开发算子,详情请见[自定义算子](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom.html)。
    diff --git a/docs/mindspore/source_zh_cn/index.rst b/docs/mindspore/source_zh_cn/index.rst index da7e541c41e52301852e4b6ba70fe2d81c6e13d1..9f72fcf8afbeb677ba65251e38dfd3e1b23074e0 100644 --- a/docs/mindspore/source_zh_cn/index.rst +++ b/docs/mindspore/source_zh_cn/index.rst @@ -1,131 +1,19 @@ -.. MindSpore documentation master file, created by - sphinx-quickstart on Thu Mar 24 11:00:00 2022. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - MindSpore 文档 ========================= .. toctree:: :glob: :maxdepth: 1 - :caption: 设计 - :hidden: - - design/overview - design/tensor_view - design/programming_paradigm - design/dynamic_graph_and_static_graph - design/dynamic_shape - design/distributed_training_design - design/data_engine - design/all_scenarios - design/graph_fusion_engine - design/pluggable_device - design/glossary - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 模型库 - :hidden: - - note/official_models - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: API - :hidden: - - api_python/mindspore - api_python/mindspore.nn - api_python/mindspore.ops - api_python/mindspore.ops.primitive - api_python/mindspore.mint - api_python/mindspore.amp - api_python/mindspore.train - api_python/mindspore.communication - api_python/mindspore.communication.comm_func - api_python/mindspore.common.initializer - api_python/mindspore.hal - api_python/mindspore.dataset - api_python/mindspore.dataset.transforms - api_python/mindspore.mindrecord - api_python/mindspore.nn.probability - api_python/mindspore.rewrite - api_python/mindspore.multiprocessing - api_python/mindspore.boost - api_python/mindspore.numpy - api_python/mindspore.scipy - api_python/mindspore.experimental - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: API映射 - :hidden: - - note/api_mapping/pytorch_api_mapping - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 迁移指南 - :titlesonly: - :hidden: - - migration_guide/overview - migration_guide/enveriment_preparation - migration_guide/analysis_and_preparation - migration_guide/model_development/model_development - migration_guide/debug_and_tune - migration_guide/sample_code - migration_guide/faq - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 语法支持 - :hidden: - - note/static_graph_syntax_support - note/static_graph_syntax/operators - note/static_graph_syntax/statements - note/static_graph_syntax/python_builtin_functions - note/index_support - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 环境变量 - :hidden: - - note/env_var_list - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: FAQ - :hidden: - - faq/installation - faq/data_processing - faq/implement_problem - faq/network_compilation - faq/operators_compile - faq/performance_tuning - faq/precision_tuning - faq/distributed_parallel - faq/inference - faq/feature_advice - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: RELEASE NOTES :hidden: + design/index + model_train/index + model_infer/index + migration_guide/index + mindformers/index + api_python/index + orange_pi/index + faq/index RELEASE .. raw:: html @@ -151,7 +39,7 @@ MindSpore 文档
    - +
    模型库 @@ -219,7 +107,7 @@ MindSpore 文档
    - +
    语法支持 diff --git a/docs/mindspore/source_zh_cn/migration_guide/analysis_and_preparation.md b/docs/mindspore/source_zh_cn/migration_guide/analysis_and_preparation.md index 2818168b25d09c6db704a95cda483396cc23c200..76f2fae512f41fbcc52429a9ea74fc626c7841b5 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/analysis_and_preparation.md +++ b/docs/mindspore/source_zh_cn/migration_guide/analysis_and_preparation.md @@ -99,11 +99,11 @@ MindRecord是MindSpore开发的一种高效数据格式,当出现精度问题 MindSpore提供了Dump功能,用来将模型训练中的图以及算子的输入输出数据保存到磁盘文件,一般用于网络迁移复杂问题定位(例如:算子溢出等)可以dump出算子级别的数据。 -获取Dump数据参考:[同步Dump数据获取介绍](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html#%E5%90%8C%E6%AD%A5dump%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4)和[异步Dump数据获取介绍](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html#%E5%BC%82%E6%AD%A5dump%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4) +获取Dump数据参考:[同步Dump数据获取介绍](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html#%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4)和[异步Dump数据获取介绍](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html#%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4-1) -分析Dump数据参考:[同步Dump数据分析介绍](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html#%E5%90%8C%E6%AD%A5dump%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E6%A0%B7%E4%BE%8B)和[异步Dump数据分析介绍](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html#%E5%BC%82%E6%AD%A5dump%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E6%A0%B7%E4%BE%8B) +分析Dump数据参考:[同步Dump数据分析介绍](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html#%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E6%A0%B7%E4%BE%8B)和[异步Dump数据分析介绍](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html#%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90%E6%A0%B7%E4%BE%8B-1) -具体可参考[Dump](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html)。 +具体可参考[Dump](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html)。 ### 性能问题 @@ -133,7 +133,7 @@ MindSpore Insight启动等使用介绍可查看[MindSpore Insight相关命令](h - 动态图模式下,程序按照代码的编写顺序逐行执行,在执行正向过程中根据反向传播的原理,动态生成反向执行图。这种模式下,编译器将神经网络中的各个算子逐一下发到设备进行计算操作,方便用户编写和调试神经网络模型。 -### [调用自定义类](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/static_graph_expert_programming.html#使用jit-class) +### [调用自定义类](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html#使用jit-class) 在静态图模式下,通过使用`jit_class`修饰自定义类,用户可以创建、调用该自定义类的实例,并且可以获取其属性和方法。 @@ -143,15 +143,15 @@ MindSpore Insight启动等使用介绍可查看[MindSpore Insight相关命令](h 自动微分能够计算可导函数在某点处的导数值,是反向传播算法的一般化。自动微分主要解决的问题是将一个复杂的数学运算分解为一系列简单的基本运算,该功能对用户屏蔽了大量的求导细节和过程,大大降低了框架的使用门槛。 -### [混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html) +### [混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html) 通常我们训练神经网络模型的时候,默认使用的数据类型为单精度FP32。近年来,为了加快训练时间、减少网络训练时候所占用的内存,并且保存训练出来的模型精度持平的条件下,业界提出越来越多的混合精度训练的方法。这里的混合精度训练是指在训练的过程中,同时使用单精度(FP32)和半精度(FP16)。 -### [自动数据增强](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/augment.html) +### [自动数据增强](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/augment.html) MindSpore除了可以让用户自定义数据增强的使用,还提供了一种自动数据增强方式,可以基于特定策略自动对图像进行数据增强处理。 -### [梯度累加](https://www.mindspore.cn/tutorials/experts/zh-CN/master/optimize/gradient_accumulation.html) +### [梯度累加](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/optimize/gradient_accumulation.html) 梯度累加是一种训练神经网络的数据样本按Batch拆分为几个小Batch的方式,然后按顺序计算。目的是为了解决由于内存不足,导致Batch size过大神经网络无法训练或者网络模型过大无法加载的OOM(Out Of Memory)问题。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/debug_and_tune.md b/docs/mindspore/source_zh_cn/migration_guide/debug_and_tune.md index 16ef1a561a1c568c8cedecfe0f440dc56e8c7de1..5378790f9b1fc250092d61d87ec64144b0ff12d9 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/debug_and_tune.md +++ b/docs/mindspore/source_zh_cn/migration_guide/debug_and_tune.md @@ -11,30 +11,22 @@ 这个大概率是网络反向出现问题。可借助[TroubleShooter比对MindSpore与PyTorch的ckpt/pth](https://gitee.com/mindspore/toolkits/blob/master/troubleshooter/docs/migrator.md#%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF2%E6%AF%94%E5%AF%B9mindspore%E4%B8%8Epytorch%E7%9A%84ckptpth)通过比较ckpt与pth的对应参数的值来检验网络反向更新的结果。 - loss出现NAN/INF: 可以通过[TroubleShooter获取INF/NAN值抛出点](https://gitee.com/mindspore/toolkits/blob/master/troubleshooter/docs/tracker.md#%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF2%E8%8E%B7%E5%8F%96infnan%E5%80%BC%E6%8A%9B%E5%87%BA%E7%82%B9)识别网络中第一个出现NAN或INF的位置。 - 也可通过[Dump](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html)工具进行溢出算子检测。 -- 性能调试阶段,可能会遇到以下常见问题: - - 第一个step耗时长 - 这个阶段主要完成图转换、图融合、图优化等操作,是生成可执行模型的过程,可参考[如何优化编译性能](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/static_graph_expert_programming.html#%E5%A6%82%E4%BD%95%E4%BC%98%E5%8C%96%E7%BC%96%E8%AF%91%E6%80%A7%E8%83%BD)。 - - 迭代间隙耗时长 - 这个阶段的耗时大部分来源于数据获取,可参考[数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html)。 - - 前反向计算耗时长 - 这个阶段主要执行网络中的前向及反向算子,承载了一个迭代的主要计算工作。可通过[Profiler](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling.html)将训练过程中的算子耗时等信息记录到文件中。该性能数据提供框架的host执行、以及算子执行的性能数据,也可通过[MindInsight](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/index.html)可视化界面供用户查看分析,帮助用户更高效地调试神经网络性能。 - - 迭代拖尾耗时长 - 这个阶段耗时长可能是集合通信耗时长,可设置融合策略进行优化,可参考[all_reduce_fusion_config设置allreduce融合策略](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.set_auto_parallel_context.html)。 + 也可通过[Dump](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html)工具进行溢出算子检测。 + - 显存调试阶段,可能遇到以下常见问题: - Malloc device memory failed: MindSpore申请device侧内存失败,原始是设备被其他进程占用,可通过ps -ef | grep "python"查看正在跑的进程。 - Out of Memory: MindSpore申请动态内存失败,可能的原因有:batch size太大,处理数据太多导致内存占用大;通信算子占用内存太多导致整体内存复用率较低。 -## MindSpore调优功能介绍 +## MindSpore功能调试介绍 ### 功能调试 在网络的迁移过程,建议优先使用PYNATIVE模式进行调试,在PYNATIVE模式下可以进行debug,日志打印也比较友好。在调试ok后转成图模式运行,图模式在执行性能上会更友好,也可以找到一些在编写网络中的问题,比如使用了三方的算子导致梯度截断。 -详情请参考[错误分析](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/error_scenario_analysis.html)。 +详情请参考[错误分析](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/error_scenario_analysis.html)。 -### 精度调试 +### 精度调优 精度调试的过程基本可以分为以下过程: @@ -201,7 +193,7 @@ trainable parameter numbers: 2 model = Model(network=train_net) ``` -- 排查是否溢出,添加loss scale时,默认会加上溢出检测,可以将是否溢出的结果进行监测,如果持续溢出的话建议优先排查为什么溢出,建议使用MindSpore Insight的[dump数据](https://mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html)。 +- 排查是否溢出,添加loss scale时,默认会加上溢出检测,可以将是否溢出的结果进行监测,如果持续溢出的话建议优先排查为什么溢出,建议使用MindSpore Insight的[dump数据](https://mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html)。 ```python import numpy as np @@ -290,7 +282,7 @@ trainable parameter numbers: 2 混合精度训练方法是通过混合使用单精度和半精度数据格式来加速深度神经网络训练的过程,同时保持了单精度训练所能达到的网络精度。混合精度训练能够加速计算过程,同时减少内存使用和存取,并使得在特定的硬件上可以训练更大的模型或 batch size。 - 具体可参考 [混合精度教程](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html)。 + 具体可参考 [混合精度教程](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html)。 - 使能图算融合 @@ -343,4 +335,4 @@ if rank_size > 1: 关于数据的性能问题,可以参考 MindSpore Insight 组件的 [数据准备性能分析](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling_ascend.html#数据准备性能分析),其给出了数据性能的常见问题及解决方法。 -更多性能调试方法请参考[性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/optimize/execution_opt.html)。 +更多性能调试方法请参考[性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/train_optimize.html)。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/faq.rst b/docs/mindspore/source_zh_cn/migration_guide/faq.rst index 8b329d18741532f82626f7556faee446eae86994..aa9df33d54180cf3da1a7c608681a5ecacd44202 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/faq.rst +++ b/docs/mindspore/source_zh_cn/migration_guide/faq.rst @@ -68,35 +68,35 @@ MindSpore官网提供了一份在使用MindSpore过程中的 `FAQ `_ 。 + A: 观察报错栈信息,由报错栈信息大概定位到出错代码块,在出错的代码块附近添加打印或调试点,进一步调试。详细可参考 `数据处理调试方法一 `_ 。 **Q: 数据增强 map 操作出错,如何调试 map 操作中各个数据处理算子?** - A: 可以通过单个算子执行的方式调试或者通过数据管道调试模式调试 map 操作。详细可参考 `数据处理调试方法二 `_ 。 + A: 可以通过单个算子执行的方式调试或者通过数据管道调试模式调试 map 操作。详细可参考 `数据处理调试方法二 `_ 。 **Q: 在训练的时候,会获得非常多warning提示我们数据集性能较慢应该怎么处理?** - A: 可以单独迭代数据集,查看每条数据的处理时间,以此判断数据集的性能如何。详细可参考 `数据处理调试方法三 `_ 。 + A: 可以单独迭代数据集,查看每条数据的处理时间,以此判断数据集的性能如何。详细可参考 `数据处理调试方法三 `_ 。 **Q: 在对数据进行处理的过程中,如果因为计算错误、数值溢出等因素,产生了异常的结果数值,从而导致训练网络时算子计算溢出、权重更新异常等问题该怎么排查?** - A: 关闭混洗,固定随机种子,确保可重现性,然后利用NumPy等工具快速校验结果。详细可参考 `数据处理调试方法四 `_ 。 + A: 关闭混洗,固定随机种子,确保可重现性,然后利用NumPy等工具快速校验结果。详细可参考 `数据处理调试方法四 `_ 。 - 更多数据处理常见问题请参考 `数据处理常见问题分析 `_ 以及迁移中的数据处理差异请参考 `MindSpore和PyTorch的数据处理差异 `_ 。 + 更多数据处理常见问题请参考 `数据处理常见问题分析 `_ 以及迁移中的数据处理差异请参考 `MindSpore和PyTorch的数据处理差异 `_ 。 - 梯度求导 **Q: 如何自己实现算子的反向计算?** - A: MindSpore提供了自动的梯度求导接口,该功能对用户屏蔽了大量的求导细节和过程。但如果有某些特殊场景,用户需要手动控制其反向的计算,用户也可以通过Cell.bprop接口对其反向进行定义。详细可参考 `自定义Cell反向 `_ 。 + A: MindSpore提供了自动的梯度求导接口,该功能对用户屏蔽了大量的求导细节和过程。但如果有某些特殊场景,用户需要手动控制其反向的计算,用户也可以通过Cell.bprop接口对其反向进行定义。详细可参考 `自定义Cell反向 `_ 。 **Q: 如何处理梯度溢出造成训练不稳定的问题?** - A: 网络溢出一般表现为loss Nan/INF,loss突然变得很大等。MindSpore提供 `dump数据 `_ 获取到溢出算子信息。当网络中出现梯度下溢时,可使用loss scale配套梯度求导使用,详细可参考 `loss scale `_ ;当网络出现梯度爆炸时,可考虑添加梯度裁剪,详细可参考 `梯度裁剪 `_ 。 + A: 网络溢出一般表现为loss Nan/INF,loss突然变得很大等。MindSpore提供 `dump数据 `_ 获取到溢出算子信息。当网络中出现梯度下溢时,可使用loss scale配套梯度求导使用,详细可参考 `loss scale `_ ;当网络出现梯度爆炸时,可考虑添加梯度裁剪,详细可参考 `梯度裁剪 `_ 。 - 调试调优 @@ -135,11 +135,14 @@ MindSpore官网提供了一份在使用MindSpore过程中的 `FAQ `_ 。 - 更多调试调优常见问题请参考 `调优常见问题及解决办法 `_ 。 + 更多调试调优常见问题请参考 + `功能调试 `_ 、 + `精度调优 `_ 、 + `性能调优 `_ 。 **Q: 模型训练过程中,第一个step耗时很长,该怎么优化?** - A: 模型训练过程中,第一个step包含网络编译时长,如果想要优化第一个step的性能,可分析模型编译是否能进行优化。详细可参考 `静态图网络编译性能优化 `_ 。 + A: 模型训练过程中,第一个step包含网络编译时长,如果想要优化第一个step的性能,可分析模型编译是否能进行优化。详细可参考 `静态图网络编译性能优化 `_ 。 **Q: 模型训练过程中,非首个step耗时很长,该怎么优化?** @@ -177,7 +180,7 @@ MindSpore官网提供了一份在使用MindSpore过程中的 `FAQ `_ 。 + 详细可参考 `静态图语法支持 `_ 。 **Q: 训练过程中出现报错:“RuntimeError: Launch kernel failed, name:Default/...” 怎么办?** @@ -191,7 +194,7 @@ MindSpore官网提供了一份在使用MindSpore过程中的 `FAQ `_ 。 + 同时计算图编译发生报错时,会自动保存analyze_failed.ir文件,可帮助分析报错代码的位置。详细可参考 `静态图模式错误分析 `_ 。 **Q: Graph模式静态图训练过程中出现Out Of Memory报错,怎么办?** @@ -201,6 +204,6 @@ MindSpore官网提供了一份在使用MindSpore过程中的 `FAQ `_ 。 + 详细可参考 `资源不够问题分析 `_ 。 更多调优常见问题请参考 `执行问题 `_ 。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/index.rst b/docs/mindspore/source_zh_cn/migration_guide/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..28765fc9fa3e207790880343b80d78d01c0beb5c --- /dev/null +++ b/docs/mindspore/source_zh_cn/migration_guide/index.rst @@ -0,0 +1,14 @@ +模型迁移 +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + enveriment_preparation + analysis_and_preparation + model_development/model_development + debug_and_tune + sample_code + reference diff --git a/docs/mindspore/source_zh_cn/migration_guide/migrator_with_tools.md b/docs/mindspore/source_zh_cn/migration_guide/migrator_with_tools.md index 0b7be47e183168b19879b26dcfa207abd917fba8..64d2769e41e0b30f52d2a4fec5fb305c2b0da547 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/migrator_with_tools.md +++ b/docs/mindspore/source_zh_cn/migration_guide/migrator_with_tools.md @@ -17,7 +17,7 @@ | [MindSpore Dev Toolkit](https://www.mindspore.cn/devtoolkit/docs/zh-CN/master/index.html) | MindSpore Dev Toolkit是一款支持MindSpore开发的多平台Python IDE插件,提供创建项目、智能补全、API互搜和文档搜索等功能。 | 通过API扫描等能力,能够提升用户的网络迁移开发效率。 | | [TroubleShooter](https://gitee.com/mindspore/toolkits/tree/master/troubleshooter) | TroubleShooter 是MindSpore网络开发调试工具包,用于提供便捷、易用的调试能力。 | 网络调试工具集(如:网络权重迁移、精度比对、代码跟踪、报错分析、执行跟踪等功能),帮助用户提高迁移调试效率。 | | [Profiler](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling.html) | Profiler可将训练过程中的算子耗时等信息记录到文件中,通过可视化界面供用户查看分析,帮助用户更高效地调试神经网络性能。 | 网络迁移后,如果执行性能不佳,可用Profiler进行性能分析,Profiler提供框架的host执行、以及算子执行的Profiler分析功能。 | -| [Dump](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html) | 提供了Dump功能,用来将模型训练中的图以及算子的输入输出数据保存到磁盘文件。 | 一般用于网络迁移复杂问题定位(例如:算子溢出等)可以dump出算子级别的数据。 | +| [Dump](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html) | 提供了Dump功能,用来将模型训练中的图以及算子的输入输出数据保存到磁盘文件。 | 一般用于网络迁移复杂问题定位(例如:算子溢出等)可以dump出算子级别的数据。 | ## 网络迁移工具应用实例 diff --git a/docs/mindspore/source_zh_cn/migration_guide/missing_api_processing_policy.md b/docs/mindspore/source_zh_cn/migration_guide/missing_api_processing_policy.md index 77baf5cd3c8af29c33f4599da913a22d2d9b4100..98a6f959098aeec7289c5fa4310cc71270b59087 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/missing_api_processing_policy.md +++ b/docs/mindspore/source_zh_cn/migration_guide/missing_api_processing_policy.md @@ -234,7 +234,7 @@ test_compare(pred, target, weight, gamma=2.0, alpha=0.25, reduction='none', avg_ ## 3. 自定义算子 -当有些情况无法使用已有的API进行包装,或者用Cell封装的方式性能非常差,这个时候就需要使用自定义算子,详情请参考Custom算子的[使用指南](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom.html)。 +当有些情况无法使用已有的API进行包装,或者用Cell封装的方式性能非常差,这个时候就需要使用自定义算子,详情请参考Custom算子的[使用指南](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom.html)。 除了可以自己迁移实现API,也可以利用`Custom`算子的`aot`开发方式调用PyTorch Aten的算子进行快速验证,请参考[基于自定义算子接口调用第三方算子库](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/use_third_party_op.html)。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/model_development/dataset.md b/docs/mindspore/source_zh_cn/migration_guide/model_development/dataset.md index 0ce24a0b9cd5ba61a9eb2b355234cbda9f1bc301..7f5cfb03600b4dc16a5f73959505a7725114b06b 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/model_development/dataset.md +++ b/docs/mindspore/source_zh_cn/migration_guide/model_development/dataset.md @@ -6,11 +6,11 @@ [数据处理](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/dataset.html) -[自动数据增强](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/augment.html) +[自动数据增强](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/augment.html) -[轻量化数据处理](https://mindspore.cn/tutorials/zh-CN/master/advanced/dataset/eager.html) +[轻量化数据处理](https://mindspore.cn/docs/zh-CN/master/model_train/dataset/eager.html) -[数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html) +[数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html) ## 数据处理差异对比 @@ -19,7 +19,7 @@ MindSpore和PyTorch的数据构建基本流程主要包括两个方面:数据 ### 处理常见数据集 MindSpore提供了很多不同领域的[常见数据集的加载接口](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.dataset.html)。 -除以上业界常用数据集外,MindSpore还开发了MindRecord数据格式以应对高效的读取、超大型数据存储与读取场景,感兴趣可以参阅[MindRecord](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset/record.html)。由于此文章是介绍同类API及写法差异,故选取一个较为经典的数据集API作为迁移对比示例。其他数据集接口差异详细可参考PyTorch与MindSpore API映射表的 [torchaudio](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html#torchaudio)、[torchtext](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html#torchtext)、[torchvision](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html#torchvision) 模块。 +除以上业界常用数据集外,MindSpore还开发了MindRecord数据格式以应对高效的读取、超大型数据存储与读取场景,感兴趣可以参阅[MindRecord](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/record.html)。由于此文章是介绍同类API及写法差异,故选取一个较为经典的数据集API作为迁移对比示例。其他数据集接口差异详细可参考PyTorch与MindSpore API映射表的 [torchaudio](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html#torchaudio)、[torchtext](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html#torchtext)、[torchvision](https://www.mindspore.cn/docs/zh-CN/master/note/api_mapping/pytorch_api_mapping.html#torchvision) 模块。 这里以FashionMnistDataset举例。下图展示了PyTorch的API使用方法(左边部分),以及MindSpore的API使用方法(右边部分)。主要的读取流程为:使用FashionMnist API加载源数据集,再使用transforms对数据内容进行变换,最后根据对数据集进行`batch`操作。两侧代码对应的关键部分,均使用颜色框进行了标记。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/model_development/gradient.md b/docs/mindspore/source_zh_cn/migration_guide/model_development/gradient.md index 6f84b633919ec9fe944a5f78697b84de947b6b7a..7cf189342ac0697d5a2d7702eea561078ebfa378 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/model_development/gradient.md +++ b/docs/mindspore/source_zh_cn/migration_guide/model_development/gradient.md @@ -357,7 +357,7 @@ z.requires_grad True ## MindSpore自动微分接口 本节介绍MindSpore提供的三种[自动微分](https://mindspore.cn/tutorials/zh-CN/master/beginner/autograd.html)接口用以计算模型的梯度结果。 -在[自动求导](https://mindspore.cn/tutorials/zh-CN/master/advanced/derivation.html)的教程中,对各种梯度计算的场景做了一些介绍。 +在[自动求导](https://mindspore.cn/docs/zh-CN/master/model_train/train_process/derivation.html)的教程中,对各种梯度计算的场景做了一些介绍。 ### mindspore.grad @@ -639,9 +639,9 @@ grad ((Tensor(shape=[1, 3], dtype=Float32, value= 由于在混合精度的场景,在求梯度的过程中可能会遇到梯度下溢,一般我们会使用loss scale配套梯度求导使用。 -> 在Ascend上因为Conv、Sort、TopK等算子只能是float16的,MatMul由于性能问题最好也是float16的,所以建议loss scale操作作为网络训练的标配。[Ascend 上只支持float16的算子列表](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#4%E8%AE%AD%E7%BB%83%E7%B2%BE%E5%BA%A6)。 +> 在Ascend上因为Conv、Sort、TopK等算子只能是float16的,MatMul由于性能问题最好也是float16的,所以建议loss scale操作作为网络训练的标配。[Ascend 上只支持float16的算子列表](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#4训练精度)。 > -> 溢出可以通过MindSpore Insight的[dump数据](https://mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html)获取到溢出算子信息。 +> 溢出可以通过MindSpore Insight的[dump数据](https://mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html)获取到溢出算子信息。 > > 一般溢出表现为loss Nan/INF,loss突然变得很大等。 @@ -707,4 +707,4 @@ grad = ops.clip_by_global_norm(grad) 梯度累加是一种训练神经网络的数据样本按Batch拆分为几个小Batch的方式,然后按顺序计算,用以解决由于内存不足,导致Batch size过大,神经网络无法训练或者网络模型过大无法加载的OOM(Out Of Memory)问题。 -详情请参考[梯度累加](https://www.mindspore.cn/tutorials/experts/zh-CN/master/optimize/gradient_accumulation.html)。 +详情请参考[梯度累加](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/optimize/gradient_accumulation.html)。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/model_development/learning_rate_and_optimizer.md b/docs/mindspore/source_zh_cn/migration_guide/model_development/learning_rate_and_optimizer.md index 322811c622b843fa72bd13d9ca025c0ba3bdda24..93feef863c0006bf981dacaebfdcab1ccd7a2b60 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/model_development/learning_rate_and_optimizer.md +++ b/docs/mindspore/source_zh_cn/migration_guide/model_development/learning_rate_and_optimizer.md @@ -2,7 +2,7 @@ [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/migration_guide/model_development/learning_rate_and_optimizer.md) -在阅读本章节之前,请先阅读MindSpore官网教程[优化器](https://mindspore.cn/tutorials/zh-CN/master/advanced/modules/optimizer.html)。 +在阅读本章节之前,请先阅读MindSpore官网教程[优化器](https://mindspore.cn/docs/zh-CN/master/model_train/custom_program/optimizer.html)。 这里就MindSpore的优化器的一些特殊使用方式和学习率衰减策略的原理做一个介绍。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/model_development/loss_function.md b/docs/mindspore/source_zh_cn/migration_guide/model_development/loss_function.md index 6dd7a2538e424abf141c060f5ae9e0d050c3a1e3..17b76f36452d12455cbd805868f611f0de7ccbf4 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/model_development/loss_function.md +++ b/docs/mindspore/source_zh_cn/migration_guide/model_development/loss_function.md @@ -2,7 +2,7 @@ [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/migration_guide/model_development/loss_function.md) -在阅读本章节之前,请先阅读MindSpore官网教程[损失函数](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/modules/loss.html)。 +在阅读本章节之前,请先阅读MindSpore官网教程[损失函数](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/loss.html)。 MindSpore官网教程损失函数中讲解了内置、自定义和多标签损失函数,以及在模型训练中的使用指导,这里就MindSpore的损失函数与PyTorch的损失函数在功能和接口差异方面给出差异列表。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/model_development/model_and_cell.md b/docs/mindspore/source_zh_cn/migration_guide/model_development/model_and_cell.md index 2b9a6c25daddb3113c41de23b6711bdf46277d9e..ebafa3a292f1bd9768bdeb22d1ca8224960e5b1a 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/model_development/model_and_cell.md +++ b/docs/mindspore/source_zh_cn/migration_guide/model_development/model_and_cell.md @@ -10,7 +10,7 @@ PyTorch和MindSpore的基础逻辑如下图所示: 可以看到,PyTorch和MindSpore在实现流程中一般都需要网络定义、正向计算、反向计算、梯度更新等步骤。 -- 网络定义:在网络定义中,一般会定义出需要的前向网络,损失函数和优化器。在Net()中定义前向网络,PyTorch的网络继承nn.Module;类似地,MindSpore的网络继承nn.Cell。在MindSpore中,损失函数和优化器除了使用MindSpore中提供的外,用户还可以使用自定义的优化器。可参考[模型模块自定义](https://mindspore.cn/tutorials/zh-CN/master/advanced/modules.html)。可以使用functional/nn等接口拼接需要的前向网络、损失函数和优化器。 +- 网络定义:在网络定义中,一般会定义出需要的前向网络,损失函数和优化器。在Net()中定义前向网络,PyTorch的网络继承nn.Module;类似地,MindSpore的网络继承nn.Cell。在MindSpore中,损失函数和优化器除了使用MindSpore中提供的外,用户还可以使用自定义的优化器。可参考[模型模块自定义](https://mindspore.cn/docs/zh-CN/master/model_train/index.html)。可以使用functional/nn等接口拼接需要的前向网络、损失函数和优化器。 - 正向计算:运行实例化后的网络,可以得到logit,将logit和target作为输入计算loss。需要注意的是,如果正向计算的函数有多个输出,在反向计算时需要注意多个输出对于计算结果的影响。 @@ -538,9 +538,9 @@ x = initializer(Uniform(), [1, 2, 3], mindspore.float32) ##### 自定义初始化Parameter -MindSpore封装的高阶API里一般会给Parameter一个默认的初始化,当这个初始化分布与需要使用的初始化、PyTorch的初始化不一致,此时需要进行自定义初始化。[网络参数初始化](https://mindspore.cn/tutorials/zh-CN/master/advanced/modules/initializer.html#自定义参数初始化)介绍了一种在使用API属性进行初始化的方法,这里介绍一种利用Cell进行Parameter初始化的方法。 +MindSpore封装的高阶API里一般会给Parameter一个默认的初始化,当这个初始化分布与需要使用的初始化、PyTorch的初始化不一致,此时需要进行自定义初始化。[网络参数初始化](https://mindspore.cn/docs/zh-CN/master/model_train/custom_program/initializer.html#自定义参数初始化)介绍了一种在使用API属性进行初始化的方法,这里介绍一种利用Cell进行Parameter初始化的方法。 -Parameter的相关介绍请参考[网络参数](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/modules/initializer.html),本节主要以`Cell`为切入口,举例获取`Cell`中的所有参数,并举例说明怎样给`Cell`里的Parameter进行初始化。 +Parameter的相关介绍请参考[网络参数](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/initializer.html),本节主要以`Cell`为切入口,举例获取`Cell`中的所有参数,并举例说明怎样给`Cell`里的Parameter进行初始化。 > 注意本节的方法不能在`construct`里执行,在网络中修改Parameter的值请使用[assign](https://www.mindspore.cn/docs/zh-CN/master/api_python/ops/mindspore.ops.assign.html)。 @@ -766,7 +766,7 @@ ms_net = mindspore.nn.Dense(3, 4) `PyNative`模式下模型进行**推理**的行为与一般Python代码无异。但是在训练过程中,注意**一旦将Tensor转换成numpy做其他的运算后将会截断网络的梯度,相当于PyTorch的detach**。 -而在使用`GRAPH_MODE`时,通常会出现语法限制。在这种情况下,需要对Python代码进行图编译操作,而这一步操作中MindSpore目前还未能支持完整的Python语法全集,所以`construct`函数的编写会存在部分限制。具体限制内容可以参考[MindSpore静态图语法](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html)。 +而在使用`GRAPH_MODE`时,通常会出现语法限制。在这种情况下,需要对Python代码进行图编译操作,而这一步操作中MindSpore目前还未能支持完整的Python语法全集,所以`construct`函数的编写会存在部分限制。具体限制内容可以参考[MindSpore静态图语法](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)。 相较于详细的语法说明,常见的限制可以归结为以下几点: @@ -881,7 +881,7 @@ dx (Tensor(shape=[2, 5], dtype=Float32, value= [0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 0.00000000e+000, 0.00000000e+000]]),) ``` -下面,我们来演示下如何[自定义反向](https://mindspore.cn/tutorials/zh-CN/master/advanced/modules/layer.html#自定义cell反向): +下面,我们来演示下如何[自定义反向](https://mindspore.cn/docs/zh-CN/master/model_train/custom_program/network_custom.html#自定义cell反向): ```python import numpy as np diff --git a/docs/mindspore/source_zh_cn/migration_guide/model_development/model_development.rst b/docs/mindspore/source_zh_cn/migration_guide/model_development/model_development.rst index 4c2e2b6908b48c9583dc6886f76cdd1e3392a768..68f9a6740057082518ce5c4cc4444265df41ae26 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/model_development/model_development.rst +++ b/docs/mindspore/source_zh_cn/migration_guide/model_development/model_development.rst @@ -23,7 +23,7 @@ - loss:损失函数。用于衡量预测值与真实值差异的程度。深度学习中,模型训练就是通过不停地迭代来缩小损失函数值的过程,定义一个好的损失函数可以帮助损失函数值更快收敛,达到更好的精度,MindSpore提供了很多\ `常见的loss函数 `__\ ,当然可以自己定义实现自己的loss函数。 -- 自动梯度求导:一般将network和loss一起包装成正向网络一起给到自动梯度求导模块进行梯度计算。MindSpore提供了自动的梯度求导接口,该功能对用户屏蔽了大量的求导细节和过程,大大降低了框架的使用门槛。需要自定义梯度时,MindSpore也提供了\ `接口 `__\ 去自由实现梯度计算。 +- 自动梯度求导:一般将network和loss一起包装成正向网络一起给到自动梯度求导模块进行梯度计算。MindSpore提供了自动的梯度求导接口,该功能对用户屏蔽了大量的求导细节和过程,大大降低了框架的使用门槛。需要自定义梯度时,MindSpore也提供了\ `接口 `__\ 去自由实现梯度计算。 - 优化器:优化器在模型训练过程中,用于计算和更新网络参数。MindSpore提供了许多\ `通用的优化器 `__\ 供用户选择,同时也支持用户根据需要自定义优化器。 @@ -130,7 +130,7 @@ MindSpore网络编写注意事项 2. 切片操作,当遇到对一个Tensor进行切片时需要注意,切片的下标是否是变量,当是变量时会有限制,请参考\ `网络主体和loss搭建 `__\ 对动态shape规避。 3. 自定义混合精度和Model里的\ ``amp_level``\ 冲突,使用自定义的混合精度就不要设置Model里的\ ``amp_level``\ 。 4. 在Ascend环境下Conv,Sort,TopK只能是float16的,注意加\ `loss - scale `__\ 避免溢出。 + scale `__\ 避免溢出。 5. 在Ascend环境下Conv,Pooling等带有stride属性的算子对stride的长度有规定,需要规避。 6. 在分布式环境下必须加seed,用以保证多卡的初始化的参数一致。 7. 网络中使用Cell的list或者Parameter的list的情况,请在\ ``init``\ 里对list进行转换,转换成\ `CellList `__\ ,\ `SequentialCell `__\ ,\ `ParameterTuple `__\ 。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/model_development/training_and_evaluation.md b/docs/mindspore/source_zh_cn/migration_guide/model_development/training_and_evaluation.md index c79470c0123aa8c806977f3c26a4bdbe8c029a76..705cb0fff32081d4993b1dc33071447d38991cb8 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/model_development/training_and_evaluation.md +++ b/docs/mindspore/source_zh_cn/migration_guide/model_development/training_and_evaluation.md @@ -336,8 +336,8 @@ mpirun --allow-run-as-root -n $RANK_SIZE python ../train.py --config_path=$CONFI 如果在GPU上,可以通过`export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7`来设置使用哪些卡,Ascend上目前不支持指定卡号。 -详情请参考[分布式案例](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/distributed_case.html)。 +详情请参考[分布式案例](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/distributed_case.html)。 ## 离线推理 -除了可以在线推理外,MindSpore提供了很多离线推理的方法适用于不同的环境,详情请参考[模型推理](https://www.mindspore.cn/tutorials/experts/zh-CN/master/infer/inference.html)。 +除了可以在线推理外,MindSpore提供了很多离线推理的方法适用于不同的环境,详情请参考[模型推理](https://www.mindspore.cn/docs/zh-CN/master/model_infer/overview.html)。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/overview.md b/docs/mindspore/source_zh_cn/migration_guide/overview.md index cac41bc188234cdf0bf8d4db6ca22a8fe5adf570..7ce764b695a13e473a47cd46f5869c2ec86410fd 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/overview.md +++ b/docs/mindspore/source_zh_cn/migration_guide/overview.md @@ -13,24 +13,28 @@ E-.-text2(在线使用ModelArts) B-->|Step 2|F(模型分析与准备) F-.-text3(算法复现/MindSpore Dev Toolkit 工具分析API满足度/分析功能满足度) B-->|Step 3|G(网络搭建对比) -G-->I(数据处理) -I-.-text4(数据集加载/增强/读取对齐) -G-->J(网络搭建) -J-.-text5(网络对齐) -G-->N(损失函数) -N-.-text6(损失函数对齐) -G-->K(学习率与优化器) -K-.-text7(优化器执行和学习率策略对齐) -G-->L(梯度求导) -L-.-text8(反向梯度对齐) -G-->M(训练及推理流程) -M-.-text9(训练与推理对齐) -B-->|Step 4|H(调试调优) -H-.-text10(功能/精度/性能三方面对齐) +G-->K(数据处理) +K-.-text4(数据集加载/增强/读取对齐) +G-->L(网络搭建) +L-.-text5(网络对齐) +G-->P(损失函数) +P-.-text6(损失函数对齐) +G-->M(学习率与优化器) +M-.-text7(优化器执行和学习率策略对齐) +G-->N(梯度求导) +N-.-text8(反向梯度对齐) +G-->O(训练及推理流程) +O-.-text9(训练与推理对齐) +B-->|Step 4|H(功能调试) +H-.-text10(功能方面对齐) +B-->|Step 5|I(精度调优) +I-.-text11(精度方面对齐) +B-->|Step 6|J(性能调优) +J-.-text12(性能方面对齐) A-->C(网络迁移调试实例) -C-.-text11(以ReNet50为例的网络迁移样例) +C-.-text13(以ReNet50为例的网络迁移样例) A-->D(常见问题) -D-.-text12(迁移过程中的常见问题与解决方法) +D-.-text14(迁移过程中的常见问题与解决方法) click C "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/sample_code.html" click D "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/faq.html" @@ -38,12 +42,14 @@ click D "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/faq.html" click E "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/enveriment_preparation.html" click F "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/analysis_and_preparation.html" click G "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/model_development.html" -click H "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html" +click H "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#功能调试" +click I "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#精度调优" +click J "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#性能调优" -click I "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/dataset.html" -click J "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/model_and_cell.html" -click K "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/learning_rate_and_optimizer.html" -click L "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/gradient.html" -click M "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/training_and_evaluation.html" -click N "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/loss_function.html" +click K "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/dataset.html" +click L "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/model_and_cell.html" +click M "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/learning_rate_and_optimizer.html" +click N "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/gradient.html" +click O "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/training_and_evaluation.html" +click P "https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/loss_function.html" ``` diff --git a/docs/mindspore/source_zh_cn/migration_guide/reference.rst b/docs/mindspore/source_zh_cn/migration_guide/reference.rst new file mode 100644 index 0000000000000000000000000000000000000000..9dc1c3a9e8339ef7cf6f7f4ddb57063d1faa2178 --- /dev/null +++ b/docs/mindspore/source_zh_cn/migration_guide/reference.rst @@ -0,0 +1,9 @@ +参考 +======== + +.. toctree:: + :maxdepth: 1 + + ../note/api_mapping/pytorch_api_mapping + migrator_with_tools + faq diff --git a/docs/mindspore/source_zh_cn/migration_guide/reproducing_algorithm.md b/docs/mindspore/source_zh_cn/migration_guide/reproducing_algorithm.md index 3bb248b3c3e310ace2a6136f6719fb552746cfcf..49f02b00af7fd7aff1d52bb6bf13bc3f353d5930 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/reproducing_algorithm.md +++ b/docs/mindspore/source_zh_cn/migration_guide/reproducing_algorithm.md @@ -82,4 +82,7 @@ - 获取loss下降趋势,帮助验证MindSpore上训练收敛趋势是否ok; - 获取参数文件,用于进行转换,进行推理验证,详细过程参考[推理及训练流程](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/training_and_evaluation.html); - - 获取性能基线,在做性能优化时有一个基础目标,如需做性能优化,请参考[调试调优](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html)。 + - 获取性能基线,在做性能优化时有一个基础目标,如需做性能优化,请参考 + [功能调试](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#功能调试)、 + [精度调优](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#精度调优)、 + [性能调优](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/debug_and_tune.html#性能调优)。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/sample_code.md b/docs/mindspore/source_zh_cn/migration_guide/sample_code.md index 04ae54db3711b79bb93ab3382e374cb1dfd5f3d6..fb3bc054c57b85221721d09b0a1be6d541ccd725 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/sample_code.md +++ b/docs/mindspore/source_zh_cn/migration_guide/sample_code.md @@ -1079,7 +1079,7 @@ MindSpore有三种方法使用混合精度: 1. 直接使用`Cast`,将网络的输入`cast`成`float16`,将loss的输入`cast`成`float32`; 2. 使用`Cell`的`to_float`方法,详情参考[网络搭建](https://www.mindspore.cn/docs/zh-CN/master/migration_guide/model_development/model_and_cell.html); -3. 使用`Model`的`amp_level`接口进行混合精度,详情参考[自动混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/mixed_precision.html#%E8%87%AA%E5%8A%A8%E6%B7%B7%E5%90%88%E7%B2%BE%E5%BA%A6)。 +3. 使用`Model`的`amp_level`接口进行混合精度,详情参考[自动混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html#%E8%87%AA%E5%8A%A8%E6%B7%B7%E5%90%88%E7%B2%BE%E5%BA%A6)。 这里我们使用第三种方法,将`Model`中的`amp_level`设置成`O3`,看一下profiler的结果: @@ -1100,7 +1100,7 @@ MindSpore有三种方法使用混合精度: ![resnet_profiler12](images/resnet_profiler12.png) -每个数据处理操作的队列,发现最后一个操作,`batch`操作空的时间比较多,可以考虑增加`batch`操作的并行度。详情请参考[数据处理性能优化](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html)。 +每个数据处理操作的队列,发现最后一个操作,`batch`操作空的时间比较多,可以考虑增加`batch`操作的并行度。详情请参考[数据处理性能优化](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html)。 整个resnet迁移需要的代码可以在[code](https://gitee.com/mindspore/docs/tree/master/docs/mindspore/source_zh_cn/migration_guide/code)获取。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/sparsity.md b/docs/mindspore/source_zh_cn/migration_guide/sparsity.md index a1ef686943b9865fbc397b6278256ba5667ee66e..bf6bddd44af1b56fb2fe7c5bc128d923dfe24bfe 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/sparsity.md +++ b/docs/mindspore/source_zh_cn/migration_guide/sparsity.md @@ -7,4 +7,4 @@ 在某些应用场景中(比如推荐系统、分子动力学、图神经网络等),数据的特征是稀疏的,若使用普通张量表征这些数据会引入大量不必要的计算、存储和通讯开销。在这种时候就可以使用稀疏张量来表征这些数据。 MindSpore现在已经支持最常用的[CSR和COO](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/tensor.html#%E7%A8%80%E7%96%8F%E5%BC%A0%E9%87%8F)两种稀疏数据格式。但是由于目前支持稀疏算子有限,大部分稀疏的特性还存在限制,在此情况下,建议优先查找对应的算子是否支持稀疏计算,如不支持的话需要转换成普通算子。 -由于转换成稠密算子后使用的显存会增加,可能不能使用参考实现的batch size进行训练,此时可以使用 [梯度累加](https://www.mindspore.cn/tutorials/experts/zh-CN/master/optimize/gradient_accumulation.html) 来模拟大batch训练。 +由于转换成稠密算子后使用的显存会增加,可能不能使用参考实现的batch size进行训练,此时可以使用 [梯度累加](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/optimize/gradient_accumulation.html) 来模拟大batch训练。 diff --git a/docs/mindspore/source_zh_cn/migration_guide/use_third_party_op.md b/docs/mindspore/source_zh_cn/migration_guide/use_third_party_op.md index 0113c8caab1c7a6acdb59bcbbfea1c72f9cc70e7..14583677f79c06f3f737f06dcc7894b4df2ac9ae 100644 --- a/docs/mindspore/source_zh_cn/migration_guide/use_third_party_op.md +++ b/docs/mindspore/source_zh_cn/migration_guide/use_third_party_op.md @@ -6,7 +6,7 @@ 当开发网络遇到内置算子不足以满足需求时,你可以利用MindSpore的Python API中的[Custom](https://www.mindspore.cn/docs/zh-CN/master/api_python/ops/mindspore.ops.Custom.html#mindspore-ops-custom)原语方便快捷地进行不同类型自定义算子的定义和使用。 -网络开发者可以根据需要选用不同的自定义算子开发方式。详情请参考Custom算子的[使用指南](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom.html)。 +网络开发者可以根据需要选用不同的自定义算子开发方式。详情请参考Custom算子的[使用指南](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom.html)。 其中,自定义算子有一种开发方式`aot`方式有其特殊的使用方式。`aot`方式可以通过加载预编译的`so`来调用相应的`cpp`/`cuda`函数。因此,当第三方库提供了`cpp`/`cuda`函数`API`时,可以尝试将其函数接口在`so`中调用,以下以PyTorch的`Aten`库为例进行介绍。 diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/acc_optimize.md b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/acc_optimize.md new file mode 100644 index 0000000000000000000000000000000000000000..4a08478c898f03d3b715b810d568835fc37a2454 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/acc_optimize.md @@ -0,0 +1,658 @@ +# 大模型精度调优指南 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/acc_optimize/acc_optimize.md) + +## 精度问题概述和场景 + +### 描述 + +随着昇腾AI处理器(以下简称为NPU)在深度学习中的广泛应用,基于昇腾NPU原生开发的MindSpore框架也展现出了更好的性能优势。在大规模集群训练过程中,性能的提升将极大节省用户进行大模型开发的成本。因此,越来越多的用户也逐渐将原本训练模型迁移至MindSpore中。然而,由于硬件以及框架使用上的差异,用户在完成模型迁移后可能会遇到精度问题。 + +本文总结了大模型训练过程中常见精度问题及通用的精度问题定位方法,力求帮助用户快速排查精度问题,缩短模型精度问题定位的时间。 + +### 常见问题归类总结 + +大模型训练中经常出现各种精度问题,常见的问题现象包括loss无法收敛、loss收敛效果不佳、训练后期loss跑飞、精度溢出、loss下降过程中与标杆无法拟合等;这些精度问题可能是多种来源造成的,包括模型结构、数据集、超参数、前反向计算精度、优化器计算、浮点计算精度、随机性等方面。 + +当出现精度问题时,可以从这些精度误差的来源进行问题分析。先根据CheckList进行快速的排查,再进行参数、权重对齐,固定随机性和开启确定性计算后,再执行进出问题排查和长稳训练排除。当前阶段本文主要针对有精度标杆的场景介绍精度定位的通用方法,后续将陆续添加无精度标杆下的精度问题定位内容。 + +## 精度问题定位CheckList + +在定位算子精度问题之前,首先要排除其他非算子因素的干扰。结合以往精度定位案例,总结了精度定位前的CheckList。为了在定位过程中少走弯路,用户可先根据CheckList进行快速的排查。 + +### 网络结构CheckList + +* 通用结构(以Llama2为例) + +| 关键参数 | 说明 | 检查项 | +| ----------------- | ------------------------------------------------------------ |------------------------------------------------------------------------------------------------------------------------------------| +| num_layers | transformer层数 | 检查是否与标杆保持一致 | +| num_heads | transformer中attention heads数量 | 检查是否与标杆保持一致 | +| hidden_size | transformer隐藏层大小 | 检查是否与标杆保持一致 | +| intermediate_size | Feed-Forward Network的隐藏层大小 | intermediate_size对应Megatron中ffn-hidden-size参数。MindFormers中若不配置,则通过multiple_of与ffn_dim_multiplier计算得到,检查是否与标杆保持一致。 | +| Attention | transformer中的attention模块 |
    - 检查以下结构及计算方式是否对齐:attention结构有MQA、GQA、MHA等不同结构。
    - 稀疏计算模式:Causal/sliding window attention(SWA)等。
    - wq/wk/wv的矩阵是否有融合计算。 | +| normalization | 正则化函数,常见结构有LayerNorm、RMSNorm | 检查是否与标杆保持一致 | +| normal_eps | 正则化的epsilon参数 | 检查是否与标杆保持一致 | +| dropout | 网络中的dropout | 当前MindSpore开启Dropout时,不能开重计算;若进行精度比对建议双边都关闭,减少随机因素。 | +| 激活函数 | 常见的激活函数ReLU/GeLU/FastGeLU/SwigLU等 | 检查是否与标杆保持一致 | +| 融合计算 | 常见的融合算子包括FA、ROPE、Norm、SwigLU;部分用户会将Wq、Wk、Wv进行融合计算 | 同硬件下进行精度比对时,若有使用融合算子,则需要保持一致 。不同硬件下进行精度比对时,则重点检查融合计算部分是否有计算差异。 | +| 位置编码 | / | 检查使用位置编码的方式:绝对/相对位置编码。 | +| vocab_size | 词表大小 | vocab size建议为16的倍数;若奇数,可能会影响matmul的计算结果。在预训练场景,可以通过修改参数来改变词表大小。在SFT场景,如果预训练权重的词表为奇数,需要对权重进行pad。 | + +* MOE结构 + +| 关键参数 | 说明 | 检查项 | +| ------------------------ | ------------------------------------------------- |-----------------------------------------------------------------------------------------------------------------| +| expert_num | 专家数量 | 检查是否与标杆一致 | +| shared_expert_num | 共享专家数量 | 检查是否与标杆一致 | +| num_experts_chosen | 每个token选择专家数目 | 检查是否与标杆一致 | +| capacity_factor | 专家容量系数 | 容量系数要求 1.0 <= 容量系数 <= expert_num/num_experts_chosen,精度对比时,建议使用该方式。当容量系数<0时,为动态容量,对应dropless MoE操作,即不丢弃任何token。 | +| aux_loss_factor | 负载均衡loss贡献因子 | 开启时,建议小于0.05;若进行精度对齐,建议不开启,loss打印方式不一致。 | +| routing_policy | 路由专家策略 | 当前MindFormers有TopkRouterV1、TopkRouterV2两种方式;V2是V1的高性能数学等价实现,建议使用V2,V1后续会废弃。 | +| enable_sdrop | 是否开启sdrop方式 | 建议设置成true,对应Megatron需要设置参数如下参数:
    moe-token-drop-policy: position
    moe-pad-expert-input-to-capacity: True。 | +| router_dense_type | 决定专家的dense层 | 需要使用fp32计算,防止溢出。 | +| use_fused_ops_topkrouter | 是否使用融合算子进行dispatch以及combine的索引计算 | 当enbable_sdrop=True时参数才生效,精度对齐建议设置成True。 | +| use_shared_expert_gating | 共享专家网络中是否使用gating系数 | 检查网络的共享专家是否有gating系数,如果有设置成True。 | + +### 优化器CheckList + +| 关键参数 | 说明 | 检查项 | +|-------------------| ---------------------- |----------------------------------------------| +| adam优化器 | 优化器类型 | 若Megatron使用adam优化器,MindFormers的数学等价实现为AdamW。 | +| eps | adam优化器极小值参数 | 检查参数是否一致,推荐值1e-8。 | +| beta1 | adam优化器梯度动量参数 | 检查参数是否一致,推荐值0.9。 | +| beta2 | adam优化器梯度方差参数 | 检查参数是否一致,推荐值0.95。 | +| weight_decay | 权重衰减 | 默认情况下bias及一维权重不进行衰减,检查用户是否有特殊操作。 | +| lr | 学习率 | 在设置了warmup、学习率衰减后,画图查看学习率变化是否一致。 | +| warmup_ratio | 学习率预热步数占比 | 参考上一条 | +| clip_grad | 修剪梯度 | 检查参数是否一致,推荐值1.0。 | +| global_batch_size | 全局批大小 | 与标杆保持一致,可以通过训练过程中的打印日志检查。 | + +### 权重CheckList + +| 关键参数 | 说明 | 检查项 | +| --------------- | -------------------- |-----------------------------------------------------------------------------------------------------------| +| param_init_type | 权重初始化类型 | MindFormers通常会设置param_init_dtype类型为fp32,这是因为梯度通信类型需要跟权重类型一致,控制通信类型为fp32。而Megatron的梯度通信类型默认为fp32,不与权重类型绑定。 | + +### 混合精度CheckList + +| 关键参数 | 说明 | 检查项 | +| ---------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| compute_dtype | 计算精度 | 与标杆保持一致 | +| layernorm_compute_type | layerNorm/RMSNorm的计算精度 | Megatron不可配置,需要检查实现是否保持一致。 | +| softmax_compute_type | MindSpore使用FlashAttention时,内部Softmax固定用FA计算。 | Megatron不可配置,需要检查实现是否保持一致。 | +| 各权重计算 | embedding、lm_head等各权重精度计算 仅在小算子拼接实现时可配置计算类型 | Megatron不可配置,需要检查实现是否保持一致。 | +| rotary_dtype | 旋转位置编码的计算精度 | 由于MindFormers权重初始化需要设置为fp32,而通常计算精度为bf16/fp16,需要检查权重计算前,是否将权重数据类型转为bf16/fp16。 | +| bias add | 线性层的Bias | 线性层若有bias,检查add的计算精度是否一致。 | +| residual add | 残差相加 | 检查残差的计算精度是否与标杆一致 | +| loss | loss计算模块 | 检查整个loss模块的计算精度是否与标杆一致 | +| 算子高精度模式 | 昇腾算子支持高精度模式 | 开启方式: context.set_context(ascend_config= {"ge_options":{ "global":{ "ge.opSelectImplmode":"high_precision" } } }) | + +### 并行策略CheckList + +| 关键参数 | 说明 | 检查项 | +| -------------------------- | -------------------------------------- |---------------------------------------------------------| +| data_parallel | 数据并行 | 并行切分会影响通信行为,切分后引入通信的计算跟单卡计算可能会有细微差异。 | +| model_parallel | 模型并行 | 不影响精度 | +| pipeline_stage | 流水并行 | 不影响精度 | +| use_seq_parallel | 使能Megatron短序列并行,仅在tp>1时生效 | 不影响精度 | +| enable_parallel_optimizer | 优化器并行 | 优化器并行MindSpore与PyTorch两个框架的实现方案不同,通信行为不一致。进行精度对齐时,建议关闭。 | +| micro_batch_interleave_num | 多副本并行 | 在进行性能优化时,需要检查开启多副本是否会影响精度。 | + +### 其他CheckList + +| 关键点 | 检查项 | +| ------------- |----------------------------------------------------------------------------------------------| +| 数据检查 | 查看数据是否异常,可随机抽取部分数据进行decode、encode检查,查看input与label的位置是否正确对应。 | +| 特殊词检查 | 检查bos_token_id、eos_token_id、pad_token_id等特殊ids是否与数据制作时的ids保持一致。 | +| input_ids校验 | 检查embedding中的inputs_id是否符合0<=inputs_id 0,权重更新,进行长稳测试。训练至某个step出现loss差异较大现象,之后训练loss开始发散,如图所示: + +![loss1](./image/loss1.png) + +在该场景下,可针对突变前后的训练进行排查,可尝试如下排查方式: + +* 检查loss突变附近的数据情况,排查是否有异常数据。通过tokenizer将数据decode为文字查看数据是否异常;同时可尝试跳过这批数据进行训练,验证是否由数据导致。 + +* 检查在突变附近是否有精度溢出情况。 + +* 可以查看local norm是否有异常,Dump突变step的训练数据,排查计算的突变点,分析是否算子异常输出。 + +#### loss后期差异较大 + +长稳测试中,还可能出现训练前期拟合较好,后期收敛loss出现较大差异,如图所示: + +![loss2](./image/loss2.png) + +在该场景下,可从如下角度进行排查: + +* 排查参数是否对齐:重点排查与优化器相关的参数,如优化器类型、learning rate、weight decay等。可通过画图对比训练过程中的learning rate变化是否一致,另外需要确认进行weight decay的权重是否与标杆一致。 + +* 混合精度排查:通过Dump工具,细致排查计算过程中混合精度是否与标杆一致; + +* 若收敛时loss存在差异,但差异很小,如小于1%,可通过评测下游任务进行精度验收。 + +#### 场景扩展 + +在完成单卡对齐的情况下,逐步由单卡扩展为多卡测试、集群测试;模型规模、相关特性如模型并行、流水并行、优化器并行等,视情况添加。由简单场景逐步扩展至实际训练的场景,从而排查新增的特性对精度的影响。 + +### 案例详解 + +本节将结合实际案例,介绍基于上述的精度定位流程完成精度排查。 + +#### 问题现象 + +在128卡集群下训练模型,使用 Ascend+MindSpore 训练与 GPU+PyTorch 训练进行对比,发现训练后期收敛的loss比 GPU+PyTorch 高0.1左右。如图所示,收敛不符合预期: + +![loss3](./image/loss3.png) + +蓝色线为 Ascend+MindSpore 训练曲线,红色线为 GPU+PyTorch 训练曲线。 + +#### 问题定位过程 + +在定位前,先对照CheckList进行检查,确认无误后启动问题的定位。 + +首先step1的loss对齐确认没问题。对比step1的local norm,计算每个权重的Local norm值与标杆的差异,Embedding权重的local norm值与标杆的差异大。 + +![local norm](./image/local_norm.png) + +排查原因为MindFormers使用fp32进行权重初始化,前向计算及反向计算embedding时均使用fp32精度计算;而PyTorch的前向及反向计算均为bf16,由此导致了计算出来的local norm值存在差异。 + +计算精度对齐后,排查优化器计算也没有问题,开始进行长稳训练对齐。 + +长稳训练排查将由单卡实验扩展到多卡实验,先设置learning rate=0, 即权重不更新。前向计算每个step的loss差异在0.001左右,前向计算误差符合预期。反向计算每个step的global norm差异在0.05左右,反向计算差异不大;初步判断模型迁移代码正确,模型结构一致,前反向计算差异不大。 + +![loss4](./image/loss4.png) + +再权重更新,单卡训练,设置learning rate=1e-5,训练1千step。收敛后期loss有稳定的0.1的差异,复现问题。 + +![loss5](./image/loss5.png) + +进行问题排查。识别如下问题: + +* 通过Dump的文件排查,识别训练过程中存在计算精度不一致的地方,并将不一致的地方统一。 + +* Weight decay实现不一致,用户PyTorch网络所有权重均进行weight decay。MindFormers中bias权重及一维权重默认不进行weight decay。 + +修复问题后,再次进行实验,训练1万step, loss差异在0轴附近波动,且小于0.03, 精度符合预期,单卡精度对齐。 + +完成单卡训练后,启动多卡训练测试:设置learning rate=1e-5,训练1千step。训练后期收敛一致,但训练中期存在稳定的0.05误差。 + +![loss6](./image/loss6.png) + +为验证该误差为合理范围内,关闭确定性计算,重复跑两次GPU实验。图中红线为MindSpore训练的曲线,蓝色、绿色线分别是第一次、第二次GPU训练的曲线。在7K step左右训练不稳定处,MindSpore训练的曲线正处于两次GPU训练的曲线之间,说明误差处于合理范围内,问题最终解决。 + +![loss7](./image/loss7.png) + +## 附录 + +当前MindFormers暂不支持直接读取PyTorch的bin数据集。当前可参考如下方法,保证Megtron读取相同数据,将Megtron中训练数据保存为npy。修改[pretrain_gpt.py](https://github.com/NVIDIA/Megatron-LM/blob/main/pretrain_gpt.py): + +```python +import numpy as np +import os + +step_num = 0 +def get_path(local_rank): + global step_num + path = f"path/step_{step_num}/rank_{local_rank}" + os.makedirs(path, exist_ok=True) + return path + +def forward_step(data_iterator, model: GPTModel): + ... + tokens, labels, loss_mask, attention_mask, position_ids = get_batch(data_iterator) + + local_rank = torch.distributed.get_rank() + path = get_path(local_rank) + print(f"paht is f{path}") + + global step_num + step_num += 1 + + tokens_npy = tokens.cpu().numpy() + np.save(os.path.join(path, 'tokens.npy'), tokens_npy) + labels_npy = labels.cpu().numpy() + np.save(os.path.join(path, 'labels.npy'), labels_npy) + loss_mask_npy = loss_mask.cpu().numpy() + np.save(os.path.join(path, 'loss_mask.npy'), loss_mask_npy) + attention_mask_npy = attention_mask.cpu().numpy() + np.save(os.path.join(path, 'attention_mask.npy'), attention_mask_npy) + ... +``` + +数据按照如下目录结构保存: + +```text +├── step_0 +│ ├── rank_0 +│ │ ├── attention_mask.npy +│ │ ├── labels.npy +│ │ ├── loss_mask.npy +│ │ └── tokens.npy +│ ├── rank_1 +│ │ ├── attention_mask.npy +│ │ ├── labels.npy +│ │ ├── loss_mask.npy +│ │ └── tokens.npy +│ ├── rank_2 +....... +│ └── rank_7 +│ ├── attention_mask.npy +│ ├── labels.npy +│ ├── loss_mask.npy +│ └── tokens.npy +├── step_1 +....... +├── step_2 +....... +``` + +MindFormers中每个step读取相应的数据进行训练。方式如下: + +新建nump_dataset.py并放入mindformers/dataset/,nump_dataset.py代码如下: + +```python +import os +import copy +from glob import glob +import numpy as np +import mindspore as ms +from mindspore.dataset.transforms import TypeCast +from mindspore.dataset import GeneratorDataset +from mindformers.tools.logger import logger +from mindformers.version_control import get_dataset_map +from mindformers.tools.register import MindFormerRegister, MindFormerModuleType +from mindformers.tools.utils import get_real_rank +from .base_dataset import BaseDataset + +class NumpyDataset: + def __init__(self, dataset_dir, rank_id): + self.token_list = [] + self.label_list = [] + self.index = [] + logger.info("dataset rank_id: %d", rank_id) + logger.info("dataset dir: %s", dataset_dir) + steps_dir = os.listdir(dataset_dir) + logger.info(f"steps dir: {steps_dir}") + new_steps_dir = [] + for step_dir in steps_dir: + if not step_dir.startswith("step_"): + continue + new_steps_dir.append(step_dir) + steps_dir = new_steps_dir + logger.info(steps_dir) + steps_dir.sort(key=lambda x: int(x.split("_")[1])) + for step_dir in steps_dir: + step_index = int(step_dir.split("_")[1]) + data_dir = os.path.join(dataset_dir, step_dir, f"rank_{rank_id}") + token_path = os.path.join(data_dir, "tokens.npy") + label_path = os.path.join(data_dir, "labels.npy") + token = np.load(token_path) + self.token_list.append(token[0]) + label = np.load(label_path) + self.label_list.append(label[0]) + self.index.append(step_index) + logger.info(self.index) + logger.info("get %d numpy data.", len(self.index)) + logger.info("==========NumpyDataset init succeed==========") + + def __len__(self): + return len(self.token_list) + + def __getitem__(self, index): + return self.token_list[index], self.label_list[index] + +@MindFormerRegister.register(MindFormerModuleType.DATASET) +class NumpyDataloader(BaseDataset): + def __new__(cls, dataset_config): + logger.info("Now create Numpy Dataset") + dataset_config = cls.check_dataset_config(dataset_config, locals()) + dataset_config = copy.deepcopy(dataset_config) + cls.init_dataset_config(dataset_config) + rank_id, device_num = cls._generate_shard_info() + dataset_config.rank_id = rank_id + dataset_config.device_num = device_num + + dataset = cls._process_numpy_data(dataset_config) + + type_cast_op = TypeCast(ms.int32) + dataset = dataset.batch(dataset_config.batch_size, drop_remainder=dataset_config.drop_remainder, + output_columns=dataset_config.input_columns, + num_parallel_workers=dataset_config.num_parallel_workers) + dataset = dataset.project(columns=dataset_config.input_columns) + for input_arg in dataset_config.input_columns: + dataset = get_dataset_map(dataset, type_cast_op, + input_columns=input_arg) + dataset = dataset.repeat(dataset_config.repeat) + return dataset + + @classmethod + def _process_numpy_data(cls, dataset_config): + dataset_dir = dataset_config.data_loader.dataset_dir + rank_id = get_real_rank() + dataset = NumpyDataset(dataset_dir, rank_id) + dataloader = GeneratorDataset(source=dataset, column_names=dataset_config.input_columns, + num_shards=None, shard_id=None, shuffle=dataset_config.data_loader.shuffle, + python_multiprocessing=dataset_config.python_multiprocessing) + return dataloader +``` + +[mindformers/dataset/\_\_init\_\_.py](https://gitee.com/mindspore/mindformers/blob/dev/mindformers/dataset/__init__.py) 添加: + +```python +from .numpy_dataset import NumpyDataloader +``` + +yaml配置参考: + +```yaml +train_dataset: &train_dataset + data_loader: + dataset_dir: "xx/xx/path" + shuffle: False #True + input_columns: ["input_ids", "labels"] + num_parallel_workers: 8 + python_multiprocessing: False + drop_remainder: True + batch_size: 1 + repeat: 1 + numa_enable: False + prefetch_size: 1 +train_dataset_task: + type: NumpyDataloader + dataset_config: *train_dataset +``` + +启动训练,即可读Megatron保存下来的numpy数据进行训练。 \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/general_process.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/general_process.png new file mode 100644 index 0000000000000000000000000000000000000000..400b15ba5a899e1a910c1040c31d0d80a03caafb Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/general_process.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/local_norm.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/local_norm.png new file mode 100644 index 0000000000000000000000000000000000000000..c648c187c6be5da9dc29c360f5c527fb0d40b644 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/local_norm.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss1.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss1.png new file mode 100644 index 0000000000000000000000000000000000000000..c665b20eaf5ff0b40f0da7c6dd7724cc219e9491 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss1.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss2.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss2.png new file mode 100644 index 0000000000000000000000000000000000000000..fef240e4e62ddb3b342877efd0c0c6e908462dff Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss2.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss3.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss3.png new file mode 100644 index 0000000000000000000000000000000000000000..15cfd9315ec6ad44caf532e0901d71fb8dfc3c80 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss3.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss4.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss4.png new file mode 100644 index 0000000000000000000000000000000000000000..24fe8e8d01c7afa149d65eaab8eee89a7b600bc5 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss4.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss5.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss5.png new file mode 100644 index 0000000000000000000000000000000000000000..355cf5e1c247c8aff4938c7bc7756e318cc2ff2e Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss5.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss6.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss6.png new file mode 100644 index 0000000000000000000000000000000000000000..c4061f5c18e886d1036001c0d509e0a3974b8684 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss6.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss7.png b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss7.png new file mode 100644 index 0000000000000000000000000000000000000000..4260277be9d8f46619b7e26531adee7c4f4138b4 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/acc_optimize/image/loss7.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/appendix/conf_files.md b/docs/mindspore/source_zh_cn/mindformers/appendix/conf_files.md new file mode 100644 index 0000000000000000000000000000000000000000..b731f640eae13c81b0036fdcfae1eaf179a0ad4d --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/appendix/conf_files.md @@ -0,0 +1,230 @@ +# 配置文件说明 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/appendix/conf_files.md) + +## 概述 + +在模型的训练和推理过程中通常需要配置不同的参数,MindFormers支持使用`YAML`文件集中管理和调整可配置项,使模型的配置更加结构化,同时提高了其可维护性。 + +## YAML文件内容说明 + +MindFormers提供的`YAML`文件中包含对于不同功能的配置项,下面按照配置项的内容对其进行说明。 + +### 基础配置 + +基础配置主要用于指定MindSpore随机种子以及加载权重的相关设置。 + +| 参数 | 说明 | 类型 | +|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------| +| seed | 设置全局种子,详情可参考[mindspore.set_seed](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.set_seed.html) | int | +| run_mode | 设置模型的运行模式,可选`train`, `finetune`, `eval`或`predict` | str | +| output_dir | 设置保存log, checkpoint, strategy等文件的路径 | str | +| load_checkpoint | 加载权重的文件或文件夹路径,目前有3个应用场景:
    1. 支持传入完整权重文件路径
    2. 支持传入离线切分后的权重文件夹路径
    3. 支持传入包含lora权重和base权重的文件夹路径
    各种权重的获取途径可参考[权重转换功能](https://www.mindspore.cn/docs/zh-CN/master/mindformers/function/weight_conversion.html) | str | +| auto_trans_ckpt | 开启在线权重自动转换功能,详情可参考[权重转换功能](https://www.mindspore.cn/docs/zh-CN/master/mindformers/function/weight_conversion.html) | bool | +| resume_training | 开启断点续训功能,详情可参考[断点续训功能](https://www.mindspore.cn/docs/zh-CN/master/mindformers/function/res_training.html) | bool | + +### Context配置 + +Context配置主要用于指定[mindspore.set_context](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.set_context.html)中的相关参数。 + +| 参数 | 说明 | 类型 | +|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|----------| +| context.mode | 设置后端执行模式,`0`表示GRAPH_MODE,MindFormers目前仅支持在GRAPH_MODE模式下运行 | int | +| context.device_target | 设置后端执行设备,MindFormers仅支持在`Ascend`设备上运行 | str | +| context.device_id | 设置执行设备ID,其值必须在可用设备范围内,默认值为`0` | int | +| context.enable_graph_kernel | 开启图算融合去优化网络执行性能, 默认值为`False`,详情可参考[图算融合](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/graph_fusion_engine.html) | bool | +| context.max_call_depth | 设置函数调用的最大深度,其值必须为正整数,默认值为`1000` | int | +| context.max_device_memory | 设置设备可用的最大内存,格式为"xxGB",默认值为`1024GB` | str | +| context.save_graphs | 在执行过程中保存编译图。
    1. `False`或`0`表示不保存中间编译图。
    2. `1`表示运行时会输出图编译过程中生成的一些中间文件。
    3. `True`或`2`表示生成更多后端流程相关的IR文件。
    4. `3`表示生成可视化计算图和更多详细的前端IR图。 | bool/int | + +### 模型配置 + +由于不同的模型配置会有差异,这里仅对MindFormers中模型的通用配置进行说明。 + +| 参数 | 说明 | 类型 | +|--------------------------------------------|--------------------------------------------------------------------------------------------------|------| +| model.arch.type | 设置模型类,构建模型时可以根据模型类对模型进行实例化 | str | +| model.model_config.type | 设置模型配置类,模型配置类需要与模型类匹配使用,即模型配置类中应包含所有模型类使用的参数 | str | +| model.model_config.num_layers | 设置模型层数,通常指模型Decoder Layer的层数 | int | +| model.model_config.seq_length | 设置模型序列长度,该参数表示模型所支持的最大序列长度 | int | +| model.model_config.hidden_size | 设置模型隐藏状态的维数 | int | +| model.model_config.vocab_size | 设置模型词表大小 | int | +| model.model_config.top_k | 设置推理时从概率最大的`top_k`个tokens中采样 | int | +| model.model_config.top_p | 设置推理时从概率最大且概率累计不超过`top_p`的tokens中采样 | int | +| model.model_config.use_past | 开启模型增量推理,开启后可使用Paged Attention提升推理性能,在模型训练时必须设置为`False` | bool | +| model.model_config.max_decode_length | 设置生成文本的最大长度,包括输入长度 | int | +| model.model_config.max_length | 同`max_decode_length`,与`max_decode_length`同时设置时,`max_length`生效 | int | +| model.model_config.max_new_tokens | 设置生成新文本的最大长度,不包括输入长度,与`max_length`同时设置时,`max_new_tokens`生效 | int | +| model.model_config.min_length | 设置生成文本的最小长度,包括输入长度 | int | +| model.model_config.min_new_tokens | 设置生成新文本的最小长度,不包括输入长度,与`min_length`同时设置时,`min_new_tokens`生效 | int | +| model.model_config.repetition_penalty | 设置生成重复文本的惩罚系数,`repetition_penalty`不小于1,等于1时不对重复输出进行惩罚 | int | +| model.model_config.block_size | 设置Paged Attention中block的大小,仅`use_past=True`时生效 | int | +| model.model_config.num_blocks | 设置Paged Attention中block的总数,仅`use_past=True`时生效,应满足`batch_size×seq_length<=block_size×num_blocks` | int | +| model.model_config.return_dict_in_generate | 设置以字典形式返回`generate`接口的推理结果,默认为`False` | bool | +| model.model_config.output_scores | 设置以字典形式返回结果时,包含每次前向生成时的输入softmax前的分数,默认为`False` | bool | +| model.model_config.output_logits | 设置以字典形式返回结果时,包含每次前向生成时模型输出的logits,默认为`False` | bool | + +### 模型训练配置 + +启动模型训练时,除了模型相关参数,还需要设置trainer、runner_config、学习率以及优化器等训练所需模块的参数,MindFormers提供了如下配置项。 + +| 参数 | 说明 | 类型 | +|---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------| +| trainer.type | 设置trainer类,通常不同应用场景的模型会设置不同的trainer类 | str | +| trainer.model_name | 设置模型名称,格式为'{name}_xxb',表示模型的某一规格 | str | +| runner_config.epochs | 设置模型训练的轮数 | int | +| runner_config.batch_size | 设置批处理数据的样本数,该配置会覆盖数据集配置中的`batch_size` | int | +| runner_config.sink_mode | 开启数据下沉模式,详情可参考[下沉模式](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/train_optimize.html) | bool | +| runner_config.sink_size | 设置每次从Host下发到Device的迭代数量,仅`sink_mode=True`时生效 | int | +| runner_config.gradient_accumulation_steps | 设置梯度累积步数,默认值为1,表示不开启梯度累积 | int | +| runner_wrapper.type | 设置wrapper类,一般设置'MFTrainOneStepCell'即可 | str | +| runner_wrapper.scale_sense.type | 设置梯度缩放类,一般设置'DynamicLossScaleUpdateCell'即可 | str | +| runner_wrapper.scale_sense.use_clip_grad | 开启梯度剪裁,开启可避免反向梯度过大导致训练无法收敛的情况 | bool | +| runner_wrapper.scale_sense.loss_scale_value | 设置loss动态尺度系数,模型loss可以根据该参数配置动态变化 | int | +| lr_schedule.type | 设置lr_schedule类,lr_schedule主要用于调整模型训练中的学习率 | str | +| lr_schedule.learning_rate | 设置初始化学习率大小 | float | +| lr_scale | 是否开启学习率缩放 | bool | +| lr_scale_factor | 设置学习率缩放系数 | int | +| layer_scale | 是否开启层衰减 | bool | +| layer_decay | 设置层衰减系数 | float | +| optimizer.type | 设置优化器类,优化器主要用于计算模型训练的梯度 | str | +| optimizer.weight_decay | 设置优化器权重衰减系数 | float | +| train_dataset.batch_size | 同`runner_config.batch_size` | int | +| train_dataset.input_columns | 设置训练数据集输入的数据列 | list | +| train_dataset.output_columns | 设置训练数据集输出的数据列 | list | +| train_dataset.column_order | 设置训练数据集输出数据列的顺序 | list | +| train_dataset.num_parallel_workers | 设置读取训练数据集的进程数 | int | +| train_dataset.python_multiprocessing | 开启Python多进程模式提升数据处理性能 | bool | +| train_dataset.drop_remainder | 是否在最后一个批处理数据包含样本数小于batch_size时,丢弃该批处理数据 | bool | +| train_dataset.repeat | 设置数据集重复数据次数 | int | +| train_dataset.numa_enable | 设置NUMA的默认状态为数据读取启动状态 | bool | +| train_dataset.prefetch_size | 设置预读取数据量 | int | +| train_dataset.data_loader.type | 设置数据加载类 | str | +| train_dataset.data_loader.dataset_dir | 设置加载数据的路径 | str | +| train_dataset.data_loader.shuffle | 是否在读取数据集时对数据进行随机排序 | bool | +| train_dataset.transforms | 设置数据增强相关选项 | bool | +| train_dataset_task.type | 设置dataset类,该类用于对数据加载类以及其他相关配置进行封装 | str | +| train_dataset_task.dataset_config | 通常设置为`train_dataset`的引用,包含`train_dataset`的所有配置项 | - | +| auto_tune | 开启数据处理参数自动调优,详情可参考[set_enable_autotune](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.config.set_enable_autotune.html) | bool | +| filepath_prefix | 设置数据优化后的参数配置的保存路径 | str | +| autotune_per_step | 设置自动数据加速的配置调整step间隔,详情可参考[set_autotune_interval](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.config.set_autotune_interval.html) | int | + +### 并行配置 + +为了提升模型的性能,在大规模集群的使用场景中通常需要为模型配置并行策略,详情可参考[分布式并行](https://www.mindspore.cn/docs/zh-CN/master/mindformers/function/distributed_parallel.html),MindFormers中的并行配置如下。 + +| 参数 | 说明 | 类型 | +|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------| +| use_parallel | 开启并行模式 | bool | +| parallel_config.data_parallel | 设置数据并行数 | int | +| parallel_config.model_parallel | 设置模型并行数 | int | +| parallel_config.context_parallel | 设置序列并行数 | int | +| parallel_config.pipeline_stage | 设置流水线并行数 | int | +| parallel_config.micro_batch_num | 设置流水线并行的微批次大小,在`parallel_config.pipeline_stage`大于1时,应满足`parallel_config.micro_batch_num` >= `parallel_config.pipeline_stage` | int | +| parallel_config.gradient_aggregation_group | 设置梯度通信算子融合组的大小 | int | +| micro_batch_interleave_num | 设置多副本并行数,大于1时开启多副本并行。通常在使用模型并行时开启,主要用于优化模型并行产生的通信损耗,仅使用流水并行时不建议开启。详情可参考[MicroBatchInterleaved](https://www.mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.MicroBatchInterleaved.html) | int | +| parallel.parallel_mode | 设置并行模式,`0`表示数据并行模式, `1`表示半自动并行模式, `2`表示自动并行模式, `3`表示混合并行模式,一般设置为半自动并行模式 | int | +| parallel.gradients_mean | 是否在梯度AllReduce后执行平均算子。通常半自动并行模式下设为`False`,数据并行模式下设为`True` | bool | +| parallel.enable_alltoall | 开启在通信期间生成AllToAll通信算子。通常仅在MOE场景下设为`True`,默认值为`False` | bool | +| parallel.full_batch | 设置在并行模式下加载完整batch的数据集,在自动并行模式和半自动并行下设置为`True`,在数据并行模式下设置为`False` | bool | +| parallel.search_mode | 设置全自动并行策略搜索模式,可选`recursive_programming`, `dynamic_programming`和`sharding_propagation`,仅在全自动并行模式下生效,实验性接口 | str | +| parallel.strategy_ckpt_save_file | 设置并行切分策略文件的保存路径 | str | +| parallel.strategy_ckpt_config.only_trainable_params | 是否仅保存(或加载)可训练参数的切分策略信息,默认为True,当网络中存在冻结的参数但又需要切分时将该参数设为`False` | bool | +| parallel.enable_parallel_optimizer | 开启优化器并行。
    1. 在数据并行模式下将模型权重参数按device数进行切分
    2. 在半自动并行模式下将模型权重参数按`parallel_config.data_parallel`进行切分 | bool | +| parallel.parallel_optimizer_config.gradient_accumulation_shard | 设置累计的梯度变量是否在数据并行的维度上进行切分,仅`enable_parallel_optimizer=True`时生效 | bool | +| parallel.parallel_optimizer_config.parallel_optimizer_threshold | 设置优化器权重参数切分的阈值,仅`enable_parallel_optimizer=True`时生效。 | int | +| parallel.parallel_optimizer_config.optimizer_weight_shard_size | 设置优化器权重参数切分通信域的大小,要求该值可以整除`parallel_config.data_parallel`,仅`enable_parallel_optimizer=True`时生效。 | int | + +> 配置并行策略时应满足device_num = data_parallel × model_parallel × context_parallel × pipeline_stage + +### 模型优化配置 + +MindFormers提供重计算相关配置,以降低模型在训练时的内存占用,详情可参考[重计算](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/recompute.html)。 + +| 参数 | 说明 | 类型 | +|----------------------------------------------------|-------------------------------|-----------| +| recompute_config.recompute | 开启重计算 | bool | +| recompute_config.select_recompute | 开启选择重计算,只针对attention层的算子进行重计算 | bool/list | +| recompute_config.parallel_optimizer_comm_recompute | 是否对由优化器并行引入的AllGather通信进行重计算 | bool/list | +| recompute_config.mp_comm_recompute | 是否对由模型并行引入的通信进行重计算 | bool | +| recompute_config.recompute_slice_activation | 是否对保留在内存中的Cell输出切片 | bool | + +### Callbacks配置 + +MindFormers提供封装后的Callbacks函数类,主要实现在模型训练过程中返回模型的训练状态并输出、保存模型权重文件等一些操作,目前支持以下几个Callbacks函数类。 + +1. MFLossMonitor + + 该回调函数类主要用于在训练过程中对训练进度、模型Loss、学习率等信息进行打印。 + +2. SummaryMonitor + + 该回调函数类主要用于收集Summary数据,详情可参考[mindspore.SummaryCollector](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.SummaryCollector.html)。 + +3. CheckpointMonitor + + 该回调函数类主要用于在模型训练过程中保存模型权重文件,有如下几个可配置项: + + | 参数 | 说明 | 类型 | + |-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|------| + | prefix | 设置保存文件名称的前缀 | str | + | directory | 设置保存文件名称的目录 | str | + | save_checkpoint_seconds | 设置保存模型权重的间隔秒数 | int | + | save_checkpoint_steps | 设置保存模型权重的间隔steps数 | int | + | keep_checkpoint_max | 设置保存模型权重文件的最大数量,如果保存路径内存在超出数量的模型权重文件,会从创建时间最早的文件开始删除,以保证文件总数不超过`keep_checkpoint_max` | int | + | keep_checkpoint_per_n_minutes | 设置保存模型权重的间隔分钟数 | int | + | integrated_save | 开启聚合保存权重文件。
    1. 设为True时表示在保存权重文件时聚合所有device的权重,即所有device权重一致
    2. 设为False时表示所有device各自保存自己的权重
    使用半自动并行模式时通常需要设置为False,以避免保存权重文件时出现内存问题 | bool | + | save_network_params | 设置仅保存模型权重,默认值为`False` | bool | + | save_trainable_params | 设置额外保存可训练的参数权重,即部分微调时模型的参数权重,默认为`False`。 | bool | + | async_save | 设置异步执行保存模型权重文件 | bool | + +在`callbacks`字段下可同时配置多个Callbacks函数类,以下是`callbacks`配置示例。 + +```yaml +callbacks: + - type: MFLossMonitor + - type: CheckpointMonitor + prefix: "name_xxb" + save_checkpoint_steps: 1000 + integrated_save: False + async_save: False +``` + +### Processor配置 + +Processor主要用于对输入模型的推理数据进行预处理,由于Processor配置项不固定,这里仅对MindFormers中的Processor通用配置项进行说明。 + +| 参数 | 说明 | 类型 | +|--------------------------------|--------------------------------------|-----| +| processor.type | 设置数据处理类 | str | +| processor.return_tensors | 设置数据处理类返回的张量类型,一般使用'ms' | str | +| processor.image_processor.type | 设置图像数据处理类 | str | +| processor.tokenizer.type | 设置文本tokenizer类 | str | +| processor.tokenizer.vocab_file | 设置文本tokenizer读取文件路径,需要与tokenizer类相对应 | str | + +### 模型评估配置 + +MindFormers提供模型评估功能,同时支持模型边训练边评估功能,以下是模型评估相关配置。 + +| 参数 | 说明 | 类型 | +|---------------------|-------------------------------------------------------------|------| +| eval_dataset | 使用方式与`train_dataset`相同 | - | +| eval_dataset_task | 使用方式与`eval_dataset_task`相同 | - | +| metric.type | 使用方式与`callbacks`相同 | - | +| do_eval | 开启边训练边评估功能 | bool | +| eval_step_interval | 设置评估的step间隔, 默认值为100,设置小于0表示关闭根据step间隔评估功能 | int | +| eval_epoch_interval | 设置评估的epoch间隔, 默认值为-1,设置小于0表示关闭根据epoch间隔评估功能,不建议在数据下沉模式使用该配置 | int | +| metric.type | 设置评估的类型 | str | + +### Profile配置 + +MindFormers提供Profile作为模型性能调优的主要工具,详情可参考[性能调优指南](https://www.mindspore.cn/docs/zh-CN/master/mindformers/perf_optimize/perf_optimize.html),以下是Profile相关配置。 + +| 参数 | 说明 | 类型 | +|-----------------------|-----------------------------------------------------------------------------------------------------------------------------|------| +| profile | 开启性能采集工具,详情可参考[mindspore.Profiler](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.Profiler.html) | bool | +| profile_start_step | 设置开始采集性能数据的step数 | int | +| profile_stop_step | 设置停止采集性能数据的step数 | int | +| profile_communication | 设置是否在多设备训练中收集通信性能数据,使用单卡训练时,该参数无效,默认值为`False` | bool | +| profile_memory | 设置是否收集Tensor内存数据 | bool | +| init_start_profile | 设置是否在Profiler初始化时开启采集性能数据,设置`profile_start_step`时该参数不生效。开启`profile_memory`时需要将该参数设为`True`。 | bool | diff --git a/docs/mindspore/source_zh_cn/mindformers/appendix/env_variables.md b/docs/mindspore/source_zh_cn/mindformers/appendix/env_variables.md new file mode 100644 index 0000000000000000000000000000000000000000..5116f6efbec6db84a83923e1412a2e8534dcb436 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/appendix/env_variables.md @@ -0,0 +1,3 @@ +# 环境变量说明 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/appendix/env_variables.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/faq/func_related.md b/docs/mindspore/source_zh_cn/mindformers/faq/func_related.md new file mode 100644 index 0000000000000000000000000000000000000000..cc95c7a1fc8596b281e252401ebe1782d4ca1936 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/faq/func_related.md @@ -0,0 +1,3 @@ +# 功能相关 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/faq/func_related.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/faq/mindformers_contribution.md b/docs/mindspore/source_zh_cn/mindformers/faq/mindformers_contribution.md new file mode 100644 index 0000000000000000000000000000000000000000..c0dd31a7b900fbd7ad33670de858a3a6dfba7378 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/faq/mindformers_contribution.md @@ -0,0 +1,3 @@ +# MindFormers贡献指南 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/faq/mindformers_contribution.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/faq/model_related.md b/docs/mindspore/source_zh_cn/mindformers/faq/model_related.md new file mode 100644 index 0000000000000000000000000000000000000000..30a5ac5645ff850fef8b899491358450a15bf31a --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/faq/model_related.md @@ -0,0 +1,3 @@ +# 模型相关 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/faq/model_related.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/faq/openmind_contribution.md b/docs/mindspore/source_zh_cn/mindformers/faq/openmind_contribution.md new file mode 100644 index 0000000000000000000000000000000000000000..94331866da59b9bf4e73e0a8ad83cf736592d193 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/faq/openmind_contribution.md @@ -0,0 +1,3 @@ +# openMind贡献指南 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/faq/openmind_contribution.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/function/dataset.md b/docs/mindspore/source_zh_cn/mindformers/function/dataset.md new file mode 100644 index 0000000000000000000000000000000000000000..7101fe965d977dfb00fa508f0fd536e5ac758171 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/function/dataset.md @@ -0,0 +1,3 @@ +# 数据集 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/function/dataset.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/function/distributed_parallel.md b/docs/mindspore/source_zh_cn/mindformers/function/distributed_parallel.md new file mode 100644 index 0000000000000000000000000000000000000000..a6994879321deb929a959665aaecf70291fa786c --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/function/distributed_parallel.md @@ -0,0 +1,3 @@ +# 分布式并行 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/function/distributed_parallel.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/function/res_training.md b/docs/mindspore/source_zh_cn/mindformers/function/res_training.md new file mode 100644 index 0000000000000000000000000000000000000000..1e9e9a557b25240ae7b4bece5b3629eaab0c5ef6 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/function/res_training.md @@ -0,0 +1,3 @@ +# 断点续训功能 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/function/res_training.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/function/weight_conversion.md b/docs/mindspore/source_zh_cn/mindformers/function/weight_conversion.md new file mode 100644 index 0000000000000000000000000000000000000000..a2c2fe74fc2425b726925c4bbe9c639d8bac69ee --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/function/weight_conversion.md @@ -0,0 +1,3 @@ +# 权重转换功能 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/function/weight_conversion.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/index.rst b/docs/mindspore/source_zh_cn/mindformers/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..8f8037ba06e038b28a786097034f44bc5696d466 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/index.rst @@ -0,0 +1,124 @@ +MindSpore Transformers 文档 +========================================= + +MindSpore Transformers(也称MindFormers)套件的目标是构建一个大模型训练、微调、评估、推理、部署的全流程开发套件,提供业内主流的Transformer类预训练模型和SOTA下游任务应用,涵盖丰富的并行特性,期望帮助用户轻松地实现大模型训练和创新研发。 + +如果您对MindFormers有任何建议,请通过 `issue `_ 与我们联系,我们将及时处理。 + +MindFormers支持一键启动任意任务的单卡/多卡训练、微调、评估、推理流程,它通过简化操作、提供灵活性和自动化流程,使得深度学习任务的执行变得更加高效和用户友好,用户可以通过以下说明文档进行学习: + +- `开发迁移 `_ +- `预训练 `_ +- `SFT微调 `_ +- `LoRA低参微调 `_ +- `评测 `_ +- `推理 `_ +- `量化 `_ +- `MindIE服务器化部署 `_ + +使用MindFormers进行灵活易用的个性化配置 +-------------------------------------------- + +MindFormers以其强大的功能集,为用户提供了灵活且易于使用的个性化配置选项。具体来说,它具备以下几个关键特性: + +1. `权重切分与合并 `_ + + 不同分布式场景下的权重灵活地进行切分与合并。 + +2. `分布式并行 `_ + + 一键配置多维混合分布式并行,让模型在上至万卡的集群中高效运行。 + +3. `数据集 `_ + + 支持多种形式的数据集。 + +4. `断点续训 `_ + + 支持step级断点续训,有效减少大规模训练时意外中断造成的时间和资源浪费。 + +使用MindFormers进行深度调优 +------------------------------------ + +- `精度调优 `_ +- `性能调优 `_ + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 开始 + :hidden: + + start/overview + start/models + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 快速入门 + :hidden: + + quick_start/install + quick_start/source_code_start + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 使用教程 + :hidden: + + usage/dev_migration + usage/pre_training + usage/sft_tuning + usage/lora_tuning + usage/evaluation + usage/inference + usage/mindie_deployment + usage/quantization + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 功能说明 + :hidden: + + function/weight_conversion + function/distributed_parallel + function/dataset + function/res_training + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 精度调优 + :hidden: + + acc_optimize/acc_optimize + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 性能调优 + :hidden: + + perf_optimize/perf_optimize + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: 附录 + :hidden: + + appendix/env_variables + appendix/conf_files + +.. toctree:: + :glob: + :maxdepth: 1 + :caption: FAQ + :hidden: + + faq/model_related + faq/func_related + faq/mindformers_contribution + faq/openmind_contribution diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/PaLM-MFU.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/PaLM-MFU.png new file mode 100644 index 0000000000000000000000000000000000000000..e5b472da43c03a619a928823da168eade74e7eb4 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/PaLM-MFU.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/big_op.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/big_op.png new file mode 100644 index 0000000000000000000000000000000000000000..3227a79e0e8e145894bab675aa87c31714b6c0dd Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/big_op.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/cast.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/cast.png new file mode 100644 index 0000000000000000000000000000000000000000..d0f0cfdfefd540f8b745ebb9eb04b54d13219141 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/cast.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/communicate.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/communicate.png new file mode 100644 index 0000000000000000000000000000000000000000..95e4d1ae62ea249640249e403fce5065647adc4c Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/communicate.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/llama_layer.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/llama_layer.png new file mode 100644 index 0000000000000000000000000000000000000000..235b408aef41f7b0f3cd2c8c72999a93923f33f0 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/llama_layer.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/llama_memory.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/llama_memory.png new file mode 100644 index 0000000000000000000000000000000000000000..8a5baa95636325e81ac941aeef547059b1f8fbf3 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/llama_memory.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/matmul.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/matmul.png new file mode 100644 index 0000000000000000000000000000000000000000..7f102150782d467df4c992c6a34f5a77cf2baf7b Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/matmul.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/process.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/process.png new file mode 100644 index 0000000000000000000000000000000000000000..d7eb74d4f3354e725b946624affa9d8051ef7606 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/process.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/reshape.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/reshape.png new file mode 100644 index 0000000000000000000000000000000000000000..6f9b5e46046b52db23b521a5bc8f0823b3139508 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/reshape.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/silu_mul.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/silu_mul.png new file mode 100644 index 0000000000000000000000000000000000000000..e7936203dfd07d40a2b7840e9ceba23eff34e76d Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/silu_mul.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/static_memory.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/static_memory.png new file mode 100644 index 0000000000000000000000000000000000000000..16dd9ac352583f31ed307e46f8ade2ee1fd91a09 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/static_memory.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/studio.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/studio.png new file mode 100644 index 0000000000000000000000000000000000000000..cc8037a800a60b6567cfac6a90041c3be23467fb Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/studio.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/timeline.png b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/timeline.png new file mode 100644 index 0000000000000000000000000000000000000000..860457eee818d6779ecea72e71870e63a7345160 Binary files /dev/null and b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/images/timeline.png differ diff --git a/docs/mindspore/source_zh_cn/mindformers/perf_optimize/perf_optimize.md b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/perf_optimize.md new file mode 100644 index 0000000000000000000000000000000000000000..539004b6fa524beec8ca59f886520919afc9e264 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/perf_optimize/perf_optimize.md @@ -0,0 +1,617 @@ +# 大模型性能调优指南 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/perf_optimize/perf_optimize.md) + +## 性能调优概述 + +本文档主要介绍大语言模型的性能调优,详细介绍了性能调优相关的基础理论知识、分析思路和相关工具使用指导,以及案例分享。 + +性能一般讨论的是机器的模型训练性能,在指定模型和输入数据的情况下,以完成一次端到端训练所需要时间作为参考指标。端到端是指完成一个人工智能模型单步训练的过程,时间主要由以下部分构成: + +* 数据加载时间:指的是模型在加载训练数据、权重等数据的时间,包括将数据从硬件存储设备读取到CPU中、CPU中数据的预处理、CPU数据放到device上。对于一些需要切分在若干张卡上的模型,数据加载还包括从数据加载卡广播到其他卡上的时间。 + +* 模型前向反向时间:特指深度学习模型的Forward和Backward,包含前向的数据计算和反向的数据微分求导。 + +* 优化器时间:通常指的是模型参数更新时间。 + +* 模型后处理时间:一般指的是优化器更新后的时间,包括数据的后处理或者一些必要的同步操作,通常取决于模型特有操作。 + +* 通信时间:概念比较宽泛,我们一般将单节点内卡与卡和多节点间的通信行为归为通信时间。通过MindSpore包含的并行技术,通信和计算通常可以并行执行,即通信被掩盖,因此我们一般考虑未被计算掩盖的通信时间。 + +* 调度时间:指的是模型从CPU的指令到调用NPU侧的核所需要的时间。 + +性能调优即通过优化模型算法、参数,优化并行策略等手段,降低上述各部分时间,一般重点针对模型前向反向时间、通信时间进行优化。 + +## 性能调优基础简介 + +### 性能指标 + +性能通常通过吞吐率、算力利用率(MFU和HFU)等指标进行评估。 + +#### 吞吐量 + +对于大语言模型来说,吞吐量主要是看每秒钟每张卡消耗的token数量;计算公式如下: + +$$ +Throughput = SeqLength * (sample/s/p) +$$ + +(sample/s/p)的计算结果可以直接从日志中获取,也可以从日志中分别获取对应字段再进行计算。 + +各字段含义如下: + +* SeqLength:指的是序列的长度,进行文本处理的时候,我们需要将输入的文本转换成数字序列,然后将这些数字序列作为模型的输入。SeqLength就是指这些数字序列的长度,也就是文本的长度。在模型训练和预测的过程中,我们需要指定一个固定的SeqLength,以便进行批处理和计算。较长的SeqLength可以提高模型的准确性,但会增加计算量和内存消耗;而较短的SeqLength则会减少计算量和内存消耗,但可能会降低模型的准确性。 + +* sample:其值等于global_batch_size。在分布式训练中,数据被分成多个部分,每个部分被送到不同的设备上进行计算。这些设备上的batch size加起来就是全局批量大小。 全局批量大小的选择是一个重要的决策,因为它会直接影响模型的训练速度和性能。如果全局批量大小太小,每个设备上的batch size可能会太小,导致模型的收敛速度变慢。如果全局批量大小太大,每个设备上的batch size可能会太大,导致显存不足或者模型的精度下降。要找到最佳Batch Size大小值,一个好的经验法则是达到处理器对给定数据类型的内存限制,即Batch Size占满内存。 + +* s:即per_step_time,指在训练过程中,每一步所花费的时间。 + +* p:即parallel_num,数据并行维度大小。 + +#### 算力利用率 + +MFU是衡量当前算力利用率的情况,不考虑重计算的情况,MFU越高说明当前的计算效率越好,统计的主要是GEMM的计算量。计算公式如下: + +$$ +MFU = \frac{FLOPs}{StepTime * HardwareCapacity} +$$ + +HFU是在MFU的基础上,将反向传播中的重计算计算量考虑在内: + +$$ +MFU = \frac{FLOPs_{recompute}}{StepTime * HardwareCapacity} +$$ + +FLOPs(floating point operations)表示浮点数运算次数,衡量了计算量的大小。如计算矩阵A(m,n)\*B(n,p),需要进行 m\*n\*p 次乘法运算和 m\*n\*p 次加法运算,共计 2\*m\*n\*p 次浮点数运算,即FLOPs为2mnp。 + +StepTime指在训练过程中每一步所花费的时间,HardwareCapacity则为集群中芯片的标称算力。 + +在统计transformer layer的计算量时,根据链式法则,反向传播中,MatMul需要对 $d_x$ 和 $d_w$ 分别求导,因此反向过程的计算量大约是正向的2倍。我们只需要计算出正向传播过程的计算量,然后估算出反向传播的计算量。 + +这里以GPT结构为例,理论估计的结果为: + +| | 激活的内存占用Byte | +| ------------------------ | ---------------------------------------------- | +| 无重计算model flops | 72 * bLs$h^2$ * [1*corr + s/(6h) + v/(12hL)] | +| 选择重计算hardware flops | 72 * bLs$h^2$ * [1*corr + 4/3s/(6h) + v/(12hL)] | +| 完全重计算hardware flops | 72 * bLs$h^2$ * [4/3*corr+ 4/3s/(6h) + v/(12hL)] | + +其中corr = (60+12/q)/72,q为GQA的倍数,q=n_heads/n_kv_heads。重计算带来的增加2倍,原因是Attention中的Q、K、V的前向需要重计算。如果只有前向需要重计算,应该在非重计算 4b$s^2$h(正向) + 8b$s^2$h(反向) = 12b$s^2$h 的基础上变成 4b$s^2$h(正向) + 8b$s^2$h(反向) + 4b$s^2$h(正向)= 16b$s^2$h。重计算增加的开销为16/12=4/3倍。 + +详细计算步骤为: + +| 模块 | 规格 | FLOPS | +|-------------------------|----------------------------------|----------------------------------------| +| attention | | | +| Query, key, Value MatMul | [b, s, h] * [h, h] | (2+4/q)*bs$h^2$ q=n_heads/n_kv_heads | +| QK BatchMatMul | [b, a, s, h/a] * [b, a, h/a, s] | 2b$s^2$h | +| score \* V | [b, a, s, s] * [b, a, s, h/a] | 2b$s^2$h | +| attention projection | [b, s, h] * [h,h] | 2bs$h^2$ | +| MLP | | | +| MLP mapping | [b, s, h] * [h, 4h] | 8bs$h^2$ | +| MLP projection | [b, s, 4h] * [4h, h] | 8bs$h^2$ | +| LmHead | | | +| lmHead projection | [b, s, h] * [v, h] | 2bshv | +| Total | | 2bshv | +| GPTlayer-Total | | (20+4/q)bs$h^2$ + 4b$s^2$h+2bshv | + +各字符含义如下: + +* b:micro batch size +* h:hidden size +* s:seq length +* v:vocab size +* L:layers + +Llama结构(gated FFN,8路GQA)稍有不同,和GPT的差别主要在于mlp层存在差异,在Llama系列中使用的GatedMLP,具体的flops计算如下: + +| MLP mapping | [b, s, h] * [h, $\hat{h}$] | 2bsh$\hat{h}$ | +| ---------------- | ------------------------------------ |----------------------------------------------| +| MLP gate | [b, s, h] * [h, $\hat{h}$] | 2bsh$\hat{h}$ | +| MLP projection | [b, s, $\hat{h}$] * [$\hat{h}$, h] | 2bsh$\hat{h}$ | +| Total | | 6bsh$\hat{h}$ | +| Llamalayer-Total | | (4+4/q)bs$h^2$ + 4b$s^2$h+6bsh$\hat{h}$ + 2bshv | + +注:$\hat{h}$ 为 ffn hidden size + +Llama系列完整的MFU估计值如下: + +![Llama_memory](./images/llama_memory.png) + +HFU/MFU可以用于对于训练性能tokens/s/p的评价。一般HFU>50%属于比较优秀的硬件利用,比如Llama2-7B为4695tokens/s/p,对应的MFU=57%, HFU=65%,属于比较理想的效果。对于大参数模型如Llama2-70B, MFU/HFU会随着并行尺度扩大而线性比衰减。[PaLM](https://arxiv.org/pdf/2204.02311.pdf)统计了几个常见大模型的MFU。 + +![PaLM-MFU](./images/PaLM-MFU.png) + +### 并行特性简介 + +在大模型训练中,由于数据量和模型复杂度的增加,单个计算节点的计算能力难以满足训练的需求。为了提高训练效率和加速训练过程,通常采用并行策略来将计算任务分配给多个计算节点进行计算。 + +并行策略通常分为数据并行(Data Parallelism,简称DP)、模型并行(一般指张量并行Tensor Parallelism,简称TP)、流水并行(Pipeline Parallelism,简称PP)、序列并行(Sequence Paralleism,简称SP)等多种并行模式。在实际应用中,通常会采用同时使用多种并行的混合并行策略,以及多种优化手段,例如使用优化器并行、重计算等方式,以减少模型对内存的使用,提高训练的效率和加速训练的过程。并行策略设计与模型的效率息息相关,在模型调优之前先确定一组或多组较优的并行策略,是至关重要的。 + +详细介绍参考文档并行策略指南。 + +### 内存分析 + +大模型的主流结构都是transformer decoder only的结构,该结构由self attention和ffn两个子层构成。典型的模型Llama2如下图所示: + +![llama_layer](./images/llama_layer.png) + +#### 静态内存 + +参数量定义:模型参数量是指一个神经网络或机器学习模型中可以进行学习和调整的参数的数量。这些参数包括权重(weights)和偏置(biases),它们在训练过程中会不断地更新以优化模型的性能。 + +以GPT结构为例,一层transfomer layer的参数量如下图所示: + +![static_memory](./images/static_memory.png) + +静态内存主要是包含模型的参数和优化器的状态,若使能了梯度累积或者流水线并行则会多一份梯度;设定N为模型参数量,t为优化器并行的规模(默认等于DP),则各个场景下的内存占用如下: + +| | 静态内存占用 | 说明 | +| ------------------- | ------------------ |-------------------------------------------------------------| +| 无并行 | 2N + 4N + 4N = 10N | FP16 weight (2N) FP32 AdamVar (4N) FP32 AdamMomentum (4N) | +| 优化器并行 | 10N / t | 权重和优化器状态切分 | +| 优化器并行+梯度累计 | 10N / t + 2N | 权重切分和优化器状态切分, 梯度累积不切分。 | + +例如一个7B的模型,若t=8,则上述三种场景下的静态内存理论预估值分别为70GB、8.75GB、22.75GB。 + +#### 动态内存 + +以GPT为例,考虑pp、tp等情况,理论计算值如下: + +| | 激活内存[Byte] | 说明 | +| ---------------------------- | ----------------------- |---------------------------------------| +| 无并行 | sbh * [34+5as/h] | 总内存 | +| 模型并行 | sbh * [10+(24+5as/h)/t] | attn/ffn输入、2*ln输入,2dropout mask没有被并行。 | +| 模型并行+序列并行 | sbh * [34+5as/h]/t | 进一步在t维度降低激活 | +| 模型并行+选择重计算 | sbh * [10+24/t] | 重计算 $s^2$ 的激活 | +| 模型并行+序列并行+选择从计算 | sbh * [34/t] | 重计算 $s^2$ 的激活 | +| 完全重计算 | sbh * [2] | 仅保存每层的输入 | + +详细计算步骤为: + +| 模块 | BP需要保存的变量 | 内存大小[Byte] | +|--------------------------| --------------------- | -------------- | +| Attention部分 | | | +| Query, key, Value MatMul | x | 2sbh | +| QK BatchedMatMul | Q, K | 4sbh | +| softmax | softmax result | 2a$s^2$b | +| softmax dropout | dropout mask | a$s^2$b | +| prob-value BatchedMatMul | dropout result and V | 2a$s^2$b + 2sbh | +| attenton projection | dropout mask+output | sbh + 2sbh | +| Totoal | | 11sbh + 5a$s^2$ | +| FFN部分 | | | +| MLP mapping | x | 2sbh | +| MLP activation | hidden | 8sbh | +| MLP projection | activated hidden | 8sbh | +| MLP dropout | dropout mask | sbh | +| Totoal | | 19sbh | +| LayerNorm部分 | | | +| two lanyernorm | input | 2sbh + 2sbh | + +各字符含义如下: + +* a:number of attention heads +* b:micro batch size +* h:hidden size +* L:number of transformer layers +* p:pipeline parallel size +* s:seq length +* t:tensor parallel size +* v:vocab size + +#### 混合精度 + +浮点数据类型主要分为双精度(FP64)、单精度(FP32)、半精度(FP16)。在神经网络模型的训练过程中,一般默认采用单精度(FP32)浮点数据类型,来表示网络模型权重和其他参数。 + +与FP32相比,FP16的存储空间是FP32的一半。类似地,FP32则是FP64的一半。因此使用FP16进行运算具备减少内存占用、计算效率更高、加快通讯效率等优势,但是使用FP16同样会带来数据溢出、舍入误差等问题。 + +在使用混合精度获得训练加速和内存节省的同时,需要考虑FP16引入问题的解决。Loss Scale损失缩放,FP16类型数据下溢问题的解决方案,主要思想是在计算损失值loss的时候,将loss扩大一定的倍数。根据链式法则,梯度也会相应扩大,然后在优化器更新权重时再缩小相应的倍数,从而避免了数据下溢。 + +详细介绍参考文档[自动混合精度](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/mixed_precision.html)。 + +### 工具介绍 + +#### profiler工具 + +MindFormers本身集成了profiling数据采集的功能,使用步骤如下: + +1. 修改配置文件 + + 在模型的配置文件中(例如run_llama2_7b.yaml)开启profiling开关,需修改的参数如下: + + ```yaml + profile: True #是否开启性能分析工具 + profile_start_step: 1 #性能分析开始的step + profile_stop_step: 10 #性能分析结束的step + init_start_profile: False #Profiler初始化的时候开启,开启后profile_start_step将不生效。 + profile_communication: True #是否在多设备训练中收集通信性能数据 + profile_memory: True #收集Tensor内存数据 + ``` + +2. 简化模型 + + 建议将模型的层数(num_layers)改为2层,方便快速采集数据。 + +3. 查看数据 + + 采集的性能数据文件会保存到模型配置文件output_dir(默认“./output”)下创建一个profile的文件夹,按照rank id生成当前机器的每一张卡的性能数据。以rank_0为例,目录为output/profile/rank_0/profiler。 + + 生成的文件及介绍参考[profile文件介绍](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling_ascend.html#目录结构),主要收集算子、任务等运行耗时,CPU利用率,内存消耗等信息,用于性能调优分析需要的各项数据。 + +#### MindStudio Insight + +MindStudio Insight提供了性能数据的多种呈现形式,包括Timeline视图、通信分析、计算耗时等的可视化呈现,以便用户分析潜在的性能瓶颈,并指导如何采取措施消除或减少这些瓶颈。MindStudio Insight支持在Timeline查看集群场景下Profiling导出的数据,并以单卡为维度进行展示,可以支持20GB以上的集群性能文件分析。 + +点击[MindStudio Insight下载链接](https://www.hiascend.com/zh/developer/download/commercial/result?module=sto),选择合适的版本安装。 + +打开MindStudio Insight工具,单击界面左上方工具栏中的“加号”,在弹窗中选择解析并导出的文件或目录,然后单击“确认”导入。 + +MindStudio Insight工具以时间线(Timeline)的呈现方式为用户提供全流程在线推理、训练过程中的运行情况,并按照调度流程来呈现整体的运行状况,并且MindStudio Insight支持集群Timeline展示。通过分析时间线,用户可以对在线推理/训练过程进行细粒度的分析,如迭代间隙是否过长、算子执行时间等,并提供一些易用性功能辅助用户快速定位出性能瓶颈。 + +时间线(Timeline)界面包含工具栏(区域一)、时间线树状图(区域二)、图形化窗格(区域三)和数据窗格(区域四)四个部分组成,如图所示。 + +![studio](./images/studio.png) + +* 区域一 + + 工具栏,包含常用快捷按钮,从左至右依次为列表标记、过滤(支持按卡或按专项层过滤展示)、算子搜索、算子连线、页面自适应和缩放按钮。 + +* 区域二 + + 时间线树状图,显示集群场景下各“Card”的分层信息,一层级为“Card”,二层级为进程或专项分层,三层级为线程等名称。包括上层应用数据(包含上层应用算子的耗时信息)、CANN层数据(包含AscendCL、GE和Runtime组件的耗时数据)、底层NPU数据(包含Ascend Hardware下各个Stream任务流的耗时数据和迭代轨迹数据、HCCL和Overlap Analysis通信数据以及其他昇腾AI处理器系统数据)、打点数据和AI Core Freq层级。 + +* 区域三 + + 图形化窗格,展示的数据是迭代内的数据,图形化窗格对应时间线树状图,逐行对时间线进行图形化展现,包括上层应用算子、各组件及接口的执行序列和执行时长。 + +* 区域四 + + 数据窗格,统计信息或算子详情信息展示区,选中详情(Slice Detail)为选中单个算子的详细信息、选中列表(Slice List)为某一泳道选中区域的算子列表信息、以及系统视图(System View)为某类算子的汇总信息。 + +单击时间线页面树状图或者图形化窗格任意位置,可以使用键盘中的W(放大)、A(左移)、S(缩小)、D(右移)键进行操作,支持放大的最大精度为1ns。本工具可以提供概览、内存、算子、通信等多个维度的分析,辅助进行性能调优。详细使用方法参考[MindStudio Insight用户指南](https://www.hiascend.com/document/detail/zh/mindstudio/70RC2/msinsightug/msascendinsightug/AscendInsight_0002.html)。 + +#### IR 图 + +在MindFormers配置文件中,只需要将save_graphs的开关设置为True,运行时会输出一些图编译过程中生成的ir后缀结尾的中间文件,我们称为IR文件。默认会在当前任务执行目录下生成一个graph的目录,所有的IR图都会保存在这其中。是一种比较直观易懂的以文本格式描述模型结构的文件,可以直接用文本编辑软件查看。 + +节选部分IR图,如下: + +```text + %13(equiv_180_CNode_16165) = Load(%para6_model.layers.0.attention.wq.weight, UMonad[U]) cnode_attrs: {checkpoint: Bool(1)} cnode_primal_attrs: {unique_id: "782039"} + : (, ) -> () + # Fullname with scope: (Default/network-MFPipelineWithLossScaleCell/network-_VirtualDatasetCell/_backbone-GradAccumulationCell/network-LlamaForCausalLM/model-LlamaModel/layers-CellList/0-LLamaDecodeLayer/attention-LLamaAttention/Load-op0) + %14(equiv_16877_x) = PrimFunc_MatMul(%12, %13, Bool(0), Bool(1)) {instance name: matmul} primitive_attrs: {in_strategy: ((1, 1), (8, 1))} cnode_attrs: {checkpoint: Bool(1)} cnode_primal_attrs: {unique_id: "782146", origin_output_shape: (4096, 4096), micro: I64(0), origin_input_shapes: ((4096, 4096), (4096, 4096))} {in_strategy: ((1, 1), (8, 1))} + : (, , , ) -> () + # Fullname with scope: (Default/network-MFPipelineWithLossScaleCell/network-_VirtualDatasetCell/_backbone-GradAccumulationCell/network-LlamaForCausalLM/model-LlamaModel/layers-CellList/0-LLamaDecodeLayer/attention-LLamaAttention/wq-Linear/MatMul-op0) + %15(equiv_16876_CNode_30913) = PrimFunc_Reshape(%14, (I64(1), I64(4096), I64(4), I64(128))) {instance name: reshape} cnode_attrs: {checkpoint: Bool(1)} cnode_primal_attrs: {unique_id: "817859", forward_comm_node_unique_id: "729440", micro: I64(0)} + : (, ) -> () + # Fullname with scope: (Default/network-MFPipelineWithLossScaleCell/network-_VirtualDatasetCell/_backbone-GradAccumulationCell/network-LlamaForCausalLM/model-LlamaModel/layers-CellList/0-LLamaDecodeLayer/attention-LLamaAttention/Reshape-op0) + %16(equiv_16875_query) = PrimFunc_Transpose(%15, (I64(0), I64(2), I64(1), I64(3))) {instance name: transpose} primitive_attrs: {in_strategy: ((1, 1, 8, 1))} cnode_attrs: {checkpoint: Bool(1)} cnode_primal_attrs: {unique_id: "782042", micro: I64(0)} {in_strategy: ((1, 1, 8, 1))} + : (, ) -> () + # Fullname with scope: (Default/network-MFPipelineWithLossScaleCell/network-_VirtualDatasetCell/_backbone-GradAccumulationCell/network-LlamaForCausalLM/model-LlamaModel/layers-CellList/0-LLamaDecodeLayer/attention-LLamaAttention/Transpose-op0) +``` + +`%XX` 表示步骤,后面对应算子名称,括号里面则包含了入参及输出。Fullname with scope则包含了完成的class,方法名等信息。 + +* `%13` + + 此步直接加载wq.weight,得到。 + +* `%14` + + 跟前面的%12输出和上述%13输出进行MatMul,得到。 + +* `%15` + + 上述14%的输出,Reshape得到。 + +* `%16` + + 上述15%的输出,Transpose得到。 + +在保存IR图时建议将模型的层数改小,减少编译存图的时间,方便快速调试。详细内容参考[IR文件介绍](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindir.html#ir文件介绍)和[分析示例](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindir.html#如何根据analyze-failir文件分析图推导失败的原因)。 + +## 性能调优指南 + +### 整体思路 + +大模型的性能优化主要依赖于profiling数据分析以及内存分析,分析当前性能的瓶颈以及与竞品的差距;MindSpore框架上的耗时主要是算子耗时以及通信耗时两部分,其中算子耗时主要是拆解出核心算子与竞品的差距,通信分析查看是否存在不合理的重排布等。 + +完成性能数据以及内存数据采集后,整体优化的流程如下: + +* 分析算子性能,尽量使用融合算子替换中小算子。 + +* 分析通信耗时,查看是否存在更优的分布式策略,分析是否存在不合理的重排布问题,提高整个集群的效率。 + +* 分析内存,查看是否存在异常大内存Tensor,是否存在可融合的算子降低激活值内存;在有内存富裕的情况就可以探讨选择重计算的设置,或者是降低模型切分的份数,减少模型切分带来的通信开销。 + +性能优化是一个循环往复的过程,正如下图所示,算子优化完毕后,就需要对集群分布式策略进行实验分析,分析通信耗时是否合理,是否存在额外的重排布开销;然后进行内存优化分析,完成内存优化后,是否可以重新调整集群策略设置,从而获取更优的策略设定。循环往复的去优化,进而一步步达到设定的性能目标。 + +![process](./images/process.png) + +完成一轮性能优化后,还需要确保模型精度对齐,对齐则应用该优化策略。 + +### 算子性能优化 + +#### GPU与NPU数据对比 + +* 基本思路 + + NPU与GPU算子耗时统计,通过profiling获取数据。 + + 对比GPU和NPU数据,找到单算子耗时差异点。 + + 性能详细分析,根据算子PMU数据分析单case性能,精确识别待优化算子。 + +* 算子耗时统计 + + NPU的算子耗时统计可直接从profiling中获取,分析出当前主要的耗时算子以及低效算子,从而找出需要优化的算子。参考[profiler工具使用介绍](#profiler工具)。 + + GPU 算子耗时统计,参考MindStudio提供的[PyTorch训练Profiling分析方法](https://www.hiascend.com/document/detail/zh/mindstudio/60RC1/quickstart/systemprofilerpt_000001.html)。 + +* 数据拆解关注点 + + 上述[profiler工具](#profiler工具)产生的性能数据中,分析生成数据中的如下文件:rank-*_ascend_ms/ASCEND_PROFILER_OUTPUT/kernel_details.csv。该文件按照算子类型统计某一类型的算子整体占比,可以从中得到需要优化哪一类算子从而带来性能提升。如下图所示,可以看到当前网络TOP耗时的算子是MatMulV2、FA等相关算子。 + + ![big_op](./images/big_op.png) + + NPU和GPU待优化算子数据比对,输出分析结果表格。 以MatMul为例,比对NPU与GPU相同shape下的算子性能差异,重点关注算子耗时占比较高且算力利用率低的shape。 + + ![matmul](./images/matmul.png) + +#### 融合算子 + +算子融合是通过将多个独立的算子组合成一个更大、更复杂的算子,从而减少运行时内存访问、提高计算效率。可以减少中间结果的存储和传输,有效的减少访存的开销;另外,合并多个算子可以减少计算的次数,在NPU等并行计算设备上,可以有效提高计算效率。 + +当前MindFormers默认会自动进行融合算子优化,将模型中符合条件的多个连续小算子自动合并成一个融合算子。 + +### 通信优化 + +在半自动并行开发模式下,需要开发者配置每一个Op算子的输入输出Tensor的并行切分策略,如果存在算子配置不匹配的情况,则会导致MindSpore框架在编译时插入通信算子,对Tensor的进行重排布来适配后续算子的切分方式。常见的通信算子主要是关注AllGather、AllReduce等。 + +分析通信重排布是否合理是利用存IR图加Profiling采集的timeline.json进行分析,通过timeline.json进行可视化查看当前的通信空档,然后更加OP编号去IR图进行通信算子的上下文分析,从而来检查此处的通信算子是否是符合预期(与自己配置的切分策略匹配)。 + +使用[profiler工具](#profiler工具)生成文件ascend_timeline_display_0.json,然后在Chrome浏览器中输入"chrome://tracing"打开文件,也可以使用[MindStudio Insight](#mindstudio-insight)打开,解析出对应的计算通信任务流的时序图。如下: + +![timeline](./images/timeline.png) + +wo-linear之后存在一个计算空档,结合IR图,可以看到在wo-linear之后存在一个AllReduce通信算子,AllReduce接收的是wo-linear的MatMul的输出。IR图如下所示: + +```text +%100(equiv_loss)) = MatMul(%98, %99) {instance name: matmul) primitive_attrs: {IsFeatureMapInputList: (0), input names: [x1, x2], transpose_x2: Bool(1), transpose_b: Bool(1), in strategy: ((1, 4), (1,4)), output names: [output], transpose_a: Bool(0), IsFeatureMapOutput: Bool(1), transpose_x1: Bool(0)} cnode_attrs: (checkpoint: Bool(1), is dynamic_len: Bool(0)} cnode_primal_attrs: (unique id: "230416", micro: I64(0))} + : (, ) -> () + # Fullname with scope: + (Default/network-_VirtualDatasetCell/_backbone-GradAccumulationCell/network-LlamaForCausalLM/model-LlamaModel/lavers-Celllist/1-LLamaDecodeLaver/attention-LhamaAttention/wo-Linear/MatMul-op8) +%101(equiv_CNode_3914) = AllReduce(%100) {instance name: forward_op_6937918150211178578} primitive_attrs: {IaFeatureMapInputList: (0), comm_reuse: Bool(1), group: "hcel_world_group", fusion: 164(0), op: "sum", rank_list: (0, 1, 2, 3), group_ranks: "WORLD_GROUP", index: 164(0), group_rank ids: (0, 1, 2, 3), IsFeatureMapOutput: Bool(1), _parallel_group: "hcel_world_group", no_eliminate: Bool(1)} cnode_attrs: {checkpoint: Bool(1), is_dynamic_len: Bool(0)} cnode_primal_attrs: {unique_id: "231701", forward_comm_node_unique_id: "224263", micro: I64(0)} + : () -> () + # Fullname with scope: + (Default/network- VirtualDatasetCell/ backbone-GradAccumulationCell/network-LlamaForCausalLM/model-LlamaModel/layers-CellList/1-LLamaDecodeLayer/attention-LLamaAttention/wo-Linear/AllReduce-op0) +``` + +可以发现MatMul算子对于两个输入都进行了切分,对第一个输入进行了列切分,第二个输入进行了行切分,此时符合TensorParallel中的Row Parallel Linear的切分方式,此时若要保持MatMul的数学等价则需要对计算结果做AllReduce操作,则此时插入的AllReduce是符合预期。 + +### 并行策略 + +#### 并行策略特点 + +不同的并行策略特点总结如下: + +* 数据并行 + + 多路数据同时训练,仅在梯度更新进行一次通信,性能最优,但内存不会减少; + +* 模型并行 + + 将整个模型切分到不同Device中,网络并行计算各自部分并在LayerNorm等位置进行通信,最省内存,但通信量很大; + +* 流水线并行 + + 将模型的不同阶段(stage)切分到不同Device中,网络串行计算各个阶段并在转换阶段时进行通信,通过重计算节省部分内存,通信量较小,但会存在计算闲置(bubble); + +* 优化器并行 + + 将优化器权重、模型权重按DP切分(DP能整除权重shape的第0维),梯度更新时进行通信,可以明显节省内存,通信量较小; + +* 序列并行 + + 短序列并行在LayerNorm处对序列维按MP进行切分,通信量不变,减少激活内存与Norm的部分计算量; + +* 多副本并行 + + 在模型并行中,MatMul等算子切分为多份,不同副本之间计算通信交错进行,实现通信掩盖; + +#### 使用建议 + +实际应用中,通常是多种并行策略组合使用。根据模型规模,机器数量确定适当的并行策略。本节介绍不同规模模型的推荐配置,示例配置中各配置项含义参考[配置说明](https://gitee.com/mindspore/mindformers/blob/dev/configs/README.md)。 + +* 小参数模型 + + 模型规模较小时(如7B),可使用纯数据并行+优化器并行,如果内存富裕可进一步开启梯度累积。使用8卡训练,[Llama2-7B并行策略推荐配置](https://gitee.com/mindspore/mindformers/blob/dev/configs/llama2/pretrain_llama2_7b.yaml)。 + +* 中等参数模型 + + 模型规模适中时(如13B),可进一步使用流水线并行,并调整重计算。使用8卡训练,[Llama2-13B并行策略推荐配置](https://gitee.com/mindspore/mindformers/blob/dev/configs/llama2/pretrain_llama2_13b.yaml)。 + +* 大参数模型 + + 模型规模较大时(如70B),需开启模型并行,同时序列并行与多副本并行也建议开启。使用64卡训练,[Llama2-70B并行策略推荐配置](https://gitee.com/mindspore/mindformers/blob/dev/configs/llama2/predict_llama2_70b.yaml)。 + +### 重计算 + +#### cast重计算 + +RmsNorm一般使用float32计算,计算之前需要将输入从fp16或bf16 Cast成fp32;RmsNorm需要存下输入用于反向计算。因此,对fp16至fp32的Cast进行重计算,可以将激活内存从RmsNorm的输入变为Cast的输入,Cast的输入的大小为RmsNorm输入大小的一半,从而达到节省内存的效果。 + +![cast](./images/cast.png) + +从高精度到低精度的Cast算子做重计算,会导致后面的算子原本只需要存cast之后的低精度激活内存,Cast算子重计算后,需要存高精度激活内存,反而会导致激活内存变大。 + +#### Silu-Mul重计算 + +在FeedForward中,中间部分激活内存往往会很大;Silu和Mul重计算代价小。对Silu和Mul算子重计算,可以省下w2的MatMul和Mul的第一个输入的激活内存。 + +![silu_mul](./images/silu_mul.png) + +#### 通信重计算 + +在开启序列并行后,RmsNorm会在序列维度切分,之后通过AllGather将不同卡的Tensor进行汇聚以供后面MatMul计算。如果将AllGather重计算,那么每张卡只需要存一份AllGather之前的激活内存,以达到减小内存的效果。 + +![communicate](./images/communicate.png) + +### 内存优化 + +#### Host侧内存分析 + +借助[profiler工具](#profiler工具),profile_memory设置为True,可以收集内存信息。分析方法可以参考[Host侧内存使用情况](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/performance_profiling_ascend.html#host侧内存使用情况)。 + +在训练时遇到host侧宕机挂掉,常常是由于OOM导致,对于此类问题目前主要有以下三种场景: + +* 模型初始化时使用了numpy初始化了超大的Tensor + + 模型脚本初始化时常常会用到numpy初始化的数组来初始化一个MindSpore的Tensor,如果这个Tensor的大小很大则会导致host侧内存OOM,例如下面的代码中会申请一个seq_len*seq_len形状的Tensor,对于序列长度达到128K以上时,则会容易导致Host内存OOM。 + + ```python + class LowerTriangularMaskWithDynamic(Cell): + @_LogActionOnce(m_logger=logger, key='AttentionMask', + no_warning=_get_parallel_mode() in (ParallelMode.STAND_ALONE,)) + def __init__(self, seq_length, compute_type=mstype.float16, + is_dynamic=False, pad_token_id=0, use_flash_attention=False, + use_prompt_flash_attention=False, use_incre_flash_attention=False, use_attn_mask_compression=False): + super().__init__() + # 省略部分代码 + self.multiply_data = Tensor([-10000.0], dtype=compute_type) + self.one = Tensor([1.0], dtype=compute_type) + self.lower_triangle_mask = Tensor(np.tril(np.ones(shape=(seq_length, seq_length), dtype=np.int8)), dtype=compute_type) + ``` + + 针对此类场景,主要规避方法是在construct中根据输入进行生成,可以进行切分并行以及内存复用,从而降低host内存开销,也降低了host静态内存的开销。 + +* 数据预处理内存优化 + + 对于数据预处理中生成数据不宜出现seq_len*seq_len的数据项,在LLM中不建议将mask之类的数据在数据预处理阶段进行生成,MindFormers在训练时采用的是full batch方式,每张卡的进程都会处理global batch size的数据集,由于预处理是流水线模式,会导致host内存逐渐被消耗。 + +* 权重加载时使用的是完整的权重 + + 目前MindFormers中进行分布式训练时,加载权重时每个训练进程都会加载一份权重,例如对于参数为13B的模型,若均是半精度存储则需要2\*13=26GB的内存,若是8卡分布式训练则加载权重至少需要8\*26=208GB的内存;因此加载完整的权重时会消耗较多的Host内存。为此需要开启配置文件的中auto_trans_ckpt的开关,使能权重自动切分,进行切片加载,以此来降低host内存开销。 + + 在Mindformers的配置文件中,开启如下开关: + + ```yaml + auto_trans_ckpt: True + ``` + +#### 峰值显存存分析 + +内存分析时,峰值内存是一个重要的关注点,执行训练时,设置如下环境变量,可以统计内存基本情况。 + + ```shell +export MS_MEMORY_STATISTIC=1 + ``` + +训练完成后,会在日志文件的末尾输出如下信息: + +```text +Device HBM memory size: 62432M +MindSpore Used memory size: 59392M +MindSpore memory base address: 0 +Used peak memory usage (without fragments): 48874M +Actual peak memory usage (with fragments): 48874M +``` + +Used peak memory usage (without fragments)表示不包含碎片的显存使用峰值。 + +Actual peak memory usage (with fragments)表示包含碎片的显存使用峰值。 + +在正式训练前,可以使用dryrun的方式模拟训练,只需要一张卡即可模拟整体的显存峰值。dryrun脚本如下: + +```shell +export ENABLE_CELL_REUSE=1 +export MS_MEMORY_STATISTIC=1 +export MS_SIMULATION_LEVEL=1 +export RANK_SIZE=16 +export RANK_ID=0 +python run_mindformer.py --config ${CONFIG} --run_mode train > dry_run.log 2>&1 & +``` + +其中RANK_SIZE表示要模拟的卡数,RANK_ID表示进行模拟的卡,ENABLE_CELL_REUSE、MS_MEMORY_STATISTIC、MS_SIMULATION_LEVEL三个环境变量用于设置dryrun模式。 + +### 典型案例 + +#### Silu-Mul重计算未生效 + +在开细粒度多副本时,对Silu和Mul做重计算可以节省内存,但关细粒度多副本时,对Silu和Mul做重计算不能节省内存。定位过程如下: + +* 确认配置了重计算 + + 在IR图中检查Cast、Silu和Mul算子是否有“recompute: Bool(1)”的标签,有标签说明算子配了重计算。 + +* 检查重计算生效算子 + + 在IR图中检查是否有Cast、Silu和Mul的duplicated标签的算子,没有带标签的算子说明实际计算图没有重计算这部分算子。这里只有Cast算子带了duplicated标签。 + + ```text + %1834(CNode_108839) = PrimFunc_Cast(%1833, I64(43)) {instance name: cast} primitive_attrs: {output_names: [output], input_names: [x, dst_type], recompute: Bool(1)} cnode_attrs: {recompute_sub_graph: U64(64), recompute_id: I64(65), duplicated: Bool(1), need_cse_after_recompute: Bool(1)} cnode_primal_attrs: {micro: I64(0)} + : (, ) -> () + ``` + +* 检查反向计算输入 + + 在IR图中检查Silu和Mul的反向算子的输入是否符合预期,在关细粒度多副本时,Silu和Mul之间、 Mul和MatMul之间均有Reshape算子,而开启细粒度多副本时,Silu、Mul和MatMul是相连的。绘制相关流程如下: + +![reshape](./images/reshape.png) + +由此可知跟因在于,细粒度多副本场景中Linear的输入shape是二维的,而非细粒度多副本中Linear的输入shape是三维的,导致Linear和Mul之间有Reshape算子,没对这个Reshape重计算导致单纯对Silu的重计算没有用而被优化掉。额外对Reshape重计算后内存可以正常减小。参考配置如下: + +```yaml +recompute_config: + recompute: False + select_recompute: ['feed_forward\.mul', 'feed_forward\.w1\.activation', 'feed_forward\.w1\.reshape', 'feed_forward\.w2\.reshape'] +``` + +#### Llama2-13B极致性能优化 + +13B默认用单机DP: 8, MP: 1, PP: 1,开完全重计算,性能在1860tokens/s/p左右,MFU40%,相较于7B(MFU53%)与70B(MFU47%),性能明显偏低。 + +经分析,13B性能瓶颈主要在于内存,无论是单机还是多机,如果不切MP,则需要开完全重计算,对Silu和Mul做选择重计算内存依然不够;完全重计算会额外多20%到25%的计算量,导致性能偏低;对MP切分可以关闭重计算,但性能比纯DP还要低些。 + +用双机调整切分策略为DP: 8, MP: 1, PP: 2, micro: 128,开完全重计算,性能提升至2136tokens/s/p。将完全重计算改为选择重计算,并精细选择算子,使每层的激活内存尽可能减少,性能提升至2189tokens/s/p。 + +```yaml +select_recompute: ['feed_forward\.mul', 'feed_forward\.w1\.activation', 'feed_forward\.w1\.reshape', 'feed_forward\.w1\.matmul', 'feed_forward\.w3\.matmul', 'feed_forward\.W3\.reshape', 'feed_forward\.w2\.matmul', 'feed_forward\.w2\.reshape', 'ffn_norm\.norm', 'ffn_norm\.rcast', 'attention_norm\.norm', 'attention_norm\.rcast', 'attention\.wq\.reshape', 'attention\.wk\.reshape', 'attention\.wv\.reshape', 'attention\.wo\.matmul', 'attention\.wo\.reshape', 'attention\.merger_head_transpose', 'add', 'attention\.flash attention'] +``` + +调整不同stage的重计算层数,使stage1的重计算量减少,性能提升至2210tokens/s/p。 + +```yaml +select_recompute: + 'feed_forward\.mul': [20, 8] + 'feed_forward\.w1\.activation': [20, 8] + 'feed_forward\.w1\.matmul': [20, 0] + 'feed_forward\.w1\.reshape': [20, 8] + 'feed_forward\.w3\.matmul': [20, 0] + 'feed_forward\.w3\.reshape': [20, 0] + 'feed_forward\.w2\.matmul': [20, 0] + 'feed_forward\.w2\.reshape': [20, 0] + 'ffn_norm\.norm': [20, 0] + 'ffn_norm\.rcast': [20, 0] + 'attention_norm\.norm': [20, 0] + 'attention_normi.rcast': [20, 0] + 'attention\.wq\.reshape': [20, 0]e + 'attention\.wk\.reshape': [20, 0]e + 'attention\.w\.reshape': [20, 0]e + 'attention\.wol.matmul': [20, 0] + 'attention\.wo\.reshape': [20, 0]e + 'attention\.merger head transpose': [20, 0] + 'add': [20, 0] + 'attention\.flash_attention': [20, 0] +``` + +使用O0/O1和dvm图算融合,内存有进一步优化,将大部分算子的选择重计算改为部分层的完全重计算,其余层配置Silu和Mul的选择重计算, stage0、stage1分别完全重计算13层、5层,性能提升至2353tokens/s/p。逐步减少stage0、stage1完全重计算至4层、0层,性能提升至2562tokens/s/p(max_device_memory: 57.2GB)。参考配置如下: + +```yaml +recompute_config: + recompute: [4, 0] + select_recompute: ['feed_forward\.mul', 'feed_forward\.w1\.activation', 'feed_forward\.w1\.reshape', 'feed_forward\.w2\.reshape'] +``` + +最终经过调优后,Llama2-13B性能优化至2562tokens/s/p,MFU55.4%,HFU60.4%,总计提升提升37%。 \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/quick_start/install.md b/docs/mindspore/source_zh_cn/mindformers/quick_start/install.md new file mode 100644 index 0000000000000000000000000000000000000000..0f5ee7c6a67c1b05422a66603c631203156d63f1 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/quick_start/install.md @@ -0,0 +1,50 @@ +# 安装 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/quick_start/install.md) + +## 版本匹配关系 + +当前支持的硬件为[Atlas 800T A2](https://www.hiascend.com/hardware/ai-server?tag=900A2)训练服务器。 + +当前套件建议使用的Python版本为3.9。 + +| MindFormers | MindSpore | CANN | 固件与驱动 | 镜像链接 | +|:-----------:|:------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------:| +| r1.3.0 | [2.3.0](https://www.mindspore.cn/install/) | 8.0.RC2.beta1
    toolkit:[aarch64](https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%208.0.RC2/Ascend-cann-toolkit_8.0.RC2_linux-aarch64.run) [x86_64](https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%208.0.RC2/Ascend-cann-toolkit_8.0.RC2_linux-x86_64.run)
    kernels:[kernels](https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%208.0.RC2/Ascend-cann-kernels-910b_8.0.RC2_linux.run) | firmware:[firmware](https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Ascend%20HDK/Ascend%20HDK%2024.1.RC2/Ascend-hdk-910b-npu-firmware_7.3.0.1.231.run)
    driver: [driver](https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Ascend%20HDK/Ascend%20HDK%2024.1.RC2/Ascend-hdk-910b-npu-driver_24.1.rc2_linux-aarch64.run) | [image](http://mirrors.cn-central-221.ovaijisuan.com/detail/138.html) | + +**当前MindFormers仅支持如上的软件配套关系**。 + +## 环境安装 + +1. 安装固件与驱动:通过[版本匹配关系](https://www.mindspore.cn/docs/zh-CN/master/mindformers/quick_start/install.html#%E7%89%88%E6%9C%AC%E5%8C%B9%E9%85%8D%E5%85%B3%E7%B3%BB)中的固件与驱动链接下载安装包,参考[昇腾官方教程](https://www.hiascend.com/document/detail/zh/quick-installation/24.0.RC1/quickinstg_train/800_9000A2/quickinstg_800_9000A2_0007.html)进行安装。 + +2. 安装CANN和MindSpore:使用官方提供的Docker镜像(镜像中已包含CANN、MindSpore,无需手动安装)或者按照MindSpore官网的[手动安装](https://www.mindspore.cn/install/#%E6%89%8B%E5%8A%A8%E5%AE%89%E8%A3%85)章节进行安装。 + +## MindFormers安装 + +目前仅支持源码编译安装,用户可以执行如下命令安装MindFormers: + +```shell +git clone -b dev https://gitee.com/mindspore/mindformers.git +cd mindformers +bash build.sh +``` + +## 安装验证 + +判断MindFormers是否安装成功可以执行以下命令: + +```shell +import mindformers as mf +mf.run_check() +``` + +出现以下类似结果,证明安装成功: + +```shell +- INFO - MindFormers version: 1.2.0 +- INFO - MindSpore version: 2.3.0 +- INFO - Ascend-cann-toolkit version: 8.0.RC2 +- INFO - Ascend driver version: 24.1.rc2 +- INFO - All checks passed, used **** seconds, the environment is correctly set up! +``` \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/quick_start/source_code_start.md b/docs/mindspore/source_zh_cn/mindformers/quick_start/source_code_start.md new file mode 100644 index 0000000000000000000000000000000000000000..8499efe53344f6477a18158cd4af4d04878f2851 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/quick_start/source_code_start.md @@ -0,0 +1,3 @@ +# 调用源码启动 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/quick_start/source_code_start.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/start/models.md b/docs/mindspore/source_zh_cn/mindformers/start/models.md new file mode 100644 index 0000000000000000000000000000000000000000..6521fbc879c39a94323743879c418c302b21a861 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/start/models.md @@ -0,0 +1,248 @@ +# 模型库 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/start/models.md) + +当前MindFormers支持的模型列表如下: + +
    The Worker and Parameter Server processes register with the Scheduler process to complete the networking.
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    模型 参数 序列 预训练 微调 推理
    LLama2 7B 4K pretrain finetune predict
    13B 4K pretrain finetune predict
    70B 4K pretrain finetune predict
    LLama3 8B 8K pretrain finetune predict
    70B 8K pretrain finetune predict
    Baichuan2 7B 4K - finetune predict
    13B 4K - finetune predict
    GLM2 6B 2K - finetune predict
    GLM3 6B 2K - finetune predict
    GLM3-32K 6B 32K - finetune predict
    Qwen 7B 8K - finetune predict
    14B 8K - finetune predict
    Qwen1.5 7B 32K pretrain finetune predict
    14B 32K pretrain finetune predict
    72B 32K pretrain finetune predict
    Qwen-VL 9.6B 2K - finetune predict
    InternLM 7B 2K - finetune predict
    20B 2K - finetune predict
    InternLM2 7B 2K - finetune predict
    20B 4K - finetune predict
    Yi 6B 2K pretrain finetune predict
    34B 4K pretrain finetune predict
    Mixtral 8x7B 32K pretrain finetune predict
    DeepSeek Coder 33B 4K pretrain finetune predict
    CodeLlama 34B 4K pretrain finetune predict
    GPT2 13B 2K pretrain finetune predict
    \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/start/overview.md b/docs/mindspore/source_zh_cn/mindformers/start/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..c46b8d549f1da0bbbd16062056f6ccccd2a406a3 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/start/overview.md @@ -0,0 +1,3 @@ +# 概览 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/start/overview.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/dev_migration.md b/docs/mindspore/source_zh_cn/mindformers/usage/dev_migration.md new file mode 100644 index 0000000000000000000000000000000000000000..d079d83fcc9efcdf01fae846f09d121721c153cf --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/dev_migration.md @@ -0,0 +1,3 @@ +# 开发迁移 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/dev_migration.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/evaluation.md b/docs/mindspore/source_zh_cn/mindformers/usage/evaluation.md new file mode 100644 index 0000000000000000000000000000000000000000..617841eadb846b645c8372b7d73ecf49bfd2252a --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/evaluation.md @@ -0,0 +1,3 @@ +# 评测 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/evaluation.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/inference.md b/docs/mindspore/source_zh_cn/mindformers/usage/inference.md new file mode 100644 index 0000000000000000000000000000000000000000..049d917358d72d55b1896baedb8f6679717b937e --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/inference.md @@ -0,0 +1,3 @@ +# 推理 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/inference.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/lora_tuning.md b/docs/mindspore/source_zh_cn/mindformers/usage/lora_tuning.md new file mode 100644 index 0000000000000000000000000000000000000000..8115f5d0bfd1f0a63d37c74b1b35469f1f80edaf --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/lora_tuning.md @@ -0,0 +1,3 @@ +# LoRA低参微调 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/lora_tuning.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/mindie_deployment.md b/docs/mindspore/source_zh_cn/mindformers/usage/mindie_deployment.md new file mode 100644 index 0000000000000000000000000000000000000000..301dc631ebfa1817205564c97d075bc610324d1d --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/mindie_deployment.md @@ -0,0 +1,3 @@ +# MindIE服务化部署 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/mindie_deployment.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/pre_training.md b/docs/mindspore/source_zh_cn/mindformers/usage/pre_training.md new file mode 100644 index 0000000000000000000000000000000000000000..43e2f84adbd2b8cd8bc14da6af3237edc414e19d --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/pre_training.md @@ -0,0 +1,3 @@ +# 预训练 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/pre_training.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/quantization.md b/docs/mindspore/source_zh_cn/mindformers/usage/quantization.md new file mode 100644 index 0000000000000000000000000000000000000000..635ebf432d058a150a9e1fbd628b8974897903e8 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/quantization.md @@ -0,0 +1,3 @@ +# 量化 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/quantization.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/mindformers/usage/sft_tuning.md b/docs/mindspore/source_zh_cn/mindformers/usage/sft_tuning.md new file mode 100644 index 0000000000000000000000000000000000000000..0331d2c875205c76b6fe1d0393d2c60275354019 --- /dev/null +++ b/docs/mindspore/source_zh_cn/mindformers/usage/sft_tuning.md @@ -0,0 +1,162 @@ +# SFT微调 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/mindformers/usage/sft_tuning.md) + +## 概述 + +SFT(Supervised Fine-Tuning,监督微调)采用有监督学习思想,是指在源数据集上进行预训练,得到一个原始模型,然后在一个新的数据集上对原始模型进行参数调整,得到新的模型,使其在新的任务上有更好的表现。 + +## SFT微调的基本流程 + +SFT微调整体包含以下几个部分: + +- **预训练:** + 首先需要在一个较大规模的数据集上训练一个神经网络模型,比如针对大语言模型,通常是在大量未标记的文本数据上进行,预训练阶段的目标是使模型获取通用的知识和理解能力。 +- **微调:** + 结合目标任务,用新的训练数据集对已经得到的预训练模型进行微调。在微调过程中,通过反向传播可以对原始模型的全部参数或者部分参数进行优化,使模型在目标任务上取得更好的效果。 +- **评估:** + 经过微调之后会得到一个新的模型,可以用目标任务的评测数据集对微调模型进行评估,从而得到微调模型在目标任务上的性能指标。 + +结合实际操作,可以将SFT微调分解为以下步骤: + +1. **选择预训练模型:** + 选择一个预训练的语言模型,如GPT-2、Llama2等。预训练模型通常是在大型文本语料库上进行过训练,以学习语言的通用表示。 +2. **下载模型权重:** + 针对选择的预训练模型,可以从HuggingFace模型库中下载预训练的权重。 +3. **模型权重转换:** + 结合自己所要使用的框架,对已经下载的HuggingFace权重进行权重转换,比如转换为MindSpore框架所支持的ckpt权重。 +4. **数据集准备:** + 结合微调的目标,选择用于微调任务的数据集,针对大语言模型,微调数据集一般是包含文本和标签的数据,比如alpaca数据集。同时在使用数据集时,需要对数据做相应的预处理,比如使用MindSpore框架时,需要将数据集转换为MindRecord格式。 +5. **执行微调任务:** + 使用微调任务的数据集对预训练模型进行训练,更新模型参数,如果是全参微调则会对所有参数进行更新,微调任务完成后,便可以得到新的模型。 + +## 基于MindFormers的全参微调实践 + +### 选择预训练模型 + +MindFormers目前已经支持业界主流大模型,该实践流程选择Llama2-7B模型SFT微调为例。 + +### 下载模型权重 + +MindFormers提供已经转换完成的预训练权重、词表文件用于预训练、微调和推理,用户也可以下载HuggingFace官方权重经过模型权重转换后进行使用。 + +词表下载链接:[tokenizer.model](https://ascend-repo-modelzoo.obs.cn-east-2.myhuaweicloud.com/MindFormers/llama2/tokenizer.model) + +| 模型名称 | MindSpore权重 | HuggingFace权重 | +|:----------|:------------------------------------------------------------------------------------------------------------:| :---------------------------------------------------------------------------------------------: | +| Llama2-7B | [Link](https://ascend-repo-modelzoo.obs.cn-east-2.myhuaweicloud.com/MindFormers/llama2/llama2_7b.ckpt) | [Link](https://huggingface.co/meta-llama/Llama-2-7b-hf) | + +> Llama2的所有权重都需要通过向Meta[提交申请](https://ai.meta.com/resources/models-and-libraries/llama-downloads)来获取,如有需要请自行申请。 + +### 模型权重转换 + +以[Llama2-7B模型](https://huggingface.co/meta-llama/Llama-2-7b-hf/tree/main)为例,原始的HuggingFace权重文件主要包含:
    + +- `config.json`:模型架构的主要配置信息
    +- `generation_config.json`:文本生成相关的配置信息
    +- `safetensors文件`:模型权重文件
    +- `model.safetensors.index.json`:safetensors模型参数文件索引和描述模型切片的json文件
    +- `bin文件`:pytorch的模型权重文件
    +- `pytorch_model.bin.index.json`:pytorch索引和描述模型切片的json文件
    +- `tokenizer.json`:分词器的词汇配置文件
    +- `tokenizer.model`:模型的分词器
    + +MindFormers提供权重转换脚本,通过执行[convert_weight.py转换脚本](https://gitee.com/mindspore/mindformers/blob/dev/convert_weight.py),可以将HuggingFace的权重转换为完整的ckpt权重。 + +```bash +python convert_weight.py --model llama --input_path TORCH_CKPT_DIR --output_path {path}/MS_CKPT_NAME +``` + +参数说明: + +```commandline +model: 模型名称(其它模型请参考模型说明文档) +input_path: 下载HuggingFace权重的文件夹路径 +output_path: 转换后的MindSpore权重文件保存路径 +``` + +### 数据集准备 + +MindFormers提供**WikiText2**作为预训练数据集,**alpaca**作为微调数据集。 + +| 数据集名称 | 适用模型 | 适用阶段 | 下载链接 | +|:----------|:-------------------------------------:|:---------:| :--------------------------------------------------------------------------------------------------------------------------------------------------------------: | +| alpaca | Llama2-7B
    Llama2-13B
    Llama2-70B | 微调 | [Link](https://github.com/tatsu-lab/stanford_alpaca/blob/main/alpaca_data.json) | + +以alpaca数据集为例,下载数据集后需要对数据集进行预处理。预处理中所用的`tokenizer.model`可以参考模型权重下载进行下载。 + +**alpaca 数据预处理** + +1. 执行MindFormers中的[alpaca_converter.py脚本](https://gitee.com/mindspore/mindformers/blob/dev/mindformers/tools/dataset_preprocess/llama/alpaca_converter.py),将数据集转换为多轮对话格式。 + + ```bash + python alpaca_converter.py \ + --data_path /{path}/alpaca_data.json \ + --output_path /{path}/alpaca-data-conversation.json + ``` + + 参数说明: + + ```commandline + data_path: 输入下载的文件路径 + output_path: 输出文件的保存路径 + ``` + +2. 执行MindFormers中的[llama_preprocess.py脚本](https://gitee.com/mindspore/mindformers/blob/dev/mindformers/tools/dataset_preprocess/llama/llama_preprocess.py),将数据转换为MindRecord格式。该操作依赖fastchat工具包解析prompt模板, 请提前安装fastchat >= 0.2.13 python = 3.9。 + + ```bash + python llama_preprocess.py \ + --dataset_type qa \ + --input_glob /{path}/alpaca-data-conversation.json \ + --model_file /{path}/tokenizer.model \ + --seq_length 4096 \ + --output_file /{path}/alpaca-fastchat4096.mindrecord + ``` + + 参数说明: + + ```commandline + dataset_type: 预处理数据类型 + input_glob: 转换后的alpaca的文件路径 + model_file: 模型tokenizer.model文件路径 + seq_length: 输出数据的序列长度 + output_file: 输出文件的保存路径 + ``` + +### 执行微调任务 + +#### 单机训练 + +以Llama2-7B为例,执行msrun启动脚本,进行8卡分布式训练,启动命令如下: + +```bash +bash scripts/msrun_launcher.sh "run_mindformer.py \ + --config configs/llama2/finetune_llama2_7b.yaml \ + --load_checkpoint /{path}/llama2_7b.ckpt \ + --train_dataset_dir /{path}/alpaca-fastchat4096.mindrecord \ + --use_parallel True \ + --run_mode finetune" 8 +``` + +参数说明: + +```commandline +config: 模型的配置文件,文件在MindFormers代码仓中config目录下 +load_checkpoint: checkpoint文件的路径 +train_dataset_dir: 训练数据集路径 +use_parallel: 是否开启并行 +run_mode: 运行模式,train:训练,fintune:微调,predict:推理 +``` + +任务执行完成后,在mindformers/output目录下,会生成checkpoint文件夹,同时模型文件会保存在该文件夹下。 + +#### 多机训练 + +多机多卡微调任务与启动预训练类似,可参考多机多卡的预训练命令,并对命令进行如下修改: + +1. 增加启动脚本入参`--load_checkpoint /{path}/llama2_7b.ckpt`加载预训练权重。 +2. 设置启动脚本中的`--train_dataset_dir /{path}/alpaca-fastchat4096.mindrecord`加载微调数据集。 +3. 设置启动脚本中的`--run_mode finetune`,run_mode表示运行模式,train:训练,fintune:微调,predict:推理。 + +任务执行完成后,在mindformers/output目录下,会生成checkpoint文件夹,同时模型文件会保存在该文件夹下。 + diff --git a/docs/mindspore/source_zh_cn/model_infer/index.rst b/docs/mindspore/source_zh_cn/model_infer/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..c2233e8af146377e6e3970247d29c8524496f915 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_infer/index.rst @@ -0,0 +1,10 @@ +模型推理 +========================= + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + llm_infer + llm_lite diff --git a/docs/mindspore/source_zh_cn/model_infer/llm_infer.rst b/docs/mindspore/source_zh_cn/model_infer/llm_infer.rst new file mode 100644 index 0000000000000000000000000000000000000000..546a479445a646a75290060dace47a6525b9815c --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_infer/llm_infer.rst @@ -0,0 +1,8 @@ +LLM 推理 +============== + +.. toctree:: + :glob: + :maxdepth: 1 + + model_compression diff --git a/docs/mindspore/source_zh_cn/model_infer/llm_lite.md b/docs/mindspore/source_zh_cn/model_infer/llm_lite.md new file mode 100644 index 0000000000000000000000000000000000000000..06898fcc75b6374ac7cad9c20d72095d47e17432 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_infer/llm_lite.md @@ -0,0 +1,3 @@ +# 端侧推理 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_infer/llm_lite.md) diff --git a/tutorials/experts/source_zh_cn/infer/model_compression.md b/docs/mindspore/source_zh_cn/model_infer/model_compression.md similarity index 97% rename from tutorials/experts/source_zh_cn/infer/model_compression.md rename to docs/mindspore/source_zh_cn/model_infer/model_compression.md index 92c0098404785f4e214d0372fa9d284159660207..07ebb561d4bb42355e81ccd8da1ddb3fb4530954 100644 --- a/tutorials/experts/source_zh_cn/infer/model_compression.md +++ b/docs/mindspore/source_zh_cn/model_infer/model_compression.md @@ -1,6 +1,6 @@ # 模型压缩 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/infer/model_compression.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_infer/model_compression.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/infer/inference.md b/docs/mindspore/source_zh_cn/model_infer/overview.md similarity index 98% rename from tutorials/experts/source_zh_cn/infer/inference.md rename to docs/mindspore/source_zh_cn/model_infer/overview.md index 5538f87af4288c3cd59706fb055a91c448726aa7..a38263b630d0adb1019f6651029204634fa69547 100644 --- a/tutorials/experts/source_zh_cn/infer/inference.md +++ b/docs/mindspore/source_zh_cn/model_infer/overview.md @@ -1,6 +1,6 @@ # 模型推理总览 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/infer/inference.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_infer/overview.md) MindSpore可以基于训练好的模型,在不同的硬件平台上执行推理任务。 diff --git a/docs/mindspore/source_zh_cn/model_train/custom_program/fusion_pass.md b/docs/mindspore/source_zh_cn/model_train/custom_program/fusion_pass.md new file mode 100644 index 0000000000000000000000000000000000000000..f99786b90d4047533c5bafbbe2bfd070df96e754 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/fusion_pass.md @@ -0,0 +1,3 @@ +# 自定义融合pass + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/fusion_pass.md) diff --git a/tutorials/source_zh_cn/advanced/modules/layer.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/hook_program.ipynb similarity index 51% rename from tutorials/source_zh_cn/advanced/modules/layer.ipynb rename to docs/mindspore/source_zh_cn/model_train/custom_program/hook_program.ipynb index 04277283826b148ffe91644e6c5b90b11a591855..b74efb6676b4932be21431f12695330599bc1a70 100644 --- a/tutorials/source_zh_cn/advanced/modules/layer.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/hook_program.ipynb @@ -4,553 +4,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_layer.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_layer.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/modules/layer.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "# Cell与参数\n", - "\n", - "Cell作为神经网络构造的基础单元,与神经网络层(Layer)的概念相对应,对Tensor计算操作的抽象封装,能够更准确清晰地对神经网络结构进行表示。除了基础的Tensor计算流程定义外,神经网络层还包含了参数管理、状态管理等功能。而参数(Parameter)是神经网络训练的核心,通常作为神经网络层的内部成员变量。本节我们将系统介绍参数、神经网络层以及其相关使用方法。" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Parameter\n", - "\n", - "参数(Parameter)是一类特殊的Tensor,是指在模型训练过程中可以对其值进行更新的变量。MindSpore提供`mindspore.Parameter`类进行Parameter的构造。为了对不同用途的Parameter进行区分,下面对两种不同类别的Parameter进行定义:\n", - "\n", - "- 可训练参数。在模型训练过程中根据反向传播算法求得梯度后进行更新的Tensor,此时需要将`required_grad`设置为`True`。\n", - "- 不可训练参数。不参与反向传播,但需要更新值的Tensor(如BatchNorm中的`mean`和`var`变量),此时需要将`requires_grad`设置为`False`。\n", - "\n", - "> Parameter默认设置`required_grad=True`。\n", - "\n", - "下面我们构造一个简单的全连接层:" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "import mindspore\n", - "from mindspore import nn\n", - "from mindspore import ops\n", - "from mindspore import Tensor, Parameter\n", - "\n", - "class Network(nn.Cell):\n", - " def __init__(self):\n", - " super().__init__()\n", - " self.w = Parameter(Tensor(np.random.randn(5, 3), mindspore.float32), name='w') # weight\n", - " self.b = Parameter(Tensor(np.random.randn(3,), mindspore.float32), name='b') # bias\n", - "\n", - " def construct(self, x):\n", - " z = ops.matmul(x, self.w) + self.b\n", - " return z\n", - "\n", - "net = Network()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "在`Cell`的`__init__`方法中,我们定义了`w`和`b`两个Parameter,并配置`name`进行命名空间管理。在`construct`方法中使用`self.attr`直接调用参与Tensor运算。" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "### 获取Parameter\n", - "\n", - "在使用Cell+Parameter构造神经网络层后,我们可以使用多种方法来获取Cell管理的Parameter。" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 获取单个参数\n", - "\n", - "单独获取某个特定参数,直接调用Python类的成员变量即可。" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "ExecuteTime": { - "end_time": "2021-12-29T03:42:22.729232Z", - "start_time": "2021-12-29T03:42:22.723517Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[-1.2192779 -0.36789745 0.0946381 ]\n" - ] - } - ], - "source": [ - "print(net.b.asnumpy())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 获取可训练参数\n", - "\n", - "可使用`Cell.trainable_params`方法获取可训练参数,通常在配置优化器时需调用此接口。" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[Parameter (name=w, shape=(5, 3), dtype=Float32, requires_grad=True), Parameter (name=b, shape=(3,), dtype=Float32, requires_grad=True)]\n" - ] - } - ], - "source": [ - "print(net.trainable_params())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 获取所有参数\n", - "\n", - "使用`Cell.get_parameters()`方法可获取所有参数,此时会返回一个Python迭代器。" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], - "source": [ - "print(type(net.get_parameters()))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "或者可以调用`Cell.parameters_and_names`返回参数名称及参数。" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "w:\n", - "[[ 4.15680408e-02 -1.20311625e-01 5.02573885e-02]\n", - " [ 1.22175144e-04 -1.34980649e-01 1.17642188e+00]\n", - " [ 7.57667869e-02 -1.74758151e-01 -5.19092619e-01]\n", - " [-1.67846107e+00 3.27240258e-01 -2.06452996e-01]\n", - " [ 5.72323874e-02 -8.27963874e-02 5.94243526e-01]]\n", - "b:\n", - "[-1.2192779 -0.36789745 0.0946381 ]\n" - ] - } - ], - "source": [ - "for name, param in net.parameters_and_names():\n", - " print(f\"{name}:\\n{param.asnumpy()}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 修改Parameter\n", - "\n", - "#### 直接修改参数值\n", - "\n", - "Parameter是一种特殊的Tensor,因此可以使用Tensor索引修改的方式对其值进行修改。" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[ 1. -0.36789745 0.0946381 ]\n" - ] - } - ], - "source": [ - "net.b[0] = 1.\n", - "print(net.b.asnumpy())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 覆盖修改参数值\n", - "\n", - "可调用`Parameter.set_data`方法,使用相同Shape的Tensor对Parameter进行覆盖。该方法常用于使用Initializer进行[Cell遍历初始化](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/modules/initializer.html#cell%E9%81%8D%E5%8E%86%E5%88%9D%E5%A7%8B%E5%8C%96)。" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[3. 4. 5.]\n" - ] - } - ], - "source": [ - "net.b.set_data(Tensor([3, 4, 5]))\n", - "print(net.b.asnumpy())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 运行时修改参数值\n", - "\n", - "参数的主要作用为模型训练时对其值进行更新,在反向传播获得梯度后,或不可训练参数需要进行更新,都涉及到运行时参数修改。由于MindSpore的[使用静态图加速](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/accelerate_with_static_graph.html)编译设计,此时需要使用`mindspore.ops.assign`接口对参数进行赋值。该方法常用于[自定义优化器](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/modules/optimizer.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BC%98%E5%8C%96%E5%99%A8)场景。下面是一个简单的运行时修改参数值样例:" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[7. 8. 9.]\n" - ] - } - ], - "source": [ - "import mindspore as ms\n", - "\n", - "@ms.jit\n", - "def modify_parameter():\n", - " b_hat = ms.Tensor([7, 8, 9])\n", - " ops.assign(net.b, b_hat)\n", - " return True\n", - "\n", - "modify_parameter()\n", - "print(net.b.asnumpy())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Parameter Tuple\n", - "\n", - "变量元组ParameterTuple,用于保存多个Parameter,继承于元组tuple,提供克隆功能。\n", - "\n", - "如下示例提供ParameterTuple创建方法:" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(Parameter (name=x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=z, shape=(), dtype=Float32, requires_grad=True))\n", - "(Parameter (name=params_copy.x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=params_copy.y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=params_copy.z, shape=(), dtype=Float32, requires_grad=True))\n" - ] - } - ], - "source": [ - "from mindspore.common.initializer import initializer\n", - "from mindspore import ParameterTuple\n", - "# 创建\n", - "x = Parameter(default_input=ms.Tensor(np.arange(2 * 3).reshape((2, 3))), name=\"x\")\n", - "y = Parameter(default_input=initializer('ones', [1, 2, 3], ms.float32), name='y')\n", - "z = Parameter(default_input=2.0, name='z')\n", - "params = ParameterTuple((x, y, z))\n", - "\n", - "# 从params克隆并修改名称为\"params_copy\"\n", - "params_copy = params.clone(\"params_copy\")\n", - "\n", - "print(params)\n", - "print(params_copy)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## Cell训练状态转换\n", - "\n", - "神经网络中的部分Tensor操作在训练和推理时的表现并不相同,如`nn.Dropout`在训练时进行随机丢弃,但在推理时则不丢弃,`nn.BatchNorm`在训练时需要更新`mean`和`var`两个变量,在推理时则固定其值不变。因此我们可以通过`Cell.set_train`接口来设置神经网络的状态。\n", - "\n", - "`set_train(True)`时,神经网络状态为`train`, `set_train`接口默认值为`True`:" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "train\n" - ] - } - ], - "source": [ - "net.set_train()\n", - "print(net.phase)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`set_train(False)`时,神经网络状态为`predict`:" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "predict\n" - ] - } - ], - "source": [ - "net.set_train(False)\n", - "print(net.phase)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 自定义神经网络层\n", - "\n", - "通常情况下,MindSpore提供的神经网络层接口和function函数接口能够满足模型构造需求,但由于AI领域不断推陈出新,因此有可能遇到新网络结构没有内置模块的情况。此时我们可以根据需要,通过MindSpore提供的function接口、Primitive算子自定义神经网络层,并可以使用`Cell.bprop`方法自定义反向。下面分别详述三种自定义方法。\n", - "\n", - "### 使用function接口构造神经网络层\n", - "\n", - "MindSpore提供大量基础的function接口,可以使用其构造复杂的Tensor操作,封装为神经网络层。下面以`Threshold`为例,其公式如下:\n", - "\n", - "$$\n", - "y =\\begin{cases}\n", - " x, &\\text{ if } x > \\text{threshold} \\\\\n", - " \\text{value}, &\\text{ otherwise }\n", - " \\end{cases}\n", - "$$\n", - "\n", - "可以看到`Threshold`判断Tensor的值是否大于`threshold`值,保留判断结果为`True`的值,替换判断结果为`False`的值。因此,对应实现如下:" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [], - "source": [ - "class Threshold(nn.Cell):\n", - " def __init__(self, threshold, value):\n", - " super().__init__()\n", - " self.threshold = threshold\n", - " self.value = value\n", - "\n", - " def construct(self, inputs):\n", - " cond = ops.gt(inputs, self.threshold)\n", - " value = ops.fill(inputs.dtype, inputs.shape, self.value)\n", - " return ops.select(cond, inputs, value)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "这里分别使用了`ops.gt`、`ops.fill`、`ops.select`来实现判断和替换。下面执行自定义的`Threshold`层:" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Tensor(shape=[3], dtype=Float32, value= [ 2.00000000e+01, 2.00000003e-01, 3.00000012e-01])" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "m = Threshold(0.1, 20)\n", - "inputs = mindspore.Tensor([0.1, 0.2, 0.3], mindspore.float32)\n", - "m(inputs)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "可以看到`inputs[0] = threshold`, 因此被替换为`20`。" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 自定义Cell反向\n", + "# Hook编程\n", "\n", - "在特殊场景下,我们不但需要自定义神经网络层的正向逻辑,也需要手动控制其反向的计算,此时我们可以通过`Cell.bprop`接口对其反向进行定义。在全新的神经网络结构设计、反向传播速度优化等场景下会用到该功能。下面我们以`Dropout2d`为例,介绍如何自定义Cell反向:" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [], - "source": [ - "class Dropout2d(nn.Cell):\n", - " def __init__(self, keep_prob):\n", - " super().__init__()\n", - " self.keep_prob = keep_prob\n", - " self.dropout2d = ops.Dropout2D(keep_prob)\n", - "\n", - " def construct(self, x):\n", - " return self.dropout2d(x)\n", - "\n", - " def bprop(self, x, out, dout):\n", - " _, mask = out\n", - " dy, _ = dout\n", - " if self.keep_prob != 0:\n", - " dy = dy * (1 / self.keep_prob)\n", - " dy = mask.astype(mindspore.float32) * dy\n", - " return (dy.astype(x.dtype), )\n", - "\n", - "dropout_2d = Dropout2d(0.8)\n", - "dropout_2d.bprop_debug = True" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`bprop`方法分别有三个入参:\n", - "\n", - "- *x*: 正向输入,当正向输入为多个时,需同样数量的入参。\n", - "- *out*: 正向输出。\n", - "- *dout*: 反向传播时,当前Cell执行之前的反向结果。\n", - "\n", - "一般我们需要根据正向输出和前层反向结果配合,根据反向求导公式计算反向结果,并将其返回。`Dropout2d`的反向计算需要根据正向输出的`mask`矩阵对前层反向结果进行mask,然后根据`keep_prob`进行缩放。最终可得到正确的计算结果。" + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_hook_program.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_hook_program.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/hook_program.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "自定义Cell反向时,在PyNative模式下支持拓展写法,可以对Cell内部的权重求导,具体列子如下:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "class NetWithParam(nn.Cell):\n", - " def __init__(self):\n", - " super(NetWithParam, self).__init__()\n", - " self.w = Parameter(Tensor(np.array([2.0], dtype=np.float32)), name='weight')\n", - " self.internal_params = [self.w]\n", - "\n", - " def construct(self, x):\n", - " output = self.w * x\n", - " return output\n", - "\n", - " def bprop(self, *args):\n", - " return (self.w * args[-1],), {self.w: args[0] * args[-1]}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`bprop`方法支持*args入参,args数组中最后一位`args[-1]`为返回给该cell的梯度。通过`self.internal_params`设置求导的权重,同时在`bprop`函数的返回值为一个元组和一个字典,返回输入对应梯度的元组,以及以key为权重,value为权重对应梯度的字典。" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Hook功能\n", - "\n", "调试深度学习网络是每一个深度学习领域的从业者需要面对且投入精力较大的工作。由于深度学习网络隐藏了中间层算子的输入、输出数据以及反向梯度,只提供网络输入数据(特征量、权重)的梯度,导致无法准确地感知中间层算子的数据变化,从而降低了调试效率。为了方便用户准确、快速地对深度学习网络进行调试,MindSpore在动态图模式下设计了Hook功能,**使用Hook功能可以捕获中间层算子的输入、输出数据以及反向梯度**。\n", "\n", - "目前,动态图模式下提供了四种形式的Hook功能,分别是:HookBackward算子和在Cell对象上进行注册的register_forward_pre_hook、register_forward_hook、register_backward_hook功能。\n", + "目前,动态图模式下提供了五种形式的Hook功能,分别是:HookBackward算子和在Cell对象上进行注册的register_forward_pre_hook、register_forward_hook、register_backward_pre_hook、register_backward_hook功能。\n", "\n", - "### HookBackward算子\n", + "## HookBackward算子\n", "\n", "HookBackward将Hook功能以算子的形式实现。用户初始化一个HookBackward算子,将其安插到深度学习网络中需要捕获梯度的位置。在网络正向执行时,HookBackward算子将输入数据不做任何修改后原样输出;在网络反向传播梯度时,在HookBackward上注册的Hook函数将会捕获反向传播至此的梯度。用户可以在Hook函数中自定义对梯度的操作,比如打印梯度,或者返回新的梯度。\n", "\n", @@ -559,23 +26,12 @@ }, { "cell_type": "code", - "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2022-03-02T09:13:38.660885Z", - "start_time": "2022-03-02T09:13:38.645597Z" + "end_time": "2024-08-15T03:32:04.585336Z", + "start_time": "2024-08-15T03:32:04.578481Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hook_fn print grad_out: (Tensor(shape=[], dtype=Float32, value= 2),)\n", - "output: (Tensor(shape=[], dtype=Float32, value= 4), Tensor(shape=[], dtype=Float32, value= 4))\n" - ] - } - ], "source": [ "import mindspore as ms\n", "from mindspore import ops\n", @@ -598,16 +54,26 @@ "\n", "output = net(ms.Tensor(1, ms.float32), ms.Tensor(2, ms.float32))\n", "print(\"output:\", output)" - ] + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hook_fn print grad_out: (Tensor(shape=[], dtype=Float32, value= 2),)\n", + "output: (Tensor(shape=[], dtype=Float32, value= 4), Tensor(shape=[], dtype=Float32, value= 4))\n" + ] + } + ], + "execution_count": 15 }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "更多HookBackward算子的说明可以参考[API文档](https://mindspore.cn/docs/zh-CN/master/api_python/ops/mindspore.ops.HookBackward.html)。\n", "\n", - "### Cell对象的register_forward_pre_hook功能\n", + "## Cell对象的register_forward_pre_hook功能\n", "\n", "用户可以在Cell对象上使用`register_forward_pre_hook`函数来注册一个自定义的Hook函数,用来捕获正向传入该Cell对象的数据。该功能在静态图模式下和在使用`@jit`修饰的函数内不起作用。`register_forward_pre_hook`函数接收Hook函数作为入参,并返回一个与Hook函数一一对应的`handle`对象。用户可以通过调用`handle`对象的`remove()`函数来删除与之对应的Hook函数。每一次调用`register_forward_pre_hook`函数,都会返回一个不同的`handle`对象。Hook函数应该按照以下的方式进行定义。" ] @@ -623,7 +89,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -634,8 +99,13 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": {}, + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2024-08-15T02:33:03.197024Z", + "start_time": "2024-08-15T02:33:03.181122Z" + } + }, "outputs": [ { "name": "stdout", @@ -688,7 +158,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -699,8 +168,13 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": {}, + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2024-08-15T02:33:11.216359Z", + "start_time": "2024-08-15T02:33:11.205063Z" + } + }, "outputs": [ { "name": "stdout", @@ -744,7 +218,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -752,7 +225,7 @@ "\n", "更多关于Cell对象的 `register_forward_pre_hook` 功能的说明可以参考[API文档](https://mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_forward_pre_hook)。\n", "\n", - "### Cell对象的register_forward_hook功能\n", + "## Cell对象的register_forward_hook功能\n", "\n", "用户可以在Cell对象上使用`register_forward_hook`函数来注册一个自定义的Hook函数,用来捕获正向传入Cell对象的数据和Cell对象的输出数据。该功能在静态图模式下和在使用`@jit`修饰的函数内不起作用。`register_forward_hook`函数接收Hook函数作为入参,并返回一个与Hook函数一一对应的`handle`对象。用户可以通过调用`handle`对象的`remove()`函数来删除与之对应的Hook函数。每一次调用`register_forward_hook`函数,都会返回一个不同的`handle`对象。Hook函数应该按照以下的方式进行定义。\n", "\n", @@ -771,7 +244,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -782,8 +254,13 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2024-08-15T02:33:22.691493Z", + "start_time": "2024-08-15T02:33:22.680164Z" + } + }, "outputs": [ { "name": "stdout", @@ -834,7 +311,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -843,43 +319,40 @@ "\n", "更多关于Cell对象的`register_forward_hook`功能的说明可以参考[API文档](https://mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_forward_hook)。\n", "\n", - "### Cell对象的register_backward_hook功能\n", + "## Cell对象的register_backward_pre_hook功能\n", "\n", - "用户可以在Cell对象上使用`register_backward_hook`函数来注册一个自定义的Hook函数,用来捕获网络反向传播时与Cell对象相关联的梯度。该功能在图模式下或者在使用`@jit`修饰的函数内不起作用。`register_backward_hook`函数接收Hook函数作为入参,并返回一个与Hook函数一一对应的`handle`对象。用户可以通过调用`handle`对象的`remove()`函数来删除与之对应的Hook函数。每一次调用`register_backward_hook`函数,都会返回一个不同的`handle`对象。\n", - "\n", - "与HookBackward算子所使用的自定义Hook函数有所不同,`register_backward_hook`使用的Hook函数的入参中,包含了表示Cell对象名称与id信息的`cell_id`、反向传入到Cell对象的梯度、以及Cell对象的反向输出的梯度。\n", + "用户可以在Cell对象上使用`register_backward_pre_hook`函数来注册一个自定义的Hook函数,用来捕获网络反向传播时与Cell对象相关联的梯度。该功能在图模式下或者在使用`@jit`修饰的函数内不起作用。`register_backward_pre_hook`函数接收Hook函数作为入参,并返回一个与Hook函数一一对应的`handle`对象。用户可以通过调用`handle`对象的`remove()`函数来删除与之对应的Hook函数。每一次调用`register_backward_pre_hook`函数,都会返回一个不同的`handle`对象。\n", "\n", + "与HookBackward算子所使用的自定义Hook函数有所不同,`register_backward_pre_hook`使用的Hook函数的入参中,包含了表示Cell对象信息`cell`以及反向传入到Cell对象的梯度。\n", "示例代码:" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "def backward_hook_function(cell_id, grad_input, grad_output):\n", - " print(grad_input)\n", + "def backward_pre_hook_function(grad_output):\n", " print(grad_output)" ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "这里的`cell_id`是Cell对象的名称以及ID信息,`grad_input`是网络反向传播时,传入到Cell对象的梯度,它对应于正向过程中下一个算子的反向输出梯度;`grad_output`是Cell对象反向输出的梯度。因此,用户可以使用`register_backward_hook`函数来捕获网络中某一个Cell对象的反向传入和反向输出梯度。用户可以在Hook函数中自定义对梯度的操作,比如查看、打印梯度,或者返回新的输出梯度。如果需要在Hook函数中返回新的输出梯度时,返回值必须是`tuple`的形式。\n", + "这里的`cell`是Cell对象信息,`grad_output`是网络反向传播时,传入到Cell对象的梯度。因此,用户可以使用`register_backward_pre_hook`函数来捕获网络中某一个Cell对象的反向梯度输入值。用户可以在Hook函数中自定义对梯度的操作,比如查看、打印梯度,或者返回新的输入梯度。如果需要在Hook函数中返回新的输入梯度时,返回值必须是`tuple`的形式。\n", "\n", "示例代码:" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2022-03-02T09:14:26.523389Z", - "start_time": "2022-03-02T09:14:26.506784Z" + "end_time": "2024-08-15T02:33:48.925726Z", + "start_time": "2024-08-15T02:33:48.885275Z" } }, "outputs": [ @@ -890,9 +363,109 @@ "(Tensor(shape=[1, 2, 1, 1], dtype=Float32, value=\n", "[[[[ 1.00000000e+00]],\n", " [[ 1.00000000e+00]]]]),)\n", + "[[[[1.99999 1.99999]\n", + " [1.99999 1.99999]]]]\n", + "-------------\n", + " [[[[1.99999 1.99999]\n", + " [1.99999 1.99999]]]]\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "import mindspore as ms\n", + "import mindspore.nn as nn\n", + "\n", + "ms.set_context(mode=ms.PYNATIVE_MODE)\n", + "\n", + "def backward_pre_hook_function(cell, grad_output):\n", + " print(grad_output)\n", + "\n", + "class Net(nn.Cell):\n", + " def __init__(self):\n", + " super(Net, self).__init__()\n", + " self.conv = nn.Conv2d(1, 2, kernel_size=2, stride=1, padding=0, weight_init=\"ones\", pad_mode=\"valid\")\n", + " self.bn = nn.BatchNorm2d(2, momentum=0.99, eps=0.00001, gamma_init=\"ones\")\n", + " self.handle = self.bn.register_backward_pre_hook(backward_pre_hook_function)\n", + " self.relu = nn.ReLU()\n", + "\n", + " def construct(self, x):\n", + " x = self.conv(x)\n", + " x = self.bn(x)\n", + " x = self.relu(x)\n", + " return x\n", + "\n", + "net = Net()\n", + "grad_net = ms.grad(net)\n", + "output = grad_net(ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32)))\n", + "print(output)\n", + "net.handle.remove()\n", + "output = grad_net(ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32)))\n", + "print(\"-------------\\n\", output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "为了避免脚本在切换到图模式时运行失败,不建议在Cell对象的 `construct` 函数中调用 `register_backward_pre_hook` 函数和 `handle` 对象的 `remove()` 函数。在PyNative模式下,如果在Cell对象的 `construct` 函数中调用 `register_backward_pre_hook` 函数,那么Cell对象每次运行都将新注册一个Hook函数。\n", + "\n", + "更多关于Cell对象的`register_backward_pre_hook`功能的说明可以参考[API文档](https://mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_backward_pre_hook)。\n", + "\n", + "## 使用cell对象的多个hook功能\n", + "\n", + "用户可以在Cell对象上使用`register_backward_hook`函数来注册一个自定义的Hook函数,用来捕获网络反向传播时与Cell对象相关联的梯度。该功能在图模式下或者在使用`@jit`修饰的函数内不起作用。`register_backward_hook`函数接收Hook函数作为入参,并返回一个与Hook函数一一对应的`handle`对象。用户可以通过调用`handle`对象的`remove()`函数来删除与之对应的Hook函数。每一次调用`register_backward_hook`函数,都会返回一个不同的`handle`对象。\n", + "\n", + "与HookBackward算子所使用的自定义Hook函数有所不同,`register_backward_hook`使用的Hook函数的入参中,包含了表示Cell对象信息`cell`、反向传入到Cell对象的梯度、以及Cell对象的反向输出的梯度。\n", + "\n", + "示例代码:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2024-08-15T01:31:51.395381Z", + "start_time": "2024-08-15T01:31:51.393199Z" + } + }, + "outputs": [], + "source": [ + "def backward_hook_function(cell, grad_input, grad_output):\n", + " print(grad_input)\n", + " print(grad_output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "这里的`cell`是Cell对象信息,`grad_input`是Cell对象反向输出的梯度,`grad_output`是网络反向传播时,传入到Cell对象的梯度。因此,用户可以使用`register_backward_hook`函数来捕获网络中某一个Cell对象的反向传入和反向输出梯度。用户可以在Hook函数中自定义对梯度的操作,比如查看、打印梯度,或者返回新的输出梯度。如果需要在Hook函数中返回新的输出梯度时,返回值必须是`tuple`的形式。\n", + "\n", + "示例代码:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "ExecuteTime": { + "end_time": "2024-08-15T02:34:40.550644Z", + "start_time": "2024-08-15T02:34:40.530050Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ "(Tensor(shape=[1, 2, 1, 1], dtype=Float32, value=\n", "[[[[ 9.99994993e-01]],\n", " [[ 9.99994993e-01]]]]),)\n", + "(Tensor(shape=[1, 2, 1, 1], dtype=Float32, value=\n", + "[[[[ 1.00000000e+00]],\n", + " [[ 1.00000000e+00]]]]),)\n", "[[[[1.99999 1.99999]\n", " [1.99999 1.99999]]]]\n", "-------------\n", @@ -908,7 +481,7 @@ "\n", "ms.set_context(mode=ms.PYNATIVE_MODE)\n", "\n", - "def backward_hook_function(cell_id, grad_input, grad_output):\n", + "def backward_hook_function(cell, grad_input, grad_output):\n", " print(grad_input)\n", " print(grad_output)\n", "\n", @@ -936,19 +509,29 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "当 `register_backward_hook` 函数和 `register_forward_pre_hook` 函数、 `register_forward_hook` 函数同时作用于同一Cell对象时,如果 `register_forward_pre_hook` 和 `register_forward_hook` 函数中有添加其他算子进行数据处理,这些新增算子会在Cell对象执行前或者执行后参与数据的正向计算,但是这些新增算子的反向梯度不在 `register_backward_hook` 函数的捕获范围内。 `register_backward_hook` 中注册的Hook函数仅捕获原始Cell对象的输入、输出梯度。\n", + "为了避免脚本在切换到图模式时运行失败,不建议在Cell对象的 `construct` 函数中调用 `register_backward_hook` 函数和 `handle` 对象的 `remove()` 函数。在PyNative模式下,如果在Cell对象的 `construct` 函数中调用 `register_backward_hook` 函数,那么Cell对象每次运行都将新注册一个Hook函数。\n", + "\n", + "更多关于Cell对象的 `register_backward_hook` 功能的说明可以参考[API文档](https://mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_backward_hook)。\n", + "\n", + "## Cell对象使用多个hook功能\n", + "\n", + "当 `register_backward_pre_hook` 函数、 `register_backward_hook` 函数、`register_forward_pre_hook` 函数、 `register_forward_hook` 函数同时作用于同一Cell对象时,如果 `register_forward_pre_hook` 和 `register_forward_hook` 函数中有添加其他算子进行数据处理,这些新增算子会在Cell对象执行前或者执行后参与数据的正向计算,但是这些新增算子的反向梯度不在 `register_backward_pre_hook` 函数和 `register_backward_hook` 函数的捕获范围内。 `register_backward_pre_hook` 中注册的Hook函数仅捕获原始Cell对象的输入梯度。`register_backward_hook` 中注册的Hook函数仅捕获原始Cell对象的输入、输出梯度。\n", "\n", "示例代码:" ] }, { "cell_type": "code", - "execution_count": 13, - "metadata": {}, + "execution_count": 14, + "metadata": { + "ExecuteTime": { + "end_time": "2024-08-15T03:04:03.727934Z", + "start_time": "2024-08-15T03:04:03.712374Z" + } + }, "outputs": [ { "name": "stdout", @@ -957,6 +540,7 @@ "forward inputs: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),)\n", "forward inputs: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),)\n", "forward outputs: [2.]\n", + "grad input: (Tensor(shape=[1], dtype=Float32, value= [ 1.00000000e+00]),)\n", "grad input: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),)\n", "grad output: (Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]),)\n", "(Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]), Tensor(shape=[1], dtype=Float32, value= [ 2.00000000e+00]))\n" @@ -981,9 +565,12 @@ " outputs = outputs + outputs\n", " return outputs\n", "\n", - "def backward_hook_fn(cell_id, grad_input, grad_output):\n", - " print(\"grad input: \", grad_input)\n", - " print(\"grad output: \", grad_output)\n", + "def backward_pre_hook_fn(cell, grad_output):\n", + " print(\"grad input: \", grad_output)\n", + "\n", + "def backward_hook_fn(cell, grad_input, grad_output):\n", + " print(\"grad input: \", grad_output)\n", + " print(\"grad output: \", grad_input)\n", "\n", "class Net(nn.Cell):\n", " def __init__(self):\n", @@ -991,7 +578,8 @@ " self.relu = nn.ReLU()\n", " self.handle = self.relu.register_forward_pre_hook(forward_pre_hook_fn)\n", " self.handle2 = self.relu.register_forward_hook(forward_hook_fn)\n", - " self.handle3 = self.relu.register_backward_hook(backward_hook_fn)\n", + " self.handle3 = self.relu.register_backward_pre_hook(backward_pre_hook_fn)\n", + " self.handle4 = self.relu.register_backward_hook(backward_hook_fn)\n", "\n", " def construct(self, x, y):\n", " x = x + y\n", @@ -1005,23 +593,20 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "这里的 `grad_input` 是梯度反向传播时传入`self.relu`的梯度,而不是传入 `forward_hook_fn` 函数中,新增的 `Add` 算子的梯度。这里的 `grad_output` 是梯度反向传播时 `self.relu` 反向输出的梯度,而不是 `forward_pre_hook_fn` 函数中新增 `Add` 算子的反向输出梯度。 `register_forward_pre_hook` 函数和 `register_forward_hook` 函数是在Cell对象执行前后起作用,不会影响Cell对象上反向Hook函数的梯度捕获范围。\n", - "\n", - "为了避免脚本在切换到图模式时运行失败,不建议在Cell对象的 `construct` 函数中调用 `register_backward_hook` 函数和 `handle` 对象的 `remove()` 函数。在PyNative模式下,如果在Cell对象的 `construct` 函数中调用 `register_backward_hook` 函数,那么Cell对象每次运行都将新注册一个Hook函数。\n", - "\n", - "更多关于Cell对象的 `register_backward_hook` 功能的说明可以参考[API文档](https://mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.register_backward_hook)。\n" + "这里的 `grad_output` 是梯度反向传播时传入`self.relu`的梯度,而不是传入 `forward_hook_fn` 函数中,新增的 `Add` 算子的梯度。这里的 `grad_input` 是梯度反向传播时 `self.relu` 反向输出的梯度,而不是 `forward_pre_hook_fn` 函数中新增 `Add` 算子的反向输出梯度。 `register_forward_pre_hook` 函数和 `register_forward_hook` 函数是在Cell对象执行前后起作用,不会影响Cell对象上反向Hook函数的梯度捕获范围。\n", + "\n" ] } ], "metadata": { + "celltoolbar": "Slideshow", "kernelspec": { - "display_name": "MindSpore", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "mindspore" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -1033,7 +618,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.5" + "version": "3.7.7" } }, "nbformat": 4, diff --git a/tutorials/source_zh_cn/advanced/modules/images/AlexNet.ppm b/docs/mindspore/source_zh_cn/model_train/custom_program/images/AlexNet.ppm similarity index 100% rename from tutorials/source_zh_cn/advanced/modules/images/AlexNet.ppm rename to docs/mindspore/source_zh_cn/model_train/custom_program/images/AlexNet.ppm diff --git a/tutorials/source_zh_cn/advanced/modules/images/learning_rate.png b/docs/mindspore/source_zh_cn/model_train/custom_program/images/learning_rate.png similarity index 100% rename from tutorials/source_zh_cn/advanced/modules/images/learning_rate.png rename to docs/mindspore/source_zh_cn/model_train/custom_program/images/learning_rate.png diff --git a/tutorials/source_zh_cn/advanced/modules/images/loss_function.png b/docs/mindspore/source_zh_cn/model_train/custom_program/images/loss_function.png similarity index 100% rename from tutorials/source_zh_cn/advanced/modules/images/loss_function.png rename to docs/mindspore/source_zh_cn/model_train/custom_program/images/loss_function.png diff --git a/tutorials/source_zh_cn/advanced/modules/initializer.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/initializer.ipynb similarity index 95% rename from tutorials/source_zh_cn/advanced/modules/initializer.ipynb rename to docs/mindspore/source_zh_cn/model_train/custom_program/initializer.ipynb index 6d5570cef70de9d9121ebe6e118bc3237d05d7fc..56d3324f53e8a65541ed0b33aa4b6c8775fa94ba 100644 --- a/tutorials/source_zh_cn/advanced/modules/initializer.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/initializer.ipynb @@ -4,15 +4,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_initializer.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_initializer.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/modules/initializer.ipynb)" + "# 自定义参数初始化\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_initializer.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_initializer.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/initializer.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# 参数初始化\n", - "\n", "## 使用内置参数初始化\n", "\n", "MindSpore提供了多种网络参数初始化的方式,并在部分算子中封装了参数初始化的功能。本节以Conv2d为例,分别介绍如何使用Initializer子类,字符串进行参数初始化。" diff --git a/docs/mindspore/source_zh_cn/model_train/custom_program/layer.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/layer.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..53f73662fe4ffe2394ef31d3a77af69d0ca4f397 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/layer.ipynb @@ -0,0 +1,405 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Cell与参数\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_layer.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_layer.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/layer.ipynb)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "Cell作为神经网络构造的基础单元,与神经网络层(Layer)的概念相对应,对Tensor计算操作的抽象封装,能够更准确清晰地对神经网络结构进行表示。除了基础的Tensor计算流程定义外,神经网络层还包含了参数管理、状态管理等功能。而参数(Parameter)是神经网络训练的核心,通常作为神经网络层的内部成员变量。本节我们将系统介绍参数、神经网络层以及其相关使用方法。" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Parameter\n", + "\n", + "参数(Parameter)是一类特殊的Tensor,是指在模型训练过程中可以对其值进行更新的变量。MindSpore提供`mindspore.Parameter`类进行Parameter的构造。为了对不同用途的Parameter进行区分,下面对两种不同类别的Parameter进行定义:\n", + "\n", + "- 可训练参数。在模型训练过程中根据反向传播算法求得梯度后进行更新的Tensor,此时需要将`required_grad`设置为`True`。\n", + "- 不可训练参数。不参与反向传播,但需要更新值的Tensor(如BatchNorm中的`mean`和`var`变量),此时需要将`requires_grad`设置为`False`。\n", + "\n", + "> Parameter默认设置`required_grad=True`。\n", + "\n", + "下面我们构造一个简单的全连接层:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import mindspore\n", + "from mindspore import nn\n", + "from mindspore import ops\n", + "from mindspore import Tensor, Parameter\n", + "\n", + "class Network(nn.Cell):\n", + " def __init__(self):\n", + " super().__init__()\n", + " self.w = Parameter(Tensor(np.random.randn(5, 3), mindspore.float32), name='w') # weight\n", + " self.b = Parameter(Tensor(np.random.randn(3,), mindspore.float32), name='b') # bias\n", + "\n", + " def construct(self, x):\n", + " z = ops.matmul(x, self.w) + self.b\n", + " return z\n", + "\n", + "net = Network()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "在`Cell`的`__init__`方法中,我们定义了`w`和`b`两个Parameter,并配置`name`进行命名空间管理。在`construct`方法中使用`self.attr`直接调用参与Tensor运算。" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "### 获取Parameter\n", + "\n", + "在使用Cell+Parameter构造神经网络层后,我们可以使用多种方法来获取Cell管理的Parameter。" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 获取单个参数\n", + "\n", + "单独获取某个特定参数,直接调用Python类的成员变量即可。" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2021-12-29T03:42:22.729232Z", + "start_time": "2021-12-29T03:42:22.723517Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-1.2192779 -0.36789745 0.0946381 ]\n" + ] + } + ], + "source": [ + "print(net.b.asnumpy())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 获取可训练参数\n", + "\n", + "可使用`Cell.trainable_params`方法获取可训练参数,通常在配置优化器时需调用此接口。" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Parameter (name=w, shape=(5, 3), dtype=Float32, requires_grad=True), Parameter (name=b, shape=(3,), dtype=Float32, requires_grad=True)]\n" + ] + } + ], + "source": [ + "print(net.trainable_params())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 获取所有参数\n", + "\n", + "使用`Cell.get_parameters()`方法可获取所有参数,此时会返回一个Python迭代器。" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(type(net.get_parameters()))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "或者可以调用`Cell.parameters_and_names`返回参数名称及参数。" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "w:\n", + "[[ 4.15680408e-02 -1.20311625e-01 5.02573885e-02]\n", + " [ 1.22175144e-04 -1.34980649e-01 1.17642188e+00]\n", + " [ 7.57667869e-02 -1.74758151e-01 -5.19092619e-01]\n", + " [-1.67846107e+00 3.27240258e-01 -2.06452996e-01]\n", + " [ 5.72323874e-02 -8.27963874e-02 5.94243526e-01]]\n", + "b:\n", + "[-1.2192779 -0.36789745 0.0946381 ]\n" + ] + } + ], + "source": [ + "for name, param in net.parameters_and_names():\n", + " print(f\"{name}:\\n{param.asnumpy()}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 修改Parameter\n", + "\n", + "#### 直接修改参数值\n", + "\n", + "Parameter是一种特殊的Tensor,因此可以使用Tensor索引修改的方式对其值进行修改。" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 1. -0.36789745 0.0946381 ]\n" + ] + } + ], + "source": [ + "net.b[0] = 1.\n", + "print(net.b.asnumpy())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 覆盖修改参数值\n", + "\n", + "可调用`Parameter.set_data`方法,使用相同Shape的Tensor对Parameter进行覆盖。该方法常用于使用Initializer进行[Cell遍历初始化](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/initializer.html#cell%E9%81%8D%E5%8E%86%E5%88%9D%E5%A7%8B%E5%8C%96)。" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[3. 4. 5.]\n" + ] + } + ], + "source": [ + "net.b.set_data(Tensor([3, 4, 5]))\n", + "print(net.b.asnumpy())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 运行时修改参数值\n", + "\n", + "参数的主要作用为模型训练时对其值进行更新,在反向传播获得梯度后,或不可训练参数需要进行更新,都涉及到运行时参数修改。由于MindSpore的[使用静态图加速](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/accelerate_with_static_graph.html)编译设计,此时需要使用`mindspore.ops.assign`接口对参数进行赋值。该方法常用于[自定义优化器](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/optimizer.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E4%BC%98%E5%8C%96%E5%99%A8)场景。下面是一个简单的运行时修改参数值样例:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[7. 8. 9.]\n" + ] + } + ], + "source": [ + "import mindspore as ms\n", + "\n", + "@ms.jit\n", + "def modify_parameter():\n", + " b_hat = ms.Tensor([7, 8, 9])\n", + " ops.assign(net.b, b_hat)\n", + " return True\n", + "\n", + "modify_parameter()\n", + "print(net.b.asnumpy())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Parameter Tuple\n", + "\n", + "变量元组ParameterTuple,用于保存多个Parameter,继承于元组tuple,提供克隆功能。\n", + "\n", + "如下示例提供ParameterTuple创建方法:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(Parameter (name=x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=z, shape=(), dtype=Float32, requires_grad=True))\n", + "(Parameter (name=params_copy.x, shape=(2, 3), dtype=Int64, requires_grad=True), Parameter (name=params_copy.y, shape=(1, 2, 3), dtype=Float32, requires_grad=True), Parameter (name=params_copy.z, shape=(), dtype=Float32, requires_grad=True))\n" + ] + } + ], + "source": [ + "from mindspore.common.initializer import initializer\n", + "from mindspore import ParameterTuple\n", + "# 创建\n", + "x = Parameter(default_input=ms.Tensor(np.arange(2 * 3).reshape((2, 3))), name=\"x\")\n", + "y = Parameter(default_input=initializer('ones', [1, 2, 3], ms.float32), name='y')\n", + "z = Parameter(default_input=2.0, name='z')\n", + "params = ParameterTuple((x, y, z))\n", + "\n", + "# 从params克隆并修改名称为\"params_copy\"\n", + "params_copy = params.clone(\"params_copy\")\n", + "\n", + "print(params)\n", + "print(params_copy)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "## Cell训练状态转换\n", + "\n", + "神经网络中的部分Tensor操作在训练和推理时的表现并不相同,如`nn.Dropout`在训练时进行随机丢弃,但在推理时则不丢弃,`nn.BatchNorm`在训练时需要更新`mean`和`var`两个变量,在推理时则固定其值不变。因此我们可以通过`Cell.set_train`接口来设置神经网络的状态。\n", + "\n", + "`set_train(True)`时,神经网络状态为`train`, `set_train`接口默认值为`True`:" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "train\n" + ] + } + ], + "source": [ + "net.set_train()\n", + "print(net.phase)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`set_train(False)`时,神经网络状态为`predict`:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "predict\n" + ] + } + ], + "source": [ + "net.set_train(False)\n", + "print(net.phase)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "MindSpore", + "language": "python", + "name": "mindspore" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/tutorials/source_zh_cn/advanced/modules/loss.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/loss.ipynb similarity index 97% rename from tutorials/source_zh_cn/advanced/modules/loss.ipynb rename to docs/mindspore/source_zh_cn/model_train/custom_program/loss.ipynb index e34a6736e6deb118b3a54041231f519939b04730..5af65261a52392475736e59b35d8ce89837272b4 100644 --- a/tutorials/source_zh_cn/advanced/modules/loss.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/loss.ipynb @@ -4,22 +4,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_loss.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_loss.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/modules/loss.ipynb)" + "# 自定义损失函数\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_loss.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_loss.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/loss.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# 损失函数\n", - "\n", "损失函数,亦称目标函数,用于衡量预测值与真实值差异的程度。\n", "\n", "在深度学习中,模型训练就是通过不断迭代来缩小损失函数值的过程。因此,在模型训练过程中损失函数的选择非常重要,一个好的损失函数能有效提升模型的性能。\n", "\n", "`mindspore.nn`模块中提供了许多[通用损失函数](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.nn.html#损失函数),但这些通用损失函数无法满足所有需求,很多情况需要用户自定义所需的损失函数。因此,本教程介绍如何自定义损失函数。\n", "\n", - "![lossfun.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/modules/images/loss_function.png)\n", + "![lossfun.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/custom_program/images/loss_function.png)\n", "\n", "## 内置损失函数\n", "\n", diff --git a/docs/mindspore/source_zh_cn/model_train/custom_program/network_custom.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/network_custom.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..556e927fb643c68dc1963d2f3d291355b1ade023 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/network_custom.ipynb @@ -0,0 +1,195 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 自定义神经网络层\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_network_custom.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_network_custom.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/network_custom.ipynb)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "通常情况下,MindSpore提供的神经网络层接口和function函数接口能够满足模型构造需求,但由于AI领域不断推陈出新,因此有可能遇到新网络结构没有内置模块的情况。此时我们可以根据需要,通过MindSpore提供的function接口、Primitive算子自定义神经网络层,并可以使用`Cell.bprop`方法自定义反向。下面分别详述三种自定义方法。\n", + "\n", + "## 使用function接口构造神经网络层\n", + "\n", + "MindSpore提供大量基础的function接口,可以使用其构造复杂的Tensor操作,封装为神经网络层。下面以`Threshold`为例,其公式如下:\n", + "\n", + "$$\n", + "y =\\begin{cases}\n", + " x, &\\text{ if } x > \\text{threshold} \\\\\n", + " \\text{value}, &\\text{ otherwise }\n", + " \\end{cases}\n", + "$$\n", + "\n", + "可以看到`Threshold`判断Tensor的值是否大于`threshold`值,保留判断结果为`True`的值,替换判断结果为`False`的值。因此,对应实现如下:" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "import mindspore\n", + "import numpy as np\n", + "from mindspore import nn, ops, Tensor, Parameter\n", + "class Threshold(nn.Cell):\n", + " def __init__(self, threshold, value):\n", + " super().__init__()\n", + " self.threshold = threshold\n", + " self.value = value\n", + "\n", + " def construct(self, inputs):\n", + " cond = ops.gt(inputs, self.threshold)\n", + " value = ops.fill(inputs.dtype, inputs.shape, self.value)\n", + " return ops.select(cond, inputs, value)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "这里分别使用了`ops.gt`、`ops.fill`、`ops.select`来实现判断和替换。下面执行自定义的`Threshold`层:" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Tensor(shape=[3], dtype=Float32, value= [ 2.00000000e+01, 2.00000003e-01, 3.00000012e-01])" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m = Threshold(0.1, 20)\n", + "inputs = mindspore.Tensor([0.1, 0.2, 0.3], mindspore.float32)\n", + "m(inputs)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "可以看到`inputs[0] = threshold`, 因此被替换为`20`。" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 自定义Cell反向\n", + "\n", + "在特殊场景下,我们不但需要自定义神经网络层的正向逻辑,也需要手动控制其反向的计算,此时我们可以通过`Cell.bprop`接口对其反向进行定义。在全新的神经网络结构设计、反向传播速度优化等场景下会用到该功能。下面我们以`Dropout2d`为例,介绍如何自定义Cell反向:" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "class Dropout2d(nn.Cell):\n", + " def __init__(self, keep_prob):\n", + " super().__init__()\n", + " self.keep_prob = keep_prob\n", + " self.dropout2d = ops.Dropout2D(keep_prob)\n", + "\n", + " def construct(self, x):\n", + " return self.dropout2d(x)\n", + "\n", + " def bprop(self, x, out, dout):\n", + " _, mask = out\n", + " dy, _ = dout\n", + " if self.keep_prob != 0:\n", + " dy = dy * (1 / self.keep_prob)\n", + " dy = mask.astype(mindspore.float32) * dy\n", + " return (dy.astype(x.dtype), )\n", + "\n", + "dropout_2d = Dropout2d(0.8)\n", + "dropout_2d.bprop_debug = True" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`bprop`方法分别有三个入参:\n", + "\n", + "- *x*: 正向输入,当正向输入为多个时,需同样数量的入参。\n", + "- *out*: 正向输出。\n", + "- *dout*: 反向传播时,当前Cell执行之前的反向结果。\n", + "\n", + "一般我们需要根据正向输出和前层反向结果配合,根据反向求导公式计算反向结果,并将其返回。`Dropout2d`的反向计算需要根据正向输出的`mask`矩阵对前层反向结果进行mask,然后根据`keep_prob`进行缩放。最终可得到正确的计算结果。" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "自定义Cell反向时,在PyNative模式下支持拓展写法,可以对Cell内部的权重求导,具体列子如下:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "class NetWithParam(nn.Cell):\n", + " def __init__(self):\n", + " super(NetWithParam, self).__init__()\n", + " self.w = Parameter(Tensor(np.array([2.0], dtype=np.float32)), name='weight')\n", + " self.internal_params = [self.w]\n", + "\n", + " def construct(self, x):\n", + " output = self.w * x\n", + " return output\n", + "\n", + " def bprop(self, *args):\n", + " return (self.w * args[-1],), {self.w: args[0] * args[-1]}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`bprop`方法支持*args入参,args数组中最后一位`args[-1]`为返回给该cell的梯度。通过`self.internal_params`设置求导的权重,同时在`bprop`函数的返回值为一个元组和一个字典,返回输入对应梯度的元组,以及以key为权重,value为权重对应梯度的字典。" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "MindSpore", + "language": "python", + "name": "mindspore" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 + } + \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/model_train/custom_program/op_custom.rst b/docs/mindspore/source_zh_cn/model_train/custom_program/op_custom.rst new file mode 100644 index 0000000000000000000000000000000000000000..76634d0507a78a5ac643bf251da1e3aaf39cfd77 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/op_custom.rst @@ -0,0 +1,12 @@ +自定义算子 +============ + +.. toctree:: + :glob: + :maxdepth: 1 + + operation/op_custom + operation/ms_kernel + operation/op_custom_adv + operation/op_custom_aot + operation/op_custom_ascendc \ No newline at end of file diff --git a/tutorials/experts/source_zh_cn/operation/ms_kernel.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/ms_kernel.ipynb similarity index 96% rename from tutorials/experts/source_zh_cn/operation/ms_kernel.ipynb rename to docs/mindspore/source_zh_cn/model_train/custom_program/operation/ms_kernel.ipynb index 503550efa4752b75f3362abb1329c69b6196d8f8..16ab2f93ba4e696694db63d383d0f0781f582bb0 100644 --- a/tutorials/experts/source_zh_cn/operation/ms_kernel.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/ms_kernel.ipynb @@ -7,7 +7,7 @@ "source": [ "# MindSpore Hybrid 语法规范\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/operation/mindspore_ms_kernel.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/operation/mindspore_ms_kernel.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/operation/ms_kernel.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/operation/mindspore_ms_kernel.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/operation/mindspore_ms_kernel.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/operation/ms_kernel.ipynb)\n", "\n", "## 概述\n", "\n", diff --git a/tutorials/experts/source_zh_cn/operation/op_custom.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom.ipynb similarity index 93% rename from tutorials/experts/source_zh_cn/operation/op_custom.ipynb rename to docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom.ipynb index 309cf89053fbc2acf5873b81eabd0c6b481bd582..cc2f115705e874ae52b2b650618e4c61d4ff9db4 100644 --- a/tutorials/experts/source_zh_cn/operation/op_custom.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom.ipynb @@ -6,7 +6,7 @@ "source": [ "# 自定义算子(基于Custom表达)\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/operation/mindspore_op_custom.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/operation/mindspore_op_custom.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/operation/op_custom.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/operation/mindspore_op_custom.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/operation/mindspore_op_custom.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom.ipynb)\n", "\n", "## 概述\n", "\n", @@ -32,7 +32,7 @@ "\n", "| 算子开发方式 | 开发语言 | 编译方式 | 支持平台 | 推荐场景 |\n", "|:-------|:------------------|:------ |:------ |:------------------------|\n", - "| [pyfunc](#自定义算子入门) | Python | N/A | `CPU` | 快速算法验证、需要与Python进行交互等场景 |\n", + "| [pyfunc](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%AE%97%E5%AD%90%E5%85%A5%E9%97%A8) | Python | N/A | `CPU` | 快速算法验证、需要与Python进行交互等场景 |\n", "| [hybrid](#hybrid类型的自定义算子开发) | MindSpore HYBRID DSL | JIT | `GPU` `CPU` | 全平台通用开发和快速验证 |\n", "| [akg](#akg类型的自定义算子开发) | MindSpore AKG DSL | JIT | `GPU` | 用于开发验证场景,不建议普通用户使用 |\n", "| [aot](#aot类型的自定义算子开发) | C/C++/CUDA | AOT | `GPU` `CPU` | 高性能手写、对接调用第三方算子库场景 |\n", @@ -190,10 +190,10 @@ "\n", "Hybrid类型的自定义算子是自定义算子的默认定义类型。通过使用Hybrid类型的自定义算子,用户可以用类Python的语法描述算子计算逻辑,且无需关注MindSpore框架对于算子定义的工程细节,让用户专注于算法本身。\n", "\n", - "Hybrid类型的自定义算子使用[MindSpore Hybrid DSL](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/ms_kernel.html#语法规则)描述算子内部计算逻辑的实现。用MindSpore Hybrid DSL定义的函数可以被[AKG算子编译器](https://gitee.com/mindspore/akg)解析进行JIT编译生成高效算子,在大规模模型的训练推理中使用。同时,用MindSpore Hybrid DSL定义的函数可以当做一个`numpy`函数直接调用,方便用户调试的同时也可以灵活的切换到[pyfunc 类型的自定义算子](#自定义算子入门一个例子),做到一次开发,多个模式多个平台多个场景复用的自定义算子表达。\n", + "Hybrid类型的自定义算子使用[MindSpore Hybrid DSL](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/ms_kernel.html#语法规则)描述算子内部计算逻辑的实现。用MindSpore Hybrid DSL定义的函数可以被[AKG算子编译器](https://gitee.com/mindspore/akg)解析进行JIT编译生成高效算子,在大规模模型的训练推理中使用。同时,用MindSpore Hybrid DSL定义的函数可以当做一个`numpy`函数直接调用,方便用户调试的同时也可以灵活的切换到[pyfunc 类型的自定义算子](#自定义算子入门),做到一次开发,多个模式多个平台多个场景复用的自定义算子表达。\n", "\n", "下面用例(test_custom_hybrid.py)介绍hybrid类型的自定义算子开发流程,其中自定义算子实现两个输入张量相加的功能。\n", - "值得注意的是,Hybrid类型的自定义算子采取源码变换的方式打通MindSpore的图编译器和算子编译器,用户可以直接使用MindSpore Hybrid DSL提供的关键词,例如下面的`output_tensor`,而无需引入对应Python函数。更多MindSpore Hybrid DSL关键词的介绍,参见[MindSpore Hybrid DSL关键词](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/ms_kernel.html#关键词)。" + "值得注意的是,Hybrid类型的自定义算子采取源码变换的方式打通MindSpore的图编译器和算子编译器,用户可以直接使用MindSpore Hybrid DSL提供的关键词,例如下面的`output_tensor`,而无需引入对应Python函数。更多MindSpore Hybrid DSL关键词的介绍,参见[MindSpore Hybrid DSL关键词](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/ms_kernel.html#关键词)。" ] }, { @@ -278,7 +278,7 @@ "\n", "算子输出shape和数据类型推理可以通过定义Python函数实现,描述算子输出shape和数据类型的推导逻辑。\n", "\n", - "若算子包含属性或者只支持特定的输入输出数据类型或数据格式,则需要注册算子信息,算子信息生成方式请参考[算子信息注册](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom_adv.html#算子信息注册)。若未注册算子信息,在后端做算子选择和映射的时候,将会从当前算子的输入中推导算子信息。\n", + "若算子包含属性或者只支持特定的输入输出数据类型或数据格式,则需要注册算子信息,算子信息生成方式请参考[算子信息注册](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom_adv.html#算子信息注册)。若未注册算子信息,在后端做算子选择和映射的时候,将会从当前算子的输入中推导算子信息。\n", "\n", "下面以test_custom_akg.py为例介绍akg类型的自定义算子开发流程,其中自定义算子实现两个输入张量相加的功能。\n", "\n", @@ -361,7 +361,7 @@ "\n", "## 采用AOT编译的自定义算子\n", "\n", - "AOT类型的自定义算子指用户事先把算子编译成二进制文件后接入网络。通常用户通过C/C++/CUDA等编程语言手工优化算子实现,并把算子以动态库的形式接入MindSpore加速网络。如此,用户可以针对算子进行极致优化,发挥对应后端硬件的极致性能。这里我们会介绍AOT类型自定义算子的一些基础知识,对于AOT类型自定义算子的更多用法和功能,请参见[AOT类型自定义算子进阶用法](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom_aot.html)\n", + "AOT类型的自定义算子指用户事先把算子编译成二进制文件后接入网络。通常用户通过C/C++/CUDA等编程语言手工优化算子实现,并把算子以动态库的形式接入MindSpore加速网络。如此,用户可以针对算子进行极致优化,发挥对应后端硬件的极致性能。这里我们会介绍AOT类型自定义算子的一些基础知识,对于AOT类型自定义算子的更多用法和功能,请参见[AOT类型自定义算子进阶用法](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom_aot.html)\n", "\n", "### aot类型的自定义算子开发\n", "\n", @@ -398,7 +398,7 @@ "\n", "算子输出shape和数据类型推理可以通过定义Python函数实现,描述算子输出shape和数据类型的推导逻辑。\n", "\n", - "若自定义算子只支持特定的输入输出数据类型,则需要定义算子信息,算子信息生成方式请参考[算子信息注册](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom_adv.html#算子信息注册)。\n", + "若自定义算子只支持特定的输入输出数据类型,则需要定义算子信息,算子信息生成方式请参考[算子信息注册](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom_adv.html#算子信息注册)。\n", "\n", "下面通过例子介绍GPU平台和CPU平台上aot类型的自定义算子开发流程,其中自定义算子实现两个输入张量相加的功能。\n", "\n", @@ -635,7 +635,7 @@ "\n", "算子输出shape和数据类型推导可以通过定义Python函数实现,描述算子输出shape和数据类型的推导逻辑。\n", "\n", - "若自定义算子只支持特定的输入输出数据类型,则需要定义算子信息,算子信息生成方式请参考[算子信息注册](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom_adv.html#算子信息注册)。\n", + "若自定义算子只支持特定的输入输出数据类型,则需要定义算子信息,算子信息生成方式请参考[算子信息注册](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom_adv.html#算子信息注册)。\n", "\n", "下面以两个输入张量相加为例,介绍julia类型的自定义算子开发流程:\n", "\n", diff --git a/tutorials/experts/source_zh_cn/operation/op_custom_adv.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_adv.ipynb similarity index 90% rename from tutorials/experts/source_zh_cn/operation/op_custom_adv.ipynb rename to docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_adv.ipynb index bcab0ee7181b2b244e4883ed935cad0ac8d50f6b..96b0b755139a00fe57498e2961b85c934b43a37d 100644 --- a/tutorials/experts/source_zh_cn/operation/op_custom_adv.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_adv.ipynb @@ -7,7 +7,7 @@ "source": [ "# 自定义算子注册\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/operation/mindspore_op_custom_adv.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/operation/mindspore_op_custom_adv.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/operation/op_custom_adv.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/operation/mindspore_op_custom_adv.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/operation/mindspore_op_custom_adv.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_adv.ipynb)\n", "\n", "## 算子信息注册\n", "\n", diff --git a/tutorials/experts/source_zh_cn/operation/op_custom_aot.md b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_aot.md similarity index 99% rename from tutorials/experts/source_zh_cn/operation/op_custom_aot.md rename to docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_aot.md index 3640f3bfc669c03f85e0ab0c9dd799d4fbb377a1..36953b4d515c01fbbc95e3b865b784ed49cb9846 100644 --- a/tutorials/experts/source_zh_cn/operation/op_custom_aot.md +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_aot.md @@ -1,10 +1,10 @@ # aot类型自定义算子进阶用法 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/operation/op_custom_aot.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_aot.md) ## 概述 -aot类型的自定义算子采用预编译的方式,要求网络开发者基于特定接口,手写算子实现函数对应的源码文件,并提前将源码文件编译为动态链接库,然后在网络运行时框架会自动调用执行动态链接库中的函数。aot类型的自定义算子支持GPU平台的CUDA语言,和CPU平台的C和C++语言。关于aot类型的自定义算子开发的基础知识请参考[基础教程](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom.html#aot类型的自定义算子开发)。 +aot类型的自定义算子采用预编译的方式,要求网络开发者基于特定接口,手写算子实现函数对应的源码文件,并提前将源码文件编译为动态链接库,然后在网络运行时框架会自动调用执行动态链接库中的函数。aot类型的自定义算子支持GPU平台的CUDA语言,和CPU平台的C和C++语言。关于aot类型的自定义算子开发的基础知识请参考[基础教程](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom.html#aot类型的自定义算子开发)。 本教程中,我们将展示aot类型自定义算子的进阶功能,包括 diff --git a/tutorials/experts/source_zh_cn/operation/op_custom_ascendc.md b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_ascendc.md similarity index 97% rename from tutorials/experts/source_zh_cn/operation/op_custom_ascendc.md rename to docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_ascendc.md index f52a82b9b5f1809e5d089090bbe2dfba945abdb7..f285626aa299ec2aa4b7ed7dfcfe7440f8ec945e 100644 --- a/tutorials/experts/source_zh_cn/operation/op_custom_ascendc.md +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_ascendc.md @@ -1,6 +1,6 @@ # Ascend C自定义算子开发与使用指南 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/operation/op_custom_ascendc.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/operation/op_custom_ascendc.md) ## 概述 @@ -108,13 +108,13 @@ MindSpore的自定义算子接口为[ops.Custom](https://www.mindspore.cn/docs/z . ├── compile_utils.py //自定义算子编译公共文件 ├── infer_file -│   ├── add_custom_infer.cc //自定义算子c++侧infer shape -│   └── custom_aot_extra.h //自定义算子infer shape编译依赖头文件 +│ ├── add_custom_infer.cc //自定义算子c++侧infer shape +│ └── custom_aot_extra.h //自定义算子infer shape编译依赖头文件 ├── op_host //自定义算子源码op_host -│   ├── add_custom.cpp -│   └── add_custom_tiling.h +│ ├── add_custom.cpp +│ └── add_custom_tiling.h ├── op_kernel //自定义算子源码op_kernel -│   └── add_custom.cpp +│ └── add_custom.cpp ├── test_compile_custom.py //自定义算子编译用例 ├── test_custom_aclnn.py //自定义算子aclnn使用样例 ├── test_custom_aclop.py //自定义算子tbe使用样例 @@ -193,8 +193,8 @@ net = CustomNet() ### 进一步阅读 -- **自定义算子注册**:更多关于自定义算子的注册信息和反向函数的编写,请参考 [自定义算子注册](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom_adv.html) 。 -- **AOT自定义算子**:对于C++的shape推导函数实现,以及AOT类型自定义算子的进阶用法,请参考 [aot类型自定义算子进阶用法](https://www.mindspore.cn/tutorials/experts/zh-CN/master/operation/op_custom_aot.html) 。 +- **自定义算子注册**:更多关于自定义算子的注册信息和反向函数的编写,请参考 [自定义算子注册](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom_adv.html) 。 +- **AOT自定义算子**:对于C++的shape推导函数实现,以及AOT类型自定义算子的进阶用法,请参考 [aot类型自定义算子进阶用法](https://www.mindspore.cn/docs/zh-CN/master/model_train/custom_program/operation/op_custom_aot.html) 。 ## 常见问题 diff --git a/tutorials/source_zh_cn/advanced/modules/optimizer.ipynb b/docs/mindspore/source_zh_cn/model_train/custom_program/optimizer.ipynb similarity index 98% rename from tutorials/source_zh_cn/advanced/modules/optimizer.ipynb rename to docs/mindspore/source_zh_cn/model_train/custom_program/optimizer.ipynb index 541c5db826bc518ac9637a8b031636dfc16bb7a9..9c76b21e6ac525c8d565045955c21caec2e08b37 100644 --- a/tutorials/source_zh_cn/advanced/modules/optimizer.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/optimizer.ipynb @@ -5,19 +5,19 @@ "id": "487f7a6d-506a-4824-94b1-a96b4866a447", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_optimizer.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/modules/mindspore_optimizer.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/modules/optimizer.ipynb)" + "# 自定义优化器\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_optimizer.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/custom_program/mindspore_optimizer.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/optimizer.ipynb)" ] }, { "cell_type": "markdown", "source": [ - "# 优化器\n", - "\n", "模型训练过程中,使用优化器更新网络参数,合适的优化器可以有效减少训练时间,提高模型性能。\n", "\n", "最基本的优化器是随机梯度下降算法(SGD),很多优化器在SGD的基础上进行了改进,以实现目标函数能更快速更有效地收敛到全局最优点。MindSpore中的`nn`模块提供了常用的优化器,如`nn.SGD`、`nn.Adam`、`nn.Momentum`等。本章主要介绍如何配置MindSpore提供的优化器以及如何自定义优化器。\n", "\n", - "![learningrate.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/modules/images/learning_rate.png)\n", + "![learningrate.png](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/custom_program/images/learning_rate.png)\n", "\n", "> MindSpore提供的优化器详细内容参见[优化器API](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.nn.html#优化器)。\n", "\n", diff --git a/docs/mindspore/source_zh_cn/model_train/custom_program/overview.md b/docs/mindspore/source_zh_cn/model_train/custom_program/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..801d13671b7151d87e7eb719cbbd070ac3c43c16 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/custom_program/overview.md @@ -0,0 +1,3 @@ +# 自定义高阶编程概述 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/custom_program/overview.md) diff --git a/tutorials/experts/source_zh_cn/dataset/augment.ipynb b/docs/mindspore/source_zh_cn/model_train/dataset/augment.ipynb similarity index 96% rename from tutorials/experts/source_zh_cn/dataset/augment.ipynb rename to docs/mindspore/source_zh_cn/model_train/dataset/augment.ipynb index 22b6243c671fbee84351884c173baf149a390dd3..2e54945bba163f30064e21426ff891a97f74d4ab 100644 --- a/tutorials/experts/source_zh_cn/dataset/augment.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/dataset/augment.ipynb @@ -6,7 +6,7 @@ "source": [ "# 自动数据增强\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/dataset/mindspore_augment.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/dataset/mindspore_augment.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/dataset/augment.ipynb)" + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_augment.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_augment.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/augment.ipynb)" ] }, { @@ -469,7 +469,7 @@ "source": [ "> 为了更好地演示效果,此处只加载5张图片,且读取时不进行`shuffle`操作,自动数据增强时也不进行`Normalize`和`HWC2CHW`操作。\n", "\n", - "![augment](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/auto_augmentation.png)\n", + "![augment](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/auto_augmentation.png)\n", "\n", "运行结果可以看到,batch中每张图像的增强效果,垂直方向表示1个batch的5张图像,水平方向表示5个batch。\n", "\n", diff --git a/tutorials/experts/source_zh_cn/dataset/cache.ipynb b/docs/mindspore/source_zh_cn/model_train/dataset/cache.ipynb similarity index 97% rename from tutorials/experts/source_zh_cn/dataset/cache.ipynb rename to docs/mindspore/source_zh_cn/model_train/dataset/cache.ipynb index 879af8bb3199feae5fde9b66573584f057ade37e..b160e53ed4028bc34d9d055fec8dc438670c05c5 100644 --- a/tutorials/experts/source_zh_cn/dataset/cache.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/dataset/cache.ipynb @@ -7,7 +7,7 @@ "source": [ "# 单节点数据缓存\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/dataset/mindspore_cache.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/dataset/mindspore_cache.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/dataset/cache.ipynb)" + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_cache.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_cache.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/cache.ipynb)" ] }, { @@ -33,12 +33,12 @@ "\n", " 用户可以在数据集加载操作中使用缓存。这将把加载完成的数据存到缓存服务器中,后续若需相同数据则可直接从中读取,避免从磁盘中重复加载。\n", "\n", - " ![cache on leaf pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/cache_dataset.png)\n", + " ![cache on leaf pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/cache_dataset.png)\n", "- 缓存经过数据增强处理后的数据\n", "\n", " 用户也可在`map`操作中使用缓存。这将允许直接缓存数据增强(如图像裁剪、缩放等)处理后的数据,避免数据增强操作重复进行,减少了不必要的计算量。\n", "\n", - " ![cache on map pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/cache_processed_data.png)" + " ![cache on map pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/cache_processed_data.png)" ] }, { diff --git a/tutorials/experts/source_zh_cn/dataset/dataset_autotune.md b/docs/mindspore/source_zh_cn/model_train/dataset/dataset_autotune.md similarity index 97% rename from tutorials/experts/source_zh_cn/dataset/dataset_autotune.md rename to docs/mindspore/source_zh_cn/model_train/dataset/dataset_autotune.md index f6268c1d920cb4c2345a62aa917934feced28738..c7f6db2e080fb85eeb01f4aaca71749c1714e49f 100644 --- a/tutorials/experts/source_zh_cn/dataset/dataset_autotune.md +++ b/docs/mindspore/source_zh_cn/model_train/dataset/dataset_autotune.md @@ -1,6 +1,6 @@ # 自动数据加速 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/dataset/dataset_autotune.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/dataset_autotune.md) ## 概述 @@ -56,7 +56,7 @@ print("tuning interval:", ds.config.get_autotune_interval()) ## 约束 - Profiling性能分析和自动数据加速无法同时开启,因为Profilling的其他处理会干扰自动数据加速进程。如果同时开启这两个功能,则会有一条警告信息提示用户检查是否为误操作。因此在使用Dataset AutoTune时,用户需要确保关闭Profiling功能。 -- 如果同时启动了[数据异构加速](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/dataset_offload.html)和自动数据加速,当有数据节点通过AutoTune进行异构硬件加速时,自动数据加速将不能保存数据管道配置并以警告日志提醒,因为此时实际运行的数据管道并不是预先定义的数据管道。 +- 如果同时启动了[数据异构加速](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/dataset_offload.html)和自动数据加速,当有数据节点通过AutoTune进行异构硬件加速时,自动数据加速将不能保存数据管道配置并以警告日志提醒,因为此时实际运行的数据管道并不是预先定义的数据管道。 - 如果数据处理管道包含不支持反序列化的节点(如用户自定义Python函数、GeneratorDataset),则使用保存的优化配置文件进行反序列化时将产生错误。此时推荐用户根据调优配置文件的内容手动修改数据管道的配置已达到加速的目的。 - 在分布式多卡训练启动自动数据加速时,`set_enable_autotune()` 需要在集群初始化完成后才能执行(mindspore.communication.management.init()),否则自动数据加速只会识别到ID为0的设备,且只会生成单个调优文件(预期生成文件数量应与设备数量相等),见以下样例: diff --git a/tutorials/experts/source_zh_cn/dataset/dataset_offload.md b/docs/mindspore/source_zh_cn/model_train/dataset/dataset_offload.md similarity index 97% rename from tutorials/experts/source_zh_cn/dataset/dataset_offload.md rename to docs/mindspore/source_zh_cn/model_train/dataset/dataset_offload.md index d23930d22db709e62927c060566c5aba40209c8e..c9f13f5a26591338a543e45ead96b5c05b018fa0 100644 --- a/tutorials/experts/source_zh_cn/dataset/dataset_offload.md +++ b/docs/mindspore/source_zh_cn/model_train/dataset/dataset_offload.md @@ -1,6 +1,6 @@ # 数据准备异构加速 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/dataset/dataset_offload.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/dataset_offload.md) ## 概述 diff --git a/tutorials/source_zh_cn/advanced/dataset/eager.ipynb b/docs/mindspore/source_zh_cn/model_train/dataset/eager.ipynb similarity index 99% rename from tutorials/source_zh_cn/advanced/dataset/eager.ipynb rename to docs/mindspore/source_zh_cn/model_train/dataset/eager.ipynb index 1754b58b11a19ad89e5f5e19fe90309b4a4168cd..9753dd0b4bc7debaf41152d88b8adf49e2dc163d 100644 --- a/tutorials/source_zh_cn/advanced/dataset/eager.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/dataset/eager.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_eager.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_eager.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/dataset/eager.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_eager.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_eager.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/eager.ipynb)\n", "\n", "# 轻量化数据处理\n" ] @@ -17,7 +17,7 @@ "\n", "基于Pipeline模式执行的最大特点是需要使用`map`方法,如下图中将`Resize`、`Crop`、`HWC2CHW`交由`map`调度,由其负责启动和执行给定的Transform,对Pipeline的数据进行映射变换。\n", "\n", - "![pipelinemode1](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/dataset/images/pipeline_mode.jpeg)\n", + "![pipelinemode1](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/pipeline_mode.jpeg)\n", "\n", "虽然构建数据管道可以批量处理输入数据,但是数据管道的API设计要求用户从构建输入源开始,逐步定义数据管道中的各个Transform,仅当在定义`map`的时候才会涉及与用户输入数据高度相关的Transform。\n", "\n", @@ -27,7 +27,7 @@ "\n", "在Eager模式下,执行Transforms不需要依赖构建数据管道`map`,而是以函数式调用的方式执行Transforms。因此代码编写会更为简洁且能立即执行得到运行结果,推荐在小型数据增强实验、模型推理等轻量化场景中使用。\n", "\n", - "![eagermode1](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/dataset/images/eager_mode.jpeg)" + "![eagermode1](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/eager_mode.jpeg)" ] }, { diff --git a/tutorials/experts/source_zh_cn/dataset/images/auto_augmentation.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/auto_augmentation.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/auto_augmentation.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/auto_augmentation.png diff --git a/tutorials/experts/source_zh_cn/dataset/images/autotune.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/autotune.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/autotune.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/autotune.png diff --git a/tutorials/source_zh_cn/advanced/dataset/images/basic_graph.graffle b/docs/mindspore/source_zh_cn/model_train/dataset/images/basic_graph.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/basic_graph.graffle rename to docs/mindspore/source_zh_cn/model_train/dataset/images/basic_graph.graffle diff --git a/tutorials/experts/source_zh_cn/dataset/images/cache_dataset.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/cache_dataset.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/cache_dataset.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/cache_dataset.png diff --git a/tutorials/experts/source_zh_cn/dataset/images/cache_pipeline_zh.eddx b/docs/mindspore/source_zh_cn/model_train/dataset/images/cache_pipeline_zh.eddx similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/cache_pipeline_zh.eddx rename to docs/mindspore/source_zh_cn/model_train/dataset/images/cache_pipeline_zh.eddx diff --git a/tutorials/experts/source_zh_cn/dataset/images/cache_processed_data.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/cache_processed_data.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/cache_processed_data.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/cache_processed_data.png diff --git a/tutorials/source_zh_cn/advanced/dataset/images/cifar10.jpg b/docs/mindspore/source_zh_cn/model_train/dataset/images/cifar10.jpg similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/cifar10.jpg rename to docs/mindspore/source_zh_cn/model_train/dataset/images/cifar10.jpg diff --git a/tutorials/experts/source_zh_cn/dataset/images/compose.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/compose.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/compose.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/compose.png diff --git a/tutorials/source_zh_cn/advanced/dataset/images/data_conversion_concept.graffle b/docs/mindspore/source_zh_cn/model_train/dataset/images/data_conversion_concept.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/data_conversion_concept.graffle rename to docs/mindspore/source_zh_cn/model_train/dataset/images/data_conversion_concept.graffle diff --git a/tutorials/source_zh_cn/advanced/dataset/images/data_conversion_concept.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/data_conversion_concept.png similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/data_conversion_concept.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/data_conversion_concept.png diff --git a/tutorials/experts/source_zh_cn/dataset/images/data_conversion_concept.pptx b/docs/mindspore/source_zh_cn/model_train/dataset/images/data_conversion_concept.pptx similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/data_conversion_concept.pptx rename to docs/mindspore/source_zh_cn/model_train/dataset/images/data_conversion_concept.pptx diff --git a/tutorials/experts/source_zh_cn/dataset/images/data_enhancement_performance_scheme.eddx b/docs/mindspore/source_zh_cn/model_train/dataset/images/data_enhancement_performance_scheme.eddx similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/data_enhancement_performance_scheme.eddx rename to docs/mindspore/source_zh_cn/model_train/dataset/images/data_enhancement_performance_scheme.eddx diff --git a/tutorials/experts/source_zh_cn/dataset/images/data_enhancement_performance_scheme.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/data_enhancement_performance_scheme.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/data_enhancement_performance_scheme.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/data_enhancement_performance_scheme.png diff --git a/tutorials/experts/source_zh_cn/dataset/images/data_loading_performance_scheme.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/data_loading_performance_scheme.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/data_loading_performance_scheme.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/data_loading_performance_scheme.png diff --git a/tutorials/source_zh_cn/advanced/dataset/images/dataset_process.eddx b/docs/mindspore/source_zh_cn/model_train/dataset/images/dataset_process.eddx similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/dataset_process.eddx rename to docs/mindspore/source_zh_cn/model_train/dataset/images/dataset_process.eddx diff --git a/tutorials/source_zh_cn/advanced/dataset/images/dataset_process.graffle b/docs/mindspore/source_zh_cn/model_train/dataset/images/dataset_process.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/dataset_process.graffle rename to docs/mindspore/source_zh_cn/model_train/dataset/images/dataset_process.graffle diff --git a/tutorials/source_zh_cn/advanced/dataset/images/eager_mode.jpeg b/docs/mindspore/source_zh_cn/model_train/dataset/images/eager_mode.jpeg similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/eager_mode.jpeg rename to docs/mindspore/source_zh_cn/model_train/dataset/images/eager_mode.jpeg diff --git a/tutorials/experts/source_zh_cn/dataset/images/map.eddx b/docs/mindspore/source_zh_cn/model_train/dataset/images/map.eddx similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/map.eddx rename to docs/mindspore/source_zh_cn/model_train/dataset/images/map.eddx diff --git a/tutorials/source_zh_cn/advanced/dataset/images/mindrecord.graffle b/docs/mindspore/source_zh_cn/model_train/dataset/images/mindrecord.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/mindrecord.graffle rename to docs/mindspore/source_zh_cn/model_train/dataset/images/mindrecord.graffle diff --git a/tutorials/source_zh_cn/advanced/dataset/images/mindrecord.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/mindrecord.png similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/mindrecord.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/mindrecord.png diff --git a/tutorials/experts/source_zh_cn/dataset/images/mindrecord.pptx b/docs/mindspore/source_zh_cn/model_train/dataset/images/mindrecord.pptx similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/mindrecord.pptx rename to docs/mindspore/source_zh_cn/model_train/dataset/images/mindrecord.pptx diff --git a/tutorials/experts/source_zh_cn/dataset/images/offload_process.PNG b/docs/mindspore/source_zh_cn/model_train/dataset/images/offload_process.PNG similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/offload_process.PNG rename to docs/mindspore/source_zh_cn/model_train/dataset/images/offload_process.PNG diff --git a/tutorials/source_zh_cn/advanced/dataset/images/op_batch.graffle b/docs/mindspore/source_zh_cn/model_train/dataset/images/op_batch.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/op_batch.graffle rename to docs/mindspore/source_zh_cn/model_train/dataset/images/op_batch.graffle diff --git a/tutorials/source_zh_cn/advanced/dataset/images/op_batch.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/op_batch.png similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/op_batch.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/op_batch.png diff --git a/tutorials/source_zh_cn/advanced/dataset/images/op_shuffle.graffle b/docs/mindspore/source_zh_cn/model_train/dataset/images/op_shuffle.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/op_shuffle.graffle rename to docs/mindspore/source_zh_cn/model_train/dataset/images/op_shuffle.graffle diff --git a/tutorials/source_zh_cn/advanced/dataset/images/op_shuffle.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/op_shuffle.png similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/op_shuffle.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/op_shuffle.png diff --git a/tutorials/experts/source_zh_cn/dataset/images/operation_fusion.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/operation_fusion.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/operation_fusion.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/operation_fusion.png diff --git a/tutorials/experts/source_zh_cn/dataset/images/pipeline.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/pipeline.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/pipeline.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/pipeline.png diff --git a/tutorials/source_zh_cn/advanced/dataset/images/pipeline_mode.jpeg b/docs/mindspore/source_zh_cn/model_train/dataset/images/pipeline_mode.jpeg similarity index 100% rename from tutorials/source_zh_cn/advanced/dataset/images/pipeline_mode.jpeg rename to docs/mindspore/source_zh_cn/model_train/dataset/images/pipeline_mode.jpeg diff --git a/tutorials/experts/source_zh_cn/dataset/images/shuffle_performance_scheme.png b/docs/mindspore/source_zh_cn/model_train/dataset/images/shuffle_performance_scheme.png similarity index 100% rename from tutorials/experts/source_zh_cn/dataset/images/shuffle_performance_scheme.png rename to docs/mindspore/source_zh_cn/model_train/dataset/images/shuffle_performance_scheme.png diff --git a/tutorials/experts/source_zh_cn/dataset/optimize.ipynb b/docs/mindspore/source_zh_cn/model_train/dataset/optimize.ipynb similarity index 97% rename from tutorials/experts/source_zh_cn/dataset/optimize.ipynb rename to docs/mindspore/source_zh_cn/model_train/dataset/optimize.ipynb index 4220a43bdd6fe22541d38b75cd87cbfbef511167..e60b82b091c33983b63599470a451b3f9d4ca0a7 100644 --- a/tutorials/experts/source_zh_cn/dataset/optimize.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/dataset/optimize.ipynb @@ -6,7 +6,7 @@ "source": [ "# 数据处理性能优化\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/dataset/mindspore_optimize.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/dataset/mindspore_optimize.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/dataset/optimize.ipynb)" + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_optimize.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_optimize.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/optimize.ipynb)" ] }, { @@ -20,7 +20,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/pipeline.png)" + "![pipeline](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/pipeline.png)" ] }, { @@ -123,7 +123,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![data-loading-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/data_loading_performance_scheme.png)" + "![data-loading-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/data_loading_performance_scheme.png)" ] }, { @@ -134,7 +134,7 @@ "\n", "- 对于已经提供加载接口的常用数据集,优先使用MindSpore提供的数据集加载接口进行加载,可以获得较好的加载性能,具体内容请参考框架提供的[数据集加载接口](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.dataset.html),如果性能仍无法满足需求,则可采取多线程并发方案,即:将数据集接口的参数`num_parallel_workers`(默认值:8)增大来取得更好的性能。\n", "\n", - "- 不支持的数据集格式,推荐先将数据集转换为MindRecord数据格式后再使用`MindDataset`类进行加载(详细使用方法参考[API](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.MindDataset.html)),具体内容请参考[将数据集转换为MindSpore数据格式](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset/record.html),如果性能仍无法满足需求,则可采取多线程并发方案,即:将数据集接口的参数`num_parallel_workers`(默认值:8)增大来取得更好的性能。\n", + "- 不支持的数据集格式,推荐先将数据集转换为MindRecord数据格式后再使用`MindDataset`类进行加载(详细使用方法参考[API](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.MindDataset.html)),具体内容请参考[将数据集转换为MindSpore数据格式](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/record.html),如果性能仍无法满足需求,则可采取多线程并发方案,即:将数据集接口的参数`num_parallel_workers`(默认值:8)增大来取得更好的性能。\n", "\n", "- 不支持的数据集格式,算法快速验证场景,优选用户自定义`GeneratorDataset`类实现(详细使用方法参考[API](https://www.mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html)),如果性能仍无法满足需求,则可采取多进程/多线程并发方案,即:\n", "\n", @@ -144,7 +144,7 @@ "\n", " **注意**:如果配置 `python_multiprocessing=True`(默认值:True)和 `num_parallel_workers>1`(默认值:1)表示启动了多进程方式进行数据load加速,此时随着数据集迭代,子进程的内存占用会逐渐增加,主要是因为自定义数据集的子进程以 Copy-On-Write 的方式获取主进程中的成员变量。举例:如果自定义数据集 `__init__` 函数中包含大量成员变量数据(例如:在数据集构建时加载了一个非常大的文件名列表)并且使用了多进程方式,那这可能会导致产生OOM的问题(总内存的预估使用量是:(子进程数量 + 1) * 父进程的内存大小)。最简单的解决方法是成员变量用非引用数据类型 (如:Pandas、Numpy或PyArrow对象)替换Python对象(如:list / dict / int / float / string等),或者加载更少的元数据以减小成员变量,或者配置 `python_multiprocessing=False` 使用多线程方式。\n", "\n", - " 3. 如果有`Using shared memory queue, but rowsize is larger than allocated memory ...`日志提示,那么将数据集接口的参数`max_rowsize`(默认值:6M)按日志提示进行增大来提升进程间数据传递的效率。" + " 3. 如果有`Using shared memory queue, but rowsize is larger than allocated memory ...`日志提示,那么将数据集接口的参数`max_rowsize`按日志提示进行增大或直接设为`None`来提升进程间数据传递的效率。" ] }, { @@ -340,7 +340,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![shuffle-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/shuffle_performance_scheme.png)" + "![shuffle-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/shuffle_performance_scheme.png)" ] }, { @@ -527,7 +527,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "![data-enhancement-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/data_enhancement_performance_scheme.png)" + "![data-enhancement-performance-scheme](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/data_enhancement_performance_scheme.png)" ] }, { @@ -545,13 +545,13 @@ " 2. 融合算子优化\n", "\n", " 在当前CPU占用率比较高时(如:单机多卡训练),使用融合操作(将两个或多个操作的功能聚合到一个操作中)来降低CPU占用会获得更好性能,可以通过配置环境变量`export OPTIMIZE=true`来使其生效。融合示例如下:\n", - " ![operation-fusion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/operation_fusion.png)\n", + " ![operation-fusion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/operation_fusion.png)\n", "\n", " 3. Compose优化\n", "\n", " 在当前CPU占用率比较高时(如:单机多卡训练),通过一个map操作接收多个增强操作(会按照顺序应用这些操作)来降低CPU降低竞争以取得更好性能。示例如下:\n", "\n", - " ![compose](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/dataset/images/compose.png)" + " ![compose](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/compose.png)" ] }, { @@ -564,7 +564,7 @@ "\n", " 2. 将`map`接口的参数`python_multiprocessing`设置为`True`/`False(默认值)`来启动多进程模式/多线程模式,多进程模式适用于cpu计算密集型任务,多线程适用于IO密集型任务;\n", "\n", - " 3. 如果有`Using shared memory queue, but rowsize is larger than allocated memory ...`日志提示,那么将`map`接口的参数`max_rowsize`(默认值:6M)按日志提示进行增大来提升进程间数据传递的效率。" + " 3. 如果有`Using shared memory queue, but rowsize is larger than allocated memory ...`日志提示,那么将`map`接口的参数`max_rowsize`按日志提示进行增大或直接设为`None`来提升进程间数据传递的效率。" ] }, { @@ -683,7 +683,7 @@ "\n", " 2. 将参数`python_multiprocessing`设置为`True`/`False(默认值)`来启动多进程模式/多线程模式,多进程模式适用于cpu计算密集型任务,多线程适用于IO密集型任务;\n", "\n", - " 3. 如果有`Using shared memory queue, but rowsize is larger than allocated memory ...`日志提示,那么将`batch`接口的参数`max_rowsize`(默认值:6M)按日志提示进行增大来提升进程间数据传递的效率。" + " 3. 如果有`Using shared memory queue, but rowsize is larger than allocated memory ...`日志提示,那么将`batch`接口的参数`max_rowsize`按日志提示进行增大或直接设为`None`来提升进程间数据传递的效率。" ] }, { @@ -698,7 +698,7 @@ "\n", " 数据的加载过程涉及频繁的磁盘操作,磁盘读写的性能直接影响了数据加载的速度。当数据集较大时,推荐使用固态硬盘进行数据存储,固态硬盘的读写速度普遍较普通磁盘高,能够减少I/O操作对数据处理性能的影响。\n", "\n", - " 一般地,加载后的数据将会被缓存到操作系统的页面缓存中,在一定程度上降低了后续读取的开销,加速了后续Epoch的数据加载速度。用户也可以通过MindSpore提供的[单节点缓存技术](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/cache.html),手动缓存加载增强后的数据,避免了重复的数据加载和数据增强。\n", + " 一般地,加载后的数据将会被缓存到操作系统的页面缓存中,在一定程度上降低了后续读取的开销,加速了后续Epoch的数据加载速度。用户也可以通过MindSpore提供的[单节点缓存技术](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/cache.html),手动缓存加载增强后的数据,避免了重复的数据加载和数据增强。\n", "\n", "2. NUMA架构\n", "\n", @@ -776,7 +776,7 @@ "source": [ "## 自动数据加速\n", "\n", - "MindSpore提供了一种自动数据调优的工具——Dataset AutoTune,用于在训练过程中根据环境资源的情况自动调整数据处理管道的并行度,最大化利用系统资源加速数据处理管道的处理速度。详细用法请参考[自动数据加速](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/dataset_autotune.html)。" + "MindSpore提供了一种自动数据调优的工具——Dataset AutoTune,用于在训练过程中根据环境资源的情况自动调整数据处理管道的并行度,最大化利用系统资源加速数据处理管道的处理速度。详细用法请参考[自动数据加速](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/dataset_autotune.html)。" ] }, { @@ -785,7 +785,7 @@ "source": [ "## 数据异构加速\n", "\n", - "MindSpore提供了一种运算负载均衡的技术,可以将MindSpore的Tensor运算分配到不同的异构硬件上,一方面均衡不同硬件之间的运算开销,另一方面利用异构硬件的优势对运算进行加速。详细用法请参考[数据异构加速](https://www.mindspore.cn/tutorials/experts/zh-CN/master/dataset/dataset_offload.html)。" + "MindSpore提供了一种运算负载均衡的技术,可以将MindSpore的Tensor运算分配到不同的异构硬件上,一方面均衡不同硬件之间的运算开销,另一方面利用异构硬件的优势对运算进行加速。详细用法请参考[数据异构加速](https://www.mindspore.cn/docs/zh-CN/master/model_train/dataset/dataset_offload.html)。" ] } ], diff --git a/docs/mindspore/source_zh_cn/model_train/dataset/overview.md b/docs/mindspore/source_zh_cn/model_train/dataset/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..2f0bdc25541396800d2445cb062cb672e7cee427 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/dataset/overview.md @@ -0,0 +1,3 @@ +# 数据处理概述 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/overview.md) diff --git a/tutorials/source_zh_cn/advanced/dataset/python_objects.ipynb b/docs/mindspore/source_zh_cn/model_train/dataset/python_objects.ipynb similarity index 93% rename from tutorials/source_zh_cn/advanced/dataset/python_objects.ipynb rename to docs/mindspore/source_zh_cn/model_train/dataset/python_objects.ipynb index 3e8b6e3952cfab50b084b6686b01c4024e5c5da8..ca0e2261e16ad23f61f8864b523aeeb5b53180ac 100644 --- a/tutorials/source_zh_cn/advanced/dataset/python_objects.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/dataset/python_objects.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_python_objects.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_python_objects.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/dataset/python_objects.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_python_objects.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_python_objects.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/python_objects.ipynb)\n", "\n", "# 数据处理管道支持Python对象\n", "\n", @@ -280,7 +280,7 @@ "source": [ "在模型训练/推理场景,从数据管道获取字典类型数据时有以下注意事项。\n", "\n", - "- 在[数据下沉](https://mindspore.cn/tutorials/experts/zh-CN/master/optimize/execution_opt.html?#%E6%95%B0%E6%8D%AE%E4%B8%8B%E6%B2%89)模式下,由于数据下沉通道当前无法支持字典类型的数据,字典类型的数据发送到下沉通道会造成错误。因此可以考虑关闭数据下沉模式(`dataset_sink_mode=False`),或在最后一个数据处理节点将字典类型的数据展开为列表或元组类型的数据,例如:" + "- 在[数据下沉](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/train_optimize.html#下沉模式)模式下,由于数据下沉通道当前无法支持字典类型的数据,字典类型的数据发送到下沉通道会造成错误。因此可以考虑关闭数据下沉模式(`dataset_sink_mode=False`),或在最后一个数据处理节点将字典类型的数据展开为列表或元组类型的数据,例如:" ] }, { diff --git a/tutorials/source_zh_cn/advanced/dataset/record.ipynb b/docs/mindspore/source_zh_cn/model_train/dataset/record.ipynb similarity index 96% rename from tutorials/source_zh_cn/advanced/dataset/record.ipynb rename to docs/mindspore/source_zh_cn/model_train/dataset/record.ipynb index 0468a7a21b62c573437cd73b06eb49466b003b7a..b33259f7cbca37cd06f6c22572df10f5c2349b41 100644 --- a/tutorials/source_zh_cn/advanced/dataset/record.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/dataset/record.ipynb @@ -4,15 +4,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_record.ipynb) \n", - "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_record.py) \n", - "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/dataset/record.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_record.ipynb) \n", + "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_record.py) \n", + "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/record.ipynb)\n", "\n", "# 格式转换\n", "\n", "MindSpore中可以把用于训练网络模型的数据集,转换为MindSpore特定的格式数据(MindSpore Record格式),从而更加方便地保存和加载数据。其目标是归一化用户的数据集,并进一步通过`MindDataset`接口实现数据的读取,并用于训练过程。\n", "\n", - "![conversion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/dataset/images/data_conversion_concept.png)\n", + "![conversion](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/data_conversion_concept.png)\n", "\n", "此外,MindSpore还针对部分数据场景进行了性能优化,使用MindSpore Record数据格式可以减少磁盘IO、网络IO开销,从而获得更好的使用体验。\n", "\n", @@ -27,7 +27,7 @@ "\n", "如下图所示,MindSpore Record文件由数据文件和索引文件组成。\n", "\n", - "![MindSpore Record](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/dataset/images/mindrecord.png)\n", + "![MindSpore Record](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/mindrecord.png)\n", "\n", "其中数据文件包含文件头、标量数据页、块数据页,用于存储用户归一化后的训练数据,且单个MindSpore Record文件建议小于20G,用户可将大数据集进行分片存储为多个MindSpore Record文件。\n", "\n", diff --git a/tutorials/source_zh_cn/advanced/dataset/sampler.ipynb b/docs/mindspore/source_zh_cn/model_train/dataset/sampler.ipynb similarity index 99% rename from tutorials/source_zh_cn/advanced/dataset/sampler.ipynb rename to docs/mindspore/source_zh_cn/model_train/dataset/sampler.ipynb index 2f8be05f7e90e212cd5fcc3ec4160b9ffffb9e0d..eb439d470fef2b3076fb0fb5390a7523d69bf5a4 100644 --- a/tutorials/source_zh_cn/advanced/dataset/sampler.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/dataset/sampler.ipynb @@ -4,9 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_sampler.ipynb) \n", - "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/dataset/mindspore_sampler.py) \n", - "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/dataset/sampler.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_sampler.ipynb) \n", + "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/dataset/mindspore_sampler.py) \n", + "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/dataset/sampler.ipynb)\n", "\n", "# 数据采样\n", "\n", @@ -20,7 +20,7 @@ "\n", "下面主要以CIFAR-10数据集为例,介绍几种常用MindSpore采样器的使用方法。\n", "\n", - "![cifar10](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/dataset/images/cifar10.jpg)\n", + "![cifar10](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/dataset/images/cifar10.jpg)\n", "\n", "> 本章节中的示例代码依赖`matplotlib`,可使用命令`pip install matplotlib`安装。如本文档以Notebook运行时,完成安装后需要重启kernel才能执行后续代码。" ] diff --git a/tutorials/experts/source_zh_cn/debug/aoe.md b/docs/mindspore/source_zh_cn/model_train/debug/aoe.md similarity index 95% rename from tutorials/experts/source_zh_cn/debug/aoe.md rename to docs/mindspore/source_zh_cn/model_train/debug/aoe.md index eb8c56b12cb3dc0ff6795466be7a8bf85155372b..bed050858027187764c79fc3eea11c7b467ed405 100644 --- a/tutorials/experts/source_zh_cn/debug/aoe.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/aoe.md @@ -1,6 +1,6 @@ # AOE调优工具 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/debug/aoe.md)   +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/aoe.md)   ## 概述 diff --git a/docs/mindspore/source_zh_cn/model_train/debug/debug_tools.rst b/docs/mindspore/source_zh_cn/model_train/debug/debug_tools.rst new file mode 100644 index 0000000000000000000000000000000000000000..2c23457d6f4c0955d23e94d242011e66309beb04 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/debug/debug_tools.rst @@ -0,0 +1,10 @@ +调试工具集 +============ + +.. toctree:: + :maxdepth: 1 + + dump + rdr + fault_recover + sdc diff --git a/tutorials/experts/source_zh_cn/debug/dump.md b/docs/mindspore/source_zh_cn/model_train/debug/dump.md similarity index 91% rename from tutorials/experts/source_zh_cn/debug/dump.md rename to docs/mindspore/source_zh_cn/model_train/debug/dump.md index c94086cc0b58290ee22e70fd1b1d63b9e92343a7..3b1ae0280a979671f2a9782df0f470005efec164 100644 --- a/tutorials/experts/source_zh_cn/debug/dump.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/dump.md @@ -1,6 +1,6 @@ # Dump功能调试 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/debug/dump.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/dump.md) 为了对训练过程进行分析,用户需要感知训练过程中算子的输入和输出数据。 @@ -15,7 +15,7 @@ MindSpore提供了两种Dump模式: > 不同模式需要不同的配置文件,生成的数据格式也不同: > -> - GPU/CPU后端和编译等级为O0/O1下的Ascend后端,推荐使用[同步Dump](#同步dump),具体参考[同步dump操作步骤](#同步dump操作步骤);编译等级为O2的Ascend后端推荐使用[异步Dump](#异步dump),具体参考[异步dump操作步骤](#异步dump操作步骤)。 +> - GPU/CPU后端和编译等级为O0/O1下的Ascend后端,推荐使用[同步Dump](#同步dump),具体参考[同步dump操作步骤](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html#%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4);编译等级为O2的Ascend后端推荐使用[异步Dump](#异步dump),具体参考[异步dump操作步骤](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html#%E6%93%8D%E4%BD%9C%E6%AD%A5%E9%AA%A4-1)。 > - Dump暂不支持异构训练,如果在异构训练场景启用Dump,生成的Dump数据对象目录可能不符合预期的目录结构。 Ascend后端同步Dump支持情况如下表(GPU/CPU后端参考 `O0/O1` 列)。 @@ -195,12 +195,12 @@ Ascend后端异步Dump支持情况如下表(GPU/CPU后端不支持)。 - `dump_mode`:设置成0,表示Dump出该网络中的所有算子数据;设置成1,表示Dump`"kernels"`里面指定的算子数据或算子类型数据;设置成2,表示使用[mindspore.set_dump](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.set_dump.html) Dump指定对象。仅在op_debug_mode设置为0时支持指定算子dump。 - `path`:Dump保存数据的绝对路径。 - `net_name`:自定义的网络名称,例如:"ResNet50"。 - - `iteration`:指定需要Dump数据的迭代。类型为str,用“|”分离要保存的不同区间的step的数据。如"0|5-8|100-120"表示Dump第1个,第6个到第9个, 第101个到第121个step的数据。指定“all”,表示Dump所有迭代的数据。仅在op_debug_mode设置为0或3时支持保存指定迭代,op_debug_mode设置为4时不支持指定迭代。 + - `iteration`:指定需要Dump数据的迭代。类型为str,用“|”分离要保存的不同区间的step的数据。如"0|5-8|100-120"表示Dump第1个,第6个到第9个,第101个到第121个step的数据。指定“all”,表示Dump所有迭代的数据。仅在op_debug_mode设置为0或3时支持保存指定迭代,op_debug_mode设置为4时不支持指定迭代。 - `saved_data`: 指定Dump的数据。类型为str,取值成"tensor",表示Dump出完整张量数据;取值成"statistic",表示只Dump张量的统计信息;取值"full"代表两种都要。同步Dump统计信息现只支持GPU场景和Ascend场景,CPU场景若选"statistic"或"full"便会错误退出。默认取值为"tensor"。保存统计信息仅支持op_debug_mode设置为0的场景。 - `input_output`:设置成0,表示Dump出算子的输入和算子的输出;设置成1,表示Dump出算子的输入;设置成2,表示Dump出算子的输出。在op_debug_mode设置为4时,只能保存算子输入。 - `kernels`:该项可以配置三种格式: - 1. 算子的名称列表。开启IR保存开关`set_context(save_graphs=2)`并执行用例,从生成的IR文件`trace_code_graph_{graph_id}`中获取算子名称。详细说明可以参照教程:[如何保存IR](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindir.html#如何保存ir)。 - 需要注意的是,是否设置`set_context(save_graphs=2)`可能会导致同一个算子的id不同,所以在Dump指定算子时要在获取算子名称之后保持这一项设置不变。或者也可以在Dump保存的`ms_output_trace_code_graph_{graph_id}.ir`文件中获取算子名称,参考[同步Dump数据对象目录](#同步dump数据对象目录)。 + 1. 算子的名称列表。开启IR保存开关`set_context(save_graphs=2)`并执行用例,从生成的IR文件`trace_code_graph_{graph_id}`中获取算子名称。详细说明可以参照教程:[如何保存IR](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindir.html#如何保存ir)。 + 需要注意的是,是否设置`set_context(save_graphs=2)`可能会导致同一个算子的id不同,所以在Dump指定算子时要在获取算子名称之后保持这一项设置不变。或者也可以在Dump保存的`ms_output_trace_code_graph_{graph_id}.ir`文件中获取算子名称,参考[同步Dump数据对象目录](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html#%E6%95%B0%E6%8D%AE%E5%AF%B9%E8%B1%A1%E7%9B%AE%E5%BD%95%E5%92%8C%E6%95%B0%E6%8D%AE%E6%96%87%E4%BB%B6%E4%BB%8B%E7%BB%8D)。 2. 还可以指定算子类型。当字符串中不带算子scope信息和算子id信息时,后台则认为其为算子类型,例如:"conv"。算子类型的匹配规则为:当发现算子名中包含算子类型字符串时,则认为匹配成功(不区分大小写),例如:"conv" 可以匹配算子 "Conv2D-op1234"、"Conv3D-op1221"。 3. 算子名称的正则表达式。当字符串符合"name-regex(xxx)"格式时,后台则会将其作为正则表达式。例如,"name-regex(Default/.+)"可匹配算子名称以"Default/"开头的所有算子。 - `support_device`:支持的设备,默认设置成0到7即可;在分布式训练场景下,需要dump个别设备上的数据,可以只在`support_device`中指定需要Dump的设备Id。该配置参数在CPU上无效,因为CPU下没有device这个概念,但是在json格式的配置文件中仍需保留该字段。 @@ -225,7 +225,7 @@ Ascend后端异步Dump支持情况如下表(GPU/CPU后端不支持)。 - `enable`:设置成true,表示开启同步Dump;设置成false时,在Ascend上会使用异步Dump,在GPU上仍然使用同步Dump。 - `trans_flag`:开启格式转换。将设备上的数据格式转换成NCHW格式。若为`True`,则数据会以Host侧的4D格式(NCHW)格式保存;若为`False`,则保留Device侧的数据格式。该配置参数在CPU上无效,因为CPU上没有format转换。默认值:true。 - `stat_calc_mode`:选择统计信息计算后端,可选"host"和"device"。选择"device"后可以使能device计算统计信息,当前只在Ascend生效,只支持`min/max/avg/l2norm`统计量。 - - `sample_mode`:设置成0,表示不开启切片dump功能;设置成1时,在图编译等级为O0的情况下开启切片dump功能。仅在op_debug_mode设置为0时生效,其它场景不会开启切片dump功能。 + - `sample_mode`:设置成0,表示不开启切片dump功能;设置成1时,在图编译等级为O0或O1的情况下开启切片dump功能。仅在op_debug_mode设置为0时生效,其它场景不会开启切片dump功能。 - `sample_num`:用于控制切片dump中切片的大小。默认值为100。 2. 设置Dump环境变量。 @@ -250,10 +250,10 @@ Ascend后端异步Dump支持情况如下表(GPU/CPU后端不支持)。 则“$MS_DIAGNOSTIC_DATA_PATH/debug_dump”就会被当做`path`的值。若Dump配置文件中设置了`path`字段,则仍以该字段的实际取值为准。 - 注意: + 注意: - - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 - - 在分布式场景下,Dump环境变量需要在调用`mindspore.communication.init`之前配置。 + - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 + - 在分布式场景下,Dump环境变量需要在调用`mindspore.communication.init`之前配置。 3. 启动网络训练脚本。 @@ -261,9 +261,9 @@ Ascend后端异步Dump支持情况如下表(GPU/CPU后端不支持)。 同步模式下,GPU环境如果要Dump数据,必须采用非数据下沉模式(设置`model.train`或`DatasetHelper`中的`dataset_sink_mode`参数为`False`),以保证可以获取每个step的Dump数据。 若脚本中都不调用`model.train`或`DatasetHelper`,则默认为非数据下沉模式。使用Dump功能将自动生成最终执行图的IR文件。 - 可以在训练脚本中设置`set_context(reserve_class_name_in_scope=False)`,避免Dump文件名称过长导致Dump数据文件生成失败。 + 可以在训练脚本中设置`set_context(reserve_class_name_in_scope=False)`,避免Dump文件名称过长导致Dump数据文件生成失败。 -4. 通过`numpy.load`读取和解析同步Dump数据,参考[同步Dump数据文件介绍](#同步dump数据文件介绍)。 +4. 通过`numpy.load`读取和解析同步Dump数据,参考[同步Dump数据文件介绍](#数据对象目录和数据文件介绍)。 ### 数据对象目录和数据文件介绍 @@ -360,7 +360,7 @@ ms_global_execution_order_graph_{graph_id}.csv 在通过Dump功能将脚本对应的图保存到磁盘上后,会产生最终执行图文件`ms_output_trace_code_graph_{graph_id}.ir`。该文件中保存了对应的图中每个算子的堆栈信息,记录了算子对应的生成脚本。 -以[AlexNet脚本](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/dump/train_alexnet.py)为例 : +以[AlexNet脚本](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/dump/train_alexnet.py)为例: ```python ... @@ -522,7 +522,7 @@ MindSpore通过异步Dump提供了Ascend平台上大型网络的调试能力。 } ``` - - `op_debug_mode`:该属性用于算子溢出调试,设置成0,表示不开启溢出;设置成3,表示开启溢出检测功能;设置成4,表示开启轻量异常Dump功能(该功能仅在使用ACL dump时生效)。在Dump数据的时候请设置成0,若设置成其他值,则只会Dump溢出算子或异常算子的数据。 + - `op_debug_mode`:该属性用于算子溢出调试,设置成0,表示不开启溢出;设置成3,表示开启溢出检测功能;设置成4,表示开启轻量异常Dump功能。在Dump数据的时候请设置成0,若设置成其他值,则只会Dump溢出算子或异常算子的数据。 - `dump_mode`:设置成0,表示Dump出该网络中的所有算子数据;设置成1,表示Dump`"kernels"`里面指定的算子数据或算子类型数据。仅在op_debug_mode设置为0时支持指定算子dump。op_debug_mode设置为非0值时,此字段的设置失效,Dump只会保存溢出算子的数据或者异常算子的数据。 - `path`:Dump保存数据的绝对路径。在图编译等级为O0时,MindSpore会在path目录下新建每个step的子目录。 - `net_name`:自定义的网络名称,例如:"ResNet50"。 @@ -550,7 +550,7 @@ MindSpore通过异步Dump提供了Ascend平台上大型网络的调试能力。 该字段为可选,默认值为["max", "min", "l2norm"]。 - - `file_format`: dump数据的文件类型,只支持`npy`和`bin`两种取值。设置成`npy`,则dump出的算子张量数据将为host侧格式的npy文件;设置成`bin`,则dump出的数据将为device侧格式的protobuf文件,需要借助转换工具进行处理,详细步骤请参考[异步Dump数据分析样例](#异步dump数据分析样例)。默认取值为`bin`。 + - `file_format`: dump数据的文件类型,只支持`npy`和`bin`两种取值。设置成`npy`,则dump出的算子张量数据将为host侧格式的npy文件;设置成`bin`,则dump出的数据将为device侧格式的protobuf文件,需要借助转换工具进行处理,详细步骤请参考[异步Dump数据分析样例](#数据分析样例-1)。默认取值为`bin`。 2. 设置数据Dump的环境变量。 @@ -566,14 +566,14 @@ MindSpore通过异步Dump提供了Ascend平台上大型网络的调试能力。 则“$MS_DIAGNOSTIC_DATA_PATH/debug_dump”就会被当做`path`的值。若Dump配置文件中设置了`path`字段,则仍以该字段的实际取值为准。 - - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 - - 在分布式场景下,Dump环境变量需要在调用`mindspore.communication.init`之前配置。 + - 在网络脚本执行前,设置好环境变量;网络脚本执行过程中设置将会不生效。 + - 在分布式场景下,Dump环境变量需要在调用`mindspore.communication.init`之前配置。 3. 执行用例Dump数据。 可以在训练脚本中设置`set_context(reserve_class_name_in_scope=False)`,避免Dump文件名称过长导致Dump数据文件生成失败。 -4. 参考[异步Dump数据分析样例](#异步dump数据分析样例)解析Dump数据文件。 +4. 参考[异步Dump数据分析样例](#数据分析样例-1)解析Dump数据文件。 > - 若需要dump全量或部分算子,则可以修改json配置文件中的`dump_mode`选项为0或1。 > - 由于Dump速度较慢,在大模型场景下开启Dump会延长不同卡之间的通信间隔时间,从而导致通信算子超时。可以通过调整通信算子的超时时间来解决此问题。对于Ascend后端,可以设置HCCL_EXEC_TIMEOUT环境变量,具体设置方法请参考[昇腾CANN文档](https://www.hiascend.com/document/detail/zh/canncommercial/80RC1/apiref/envvar/envref_07_0072.html)。 @@ -594,6 +594,7 @@ MindSpore通过异步Dump提供了Ascend平台上大型网络的调试能力。 {op_type}.{op_name}.{task_id}.{stream_id}.{timestamp} Opdebug.Node_OpDebug.{task_id}.{stream_id}.{timestamp} mapping.csv + acl_dump_{device_id}.json ``` 图编译等级为O0或O1时,Dump目录结构如下所示,此种场景下aclop和aclnn算子的Dump数据会保存于{device_id}目录,"ReduceSum"类通信算子的Dump数据会保存在{iteration_id}目录: @@ -614,10 +615,9 @@ MindSpore通过异步Dump提供了Ascend平台上大型网络的调试能力。 {op_type}.{op_name}.{task_id}.{stream_id}.{timestamp} //aclop 算子 {op_name}.{op_type}.{task_id}.{stream_id}.{timestamp} //aclnn 算子 mapping.csv + acl_dump_{device_id}.json ``` -使能ACL dump时,除上述dump数据外,还会在{path}目录生成调用acl接口所需要的json文件,一般情况下无需关注。 - - `path`:`data_dump.json`配置文件中设置的绝对路径。 - `time`: dump目录的创建时间。 - `device_id`: 卡号。 @@ -631,6 +631,8 @@ MindSpore通过异步Dump提供了Ascend平台上大型网络的调试能力。 - `timestamp`:时间戳。 - `step_id`: 用户侧的训练轮次。 +在{path}目录的`acl_dump_{device_id}.json`文件,是异步Dump在接口调用过程中生成的中间文件,一般情况下无需关注。 + 其中,溢出文件(`Opdebug.Node_OpDebug.{task_id}.{stream_id}.{timestamp}`文件)只会在开启溢出Dump且检测到溢出时保存。 若配置文件中`file_format`值设置为`npy`,算子文件会保存成npy格式的文件,溢出文件会被保存成json格式的文件。文件命名格式分别为: @@ -658,15 +660,13 @@ Opdebug.Node_OpDebug.{task_id}.{stream_id}.{timestamp}.output.0.json 如果`op_type`和`op_name`中出现了“.”、“/”、“\”、空格时,会转换为下划线表示。 -Dump生成的原始数据文件也可以使用MindSpore Insight的数据解析工具DumpParser解析,DumpParser的使用方式详见[DumpParser介绍](https://gitee.com/mindspore/mindinsight/tree/master/mindinsight/parser) 。MindSpore Insight解析出来的数据格式与同步dump的数据格式完全相同。 - -若配置`file_format`值为`npy`,则启用异步dump生成的数据文件命名规则与同步Dump相同,可以参考[同步Dump数据文件介绍](#同步dump数据文件介绍),溢出检测生成的溢出文件是`json`格式,溢出文件内容解析可参考[解析算子溢出数据文件](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/devguide/appdevg/aclpythondevg/aclpythondevg_0078.html#ZH-CN_TOPIC_0000001781325073__section6864050111619) 。 +若配置`file_format`值为`npy`,则启用异步dump生成的数据文件命名规则与同步Dump相同,可以参考[同步Dump数据文件介绍](#数据对象目录和数据文件介绍),溢出检测生成的溢出文件是`json`格式,溢出文件内容解析可参考[解析算子溢出数据文件](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/devguide/appdevg/aclpythondevg/aclpythondevg_0078.html#ZH-CN_TOPIC_0000001781325073__section6864050111619) 。 -选项`saved_data`只有在`file_format`为"npy"的时候生效。如`saved_data`是"statistic"或者"full"。张量统计数据会落盘到`statistic.csv`。如`saved_data`是"tensor"或者"full"完整张量数据会落盘到`{op_type}.{op_name}.{task_id}.{stream_id}.{timestamp}.{input_output_index}.{slot}.{format}.npy`。`statistic.csv`的格式与同步Dump相同,可以参考[同步Dump数据文件介绍](#同步dump数据文件介绍)。 +选项`saved_data`只有在`file_format`为"npy"的时候生效。如`saved_data`是"statistic"或者"full"。张量统计数据会落盘到`statistic.csv`。如`saved_data`是"tensor"或者"full"完整张量数据会落盘到`{op_type}.{op_name}.{task_id}.{stream_id}.{timestamp}.{input_output_index}.{slot}.{format}.npy`。`statistic.csv`的格式与同步Dump相同,可以参考[同步Dump数据文件介绍](#数据对象目录和数据文件介绍)。 ### 数据分析样例 -异步Dump不会自动保存`.ir`文件,要想查看`.ir`文件,可以在执行用例前通过MindSpore的IR保存开关`set_context(save_graphs=2)`, 执行用例后查看保存的`trace_code_graph_{xxx}`文件, 可以用vi打开。文件查看方式请参考同步dump的数据分析样例。在图编译等级为O0或O1时,异步Dump保存的算子文件和图文件中的算子名不同,所以此场景不推荐使用异步Dump,建议使用同步Dump。在图编译等级为O2时,由于`.ir`文件中并不是最终执行图,不能保证算子文件和`.ir`文件中的算子名一一对应。保存最终的执行图请参考昇腾社区文档[DUMP_GE_GRAPH](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/apiref/envref/envref_07_0011.html) 、[DUMP_GRAPH_LEVEL](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/apiref/envref/envref_07_0012.html) 和[DUMP_GRAPH_PATH](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/apiref/envref/envref_07_0013.html) 。 +异步Dump不会自动保存`.ir`文件,要想查看`.ir`文件,可以在执行用例前通过MindSpore的IR保存开关`set_context(save_graphs=2)`,执行用例后查看保存的`trace_code_graph_{xxx}`文件,可以用vi打开。文件查看方式请参考同步dump的数据分析样例。在图编译等级为O0或O1时,异步Dump保存的算子文件和图文件中的算子名不同,所以此场景不推荐使用异步Dump,建议使用同步Dump。在图编译等级为O2时,由于`.ir`文件中并不是最终执行图,不能保证算子文件和`.ir`文件中的算子名一一对应。保存最终的执行图请参考昇腾社区文档[DUMP_GE_GRAPH](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/apiref/envref/envref_07_0011.html) 、[DUMP_GRAPH_LEVEL](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/apiref/envref/envref_07_0012.html) 和[DUMP_GRAPH_PATH](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/80RC1alpha001/apiref/envref/envref_07_0013.html) 。 通过异步Dump的功能,获取到算子异步Dump生成的数据文件。如果异步Dump配置文件中设置的`file_format`为"npy",可以跳过以下步骤中的1、2,如果没有设置`file_format`,或者设置为"bin",需要先转换成`.npy`格式的文件。 @@ -729,7 +729,7 @@ Dump生成的原始数据文件也可以使用MindSpore Insight的数据解析 在一些特殊场景下,可在开发指导下应用GE dump模式。 -如果要使能GE dump,除了配置环境变量MINDSPORE_DUMP_CONFIG之外,还需要另外配置环境变量ENABLE_MS_GE_DUMP=1,该方式仅支持图编译等级为O2的场景。配置文件的格式和acl dump相同,op_debug_mode字段不支持配置为4,其余各项参数和acl dump相同。 +如果要使能GE dump,除了配置环境变量MINDSPORE_DUMP_CONFIG之外,还需要另外配置环境变量ENABLE_MS_GE_DUMP=1,该方式仅支持图编译等级为O2的场景。配置文件的格式和异步Dump相同,op_debug_mode字段不支持配置为4,其余各项参数和异步Dump相同。 ```bash export ENABLE_MS_GE_DUMP=1 @@ -750,7 +750,7 @@ GE dump的目录结构如下: mapping.csv ``` -其中, `path`、`time`、`device_id`、`model_name`、`model_id`、`iteration_id`、`op_type`、`op_name`、`task_id`、`stream_id`、`timestamp`的含义和acl dump的相同。 +其中, `path`、`time`、`device_id`、`model_name`、`model_id`、`iteration_id`、`op_type`、`op_name`、`task_id`、`stream_id`、`timestamp`的含义和异步Dump的相同。 该方式在将来会被废弃,不推荐使用。 @@ -760,4 +760,4 @@ GE dump的目录结构如下: - Dump仅支持bool、int、int8、in16、int32、int64、uint、uint8、uint16、uint32、uint64、float、float16、float32、float64、bfloat16、double、complex64、complex128类型数据的保存。 - complex64和complex128仅支持保存为npy文件,不支持保存为统计值信息。 - Print算子内部有一个输入参数为string类型,string类型不属于Dump支持的数据类型,所以在脚本中包含Print算子时,会有错误日志,这不会影响其它类型数据的保存。 -- 使能ACL dump时,不支持同时使用set_context(ascend_config={"exception_dump": "2")配置轻量异常dump; 支持同时使用set_context(ascend_config={"exception_dump": "1")配置全量异常dump。 +- 使能异步Dump时,不支持同时使用set_context(ascend_config={"exception_dump": "2")配置轻量异常dump; 支持同时使用set_context(ascend_config={"exception_dump": "1")配置全量异常dump。 diff --git a/tutorials/source_zh_cn/advanced/error_analysis.rst b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis.rst similarity index 93% rename from tutorials/source_zh_cn/advanced/error_analysis.rst rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis.rst index e444457a5b899884d2c8ce4e439bac091fa79388..9c62f6190f8571af6c4255389b7331fd9b2d4513 100644 --- a/tutorials/source_zh_cn/advanced/error_analysis.rst +++ b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis.rst @@ -2,7 +2,7 @@ ======== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/error_analysis.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis.rst :alt: 查看源文件 .. toctree:: @@ -91,7 +91,7 @@ MindSpore网络训练的一般过程是数据加载与处理,网络构建与 Traceback of Net Construct Code”部分内容,分析报错位置。 4) 基于可能的报错问题场景以及类型,假设导致报错问题的可能原因。 -具体如何基于不同场景进行错误分析请参考\ `错误分析 `__\ 。 +具体如何基于不同场景进行错误分析请参考\ `错误分析 `__\ 。 错误搜索 ^^^^^^^^ @@ -216,10 +216,10 @@ MindSpore网络训练的一般过程是数据加载与处理,网络构建与 +----------+----------------+----------------------------------------------+-----------------------------------+ | | metrics | 当训练结束后,可以使用metrics评估训练\ | `MindSpore \ | | | | 结果的好坏。提供了多种metrics评估指标\ | metrics功能介绍 `_ | -| | | | | +| | | ,如:accuracy、loss、preci\ | w.mindspore.cn/docs | +| | | sion、recall、F1 | /zh-CN/master/model_train/ | +| | | | train_process/model/metric | +| | | | .html#>`_ | | | | | | +----------+----------------+----------------------------------------------+-----------------------------------+ | | print\_接口 | print\_接口可以将用户输入的Tensor或\ | `print\_接口功能介绍 `_ | +----------+----------------+----------------------------------------------+-----------------------------------+ | | 数据Dump | 训练网络时,若训练结果和预期有偏差,通过Du\ | `Dump功能调试 `_ | +| | | mp功能保存算子输入输出数据进行调试。 | mindspore.cn/docs/ | +| | | | /zh-CN/master/model_train/ | +| | | | debug/dump.html>`_ | +----------+----------------+----------------------------------------------+-----------------------------------+ | 执行控制 | Callback | 用户可以使用回调函数在特定时期执行特定动作或\| `回调机制 | | | | 观察训练过程中网络信息,例如:保存模型参数、\| Callback `_ | -| | | | | +| | | 监控loss、动态调整参数、提前终止训练任务\ | indspore.cn/docs | +| | | 等。 | /zh-CN/master/model_train/ | +| | | | train_process/model/ | +| | | | callback.html#>`_ | +----------+----------------+----------------------------------------------+-----------------------------------+ | | Hook | 在pynative模式使用Hook功能可以捕\ | `Hook功能 `_ | -| | | 注册的register_forward_pr\ | | +| | | 获中间层算子的输入、输出数据以及反向梯度。已\| ndspore.cn/docs | +| | | 提供了四种形式的Hook功能,分别为:Hoo\ | /zh-CN/master/model_train/ | +| | | kBackward算子和在Cell对象上进行\ | /custom_program/hook_program | +| | | 注册的register_forward_pr\ | .html>`_ | | | | e_hook、register_forwar\ | | | | | d_hook、register_backwa\ | | | | | rd_hook功能。 | | @@ -291,24 +291,24 @@ MindSpore为框架开发者提供了丰富的调试手段,调试功能涵盖 | 数据记录 | RDR | Running Data\ | `Running Data | | | | Recorder(RDR)\ | Recorder `_ | +| | | 执行状态数据的功能。框架运\ | spore.cn/docs | +| | | 行异常会自动地导出预先记录\ | /zh-CN/master | +| | | 的数据以辅助定位运行异常的\ | /model_train/debug/rdr | +| | | 原因,也可以在框架正常执行\ | .html#>`_ | +| | | 过程保存框架关键状态数据,\ | | | | | 例如:IR、图执行顺序、内\ | | | | | 存分配等信息。 | | +---------------+-----------------------+-----------------------------+---------------------------+ | 专项控制 | 内存复用 | 可配置内存复用的开启与关闭\ | `内存复用 `_ | | | | | | | | | | | | | | | | +| | | | | +---------------+-----------------------+-----------------------------+---------------------------+ diff --git a/tutorials/source_zh_cn/advanced/error_analysis/cann_error_cases.md b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/cann_error_cases.md similarity index 99% rename from tutorials/source_zh_cn/advanced/error_analysis/cann_error_cases.md rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/cann_error_cases.md index 8887d8fdc968238addb0f2d4530e51e6fcf82837..3e5da3ed7b45ca61e6dc9aa2f5775d61ce853ca9 100644 --- a/tutorials/source_zh_cn/advanced/error_analysis/cann_error_cases.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/cann_error_cases.md @@ -1,6 +1,6 @@ # CANN常见错误分析 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/error_analysis/cann_error_cases.md)   +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/cann_error_cases.md)   本文主要介绍用户常见的CANN错误处理方法。在遇到CANN错误时,MindSpore的日志可能不足以分析相关错误,可以通过设置以下两个环境变量来打印CANN的日志以更好地分析错误: diff --git a/tutorials/source_zh_cn/advanced/error_analysis/error_scenario_analysis.md b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/error_scenario_analysis.md similarity index 87% rename from tutorials/source_zh_cn/advanced/error_analysis/error_scenario_analysis.md rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/error_scenario_analysis.md index 6f5db1e936a222932895af8571ef45d5e23ac71c..4942b03470dfb24538a1f1ff79bb799982fdd034 100644 --- a/tutorials/source_zh_cn/advanced/error_analysis/error_scenario_analysis.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/error_scenario_analysis.md @@ -1,6 +1,6 @@ # 错误分析 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/error_analysis/error_scenario_analysis.md)   +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/error_scenario_analysis.md)   如前文所述,错误分析是指基于获取到的网络、框架各种信息(例如:错误信息、网络代码等信息)进行错误原因分析,推断错误的可能原因。 @@ -20,9 +20,9 @@ | 常见错误类型 | 错误说明 | 案例分析 | |-------------|---------|---| -| 数据准备错误 | 数据集本身问题,包括数据集路径问题以及MindRecord 文件问题 | [数据准备错误案例](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/minddata_debug.html#数据准备) | -| 数据加载错误 | 数据加载阶段的资源配置错误、自定义加载方法错误以及迭代器使用错误等 | [数据加载错误案例](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/minddata_debug.html#数据加载) | -| 数据增强错误 | 数据格式不匹配、数据尺寸不匹配、资源占用问题、多线程卡死 | [数据增强错误案例](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/minddata_debug.html#数据增强) | +| 数据准备错误 | 数据集本身问题,包括数据集路径问题以及MindRecord 文件问题 | [数据准备错误案例](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/minddata_debug.html#数据准备) | +| 数据加载错误 | 数据加载阶段的资源配置错误、自定义加载方法错误以及迭代器使用错误等 | [数据加载错误案例](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/minddata_debug.html#数据加载) | +| 数据增强错误 | 数据格式不匹配、数据尺寸不匹配、资源占用问题、多线程卡死 | [数据增强错误案例](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/minddata_debug.html#数据增强) | ## 网络构建与训练错误分析 @@ -32,11 +32,11 @@ | 常见错误类型 | 错误说明 | 案例分析 | | - | - | - | -| context配置问题 | 系统进行上下文配置时的错误 | [context配置问题分析](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindrt_debug.html#context%E9%85%8D%E7%BD%AE%E9%97%AE%E9%A2%98)| -| 语法错误 | 包括Python语法错误和MindSpore静态图语法错误,例如控制流语法不支持、Tensor切片错误等 | [语法错误分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindrt_debug.html#语法问题) | -| 算子编译错误 | 包括算子参数值/类型/shape不满足要求、算子功能限制等 | [算子编译错误分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindrt_debug.html#算子编译错误) | -| 算子执行错误 | 包括输入数据异常、算子实现错误、功能限制、资源限制等 | [算子执行错误分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindrt_debug.html#算子执行错误) | -| 资源不足 | 包括设备内存不足、函数调用栈超限、流资源超限等 | [资源不足分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindrt_debug.html#资源不足) | +| context配置问题 | 系统进行上下文配置时的错误 | [context配置问题分析](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindrt_debug.html#context%E9%85%8D%E7%BD%AE%E9%97%AE%E9%A2%98)| +| 语法错误 | 包括Python语法错误和MindSpore静态图语法错误,例如控制流语法不支持、Tensor切片错误等 | [语法错误分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindrt_debug.html#语法问题) | +| 算子编译错误 | 包括算子参数值/类型/shape不满足要求、算子功能限制等 | [算子编译错误分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindrt_debug.html#算子编译错误) | +| 算子执行错误 | 包括输入数据异常、算子实现错误、功能限制、资源限制等 | [算子执行错误分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindrt_debug.html#算子执行错误) | +| 资源不足 | 包括设备内存不足、函数调用栈超限、流资源超限等 | [资源不足分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindrt_debug.html#资源不足) | ### 动态图模式错误分析 @@ -69,9 +69,9 @@ - 如果是计算图编译报错,根据报错描述和发生报错时自动保存的`analyze_failed.ir`文件,分析计算图推导失败的原因和位置; - 如果是计算图执行报错,可能是资源不足导致的执行报错,也可能是算子的执行报错,需要根据报错信息进行区分。如果是算子执行报错,首先确认是哪个算子,然后使用Dump功能保存算子的输入数据,通过输入数据分析算子报错的原因; -分析计算图推导失败的原因可以参考[`analyze_failed.ir`分析方法](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/mindir.html#如何根据analyze-failir文件分析图推导失败的原因)。 +分析计算图推导失败的原因可以参考[`analyze_failed.ir`分析方法](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/mindir.html#如何根据analyze-failir文件分析图推导失败的原因)。 -使用Dump保存算子输入数据可以参考[Dump功能调试](https://www.mindspore.cn/tutorials/experts/zh-CN/master/debug/dump.html)。 +使用Dump保存算子输入数据可以参考[Dump功能调试](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/dump.html)。 ## 分布式并行错误分析 @@ -274,11 +274,11 @@ EK0001: Path [/ms_test/csj/csj/user_scene/profiler_chinese_中文/resnet/scripts | 常见错误类型 | 错误说明 | 案例分析 | | - | - | - | -| AICORE算子编译问题 | AICORE算子编译时的错误 | [AICORE算子编译问题分析](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/cann_error_cases.html#aicore算子编译问题)| -| AICORE算子执行问题 | AICORE算子执行时的错误 | [AICORE算子执行问题分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/cann_error_cases.html#aicore算子执行问题) | -| AICPU算子执行问题 | AICPU算子执行时的错误 | [AICPU算子执行问题分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/cann_error_cases.html#aicpu算子执行问题) | -| runtime常见问题 | 包括输入数据异常、算子实现错误、功能限制、资源限制等 | [runtime常见问题分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/cann_error_cases.html#runtime常见问题) | -| HCCL&HCCP常见问题 | 多机多卡训练时的通信常见问题,包括socket建链超时、notify wait超时、ranktable配置错误等 | [HCCL&HCCP常见问题](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/cann_error_cases.html#hcclhccp常见问题) | -| profiling常见问题 | 性能调优运行profiling时的错误 | [profiling常见问题分析](https://mindspore.cn/tutorials/zh-CN/master/advanced/error_analysis/cann_error_cases.html#profiling常见问题) | +| AICORE算子编译问题 | AICORE算子编译时的错误 | [AICORE算子编译问题分析](https://www.mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/cann_error_cases.html#aicore算子编译问题)| +| AICORE算子执行问题 | AICORE算子执行时的错误 | [AICORE算子执行问题分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/cann_error_cases.html#aicore算子执行问题) | +| AICPU算子执行问题 | AICPU算子执行时的错误 | [AICPU算子执行问题分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/cann_error_cases.html#aicpu算子执行问题) | +| runtime常见问题 | 包括输入数据异常、算子实现错误、功能限制、资源限制等 | [runtime常见问题分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/cann_error_cases.html#runtime常见问题) | +| HCCL&HCCP常见问题 | 多机多卡训练时的通信常见问题,包括socket建链超时、notify wait超时、ranktable配置错误等 | [HCCL&HCCP常见问题](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/cann_error_cases.html#hcclhccp常见问题) | +| profiling常见问题 | 性能调优运行profiling时的错误 | [profiling常见问题分析](https://mindspore.cn/docs/zh-CN/master/model_train/debug/error_analysis/cann_error_cases.html#profiling常见问题) | 更多有关CANN错误的信息可前往[昇腾CANN开发者文档](https://www.hiascend.com/document/moreVersion/zh/CANNCommunityEdition/),查询对应CANN版本的故障处理章节。 diff --git a/tutorials/source_zh_cn/advanced/error_analysis/images/dot_to_png.png b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/dot_to_png.png similarity index 100% rename from tutorials/source_zh_cn/advanced/error_analysis/images/dot_to_png.png rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/dot_to_png.png diff --git a/tutorials/source_zh_cn/advanced/error_analysis/images/minddata_errmsg.png b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/minddata_errmsg.png similarity index 100% rename from tutorials/source_zh_cn/advanced/error_analysis/images/minddata_errmsg.png rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/minddata_errmsg.png diff --git a/tutorials/source_zh_cn/advanced/error_analysis/images/pynative_errmsg.png b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/pynative_errmsg.png similarity index 100% rename from tutorials/source_zh_cn/advanced/error_analysis/images/pynative_errmsg.png rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/images/pynative_errmsg.png diff --git a/tutorials/source_zh_cn/advanced/error_analysis/minddata_debug.md b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/minddata_debug.md similarity index 99% rename from tutorials/source_zh_cn/advanced/error_analysis/minddata_debug.md rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/minddata_debug.md index 50bba0dd36deb2feaa4991e36d44e69840df648a..dd3bbadcde1153bf87e9774d9c05e35d2ae0b853 100644 --- a/tutorials/source_zh_cn/advanced/error_analysis/minddata_debug.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/minddata_debug.md @@ -1,6 +1,6 @@ # 数据处理调试方法与常见问题分析 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/error_analysis/minddata_debug.md)   +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/minddata_debug.md)   ## 数据处理调试方法 diff --git a/tutorials/source_zh_cn/advanced/error_analysis/mindir.md b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindir.md similarity index 99% rename from tutorials/source_zh_cn/advanced/error_analysis/mindir.md rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindir.md index de9639a3a33130ede8b19ee3821ca3374d674f66..075829f269d02608dbe4c3e39b9416da66f35f0b 100644 --- a/tutorials/source_zh_cn/advanced/error_analysis/mindir.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindir.md @@ -1,6 +1,6 @@ # IR文件分析 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/error_analysis/mindir.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindir.md) ## 概述 diff --git a/tutorials/source_zh_cn/advanced/error_analysis/mindrt_debug.md b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindrt_debug.md similarity index 98% rename from tutorials/source_zh_cn/advanced/error_analysis/mindrt_debug.md rename to docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindrt_debug.md index 1187c4419e95ab72e1e8309633bb5c7cef97fda6..0beff393bff646ee8c8266e6865b7acbc18de9db 100644 --- a/tutorials/source_zh_cn/advanced/error_analysis/mindrt_debug.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindrt_debug.md @@ -1,6 +1,6 @@ # 网络构建与训练常见错误分析 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/error_analysis/mindrt_debug.md)   +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/error_analysis/mindrt_debug.md)   静态图模式下,网络构建与训练过程的常见的报错类型如下所示: diff --git a/tutorials/experts/source_zh_cn/debug/fault_recover.md b/docs/mindspore/source_zh_cn/model_train/debug/fault_recover.md similarity index 98% rename from tutorials/experts/source_zh_cn/debug/fault_recover.md rename to docs/mindspore/source_zh_cn/model_train/debug/fault_recover.md index d9e8fdb2b3dc1ce2db045bbd6fb1f076d941d537..ba17a2cd46b4b8f75c399043cbba2348a1740ea9 100644 --- a/tutorials/experts/source_zh_cn/debug/fault_recover.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/fault_recover.md @@ -1,6 +1,6 @@ # 故障恢复 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/debug/fault_recover.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/fault_recover.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/optimize/graph_fusion_engine.ipynb b/docs/mindspore/source_zh_cn/model_train/debug/graph_fusion_engine.ipynb similarity index 90% rename from tutorials/experts/source_zh_cn/optimize/graph_fusion_engine.ipynb rename to docs/mindspore/source_zh_cn/model_train/debug/graph_fusion_engine.ipynb index 6be1a05bd2bc05c11afffee61cf49cb5a928443e..1a3fda8c431e203764324660c2d1fcfd8d62c253 100644 --- a/tutorials/experts/source_zh_cn/optimize/graph_fusion_engine.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/debug/graph_fusion_engine.ipynb @@ -7,7 +7,7 @@ "source": [ "# 使能图算融合\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/optimize/mindspore_graph_fusion_engine.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/optimize/mindspore_graph_fusion_engine.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/optimize/graph_fusion_engine.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/debug/mindspore_graph_fusion_engine.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/debug/mindspore_graph_fusion_engine.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/graph_fusion_engine.ipynb)\n", "\n", "## 概述\n", "\n", @@ -98,7 +98,7 @@ "source": [ "该计算图的融合结果如图1所示,其中左图为未使能图算融合时的对应计算图,右图为使能图算融合后的对应计算图。可以看到该网络中的加法和乘法被融合成一个算子。该融合过程可以通过查看中间IR,或者通过Profiling等工具跟踪算子执行过程进行验证。\n", "\n", - "![基本算子融合示例](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/graph_kernel_example_fuse_basic.png)\n", + "![基本算子融合示例](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/debug/images/graph_kernel_example_fuse_basic.png)\n", "\n", "图1:*图算融合优化计算图*\n", "\n", @@ -175,7 +175,7 @@ "source": [ "该计算图的融合结果如图2所示,其中左图为未使能图算融合时的对应计算图,右图为使能图算融合后的对应计算图。可以看到不仅自定义算子`MyOp`中的基本算子进行了融合,并且与主图中的其他算子也进行了更大范围融合。该融合过程可以通过查看中间IR,或者通过Profiling等工具跟踪算子执行过程进行验证。\n", "\n", - "![自定义组合算子融合示例](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/graph_kernel_example_custom_op.png)\n", + "![自定义组合算子融合示例](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/debug/images/graph_kernel_example_custom_op.png)\n", "\n", "图2:*自定义组合算子优化计算图*\n", "\n", diff --git a/docs/mindspore/source_zh_cn/model_train/debug/images/data-and-graph-sink.eddx b/docs/mindspore/source_zh_cn/model_train/debug/images/data-and-graph-sink.eddx new file mode 100644 index 0000000000000000000000000000000000000000..ac699504b7016c7bf26787615d0d86fed5d1cd14 Binary files /dev/null and b/docs/mindspore/source_zh_cn/model_train/debug/images/data-and-graph-sink.eddx differ diff --git a/tutorials/source_zh_cn/advanced/images/error_debug.png b/docs/mindspore/source_zh_cn/model_train/debug/images/error_debug.png similarity index 100% rename from tutorials/source_zh_cn/advanced/images/error_debug.png rename to docs/mindspore/source_zh_cn/model_train/debug/images/error_debug.png diff --git a/tutorials/source_zh_cn/advanced/images/graph_errmsg.png b/docs/mindspore/source_zh_cn/model_train/debug/images/graph_errmsg.png similarity index 100% rename from tutorials/source_zh_cn/advanced/images/graph_errmsg.png rename to docs/mindspore/source_zh_cn/model_train/debug/images/graph_errmsg.png diff --git a/tutorials/experts/source_zh_cn/optimize/images/graph_kernel_example_custom_op.png b/docs/mindspore/source_zh_cn/model_train/debug/images/graph_kernel_example_custom_op.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/graph_kernel_example_custom_op.png rename to docs/mindspore/source_zh_cn/model_train/debug/images/graph_kernel_example_custom_op.png diff --git a/tutorials/experts/source_zh_cn/optimize/images/graph_kernel_example_fuse_basic.png b/docs/mindspore/source_zh_cn/model_train/debug/images/graph_kernel_example_fuse_basic.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/graph_kernel_example_fuse_basic.png rename to docs/mindspore/source_zh_cn/model_train/debug/images/graph_kernel_example_fuse_basic.png diff --git a/tutorials/experts/source_zh_cn/optimize/mem_reuse.md b/docs/mindspore/source_zh_cn/model_train/debug/mem_reuse.md similarity index 89% rename from tutorials/experts/source_zh_cn/optimize/mem_reuse.md rename to docs/mindspore/source_zh_cn/model_train/debug/mem_reuse.md index 3276823340a7160ddcba9950c9bf48ca9468b726..8cf702cfb81dfc4b8795eac40ef8766050056543 100644 --- a/tutorials/experts/source_zh_cn/optimize/mem_reuse.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/mem_reuse.md @@ -1,6 +1,6 @@ # 内存复用 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/optimize/mem_reuse.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/mem_reuse.md) ## 概述 diff --git a/docs/mindspore/source_zh_cn/model_train/debug/opt_tools.rst b/docs/mindspore/source_zh_cn/model_train/debug/opt_tools.rst new file mode 100644 index 0000000000000000000000000000000000000000..45cf0c70f53989e0f2bd3b0056e860413d90c55b --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/debug/opt_tools.rst @@ -0,0 +1,9 @@ +调优工具集 +============ + +.. toctree:: + :maxdepth: 1 + + graph_fusion_engine + mem_reuse + aoe \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/model_train/debug/overview.md b/docs/mindspore/source_zh_cn/model_train/debug/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..86e46febcf35e46b3992223ced79ddb0d9f871a3 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/debug/overview.md @@ -0,0 +1,3 @@ +# 调试调优概述 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/overview.md) diff --git a/tutorials/experts/source_zh_cn/debug/rdr.md b/docs/mindspore/source_zh_cn/model_train/debug/rdr.md similarity index 96% rename from tutorials/experts/source_zh_cn/debug/rdr.md rename to docs/mindspore/source_zh_cn/model_train/debug/rdr.md index d599b0f102700fb376950ce4ec2d1f9bc6ebc2a5..8a1e17a454217adf2f19b75e6ae29d4dae0be7ed 100644 --- a/tutorials/experts/source_zh_cn/debug/rdr.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/rdr.md @@ -1,6 +1,6 @@ # Running Data Recorder -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/debug/rdr.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/rdr.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/debug/sdc.md b/docs/mindspore/source_zh_cn/model_train/debug/sdc.md similarity index 98% rename from tutorials/experts/source_zh_cn/debug/sdc.md rename to docs/mindspore/source_zh_cn/model_train/debug/sdc.md index ab34a23b9c8740e39d717746399a3cdaa15a9876..900b1ea95facbb09693fac43b7b80bcbba5c431f 100644 --- a/tutorials/experts/source_zh_cn/debug/sdc.md +++ b/docs/mindspore/source_zh_cn/model_train/debug/sdc.md @@ -1,6 +1,6 @@ # 特征值检测 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/debug/sdc.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/debug/sdc.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/index.rst b/docs/mindspore/source_zh_cn/model_train/index.rst similarity index 36% rename from tutorials/experts/source_zh_cn/index.rst rename to docs/mindspore/source_zh_cn/model_train/index.rst index 7f6977b5aa753ed12616695ef1568f83e0446800..c97c3924f59c5542669a8700a05d4debdae45a9c 100644 --- a/tutorials/experts/source_zh_cn/index.rst +++ b/docs/mindspore/source_zh_cn/model_train/index.rst @@ -1,92 +1,85 @@ -.. MindSpore documentation master file, created by - sphinx-quickstart on Thu Mar 24 11:00:00 2022. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -深度开发 -===================== - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 分布式并行 - :titlesonly: - - parallel/overview - parallel/startup_method - parallel/data_parallel - parallel/semi_auto_parallel - parallel/auto_parallel - parallel/manual_parallel - parallel/parameter_server_training - parallel/model_save_load - parallel/recover - parallel/optimize_technique - parallel/others - parallel/distributed_case - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 自定义算子 - - operation/op_custom - operation/ms_kernel - operation/op_custom_adv - operation/op_custom_aot - operation/op_custom_ascendc +模型构建与训练 +========================= .. toctree:: :glob: :maxdepth: 1 - :caption: 性能优化 + :caption: 编程形态 - Profiling↗ - optimize/execution_opt - optimize/graph_fusion_engine - optimize/mem_reuse + program_form/overview + program_form/pynative + program_form/static_graph + program_form/jit + program_form/interface + program_form/index_support .. toctree:: :glob: :maxdepth: 1 - :caption: 算法优化 - - optimize/gradient_accumulation - optimize/thor + :caption: 自定义高阶编程 + + custom_program/overview + custom_program/layer + custom_program/op_custom + custom_program/initializer + custom_program/loss + custom_program/optimizer + custom_program/fusion_pass + custom_program/network_custom + custom_program/hook_program .. toctree:: :glob: :maxdepth: 1 - :caption: 高阶函数式编程 + :caption: 数据加载与处理 - vmap/vmap - func_programming/Jacobians_Hessians - func_programming/per_sample_gradients + dataset/overview + dataset/sampler + dataset/record + dataset/eager + dataset/python_objects + dataset/augment + dataset/cache + dataset/optimize .. toctree:: :glob: :maxdepth: 1 - :caption: 数据处理 + :caption: 训练流程 - dataset/augment - dataset/cache - dataset/optimize + train_process/overview + train_process/model + train_process/dynamic_shape + train_process/train_optimize + train_process/func_programming + train_process/derivation + train_process/algorithm_optimize .. toctree:: :glob: :maxdepth: 1 - :caption: 模型推理 + :caption: 分布式并行 - infer/inference - infer/model_compression + parallel/overview + parallel/startup_method + parallel/data_parallel + parallel/semi_auto_parallel + parallel/auto_parallel + parallel/manual_parallel + parallel/parameter_server_training + parallel/model_save_load + parallel/recover + parallel/optimize_technique + parallel/others + parallel/distributed_case .. toctree:: :glob: :maxdepth: 1 - :caption: 复杂问题调试 + :caption: 调试调优 - debug/dump - debug/aoe - debug/rdr - debug/fault_recover - debug/sdc + debug/overview + debug/error_analysis + debug/debug_tools + debug/opt_tools + 报错地图↗ diff --git a/tutorials/experts/source_zh_cn/parallel/advanced_operator_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/advanced_operator_parallel.md similarity index 87% rename from tutorials/experts/source_zh_cn/parallel/advanced_operator_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/advanced_operator_parallel.md index 80b9b25a04b89b8ee93804a8ab31f60dd36d27f4..daab4a65b3da566c69cbb70805ee597e4a24f422 100644 --- a/tutorials/experts/source_zh_cn/parallel/advanced_operator_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/advanced_operator_parallel.md @@ -1,16 +1,16 @@ # 高阶算子级并行 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/advanced_operator_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/advanced_operator_parallel.md) ## 概述 -[算子级并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/operator_parallel.html) 是大模型训练推理中常用的并行技术,它可以将张量切分到多卡上,有效降低单卡上的显存。MindSpore进行算子级并行的配置是通过mindspore.ops.Primitive.shard()接口,对算子的每个输入,以tuple描述张量的切分,对于大多数场景配置简易,相应地,该种切分方式仅描述了张量切分,却向用户屏蔽了张量在设备rank上的排布,因此表达的张量切分与设备排布的映射关系有限,无法支撑一些更为复杂的场景的切分。因此,本教程将介绍开放设备排布描述的算子级并行配置方法。 +[算子级并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/operator_parallel.html) 是大模型训练推理中常用的并行技术,它可以将张量切分到多卡上,有效降低单卡上的显存。MindSpore进行算子级并行的配置是通过mindspore.ops.Primitive.shard()接口,对算子的每个输入,以tuple描述张量的切分,对于大多数场景配置简易,相应地,该种切分方式仅描述了张量切分,却向用户屏蔽了张量在设备rank上的排布,因此表达的张量切分与设备排布的映射关系有限,无法支撑一些更为复杂的场景的切分。因此,本教程将介绍开放设备排布描述的算子级并行配置方法。 > 高级算子级并行模型支持的硬件平台包括Ascend、GPU,需要在Graph模式下运行。 ## 背景 -[算子级并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/operator_parallel.html) 章节中介绍了MindSpore对张量的基本切分逻辑,但是不能表达出所有的切分场景。对于一个二维张量 "[[a0, a1, a2, a3], [a4, a5, a6, a7]]"如下图所示的张量分布: +[算子级并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/operator_parallel.html) 章节中介绍了MindSpore对张量的基本切分逻辑,但是不能表达出所有的切分场景。对于一个二维张量 "[[a0, a1, a2, a3], [a4, a5, a6, a7]]"如下图所示的张量分布: ![image](images/advanced_operator_parallel_view1.PNG) @@ -235,4 +235,4 @@ epoch: 0, step: 90, loss is 0.7807965 ... ``` -其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 diff --git a/tutorials/experts/source_zh_cn/parallel/auto_parallel.rst b/docs/mindspore/source_zh_cn/model_train/parallel/auto_parallel.rst similarity index 88% rename from tutorials/experts/source_zh_cn/parallel/auto_parallel.rst rename to docs/mindspore/source_zh_cn/model_train/parallel/auto_parallel.rst index ab621d957349a4f20bd888b2427cefb8cb900fa1..0dab543e53409ae3533a979404618f25854aba67 100644 --- a/tutorials/experts/source_zh_cn/parallel/auto_parallel.rst +++ b/docs/mindspore/source_zh_cn/model_train/parallel/auto_parallel.rst @@ -2,7 +2,7 @@ ======================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/auto_parallel.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/auto_parallel.rst :alt: 查看源文件 .. toctree:: @@ -14,8 +14,8 @@ 自动并行模式让用户无需关心策略配置,自动地建立代价模型,找到训练时间较短的并行策略。当前MindSpore支持如下两种不同的自动并行方案: -- `切分策略传播算法 `_:由配置并行策略的算子向未配置的算子传播并行策略。在传播时,算法会尽量选取引发张量重排布通信最少的策略。 -- `双递归策略搜索算法 `_:其基于符号运算的代价模型可以自由适配不同的加速器集群,对于巨大网络以及大规模多卡切分能够保证瞬间生成最优策略。 +- `切分策略传播算法 `_:由配置并行策略的算子向未配置的算子传播并行策略。在传播时,算法会尽量选取引发张量重排布通信最少的策略。 +- `双递归策略搜索算法 `_:其基于符号运算的代价模型可以自由适配不同的加速器集群,对于巨大网络以及大规模多卡切分能够保证瞬间生成最优策略。 自动并行算法是基于算子级模型并行的策略搜索算法,要了解其原理,首先需要了解MindSpore算子级并行中的基本概念:分布式算子、张量排布和张量重排布。算子级并行属于“单程序多数据”(Single Program Multiple Data,SPMD)的一种实现。同一段程序执行在不同数据分片上。MindSpore将单机版本的程序转换成并行版本的程序。该转换是细粒度的,会将单机版本程序中每个算子替换成分布式算子,同时保证替换是数学等价的。 diff --git a/tutorials/experts/source_zh_cn/parallel/comm_fusion.md b/docs/mindspore/source_zh_cn/model_train/parallel/comm_fusion.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/comm_fusion.md rename to docs/mindspore/source_zh_cn/model_train/parallel/comm_fusion.md index ee7d3ba671eeb92f98ab4902c9121eaac706797d..df9e98e5bf47376ab2c4c37ffd215bf2c1180bff 100644 --- a/tutorials/experts/source_zh_cn/parallel/comm_fusion.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/comm_fusion.md @@ -1,6 +1,6 @@ # 分布式训练通信融合 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/comm_fusion.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/comm_fusion.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/comm_subgraph.md b/docs/mindspore/source_zh_cn/model_train/parallel/comm_subgraph.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/comm_subgraph.md rename to docs/mindspore/source_zh_cn/model_train/parallel/comm_subgraph.md index edf1a9bfb631a11b79b9cd156d3547b174dce8a1..c586b380ea16134bbdb63e21f16254e8c1e94445 100644 --- a/tutorials/experts/source_zh_cn/parallel/comm_subgraph.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/comm_subgraph.md @@ -1,6 +1,6 @@ # 通信子图提取与复用 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/comm_subgraph.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/comm_subgraph.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/data_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/data_parallel.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/data_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/data_parallel.md index b31d57cd185f7d2d7d761f71e050d817161ea323..ab585559af943e24ea5952da1d65b2ac7cf5926f 100644 --- a/tutorials/experts/source_zh_cn/parallel/data_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/data_parallel.md @@ -1,6 +1,6 @@ # 数据并行 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/data_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/data_parallel.md) ## 概述 @@ -211,4 +211,4 @@ epoch: 0 step: 30, loss is 2.2938071 ... ``` -其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 diff --git a/tutorials/experts/source_zh_cn/parallel/dataset_slice.md b/docs/mindspore/source_zh_cn/model_train/parallel/dataset_slice.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/dataset_slice.md rename to docs/mindspore/source_zh_cn/model_train/parallel/dataset_slice.md index de1f5ec00d5ae0706ce8a0afdc05eeed1ec02061..a4506e2f19ecfca7cc8e2606eb309e6a24a7d828 100644 --- a/tutorials/experts/source_zh_cn/parallel/dataset_slice.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/dataset_slice.md @@ -1,6 +1,6 @@ # 数据集切分 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/dataset_slice.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/dataset_slice.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/disaster_recover.md b/docs/mindspore/source_zh_cn/model_train/parallel/disaster_recover.md similarity index 95% rename from tutorials/experts/source_zh_cn/parallel/disaster_recover.md rename to docs/mindspore/source_zh_cn/model_train/parallel/disaster_recover.md index 7bc2bd89e42f3606671c9f57a32802ff550419b6..42d0d9cfffab8b583ed9734a798e10ae9faaa73c 100644 --- a/tutorials/experts/source_zh_cn/parallel/disaster_recover.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/disaster_recover.md @@ -1,6 +1,6 @@ # 动态组网场景下故障恢复 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/disaster_recover.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/disaster_recover.md) ## 概述 @@ -10,7 +10,7 @@ > 动态组网场景下的容灾恢复仅支持GPU,需要在Graph模式下运行。 -更多详细说明请查看[动态组网环境变量](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)。 +更多详细说明请查看[动态组网环境变量](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)。 ## 操作实践 @@ -35,7 +35,7 @@ ### 网络结构 -网络结构和数据集加载与[动态组网启动](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)中的示例一致。 +网络结构和数据集加载与[动态组网启动](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)中的示例一致。 ### 定义训练过程 diff --git a/tutorials/experts/source_zh_cn/parallel/distributed_case.rst b/docs/mindspore/source_zh_cn/model_train/parallel/distributed_case.rst similarity index 68% rename from tutorials/experts/source_zh_cn/parallel/distributed_case.rst rename to docs/mindspore/source_zh_cn/model_train/parallel/distributed_case.rst index 478bc71e14f42a8fff457c2d3845aa83dd3441f4..baa0d4a5cee90c80e3b2bdbebfc659f74746095a 100644 --- a/tutorials/experts/source_zh_cn/parallel/distributed_case.rst +++ b/docs/mindspore/source_zh_cn/model_train/parallel/distributed_case.rst @@ -2,7 +2,7 @@ ======================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/distributed_case.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/distributed_case.rst :alt: 查看源文件 .. toctree:: diff --git a/tutorials/experts/source_zh_cn/parallel/distributed_gradient_accumulation.md b/docs/mindspore/source_zh_cn/model_train/parallel/distributed_gradient_accumulation.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/distributed_gradient_accumulation.md rename to docs/mindspore/source_zh_cn/model_train/parallel/distributed_gradient_accumulation.md index 24658acf4bd91d72aacfe183eda738115f8d6c25..43944d586df4a6c15e53e8304aebdd6d9b579837 100644 --- a/tutorials/experts/source_zh_cn/parallel/distributed_gradient_accumulation.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/distributed_gradient_accumulation.md @@ -1,6 +1,6 @@ # 梯度累加 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/distributed_gradient_accumulation.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/distributed_gradient_accumulation.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/distributed_graph_partition.md b/docs/mindspore/source_zh_cn/model_train/parallel/distributed_graph_partition.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/distributed_graph_partition.md rename to docs/mindspore/source_zh_cn/model_train/parallel/distributed_graph_partition.md index 7f87e1533493cf4cda4f8e73089612378e87f3a3..cb138ba565ccf0cf4d348c8900250dcfe7abc179 100644 --- a/tutorials/experts/source_zh_cn/parallel/distributed_graph_partition.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/distributed_graph_partition.md @@ -1,6 +1,6 @@ # 分布式图切分 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/distributed_graph_partition.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/distributed_graph_partition.md) ## 概述 @@ -16,7 +16,7 @@ ## 基本原理 -分布式任务需要在一个集群中执行,MindSpore为了在分布式图切分场景中拥有更好的可扩展性和可靠性,复用了MindSpore内置的[动态组网模块](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)。 +分布式任务需要在一个集群中执行,MindSpore为了在分布式图切分场景中拥有更好的可扩展性和可靠性,复用了MindSpore内置的[动态组网模块](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)。 对于`分布式图切分`来说,每一个进程都代表一个计算节点(称之为`Worker`),通过上述的`动态组网`模块,启动的调度节点(称之为`Scheduler`)可以让发现各个计算节点,进而组成一个计算集群。 在`动态组网`后,MindSpore会根据用户启动配置,为每个进程分配`role`和`rank`,即每个进程的`角色`和`id`,两者组成了每个进程的唯一`标签`,并且是Python层API`place`的入参。有了这层对应关系,用户可以通过调用`place`接口,对任意算子设置进程标签,MindSpore图编译模块处理后,将计算图切分成多个子图分发到不同进程上执行。`place`具体用法可参考[Primitive.place](https://www.mindspore.cn/docs/zh-CN/master/api_python/ops/mindspore.ops.Primitive.html#mindspore.ops.Primitive.place)以及[Cell.place](https://www.mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.place)接口文档。 @@ -228,7 +228,7 @@ if get_rank() == 0: #### 启动Scheduler和Worker进程 -由于是在节点内启动多个进程,因此只需要通过一个Shell脚本启动一个`Scheduler`进程和多个`Worker`进程。对于脚本中的环境变量含义以及用法,可以参考[动态组网环境变量](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)。 +由于是在节点内启动多个进程,因此只需要通过一个Shell脚本启动一个`Scheduler`进程和多个`Worker`进程。对于脚本中的环境变量含义以及用法,可以参考[动态组网环境变量](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)。 run.sh执行脚本如下: diff --git a/tutorials/experts/source_zh_cn/parallel/dynamic_cluster.md b/docs/mindspore/source_zh_cn/model_train/parallel/dynamic_cluster.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/dynamic_cluster.md rename to docs/mindspore/source_zh_cn/model_train/parallel/dynamic_cluster.md index 7614617354313f0d586cf13d5eb4f571d0eb9ee6..857cd7d56991bd66610ed7818695f2e3b1232821 100644 --- a/tutorials/experts/source_zh_cn/parallel/dynamic_cluster.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/dynamic_cluster.md @@ -1,12 +1,12 @@ # 动态组网启动 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/dynamic_cluster.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/dynamic_cluster.md) ## 概述 出于训练时的可靠性要求,MindSpore提供了**动态组网**特性,用户能够不依赖任何第三方库(OpenMPI)来启动Ascend/GPU/CPU分布式训练任务,并且训练脚本无需做任何修改。我们建议用户优先使用此种启动方式。 -MindSpore**动态组网**特性通过**复用Parameter Server模式训练架构**,取代了OpenMPI能力,可参考[Parameter Server模式](https://mindspore.cn/tutorials/experts/zh-CN/master/parallel/parameter_server_training.html)训练教程。 +MindSpore**动态组网**特性通过**复用Parameter Server模式训练架构**,取代了OpenMPI能力,可参考[Parameter Server模式](https://mindspore.cn/docs/zh-CN/master/model_train/parallel/parameter_server_training.html)训练教程。 **动态组网**特性将多个MindSpore训练进程作为`Worker`启动,并且额外启动一个`Scheduler`负责组网和容灾恢复,因此无需借助OpenMPI的消息传递机制即可实现分布式训练。用户只需对启动脚本做少量修改,即可执行分布式训练。 @@ -30,7 +30,7 @@ MindSpore**动态组网**特性通过**复用Parameter Server模式训练架构*
    Worker和Parameter Server进程会向Scheduler进程注册从而完成组网。 @@ -412,7 +412,7 @@ bash run_dynamic_cluster_2.sh ## 容灾恢复 -动态组网支持数据并行下容灾恢复。在多卡数据并行训练场景下,发生进程异常退出,重新拉起对应进程对应的脚本后训练可继续,并且不影响精度收敛。容灾恢复配置和样例可参考[动态组网场景下故障恢复](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/disaster_recover.html)教程。 +动态组网支持数据并行下容灾恢复。在多卡数据并行训练场景下,发生进程异常退出,重新拉起对应进程对应的脚本后训练可继续,并且不影响精度收敛。容灾恢复配置和样例可参考[动态组网场景下故障恢复](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/disaster_recover.html)教程。 ## 安全认证 diff --git a/tutorials/experts/source_zh_cn/parallel/fault_recover.md b/docs/mindspore/source_zh_cn/model_train/parallel/fault_recover.md similarity index 93% rename from tutorials/experts/source_zh_cn/parallel/fault_recover.md rename to docs/mindspore/source_zh_cn/model_train/parallel/fault_recover.md index ea0af4f5958e72f9c83036891d988b091e6e07ca..6f856ac3789d3fbdcc1fa9ee62b843a6285b14f6 100644 --- a/tutorials/experts/source_zh_cn/parallel/fault_recover.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/fault_recover.md @@ -1,6 +1,6 @@ # 基于冗余信息的故障恢复 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/fault_recover.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/fault_recover.md) ## 概述 @@ -10,12 +10,12 @@ 但是,对于大模型来说,使用汇聚保存对各种资源的开销都过于巨大,因此,本文档介绍的是每张卡仅仅保存自身的权重信息的恢复方案。对于大模型来说,往往会同时应用上数据并行与模型并行,而数据并行的维度所划分的设备,它们持有的权重信息是完全一致的,这也为大模型提供了冗余的备份,本文档也将指出如何去获取这个冗余信息。 -关于并行策略与权重的切片划分的关系,可以进行如下映射。关于数据并行,模型并行的概念,请参考[算子级并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/operator_parallel.html) ;关于优化器并行,请参考[优化器并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/optimizer_parallel.html)。 +关于并行策略与权重的切片划分的关系,可以进行如下映射。关于数据并行,模型并行的概念,请参考[算子级并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/operator_parallel.html) ;关于优化器并行,请参考[优化器并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/optimizer_parallel.html)。 - 数据并行 + 不开启优化器并行:并行通信域内的rank持有相同权重切片。 - 模型并行:并行通信域内的rank持有不同权重切片。 -另外,需要注意的是,本文档介绍分布式故障恢复方案,需要在[下沉模式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/optimize/execution_opt.html) 下使用。 +另外,需要注意的是,本文档介绍分布式故障恢复方案,需要在[下沉模式](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/train_optimize.html#下沉模式) 下使用。 相关环境变量: diff --git a/tutorials/experts/source_zh_cn/parallel/host_device_training.md b/docs/mindspore/source_zh_cn/model_train/parallel/host_device_training.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/host_device_training.md rename to docs/mindspore/source_zh_cn/model_train/parallel/host_device_training.md index bbfa9fb9ec8b0f0a862f23312bd520ab87c82a75..a4e85ed90032e73a920bf95d999944d126f7c17e 100644 --- a/tutorials/experts/source_zh_cn/parallel/host_device_training.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/host_device_training.md @@ -1,6 +1,6 @@ # Host&Device异构 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/host_device_training.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/host_device_training.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/images/advanced_operator_parallel_view1.PNG b/docs/mindspore/source_zh_cn/model_train/parallel/images/advanced_operator_parallel_view1.PNG similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/advanced_operator_parallel_view1.PNG rename to docs/mindspore/source_zh_cn/model_train/parallel/images/advanced_operator_parallel_view1.PNG diff --git a/tutorials/experts/source_zh_cn/parallel/images/advanced_operator_parallel_view2.PNG b/docs/mindspore/source_zh_cn/model_train/parallel/images/advanced_operator_parallel_view2.PNG similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/advanced_operator_parallel_view2.PNG rename to docs/mindspore/source_zh_cn/model_train/parallel/images/advanced_operator_parallel_view2.PNG diff --git a/tutorials/experts/source_zh_cn/parallel/images/checkpoint_integrate_process.pptx b/docs/mindspore/source_zh_cn/model_train/parallel/images/checkpoint_integrate_process.pptx similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/checkpoint_integrate_process.pptx rename to docs/mindspore/source_zh_cn/model_train/parallel/images/checkpoint_integrate_process.pptx diff --git a/tutorials/experts/source_zh_cn/parallel/images/comm_subgraph.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/comm_subgraph.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/comm_subgraph.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/comm_subgraph.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/data_parallel.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/data_parallel.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/data_parallel.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/data_parallel.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/distributed_graph_partition.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/distributed_graph_partition.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/distributed_graph_partition.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/distributed_graph_partition.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/host_device_image_0_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/host_device_image_0_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/host_device_image_0_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/host_device_image_0_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/host_device_image_1_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/host_device_image_1_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/host_device_image_1_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/host_device_image_1_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/megatron.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/megatron.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/megatron.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/megatron.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/memory_offload.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/memory_offload.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/memory_offload.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/memory_offload.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/mindspore.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/mindspore.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/mindspore.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/mindspore.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_0_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_0_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_0_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_0_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_1_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_1_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_1_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_1_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_2_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_2_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_2_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_2_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_3_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_3_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_3_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_3_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_4_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_4_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/operator_parallel_image_4_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/operator_parallel_image_4_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/optimizer_parallel_image_0_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/optimizer_parallel_image_0_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/optimizer_parallel_image_0_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/optimizer_parallel_image_0_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/optimizer_parallel_image_1_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/optimizer_parallel_image_1_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/optimizer_parallel_image_1_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/optimizer_parallel_image_1_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/pangu_strategy.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/pangu_strategy.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/pangu_strategy.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/pangu_strategy.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_0_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_0_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_0_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_0_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_1_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_1_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_1_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_1_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_2_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_2_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/pipeline_parallel_image_2_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/pipeline_parallel_image_2_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/pynative_jit.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/pynative_jit.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/pynative_jit.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/pynative_jit.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/recompute_image_0_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/recompute_image_0_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/recompute_image_0_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/recompute_image_0_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/recompute_image_1_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/recompute_image_1_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/recompute_image_1_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/recompute_image_1_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/sharding_propagation_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/sharding_propagation_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/sharding_propagation_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/sharding_propagation_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/sp_case1_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/sp_case1_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/sp_case1_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/sp_case1_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/sp_case2_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/sp_case2_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/sp_case2_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/sp_case2_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/sp_case3_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/sp_case3_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/sp_case3_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/sp_case3_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/tensor_layout_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/tensor_layout_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/tensor_layout_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/tensor_layout_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/images/tensor_redistribution_zh.png b/docs/mindspore/source_zh_cn/model_train/parallel/images/tensor_redistribution_zh.png similarity index 100% rename from tutorials/experts/source_zh_cn/parallel/images/tensor_redistribution_zh.png rename to docs/mindspore/source_zh_cn/model_train/parallel/images/tensor_redistribution_zh.png diff --git a/tutorials/experts/source_zh_cn/parallel/manual_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/manual_parallel.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/manual_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/manual_parallel.md index 90368dbe2e349e3e68fb5cb9f75465fd20b415a3..800dbbb8a4f49d99ba336663a2b63f3493069fc7 100644 --- a/tutorials/experts/source_zh_cn/parallel/manual_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/manual_parallel.md @@ -1,6 +1,6 @@ # 手动并行 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/manual_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/manual_parallel.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/memory_offload.md b/docs/mindspore/source_zh_cn/model_train/parallel/memory_offload.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/memory_offload.md rename to docs/mindspore/source_zh_cn/model_train/parallel/memory_offload.md index 6ad4f07640e0b37b8041f67c7655ce95628aacaf..fa184506a5fac5408e42348d8412542162c573c8 100644 --- a/tutorials/experts/source_zh_cn/parallel/memory_offload.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/memory_offload.md @@ -1,6 +1,6 @@ # 异构存储 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/memory_offload.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/memory_offload.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/model_loading.md b/docs/mindspore/source_zh_cn/model_train/parallel/model_loading.md similarity index 89% rename from tutorials/experts/source_zh_cn/parallel/model_loading.md rename to docs/mindspore/source_zh_cn/model_train/parallel/model_loading.md index dc649b151b702584b0ac3138665d74e9bb89a76a..1e1aefc473936f12001e200236679c12b0c7ea3b 100644 --- a/tutorials/experts/source_zh_cn/parallel/model_loading.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/model_loading.md @@ -1,14 +1,14 @@ # 模型加载 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/model_loading.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/model_loading.md) ## 概述 -分布式下的模型加载主要是指分布式推理,即推理阶段采用多卡进行推理。如果训练时采用数据并行或者模型参数是合并保存,那么每张卡均持有完整的权重,每张卡推理自身的输入数据,推理方式与[单卡推理](https://www.mindspore.cn/tutorials/experts/zh-CN/master/infer/inference.html#modeleval模型验证)一致,只需要注意每卡加载同样的CheckPoint文件进行推理。 +分布式下的模型加载主要是指分布式推理,即推理阶段采用多卡进行推理。如果训练时采用数据并行或者模型参数是合并保存,那么每张卡均持有完整的权重,每张卡推理自身的输入数据,推理方式与[单卡推理](https://www.mindspore.cn/docs/zh-CN/master/model_infer/overview.html#modeleval模型验证)一致,只需要注意每卡加载同样的CheckPoint文件进行推理。 本篇教程主要介绍在多卡训练过程中,每张卡上保存模型的切片,在推理阶段采用多卡形式,按照推理策略重新加载模型进行推理的过程。针对超大规模神经网络模型的参数个数过多,模型无法完全加载至单卡中进行推理的问题,可利用多卡进行分布式推理。 -> - 当模型非常大,本教程中使用[load_distributed_checkpoint](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.load_distributed_checkpoint.html)接口主机内存不足情况下,可以参考[模型转换](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_transformation.html#对目标网络执行编译) 章节,先对网络执行编译,然后执行分布式Checkpoint转换,就可以让每张卡加载自身对应的切片Checkpoint。 -> - 若采用流水线分布式推理,则训练也必须采用流水线并行训练,并且流水线并行训练和推理所用的`device_num`以及`pipeline_stages`必须相同。流水线并行推理时,`micro_batch`为1,不需要调用`PipelineCell`,每个`stage`只需要加载本`stage`的Checkpoint文件。参考[流水线并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/pipeline_parallel.html)训练教程。 +> - 当模型非常大,本教程中使用[load_distributed_checkpoint](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.load_distributed_checkpoint.html)接口主机内存不足情况下,可以参考[模型转换](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_transformation.html#对目标网络执行编译) 章节,先对网络执行编译,然后执行分布式Checkpoint转换,就可以让每张卡加载自身对应的切片Checkpoint。 +> - 若采用流水线分布式推理,则训练也必须采用流水线并行训练,并且流水线并行训练和推理所用的`device_num`以及`pipeline_stages`必须相同。流水线并行推理时,`micro_batch`为1,不需要调用`PipelineCell`,每个`stage`只需要加载本`stage`的Checkpoint文件。参考[流水线并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/pipeline_parallel.html)训练教程。 相关接口: @@ -46,7 +46,7 @@ 其中,`test_loading.py`是定义网络结构和推理的脚本。`run_loading.sh`是执行脚本。 -用户首先需要按照[模型保存](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_saving.html)教程执行8卡分布式训练,训练结束后将会在当前路径生成Checkpoint文件目录以及切分策略文件: +用户首先需要按照[模型保存](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_saving.html)教程执行8卡分布式训练,训练结束后将会在当前路径生成Checkpoint文件目录以及切分策略文件: ```text src_checkpoints/ diff --git a/tutorials/experts/source_zh_cn/parallel/model_save_load.rst b/docs/mindspore/source_zh_cn/model_train/parallel/model_save_load.rst similarity index 55% rename from tutorials/experts/source_zh_cn/parallel/model_save_load.rst rename to docs/mindspore/source_zh_cn/model_train/parallel/model_save_load.rst index 382ffb0094ef2e89f3d8c62255206322e016d6e8..4011999da26dd9000a2ad5b2eb77a1d70692e3a3 100644 --- a/tutorials/experts/source_zh_cn/parallel/model_save_load.rst +++ b/docs/mindspore/source_zh_cn/model_train/parallel/model_save_load.rst @@ -2,7 +2,7 @@ ======================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/model_save_load.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/model_save_load.rst :alt: 查看源文件 .. toctree:: @@ -15,6 +15,6 @@ MindSpore中模型保存可以分为合并保存和非合并保存,模型的加载也可以分为完整加载和切片加载。若加载后的分布式切分策略或集群卡数改变,则需要对保存的checkpoint文件进行模型转换。详细请参考: -- `模型保存 `_ -- `模型加载 `_ -- `模型转换 `_ +- `模型保存 `_ +- `模型加载 `_ +- `模型转换 `_ diff --git a/tutorials/experts/source_zh_cn/parallel/model_saving.md b/docs/mindspore/source_zh_cn/model_train/parallel/model_saving.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/model_saving.md rename to docs/mindspore/source_zh_cn/model_train/parallel/model_saving.md index a4459a3c7d9748371412b75778bf48a798d27494..a657802b81002093e4050d4b89b0c7417bbd6c5c 100644 --- a/tutorials/experts/source_zh_cn/parallel/model_saving.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/model_saving.md @@ -1,6 +1,6 @@ # 模型保存 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/model_saving.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/model_saving.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/model_transformation.md b/docs/mindspore/source_zh_cn/model_train/parallel/model_transformation.md similarity index 91% rename from tutorials/experts/source_zh_cn/parallel/model_transformation.md rename to docs/mindspore/source_zh_cn/model_train/parallel/model_transformation.md index 4f205f9023f9802f2ca97e23716cf5e6d9a5724a..fae35fc4699a3d984b29f3d119eabe7171a05c4b 100644 --- a/tutorials/experts/source_zh_cn/parallel/model_transformation.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/model_transformation.md @@ -1,6 +1,6 @@ # 模型转换 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/model_transformation.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/model_transformation.md) ## 概述 @@ -85,7 +85,7 @@ ### 分布式模型保存 -首先,按照[模型保存](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_saving.html)教程执行8卡分布式训练,并行模式为`SEMI_AUTO_PARALLEL`或者`AUTO_PARALLEL`,同时通过调用`set_auto_parallel_context`接口自定义`strategy_ckpt_config`参数配置模型切分策略文件存储路径,训练一段时间后,调用存储Checkpoint的`train.ModelCheckpoint`函数,将分布式的Checkpoint存储下来。 +首先,按照[模型保存](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_saving.html)教程执行8卡分布式训练,并行模式为`SEMI_AUTO_PARALLEL`或者`AUTO_PARALLEL`,同时通过调用`set_auto_parallel_context`接口自定义`strategy_ckpt_config`参数配置模型切分策略文件存储路径,训练一段时间后,调用存储Checkpoint的`train.ModelCheckpoint`函数,将分布式的Checkpoint存储下来。 训练结束后,将会在当前路径生成源Checkpoint文件目录以及源切分策略文件: @@ -410,8 +410,8 @@ epoch: 1, step: 100, loss is 0.07113413 ### 流水线并行模型转换 -[流水线并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/pipeline_parallel.html) 是对线性的网络进行切分,得到多个子网络,子网络之间在多卡间进行流水,因此每个子图存储下来的切分策略文件是不一致的,所有切分策略汇聚在一起才能得到完整的网络的切分信息。 -因此针对流水线并行的维度,相比于其它维度的转换,需要事先执行一次汇聚切分策略文件的操作,得到汇聚后的切分策略文件,以这一份文件作为分布式Checkpoint转换依赖的策略文件。此外,与前面的[执行分布式Checkpoint转换](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_transformation.html#执行分布式checkpoint转换)没有差异。 +[流水线并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/pipeline_parallel.html) 是对线性的网络进行切分,得到多个子网络,子网络之间在多卡间进行流水,因此每个子图存储下来的切分策略文件是不一致的,所有切分策略汇聚在一起才能得到完整的网络的切分信息。 +因此针对流水线并行的维度,相比于其它维度的转换,需要事先执行一次汇聚切分策略文件的操作,得到汇聚后的切分策略文件,以这一份文件作为分布式Checkpoint转换依赖的策略文件。此外,与前面的[执行分布式Checkpoint转换](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_transformation.html#执行分布式checkpoint转换)没有差异。 相关接口: @@ -419,7 +419,7 @@ epoch: 1, step: 100, loss is 0.07113413 首先,执行8卡的流水线并行训练,其中pipeline并行维度为2,且开启优化器并行。 -训练代码在[pipeline_train.py](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/model_saving_loading/pipeline_train.py)中,网络结构在[模型保存](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_saving.html)这一章的基础上增加了流水线并行的配置,并行维度为2。 +训练代码在[pipeline_train.py](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/model_saving_loading/pipeline_train.py)中,网络结构在[模型保存](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_saving.html)这一章的基础上增加了流水线并行的配置,并行维度为2。 核心代码为: @@ -475,11 +475,11 @@ bash run_pipeline_train.sh ... ``` -参考[对目标网络执行编译](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_transformation.html#%E5%AF%B9%E7%9B%AE%E6%A0%87%E7%BD%91%E7%BB%9C%E6%89%A7%E8%A1%8C%E7%BC%96%E8%AF%91)章节,同样编译目标网络以得到目标网络的切分策略文件。 +参考[对目标网络执行编译](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_transformation.html#%E5%AF%B9%E7%9B%AE%E6%A0%87%E7%BD%91%E7%BB%9C%E6%89%A7%E8%A1%8C%E7%BC%96%E8%AF%91)章节,同样编译目标网络以得到目标网络的切分策略文件。 下一步展开包含pipeline并行维度的分布式Checkpoint维度转换,首先使用接口`merge_pipeline_strategys`对pipline训练得到的切分策略文件进行合并,而后使用接口`transform_checkpoints`或者`transform_checkpoint_by_rank`进行分布式Checkpoint转换。 -示例给出使用`transform_checkpoints`的接口,使用`transform_checkpoint_by_rank`接口请参考[执行分布式Checkpoint转换](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_transformation.html#执行分布式checkpoint转换) 章节的介绍。 +示例给出使用`transform_checkpoints`的接口,使用`transform_checkpoint_by_rank`接口请参考[执行分布式Checkpoint转换](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_transformation.html#执行分布式checkpoint转换) 章节的介绍。 ```python import mindspore as ms @@ -496,7 +496,7 @@ ms.transform_checkpoints(args_opt.src_checkpoints_dir, args_opt.dst_checkpoints_ bash run_retrain_pipeline_convert.sh ``` -转换完成后,参照[加载转换得到的Checkpoint文件](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_transformation.html#%E5%8A%A0%E8%BD%BD%E8%BD%AC%E6%8D%A2%E5%BE%97%E5%88%B0%E7%9A%84checkpoint%E6%96%87%E4%BB%B6)章节,执行没有pipeline维度的分布式网络。 +转换完成后,参照[加载转换得到的Checkpoint文件](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_transformation.html#%E5%8A%A0%E8%BD%BD%E8%BD%AC%E6%8D%A2%E5%BE%97%E5%88%B0%E7%9A%84checkpoint%E6%96%87%E4%BB%B6)章节,执行没有pipeline维度的分布式网络。 示例中,加载转换后的Checkpoint进行二阶段微调训练的脚本执行命令为: @@ -542,7 +542,7 @@ epoch: 1, step: 120, loss is 0.10741685 ... ``` -参考[对目标网络执行编译](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_transformation.html#%E5%AF%B9%E7%9B%AE%E6%A0%87%E7%BD%91%E7%BB%9C%E6%89%A7%E8%A1%8C%E7%BC%96%E8%AF%91)章节,同样编译目标网络以得到目标网络的切分策略文件。 +参考[对目标网络执行编译](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_transformation.html#%E5%AF%B9%E7%9B%AE%E6%A0%87%E7%BD%91%E7%BB%9C%E6%89%A7%E8%A1%8C%E7%BC%96%E8%AF%91)章节,同样编译目标网络以得到目标网络的切分策略文件。 网络训练并行策略中流水线并行维度为2,网络将被切分为两个子网络进行训练,分别取两个子网络的策略文件`src_strategy_0.ckpt`和`src_strategy_4.ckpt`使用`transform_checkpoints`接口进行单个子网络的权重转换。 diff --git a/tutorials/experts/source_zh_cn/parallel/mpirun.md b/docs/mindspore/source_zh_cn/model_train/parallel/mpirun.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/mpirun.md rename to docs/mindspore/source_zh_cn/model_train/parallel/mpirun.md index cbed97f47aa98e372c25a3902681b95564e00d74..0996175dbc131da970fc33e59a04d7e959be1e08 100644 --- a/tutorials/experts/source_zh_cn/parallel/mpirun.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/mpirun.md @@ -1,6 +1,6 @@ # mpirun启动 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/mpirun.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/mpirun.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/ms_operator.md b/docs/mindspore/source_zh_cn/model_train/parallel/ms_operator.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/ms_operator.md rename to docs/mindspore/source_zh_cn/model_train/parallel/ms_operator.md index a00a01007809a6fbfe42573859598f410dbe63bb..ed864110052c41f7337987044d6696e2b46aca4d 100644 --- a/tutorials/experts/source_zh_cn/parallel/ms_operator.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/ms_operator.md @@ -1,6 +1,6 @@ # 在K8S集群上进行分布式训练 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/ms_operator.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/ms_operator.md) MindSpore Operator 是遵循Kubernetes的Operator模式(基于CRD-Custom Resource Definition功能),实现的在Kubernetes上进行分布式训练的插件。其中,MindSpore Operator在CRD中定义了Scheduler、PS、Worker三种角色,用户只需通过简单的YAML文件配置,就可以轻松地在K8S上使用MindSpore进行分布式训练。MindSpore Operator的代码仓详见:[ms-operator](https://gitee.com/mindspore/ms-operator/)。 diff --git a/tutorials/experts/source_zh_cn/parallel/msrun_launcher.md b/docs/mindspore/source_zh_cn/model_train/parallel/msrun_launcher.md similarity index 96% rename from tutorials/experts/source_zh_cn/parallel/msrun_launcher.md rename to docs/mindspore/source_zh_cn/model_train/parallel/msrun_launcher.md index 775eeb3004b38d06af92807d6a6f4897a1ad5b47..c38ecd794f1eac99f586cd6f0e89af3500a18baf 100644 --- a/tutorials/experts/source_zh_cn/parallel/msrun_launcher.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/msrun_launcher.md @@ -1,10 +1,10 @@ # msrun启动 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/msrun_launcher.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/msrun_launcher.md) ## 概述 -`msrun`是[动态组网](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)启动方式的封装,用户可使用`msrun`以单个命令行指令的方式在各节点拉起多进程分布式任务,并且无需手动设置[动态组网环境变量](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)。`msrun`同时支持`Ascend`,`GPU`和`CPU`后端。与`动态组网`启动方式一样,`msrun`无需依赖第三方库以及配置文件。 +`msrun`是[动态组网](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)启动方式的封装,用户可使用`msrun`以单个命令行指令的方式在各节点拉起多进程分布式任务,并且无需手动设置[动态组网环境变量](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)。`msrun`同时支持`Ascend`,`GPU`和`CPU`后端。与`动态组网`启动方式一样,`msrun`无需依赖第三方库以及配置文件。 > - `msrun`在用户安装MindSpore后即可使用,可使用指令`msrun --help`查看支持参数。 > - `msrun`支持`图模式`以及`PyNative模式`。 diff --git a/tutorials/experts/source_zh_cn/parallel/multiple_copy.md b/docs/mindspore/source_zh_cn/model_train/parallel/multiple_copy.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/multiple_copy.md rename to docs/mindspore/source_zh_cn/model_train/parallel/multiple_copy.md index 05b35937d49a299f5d55bcf5626de28c09c26947..59f2112e6e174e931b7be031999bb9d7f2006b6a 100644 --- a/tutorials/experts/source_zh_cn/parallel/multiple_copy.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/multiple_copy.md @@ -1,6 +1,6 @@ # 多副本并行 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/multiple_copy.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/multiple_copy.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/multiple_mix.md b/docs/mindspore/source_zh_cn/model_train/parallel/multiple_mix.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/multiple_mix.md rename to docs/mindspore/source_zh_cn/model_train/parallel/multiple_mix.md index 3fc68e2710668c3e5ae0a7975c700c20292ad6f0..99c60cb11677387595553e74df653d088c38cb89 100644 --- a/tutorials/experts/source_zh_cn/parallel/multiple_mix.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/multiple_mix.md @@ -1,6 +1,6 @@ # 基于双递归搜索的多维混合并行案例 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/multiple_mix.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/multiple_mix.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/operator_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/operator_parallel.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/operator_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/operator_parallel.md index be2beab2f14e2a583be7fbdc831329a109d4e49d..878094040fa7c23d236e08b3ce2787d969cbc367 100644 --- a/tutorials/experts/source_zh_cn/parallel/operator_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/operator_parallel.md @@ -1,6 +1,6 @@ # 算子级并行 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/operator_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/operator_parallel.md) ## 概述 @@ -241,4 +241,4 @@ epoch: 0, step: 100, loss is 0.71934 ... ``` -其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 diff --git a/docs/mindspore/source_zh_cn/model_train/parallel/optimize_technique.rst b/docs/mindspore/source_zh_cn/model_train/parallel/optimize_technique.rst new file mode 100644 index 0000000000000000000000000000000000000000..b6cf292c8fd388a0c3d61f4a50e2b22e0ba2f35e --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/parallel/optimize_technique.rst @@ -0,0 +1,42 @@ +优化方法 +======================== + +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/model_train/parallel/optimize_technique.rst + :alt: 查看源文件 + +.. toctree:: + :maxdepth: 1 + :hidden: + + strategy_select + split_technique + multiple_copy + distributed_gradient_accumulation + recompute + dataset_slice + host_device_training + memory_offload + comm_fusion + comm_subgraph + +考虑到实际并行训练中,可能会对训练性能、吞吐量或规模有要求,可以从三个方面考虑优化:并行策略优化、内存优化和通信优化 + +- 并行策略优化:并行策略优化主要包括并行策略的选择、算子级并行下的切分技巧以及多副本技巧。 + + - `策略选择 `_:根据模型规模和数据量大小,可以选择不同的并行策略,以提高训练效率和资源利用率。 + - `切分技巧 `_:切分技巧是指通过手动配置某些关键算子的切分策略,减少张量重排布来提升训练效率。 + - `多副本 `_:多副本是指在一个迭代步骤中,将一个训练batch拆分成多个,将模型并行通信与计算进行并发,提升资源利用率。 + +- 内存优化:内存优化包括梯度累加、重计算、数据集切分、Host&Device异构和异构存储,主要目标是节省内存空间。 + + - `梯度累加 `_:梯度累加通过在多个MicroBatch上计算梯度并将它们累加起来,然后一次性应用这个累加梯度来更新神经网络的参数。通过这种方法少量设备也能训练大Batch,有效减低内存峰值。 + - `重计算 `_:重计算是一种以时间换空间的技术,通过不保存某些正向算子的计算结果,以节省内存空间,在计算反向算子时,需要用到正向结果再重新计算正向算子。 + - `数据集切分 `_:数据集单个数据过大甚至无法加载到单个设备的时候,可以对数据进行切分,进行分布式训练。数据集切分配合模型并行是有效降低显存占用的方式。 + - `Host&Device异构 `_:在遇到参数量超过Device内存上限的时候,可以把一些内存占用量大且计算量少的算子放在Host端,这样能同时利用Host端内存大,Device端计算快的特性,提升了设备的利用率。 + - `异构存储 `_:异构存储可以将暂时不需要用到的参数或中间结果拷贝到Host端内存或者硬盘,在需要时再恢复至Device端,从而减少显存占用。 + +- 通信优化:通信优化包括通信融合和通信子图提取与复用,主要目标是减少通信延时,提升性能。 + + - `通信融合 `_:通信融合可以将相同源节点和目标节点的通信算子合并到一次通信过程,避免多次通信带来额外开销。 + - `通信子图提取与复用 `_:通过对通信算子提取通信子图,替换原本的通信算子,可以减少通信耗时,同时减少模型编译时间。 diff --git a/tutorials/experts/source_zh_cn/parallel/optimizer_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/optimizer_parallel.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/optimizer_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/optimizer_parallel.md index 16bf0056c1e20063ca111740f2ee542669efa788..17b05c24ad9cddb8f4272d294797e83ecb7d0444 100644 --- a/tutorials/experts/source_zh_cn/parallel/optimizer_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/optimizer_parallel.md @@ -1,6 +1,6 @@ # 优化器并行 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/optimizer_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/optimizer_parallel.md) ## 概述 @@ -137,7 +137,7 @@ net.layer2.set_comm_fusion(1) net.layer3.set_comm_fusion(2) ``` -> 这里为了减少通信成本,为不同层配置了通信融合,详细可以参考[通信算子融合](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/comm_fusion.html)。 +> 这里为了减少通信成本,为不同层配置了通信融合,详细可以参考[通信算子融合](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/comm_fusion.html)。 ### 训练网络 @@ -209,7 +209,7 @@ epoch: 0, step: 100, loss is 0.6854114 ... ``` -其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 ## 高级接口 diff --git a/tutorials/experts/source_zh_cn/parallel/others.rst b/docs/mindspore/source_zh_cn/model_train/parallel/others.rst similarity index 72% rename from tutorials/experts/source_zh_cn/parallel/others.rst rename to docs/mindspore/source_zh_cn/model_train/parallel/others.rst index ddf61f7e894007400a548efc63d4f192e4bbca2c..69a20be91fe3ecba26457f3a6898b3bc117e322e 100644 --- a/tutorials/experts/source_zh_cn/parallel/others.rst +++ b/docs/mindspore/source_zh_cn/model_train/parallel/others.rst @@ -2,7 +2,7 @@ ======================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/others.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/others.rst :alt: 查看源文件 .. toctree:: diff --git a/tutorials/experts/source_zh_cn/parallel/overview.md b/docs/mindspore/source_zh_cn/model_train/parallel/overview.md similarity index 71% rename from tutorials/experts/source_zh_cn/parallel/overview.md rename to docs/mindspore/source_zh_cn/model_train/parallel/overview.md index 181599eca919827d225618e3f8cc102f58c298f0..01d539da17abbc4e30aace49b0cd240b2e2aa7cd 100644 --- a/tutorials/experts/source_zh_cn/parallel/overview.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/overview.md @@ -1,6 +1,6 @@ # 分布式并行总览 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/overview.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/overview.md) 在深度学习中,当数据集和参数量的规模越来越大,训练所需的时间和硬件资源会随之增加,最后会变成制约训练的瓶颈。分布式并行训练,可以降低对内存、计算性能等硬件的需求,是进行训练的重要优化手段。此外,分布式并行对大模型训练和推理有着重要的意义,它为处理大规模数据和复杂模型提供了强大的计算能力和性能优势。 @@ -15,51 +15,51 @@ MindSpore目前支持四种启动方式: - **mpirun**:通过多进程通信库OpenMPI启动,支持Ascend/GPU。 - **rank table**:配置rank_table表后,通过脚本启动和卡数对应的进程,支持Ascend。 -详细可参考[分布式并行启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)章节。 +详细可参考[分布式并行启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)章节。 ## 并行模式 目前MindSpore可以采取下述的几种并行模式,您可以按需求选择: -- **数据并行模式**:数据并行模式下,数据集可以在样本维度拆分并下发到不同的卡上。如果您的数据集较大,而模型参数规模能在单卡运算,您可以选择这种并行模型。参考[数据并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/data_parallel.html)教程了解更多信息。 -- **自动并行模式**:融合了数据并行、算子级模型并行的分布式并行模式,可以自动建立代价模型,找到训练时间较短的并行策略,为用户选择合适的并行模式。如果您的数据集和模型参数规模都较大,且希望自动配置并行策略,您可以选择这种并行模型。参考[自动并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/auto_parallel.html)教程了解更多信息。 -- **半自动并行模式**:相较于自动并行,该模式需要用户对算子手动配置切分策略实现并行。如果您数据集和模型参数规模都较大,且您对模型的结构比较熟悉,知道哪些“关键算子”容易成为计算瓶颈,为“关键算子”配置合适的切分策略可以获得更好的性能,您可以选择这种并行模式。此外该模式还可以手动配置优化器并行和流水线并行。参考[半自动并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/semi_auto_parallel.html)教程了解更多信息。 -- **手动并行模式**:在手动并行模式下,您可以基于通信原语例如`AllReduce`、`AllGather`、`Broadcast`等通信算子进行数据传输,手动实现分布式系统下模型的并行通信。您可以参考[手动并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/manual_parallel.html)教程了解更多信息。 -- **参数服务器模式**:相比于同步的训练方法,参数服务器具有更好的灵活性、可拓展性。您可以参考[参数服务器](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/parameter_server_training.html)模式教程了解更多信息。 +- **数据并行模式**:数据并行模式下,数据集可以在样本维度拆分并下发到不同的卡上。如果您的数据集较大,而模型参数规模能在单卡运算,您可以选择这种并行模型。参考[数据并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/data_parallel.html)教程了解更多信息。 +- **自动并行模式**:融合了数据并行、算子级模型并行的分布式并行模式,可以自动建立代价模型,找到训练时间较短的并行策略,为用户选择合适的并行模式。如果您的数据集和模型参数规模都较大,且希望自动配置并行策略,您可以选择这种并行模型。参考[自动并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/auto_parallel.html)教程了解更多信息。 +- **半自动并行模式**:相较于自动并行,该模式需要用户对算子手动配置切分策略实现并行。如果您数据集和模型参数规模都较大,且您对模型的结构比较熟悉,知道哪些“关键算子”容易成为计算瓶颈,为“关键算子”配置合适的切分策略可以获得更好的性能,您可以选择这种并行模式。此外该模式还可以手动配置优化器并行和流水线并行。参考[半自动并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/semi_auto_parallel.html)教程了解更多信息。 +- **手动并行模式**:在手动并行模式下,您可以基于通信原语例如`AllReduce`、`AllGather`、`Broadcast`等通信算子进行数据传输,手动实现分布式系统下模型的并行通信。您可以参考[手动并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/manual_parallel.html)教程了解更多信息。 +- **参数服务器模式**:相比于同步的训练方法,参数服务器具有更好的灵活性、可拓展性。您可以参考[参数服务器](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/parameter_server_training.html)模式教程了解更多信息。 ## 保存和加载模型 -模型的保存可以分为合并保存和非合并保存,可以通过`mindspore.save_checkpoint`或者`mindspore.train.CheckpointConfig`中的`integrated_save`参数选择是否合并保存。合并保存模式下模型参数会自动聚合保存到模型文件中,而非合并保存模式下每张卡保存各自卡上的参数切片。关于各并行模式下的模型保存可以参考[模型保存](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_saving.html)教程。 +模型的保存可以分为合并保存和非合并保存,可以通过`mindspore.save_checkpoint`或者`mindspore.train.CheckpointConfig`中的`integrated_save`参数选择是否合并保存。合并保存模式下模型参数会自动聚合保存到模型文件中,而非合并保存模式下每张卡保存各自卡上的参数切片。关于各并行模式下的模型保存可以参考[模型保存](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_saving.html)教程。 -模型的加载可以分为完整加载和切片加载。若保存的是完整参数的模型文件,则可以直接通过`load_checkpoint`接口加载模型文件。若保存的是多卡下的参数切片文件,则需要考虑加载后的分布式切分策略或集群规模是否有变化。如果分布式切分策略或集群规模不变,则可以通过`load_distributed_checkpoint`接口加载各卡对应的参数切片文件,可以参考[模型加载](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html)教程。 +模型的加载可以分为完整加载和切片加载。若保存的是完整参数的模型文件,则可以直接通过`load_checkpoint`接口加载模型文件。若保存的是多卡下的参数切片文件,则需要考虑加载后的分布式切分策略或集群规模是否有变化。如果分布式切分策略或集群规模不变,则可以通过`load_distributed_checkpoint`接口加载各卡对应的参数切片文件,可以参考[模型加载](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html)教程。 -若保存和加载的分布式切分策略或集群卡数改变的情况下,则需要对分布式下的Checkpoint文件进行转换以适配新的分布式切分策略或集群卡数。您可以参考[模型转换](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_transformation.html)了解更多信息。 +若保存和加载的分布式切分策略或集群卡数改变的情况下,则需要对分布式下的Checkpoint文件进行转换以适配新的分布式切分策略或集群卡数。您可以参考[模型转换](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_transformation.html)了解更多信息。 ## 故障恢复 在分布式并行训练过程中,可能会遇到计算节点的故障或通信中断等问题。MindSpore提供了三种恢复方式以保证训练的稳定性和连续性: -- **根据完整Checkpoint恢复**:在保存Checkpoint文件前,通过AllGather算子汇聚模型的完整参数,每张卡均保存了完整的模型参数文件,可以直接加载恢复。多个checkpoints副本提高了模型的容错性,但是对于大模型来说,汇聚的过程会导致各种资源开销过大。详细可参考[模型加载](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/model_loading.html)教程。 -- **动态组网场景下故障恢复**:在动态组网中,若某个进程出现故障,其他进程会进入等待状态,可以通过重新拉起故障进程使得训练任务继续进行(目前仅支持GPU硬件平台)。和其他方式相比,该故障恢复方式无需重启集群。详细可参考[动态组网场景下故障恢复](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/disaster_recover.html)教程。 -- **根据参数切分的冗余信息恢复**:在大模型训练中,根据数据并行的维度所划分的设备,他们的模型参数是相同的。根据这个原理,可以利用这些冗余的参数信息作为备份,在一个节点故障时,利用相同参数的另一节点就可以恢复故障的节点。详细可参考[基于冗余信息的故障恢复](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/fault_recover.html)教程。 +- **根据完整Checkpoint恢复**:在保存Checkpoint文件前,通过AllGather算子汇聚模型的完整参数,每张卡均保存了完整的模型参数文件,可以直接加载恢复。多个checkpoints副本提高了模型的容错性,但是对于大模型来说,汇聚的过程会导致各种资源开销过大。详细可参考[模型加载](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/model_loading.html)教程。 +- **动态组网场景下故障恢复**:在动态组网中,若某个进程出现故障,其他进程会进入等待状态,可以通过重新拉起故障进程使得训练任务继续进行(目前仅支持GPU硬件平台)。和其他方式相比,该故障恢复方式无需重启集群。详细可参考[动态组网场景下故障恢复](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/disaster_recover.html)教程。 +- **根据参数切分的冗余信息恢复**:在大模型训练中,根据数据并行的维度所划分的设备,他们的模型参数是相同的。根据这个原理,可以利用这些冗余的参数信息作为备份,在一个节点故障时,利用相同参数的另一节点就可以恢复故障的节点。详细可参考[基于冗余信息的故障恢复](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/fault_recover.html)教程。 ## 优化方法 如果对性能、吞吐量或规模有要求,或者不知道如何选择并行策略,可以考虑以下优化技术: - **并行策略优化**: - - **策略选择**:根据您的模型规模和数据量大小,您可以参考[策略选择](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/strategy_select.html)教程来选择不同的并行策略,以提高训练效率和资源利用率。 - - **切分技巧**:切分技巧也是实现高效并行计算的关键,在[切分技巧](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/split_technique.html)教程中,您可以通过具体案例了解到如何应用各种切分技巧来提升效率。 - - **多副本并行**:在现有的单副本模式下,某些底层算子在进行通信的时候,无法同时进行计算,从而导致资源浪费。多副本并行通过对数据按照Batch Size维度进行切分为多个副本,可以使一个副本在通信时,另一副本进行计算操作,提升了资源利用率,详细可参考[多副本并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/multiple_copy.html)教程。 + - **策略选择**:根据您的模型规模和数据量大小,您可以参考[策略选择](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/strategy_select.html)教程来选择不同的并行策略,以提高训练效率和资源利用率。 + - **切分技巧**:切分技巧也是实现高效并行计算的关键,在[切分技巧](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/split_technique.html)教程中,您可以通过具体案例了解到如何应用各种切分技巧来提升效率。 + - **多副本并行**:在现有的单副本模式下,某些底层算子在进行通信的时候,无法同时进行计算,从而导致资源浪费。多副本并行通过对数据按照Batch Size维度进行切分为多个副本,可以使一个副本在通信时,另一副本进行计算操作,提升了资源利用率,详细可参考[多副本并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/multiple_copy.html)教程。 - **内存优化**: - - **梯度累加**:梯度累加通过在多个MicroBatch上计算梯度并将它们累加起来,然后一次性应用这个累加梯度来更新神经网络的参数。通过这种方法少量设备也能训练大Batch Size,有效减低内存峰值,详细可参考[梯度累加](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/distributed_gradient_accumulation.html)教程。 - - **重计算**:重计算通过不保存某些正向算子的计算结果,以节省内存空间,在计算反向算子时,需要用到正向结果再重新计算正向算子。详细可参考[重计算](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/recompute.html)教程。 - - **数据集切分**:数据集单个数据过大的时候,可以对数据进行切分,进行分布式训练。数据集切分配合模型并行是有效降低显存占用的方式。详细可参考[数据集切分](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dataset_slice.html)教程。 - - **Host&Device异构**:在遇到参数量超过Device内存上限的时候,可以把一些内存占用量大且计算量少的算子放在Host端,这样能同时利用Host端内存大,Device端计算快的特性,提升了设备的利用率。详细可参考[Host&Device异构](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/host_device_training.html)教程。 - - **异构存储**:大模型目前受限显存大小,难以在单卡上训练。大规模分布式集群训练中,在通信代价越来越大的情况下,提升单机的显存,减少通信,也能提升训练性能。异构存储可以将暂时不需要用到的参数或中间结果拷贝到Host端内存或者硬盘,在需要时再恢复至Device端。详细可参考[异构存储](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/memory_offload.html)教程。 + - **梯度累加**:梯度累加通过在多个MicroBatch上计算梯度并将它们累加起来,然后一次性应用这个累加梯度来更新神经网络的参数。通过这种方法少量设备也能训练大Batch Size,有效减低内存峰值,详细可参考[梯度累加](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/distributed_gradient_accumulation.html)教程。 + - **重计算**:重计算通过不保存某些正向算子的计算结果,以节省内存空间,在计算反向算子时,需要用到正向结果再重新计算正向算子。详细可参考[重计算](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/recompute.html)教程。 + - **数据集切分**:数据集单个数据过大的时候,可以对数据进行切分,进行分布式训练。数据集切分配合模型并行是有效降低显存占用的方式。详细可参考[数据集切分](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dataset_slice.html)教程。 + - **Host&Device异构**:在遇到参数量超过Device内存上限的时候,可以把一些内存占用量大且计算量少的算子放在Host端,这样能同时利用Host端内存大,Device端计算快的特性,提升了设备的利用率。详细可参考[Host&Device异构](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/host_device_training.html)教程。 + - **异构存储**:大模型目前受限显存大小,难以在单卡上训练。大规模分布式集群训练中,在通信代价越来越大的情况下,提升单机的显存,减少通信,也能提升训练性能。异构存储可以将暂时不需要用到的参数或中间结果拷贝到Host端内存或者硬盘,在需要时再恢复至Device端。详细可参考[异构存储](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/memory_offload.html)教程。 - **通信优化**: - - **通信融合**:通信融合可以将相同源节点和目标节点的通信算子合并到一次通信过程,避免多次通信带来额外开销。详细可参考[通信融合](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/comm_fusion.html)。 - - **通信子图提取与复用**:通过对通信算子提取通信子图,替换原本的通信算子,可以减少通信耗时,同时减少模型编译时间。详细可参考[通信子图提取与复用](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/comm_subgraph.html)。 + - **通信融合**:通信融合可以将相同源节点和目标节点的通信算子合并到一次通信过程,避免多次通信带来额外开销。详细可参考[通信融合](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/comm_fusion.html)。 + - **通信子图提取与复用**:通过对通信算子提取通信子图,替换原本的通信算子,可以减少通信耗时,同时减少模型编译时间。详细可参考[通信子图提取与复用](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/comm_subgraph.html)。 ## 不同平台差异 @@ -71,14 +71,14 @@ MindSpore目前支持四种启动方式: - GPU支持msrun、动态组网和mpirun三种启动方式。 - CPU支持msrun和动态组网启动。 -详细过程请参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +详细过程请参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 ### 并行方式的差异 - Ascend和GPU支持所有并行方式,包括数据并行、半自动并行、自动并行等。 - CPU仅支持数据并行。 -详细过程请参考[数据并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/data_parallel.html)、[半自动并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/semi_auto_parallel.html)、[自动并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/auto_parallel.html)。 +详细过程请参考[数据并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/data_parallel.html)、[半自动并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/semi_auto_parallel.html)、[自动并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/auto_parallel.html)。 ### 优化特性支持的差异 @@ -86,5 +86,5 @@ MindSpore目前支持四种启动方式: - GPU支持除了通信子图提取与复用以外的优化特性。 - CPU不支持优化特性。 -详细过程请参考[优化方法](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/optimize_technique.html)。 +详细过程请参考[优化方法](https://www.mindspore.cn/docs/en/master/model_train/parallel/optimize_technique.html)。 diff --git a/tutorials/experts/source_zh_cn/parallel/pangu_alpha.md b/docs/mindspore/source_zh_cn/model_train/parallel/pangu_alpha.md similarity index 99% rename from tutorials/experts/source_zh_cn/parallel/pangu_alpha.md rename to docs/mindspore/source_zh_cn/model_train/parallel/pangu_alpha.md index 3487b1f2e6fd53f697f52cc799cda29ed45ce374..aefe7a9c10fe892642cf406d65880da8b0647acb 100644 --- a/tutorials/experts/source_zh_cn/parallel/pangu_alpha.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/pangu_alpha.md @@ -1,6 +1,6 @@ # 鹏程·盘古模型网络多维度混合并行解析 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/pangu_alpha.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/pangu_alpha.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/parameter_server_training.md b/docs/mindspore/source_zh_cn/model_train/parallel/parameter_server_training.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/parameter_server_training.md rename to docs/mindspore/source_zh_cn/model_train/parallel/parameter_server_training.md index a24dcc604b626c76fbb1c3ff075ffb5eb32e5111..c87d5a63a240a294c1eedd9de8e18e335497eb6c 100644 --- a/tutorials/experts/source_zh_cn/parallel/parameter_server_training.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/parameter_server_training.md @@ -1,6 +1,6 @@ # 参数服务器 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/parameter_server_training.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/parameter_server_training.md) ## 概述 @@ -48,7 +48,7 @@ export MS_SCHED_PORT=XXXX # Scheduler port export MS_ROLE=MS_SCHED # The role of this process: MS_SCHED represents the scheduler, MS_WORKER represents the worker, MS_PSERVER represents the Server ``` -更多详细说明请查看[动态组网环境变量](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/dynamic_cluster.html)。 +更多详细说明请查看[动态组网环境变量](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/dynamic_cluster.html)。 ## 操作实践 diff --git a/tutorials/experts/source_zh_cn/parallel/pipeline_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/pipeline_parallel.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/pipeline_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/pipeline_parallel.md index 1ecf769245a92a7ac6f8b6896d2c5dae258dff78..bd6a86a0b65f7fdfbb9a6d147bac7519915b1ef0 100644 --- a/tutorials/experts/source_zh_cn/parallel/pipeline_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/pipeline_parallel.md @@ -1,6 +1,6 @@ # 流水线并行 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/pipeline_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/pipeline_parallel.md) ## 概述 @@ -273,7 +273,7 @@ Tensor(shape=[8, 512], dtype=Float32, value= [ 4.89746094e-01 3.56689453e-01 -4.90966797e-01 ... -3.30078125e-e01 -2.38525391e-01 7.33398438e-01]]) ``` -其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 ## 推理操作实践 diff --git a/tutorials/experts/source_zh_cn/parallel/rank_table.md b/docs/mindspore/source_zh_cn/model_train/parallel/rank_table.md similarity index 99% rename from tutorials/experts/source_zh_cn/parallel/rank_table.md rename to docs/mindspore/source_zh_cn/model_train/parallel/rank_table.md index 5ab6144d003be47df3c83533d037ae93215c0ac5..13da697c600ae6860071568d04eb9f4986af3e47 100644 --- a/tutorials/experts/source_zh_cn/parallel/rank_table.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/rank_table.md @@ -1,6 +1,6 @@ # rank table启动 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/rank_table.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/rank_table.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/recompute.md b/docs/mindspore/source_zh_cn/model_train/parallel/recompute.md similarity index 99% rename from tutorials/experts/source_zh_cn/parallel/recompute.md rename to docs/mindspore/source_zh_cn/model_train/parallel/recompute.md index 1109118497c2a24e3bb86d6dc236114cca9ad37d..8c6535a5223da557b4a5cbd0acda27db21546dce 100644 --- a/tutorials/experts/source_zh_cn/parallel/recompute.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/recompute.md @@ -1,6 +1,6 @@ # 重计算 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/recompute.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/recompute.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/recover.rst b/docs/mindspore/source_zh_cn/model_train/parallel/recover.rst similarity index 40% rename from tutorials/experts/source_zh_cn/parallel/recover.rst rename to docs/mindspore/source_zh_cn/model_train/parallel/recover.rst index c8ce23ce6e7dc4a7d1909d853f2d2da3c523839e..4c1afb13f6e6b5b0848fe0d09d14c1e9ce12a471 100644 --- a/tutorials/experts/source_zh_cn/parallel/recover.rst +++ b/docs/mindspore/source_zh_cn/model_train/parallel/recover.rst @@ -2,7 +2,7 @@ ======================== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/recover.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/recover.rst :alt: 查看源文件 .. toctree:: @@ -14,6 +14,6 @@ 在分布式并行训练过程中,遇到计算节点的故障或通信中断等问题,MindSpore有三种恢复方式: -- 模型重新加载:在训练时,通过配置参数合并保存,每张卡均保存了完整的模型参数文件,发生故障后可以直接加载之前保存的checkpoint进行恢复。详细请参考模型保存与加载中的 `模型加载 `_ 。 -- `动态组网场景下故障恢复 `_:在动态组网启动场景下,若某个进程出现故障,其他进程会进入等待状态,可以通过重新拉起故障进程使得训练任务继续进行,而无需重启集群(目前仅支持GPU硬件平台)。 -- `基于冗余信息的故障恢复 `_:在大模型训练中,根据数据并行的维度所划分的设备,他们的模型参数是相同的。根据这个原理,可以利用这些冗余的参数信息作为备份,在一个节点故障时,利用相同参数的另一节点就可以恢复故障的节点。 +- 模型重新加载:在训练时,通过配置参数合并保存,每张卡均保存了完整的模型参数文件,发生故障后可以直接加载之前保存的checkpoint进行恢复。详细请参考模型保存与加载中的 `模型加载 `_ 。 +- `动态组网场景下故障恢复 `_:在动态组网启动场景下,若某个进程出现故障,其他进程会进入等待状态,可以通过重新拉起故障进程使得训练任务继续进行,而无需重启集群(目前仅支持GPU硬件平台)。 +- `基于冗余信息的故障恢复 `_:在大模型训练中,根据数据并行的维度所划分的设备,他们的模型参数是相同的。根据这个原理,可以利用这些冗余的参数信息作为备份,在一个节点故障时,利用相同参数的另一节点就可以恢复故障的节点。 diff --git a/tutorials/experts/source_zh_cn/parallel/sapp.md b/docs/mindspore/source_zh_cn/model_train/parallel/sapp.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/sapp.md rename to docs/mindspore/source_zh_cn/model_train/parallel/sapp.md index eb4f3c876ff12f60e5c28ac02841391704178a7f..0d037bcd91a67535c503856a969e470db91a709c 100644 --- a/tutorials/experts/source_zh_cn/parallel/sapp.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/sapp.md @@ -1,6 +1,6 @@ # 双递归策略搜索算法 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/sapp.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/sapp.md) ## 概述 @@ -239,4 +239,4 @@ input_names: [x1, x2], transpose_x2: Bool(1), transpose_x1: Bool(0), transpose_b 对于第一个MatMul算子,其两个输入从原来的(256, 784)、(512, 784)被切分为(64, 392)、(512, 392),第二个输入转置后,算子的输出为(64, 512)。 -其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 diff --git a/docs/mindspore/source_zh_cn/model_train/parallel/semi_auto_parallel.rst b/docs/mindspore/source_zh_cn/model_train/parallel/semi_auto_parallel.rst new file mode 100644 index 0000000000000000000000000000000000000000..8cfc631270286bd8d748fb5ab4c51a2bd784edb8 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/parallel/semi_auto_parallel.rst @@ -0,0 +1,22 @@ +半自动并行 +======================== + +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/semi_auto_parallel.rst + :alt: 查看源文件 + +.. toctree:: + :maxdepth: 1 + :hidden: + + operator_parallel + advanced_operator_parallel + optimizer_parallel + pipeline_parallel + +半自动并行支持多种并行模式的自动混合使用,包括: + +- `算子级并行 `_:算子级并行是指以算子为单位,把输入张量和模型参数切分到多台设备上进行计算,提升整体速度。 +- `高阶算子级并行 `_:高阶算子级并行是指允许自定义设备排布与张量排布的算子级并行,以实现更复杂的切分逻辑。 +- `优化器并行 `_:优化器并行可以减少多台设备对于相同权重更新的冗余计算,将计算量分散到多个设备上。 +- `流水线并行 `_:流水线并行是指将模型按层切分,每个设备只处理模型中某一部分。 diff --git a/tutorials/experts/source_zh_cn/parallel/shard_function_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/shard_function_parallel.md similarity index 98% rename from tutorials/experts/source_zh_cn/parallel/shard_function_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/shard_function_parallel.md index 86bc667529193ac3ad179513f83d7ed3bcc3a583..366c8a8f38b6ed0122d190df3fb1b59ec0c1e2d9 100644 --- a/tutorials/experts/source_zh_cn/parallel/shard_function_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/shard_function_parallel.md @@ -1,6 +1,6 @@ # 函数式算子切分 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/shard_function_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/shard_function_parallel.md) ## 概述 @@ -236,7 +236,7 @@ print('result.shape:', result.shape) > > 即通过该方式启动时,`shard`内部的模型并行产生的通信只能发生在`world group`内部,所以指定的切分策略目前只能支持切一个维度。 -上述代码需要在配置分布式变量后才可以运行。Ascend环境需要配置RANK_TABLE_FILE、RANK_ID和DEVICE_ID。配置的过程请参考[此处](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/rank_table.html)。 +上述代码需要在配置分布式变量后才可以运行。Ascend环境需要配置RANK_TABLE_FILE、RANK_ID和DEVICE_ID。配置的过程请参考[此处](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/rank_table.html)。 Ascend分布式相关的环境变量有: diff --git a/tutorials/experts/source_zh_cn/parallel/sharding_propagation.md b/docs/mindspore/source_zh_cn/model_train/parallel/sharding_propagation.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/sharding_propagation.md rename to docs/mindspore/source_zh_cn/model_train/parallel/sharding_propagation.md index 6f4f6baf6fb60a8499add22c43b5f3e01d69bc8a..d4356ff319b004e29b1934daedaa4322366c292d 100644 --- a/tutorials/experts/source_zh_cn/parallel/sharding_propagation.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/sharding_propagation.md @@ -1,6 +1,6 @@ # 切分策略传播算法 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/sharding_propagation.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/sharding_propagation.md) ## 概述 @@ -277,8 +277,8 @@ epoch: 0, step: 1000, loss is 0.46586612 对于第一个MatMul算子,其输入根据策略((2, 1), (1, 4))切分后,第一、第二个输入的shape分别从原来的(256, 784)、(784, 64)切分为(128, 784)、(784, 16),因此得到输出的shape为(128, 16)。 -其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/startup_method.html)。 +其他启动方式如动态组网、`rank table`的启动可参考[启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/startup_method.html)。 ### 配置算子切分策略的经验性原则 -给定一个新模型,从用户的角度,关键问题是配置哪些算子的切分策略来获得较好的性能。由于策略传播的目标是最小化张量重排布的代价,而非最小化端到端的迭代时间,因此,为“关键算子”配置合适的切分策略是十分重要的。然而,并不存在明确的规定约束哪些算子是必须配置切分策略的。尽管如此,基于我们训练大模型的经验,确实有一些原则可以用来指导新用户配置并行策略。我们总结出3条经验性的原则供参考,详见[切分技巧](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/split_technique.html)。 +给定一个新模型,从用户的角度,关键问题是配置哪些算子的切分策略来获得较好的性能。由于策略传播的目标是最小化张量重排布的代价,而非最小化端到端的迭代时间,因此,为“关键算子”配置合适的切分策略是十分重要的。然而,并不存在明确的规定约束哪些算子是必须配置切分策略的。尽管如此,基于我们训练大模型的经验,确实有一些原则可以用来指导新用户配置并行策略。我们总结出3条经验性的原则供参考,详见[切分技巧](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/split_technique.html)。 diff --git a/tutorials/experts/source_zh_cn/parallel/split_technique.md b/docs/mindspore/source_zh_cn/model_train/parallel/split_technique.md similarity index 96% rename from tutorials/experts/source_zh_cn/parallel/split_technique.md rename to docs/mindspore/source_zh_cn/model_train/parallel/split_technique.md index 21008c8708c5ca862e0c5368de8abcef318705e5..99d3701ae976e125395f7331ca74737034c1bf85 100644 --- a/tutorials/experts/source_zh_cn/parallel/split_technique.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/split_technique.md @@ -1,6 +1,6 @@ # 切分技巧 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/split_technique.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/split_technique.md) ## 概述 diff --git a/tutorials/experts/source_zh_cn/parallel/startup_method.rst b/docs/mindspore/source_zh_cn/model_train/parallel/startup_method.rst similarity index 51% rename from tutorials/experts/source_zh_cn/parallel/startup_method.rst rename to docs/mindspore/source_zh_cn/model_train/parallel/startup_method.rst index 414a102393460dc23ee806ca35116f6fa6dc623b..de40fd42a5f5aa969f564f0ea4e9689aaac11088 100644 --- a/tutorials/experts/source_zh_cn/parallel/startup_method.rst +++ b/docs/mindspore/source_zh_cn/model_train/parallel/startup_method.rst @@ -2,7 +2,7 @@ ============================ .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/startup_method.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/startup_method.rst :alt: 查看源文件 .. toctree:: @@ -19,10 +19,10 @@ 目前GPU、Ascend和CPU分别支持多种启动方式。主要有\ ``msrun``\、动态组网、\ ``mpirun``\和\ ``rank table``\四种方式: -- `msrun `_: `msrun` 是动态组网的封装,允许用户使用单命令行指令在各节点拉起分布式任务,安装MindSpore后即可使用。此方式不依赖第三方库以及配置文件,具有容灾恢复功能,安全性较好,支持三种硬件平台。建议用户优先使用此种启动方式。 -- `动态组网 `_:动态组网需要用户手动拉起多进程以及导出环境变量,是 `msrun` 的具体实现,Parameter Server训练模式建议使用此方式,其余分布式场景建议使用 `msrun` 。 -- `mpirun `_:此方式依赖开源库OpenMPI,启动命令简单,多机需要保证两两之间免密登录,推荐有OpenMPI使用经验的用户使用此种启动方式。 -- `rank table `_:此方式需要在Ascend硬件平台使用,不依赖第三方库。手动配置rank_table文件后,就可以通过脚本启动并行程序,多机脚本一致,方便批量部署。 +- `msrun `_: `msrun` 是动态组网的封装,允许用户使用单命令行指令在各节点拉起分布式任务,安装MindSpore后即可使用。此方式不依赖第三方库以及配置文件,具有容灾恢复功能,安全性较好,支持三种硬件平台。建议用户优先使用此种启动方式。 +- `动态组网 `_:动态组网需要用户手动拉起多进程以及导出环境变量,是 `msrun` 的具体实现,Parameter Server训练模式建议使用此方式,其余分布式场景建议使用 `msrun` 。 +- `mpirun `_:此方式依赖开源库OpenMPI,启动命令简单,多机需要保证两两之间免密登录,推荐有OpenMPI使用经验的用户使用此种启动方式。 +- `rank table `_:此方式需要在Ascend硬件平台使用,不依赖第三方库。手动配置rank_table文件后,就可以通过脚本启动并行程序,多机脚本一致,方便批量部署。 .. warning:: `rank_table` 启动方式将在MindSpore 2.4版本废弃。 diff --git a/tutorials/experts/source_zh_cn/parallel/strategy_select.md b/docs/mindspore/source_zh_cn/model_train/parallel/strategy_select.md similarity index 33% rename from tutorials/experts/source_zh_cn/parallel/strategy_select.md rename to docs/mindspore/source_zh_cn/model_train/parallel/strategy_select.md index 6960cd75349d283ac60ebeb20eddaaeb504574e8..5da23fc5c555ad8a367462669de72e5f79c640bb 100644 --- a/tutorials/experts/source_zh_cn/parallel/strategy_select.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/strategy_select.md @@ -1,18 +1,18 @@ # 策略选择 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/strategy_select.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/strategy_select.md) ## 概述 在分布式模型训练中,针对不同的模型规模和数据量大小,可以选择不同的并行策略来提高训练效率和资源利用率。以下是不同并行策略的解释和适用情况: -1. [数据并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/data_parallel.html):数据并行是指在训练过程中,将不同的训练样本分布到不同的设备(如Ascend或GPU)上,每个设备计算其分配的样本的梯度。然后通过梯度的平均或累加来更新模型的参数。数据并行适用于数据量较大,而模型参数量较少,可以在单个设备上加载的情况。数据并行能够充分利用多个设备的计算能力,加速训练过程。 +1. [数据并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/data_parallel.html):数据并行是指在训练过程中,将不同的训练样本分布到不同的设备(如Ascend或GPU)上,每个设备计算其分配的样本的梯度。然后通过梯度的平均或累加来更新模型的参数。数据并行适用于数据量较大,而模型参数量较少,可以在单个设备上加载的情况。数据并行能够充分利用多个设备的计算能力,加速训练过程。 -2. [算子级并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/operator_parallel.html):算子级并行是指以算子为单位,把输入张量和模型参数切分到多台设备上进行计算,每个设备负责计算模型的一部分,提升整体速度。算子级并行又分为需要手动配置切分策略的[半自动并行模式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/semi_auto_parallel.html)以及只需配置少部分甚至无需配置切分策略的[自动并行模式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/auto_parallel.html)。算子级并行适用于模型架构较大,无法完全载入单个设备内存的情况。 +2. [算子级并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/operator_parallel.html):算子级并行是指以算子为单位,把输入张量和模型参数切分到多台设备上进行计算,每个设备负责计算模型的一部分,提升整体速度。算子级并行又分为需要手动配置切分策略的[半自动并行模式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/semi_auto_parallel.html)以及只需配置少部分甚至无需配置切分策略的[自动并行模式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/auto_parallel.html)。算子级并行适用于模型架构较大,无法完全载入单个设备内存的情况。 -3. [优化器并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/optimizer_parallel.html):优化器并行通过将优化器的计算量分散到数据并行维度的卡上,在大规模网络上(比如Bert、GPT)可以有效减少内存消耗并提升网络性能,推荐并行训练时开启。 +3. [优化器并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/optimizer_parallel.html):优化器并行通过将优化器的计算量分散到数据并行维度的卡上,在大规模网络上(比如Bert、GPT)可以有效减少内存消耗并提升网络性能,推荐并行训练时开启。 -4. [流水线并行](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/pipeline_parallel.html):流水线并行将整个训练过程分成多个阶段,每个阶段的计算在不同的设备上进行。数据在不同阶段之间流动,类似于流水线。这种策略适用于网络模型较大,单卡无法载入,且网络可以较为平均地分为多个阶段的计算,并且每个阶段的计算时间较长,从而可以最大限度地重叠计算和通信。 +4. [流水线并行](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/pipeline_parallel.html):流水线并行将整个训练过程分成多个阶段,每个阶段的计算在不同的设备上进行。数据在不同阶段之间流动,类似于流水线。这种策略适用于网络模型较大,单卡无法载入,且网络可以较为平均地分为多个阶段的计算,并且每个阶段的计算时间较长,从而可以最大限度地重叠计算和通信。 选择适当的并行策略取决于具体的训练任务和资源配置。通常情况下,可以根据以下指导原则进行选择: diff --git a/tutorials/experts/source_zh_cn/parallel/support_dynamic_shape_in_parallel.md b/docs/mindspore/source_zh_cn/model_train/parallel/support_dynamic_shape_in_parallel.md similarity index 97% rename from tutorials/experts/source_zh_cn/parallel/support_dynamic_shape_in_parallel.md rename to docs/mindspore/source_zh_cn/model_train/parallel/support_dynamic_shape_in_parallel.md index 1f520cf0541c54b87c67db0546173449b2481647..7f72722749146002256f5fab8cde8b04e5ca671b 100644 --- a/tutorials/experts/source_zh_cn/parallel/support_dynamic_shape_in_parallel.md +++ b/docs/mindspore/source_zh_cn/model_train/parallel/support_dynamic_shape_in_parallel.md @@ -1,6 +1,6 @@ # 分布式并行支持动态Shape -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/parallel/support_dynamic_shape_in_parallel.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/parallel/support_dynamic_shape_in_parallel.md) ## 概述 diff --git a/docs/mindspore/source_zh_cn/model_train/program_form/images/dynamic.png b/docs/mindspore/source_zh_cn/model_train/program_form/images/dynamic.png new file mode 100644 index 0000000000000000000000000000000000000000..219dae25c919ec3bb2a49df919177cb462bc9b94 Binary files /dev/null and b/docs/mindspore/source_zh_cn/model_train/program_form/images/dynamic.png differ diff --git a/docs/mindspore/source_zh_cn/note/index_support.ipynb b/docs/mindspore/source_zh_cn/model_train/program_form/index_support.ipynb similarity index 98% rename from docs/mindspore/source_zh_cn/note/index_support.ipynb rename to docs/mindspore/source_zh_cn/model_train/program_form/index_support.ipynb index f08cd73866a70d7113b303671c46381063f401cf..7a042cf3ec359870a0e2ca262c8901432d4e76ef 100644 --- a/docs/mindspore/source_zh_cn/note/index_support.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/program_form/index_support.ipynb @@ -7,7 +7,7 @@ "source": [ "# Tensor索引支持\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/mindspore_index_support.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/mindspore_index_support.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/index_support.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/mindspore_index_support.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/mindspore_index_support.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/index_support.ipynb)\n", "\n", "Tensor 支持单层与多层索引取值,赋值以及增强赋值,支持动态图(PyNative)以及静态图(Graph)模式。\n", "\n", diff --git a/docs/mindspore/source_zh_cn/model_train/program_form/interface.md b/docs/mindspore/source_zh_cn/model_train/program_form/interface.md new file mode 100644 index 0000000000000000000000000000000000000000..0bbfe47758d662d0a926f2498fec526a87ddbb11 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/program_form/interface.md @@ -0,0 +1,3 @@ +# 接口形态 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/interface.md) diff --git a/docs/mindspore/source_zh_cn/model_train/program_form/jit.ipynb b/docs/mindspore/source_zh_cn/model_train/program_form/jit.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..408710425f82c0f07f8f1019d9c08dad36185777 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/program_form/jit.ipynb @@ -0,0 +1,261 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# 动静转换\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/mindspore_jit.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/mindspore_jit.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/jit.ipynb)\n", + "\n", + "## 概述\n", + "\n", + "当前在业界支持动态图和静态图两种模式,动态图通过解释执行,具有动态语法亲和性,表达灵活;静态图使用jit编译优化执行,偏静态语法,在语法上有较多限制。动态图和静态图的编译流程不一致,语法约束不一致。MindSpore针对动态图和静态图模式,首先统一API表达,在两种模式下使用相同的API;其次统一动态图和静态图的底层微分机制。\n", + "\n", + "![dynamic](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/program_form/images/dynamic.png)\n", + "\n", + "## 动态图和静态图互相转换\n", + "\n", + "在MindSpore中,我们可以通过控制模式输入参数来切换执行使用动态图还是静态图。例如:" + ], + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 5, + "source": [ + "import mindspore as ms\n", + "ms.set_context(mode=ms.PYNATIVE_MODE)" + ], + "outputs": [], + "metadata": { + "ExecuteTime": { + "end_time": "2022-01-04T10:51:23.461198Z", + "start_time": "2022-01-04T10:51:23.447508Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "由于在静态图下,对于Python语法有所限制,因此从动态图切换成静态图时,需要符合静态图的语法限制,才能正确使用静态图来进行执行。更多静态图的语法限制可以参考[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)。\n", + "\n", + "## 动静结合\n", + "\n", + "MindSpore支持在动态图下使用静态编译的方式来进行混合执行,通过使用jit修饰需要用静态图来执行的函数对象,即可实现动态图和静态图的混合执行,更多jit的使用可参考[jit文档](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/accelerate_with_static_graph.html#基于装饰器的开启方式)。\n", + "\n", + "例如:" + ], + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 6, + "source": [ + "import numpy as np\n", + "import mindspore as ms\n", + "import mindspore.nn as nn\n", + "\n", + "class AddMulMul(nn.Cell):\n", + " def __init__(self):\n", + " super(AddMulMul, self).__init__()\n", + " self.param = ms.Parameter(ms.Tensor(0.5, ms.float32))\n", + "\n", + " @ms.jit\n", + " def construct(self, x):\n", + " x = x + x\n", + " x = x * self.param\n", + " x = x * x\n", + " return x\n", + "\n", + "class CellCallSingleCell(nn.Cell):\n", + " def __init__(self):\n", + " super(CellCallSingleCell, self).__init__()\n", + " self.conv = nn.Conv2d(1, 2, kernel_size=2, stride=1, padding=0, weight_init=\"ones\", pad_mode=\"valid\")\n", + " self.bn = nn.BatchNorm2d(2, momentum=0.99, eps=0.00001, gamma_init=\"ones\")\n", + " self.relu = nn.ReLU()\n", + " self.add_mul_mul = AddMulMul()\n", + "\n", + " def construct(self, x):\n", + " x = self.conv(x)\n", + " x = self.bn(x)\n", + " x = self.add_mul_mul(x)\n", + " x = self.relu(x)\n", + " return x\n", + "\n", + "ms.set_context(mode=ms.PYNATIVE_MODE, device_target=\"CPU\")\n", + "inputs = ms.Tensor(np.ones([1, 1, 2, 2]).astype(np.float32))\n", + "net = CellCallSingleCell()\n", + "out = net(inputs)\n", + "print(out)" + ], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[[15.99984]]\n", + "\n", + " [[15.99984]]]]\n" + ] + } + ], + "metadata": { + "ExecuteTime": { + "end_time": "2022-01-04T10:51:23.514919Z", + "start_time": "2022-01-04T10:51:23.462207Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "## 静态图语法增强技术\n", + "\n", + "在MindSpore静态图模式下,用户编写程序时需要遵循MindSpore[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html),语法使用存在约束限制。而在动态图模式下,Python脚本代码会根据Python语法进行执行,用户可以使用任意Python语法。可以看出,静态图和动态图的语法约束限制是不同的。\n", + "\n", + "JIT Fallback是从静态图的角度出发考虑静态图和动态图的统一。在编译过程中发现不支持的语法时,将该语法Fallback到Python解释器进行解释执行。通过JIT Fallback特性,静态图可以支持尽量多的动态图语法,使得静态图提供接近动态图的语法使用体验,从而实现动静统一。\n", + "\n", + "在图模式场景下,MindSpore框架在图编译过程中遇到不支持语法或不支持符号时会报错,多数是在类型推导阶段。图编译阶段首先对用户编写的Python源码进行解析,然后执行后续的静态分析、类型推导、优化等步骤。因此,JIT Fallback特性需要预先检测不支持语法。常见的不支持语法主要包括:调用第三方库的方法、调用类名来创建对象、调用未支持的Python内置函数等。对不支持的语法Fallback到Python解释器进行解释执行。由于图模式采用[中间表示MindIR](https://www.mindspore.cn/docs/zh-CN/master/design/all_scenarios.html#中间表示mindir),需要将解释执行的语句转换到中间表示,记录下解释器需要的信息。\n", + "\n", + "下面主要介绍使用JIT Fallback扩展支持的静态图语法。JIT语法支持级别选项jit_syntax_level的默认值为`LAX`,即使用JIT Fallback的能力扩展静态图语法。\n", + "\n", + "### 调用第三方库\n", + "\n", + "完善支持NumPy、SciPy等第三方库。静态图模式支持np.ndarray等众多第三方库数据类型及其运算操作,支持获取调用第三方库的属性和方法,并支持通过Tensor的asnumpy()等方法与NumPy等三方库进行交互处理。也就是说,用户可以在静态图模式下调用MindSpore自身接口和算子,或者直接调用三方库的接口,也可以把它们融合在一起使用。\n", + "\n", + "- 支持第三方库(如NumPy、SciPy等)的数据类型,允许调用和返回第三方库的对象。\n", + "- 支持调用第三方库的方法。\n", + "- 支持使用NumPy第三方库数据类型创建Tensor对象。\n", + "- 暂不支持对第三方库数据类型的下标索引赋值。\n", + "\n", + "更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[调用第三方库](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#调用第三方库-1)。\n", + "\n", + "### 支持自定义类的使用\n", + "\n", + "用户自定义的类,没有使用`@jit_class`修饰,也没有继承`nn.Cell`。通过JIT Fallback技术方案,静态图模式下允许创建和引用自定义类的实例,可以支持直接获取和调用自定义类实例的属性和方法,并且允许修改属性(Inplace操作)。\n", + "\n", + "更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[支持自定义类的使用](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#支持自定义类的使用)。\n", + "\n", + "### 基础运算符支持更多数据类型\n", + "\n", + "在静态图语法重载了以下运算符: ['+', '-', '*', '/', '//', '%', '**', '<<', '>>', '&', '|', '^', 'not', '==', '!=', '<', '>', '<=', '>=', 'in', 'not in', 'y=x[0]']。图模式重载的运算符详见[运算符](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/operators.html)。列表中的运算符在输入图模式中不支持的输入类型时将使用扩展静态图语法支持,并使输出结果与动态图模式下的输出结果一致。\n", + "\n", + "更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[基础运算符支持更多数据类型](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#基础运算符支持更多数据类型)。\n", + "\n", + "### 基础类型\n", + "\n", + "扩展对Python原生数据类型`List`、`Dictionary`、`None`的支持。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[基础类型](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#基础类型)。\n", + "\n", + "#### 支持列表就地修改操作\n", + "\n", + "- 支持从全局变量中获取原`List`对象。\n", + "- 不支持对输入`List`对象进行inplace操作。\n", + "- 支持部分`List`内置函数的就地修改操作。\n", + "\n", + "#### 支持Dictionary的高阶用法\n", + "\n", + "- 支持顶图返回Dictionary。\n", + "- 支持Dictionary索引取值和赋值。\n", + "\n", + "#### 支持使用None\n", + "\n", + "`None`是Python中的一个特殊值,表示空,可以赋值给任何变量。对于没有返回值语句的函数认为返回`None`。同时也支持`None`作为顶图或者子图的入参或者返回值。支持`None`作为切片的下标,作为`List`、`Tuple`、`Dictionary`的输入。\n", + "\n", + "### 内置函数支持更多数据类型\n", + "\n", + "扩展内置函数的支持范围。Python内置函数完善支持更多输入类型,例如第三方库数据类型。更多内置函数的支持情况可见[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/python_builtin_functions.html)章节。\n", + "\n", + "### 支持控制流\n", + "\n", + "为了提高Python标准语法支持度,实现动静统一,扩展支持更多数据类型在控制流语句的使用。控制流语句是指`if`、`for`、`while`等流程控制语句。理论上,通过扩展支持的语法,在控制流场景中也支持。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[支持控制流](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#支持控制流)。\n", + "\n", + "### 支持属性设置与修改\n", + "\n", + "支持更多类型的Inplace操作。之前版本只支持通过Inplace算子对Parameter类型进行值修改,在MindSpore2.1版本静态图模式下,支持了自定义类,Cell子类,jit_class类的属性修改。除了支持更改类self属性和全局变量的属性以外,也新增支持对List类型的extend()、reverse()、insert()、pop()等Inplace操作。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[支持属性设置与修改](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#支持属性设置与修改-1)。\n", + "\n", + "- 对自定义类对象以及第三方类型的属性进行设置与修改。\n", + "- 对Cell的self对象进行修改。\n", + "- 对静态图内的Cell对象以及jit_class对象进行设置与修改。\n", + "\n", + "### 支持求导\n", + "\n", + "使用JIT Fallback支持的静态图语法,同样支持其在求导中使用。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[支持求导](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#支持求导)。\n", + "\n", + "### Annotation Type\n", + "\n", + "对于运行时的JIT Fallback支持的语法,会产生一些无法被类型推导出的节点,这种类型称为`Any`类型。因为该类型无法在编译时推导出正确的类型,所以这种`Any`将会以一种默认最大精度`float64`进行运算,防止其精度丢失。为了能更好的优化相关性能,需要减少`Any`类型数据的产生。当用户可以明确知道当前通过扩展支持的语句会产生具体类型的时候,我们推荐使用`Annotation @jit.typing:`的方式进行指定对应Python语句类型,从而确定解释节点的类型避免`Any`类型的生成。更多使用可见[静态图语法支持](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html)中的[Annotation Type](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#annotation-type)。\n", + "\n", + "### 使用须知\n", + "\n", + "在使用静态图JIT Fallback扩展支持语法时,请注意以下几点:\n", + "\n", + "1. 对标动态图的支持能力,即:须在动态图语法范围内,包括但不限于数据类型等。\n", + "\n", + "2. 在扩展静态图语法时,支持了更多的语法,但执行性能可能会受影响,不是最佳。\n", + "\n", + "3. 在扩展静态图语法时,支持了更多的语法,由于使用Python的能力,不能使用MindIR导入导出的能力。\n", + "\n", + "4. 暂不支持跨Python文件重复定义同名的全局变量,且这些全局变量在网络中会被用到。" + ], + "metadata": {}, + "attachments": {} + }, + { + "cell_type": "markdown", + "source": [ + "## 动态图转静态图技术\n", + "\n", + "MindSpore提供了一种在代码无需修改的情况下,直接将用户的动态图代码转换成静态图的功能——PIJit。该功能同时兼顾性能和易用性,去除动静模式切换的代价,真正做到动静统一。它基于Python字节码的分析,对Python的执行流进行图捕获,可以以静态图方式运行的子图便以静态图方式运行,Python语法不支持的子图便以动态图方式运行,同时通过修改调整字节码的方式链接静态图,达到动静混合执行。在满足易用性的前提下,尽可能地提高性能。\n", + "\n", + "### PIJit包含以下功能\n", + "\n", + "- 1. 图捕获:对字节码预处理,动态跟踪解释执行,识别MindSpore可入图操作,提供裂图功能保证函数(字节码)功能的正确性。\n", + "- 2. 字节码支持:当前支持Python3.7、Python3.8、Python3.9和Python3.10的字节码。\n", + "- 3. 图优化:对图中生成的字节码进行优化,包括分支裁剪、字节码筛选、函数字节码内联、常量折叠等功能。\n", + "- 4. 异常捕获机制:支持with、try-except语法。\n", + "- 5. 支持循环处理:通过模拟字节码的操作栈实现图捕获、裂图等特性。\n", + "- 6. UD分析:通过变量的user-def链分析的方法,解决部分参数类型不能作为静态图的返回值问题(函数、Bool、None),同时减少无用的入参,提高图的执行效率,减少数据的拷贝。\n", + "- 7. 副作用分析处理:弥补静态图的副作用处理上的劣势,根据不同场景,收集记录产生副作用的变量及字节码,在保证程序语义的基础上,在静态图外补充副作用的处理。\n", + "- 8. 守护门禁:门禁(Guard)记录了子图/优化进入的输入需要满足的条件,检查输入是否适合对应的子图优化。\n", + "- 9. Cache:图管理(Cache)则缓存了子图/优化和门禁(Guard)对应关系。\n", + "- 10. Dynamic Shape和Symbolic Shape: 使用input_signature支持Tensor/Tensor List/Tensor Tuple的DynamicShape和SymblicShape作为输入提示。同时支持自动多次运行后,识别Dynamic Shape。\n", + "- 11. 即时跟踪编译: 在跟踪和字节码分析过程中,支持算子等类型推导。\n", + "- 12. 自动混合精度: 支持原生mindspore.nn.Cell的自动混合精度能力。\n", + "\n", + "### 使用方式\n", + "\n", + "def jit(fn=None, input_signature=None, hash_args=None, jit_config=None, mode=\"PIJit\"):\n", + "\n", + "原Jit功能使用mode=\"PSJit\",新特性PIJit使用mode=\"PIJit\",jit_config传递一个参数字典,可以提供一些优化和调试选项。如:print_after_all可以打印入图的字节码和裂图信息,loop_unrolling可以提供循环展开功能,enable_dynamic_shape使能动态Shape。\n", + "\n", + "### 使用限制\n", + "\n", + "- 不支持在静态图模式下,运行带装饰@jit(mode=\\\"PIJit\\\")的函数,此时该装饰@jit(mode=\\\"PIJit\\\")视为无效。\n", + "- 不支持在@jit(mode=\\\"PSJit\\\")装饰的函数内部调用带装饰@jit(mode=\\\"PIJit\\\")的函数,该装饰 @jit(mode=\\\"PIJit\\\")视为无效。\n", + "\n" + ], + "metadata": {} + } + ], + "metadata": { + "kernelspec": { + "display_name": "MindSpore", + "language": "python", + "name": "mindspore" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 + } \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/model_train/program_form/overview.md b/docs/mindspore/source_zh_cn/model_train/program_form/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..62b4b76d996efc6dadaf28e79785f6d3a6a10cf0 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/program_form/overview.md @@ -0,0 +1,3 @@ +# 编程形态概述 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/overview.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/model_train/program_form/pynative.ipynb b/docs/mindspore/source_zh_cn/model_train/program_form/pynative.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..3d28da7277ca25dbd556664988536d5f3167c7c1 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/program_form/pynative.ipynb @@ -0,0 +1,92 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# 动态图编程\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/mindspore_pynative.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/mindspore_pynative.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/pynative.ipynb)\n", + "\n", + "在MindSpore中,动态图模式又被称为PyNative模式,可以通过`set_context(mode=PYNATIVE_MODE)`来设置成动态图模式。在脚本开发和网络流程调试中,推荐使用动态图模式进行调试,支持执行单算子、普通函数和网络、以及单独求梯度的操作。\n", + "\n", + "在PyNative模式下,用户可以使用完整的Python API,此外针对使用MindSpore提供的API时,框架会根据用户选择的硬件平台(Ascend,GPU,CPU),将算子API的操作在对应的硬件平台上执行,并返回相应的结果。框架整体的执行过程如下:\n", + "\n", + "![process](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/design/images/framework.png)\n", + "\n", + "通过前端的Python API,调用到框架层,最终到相应的硬件设备上进行计算。例如:完成一个加法。" + ], + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 2, + "source": [ + "import numpy as np\n", + "import mindspore as ms\n", + "import mindspore.ops as ops\n", + "\n", + "ms.set_context(mode=ms.PYNATIVE_MODE, device_target=\"CPU\")\n", + "x = ms.Tensor(np.ones([1, 3, 3, 4]).astype(np.float32))\n", + "y = ms.Tensor(np.ones([1, 3, 3, 4]).astype(np.float32))\n", + "output = ops.add(x, y)\n", + "print(output.asnumpy())" + ], + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[[[2. 2. 2. 2.]\n", + " [2. 2. 2. 2.]\n", + " [2. 2. 2. 2.]]\n", + "\n", + " [[2. 2. 2. 2.]\n", + " [2. 2. 2. 2.]\n", + " [2. 2. 2. 2.]]\n", + "\n", + " [[2. 2. 2. 2.]\n", + " [2. 2. 2. 2.]\n", + " [2. 2. 2. 2.]]]]\n" + ] + } + ], + "metadata": { + "ExecuteTime": { + "end_time": "2022-01-04T10:51:23.292278Z", + "start_time": "2022-01-04T10:51:23.284465Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "此例中,当调用到Python接口ops.add(x, y)时,会将Python的接口调用通过Pybind11调用到框架的C++层,转换成C++的调用,接着框架会根据用户设置的device_target选择对应的硬件设备,在该硬件设备上执行add这个操作。\n", + "\n", + "从上述原理可以看到,在PyNative模式下,Python脚本代码会根据Python的语法进行执行,而执行过程中涉及到MindSpore的API,会根据用户设置在不同的硬件上进行执行,从而进行加速。因此,在PyNative模式下,用户可以随意使用Python的语法以及调试方法。例如可以使用常见的PyCharm、VS Code等IDE进行代码的调试。\n", + "\n" + ], + "metadata": {} + } + ], + "metadata": { + "kernelspec": { + "display_name": "MindSpore", + "language": "python", + "name": "mindspore" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 + } \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/model_train/program_form/static_graph.rst b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph.rst new file mode 100644 index 0000000000000000000000000000000000000000..06aa65c3f1d29e04a5b2d19ae988ed37bcd9930b --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph.rst @@ -0,0 +1,1835 @@ +静态图编程 +=============== + +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg + :target: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_static_graph_syntax_support.ipynb +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg + :target: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_static_graph_syntax_support.py +.. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_syntax_support.ipynb + :alt: 查看源文件 + +.. toctree:: + :maxdepth: 1 + :hidden: + + static_graph_syntax/operators + static_graph_syntax/statements + static_graph_syntax/python_builtin_functions + static_graph_syntax/static_graph_expert_programming.ipynb + +概述 +---- + +在Graph模式下,Python代码并不是由Python解释器去执行,而是将代码编译成静态计算图,然后执行静态计算图。 + +在静态图模式下,MindSpore通过源码转换的方式,将Python的源码转换成中间表达IR(Intermediate +Representation),并在此基础上对IR图进行优化,最终在硬件设备上执行优化后的图。MindSpore使用基于图表示的函数式IR,称为MindIR,详情可参考\ `中间表示MindIR `_\ 。 + +MindSpore的静态图执行过程实际包含两步,对应静态图的Define和Run阶段,但在实际使用中,在实例化的Cell对象被调用时用户并不会分别感知到这两阶段,MindSpore将两阶段均封装在Cell的\ ``__call__``\ 方法中,因此实际调用过程为: + +``model(inputs) = model.compile(inputs) + model.construct(inputs)``\ ,其中\ ``model``\ 为实例化Cell对象。 + +使用Graph模式有两种方式:一是调用\ ``@jit``\ 装饰器修饰函数或者类的成员方法,所修饰的函数或方法将会被编译成静态计算图。\ ``jit``\ 使用规则详见\ `jit +API文档 `_\ 。二是设置\ ``ms.set_context(mode=ms.GRAPH_MODE)``\ ,使用\ ``Cell``\ 类并且在\ ``construct``\ 函数中编写执行代码,此时\ ``construct``\ 函数的代码将会被编译成静态计算图。\ ``Cell``\ 定义详见\ `Cell +API文档 `_\ 。 + +由于语法解析的限制,当前在编译构图时,支持的数据类型、语法以及相关操作并没有完全与Python语法保持一致,部分使用受限。借鉴传统JIT编译的思路,从图模式的角度考虑动静图的统一,扩展图模式的语法能力,使得静态图提供接近动态图的语法使用体验,从而实现动静统一。为了便于用户选择是否扩展静态图语法,提供了JIT语法支持级别选项\ ``jit_syntax_level``\ ,其值必须在[STRICT,LAX]范围内,选择\ ``STRICT``\ 则认为使用基础语法,不扩展静态图语法。默认值为\ ``LAX``\ ,更多请参考本文的\ `扩展语法(LAX级别) <#扩展语法lax级别>`_\ 章节。全部级别都支持所有后端。 + +- STRICT: 仅支持基础语法,且执行性能最佳。可用于MindIR导入导出。 +- LAX: + 支持更多复杂语法,最大程度地兼容Python所有语法。由于存在可能无法导出的语法,不能用于MindIR导入导出。 + +本文主要介绍,在编译静态图时,支持的数据类型、语法以及相关操作,这些规则仅适用于Graph模式。 + +基础语法(STRICT级别) +---------------------- + +静态图内的常量与变量 +~~~~~~~~~~~~~~~~~~~~ + +在静态图中,常量与变量是理解静态图语法的一个重要概念,很多语法在常量输入和变量输入情况下支持的方法与程度是不同的。因此,在介绍静态图具体支持的语法之前,本小节先会对静态图中常量与变量的概念进行说明。 + +在静态图模式下,一段程序的运行会被分为编译期以及执行期。 +在编译期,程序会被编译成一张中间表示图,并且程序不会真正的执行,而是通过抽象推导的方式对中间表示进行静态解析。这使得在编译期时,我们无法保证能获取到所有中间表示中节点的值。 +常量和变量也就是通过能否能在编译器获取到其真实值来区分的。 + +- 常量: 编译期内可以获取到值的量。 +- 变量: 编译期内无法获取到值的量。 + +常量产生场景 +^^^^^^^^^^^^ + +- 作为图模式输入的标量,列表以及元组均为常量(在不使用mutable接口的情况下)。例如: + + .. code:: python + + from mindspore import Tensor, jit + + a = 1 + b = [Tensor([1]), Tensor([2])] + c = ["a", "b", "c"] + + @jit + def foo(a, b, c): + return a, b, c + + 上述代码中,输入\ ``a``\ ,\ ``b``\ ,\ ``c``\ 均为常量。 + +- 图模式内生成的标量或者Tensor为常量。例如: + + .. code:: python + + from mindspore import jit, Tensor + + @jit + def foo(): + a = 1 + b = "2" + c = Tensor([1, 2, 3]) + return a, b, c + + 上述代码中, ``a``\ ,\ ``b``\ ,\ ``c``\ 均为常量。 + +- 常量运算得到的结果为常量。例如: + + .. code:: python + + from mindspore import jit, Tensor + + @jit + def foo(): + a = Tensor([1, 2, 3]) + b = Tensor([1, 1, 1]) + c = a + b + return c + + 上述代码中,\ ``a``\ 、\ ``b``\ 均为图模式内产生的Tensor为常量,因此其计算得到的结果也是常量。但如果其中之一为变量时,其返回值也会为变量。 + +变量产生场景 +^^^^^^^^^^^^ + +- 所有mutable接口的返回值均为变量(无论是在图外使用mutable还是在图内使用)。例如: + + .. code:: python + + from mindspore import Tensor, jit + from mindspore import mutable + + a = mutable([Tensor([1]), Tensor([2])]) + + @jit + def foo(a): + b = mutable(Tensor([3])) + c = mutable((Tensor([1]), Tensor([2]))) + return a, b, c + + 上述代码中,\ ``a``\ 是在图外调用mutable接口的,\ ``b``\ 和\ ``c``\ 是在图内调用mutable接口生成的,\ ``a``\ 、\ ``b``\ 、\ ``c``\ 均为变量。 + +- 作为静态图的输入的Tensor都是变量。例如: + + .. code:: python + + from mindspore import Tensor, jit + + a = Tensor([1]) + b = (Tensor([1]), Tensor([2])) + + @jit + def foo(a, b): + return a, b + + 上述代码中,\ ``a``\ 是作为图模式输入的Tensor,因此其为变量。但\ ``b``\ 是作为图模式输入的元组,非Tensor类型,即使其内部的元素均为Tensor,\ ``b``\ 也是常量。 + +- 通过变量计算得到的是变量。 + + 如果一个量是算子的输出,那么其多数情况下为常量。例如: + + .. code:: python + + from mindspore import Tensor, jit, ops + + a = Tensor([1]) + b = Tensor([2]) + + @jit + def foo(a, b): + c = a + b + return c + + 在这种情况下,\ ``c``\ 是\ ``a``\ 和\ ``b``\ 计算来的结果,且用来计算的输入\ ``a``\ 、\ ``b``\ 均为变量,因此\ ``c``\ 也是变量。 + +数据类型 +~~~~~~~~ + +Python内置数据类型 +^^^^^^^^^^^^^^^^^^ + +当前支持的\ ``Python``\ 内置数据类型包括:\ ``Number``\ 、\ ``String``\ 、\ ``List``\ 、\ ``Tuple``\ 和\ ``Dictionary``\ 。 + +Number +'''''' + +支持\ ``int``\ (整型)、\ ``float``\ (浮点型)、\ ``bool``\ (布尔类型),不支持\ ``complex``\ (复数)。 + +支持在网络里定义\ ``Number``\ ,即支持语法:\ ``y = 1``\ 、\ ``y = 1.2``\ 、\ ``y = True``\ 。 + +当数据为常量时,编译时期可以获取到数值,在网络中可以支持强转\ ``Number``\ 的语法:\ ``y = int(x)``\ 、\ ``y = float(x)``\ 、\ ``y = bool(x)``\ 。 +当数据为变量时,即需要在运行时期才可以获取到数值,也支持使用int(),float(),bool()等内置函数\ `Python内置函数 `_\ 进行数据类型的转换。例如: + +.. code:: python + + from mindspore import Tensor, jit + + @jit + def foo(x): + out1 = int(11.1) + out2 = int(Tensor([10])) + out3 = int(x.asnumpy()) + return out1, out2, out3 + + res = foo(Tensor(2)) + print("res[0]:", res[0]) + print("res[1]:", res[1]) + print("res[2]:", res[2]) + +运行结果如下: + +.. code:: text + + res[0]: 11 + res[1]: 10 + res[2]: 2 + +支持返回Number类型。例如: + +.. code:: python + + import mindspore as ms + + @ms.jit + def test_return_scalar(x, y): + return x + y + + res = test_return_scalar(ms.mutable(1), ms.mutable(2)) + print(res) + +运行结果如下: + +.. code:: text + + 3 + +String +'''''' + +支持在网络里构造\ ``String``\ ,即支持使用引号(\ ``'``\ 或\ ``"``\ )来创建字符串,如\ ``x = 'abcd'``\ 或\ ``y = "efgh"``\ 。可以通过\ ``str()``\ 的方式进行将常量转换成字符串。支持对字符串连接,截取,以及使用成员运算符(\ ``in``\ 或\ ``not in``\ )判断字符串是否包含指定的字符。支持格式化字符串的输出,将一个值插入到一个有字符串格式符\ ``%s``\ 的字符串中。支持在常量场景下使用格式化字符串函数\ ``str.format()``\ 。 + +例如: + +.. code:: python + + from mindspore import jit + + @jit + def foo(): + var1 = 'Hello!' + var2 = "MindSpore" + var3 = str(123) + var4 = "{} is {}".format("string", var3) + return var1[0], var2[4:9], var1 + var2, var2 * 2, "H" in var1, "My name is %s!" % var2, var4 + + res = foo() + print("res:", res) + +运行结果如下: + +.. code:: text + + res: ('H', 'Spore', 'Hello!MindSpore', 'MindSporeMindSpore', True, 'My name is MindSpore!', 'string is 123') + +List +'''' + +在\ ``JIT_SYNTAX_LEVEL``\ 设置为\ ``LAX``\ 的情况下,静态图模式可以支持部分\ ``List``\ 对象的inplace操作,具体介绍详见\ `支持列表就地修改操作 <#支持列表就地修改操作>`_\ 章节。 + +``List``\ 的基础使用场景如下: + +- 图模式支持图内创建\ ``List``\ 。 + + 支持在图模式内创建\ ``List``\ 对象,且\ ``List``\ 内对象的元素可以包含任意图模式支持的类型,也支持多层嵌套。例如: + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def generate_list(): + a = [1, 2, 3, 4] + b = ["1", "2", "a"] + c = [ms.Tensor([1]), ms.Tensor([2])] + d = [a, b, c, (4, 5)] + return d + + 上述示例代码中,所有的\ ``List``\ 对象都可以被正常的创建。 + +- 图模式支持返回\ ``List``\ 。 + + 在MindSpore2.0版本之前,当图模式返回\ ``List`` + 对象时,\ ``List``\ 会被转换为\ ``Tuple``\ 。MindSpore2.0版本已经可以支持返回\ ``List``\ 对象。例如: + + .. code:: python + + import mindspore as ms + + @ms.jit + def list_func(): + a = [1, 2, 3, 4] + return a + + output = list_func() # output: [1, 2, 3, 4] + + 与图模式内创建\ ``List`` + 相同,图模式返回\ ``List``\ 对象可以包括任意图模式支持的类型,也支持多层嵌套。 + +- 图模式支持从全局变量中获取\ ``List``\ 对象。 + + .. code:: python + + import mindspore as ms + + global_list = [1, 2, 3, 4] + + @ms.jit + def list_func(): + global_list.reverse() + return global_list + + output = list_func() # output: [4, 3, 2, 1] + + 需要注意的是,在基础场景下图模式返回的列表与全局变量的列表不是同一个对象,当\ ``JIT_SYNTAX_LEVEL``\ 设置为\ ``LAX``\ 时,返回的对象与全局对象为统一对象。 + +- 图模式支持以\ ``List``\ 作为输入。 + + 图模式支持\ ``List``\ 作为静态图的输入,作为输入的\ ``List``\ 对象的元素必须为图模式支持的输入类型,也支持多层嵌套。 + + .. code:: python + + import mindspore as ms + + list_input = [1, 2, 3, 4] + + @ms.jit + def list_func(x): + return x + + output = list_func(list_input) # output: [1, 2, 3, 4] + + 需要注意的是,\ ``List``\ 作为静态图输入时,无论其内部的元素是什么类型,一律被视为常量。 + +- 图模式支持List的内置方法。 + + ``List`` 内置方法的详细介绍如下: + + - List索引取值 + + 基础语法:\ ``element = list_object[index]``\ 。 + + 基础语义:将\ ``List``\ 对象中位于第\ ``index``\ 位的元素提取出来(\ ``index``\ 从0开始)。支持多层索引取值。 + + 索引值\ ``index``\ 支持类型包括\ ``int``\ ,\ ``Tensor``\ 和\ ``slice``\ 。其中,\ ``int``\ 以及\ ``Tensor``\ 类型的输入可以支持常量以及变量,\ ``slice``\ 内部数据必须为编译时能够确定的常量。 + + 示例如下: + + .. code:: python + + import mindspore as ms + @ms.jit() + def list_getitem_func(): + x = [[1, 2], 3, 4] + a = x[0] + b = x[0][ms.Tensor([1])] + c = x[1:3:1] + return a, b, c + + a, b, c = list_getitem_func() + print('a:{}'.format(a)) + print('b:{}'.format(b)) + print('c:{}'.format(c)) + + 运行结果如下: + + .. code:: text + + a:[1, 2] + b:2 + c:[3, 4] + + - List索引赋值 + + 基础语法:\ ``list_object[index] = target_element``\ 。 + + 基础语义:将\ ``List``\ 对象中位于第\ ``index``\ 位的元素赋值为 + ``target_element``\ (\ ``index``\ 从0开始)。支持多层索引赋值。 + + 索引值\ ``index``\ 支持类型包括\ ``int``\ ,\ ``Tensor``\ 和\ ``slice``\ 。其中,\ ``int`` + 以及\ ``Tensor``\ 类型的输入可以支持常量以及变量,\ ``slice``\ 内部数据必须为编译时能够确定的常量。 + + 索引赋值对象\ ``target_element``\ 支持所有图模式支持的数据类型。 + + 目前,\ ``List``\ 索引赋值不支持inplace操作, + 索引赋值后将会生成一个新的对象。该操作后续将会支持inplace操作。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_setitem_func(): + x = [[0, 1], 2, 3, 4] + x[1] = 10 + x[2] = "ok" + x[3] = (1, 2, 3) + x[0][1] = 88 + return x + + output = test_setitem_func() + print('output:{}'.format(output)) + + 运行结果如下: + + .. code:: text + + output:[[0, 88], 10, 'ok', (1, 2, 3)] + + - List.append + + 基础语法:\ ``list_object.append(target_element)``\ 。 + + 基础语义:向\ ``List``\ 对象\ ``list_object``\ 的最后追加元素\ ``target_element``\ 。 + + 目前,\ ``List.append``\ 不支持inplace操作, + 索引赋值后将会生成一个新的对象。该操作后续将会支持inplace操作。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list(): + x = [1, 2, 3] + x.append(4) + return x + + x = test_list() + print('x:{}'.format(x)) + + 运行结果如下: + + .. code:: text + + x:[1, 2, 3, 4] + + - List.clear + + 基础语法:\ ``list_object.clear()``\ 。 + + 基础语义:清空\ ``List``\ 对象 ``list_object``\ 中包含的元素。 + + 目前,\ ``List.clear``\ 不支持inplace, + 索引赋值后将会生成一个新的对象。该操作后续将会支持inplace。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_clear(): + x = [1, 3, 4] + x.clear() + return x + + x = test_list_clear() + print('x:{}'.format(x)) + + 运行结果如下: + + .. code:: text + + x:[] + + - List.extend + + 基础语法:\ ``list_object.extend(target)``\ 。 + + 基础语义:向\ ``List``\ 对象\ ``list_object``\ 的最后依次插入\ ``target``\ 内的所有元素。 + + ``target``\ 支持的类型为\ ``Tuple``\ ,\ ``List``\ 以及\ ``Tensor``\ 。其中,如果\ ``target``\ 类型为\ ``Tensor``\ 的情况下,会先将该\ ``Tensor``\ 转换为\ ``List``\ ,再进行插入操作。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_extend(): + x1 = [1, 2, 3] + x1.extend((4, "a")) + x2 = [1, 2, 3] + x2.extend(ms.Tensor([4, 5])) + return x1, x2 + + output1, output2 = test_list_extend() + print('output1:{}'.format(output1)) + print('output2:{}'.format(output2)) + + 运行结果如下: + + .. code:: text + + output1:[1, 2, 3, 4, 'a'] + output2:[1, 2, 3, Tensor(shape=[], dtype=Int64, value= 4), Tensor(shape=[], dtype=Int64, value= 5)] + + - List.pop + + 基础语法:\ ``pop_element = list_object.pop(index=-1)``\ 。 + + 基础语义:将\ ``List``\ 对象\ ``list_object`` + 的第\ ``index``\ 个元素从\ ``list_object``\ 中删除,并返回该元素。 + + ``index`` 要求必须为常量\ ``int``, + 当\ ``list_object``\ 的长度为\ ``list_obj_size``\ 时,\ ``index``\ 的取值范围为:\ ``[-list_obj_size,list_obj_size-1]``\ 。\ ``index``\ 为负数,代表从后往前的位数。当没有输入\ ``index``\ 时,默认值为-1,即删除最后一个元素。 + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_pop(): + x = [1, 2, 3] + b = x.pop() + return b, x + + pop_element, res_list = test_list_pop() + print('pop_element:{}'.format(pop_element)) + print('res_list:{}'.format(res_list)) + + 运行结果如下: + + .. code:: text + + pop_element:3 + res_list:[1, 2] + + - List.reverse + + 基础语法:\ ``list_object.reverse()``\ 。 + + 基础语义:将\ ``List``\ 对象\ ``list_object``\ 的元素顺序倒转。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_reverse(): + x = [1, 2, 3] + x.reverse() + return x + + output = test_list_reverse() + print('output:{}'.format(output)) + + 运行结果如下: + + .. code:: text + + output:[3, 2, 1] + + - List.insert + + 基础语法:\ ``list_object.insert(index, target_obj)``\ 。 + + 基础语义:将\ ``target_obj``\ 插入到\ ``list_object``\ 的第\ ``index``\ 位。 + + ``index``\ 要求必须为常量\ ``int``\ 。如果\ ``list_object``\ 的长度为\ ``list_obj_size``\ 。当\ ``index < -list_obj_size``\ 时,插入到\ ``List``\ 的第一位。当\ ``index >= list_obj_size``\ 时,插入到\ ``List``\ 的最后。\ ``index``\ 为负数代表从后往前的位数。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_list_insert(): + x = [1, 2, 3] + x.insert(3, 4) + return x + + output = test_list_insert() + print('output:{}'.format(output)) + + 运行结果如下: + + .. code:: text + + output:[1, 2, 3, 4] + +Tuple +''''' + +支持在网络里构造元组\ ``Tuple``\ ,使用小括号包含元素,即支持语法\ ``y = (1, 2, 3)``\ 。元组\ ``Tuple``\ 的元素不能修改,但支持索引访问元组\ ``Tuple``\ 中的元素,支持对元组进行连接组合。 + +- 支持索引取值。 + + 支持使用方括号加下标索引的形式来访问元组\ ``Tuple``\ 中的元素,索引值支持\ ``int``\ 、\ ``slice``\ 、\ ``Tensor``\ ,也支持多层索引取值,即支持语法\ ``data = tuple_x[index0][index1]...``\ 。 + + 索引值为\ ``Tensor``\ 有如下限制: + + - ``Tuple``\ 里存放的都是\ ``Cell``\ ,每个\ ``Cell``\ 要在\ ``Tuple``\ 定义之前完成定义,每个\ ``Cell``\ 的入参个数、入参类型和入参\ ``shape``\ 要求一致,每个\ ``Cell``\ 的输出个数、输出类型和输出\ ``shape``\ 也要求一致。 + + - 索引\ ``Tensor``\ 是一个\ ``dtype``\ 为\ ``int32``\ 的标量\ ``Tensor``\ ,取值范围在\ ``[-tuple_len, tuple_len)``\ ,\ ``Ascend``\ 后端不支持负数索引。 + + - 支持\ ``CPU``\ 、\ ``GPU``\ 和\ ``Ascend``\ 后端。 + + ``int``\ 、\ ``slice``\ 索引示例如下: + + .. code:: python + + import numpy as np + import mindspore as ms + + t = ms.Tensor(np.array([1, 2, 3])) + + @ms.jit() + def test_index(): + x = (1, (2, 3, 4), 3, 4, t) + y = x[1][1] + z = x[4] + m = x[1:4] + n = x[-4] + return y, z, m, n + + y, z, m, n = test_index() + print('y:{}'.format(y)) + print('z:{}'.format(z)) + print('m:{}'.format(m)) + print('n:{}'.format(n)) + + 运行结果如下: + + .. code:: text + + y:3 + z:[1 2 3] + m:((2, 3, 4), 3, 4) + n:(2, 3, 4) + + ``Tensor``\ 索引示例如下: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.relu = nn.ReLU() + self.softmax = nn.Softmax() + self.layers = (self.relu, self.softmax) + + def construct(self, x, index): + ret = self.layers[index](x) + return ret + + x = ms.Tensor([-1.0], ms.float32) + + net = Net() + ret = net(x, 0) + print('ret:{}'.format(ret)) + + 运行结果如下: + + .. code:: text + + ret:[0.] + +- 支持连接组合。 + + 与字符串\ ``String``\ 类似,元组支持使用\ ``+``\ 和\ ``*``\ 进行组合,得到一个新的元组\ ``Tuple``\ ,例如: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_index(): + x = (1, 2, 3) + y = (4, 5, 6) + return x + y, x * 2 + + out1, out2 = test_index() + print('out1:{}'.format(out1)) + print('out2:{}'.format(out2)) + + 运行结果如下: + + .. code:: text + + out1:(1, 2, 3, 4, 5, 6) + out2:(1, 2, 3, 1, 2, 3) + +Dictionary +'''''''''' + +支持在网络里构造字典\ ``Dictionary``\ ,每个键值\ ``key:value``\ 用冒号\ ``:``\ 分割,每个键值对之间用逗号\ ``,``\ 分割,整个字典使用大括号\ ``{}``\ 包含键值对,即支持语法\ ``y = {"a": 1, "b": 2}``\ 。 + +键\ ``key``\ 是唯一的,如果字典中存在多个相同的\ ``key``\ ,则重复的\ ``key``\ 以最后一个作为最终结果;而值\ ``value``\ 可以不是唯一的。键\ ``key``\ 需要保证是不可变的。当前键\ ``key``\ 支持\ ``String``\ 、\ ``Number``\ 、常量\ ``Tensor``\ 以及只包含这些类型对象的\ ``Tuple``\ ;值\ ``value``\ 支持\ ``Number``\ 、\ ``Tuple``\ 、\ ``Tensor``\ 、\ ``List``\ 、\ ``Dictionary``\ 和\ ``None``\ 。 + +- 支持接口。 + + ``keys``\ :取出\ ``dict``\ 里所有的\ ``key``\ 值,组成\ ``Tuple``\ 返回。 + + ``values``\ :取出\ ``dict``\ 里所有的\ ``value``\ 值,组成\ ``Tuple``\ 返回。 + + ``items``\ :取出\ ``dict``\ 里每一对\ ``key``\ 和\ ``value``\ 组成的\ ``Tuple``\ ,最终组成\ ``List``\ 返回。 + + ``get``\ :\ ``dict.get(key[, value])``\ 返回指定\ ``key``\ 对应的\ ``value``\ 值,如果指定\ ``key``\ 不存在,返回默认值\ ``None``\ 或者设置的默认值\ ``value``\ 。 + + ``clear``\ :删除\ ``dict``\ 里所有的元素。 + + ``has_key``\ :\ ``dict.has_key(key)``\ 判断\ ``dict``\ 里是否存在指定\ ``key``\ 。 + + ``update``\ :\ ``dict1.update(dict2)``\ 把\ ``dict2``\ 中的元素更新到\ ``dict1``\ 中。 + + ``fromkeys``\ :\ ``dict.fromkeys(seq([, value]))``\ 用于创建新的\ ``Dictionary``\ ,以序列\ ``seq``\ 中的元素做\ ``Dictionary``\ 的\ ``key``\ ,\ ``value``\ 为所有\ ``key``\ 对应的初始值。 + + 示例如下,其中返回值中的\ ``x``\ 和\ ``new_dict``\ 是一个\ ``Dictionary``\ ,在图模式JIT语法支持级别选项为LAX下扩展支持,更多Dictionary的高阶使用请参考本文的\ `支持Dictionary的高阶用法 <#支持dictionary的高阶用法>`_\ 章节。 + + .. code:: python + + import mindspore as ms + import numpy as np + + x = {"a": ms.Tensor(np.array([1, 2, 3])), "b": ms.Tensor(np.array([4, 5, 6])), "c": ms.Tensor(np.array([7, 8, 9]))} + + @ms.jit() + def test_dict(): + x_keys = x.keys() + x_values = x.values() + x_items = x.items() + value_a = x.get("a") + check_key = x.has_key("a") + y = {"a": ms.Tensor(np.array([0, 0, 0]))} + x.update(y) + new_dict = x.fromkeys("abcd", 123) + return x_keys, x_values, x_items, value_a, check_key, x, new_dict + + x_keys, x_values, x_items, value_a, check_key, new_x, new_dict = test_dict() + print('x_keys:{}'.format(x_keys)) + print('x_values:{}'.format(x_values)) + print('x_items:{}'.format(x_items)) + print('value_a:{}'.format(value_a)) + print('check_key:{}'.format(check_key)) + print('new_x:{}'.format(new_x)) + print('new_dict:{}'.format(new_dict)) + + 运行结果如下: + + .. code:: text + + x_keys:('a', 'b', 'c') + x_values:(Tensor(shape=[3], dtype=Int64, value= [1, 2, 3]), Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])) + x_items:[('a', Tensor(shape=[3], dtype=Int64, value= [1, 2, 3])), ('b', Tensor(shape=[3], dtype=Int64, value= [4, 5, 6])), ('c', Tensor(shape=[3], dtype=Int64, value= [7, 8, 9]))] + value_a:[1 2 3] + check_key:True + new_x:{'a': Tensor(shape=[3], dtype=Int64, value= [0, 0, 0]), 'b': Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), 'c': Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])} + new_dict:{'a': 123, 'b': 123, 'c': 123, 'd': 123} + +MindSpore自定义数据类型 +^^^^^^^^^^^^^^^^^^^^^^^ + +当前MindSpore自定义数据类型包括:\ ``Tensor``\ 、\ ``Primitive``\ 、\ ``Cell``\ 和\ ``Parameter``\ 。 + +Tensor +'''''' + +Tensor的属性与接口详见\ `Tensor +API文档 `_\ 。 + +支持在静态图模式下创建和使用Tensor。创建方式有使用\ `tensor函数接口 `_\ 和使用\ ``Tensor``\ 类接口。推荐使用tensor函数接口,用户可以使用指定所需要的dtype类型。代码用例如下。 + +.. code:: python + + import mindspore as ms + import mindspore.nn as nn + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + + @ms.jit + def construct(self, x): + return ms.tensor(x.asnumpy(), dtype=ms.float32) + + ms.set_context(mode=ms.GRAPH_MODE) + net = Net() + x = ms.Tensor(1, dtype=ms.int32) + print(net(x)) + +运行结果如下: + +.. code:: text + + 1.0 + +Primitive +''''''''' + +当前支持在construct里构造\ ``Primitive``\ 及其子类的实例。 + +但在调用时,参数只能通过位置参数方式传入,不支持通过键值对方式传入。 + +示例如下: + +.. code:: python + + import mindspore as ms + from mindspore import nn, ops, Tensor, set_context + import numpy as np + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + + def construct(self, x): + reduce_sum = ops.ReduceSum(True) #支持在construct里构造`Primitive`及其子类的实例 + ret = reduce_sum(x, axis=2) + return ret + + x = Tensor(np.random.randn(3, 4, 5, 6).astype(np.float32)) + net = Net() + ret = net(x) + print('ret.shape:{}'.format(ret.shape)) + +上面所定义的网络里,reduce_sum(x, +axis=2)的参数不支持通过键值对方式传入,只能通过位置参数方式传入,即reduce_sum(x, +2)。 + +结果报错如下: + +.. code:: text + + ValueError: For 'ReduceSum', the second input type should be tensor or scalar, but got invalid abstract type:AbstractKeywordArg. + +当前不支持在网络调用\ ``Primitive``\ 及其子类相关属性和接口。 + +当前已定义的\ ``Primitive``\ 详见\ `Primitive +API文档 `_\ 。 + +Cell +'''' + +当前支持在网络里构造\ ``Cell``\ 及其子类的实例,即支持语法\ ``cell = Cell(args...)``\ 。 + +但在调用时,参数只能通过位置参数方式传入,不支持通过键值对方式传入,即不支持在语法\ ``cell = Cell(arg_name=value)``\ 。 + +当前不支持在网络调用\ ``Cell``\ 及其子类相关属性和接口,除非是在\ ``Cell``\ 自己的\ ``construct``\ 中通过\ ``self``\ 调用。 + +``Cell``\ 定义详见\ `Cell +API文档 `_\ 。 + +Parameter +''''''''' + +``Parameter``\ 是变量张量,代表在训练网络时,需要被更新的参数。 + +``Parameter``\ 的定义和使用详见\ `Parameter +API文档 `_\ 。 + +运算符 +~~~~~~ + +算术运算符和赋值运算符支持\ ``Number``\ 和\ ``Tensor``\ 运算,也支持不同\ ``dtype``\ 的\ ``Tensor``\ 运算。详见\ `运算符 `_\ 。 + +原型 +~~~~ + +原型代表编程语言中最紧密绑定的操作。 + +属性引用与修改 +^^^^^^^^^^^^^^ + +属性引用是后面带有一个句点加一个名称的原型。 + +在MindSpore的Cell 实例中使用属性引用作为左值需满足如下要求: + +- 被修改的属性属于本\ ``cell``\ 对象,即必须为\ ``self.xxx``\ 。 +- 该属性在Cell的\ ``__init__``\ 函数中完成初始化且其为Parameter类型。 + +在JIT语法支持级别选项为\ ``LAX``\ 时,可以支持更多情况的属性修改,具体详见\ `支持属性设置与修改 <#支持属性设置与修改>`_\ 。 + +示例如下: + +.. code:: python + + import mindspore as ms + from mindspore import nn, set_context + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.weight = ms.Parameter(ms.Tensor(3, ms.float32), name="w") + self.m = 2 + + def construct(self, x, y): + self.weight = x # 满足条件可以修改 + # self.m = 3 # self.m 非Parameter类型禁止修改 + # y.weight = x # y不是self,禁止修改 + return x + + net = Net() + ret = net(1, 2) + print('ret:{}'.format(ret)) + +运行结果如下: + +.. code:: text + + ret:1 + +索引取值 +^^^^^^^^ + +对序列\ ``Tuple``\ 、\ ``List``\ 、\ ``Dictionary``\ 、\ ``Tensor``\ 的索引取值操作(Python称为抽取)。 + +``Tuple``\ 的索引取值请参考本文的\ `Tuple <#tuple>`_\ 章节。 + +``List``\ 的索引取值请参考本文的\ `List <#list>`_\ 章节。 + +``Dictionary``\ 的索引取值请参考本文的\ `Dictionary <#dictionary>`_\ 章节。 + +``Tensor``\ 的索引取详见\ `Tensor +索引取值文档 `_\ 。 + +调用 +^^^^ + +所谓调用就是附带可能为空的一系列参数来执行一个可调用对象(例如:\ ``Cell``\ 、\ ``Primitive``)。 + +示例如下: + +.. code:: python + + import mindspore as ms + from mindspore import nn, ops, set_context + import numpy as np + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.matmul = ops.MatMul() + + def construct(self, x, y): + out = self.matmul(x, y) # Primitive调用 + return out + + x = ms.Tensor(np.ones(shape=[1, 3]), ms.float32) + y = ms.Tensor(np.ones(shape=[3, 4]), ms.float32) + net = Net() + ret = net(x, y) + print('ret:{}'.format(ret)) + +运行结果如下: + +.. code:: text + + ret:[[3. 3. 3. 3.]] + +语句 +~~~~ + +当前静态图模式支持部分Python语句,包括raise语句、assert语句、pass语句、return语句、break语句、continue语句、if语句、for语句、while语句、with语句、列表生成式、生成器表达式、函数定义语句等,详见\ `Python语句 `_\ 。 + +Python内置函数 +~~~~~~~~~~~~~~ + +当前静态图模式支持部分Python内置函数,其使用方法与对应的Python内置函数类似,详见\ `Python内置函数 `_\ 。 + +网络定义 +~~~~~~~~ + +网络入参 +^^^^^^^^ + +在对整网入参求梯度的时候,会忽略非\ ``Tensor``\ 的入参,只计算\ ``Tensor``\ 入参的梯度。 + +示例如下。整网入参\ ``(x, y, z)``\ 中,\ ``x``\ 和\ ``z``\ 是\ ``Tensor``\ ,\ ``y``\ 是非\ ``Tensor``\ 。因此,\ ``grad_net``\ 在对整网入参\ ``(x, y, z)``\ 求梯度的时候,会自动忽略\ ``y``\ 的梯度,只计算\ ``x``\ 和\ ``z``\ 的梯度,返回\ ``(grad_x, grad_z)``\ 。 + +.. code:: python + + import numpy as np + import mindspore as ms + from mindspore import nn + + ms.set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + + def construct(self, x, y, z): + return x + y + z + + class GradNet(nn.Cell): + def __init__(self, net): + super(GradNet, self).__init__() + self.forward_net = net + + def construct(self, x, y, z): + return ms.grad(self.forward_net, grad_position=(0, 1, 2))(x, y, z) + + input_x = ms.Tensor([1]) + input_y = 2 + input_z = ms.Tensor([3]) + + net = Net() + grad_net = GradNet(net) + ret = grad_net(input_x, input_y, input_z) + print('ret:{}'.format(ret)) + +运行结果如下: + +.. code:: text + + ret:(Tensor(shape=[1], dtype=Int64, value= [1]), Tensor(shape=[1], dtype=Int64, value= [1])) + +基础语法的语法约束 +------------------ + +图模式下的执行图是从源码转换而来,并不是所有的Python语法都能支持。下面介绍在基础语法下存在的一些语法约束。更多网络编译问题可见\ `网络编译 `_\ 。 + +1. 当\ ``construct``\ 函数里,使用未定义的类成员时,将抛出\ ``AttributeError``\ 异常。示例如下: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + + def construct(self, x): + return x + self.y + + net = Net() + net(1) + + 结果报错如下: + + .. code:: text + + AttributeError: External object has no attribute y + +2. ``nn.Cell``\ 不支持\ ``classmethod``\ 修饰的类方法。示例如下: + + .. code:: python + + import mindspore as ms + + ms.set_context(mode=ms.GRAPH_MODE) + + class Net(ms.nn.Cell): + @classmethod + def func(cls, x, y): + return x + y + + def construct(self, x, y): + return self.func(x, y) + + net = Net() + out = net(ms.Tensor(1), ms.Tensor(2)) + print(out) + + 结果报错如下: + + .. code:: text + + TypeError: The parameters number of the function is 3, but the number + of provided arguments is 2. + +3. 在图模式下,有些Python语法难以转换成图模式下的\ `中间表示MindIR `_\ 。对标Python的关键字,存在部分关键字在图模式下是不支持的:AsyncFunctionDef、Delete、AnnAssign、AsyncFor、AsyncWith、Match、Try、Import、ImportFrom、Nonlocal、NamedExpr、Set、SetComp、Await、Yield、YieldFrom、Starred。如果在图模式下使用相关的语法,将会有相应的报错信息提醒用户。 + + 如果使用Try语句,示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit + def test_try_except(x, y): + global_out = 1 + try: + global_out = x / y + except ZeroDivisionError: + print("division by zero, y is zero.") + return global_out + + test_try_except_out = test_try_except(1, 0) + print("out:", test_try_except_out) + + 结果报错如下: + + .. code:: text + + RuntimeError: Unsupported statement 'Try'. + +4. 对标Python内置数据类型,除去当前图模式下支持的\ `Python内置数据类型 <#python内置数据类型>`_\ ,复数\ ``complex``\ 和集合\ ``set``\ 类型是不支持的。列表\ ``list``\ 和字典\ ``dictionary``\ 的一些高阶用法在基础语法场景下是不支持的,需要在JIT语法支持级别选项\ ``jit_syntax_level``\ 为\ ``LAX``\ 时才支持,更多请参考本文的\ `扩展语法(LAX级别) <#扩展语法lax级别>`_\ 章节。 + +5. 对标Python的内置函数,在基础语法场景下,除去当前图模式下支持的\ `Python内置函数 `_\ ,仍存在部分内置函数在图模式下是不支持的,例如:basestring、bin、bytearray、callable、chr、cmp、compile、 + delattr、dir、divmod、eval、execfile、file、frozenset、hash、hex、id、input、issubclass、iter、locals、long、memoryview、next、object、oct、open、ord、property、raw_input、reduce、reload、repr、reverse、set、slice、sorted、unichr、unicode、vars、xrange、\__import\_\_。 + +6. Python提供了很多第三方库,通常需要通过import语句调用。在图模式下JIT语法支持级别为STRICT时,不能直接使用第三方库。如果需要在图模式下使用第三方库的数据类型或者调用第三方库的方法,需要在JIT语法支持级别选项\ ``jit_syntax_level``\ 为\ ``LAX``\ 时才支持,更多请参考本文的\ `扩展语法(LAX级别) <#扩展语法lax级别>`_\ 中的\ `调用第三方库 <#调用第三方库>`_\ 章节。 + +7. 在图模式下,不感知在图外对类的属性的修改,即图外对类的属性修改不会生效。例如: + + .. code:: python + + import mindspore as ms + from mindspore import nn, ops, Tensor, context + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.len = 1 + + def construct(self, inputs): + x = inputs + self.len + return x + + context.set_context(mode=ms.GRAPH_MODE) + inputs = 2 + net = Net() + print("out1:", net(inputs)) + net.len = 2 + print("out2:", net(inputs)) + + 输出的结果将不会发生变化: + + .. code:: text + + out1: 3 + out2: 3 + +扩展语法(LAX级别) +------------------- + +下面主要介绍当前扩展支持的静态图语法。 + +调用第三方库 +~~~~~~~~~~~~ + +- 第三方库 + + 1. Python内置模块和Python标准库。例如\ ``os``\ 、\ ``sys``\ 、\ ``math``\ 、\ ``time``\ 等模块。 + + 2. 第三方代码库。路径在Python安装目录的\ ``site-packages``\ 目录下,需要先安装后导入,例如\ ``NumPy``\ 、\ ``SciPy``\ 等。需要注意的是,\ ``mindyolo``\ 、\ ``mindflow``\ 等MindSpore套件不被视作第三方库,具体列表可以参考\ `parser `_\ 文件的 + ``_modules_from_mindspore`` 列表。 + + 3. 通过环境变量\ ``MS_JIT_IGNORE_MODULES``\ 指定的模块。与之相对的有环境变量\ ``MS_JIT_MODULES``\ ,具体使用方法请参考\ `环境变量 `_\ 。 + +- 支持第三方库的数据类型,允许调用和返回第三方库的对象。 + + 示例如下: + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + a = np.array([1, 2, 3]) + b = np.array([4, 5, 6]) + out = a + b + return out + + print(func()) + + 运行结果如下: + + .. code:: text + + [5 7 9] + +- 支持调用第三方库的方法。 + + 示例如下: + + .. code:: python + + from scipy import linalg + import mindspore as ms + + @ms.jit + def func(): + x = [[1, 2], [3, 4]] + return linalg.qr(x) + + out = func() + print(out[0].shape) + + 运行结果如下: + + .. code:: text + + (2, 2) + +- 支持使用NumPy第三方库数据类型创建Tensor对象。 + + 示例如下: + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + x = np.array([1, 2, 3]) + out = ms.Tensor(x) + 1 + return out + + print(func()) + + 运行结果如下: + + .. code:: text + + [2 3 4] + +- 暂不支持对第三方库数据类型的下标索引赋值。 + + 示例如下: + + .. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + x = np.array([1, 2, 3]) + x[0] += 1 + return ms.Tensor(x) + + res = func() + print("res: ", res) + + 报错信息如下: + + .. code:: text + + RuntimeError: For operation 'setitem', current input arguments types + are . The 1-th argument type 'External' is + not supported now. + +支持自定义类的使用 +~~~~~~~~~~~~~~~~~~ + +支持在图模式下使用用户自定义的类,可以对类进行实例化,使用对象的属性及方法。 + +例如下面的例子,其中\ ``GetattrClass``\ 是用户自定义的类,没有使用\ ``@jit_class``\ 修饰,也没有继承\ ``nn.Cell``\ 。 + +.. code:: python + + import mindspore as ms + + ms.set_context(mode=ms.GRAPH_MODE) + + class GetattrClass(): + def __init__(self): + self.attr1 = 99 + self.attr2 = 1 + + def method1(self, x): + return x + self.attr2 + + class GetattrClassNet(ms.nn.Cell): + def __init__(self): + super(GetattrClassNet, self).__init__() + self.cls = GetattrClass() + + def construct(self): + return self.cls.method1(self.cls.attr1) + + net = GetattrClassNet() + out = net() + assert out == 100 + +基础运算符支持更多数据类型 +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +在静态图语法重载了以下运算符: ['+', '-', +'\*','/','//','%','\*\*','<<','>>','&','\|','^', 'not', '==', '!=', '<', +'>', '<=', '>=', 'in', 'not in', +'y=x[0]']。图模式重载的运算符详见\ `运算符 `_\ 。列表中的运算符在输入图模式中不支持的输入类型时将使用扩展静态图语法支持,并使输出结果与动态图模式下的输出结果一致。 + +代码用例如下。 + +.. code:: python + + import mindspore as ms + import mindspore.nn as nn + from mindspore import Tensor + ms.set_context(mode=ms.GRAPH_MODE) + + class InnerClass(nn.Cell): + def construct(self, x, y): + return x.asnumpy() + y.asnumpy() + + net = InnerClass() + ret = net(Tensor([4, 5]), Tensor([1, 2])) + print(ret) + +运行结果如下: + +.. code:: text + + [5 7] + +上述例子中,\ ``.asnumpy()``\ 输出的数据类型: +``numpy.ndarray``\ 为运算符\ ``+``\ 在图模式中不支持的输入类型。因此\ ``x.asnumpy() + y.asnumpy()``\ 将使用扩展语法支持。 + +在另一个用例中: + +.. code:: python + + class InnerClass(nn.Cell): + def construct(self): + return (None, 1) in ((None, 1), 1, 2, 3) + + net = InnerClass() + print(net()) + +运行结果如下: + +.. code:: text + + True + +``tuple`` in +``tuple``\ 在原本的图模式中是不支持的运算,现已使用扩展静态图语法支持。 + +基础类型 +~~~~~~~~ + +扩展对Python原生数据类型\ ``List``\ 、\ ``Dictionary``\ 、\ ``None``\ 的支持。 + +支持列表就地修改操作 +^^^^^^^^^^^^^^^^^^^^ + +列表\ ``List``\ 以及元组\ ``Tuple``\ 是Python中最基本的序列内置类型,\ ``List``\ 与\ ``Tuple``\ 最核心的区别是\ ``List``\ 是可以改变的对象,而\ ``Tuple``\ 是不可以更改的。这意味着\ ``Tuple``\ 一旦被创建,就不可以在对象地址不变的情况下更改。而\ ``List``\ 则可以通过一系列inplace操作,在不改变对象地址的情况下,对对象进行修改。例如: + +.. code:: python + + a = [1, 2, 3, 4] + a_id = id(a) + a.append(5) + a_after_id = id(a) + assert a_id == a_after_id + +上述示例代码中,通过\ ``append``\ 这个inplace语法更改\ ``List``\ 对象的时候,其对象的地址并没有被修改。而\ ``Tuple``\ 是不支持这种inplace操作的。在\ ``JIT_SYNTAX_LEVEL``\ 设置为\ ``LAX``\ 的情况下,静态图模式可以支持部分\ ``List``\ 对象的inplace操作。 + +具体使用场景如下: + +- 支持从全局变量中获取原\ ``List``\ 对象。 + + 在下面示例中,静态图获取到\ ``List``\ 对象,并在原有对象上进行了图模式支持的inplace操作\ ``list.reverse()``, + 并将原有对象返回。可以看到图模式返回的对象与原有的全局变量对象id相同,即两者为同一对象。若\ ``JIT_SYNTAX_LEVEL``\ 设置为\ ``STRICT``\ 选项,则返回的\ ``List``\ 对象与全局对象为两个不同的对象。 + + .. code:: python + + import mindspore as ms + + global_list = [1, 2, 3, 4] + + @ms.jit + def list_func(): + global_list.reverse() + return global_list + + output = list_func() # output: [4, 3, 2, 1] + assert id(global_list) == id(output) + +- 不支持对输入\ ``List``\ 对象进行inplace操作。 + + ``List``\ 作为静态图输入时,会对该\ ``List``\ 对象进行一次复制,并使用该复制对象进行后续的计算,因此无法对原输入对象进行inplace操作。例如: + + .. code:: python + + import mindspore as ms + + list_input = [1, 2, 3, 4] + + @ms.jit + def list_func(x): + x.reverse() + return x + + output = list_func(list_input) # output: [4, 3, 2, 1] list_input: [1, 2, 3, 4] + assert id(output) != id(list_input) + + 如上述用例所示,\ ``List``\ 对象作为图模式输入时无法在原有对象上进行inplace操作。图模式返回的对象与输入的对象id不同,为不同对象。 + +- 支持部分\ ``List``\ 内置函数的就地修改操作。 + + 在\ ``JIT_SYNTAX_LEVEL``\ 设置为\ ``LAX``\ 的情况下,图模式部分\ ``List``\ 内置函数支持inplace。在 + ``JIT_SYNTAX_LEVEL``\ 为 ``STRICT`` + 的情况下,所有方法均不支持inplace操作。 + + 目前,图模式支持的\ ``List``\ 就地修改内置方法有\ ``extend``\ 、\ ``pop``\ 、\ ``reverse``\ 以及\ ``insert``\ 。内置方法\ ``append``\ 、\ ``clear``\ 以及索引赋值暂不支持就地修改,后续版本将会支持。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + list_input = [1, 2, 3, 4] + + @ms.jit + def list_func(): + list_input.reverse() + return list_input + + output = list_func() # output: [4, 3, 2, 1] list_input: [4, 3, 2, 1] + assert id(output) == id(list_input) + +支持Dictionary的高阶用法 +^^^^^^^^^^^^^^^^^^^^^^^^ + +- 支持顶图返回Dictionary。 + + 示例如下: + + .. code:: python + + import mindspore as ms + + @ms.jit() + def test_dict(): + x = {'a': 'a', 'b': 'b'} + y = x.get('a') + z = dict(y=y) + return z + + out = test_dict() + print("out:", out) + + 运行结果如下: + + .. code:: text + + out: {'y': 'a'} + +- 支持Dictionary索引取值和赋值。 + + 示例如下: + + .. code:: python + + import mindspore as ms + import numpy as np + + x = {"a": ms.Tensor(np.array([1, 2, 3])), "b": ms.Tensor(np.array([4, 5, 6])), "c": ms.Tensor(np.array([7, 8, 9]))} + + @ms.jit() + def test_dict(): + y = x["b"] + x["a"] = (2, 3, 4) + return x, y + + out1, out2 = test_dict() + print('out1:{}'.format(out1)) + print('out2:{}'.format(out2)) + + 运行结果如下: + + .. code:: text + + out1:{'a': (2, 3, 4), 'b': Tensor(shape=[3], dtype=Int64, value= [4, 5, 6]), 'c': Tensor(shape=[3], dtype=Int64, value= [7, 8, 9])} + out2:[4 5 6] + +支持使用None +^^^^^^^^^^^^ + +``None``\ 是Python中的一个特殊值,表示空,可以赋值给任何变量。对于没有返回值语句的函数认为返回\ ``None``\ 。同时也支持\ ``None``\ 作为顶图或者子图的入参或者返回值。支持\ ``None``\ 作为切片的下标,作为\ ``List``\ 、\ ``Tuple``\ 、\ ``Dictionary``\ 的输入。 + +示例如下: + +.. code:: python + + import mindspore as ms + + @ms.jit + def test_return_none(): + return 1, "a", None + + res = test_return_none() + print(res) + +运行结果如下: + +.. code:: text + + (1, 'a', None) + +对于没有返回值的函数,默认返回\ ``None``\ 对象。 + +.. code:: python + + import mindspore as ms + + @ms.jit + def foo(): + x = 3 + print("x:", x) + + res = foo() + assert res is None + +运行结果如下: + +.. code:: text + + x: + 3 + +如下面例子,\ ``None``\ 作为顶图的默认入参。 + +.. code:: python + + import mindspore as ms + + @ms.jit + def foo(x, y=None): + if y is not None: + print("y:", y) + else: + print("y is None") + print("x:", x) + return y + + x = [1, 2] + res = foo(x) + assert res is None + +运行结果如下: + +.. code:: text + + y is None + x: + [1, 2] + +内置函数支持更多数据类型 +~~~~~~~~~~~~~~~~~~~~~~~~ + +扩展内置函数的支持范围。Python内置函数完善支持更多输入类型,例如第三方库数据类型。 + +例如下面的例子,\ ``x.asnumpy()``\ 和\ ``np.ndarray``\ 均是扩展支持的类型。更多内置函数的支持情况可见\ `Python内置函数 `_\ 章节。 + +.. code:: python + + import numpy as np + import mindspore as ms + import mindspore.nn as nn + + ms.set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def construct(self, x): + return isinstance(x.asnumpy(), np.ndarray) + + x = ms.Tensor(np.array([-1, 2, 4])) + net = Net() + out = net(x) + assert out + +支持控制流 +~~~~~~~~~~ + +为了提高Python标准语法支持度,实现动静统一,扩展支持更多数据类型在控制流语句的使用。控制流语句是指\ ``if``\ 、\ ``for``\ 、\ ``while``\ 等流程控制语句。理论上,通过扩展支持的语法,在控制流场景中也支持。代码用例如下: + +.. code:: python + + import numpy as np + import mindspore as ms + + @ms.jit + def func(): + x = np.array(1) + if x <= 1: + x += 1 + return ms.Tensor(x) + + res = func() + print("res: ", res) + +运行结果如下: + +.. code:: text + + res: 2 + +支持属性设置与修改 +~~~~~~~~~~~~~~~~~~ + +具体使用场景如下: + +- 对自定义类对象以及第三方类型的属性进行设置与修改。 + + 图模式下支持对自定义类对象的属性进行设置与修改,例如: + + .. code:: python + + from mindspore import jit + + class AssignClass(): + def __init__(self): + self.x = 1 + + obj = AssignClass() + + @jit + def foo(): + obj.x = 100 + + foo() + print(f"obj.x is: {obj.x}") + + 运行结果如下: + + .. code:: text + + obj.x is: 100 + + 图模式下支持对第三方库对象的属性进行设置与修改,例如: + + .. code:: python + + from mindspore import jit + import numpy as np + + @jit + def foo(): + a = np.array([1, 2, 3, 4]) + a.shape = (2, 2) + return a.shape + + shape = foo() + print(f"shape is {shape}") + + 运行结果如下: + + .. code:: text + + shape is (2, 2) + +- 对Cell的self对象进行修改,例如: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.m = 2 + + def construct(self): + self.m = 3 + return 0 + + net = Net() + net() + print(f"net.m is {net.m}") + + 运行结果如下: + + .. code:: text + + net.m is 3 + + 注意,self对象支持属性修改和设置。若\ ``__init__``\ 内没有定义某个属性,对齐PYNATIVE模式,图模式也允许设置此属性。例如: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context + set_context(mode=ms.GRAPH_MODE) + + class Net(nn.Cell): + def __init__(self): + super().__init__() + self.m = 2 + + def construct(self): + self.m2 = 3 + return 0 + + net = Net() + net() + print(f"net.m2 is {net.m2}") + + 运行结果如下: + + .. code:: text + + net.m2 is 3 + +- 对静态图内的Cell对象以及jit_class对象进行设置与修改。 + + 支持对图模式jit_class对象进行属性修改,例如: + + .. code:: python + + import mindspore as ms + from mindspore import nn, set_context, jit_class + set_context(mode=ms.GRAPH_MODE) + + @jit_class + class InnerClass(): + def __init__(self): + self.x = 10 + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.inner = InnerClass() + + def construct(self): + self.inner.x = 100 + return 0 + + net = Net() + net() + print(f"net.inner.x is {net.inner.x}") + + 运行结果如下: + + .. code:: text + + net.inner.x is 100 + +支持求导 +~~~~~~~~ + +扩展支持的静态图语法,同样支持其在求导中使用,例如: + +.. code:: python + + import mindspore as ms + from mindspore import ops, set_context + set_context(mode=ms.GRAPH_MODE) + + @ms.jit + def dict_net(a): + x = {'a': a, 'b': 2} + return a, (x, (1, 2)) + + out = ops.grad(dict_net)(ms.Tensor([1])) + assert out == 2 + +Annotation Type +~~~~~~~~~~~~~~~ + +对于运行时的扩展支持的语法,会产生一些无法被类型推导出的节点,比如动态创建Tensor等。这种类型称为\ ``Any``\ 类型。因为该类型无法在编译时推导出正确的类型,所以这种\ ``Any``\ 将会以一种默认最大精度\ ``float64``\ 进行运算,防止其精度丢失。为了能更好的优化相关性能,需要减少\ ``Any``\ 类型数据的产生。当用户可以明确知道当前通过扩展支持的语句会产生具体类型的时候,我们推荐使用\ ``Annotation @jit.typing:``\ 的方式进行指定对应Python语句类型,从而确定解释节点的类型避免\ ``Any``\ 类型的生成。 + +例如,\ `Tensor `_\ 类和\ `tensor `_\ 接口的区别就在于在\ ``tensor``\ 接口内部运用了Annotation +Type机制。当\ ``tensor``\ 函数的\ ``dtype``\ 确定时,函数内部会利用\ ``Annotation``\ 指定输出类型从而避免\ ``Any``\ 类型的产生。\ ``Annotation Type``\ 的使用只需要在对应Python语句上面或者后面加上注释 +``# @jit.typing: () -> tensor_type[float32]`` 即可,其中 ``->`` 后面的 +``tensor_type[float32]`` 指示了被注释的语句输出类型。 + +代码用例如下。 + +.. code:: python + + import mindspore as ms + import mindspore.nn as nn + from mindspore import ops, Tensor + + class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.abs = ops.Abs() + + @ms.jit + def construct(self, x, y): + y1 = ms.tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) + y2 = ms.Tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) # @jit.typing: () -> tensor_type[float32] + y3 = Tensor(x.asnumpy() + y.asnumpy()) + y4 = Tensor(x.asnumpy() + y.asnumpy(), dtype=ms.float32) + return self.abs(y1), self.abs(y2), self.abs(y3), self.abs(y4) + + ms.set_context(mode=ms.GRAPH_MODE) + net = Net() + x = ms.Tensor(-1, dtype=ms.int32) + y = ms.Tensor(-1, dtype=ms.float32) + y1, y2, y3, y4 = net(x, y) + + print(f"y1 value is {y1}, dtype is {y1.dtype}") + print(f"y2 value is {y2}, dtype is {y2.dtype}") + print(f"y3 value is {y3}, dtype is {y3.dtype}") + print(f"y4 value is {y4}, dtype is {y4.dtype}") + +运行结果如下: + +.. code:: text + + y1 value is 2.0, dtype is Float32 + y2 value is 2.0, dtype is Float32 + y3 value is 2.0, dtype is Float64 + y4 value is 2.0, dtype is Float32 + +上述例子,可以看到创建了\ ``Tensor``\ 的相关区别。对于\ ``y3``\ 、\ ``y4``\ ,因为\ ``Tensor``\ 类没有增加\ ``Annotation``\ 指示,\ ``y3``\ 、\ ``y4``\ 没有办法推出正确的类型,导致只能按照最高精度\ ``float64``\ 进行运算。 +对于\ ``y2``\ ,由于创建\ ``Tensor``\ 时,通过\ ``Annotation``\ 指定了对应类型,使得其类型可以按照指定类型进行运算。 +对于\ ``y1``\ ,由于使用了\ ``tensor``\ 函数接口创建\ ``Tensor``\ ,传入的\ ``dtype``\ 参数作为\ ``Annotation``\ 的指定类型,所以也避免了\ ``Any``\ 类型的产生。 + +扩展语法的语法约束 +------------------ + +在使用静态图扩展支持语法时,请注意以下几点: + +1. 对标动态图的支持能力,即:须在动态图语法范围内,包括但不限于数据类型等。 + +2. 在扩展静态图语法时,支持了更多的语法,但执行性能可能会受影响,不是最佳。 + +3. 在扩展静态图语法时,支持了更多的语法,由于使用Python的能力,不能使用MindIR导入导出的能力。 + +4. 暂不支持跨Python文件重复定义同名的全局变量,且这些全局变量在网络中会被用到。 \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/note/static_graph_syntax/operators.md b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/operators.md similarity index 99% rename from docs/mindspore/source_zh_cn/note/static_graph_syntax/operators.md rename to docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/operators.md index 16b173d1a0fb9ba62265f8e935657e2ade883d0e..99c8d6dae805fc6c37a2d723538c4795d7293b13 100644 --- a/docs/mindspore/source_zh_cn/note/static_graph_syntax/operators.md +++ b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/operators.md @@ -1,6 +1,6 @@ # 静态图语法-运算符 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/static_graph_syntax/operators.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/operators.md) 算术运算符和赋值运算符支持`Number`和`Tensor`运算,也支持不同`dtype`的`Tensor`运算。 diff --git a/docs/mindspore/source_zh_cn/note/static_graph_syntax/python_builtin_functions.ipynb b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/python_builtin_functions.ipynb similarity index 96% rename from docs/mindspore/source_zh_cn/note/static_graph_syntax/python_builtin_functions.ipynb rename to docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/python_builtin_functions.ipynb index 7472ffe630af3aeee0b60dcec03abbb312175e91..0514985329152fe3f690807983ead130d32698b4 100644 --- a/docs/mindspore/source_zh_cn/note/static_graph_syntax/python_builtin_functions.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/python_builtin_functions.ipynb @@ -7,7 +7,7 @@ "source": [ "# 静态图语法-Python内置函数\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/static_graph_syntax/mindspore_python_builtin_functions.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/static_graph_syntax/mindspore_python_builtin_functions.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/static_graph_syntax/python_builtin_functions.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_python_builtin_functions.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_python_builtin_functions.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/python_builtin_functions.ipynb)\n", "\n", "当前静态图模式支持的Python内置函数包括:`int`、`float`、`bool`、`str`、`tuple`、`list`、`dict`、`getattr`、`hasattr`、`len`、`isinstance`、`all`、`any`、`round`、`max`、`min`、`sum`、`abs`、`map`、`zip`、`range`、`enumerate`、`super`、`pow`、`print`、`filter`、`type`。图模式下内置函数的使用方法与对应的Python内置函数类似。\n", "\n", @@ -466,7 +466,7 @@ "source": [ "在静态图模式下对象的属性可能会和动态图模式下有区别,建议使用`default`输入,或者在使用`getattr`前先使用`hasattr`进行校验。\n", "\n", - "其中`getattr(x.asnumpy(), \"shape\", np.array([0, 1, 2, 3, 4]))`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#扩展语法lax级别)章节。\n", + "其中`getattr(x.asnumpy(), \"shape\", np.array([0, 1, 2, 3, 4]))`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#扩展语法lax级别-3)章节。\n", "\n", "## hasattr\n", "\n", @@ -531,7 +531,7 @@ "id": "d250cfe9", "metadata": {}, "source": [ - "其中`hasattr(Tensor(np.array([1, 2, 3, 4])).asnumpy(), \"__len__\")`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#扩展语法lax级别)章节。\n", + "其中`hasattr(Tensor(np.array([1, 2, 3, 4])).asnumpy(), \"__len__\")`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#扩展语法lax级别-3)章节。\n", "\n", "## len\n", "\n", @@ -600,7 +600,7 @@ "id": "e7cfebfe", "metadata": {}, "source": [ - "其中`len(w.asnumpy())`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#扩展语法lax级别)章节。\n", + "其中`len(w.asnumpy())`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#扩展语法lax级别-3)章节。\n", "\n", "## isinstance\n", "\n", @@ -665,7 +665,7 @@ "id": "abbdad59", "metadata": {}, "source": [ - "其中`isinstance(w.asnumpy(), np.ndarray)`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#扩展语法lax级别)章节。\n", + "其中`isinstance(w.asnumpy(), np.ndarray)`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#扩展语法lax级别-3)章节。\n", "\n", "## all\n", "\n", @@ -738,7 +738,7 @@ "id": "c584d3aa", "metadata": {}, "source": [ - "其中`all(x.asnumpy())`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#扩展语法lax级别)章节。\n", + "其中`all(x.asnumpy())`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#扩展语法lax级别-3)章节。\n", "\n", "## any\n", "\n", @@ -1122,7 +1122,7 @@ "id": "bd2880eb", "metadata": {}, "source": [ - "其中`abs(Tensor([-1, 2]).asnumpy())`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#扩展语法lax级别)章节。\n", + "其中`abs(Tensor([-1, 2]).asnumpy())`属于高阶用法,更多介绍可见[扩展语法(LAX级别)](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#扩展语法lax级别-3)章节。\n", "\n", "## map\n", "\n", diff --git a/docs/mindspore/source_zh_cn/note/static_graph_syntax/statements.ipynb b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/statements.ipynb similarity index 96% rename from docs/mindspore/source_zh_cn/note/static_graph_syntax/statements.ipynb rename to docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/statements.ipynb index 9752da6c601650e9d7d34a575d8cb4ab2be2b7c5..241996a08a8dff6db048230fcd27ad676985355f 100644 --- a/docs/mindspore/source_zh_cn/note/static_graph_syntax/statements.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/statements.ipynb @@ -7,7 +7,7 @@ "source": [ "# 静态图语法-Python语句\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/static_graph_syntax/mindspore_statements.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/static_graph_syntax/mindspore_statements.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/static_graph_syntax/statements.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_statements.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_statements.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/statements.ipynb)\n", "\n", "## 简单语句\n", "\n", @@ -1002,7 +1002,7 @@ "\n", "在图模式下,有限制地支持`with`语句。`with`语句要求对象必须有两个魔术方法:`__enter__()`和`__exit__()`。\n", "\n", - "值得注意的是with语句中使用的类需要有装饰器@ms.jit_class修饰或者继承于nn.Cell,更多介绍可见[使用jit_class](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/static_graph_expert_programming.html#使用jit-class)。\n", + "值得注意的是with语句中使用的类需要有装饰器@ms.jit_class修饰或者继承于nn.Cell,更多介绍可见[使用jit_class](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/static_graph_expert_programming.html#使用jit-class)。\n", "\n", "示例如下:" ] diff --git a/tutorials/source_zh_cn/advanced/static_graph_expert_programming.ipynb b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_expert_programming.ipynb similarity index 96% rename from tutorials/source_zh_cn/advanced/static_graph_expert_programming.ipynb rename to docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_expert_programming.ipynb index 6e23aa772c6cac82d3d135004fab52f4da15d9ae..ff78270f9605e86cfa3f61e9fc19576b62af9387 100644 --- a/tutorials/source_zh_cn/advanced/static_graph_expert_programming.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_expert_programming.ipynb @@ -7,9 +7,9 @@ "source": [ "# 静态图高级编程技巧\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/mindspore_static_graph_expert_programming.ipynb) \n", - "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/mindspore_static_graph_expert_programming.py) \n", - "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/static_graph_expert_programming.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_static_graph_expert_programming.ipynb) \n", + "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_static_graph_expert_programming.py) \n", + "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_expert_programming.ipynb)\n", "\n", "本篇章介绍一些常用的静态图优化的高级编程技巧,这些技巧能够有效地提高静态图的编译效率以及执行效率,并使程序运行地更加稳定。有关静态图编译的基础介绍,请见[使用静态图加速](https://www.mindspore.cn/tutorials/zh-CN/master/beginner/accelerate_with_static_graph.html)。\n", "\n", @@ -377,6 +377,20 @@ "```text\n", "Enable comile_cache cost time: 0.6357541084289551\n", "Enable comile_cache cost time: 0.09379792213439941\n", + "```\n", + "\n", + "可以看到,开启编译缓存时,第2次执行样例耗时只有第一次执行耗时的1/7左右。\n", + "\n", + "说明:打开编译缓存功能时,第一次执行由于暂未生成缓存,所以会有 Warning:" + ] + }, + { + "cell_type": "markdown", + "id": "81569f5f", + "metadata": {}, + "source": [ + "```text\n", + "Warning: Check the consistency of dependency files hash failed. Execute all the compilation actions.\n", "```" ] }, @@ -385,8 +399,6 @@ "id": "b5655959", "metadata": {}, "source": [ - "可以看到,开启编译缓存时,第2次执行样例耗时只有第一次执行耗时的1/7左右。\n", - "\n", "## 如何优化执行性能\n", "\n", "### 使用jit_class\n", @@ -403,7 +415,7 @@ "\n", "- 自定义类\n", "\n", - " 定义自定义类后,可以对类进行实例化、调用类对象的属性和方法,请参考[自定义类的使用](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax_support.html#支持自定义类的使用)。相比于`Cell`的类定义,自定义类更贴近用户调用Python类的使用习惯。自定义类在静态图模式下的实现方式与`Cell`不同,例如,调用自定义类对象的函数方法时,其函数方法中的代码不会被编译成静态计算图,而是通过Python解释器进行解释执行。\n", + " 定义自定义类后,可以对类进行实例化、调用类对象的属性和方法,请参考[自定义类的使用](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph.html#支持自定义类的使用)。相比于`Cell`的类定义,自定义类更贴近用户调用Python类的使用习惯。自定义类在静态图模式下的实现方式与`Cell`不同,例如,调用自定义类对象的函数方法时,其函数方法中的代码不会被编译成静态计算图,而是通过Python解释器进行解释执行。\n", "\n", "- `@jit_class`修饰的类\n", "\n", @@ -828,7 +840,7 @@ "\n", "使用场景:在处理无依赖关系的批量数据且相关的算子支持Vmap功能时,可以使用Vmap替代for循环处理批量数据来优化执行性能(也可以提高编译性能)。\n", "\n", - "MindSpore已支持Vmap特性,Vmap的详细介绍可参考[自动向量化Vmap](https://www.mindspore.cn/tutorials/experts/zh-CN/master/vmap/vmap.html)。\n", + "MindSpore已支持Vmap特性,Vmap的详细介绍可参考[自动向量化Vmap](https://www.mindspore.cn/docs/zh-CN/master/model_train/train_process/func_programming/vmap.html)。\n", "\n", "一个使用Vmap替换for循环处理批量数据来优化编译性能的代码样例如下:\n", "\n", diff --git a/docs/mindspore/source_zh_cn/note/static_graph_syntax_support.ipynb b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_syntax_support.ipynb similarity index 97% rename from docs/mindspore/source_zh_cn/note/static_graph_syntax_support.ipynb rename to docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_syntax_support.ipynb index eead82dd905a9cfaceaa4d4c2d78433fb86a2091..5ea7ed158d83f9e14c4d1eb056ef2143ba836a14 100644 --- a/docs/mindspore/source_zh_cn/note/static_graph_syntax_support.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_syntax_support.ipynb @@ -7,7 +7,7 @@ "source": [ "# 静态图语法支持\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/mindspore_static_graph_syntax_support.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/note/mindspore_static_graph_syntax_support.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/static_graph_syntax_support.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_static_graph_syntax_support.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/program_form/static_graph_syntax/mindspore_static_graph_syntax_support.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/program_form/static_graph_syntax/static_graph_syntax_support.ipynb)\n", "\n", "## 概述\n", "\n", @@ -1176,7 +1176,7 @@ "\n", "### 运算符\n", "\n", - "算术运算符和赋值运算符支持`Number`和`Tensor`运算,也支持不同`dtype`的`Tensor`运算。详见[运算符](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/operators.html)。\n", + "算术运算符和赋值运算符支持`Number`和`Tensor`运算,也支持不同`dtype`的`Tensor`运算。详见[运算符](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/operators.html)。\n", "\n", "### 原型\n", "\n", @@ -1248,7 +1248,7 @@ "\n", "`Dictionary`的索引取值请参考本文的[Dictionary](#dictionary)章节。\n", "\n", - "`Tensor`的索引取详见[Tensor 索引取值文档](https://www.mindspore.cn/docs/zh-CN/master/note/index_support.html#索引取值)。\n", + "`Tensor`的索引取详见[Tensor 索引取值文档](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/index_support.html#索引取值)。\n", "\n", "#### 调用\n", "\n", @@ -1301,11 +1301,11 @@ "source": [ "### 语句\n", "\n", - "当前静态图模式支持部分Python语句,包括raise语句、assert语句、pass语句、return语句、break语句、continue语句、if语句、for语句、while语句、with语句、列表生成式、生成器表达式、函数定义语句等,详见[Python语句](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/statements.html)。\n", + "当前静态图模式支持部分Python语句,包括raise语句、assert语句、pass语句、return语句、break语句、continue语句、if语句、for语句、while语句、with语句、列表生成式、生成器表达式、函数定义语句等,详见[Python语句](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/statements.html)。\n", "\n", "### Python内置函数\n", "\n", - "当前静态图模式支持部分Python内置函数,其使用方法与对应的Python内置函数类似,详见[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/python_builtin_functions.html)。\n", + "当前静态图模式支持部分Python内置函数,其使用方法与对应的Python内置函数类似,详见[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/python_builtin_functions.html)。\n", "\n", "### 网络定义\n", "\n", @@ -1462,7 +1462,7 @@ "source": [ "4. 对标Python内置数据类型,除去当前图模式下支持的[Python内置数据类型](#python内置数据类型),复数`complex`和集合`set`类型是不支持的。列表`list`和字典`dictionary`的一些高阶用法在基础语法场景下是不支持的,需要在JIT语法支持级别选项`jit_syntax_level`为`LAX`时才支持,更多请参考本文的[扩展语法(LAX级别)](#扩展语法lax级别)章节。\n", "\n", - "5. 对标Python的内置函数,在基础语法场景下,除去当前图模式下支持的[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/python_builtin_functions.html),仍存在部分内置函数在图模式下是不支持的,例如:basestring、bin、bytearray、callable、chr、cmp、compile、 delattr、dir、divmod、eval、execfile、file、frozenset、hash、hex、id、input、issubclass、iter、locals、long、memoryview、next、object、oct、open、ord、property、raw_input、reduce、reload、repr、reverse、set、slice、sorted、unichr、unicode、vars、xrange、\\_\\_import\\_\\_。\n", + "5. 对标Python的内置函数,在基础语法场景下,除去当前图模式下支持的[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/python_builtin_functions.html),仍存在部分内置函数在图模式下是不支持的,例如:basestring、bin、bytearray、callable、chr、cmp、compile、 delattr、dir、divmod、eval、execfile、file、frozenset、hash、hex、id、input、issubclass、iter、locals、long、memoryview、next、object、oct、open、ord、property、raw_input、reduce、reload、repr、reverse、set、slice、sorted、unichr、unicode、vars、xrange、\\_\\_import\\_\\_。\n", "\n", "6. Python提供了很多第三方库,通常需要通过import语句调用。在图模式下JIT语法支持级别为STRICT时,不能直接使用第三方库。如果需要在图模式下使用第三方库的数据类型或者调用第三方库的方法,需要在JIT语法支持级别选项`jit_syntax_level`为`LAX`时才支持,更多请参考本文的[扩展语法(LAX级别)](#扩展语法lax级别)中的[调用第三方库](#调用第三方库)章节。\n", "\n", @@ -1713,7 +1713,7 @@ "source": [ "### 基础运算符支持更多数据类型\n", "\n", - "在静态图语法重载了以下运算符: ['+', '-', '*', '/', '//', '%', '**', '<<', '>>', '&', '|', '^', 'not', '==', '!=', '<', '>', '<=', '>=', 'in', 'not in', 'y=x[0]']。图模式重载的运算符详见[运算符](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/operators.html)。列表中的运算符在输入图模式中不支持的输入类型时将使用扩展静态图语法支持,并使输出结果与动态图模式下的输出结果一致。\n", + "在静态图语法重载了以下运算符: ['+', '-', '*', '/', '//', '%', '**', '<<', '>>', '&', '|', '^', 'not', '==', '!=', '<', '>', '<=', '>=', 'in', 'not in', 'y=x[0]']。图模式重载的运算符详见[运算符](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/operators.html)。列表中的运算符在输入图模式中不支持的输入类型时将使用扩展静态图语法支持,并使输出结果与动态图模式下的输出结果一致。\n", "\n", "代码用例如下。" ] @@ -2104,7 +2104,7 @@ "\n", "扩展内置函数的支持范围。Python内置函数完善支持更多输入类型,例如第三方库数据类型。\n", "\n", - "例如下面的例子,`x.asnumpy()`和`np.ndarray`均是扩展支持的类型。更多内置函数的支持情况可见[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/note/static_graph_syntax/python_builtin_functions.html)章节。" + "例如下面的例子,`x.asnumpy()`和`np.ndarray`均是扩展支持的类型。更多内置函数的支持情况可见[Python内置函数](https://www.mindspore.cn/docs/zh-CN/master/model_train/program_form/static_graph_syntax/python_builtin_functions.html)章节。" ] }, { diff --git a/docs/mindspore/source_zh_cn/model_train/train_process/algorithm_optimize.rst b/docs/mindspore/source_zh_cn/model_train/train_process/algorithm_optimize.rst new file mode 100644 index 0000000000000000000000000000000000000000..9159f04a79a94b715a8eb0767c1f340747000b06 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/train_process/algorithm_optimize.rst @@ -0,0 +1,8 @@ +高阶训练策略 +============== + +.. toctree:: + :maxdepth: 1 + + optimize/gradient_accumulation + optimize/thor \ No newline at end of file diff --git a/tutorials/source_zh_cn/advanced/derivation.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/derivation.ipynb similarity index 98% rename from tutorials/source_zh_cn/advanced/derivation.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/derivation.ipynb index d7bace6d3d6266c5c27985a7447e952e99e9c10f..65de0de7f0cb057bc7fbbb28b4dba7a22e4eac55 100644 --- a/tutorials/source_zh_cn/advanced/derivation.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/derivation.ipynb @@ -5,12 +5,12 @@ "id": "99803a48", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/mindspore_derivation.ipynb) \n", - "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/mindspore_derivation.py) \n", - "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/derivation.ipynb)\n", - "\n", "# 高级自动微分\n", "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/mindspore_derivation.ipynb) \n", + "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/mindspore_derivation.py) \n", + "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/derivation.ipynb)\n", + "\n", "`mindspore.ops`模块提供的`grad`和`value_and_grad`接口可以生成网络模型的梯度。`grad`计算网络梯度,`value_and_grad`同时计算网络的正向输出和梯度。本文主要介绍如何使用`grad`接口的主要功能,包括一阶、二阶求导,单独对输入或网络权重求导,返回辅助变量,以及如何停止计算梯度。\n", "\n", "> 更多求导接口相关信息可参考[API文档](https://mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.grad.html)。\n", diff --git a/docs/mindspore/source_zh_cn/model_train/train_process/dynamic_shape.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/dynamic_shape.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..9f986e9ea719d0657811dde57b12000721615fe8 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/train_process/dynamic_shape.ipynb @@ -0,0 +1,117 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "126f1b43", + "metadata": {}, + "source": [ + "# 动态shape指示配置\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/mindspore_dynamic_shape.ipynb) \n", + "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/mindspore_dynamic_shape.py) \n", + "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/dynamic_shape.ipynb)\n", + "\n", + "## 背景介绍\n", + "\n", + "动态shape是深度学习框架领域较为常见的一个研究课题,MindSpore针对动态shape也做了大量的探索与研究,并且基于研究成果初步支持了静态图模式下的动态shape能力。\n", + "\n", + "本文主要针对MindSpore静态图动态shape作说明介绍,后文中动态shape均泛指静态图动态shape。\n", + "动态shape需要解决的核心问题是输入数据尺寸变化时,如何做到一次编译多次执行。通过静态shape处理多尺寸数据与通过动态shape处理多尺寸数据的流程对比示意图如下:\n", + "\n", + "![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/static_dynamic_shape_diff.png)\n", + "\n", + "如上图所示,当输入多种尺寸的数据时,静态shape会对每一种输入尺寸都进行一次编译,而动态shape只需要编译一次,因此动态shape相比静态shape节省了大量的编译耗时,因此能提升网络端到端执行性能。\n", + "\n", + "## 符号引擎设计\n", + "\n", + "虽然动态shape弥补了静态shape多次编译的不足,但是也带来了执行性能下降、无法进行并行切分、无法进行内存复用优化等新的挑战。MindSpore通过支持符号引擎能力,继承了静态shape\n", + "场景下的大部分并行切分能力和算子融合能力,并通过虚拟内存实现了内存的深度优化,实现动态shape执行性能和内存效率达到静态shape的90%左右。\n", + "\n", + "动态shape通过符号shape来表达shape,例如存在两组输入数据为Tensor(shape=(8, 10))和Tensor(shape=(8, 100)),使用静态shape多次编译会产生Tensor(shape=(8, 10))\n", + "和Tensor(shape=(8, 100))两种IR,动态shape产生Tensor(shape=(8, Any))一种IR,Any表示axis为动态,通过符号引擎shape可进一步将动态shape IR表示\n", + "为Tensor(shape=(8, 10*s1))。符号shape通过符号运算来表达shape的推导过程,以实现在动态shape场景下用符号判断代替数值判断的能力。一次基于符号引擎推导动态shape的IR\n", + "的示例如下:\n", + "\n", + "![image](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/symbol_engine.png)\n", + "\n", + "如图,符号引擎将输入结点的shape标记为`s1`, `s2`等,在算子shape推导时,将输出shape存为基于输入shape的表达式。例如:对于`40Mul`结点,它的输出shape不再是Any,而是`max(s1,s2)`;到`104BatchMatMul`结点,基于矩阵乘的约束,可以直接设定`s4 == s6`;对于`112Add`结点,因为`s5`和`s7`都是大于1的值,可以断定此结点不存在广播场景,从而判断出`s5`与`s7`相等。通过符号shape引擎,动态shape也具备了一定的shape判断能力,框架可以在此基础上完成更多计算图优化功能。\n", + "\n", + "符号引擎的详细使用指导可参考[Symbol API文档](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.Symbol.html)。\n", + "\n", + "## 使用方法\n", + "\n", + "MindSpore通过set_inputs接口设置静态图输入Tensor对应的axis为动态,使能网络动态shape编译。\n", + "例如,对两个矩阵进行相加,矩阵的大小变化的,此时我们希望矩阵相加对应的计算逻辑只编译一次,输入不同尺寸的矩阵进行计算时可以复用同一次编译过程。\n", + "设置动态shape编译,如何指定对应axis为动态,可以使用符号引擎和set_inputs接口进行设置,mindspore.jit装饰器方式请使用input_signature参数进行设置。\n", + "下述样例是一个通过动态shape实现多个不同尺寸的矩阵自身相加的示例:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "928ddf6e", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import mindspore as ms\n", + "from mindspore import nn, Tensor, Symbol\n", + "\n", + "class Net(nn.Cell):\n", + " def construct(self, x):\n", + " return x + x\n", + "\n", + "ms.context.set_context(mode=ms.context.GRAPH_MODE)\n", + "net = Net()\n", + "width = Symbol()\n", + "height = Symbol()\n", + "dyn_t = Tensor(shape=(width, height), dtype=ms.float32)\n", + "# Set Tensor shape dynamic\n", + "net.set_inputs(dyn_t)\n", + "# Execute with shape=(2 ,3)\n", + "input_x1 = Tensor(np.random.randn(2, 3), dtype=ms.float32)\n", + "out = net(input_x1)\n", + "# Execute with shape=(4, 5)\n", + "input_x2 = Tensor(np.random.randn(4, 5), dtype=ms.float32)\n", + "out = net(input_x2)" + ] + }, + { + "cell_type": "markdown", + "id": "2f475487", + "metadata": {}, + "source": [ + "set_inputs详细使用指导可参考[Cell.set_inputs API文档](https://www.mindspore.cn/docs/zh-CN/master/api_python/nn/mindspore.nn.Cell.html#mindspore.nn.Cell.set_inputs)。\n", + "\n", + "input_signature详细使用指导可参考[mindspore.jit API文档](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.jit.html)。\n", + "\n", + "分布式并行场景如何使用动态shape可参考[分布式并行支持动态shape文档](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/support_dynamic_shape_in_parallel.html)。\n", + "\n", + "## 支持情况\n", + "\n", + "MindSpore在当前版本仅有部分API可以支持动态shape编译执行,正在持续完善全量API的支持能力,当前阶段[mindspore.mint](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.mint.html)接口支持动态shape。" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "MindSpore", + "language": "python", + "name": "mindspore" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/mindspore/source_zh_cn/model_train/train_process/func_programming.rst b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming.rst new file mode 100644 index 0000000000000000000000000000000000000000..ac308b949f975215b25dd1d48408c3e4ba856460 --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming.rst @@ -0,0 +1,9 @@ +高阶函数式编程 +============== + +.. toctree:: + :maxdepth: 1 + + func_programming/vmap + func_programming/Jacobians_Hessians + func_programming/per_sample_gradients diff --git a/tutorials/experts/source_zh_cn/func_programming/Jacobians_Hessians.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/Jacobians_Hessians.ipynb similarity index 96% rename from tutorials/experts/source_zh_cn/func_programming/Jacobians_Hessians.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/func_programming/Jacobians_Hessians.ipynb index db4465841af9993829b76ab11e7a9fa65a19cd6a..4e3ba83fa50837a0d1a0274ab8915c30f27869e4 100644 --- a/tutorials/experts/source_zh_cn/func_programming/Jacobians_Hessians.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/Jacobians_Hessians.ipynb @@ -6,7 +6,7 @@ "source": [ "# 使用函数变换计算雅可比矩阵和黑塞矩阵\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/func_programming/mindspore_Jacobians_Hessians.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/func_programming/mindspore_Jacobians_Hessians.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/func_programming/Jacobians_Hessians.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/func_programming/mindspore_Jacobians_Hessians.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/func_programming/mindspore_Jacobians_Hessians.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/Jacobians_Hessians.ipynb)\n", "\n" ] }, diff --git a/tutorials/experts/source_zh_cn/func_programming/per_sample_gradients.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/per_sample_gradients.ipynb similarity index 92% rename from tutorials/experts/source_zh_cn/func_programming/per_sample_gradients.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/func_programming/per_sample_gradients.ipynb index e0f73340b432229fa35bc0a8e5b858c52dfd9860..c6658a35ed1ac82ab233951dd14a80f003532ecd 100644 --- a/tutorials/experts/source_zh_cn/func_programming/per_sample_gradients.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/per_sample_gradients.ipynb @@ -6,7 +6,7 @@ "source": [ "# Per-sample-gradients\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/func_programming/mindspore_per_sample_gradients.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/func_programming/mindspore_per_sample_gradients.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/func_programming/per_sample_gradients.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/func_programming/mindspore_per_sample_gradients.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/func_programming/mindspore_per_sample_gradients.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/per_sample_gradients.ipynb)\n", "\n", "计算per-sample-gradients是指计算一个批量样本中每个样本的梯度。在训练神经网络时,很多深度学习框架会计算批量样本的梯度,并利用批量样本的梯度更新网络参数。per-sample-gradients可以帮助我们在训练神经网络时,更准确地计算每个样本对网络参数的影响,从而更好地提高模型的训练效果。\n" ] diff --git a/tutorials/experts/source_zh_cn/vmap/vmap.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/vmap.ipynb similarity index 98% rename from tutorials/experts/source_zh_cn/vmap/vmap.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/func_programming/vmap.ipynb index 2418d331600e12cfab7e4059a0ef4f16dc000685..a7b8a6e32ad580dfba466fa2a48036373fe1abf3 100644 --- a/tutorials/experts/source_zh_cn/vmap/vmap.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/vmap.ipynb @@ -6,7 +6,7 @@ "source": [ "# 自动向量化Vmap\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/vmap/mindspore_vmap.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/vmap/mindspore_vmap.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/vmap/vmap.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/func_programming/mindspore_vmap.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/func_programming/mindspore_vmap.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/func_programming/vmap.ipynb)\n", "\n", "## 概述\n", "\n", diff --git a/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/static_dynamic_shape_diff.png b/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/static_dynamic_shape_diff.png new file mode 100644 index 0000000000000000000000000000000000000000..4ab20b1afce03afc975103f5ea6c644c652711b8 Binary files /dev/null and b/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/static_dynamic_shape_diff.png differ diff --git a/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/symbol_engine.png b/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/symbol_engine.png new file mode 100644 index 0000000000000000000000000000000000000000..08bcf3c89beac699bacfdcdce7a812c3ba376daf Binary files /dev/null and b/docs/mindspore/source_zh_cn/model_train/train_process/images/dynamic_shape/symbol_engine.png differ diff --git a/tutorials/experts/source_zh_cn/optimize/images/image-data-sink.png b/docs/mindspore/source_zh_cn/model_train/train_process/images/image-data-sink.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/image-data-sink.png rename to docs/mindspore/source_zh_cn/model_train/train_process/images/image-data-sink.png diff --git a/tutorials/experts/source_zh_cn/optimize/images/image-graph-sink.png b/docs/mindspore/source_zh_cn/model_train/train_process/images/image-graph-sink.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/image-graph-sink.png rename to docs/mindspore/source_zh_cn/model_train/train_process/images/image-graph-sink.png diff --git a/tutorials/experts/source_zh_cn/optimize/images/image-loop-sink.png b/docs/mindspore/source_zh_cn/model_train/train_process/images/image-loop-sink.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/image-loop-sink.png rename to docs/mindspore/source_zh_cn/model_train/train_process/images/image-loop-sink.png diff --git a/tutorials/experts/source_zh_cn/optimize/images/image-user-view.png b/docs/mindspore/source_zh_cn/model_train/train_process/images/image-user-view.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/image-user-view.png rename to docs/mindspore/source_zh_cn/model_train/train_process/images/image-user-view.png diff --git a/tutorials/experts/source_zh_cn/optimize/images/image-without-sink.png b/docs/mindspore/source_zh_cn/model_train/train_process/images/image-without-sink.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/image-without-sink.png rename to docs/mindspore/source_zh_cn/model_train/train_process/images/image-without-sink.png diff --git a/tutorials/source_zh_cn/advanced/model.rst b/docs/mindspore/source_zh_cn/model_train/train_process/model.rst similarity index 95% rename from tutorials/source_zh_cn/advanced/model.rst rename to docs/mindspore/source_zh_cn/model_train/train_process/model.rst index 5cdb9119d5c7751324275b9df6d14f290e03cf13..f6356b374d853dd98f1b3cb4fa7422dc90b95e8b 100644 --- a/tutorials/source_zh_cn/advanced/model.rst +++ b/docs/mindspore/source_zh_cn/model_train/train_process/model.rst @@ -1,9 +1,9 @@ .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg - :target: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_model.ipynb + :target: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_model.ipynb .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg - :target: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_model.py + :target: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_model.py .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/model/model.ipynb + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/model/model.ipynb :alt: 查看源文件 高阶封装:Model @@ -24,7 +24,7 @@ 本文档首先对MindSpore的Model进行基本介绍,然后重点讲解如何使用\ ``Model``\ 进行模型训练、评估和推理。 -.. figure:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/model/images/model.png +.. figure:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/model/images/model.png :alt: model diff --git a/tutorials/source_zh_cn/advanced/model/callback.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/model/callback.ipynb similarity index 98% rename from tutorials/source_zh_cn/advanced/model/callback.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/model/callback.ipynb index 04048513de9e6e378eb4c7a05db5809ea2dfb8af..18cf3b8fbe0a71bf2b9ece19a3aee7ff8b83eeb4 100644 --- a/tutorials/source_zh_cn/advanced/model/callback.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/model/callback.ipynb @@ -5,9 +5,12 @@ "id": "f2df123f-eb9a-4816-8cef-2fa48f21cffd", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_callback.ipynb) \n", - "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_callback.py) \n", - "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/model/callback.ipynb)" + "# 回调机制 Callback\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_callback.ipynb) \n", + "[![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_callback.py) \n", + "[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/model/callback.ipynb)\n", + "\n" ] }, { @@ -15,8 +18,6 @@ "id": "7bcf904e", "metadata": {}, "source": [ - "# 回调机制 Callback\n", - "\n", "在深度学习训练过程中,为及时掌握网络模型的训练状态、实时观察网络模型各参数的变化情况和实现训练过程中用户自定义的一些操作,MindSpore提供了回调机制(Callback)来实现上述功能。\n", "\n", "Callback回调机制一般用在网络模型训练过程`Model.train`中,MindSpore的`Model`会按照Callback列表`callbacks`顺序执行回调函数,用户可以通过设置不同的回调类来实现在训练过程中或者训练后执行的功能。\n", diff --git a/tutorials/source_zh_cn/advanced/model/images/model.graffle b/docs/mindspore/source_zh_cn/model_train/train_process/model/images/model.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/model/images/model.graffle rename to docs/mindspore/source_zh_cn/model_train/train_process/model/images/model.graffle diff --git a/tutorials/source_zh_cn/advanced/model/images/model.png b/docs/mindspore/source_zh_cn/model_train/train_process/model/images/model.png similarity index 100% rename from tutorials/source_zh_cn/advanced/model/images/model.png rename to docs/mindspore/source_zh_cn/model_train/train_process/model/images/model.png diff --git a/tutorials/source_zh_cn/advanced/model/images/save.graffle b/docs/mindspore/source_zh_cn/model_train/train_process/model/images/save.graffle similarity index 100% rename from tutorials/source_zh_cn/advanced/model/images/save.graffle rename to docs/mindspore/source_zh_cn/model_train/train_process/model/images/save.graffle diff --git a/tutorials/source_zh_cn/advanced/model/metric.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/model/metric.ipynb similarity index 94% rename from tutorials/source_zh_cn/advanced/model/metric.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/model/metric.ipynb index 5753e3dfef24a111332ae8396bf9382e3cf492c6..e57387a7ecb4427499ae2d642e7601202e35e03d 100644 --- a/tutorials/source_zh_cn/advanced/model/metric.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/model/metric.ipynb @@ -4,15 +4,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_metric.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_metric.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/model/metric.ipynb)" + "# 评价指标 Metrics\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_metric.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_metric.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/model/metric.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# 评价指标 Metrics\n", - "\n", "当训练任务结束,常常需要评价函数(Metrics)来评估模型的好坏。不同的训练任务往往需要不同的Metrics函数。例如,对于二分类问题,常用的评价指标有precision(准确率)、recall(召回率)等,而对于多分类任务,可使用宏平均(Macro)和微平均(Micro)来评估。\n", "\n", "MindSpore提供了大部分常见任务的评价函数,如`Accuracy`、`Precision`、`MAE`和`MSE`等,由于MindSpore提供的评价函数无法满足所有任务的需求,很多情况下用户需要针对具体的任务自定义Metrics来评估训练的模型。\n", diff --git a/tutorials/source_zh_cn/advanced/model/model.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/model/model.ipynb similarity index 93% rename from tutorials/source_zh_cn/advanced/model/model.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/model/model.ipynb index c644b6d74b67c1a7354e1b8cfaa98f567ebf891f..813f169017e8834b2f8ccdedf571cf9ad8489092 100644 --- a/tutorials/source_zh_cn/advanced/model/model.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/model/model.ipynb @@ -4,15 +4,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_model.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/zh_cn/advanced/model/mindspore_model.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/source_zh_cn/advanced/model/model.ipynb)" + "# 高阶封装:Model\n", + "\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_model.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/model/mindspore_model.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/model/model.ipynb)\n", + "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# 高阶封装:Model\n", - "\n", "通常情况下,定义训练和评估网络并直接运行,已经可以满足基本需求。\n", "\n", "一方面,`Model`可以在一定程度上简化代码。例如:无需手动遍历数据集;在不需要自定义`nn.TrainOneStepCell`的场景下,可以借助`Model`自动构建训练网络;可以使用`Model`的`eval`接口进行模型评估,直接输出评估结果,无需手动调用评价指标的`clear`、`update`、`eval`函数等。\n", @@ -21,7 +22,7 @@ "\n", "本文档首先对MindSpore的Model进行基本介绍,然后重点讲解如何使用`Model`进行模型训练、评估和推理。\n", "\n", - "![model](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/source_zh_cn/advanced/model/images/model.png)" + "![model](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/model/images/model.png)" ] }, { diff --git a/tutorials/experts/source_zh_cn/optimize/gradient_accumulation.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/gradient_accumulation.ipynb similarity index 95% rename from tutorials/experts/source_zh_cn/optimize/gradient_accumulation.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/gradient_accumulation.ipynb index 05df77f7c70318f50b418255fbdc4244af37604d..e6e7c4b386b29cdec9bb9dc1e2e6a807f2c5e1b7 100644 --- a/tutorials/experts/source_zh_cn/optimize/gradient_accumulation.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/gradient_accumulation.ipynb @@ -7,7 +7,7 @@ "source": [ "# 梯度累加\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/optimize/mindspore_gradient_accumulation.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/optimize/mindspore_gradient_accumulation.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/optimize/gradient_accumulation.ipynb)" + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/optimize/mindspore_gradient_accumulation.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/optimize/mindspore_gradient_accumulation.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/gradient_accumulation.ipynb)" ] }, { @@ -51,7 +51,7 @@ "\n", "最终在上面步骤中累加梯度会产生与使用全局Batch size大小相同的梯度总和。\n", "\n", - "![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/GradientAccumulation1.png)\n", + "![](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/images/GradientAccumulation1.png)\n", "\n", "当然在实际工程当中,关于调参和算法上有两点需要注意的:\n", "\n", diff --git a/tutorials/experts/source_zh_cn/optimize/images/GradientAccumulation1.png b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/images/GradientAccumulation1.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/images/GradientAccumulation1.png rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/images/GradientAccumulation1.png diff --git a/docs/mindspore/source_zh_cn/model_train/train_process/optimize/images/data-and-graph-sink.eddx b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/images/data-and-graph-sink.eddx new file mode 100644 index 0000000000000000000000000000000000000000..ac699504b7016c7bf26787615d0d86fed5d1cd14 Binary files /dev/null and b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/images/data-and-graph-sink.eddx differ diff --git a/tutorials/experts/source_zh_cn/optimize/thor.rst b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor.rst similarity index 64% rename from tutorials/experts/source_zh_cn/optimize/thor.rst rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor.rst index 0ad00bf2b5e01ecfbbb5ebff0c8c6254c3c65470..d3db5d603acb940c84da93d8a9a23c6388ec2de7 100644 --- a/tutorials/experts/source_zh_cn/optimize/thor.rst +++ b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor.rst @@ -2,7 +2,7 @@ =========== .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg - :target: https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/optimize/thor.rst + :target: https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor.rst :alt: 查看源文件 .. toctree:: diff --git a/tutorials/experts/source_zh_cn/optimize/thor/images/deeplearning_train_process.png b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/deeplearning_train_process.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/thor/images/deeplearning_train_process.png rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/deeplearning_train_process.png diff --git a/tutorials/experts/source_zh_cn/optimize/thor/images/different_train_process.png b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/different_train_process.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/thor/images/different_train_process.png rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/different_train_process.png diff --git a/tutorials/experts/source_zh_cn/optimize/thor/images/split_dimension.png b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/split_dimension.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/thor/images/split_dimension.png rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/split_dimension.png diff --git a/tutorials/experts/source_zh_cn/optimize/thor/images/thor_in_bert.png b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_in_bert.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/thor/images/thor_in_bert.png rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_in_bert.png diff --git a/tutorials/experts/source_zh_cn/optimize/thor/images/thor_in_resnet.png b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_in_resnet.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/thor/images/thor_in_resnet.png rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_in_resnet.png diff --git a/tutorials/experts/source_zh_cn/optimize/thor/images/thor_largebs_in_resnet.png b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_largebs_in_resnet.png similarity index 100% rename from tutorials/experts/source_zh_cn/optimize/thor/images/thor_largebs_in_resnet.png rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/images/thor_largebs_in_resnet.png diff --git a/tutorials/experts/source_zh_cn/optimize/thor/intro.md b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/intro.md similarity index 98% rename from tutorials/experts/source_zh_cn/optimize/thor/intro.md rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/intro.md index 35604d90b6c8d5de276cfa51ffb3dd404382f20b..66ccd3814dc26c7356fb7b8d684da16de5052a86 100644 --- a/tutorials/experts/source_zh_cn/optimize/thor/intro.md +++ b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/intro.md @@ -1,6 +1,6 @@ # 二阶优化器THOR介绍 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/optimize/thor/intro.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/intro.md) 深度学习训练过程可以看成损失函数损失值下降过程,合适的优化器可以让深度学习训练时间大大减少。优化器可以分为一阶优化器和二阶优化器,目前业界主流使用的仍然是一阶优化器,二阶优化器因为单步训练时间过久而没有被广泛应用,而近年来,将二阶优化应用到深度学习训练中有了理论突破,并取得了不错的结果。 diff --git a/tutorials/experts/source_zh_cn/optimize/thor/resnet50.md b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/resnet50.md similarity index 97% rename from tutorials/experts/source_zh_cn/optimize/thor/resnet50.md rename to docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/resnet50.md index 7873915224448e3e8133cf14b738bf5cf728755c..b54ecd981917ec869607c60ce0912f971c56488f 100644 --- a/tutorials/experts/source_zh_cn/optimize/thor/resnet50.md +++ b/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/resnet50.md @@ -1,6 +1,6 @@ # 在ResNet-50网络上应用二阶优化实践 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/optimize/thor/resnet50.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/optimize/thor/resnet50.md) ## 概述 @@ -70,11 +70,11 @@ MindSpore开发团队在现有的自然梯度算法的基础上,对FIM矩阵 #### Atlas训练系列产品 -Atlas训练系列产品的分布式环境变量配置参考[rank table启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/rank_table.html)。 +Atlas训练系列产品的分布式环境变量配置参考[rank table启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/rank_table.html)。 #### GPU -GPU的分布式环境配置参考[mpirun启动方式](https://www.mindspore.cn/tutorials/experts/zh-CN/master/parallel/mpirun.html)。 +GPU的分布式环境配置参考[mpirun启动方式](https://www.mindspore.cn/docs/zh-CN/master/model_train/parallel/mpirun.html)。 ## 加载处理数据集 @@ -168,7 +168,7 @@ def create_dataset2(dataset_path, do_train, repeat_num=1, batch_size=32, target= return data_set ``` -> MindSpore支持进行多种数据处理和增强的操作,各种操作往往组合使用,具体可以参考[数据处理](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset.html)和[数据增强](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/dataset.html)章节。 +> MindSpore支持进行多种数据处理和增强的操作,各种操作往往组合使用,具体可以参考[数据加载与处理](https://www.mindspore.cn/docs/zh-CN/master/model_train/index.html)章节。 ## 定义网络 diff --git a/docs/mindspore/source_zh_cn/model_train/train_process/overview.md b/docs/mindspore/source_zh_cn/model_train/train_process/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..6d6c34a0283754e6bd821b5f2cd9075c758e388a --- /dev/null +++ b/docs/mindspore/source_zh_cn/model_train/train_process/overview.md @@ -0,0 +1,3 @@ +# 训练流程概述 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/overview.md) diff --git a/tutorials/experts/source_zh_cn/optimize/execution_opt.ipynb b/docs/mindspore/source_zh_cn/model_train/train_process/train_optimize.ipynb similarity index 94% rename from tutorials/experts/source_zh_cn/optimize/execution_opt.ipynb rename to docs/mindspore/source_zh_cn/model_train/train_process/train_optimize.ipynb index 8d1ec0df77155a8c6d6fb2f1769b6cfd84539dad..3e6b53331ba4160c50b1ff467df2e221997760f4 100644 --- a/tutorials/experts/source_zh_cn/optimize/execution_opt.ipynb +++ b/docs/mindspore/source_zh_cn/model_train/train_process/train_optimize.ipynb @@ -4,11 +4,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# 下沉模式\n", + "# 训练性能优化\n", "\n", - "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/optimize/mindspore_execution_opt.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/tutorials/experts/zh_cn/optimize/mindspore_execution_opt.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/tutorials/experts/source_zh_cn/optimize/execution_opt.ipynb)\n", + "[![下载Notebook](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_notebook.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/mindspore_train_optimize.ipynb) [![下载样例代码](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_download_code.svg)](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/master/zh_cn/model_train/train_process/mindspore_train_optimize.py) [![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/model_train/train_process/train_optimize.ipynb)\n", "\n", - "## 概述\n", + "## 下沉模式\n", + "\n", + "### 概述\n", "\n", "昇腾芯片集成了AICORE和AICPU等计算单元。其中AICORE负责稠密Tensor和Vector运算,AICPU负责复杂控制逻辑的处理。\n", "\n", @@ -16,15 +18,15 @@ "\n", "从用户的视角来看,网络训练的流程如下:\n", "\n", - "![user-view](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/image-user-view.png)\n", + "![user-view](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/images/image-user-view.png)\n", "\n", "本教程以训练的执行流程为例介绍数据下沉、图下沉和循环下沉的原理和使用方法。\n", "\n", - "## 数据下沉\n", + "### 数据下沉\n", "\n", "为了提升网络的执行性能,通常使用专用芯片来执行算子,一个芯片对应一个Device,Host与Device的一般交互流程如下:\n", "\n", - "![without-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/image-without-sink.png)\n", + "![without-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/images/image-without-sink.png)\n", "\n", "由上图可见,每个训练迭代都需要从Host拷贝数据到Device,可通过数据下沉消除Host和Device间拷贝输入数据的开销。\n", "\n", @@ -32,31 +34,31 @@ "\n", "GPU后端和昇腾后端都支持数据下沉,GPU数据下沉的Host-Device交互流程如下:\n", "\n", - "![data-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/image-data-sink.png)\n", + "![data-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/images/image-data-sink.png)\n", "\n", "用户可通过[train](https://mindspore.cn/docs/zh-CN/master/api_python/train/mindspore.train.Model.html#mindspore.train.Model.train)接口的`dataset_sink_mode`控制是否使能数据下沉。\n", "\n", - "## 图下沉\n", + "### 图下沉\n", "\n", "一般情况下,每个训练迭代都需要下发并触发device上每个算子的执行,Host与Device交互频繁。\n", "\n", "为减少Host与Device的交互,在图编译时,将网络中的算子打包并一起下发到device,每次迭代只触发一次计算图的执行即可,从而提升网络的执行效率。\n", "\n", - "![graph-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/image-graph-sink.png)\n", + "![graph-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/images/image-graph-sink.png)\n", "\n", "GPU后端暂不支持图下沉;使用昇腾设备时,开启数据下沉会同时启用图下沉。\n", "\n", - "## 循环下沉\n", + "### 循环下沉\n", "\n", "启用数据下沉和图下沉后,每个迭代的计算结果都会返回Host,并由Host判断是否需要进入下一个迭代,为减少每个迭代的Device-Host交互,可以将进入下一个迭代的循环判断下沉到Device,这样等所有迭代执行完成后再将计算结果返回到Host。循环下沉的Host-Device交互流程如下:\n", "\n", - "![loop-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/tutorials/experts/source_zh_cn/optimize/images/image-loop-sink.png)\n", + "![loop-sink](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/docs/mindspore/source_zh_cn/model_train/train_process/images/image-loop-sink.png)\n", "\n", "用户通过[train](https://mindspore.cn/docs/zh-CN/master/api_python/train/mindspore.train.Model.html#mindspore.train.Model.train)接口的`dataset_sink_mode`和`sink_size`参数控制每个epoch的下沉迭代数量,Device侧连续执行`sink_size`个迭代后才返回到Host。\n", "\n", - "## 使用方法\n", + "### 使用方法\n", "\n", - "### `Model.train`实现数据下沉\n", + "#### `Model.train`实现数据下沉\n", "\n", "`Model`的`train`接口参数`dataset_sink_mode`可以控制数据是否下沉。`dataset_sink_mode`为True表示数据下沉,否则为非下沉。所谓下沉即数据通过通道直接传送到Device上。\n", "\n", @@ -76,7 +78,7 @@ ">\n", "> - 由于数据下沉对数据集的遍历是连续,当前不支持非连续遍历。\n", ">\n", - "> - 如果在使用数据下沉模式时,出现`fault kernel_name=GetNext`、`GetNext... task error`或者`outputs = self.get_next()`等类似的错误,那么有可能是数据处理过程中某些样本处理太耗时,导致网络计算侧长时间拿不到数据报错,此时可以将`dataset_sink_mode`设置为False再次验证,或者对数据集使用`create_dict_iterator()`接口单独循环数据集,并参考[数据处理性能优化](https://mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html)调优数据处理,保证数据处理高性能。\n", + "> - 如果在使用数据下沉模式时,出现`fault kernel_name=GetNext`、`GetNext... task error`或者`outputs = self.get_next()`等类似的错误,那么有可能是数据处理过程中某些样本处理太耗时,导致网络计算侧长时间拿不到数据报错,此时可以将`dataset_sink_mode`设置为False再次验证,或者对数据集使用`create_dict_iterator()`接口单独循环数据集,并参考[数据处理性能优化](https://mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html)调优数据处理,保证数据处理高性能。\n", "\n", "代码样例如下:" ] @@ -277,7 +279,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### `data_sink`实现数据下沉\n", + "#### `data_sink`实现数据下沉\n", "\n", "在MindSpore的函数式编程范式中,还可以使用[data_sink接口](https://mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.data_sink.html)将模型的执行函数和数据集绑定,实现数据下沉。参数含义如下:\n", "\n", @@ -293,7 +295,7 @@ ">\n", "> - 由于数据下沉对数据集的遍历是连续,当前不支持非连续遍历。\n", ">\n", - "> - 如果在使用数据下沉模式时,出现`fault kernel_name=GetNext`、`GetNext... task error`或者`outputs = self.get_next()`等类似的错误,那么有可能是数据处理过程中某些样本处理太耗时,导致网络计算侧长时间拿不到数据报错,此时可以将`dataset_sink_mode`设置为False再次验证,或者对数据集使用`create_dict_iterator()`接口单独循环数据集,并参考[数据处理性能优化](https://mindspore.cn/tutorials/experts/zh-CN/master/dataset/optimize.html)调优数据处理,保证数据处理高性能。\n", + "> - 如果在使用数据下沉模式时,出现`fault kernel_name=GetNext`、`GetNext... task error`或者`outputs = self.get_next()`等类似的错误,那么有可能是数据处理过程中某些样本处理太耗时,导致网络计算侧长时间拿不到数据报错,此时可以将`dataset_sink_mode`设置为False再次验证,或者对数据集使用`create_dict_iterator()`接口单独循环数据集,并参考[数据处理性能优化](https://mindspore.cn/docs/zh-CN/master/model_train/dataset/optimize.html)调优数据处理,保证数据处理高性能。\n", "\n", "代码示例如下:" ] @@ -490,7 +492,10 @@ "2. 每次下沉1个epoch的数据,每个epoch执行结束后返回loss,训练10个epoch需要在Host侧循环调用10次;\n", "3. 单次下沉10个epoch的数据,10个epoch执行结束后返回loss,无需在Host侧进行循环。\n", "\n", - "上述方法中,方法1在每个step结束后与Device进行一次交互,效率较低;方法3在训练中不需要与Device进行交互,执行效率最高,但只能返回最后的一个step的loss。" + "上述方法中,方法1在每个step结束后与Device进行一次交互,效率较低;方法3在训练中不需要与Device进行交互,执行效率最高,但只能返回最后的一个step的loss。\n", + "\n", + "## 与数据流水的协同优化\n", + "\n" ] } ], diff --git a/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/DataLoader.md b/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/DataLoader.md index ca2629118403afc671bf6afbf1a522945ac0f2a3..ef9dff1a797d3adb4e0063999b0fa71e251a26a9 100644 --- a/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/DataLoader.md +++ b/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/DataLoader.md @@ -20,7 +20,7 @@ class torch.utils.data.DataLoader( class mindspore.dataset.GeneratorDataset( source, column_names=None, column_types=None, schema=None, num_samples=None, num_parallel_workers=1, shuffle=None, sampler=None, - num_shards=None, shard_id=None, python_multiprocessing=True, max_rowsize=6) + num_shards=None, shard_id=None, python_multiprocessing=True, max_rowsize=None) ``` 更多内容详见[mindspore.dataset.GeneratorDataset](https://mindspore.cn/docs/zh-CN/master/api_python/dataset/mindspore.dataset.GeneratorDataset.html#mindspore.dataset.GeneratorDataset)。 diff --git a/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/Transformer.md b/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/Transformer.md index b4c325ff8bb16acda646e4dc2726d5dd6d5c175e..4e91f74cb5c82f63d2e957bd0e64c391b6b3f917 100644 --- a/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/Transformer.md +++ b/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/Transformer.md @@ -1,6 +1,6 @@ # 比较与torch.nn.Transformer -[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/Transformer.md) +[![View Source On Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/Transformer.md) ## torch.nn.Transformer diff --git a/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/deform_conv2d.md b/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/deform_conv2d.md index d46a56de645198087aa5e5458b6e23501d83314f..08ee6ac1ce4c666ec21a3cd55bca7b6d289adec9 100644 --- a/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/deform_conv2d.md +++ b/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/deform_conv2d.md @@ -1,6 +1,6 @@ # 比较与torchvision.ops.deform_conv2d的差异 -[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/note/api_mapping/pytorch_diff/deform_conv2d.md) +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/note/api_mapping/pytorch_diff/deform_conv2d.md) ## torchvision.ops.deform_conv2d diff --git a/docs/mindspore/source_zh_cn/note/env_var_list.rst b/docs/mindspore/source_zh_cn/note/env_var_list.rst index f71bfeec239c62d852e6f08030f11aec181dcdc6..dce16d26e803db83ca649c31fbaaa615ab84c353 100644 --- a/docs/mindspore/source_zh_cn/note/env_var_list.rst +++ b/docs/mindspore/source_zh_cn/note/env_var_list.rst @@ -59,8 +59,8 @@ false: 关闭pipeline树优化 - -具体用法详见 `单节点数据缓存 `_ -和 `数据处理性能优化 `_ 。 +具体用法详见 `单节点数据缓存 `_ +和 `数据处理性能优化 `_ 。 图编译执行 ---------- @@ -85,14 +85,14 @@ - 指定静态图模式下哪些模块需要JIT静态编译,其函数方法会被编译成静态计算图 - String - 模块名,对应import导入的顶层模块的名称。如果有多个,使用英文逗号分隔。例如:`export MS_JIT_MODULES=mindflow,mindyolo`。 - - 默认情况下,第三方库之外的模块都会进行JIT静态编译。MindSpore套件等一些模块如 `mindflow`、`mindyolo` 等并不会被视作第三方库,请参考 `调用第三方库 `_ 。如果有类似MindSpore套件的模块,内部存在 `nn.Cell`、`@ms.jit` 修饰函数或需要编译成静态计算图的函数方法,可以通过配置该环境变量,使该模块进行JIT静态编译而不会被当成第三方库。 + - 默认情况下,第三方库之外的模块都会进行JIT静态编译。MindSpore套件等一些模块如 `mindflow`、`mindyolo` 等并不会被视作第三方库,请参考 `调用第三方库 `_ 。如果有类似MindSpore套件的模块,内部存在 `nn.Cell`、`@ms.jit` 修饰函数或需要编译成静态计算图的函数方法,可以通过配置该环境变量,使该模块进行JIT静态编译而不会被当成第三方库。 * - MS_JIT_IGNORE_MODULES - 指定静态图模式下哪些模块是第三方库,不进行JIT静态编译,其函数方法会被解释执行。 - String - 模块名,对应import导入的顶层模块的名称。如果有多个,使用英文逗号分隔。例如:`export MS_JIT_IGNORE_MODULES=numpy,scipy`。 - 静态图模式能够自动识别第三方库,一般情况下不需要为NumPy、SciPy这些可识别的第三方库设置该环境变量。如果 `MS_JIT_IGNORE_MODULES` 和 `MS_JIT_MODULES` 同时指定同一个模块名,前者生效,后者不生效。 * - MS_DEV_FALLBACK_DUMP_NODE - - 是否打印代码中由 `静态图语法增强技术 `_ 支持的语法表达式 + - 是否打印代码中由 `静态图语法增强技术 `_ 支持的语法表达式 - Integer - 1:开启打印功能。 @@ -285,13 +285,13 @@ Dump调试 - 取值 - 说明 * - MINDSPORE_DUMP_CONFIG - - 指定 `云侧Dump功能 `_ + - 指定 `云侧Dump功能 `_ 或 `端侧Dump功能 `_ 所依赖的配置文件的路径 - String - 文件路径,支持相对路径与绝对路径 - * - MS_DIAGNOSTIC_DATA_PATH - - 使用 `云侧Dump功能 `_ 时, + - 使用 `云侧Dump功能 `_ 时, 如果Dump配置文件没有设置 `path` 字段或者设置为空字符串,则 `$MS_DIAGNOSTIC_DATA_PATH` `/debug_dump` 就会被当做path的值。 若Dump配置文件中设置了 `path` 字段,则仍以该字段的实际取值为准。 - String @@ -342,7 +342,7 @@ Dump调试 - 文件路径,支持相对路径与绝对路径 - -具体用法详见 `Dump功能调试 `_ 。 +具体用法详见 `Dump功能调试 `_ 。 分布式并行 ----------- @@ -396,7 +396,7 @@ Dump调试 MS_WORKER: 代表Worker进程,一般设置分布式训练进程为此角色。 - MS_PSERVER: 代表Parameter Server进程,只有在Parameter Server模式下此角色生效,具体请参考 `Parameter Server模式 `_ 。 + MS_PSERVER: 代表Parameter Server进程,只有在Parameter Server模式下此角色生效,具体请参考 `Parameter Server模式 `_ 。 - Worker和Parameter Server进程会向Scheduler进程注册从而完成组网。 * - MS_SCHED_HOST - 指定Scheduler的IP地址。 @@ -500,7 +500,7 @@ Dump调试 delete_depend_list(List[string]):需要被删除的算子名称列表,算子名称不存在或者和graph_id不匹配,删除节点的动作将失效。 -动态组网相关的具体用法详见 `动态组网 `_ 。 +动态组网相关的具体用法详见 `动态组网 `_ 。 算子编译 -------- @@ -724,7 +724,7 @@ Dump调试 注意:glog不支持日志文件的绕接,如果需要控制日志文件对磁盘空间的占用,可选用操作系统提供的日志文件管理工具,例如:Linux的logrotate。请在 `import mindspore` 之前设置日志相关环境变量。 -RDR相关的具体用法详见 `Running Data Recorder `_ 。 +RDR相关的具体用法详见 `Running Data Recorder `_ 。 特征值检测 ------------ @@ -764,7 +764,7 @@ RDR相关的具体用法详见 `Running Data Recorder `_ 。 +特征值检测的更多内容详见 `特征值检测 `_ 。 三方库 ------ diff --git a/docs/mindspore/source_zh_cn/orange_pi/debug.md b/docs/mindspore/source_zh_cn/orange_pi/debug.md new file mode 100644 index 0000000000000000000000000000000000000000..865838b6c775c358b4db6f37c0473b70ebb8918a --- /dev/null +++ b/docs/mindspore/source_zh_cn/orange_pi/debug.md @@ -0,0 +1,3 @@ +# 功能调试 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/orange_pi/debug.md) \ No newline at end of file diff --git a/docs/mindspore/source_zh_cn/orange_pi/index.rst b/docs/mindspore/source_zh_cn/orange_pi/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..56f2629997f652271d72498764f59f486130e9f9 --- /dev/null +++ b/docs/mindspore/source_zh_cn/orange_pi/index.rst @@ -0,0 +1,11 @@ +香橙派开发 +=============== + +.. toctree:: + :glob: + :maxdepth: 1 + + overview + quick_start + debug + model_infer diff --git a/docs/mindspore/source_zh_cn/orange_pi/model_infer.md b/docs/mindspore/source_zh_cn/orange_pi/model_infer.md new file mode 100644 index 0000000000000000000000000000000000000000..a61812a2d3d86e8df135e74d9d2786267cd74762 --- /dev/null +++ b/docs/mindspore/source_zh_cn/orange_pi/model_infer.md @@ -0,0 +1,7 @@ +# 模型推理 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/orange_pi/model_infer.md) + +## 在线推理 + +## 离线推理 diff --git a/docs/mindspore/source_zh_cn/orange_pi/overview.md b/docs/mindspore/source_zh_cn/orange_pi/overview.md new file mode 100644 index 0000000000000000000000000000000000000000..ad19dbe45ff41db7217ad40dfa628b97b51437cb --- /dev/null +++ b/docs/mindspore/source_zh_cn/orange_pi/overview.md @@ -0,0 +1,3 @@ +# 了解香橙派 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/orange_pi/overview.md) diff --git a/docs/mindspore/source_zh_cn/orange_pi/quick_start.md b/docs/mindspore/source_zh_cn/orange_pi/quick_start.md new file mode 100644 index 0000000000000000000000000000000000000000..a5a172d95a26a69e228960758f7cda68f3f9b32e --- /dev/null +++ b/docs/mindspore/source_zh_cn/orange_pi/quick_start.md @@ -0,0 +1,9 @@ +# 快速入门 + +[![查看源文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg)](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/orange_pi/quick_start.md) + +## 安装 + +## 启动 + +## 运行 diff --git a/docs/xai/docs/source_en/using_cv_benchmarks.md b/docs/xai/docs/source_en/using_cv_benchmarks.md index ffbb80a9e87a296139a584d08728f72bc14c3d9d..dcdc274c2b4025dd953cf467658c21aeed0c2de4 100644 --- a/docs/xai/docs/source_en/using_cv_benchmarks.md +++ b/docs/xai/docs/source_en/using_cv_benchmarks.md @@ -10,7 +10,7 @@ Benchmarks are algorithms evaluating the goodness of saliency maps from explaine The complete code of the tutorial below is [using_cv_benchmarks.py](https://gitee.com/mindspore/xai/blob/master/examples/using_cv_benchmarks.py). -Please follow the [Downloading Data Package](https://www.mindspore.cn/xai/docs/en/master/using_cv_explainers.html#downloading-data-package) instructions to download the necessary files for the tutorial. +Please follow the [Downloading Data Package](https://www.mindspore.cn/xai/docs/en/master/using_cv_explainers.html#downloading-data-package-and-model) instructions to download the necessary files for the tutorial. With the tutorial package, we have to get the sample image, trained classifier, explainer and optionally the saliency map ready: diff --git a/install/mindspore_ascend_install_pip.md b/install/mindspore_ascend_install_pip.md index 8363d03faa1077203154fd11436d3234c8566688..97366302ba388f9c60b81f594dccd442d934cb43 100644 --- a/install/mindspore_ascend_install_pip.md +++ b/install/mindspore_ascend_install_pip.md @@ -31,7 +31,7 @@ ```bash wget https://gitee.com/mindspore/mindspore/raw/master/scripts/install/euleros-ascend-pip.sh -# 安装MindSpore 2.3.0和Python 3.9 +# 安装MindSpore 2.3.1和Python 3.9 # 默认LOCAL_ASCEND路径为/usr/local/Ascend PYTHON_VERSION=3.9 bash -i ./euleros-ascend-pip.sh # 如需指定Python和MindSpore版本,以Python 3.8和MindSpore 1.6.0为例 diff --git a/install/mindspore_ascend_install_pip_en.md b/install/mindspore_ascend_install_pip_en.md index c97e916db846fde0ad90f231860b03a6b1a0ea96..a3a453637734a627e6744d12d8565d6144f41405 100644 --- a/install/mindspore_ascend_install_pip_en.md +++ b/install/mindspore_ascend_install_pip_en.md @@ -31,7 +31,7 @@ Run the following command to obtain and run the automatic installation script. T ```bash wget https://gitee.com/mindspore/mindspore/raw/master/scripts/install/euleros-ascend-pip.sh -# install MindSpore 2.3.0 and Python 3.9 +# install MindSpore 2.3.1 and Python 3.9 # the default value of LOCAL_ASCEND is /usr/local/Ascend PYTHON_VERSION=3.9 bash -i ./euleros-ascend-pip.sh # to specify Python and MindSpore version, taking Python 3.8 and MindSpore 1.6.0 as examples diff --git a/install/mindspore_gpu_install_conda.md b/install/mindspore_gpu_install_conda.md index d4a122eecb1e0da25c26d80c79135ea3bcdf711b..8be0fbcee66fe25a8365aeee95c8a4e171008d46 100644 --- a/install/mindspore_gpu_install_conda.md +++ b/install/mindspore_gpu_install_conda.md @@ -139,7 +139,7 @@ source ~/.bashrc ### 安装cuDNN -完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/zh-cn/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 +完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 ```bash tar -zxvf cudnn.tgz diff --git a/install/mindspore_gpu_install_conda_en.md b/install/mindspore_gpu_install_conda_en.md index b6cd419fdf9aea02ea105dfbbcce8039a8ac0729..f0a8d4a490a083a9fbc3d523bb5aa017ac6e6a9c 100644 --- a/install/mindspore_gpu_install_conda_en.md +++ b/install/mindspore_gpu_install_conda_en.md @@ -139,7 +139,7 @@ When the default path /usr/local/cuda has an installation package, the LD_LIBRAR ### Installing cuDNN -After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/zh-cn/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. +After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. ```bash tar -zxvf cudnn.tgz diff --git a/install/mindspore_gpu_install_nightly.md b/install/mindspore_gpu_install_nightly.md index 3a9f70f87fb78007aa0842800d2be6cbdc988605..73b20c52b0f75343c2c867f3149856de466129ef 100644 --- a/install/mindspore_gpu_install_nightly.md +++ b/install/mindspore_gpu_install_nightly.md @@ -85,7 +85,7 @@ source ~/.bashrc ### 安装cuDNN -完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/zh-cn/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 +完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 ```bash tar -zxvf cudnn.tgz diff --git a/install/mindspore_gpu_install_nightly_en.md b/install/mindspore_gpu_install_nightly_en.md index 05783d35e9c63dc0ddf12d2012055b61286c7e2a..68472e72532dba47d0938da5e814bd74080f5bf3 100644 --- a/install/mindspore_gpu_install_nightly_en.md +++ b/install/mindspore_gpu_install_nightly_en.md @@ -85,7 +85,7 @@ When the default path /usr/local/cuda has an installation package, the LD_LIBRAR ### Installing cuDNN -After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/zh-cn/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. +After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. ```bash tar -zxvf cudnn.tgz diff --git a/install/mindspore_gpu_install_pip.md b/install/mindspore_gpu_install_pip.md index 6cb27db35d014e9ef42bf15d0d1547f40030331a..e52d98dedc6e213520297b4da7389bdc3eb90101 100644 --- a/install/mindspore_gpu_install_pip.md +++ b/install/mindspore_gpu_install_pip.md @@ -127,7 +127,7 @@ source ~/.bashrc ### 安装cuDNN -完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/zh-cn/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 +完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 ```bash tar -zxvf cudnn.tgz diff --git a/install/mindspore_gpu_install_pip_en.md b/install/mindspore_gpu_install_pip_en.md index dcd4d3a06c0d2b03e633398e93ded93ff444f1db..1f908ed41c4e3085e8272e0a1ac6a3304403173e 100644 --- a/install/mindspore_gpu_install_pip_en.md +++ b/install/mindspore_gpu_install_pip_en.md @@ -127,7 +127,7 @@ When the default path /usr/local/cuda has an installation package, the LD_LIBRAR ### Installing cuDNN -After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/zh-cn/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. +After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. ```bash tar -zxvf cudnn.tgz diff --git a/install/mindspore_gpu_install_source.md b/install/mindspore_gpu_install_source.md index b27524d9c5815e6bd5ec19f3a4c6976b21c1949c..5a74ebf38693e9b82c52221f40acb3abf4b15104 100644 --- a/install/mindspore_gpu_install_source.md +++ b/install/mindspore_gpu_install_source.md @@ -145,7 +145,7 @@ source ~/.bashrc ### 安装cuDNN -完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/zh-cn/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 +完成CUDA的安装后,在[cuDNN页面](https://developer.nvidia.com/cudnn)登录并下载对应的cuDNN安装包。如果之前安装了CUDA 10.1,下载配套CUDA 10.1的cuDNN v7.6.x;如果之前安装了CUDA 11.1,下载配套CUDA 11.1的cuDNN v8.0.x;如果之前安装了CUDA 11.6,下载配套CUDA 11.6的cuDNN v8.5.x。注意下载后缀名为tgz的压缩包。假设下载的cuDNN包名为`cudnn.tgz`,安装的CUDA版本为11.6,执行以下命令安装cuDNN。 ```bash tar -zxvf cudnn.tgz diff --git a/install/mindspore_gpu_install_source_en.md b/install/mindspore_gpu_install_source_en.md index d5cd34f6447f578ca327f874e4f75ff4820582a4..e029eae3f211faa667a1e1dd50c808ee9431f911 100644 --- a/install/mindspore_gpu_install_source_en.md +++ b/install/mindspore_gpu_install_source_en.md @@ -145,7 +145,7 @@ When the default path /usr/local/cuda has an installation package, the LD_LIBRAR ### Installing cuDNN -After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/zh-cn/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. +After completing the installation of CUDA, Log in and download the corresponding cuDNN installation package from [cuDNN page](https://developer.nvidia.com/cudnn). If CUDA 10.1 was previously installed, download cuDNN v7.6.x for CUDA 10.1. If CUDA 11.1 was previously installed, download cuDNN v8.0.x for CUDA 11.1. If CUDA 11.6 was previously installed, download cuDNN v8.5.x for CUDA 11.6. Note that download the tgz compressed file. Assuming that the downloaded cuDNN package file is named `cudnn.tgz` and the installed CUDA version is 11.6, execute the following command to install cuDNN. ```bash tar -zxvf cudnn.tgz diff --git a/resource/release/release_list_en.md b/resource/release/release_list_en.md index 81133cf91c2dadddebaf0acd5cca869000f4b17d..e1252750d4d0bce78a750bf71dfbafd5b69db9dc 100644 --- a/resource/release/release_list_en.md +++ b/resource/release/release_list_en.md @@ -6,6 +6,7 @@ - [Related Documents](#related-documents) - [Ascend Supporting Software Package](#ascend-supporting-software-package) - [Downloads](#downloads) + - [2.3.1](#231) - [2.3.0](#230) - [2.3.0-rc2](#230-rc2) - [2.3.0-RC1](#230-rc1) @@ -61,11 +62,11 @@ | Category | Subcategory | Version | | --- | --- | --- | -| Releasenotes and API Updates | | [2.3.0](https://gitee.com/mindspore/mindspore/blob/master/RELEASE.md#mindspore-230-release-notes)    [2.3.0-rc2](https://gitee.com/mindspore/mindspore/blob/master/RELEASE.md#mindspore-230-rc2-release-notes)    [2.3.0-rc1](https://gitee.com/mindspore/mindspore/blob/master/RELEASE.md#mindspore-230-rc1-release-notes)    [2.2.14](https://gitee.com/mindspore/mindspore/blob/r2.2/RELEASE.md#)    [2.1.1](https://gitee.com/mindspore/mindspore/blob/r2.1/RELEASE.md#)    [2.0.0](https://gitee.com/mindspore/mindspore/blob/r2.0/RELEASE.md#)    [2.0.0-alpha](https://gitee.com/mindspore/mindspore/blob/r2.0.0-alpha/RELEASE.md#)    [1.10.1](https://gitee.com/mindspore/mindspore/blob/r1.10/RELEASE.md#)    [1.9.0](https://gitee.com/mindspore/mindspore/blob/r1.9/RELEASE.md#)    [1.8.1](https://gitee.com/mindspore/mindspore/blob/r1.8/RELEASE.md#)   
    [1.7.1](https://gitee.com/mindspore/mindspore/blob/r1.7/RELEASE.md#)    [1.6.2](https://gitee.com/mindspore/mindspore/blob/r1.6/RELEASE.md#)    [1.5.2](https://gitee.com/mindspore/mindspore/blob/r1.5/RELEASE.md#)    [1.3.0](https://gitee.com/mindspore/mindspore/blob/r1.3/RELEASE.md#)    [1.2.1](https://gitee.com/mindspore/mindspore/blob/r1.2/RELEASE.md#)    [1.1.1](https://gitee.com/mindspore/mindspore/blob/r1.1/RELEASE.md#)    [1.0.1](https://gitee.com/mindspore/mindspore/blob/r1.0/RELEASE.md#)    [0.7.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.7/RELEASE.md#)   
    [0.6.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.6/RELEASE.md#)    [0.5.2-beta](https://gitee.com/mindspore/mindspore/blob/r0.5/RELEASE.md#)    [0.3.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.3/RELEASE.md#)    [0.2.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.2/RELEASE.md#)    [0.1.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.1/RELEASE.md#) | -| Installation | | [2.3.0](https://gitee.com/mindspore/docs/tree/r2.3.0/install)    [2.3.0-rc2](https://gitee.com/mindspore/docs/tree/r2.3.0rc2/install)    [2.3.0-rc1](https://gitee.com/mindspore/docs/tree/r2.3.q1/install)    [2.2.14](https://gitee.com/mindspore/docs/tree/r2.2/install)    [2.1.1](https://gitee.com/mindspore/docs/tree/r2.1/install)    [2.0.0](https://gitee.com/mindspore/docs/tree/r2.0/install)    [2.0.0-alpha](https://gitee.com/mindspore/docs/tree/r2.0.0-alpha/install)    [1.10.1](https://gitee.com/mindspore/docs/tree/r1.10/install)    [1.9.0](https://gitee.com/mindspore/docs/tree/r1.9/install)    [1.8.1](https://gitee.com/mindspore/docs/tree/r1.8/install)   
    [1.7.1](https://gitee.com/mindspore/docs/tree/r1.7/install)    [1.6.2](https://gitee.com/mindspore/docs/tree/r1.6/install)    [1.5.2](https://gitee.com/mindspore/docs/tree/r1.5/install)    [1.3.0](https://gitee.com/mindspore/docs/tree/r1.3/install)    [1.2.1](https://gitee.com/mindspore/docs/tree/r1.2/install)    [1.1.1](https://gitee.com/mindspore/docs/tree/r1.1/install)    [1.0.1](https://gitee.com/mindspore/docs/tree/r1.0/install)    [0.7.0-beta](https://gitee.com/mindspore/docs/tree/r0.7/install)   
    [0.6.0-beta](https://gitee.com/mindspore/docs/tree/r0.6/install)    [0.5.2-beta](https://gitee.com/mindspore/docs/tree/r0.5/install)    [0.3.0-alpha](https://gitee.com/mindspore/docs/tree/r0.3/install)    [0.2.0-alpha](https://gitee.com/mindspore/docs/tree/r0.2/install)    [0.1.0-alpha](https://gitee.com/mindspore/docs/tree/r0.1/install) | -| Tutorials | | [2.3.0](https://www.mindspore.cn/tutorials/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/tutorials/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/tutorials/en/r2.3.0rc1/index.html)    [2.2.14](https://mindspore.cn/tutorials/en/r2.2/index.html)    [2.1.1](https://mindspore.cn/tutorials/en/r2.1/index.html)    [2.0.0](https://mindspore.cn/tutorials/en/r2.0/index.html)    [2.0.0-alpha](https://mindspore.cn/tutorials/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/tutorials/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/tutorials/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/tutorials/en/r1.8/index.html)   
    [1.7.1](https://www.mindspore.cn/tutorials/en/r1.7/index.html)    [1.6.2](https://www.mindspore.cn/tutorials/en/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/tutorials/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/tutorials/en/r1.3/index.html)    [1.2.1-Training](https://www.mindspore.cn/tutorial/training/en/r1.2/index.html)    [1.2.1-Inference](https://www.mindspore.cn/tutorial/inference/en/r1.2/index.html)   
    [1.2.1-Mobile Phone&IoT](https://www.mindspore.cn/tutorial/lite/en/r1.2/index.html)    [1.1.1-Training](https://www.mindspore.cn/tutorial/training/en/r1.1/index.html)    [1.1.1-Inference](https://www.mindspore.cn/tutorial/inference/en/r1.1/index.html)   
    [1.1.1-Mobile Phone&IoT](https://www.mindspore.cn/tutorial/lite/en/r1.1/index.html)    [1.0.1-Training](https://www.mindspore.cn/tutorial/training/en/r1.0/index.html)    [1.0.1-Inference](https://www.mindspore.cn/tutorial/inference/en/r1.0/index.html)   
    [1.0.0-Mobile Phone&IoT](https://www.mindspore.cn/tutorial/lite/en/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/tutorial/en/r0.7/index.html)    [0.7.0-beta-Mobile Phone&IoT](https://www.mindspore.cn/lite/tutorial/en/r0.7/index.html)   
    [0.6.0-beta](https://www.mindspore.cn/tutorial/en/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/tutorial/en/r0.5/index.html)   [0.3.0-alpha](https://www.mindspore.cn/tutorial/en/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/tutorial/en/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/tutorial/en/0.1.0-alpha/index.html)   
    [master](https://www.mindspore.cn/tutorials/en/master/index.html) | -| Docs |MindSpore | [2.3.0](https://www.mindspore.cn/docs/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/docs/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/docs/en/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/docs/en/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/docs/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/docs/en/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/docs/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/docs/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/docs/en/r1.8/index.html)   
    [1.7.1](https://www.mindspore.cn/docs/en/r1.7/index.html)    [1.6.2](https://www.mindspore.cn/docs/programming_guide/en/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/programming_guide/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/programming_guide/en/r1.3/index.html)    [1.2.1-Programming Guide](https://www.mindspore.cn/doc/programming_guide/en/r1.2/index.html)   
    [1.2.1-Design&Specification](https://www.mindspore.cn/doc/note/en/r1.2/index.html)    [1.2.1-FAQ](https://www.mindspore.cn/doc/faq/en/r1.2/index.html)    [1.1.1-Programming Guide](https://www.mindspore.cn/doc/programming_guide/en/r1.1/index.html)   
    [1.1.1-Design&Specification](https://www.mindspore.cn/doc/note/en/r1.1/index.html)    [1.1.1-FAQ](https://www.mindspore.cn/doc/faq/en/r1.1/index.html)    [1.0.1-Programming Guide](https://www.mindspore.cn/doc/programming_guide/en/r1.0/index.html)   
    [1.0.1-Design&Specification](https://www.mindspore.cn/doc/note/en/r1.0/index.html)    [1.0.1-FAQ](https://www.mindspore.cn/doc/faq/en/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/docs/en/r0.7/index.html)    [0.6.0-beta](https://www.mindspore.cn/docs/en/r0.6/index.html)   
    [0.5.2-beta](https://www.mindspore.cn/docs/en/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/docs/en/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/docs/en/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/docs/en/0.1.0-alpha/index.html)    [master](https://www.mindspore.cn/docs/en/master/index.html) | -| |MindSpore Lite | [2.3.0](https://www.mindspore.cn/lite/docs/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/docs/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/docs/en/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/docs/en/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/docs/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/docs/en/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/docs/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/docs/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/docs/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/docs/en/r1.8/index.html)   
    [1.7.0](https://www.mindspore.cn/lite/docs/en/r1.7/index.html)    [1.6.1](https://www.mindspore.cn/lite/docs/en/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/docs/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/docs/en/r1.3/index.html)    [0.7.0-beta](https://www.mindspore.cn/lite/docs/en/r0.7/index.html)    [master](https://www.mindspore.cn/lite/docs/en/master/index.html) | +| Releasenotes and API Updates | | [2.3.1](https://gitee.com/mindspore/mindspore/blob/master/RELEASE.md#mindspore-231-release-notes)    [2.3.0](https://gitee.com/mindspore/mindspore/blob/master/RELEASE.md#mindspore-230-release-notes)    [2.3.0-rc2](https://gitee.com/mindspore/mindspore/blob/master/RELEASE.md#mindspore-230-rc2-release-notes)    [2.3.0-rc1](https://gitee.com/mindspore/mindspore/blob/master/RELEASE.md#mindspore-230-rc1-release-notes)    [2.2.14](https://gitee.com/mindspore/mindspore/blob/r2.2/RELEASE.md#)    [2.1.1](https://gitee.com/mindspore/mindspore/blob/r2.1/RELEASE.md#)    [2.0.0](https://gitee.com/mindspore/mindspore/blob/r2.0/RELEASE.md#)    [2.0.0-alpha](https://gitee.com/mindspore/mindspore/blob/r2.0.0-alpha/RELEASE.md#)    [1.10.1](https://gitee.com/mindspore/mindspore/blob/r1.10/RELEASE.md#)    [1.9.0](https://gitee.com/mindspore/mindspore/blob/r1.9/RELEASE.md#)    [1.8.1](https://gitee.com/mindspore/mindspore/blob/r1.8/RELEASE.md#)   
    [1.7.1](https://gitee.com/mindspore/mindspore/blob/r1.7/RELEASE.md#)    [1.6.2](https://gitee.com/mindspore/mindspore/blob/r1.6/RELEASE.md#)    [1.5.2](https://gitee.com/mindspore/mindspore/blob/r1.5/RELEASE.md#)    [1.3.0](https://gitee.com/mindspore/mindspore/blob/r1.3/RELEASE.md#)    [1.2.1](https://gitee.com/mindspore/mindspore/blob/r1.2/RELEASE.md#)    [1.1.1](https://gitee.com/mindspore/mindspore/blob/r1.1/RELEASE.md#)    [1.0.1](https://gitee.com/mindspore/mindspore/blob/r1.0/RELEASE.md#)    [0.7.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.7/RELEASE.md#)   
    [0.6.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.6/RELEASE.md#)    [0.5.2-beta](https://gitee.com/mindspore/mindspore/blob/r0.5/RELEASE.md#)    [0.3.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.3/RELEASE.md#)    [0.2.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.2/RELEASE.md#)    [0.1.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.1/RELEASE.md#) | +| Installation | | [2.3.1](https://gitee.com/mindspore/docs/tree/r2.3.1/install)    [2.3.0](https://gitee.com/mindspore/docs/tree/r2.3.0/install)    [2.3.0-rc2](https://gitee.com/mindspore/docs/tree/r2.3.0rc2/install)    [2.3.0-rc1](https://gitee.com/mindspore/docs/tree/r2.3.q1/install)    [2.2.14](https://gitee.com/mindspore/docs/tree/r2.2/install)    [2.1.1](https://gitee.com/mindspore/docs/tree/r2.1/install)    [2.0.0](https://gitee.com/mindspore/docs/tree/r2.0/install)    [2.0.0-alpha](https://gitee.com/mindspore/docs/tree/r2.0.0-alpha/install)    [1.10.1](https://gitee.com/mindspore/docs/tree/r1.10/install)    [1.9.0](https://gitee.com/mindspore/docs/tree/r1.9/install)    [1.8.1](https://gitee.com/mindspore/docs/tree/r1.8/install)   
    [1.7.1](https://gitee.com/mindspore/docs/tree/r1.7/install)    [1.6.2](https://gitee.com/mindspore/docs/tree/r1.6/install)    [1.5.2](https://gitee.com/mindspore/docs/tree/r1.5/install)    [1.3.0](https://gitee.com/mindspore/docs/tree/r1.3/install)    [1.2.1](https://gitee.com/mindspore/docs/tree/r1.2/install)    [1.1.1](https://gitee.com/mindspore/docs/tree/r1.1/install)    [1.0.1](https://gitee.com/mindspore/docs/tree/r1.0/install)    [0.7.0-beta](https://gitee.com/mindspore/docs/tree/r0.7/install)   
    [0.6.0-beta](https://gitee.com/mindspore/docs/tree/r0.6/install)    [0.5.2-beta](https://gitee.com/mindspore/docs/tree/r0.5/install)    [0.3.0-alpha](https://gitee.com/mindspore/docs/tree/r0.3/install)    [0.2.0-alpha](https://gitee.com/mindspore/docs/tree/r0.2/install)    [0.1.0-alpha](https://gitee.com/mindspore/docs/tree/r0.1/install) | +| Tutorials | | [2.3.1](https://www.mindspore.cn/tutorials/en/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/tutorials/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/tutorials/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/tutorials/en/r2.3.0rc1/index.html)    [2.2.14](https://mindspore.cn/tutorials/en/r2.2/index.html)    [2.1.1](https://mindspore.cn/tutorials/en/r2.1/index.html)    [2.0.0](https://mindspore.cn/tutorials/en/r2.0/index.html)    [2.0.0-alpha](https://mindspore.cn/tutorials/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/tutorials/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/tutorials/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/tutorials/en/r1.8/index.html)   
    [1.7.1](https://www.mindspore.cn/tutorials/en/r1.7/index.html)    [1.6.2](https://www.mindspore.cn/tutorials/en/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/tutorials/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/tutorials/en/r1.3/index.html)    [1.2.1-Training](https://www.mindspore.cn/tutorial/training/en/r1.2/index.html)    [1.2.1-Inference](https://www.mindspore.cn/tutorial/inference/en/r1.2/index.html)   
    [1.2.1-Mobile Phone&IoT](https://www.mindspore.cn/tutorial/lite/en/r1.2/index.html)    [1.1.1-Training](https://www.mindspore.cn/tutorial/training/en/r1.1/index.html)    [1.1.1-Inference](https://www.mindspore.cn/tutorial/inference/en/r1.1/index.html)   
    [1.1.1-Mobile Phone&IoT](https://www.mindspore.cn/tutorial/lite/en/r1.1/index.html)    [1.0.1-Training](https://www.mindspore.cn/tutorial/training/en/r1.0/index.html)    [1.0.1-Inference](https://www.mindspore.cn/tutorial/inference/en/r1.0/index.html)   
    [1.0.0-Mobile Phone&IoT](https://www.mindspore.cn/tutorial/lite/en/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/tutorial/en/r0.7/index.html)    [0.7.0-beta-Mobile Phone&IoT](https://www.mindspore.cn/lite/tutorial/en/r0.7/index.html)   
    [0.6.0-beta](https://www.mindspore.cn/tutorial/en/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/tutorial/en/r0.5/index.html)   [0.3.0-alpha](https://www.mindspore.cn/tutorial/en/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/tutorial/en/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/tutorial/en/0.1.0-alpha/index.html)   
    [master](https://www.mindspore.cn/tutorials/en/master/index.html) | +| Docs |MindSpore | [2.3.1](https://www.mindspore.cn/docs/en/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/docs/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/docs/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/docs/en/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/docs/en/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/docs/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/docs/en/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/docs/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/docs/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/docs/en/r1.8/index.html)   
    [1.7.1](https://www.mindspore.cn/docs/en/r1.7/index.html)    [1.6.2](https://www.mindspore.cn/docs/programming_guide/en/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/programming_guide/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/programming_guide/en/r1.3/index.html)    [1.2.1-Programming Guide](https://www.mindspore.cn/doc/programming_guide/en/r1.2/index.html)   
    [1.2.1-Design&Specification](https://www.mindspore.cn/doc/note/en/r1.2/index.html)    [1.2.1-FAQ](https://www.mindspore.cn/doc/faq/en/r1.2/index.html)    [1.1.1-Programming Guide](https://www.mindspore.cn/doc/programming_guide/en/r1.1/index.html)   
    [1.1.1-Design&Specification](https://www.mindspore.cn/doc/note/en/r1.1/index.html)    [1.1.1-FAQ](https://www.mindspore.cn/doc/faq/en/r1.1/index.html)    [1.0.1-Programming Guide](https://www.mindspore.cn/doc/programming_guide/en/r1.0/index.html)   
    [1.0.1-Design&Specification](https://www.mindspore.cn/doc/note/en/r1.0/index.html)    [1.0.1-FAQ](https://www.mindspore.cn/doc/faq/en/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/docs/en/r0.7/index.html)    [0.6.0-beta](https://www.mindspore.cn/docs/en/r0.6/index.html)   
    [0.5.2-beta](https://www.mindspore.cn/docs/en/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/docs/en/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/docs/en/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/docs/en/0.1.0-alpha/index.html)    [master](https://www.mindspore.cn/docs/en/master/index.html) | +| |MindSpore Lite | [2.3.1](https://www.mindspore.cn/lite/docs/en/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/lite/docs/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/docs/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/docs/en/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/docs/en/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/docs/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/docs/en/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/docs/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/docs/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/docs/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/docs/en/r1.8/index.html)   
    [1.7.0](https://www.mindspore.cn/lite/docs/en/r1.7/index.html)    [1.6.1](https://www.mindspore.cn/lite/docs/en/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/docs/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/docs/en/r1.3/index.html)    [0.7.0-beta](https://www.mindspore.cn/lite/docs/en/r0.7/index.html)    [master](https://www.mindspore.cn/lite/docs/en/master/index.html) | | |MindSpore Insight | [2.3.0](https://www.mindspore.cn/mindinsight/docs/en/r2.3/index.html)    [2.2.10](https://www.mindspore.cn/mindinsight/docs/en/r2.2/index.html)    [2.1.0](https://www.mindspore.cn/mindinsight/docs/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/mindinsight/docs/en/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/mindinsight/docs/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/mindinsight/docs/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/mindinsight/docs/en/r1.9/index.html)    [1.8.0](https://www.mindspore.cn/mindinsight/docs/en/r1.8/index.html)   
    [1.7.0](https://www.mindspore.cn/mindinsight/docs/en/r1.7/index.html)    [1.6.1](https://www.mindspore.cn/mindinsight/docs/en/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/mindinsight/docs/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/mindinsight/docs/en/r1.3/index.html)    [master](https://www.mindspore.cn/mindinsight/docs/en/master/index.html) | | |MindSpore Hub | [1.9.0](https://www.mindspore.cn/hub/docs/en/r1.9/index.html)    [1.6.0](https://www.mindspore.cn/hub/docs/en/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/hub/docs/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/hub/docs/en/r1.3/index.html)    [master](https://www.mindspore.cn/hub/docs/en/master/index.html) | | |MindSpore Armour | [2.0.0](https://www.mindspore.cn/mindarmour/docs/en/r2.0/index.html)    [1.9.0](https://www.mindspore.cn/mindarmour/docs/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/mindarmour/docs/en/r1.8/index.html)    [1.7.0](https://www.mindspore.cn/mindarmour/docs/en/r1.7/index.html)    [1.6.0](https://www.mindspore.cn/mindarmour/docs/en/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/mindarmour/docs/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/mindarmour/docs/en/r1.3/index.html)    [master](https://www.mindspore.cn/mindarmour/docs/en/master/index.html) | @@ -81,14 +82,14 @@ | |MindSpore Flow | [0.2.0](https://mindspore.cn/mindflow/docs/en/r0.2/index.html)    [0.1.0](https://mindspore.cn/mindflow/docs/en/r0.1/index.html)    [0.1.0-alpha](https://mindspore.cn/mindflow/docs/en/r0.1.0-alpha/index.html)    [master](https://mindspore.cn/mindflow/docs/en/master/index.html) | | |MindSpore Reinforcement | [0.7.0](https://www.mindspore.cn/reinforcement/docs/en/r0.7/index.html)    [0.6.0](https://www.mindspore.cn/reinforcement/docs/en/r0.6/index.html)    [0.6.0-alpha](https://www.mindspore.cn/reinforcement/docs/en/r0.6.0-alpha/index.html)    [0.5.0](https://www.mindspore.cn/reinforcement/docs/en/r0.5/index.html)    [0.3.0](https://www.mindspore.cn/reinforcement/docs/en/r0.3/index.html)    [0.2.1](https://www.mindspore.cn/reinforcement/docs/en/r0.2/index.html)    [0.1.0](https://www.mindspore.cn/reinforcement/docs/en/r0.1/index.html)    [master](https://www.mindspore.cn/reinforcement/docs/en/master/index.html) | | |MindSpore Graph Learning | [0.2.0](https://www.mindspore.cn/graphlearning/docs/en/r0.2/index.html)    [0.2.0-alpha](https://www.mindspore.cn/graphlearning/docs/en/r0.2.0-alpha/index.html)    [0.1.0](https://www.mindspore.cn/graphlearning/docs/en/r0.1/index.html)    [master](https://www.mindspore.cn/graphlearning/docs/en/master/index.html) | -| |MindSpore Golden Stick | [0.4.0](https://www.mindspore.cn/golden_stick/docs/en/r0.4/index.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/en/r0.3/index.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/en/r0.3.0-alpha/index.html)    [0.2.0](http://www.mindspore.cn/golden_stick/docs/en/r0.2/index.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/en/r0.1/index.html)    [master](http://www.mindspore.cn/golden_stick/docs/en/master/index.html)| +| |MindSpore Golden Stick | [0.5.0](https://www.mindspore.cn/golden_stick/docs/en/r0.5.0/index.html)    [0.4.0](https://www.mindspore.cn/golden_stick/docs/en/r0.4/index.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/en/r0.3/index.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/en/r0.3.0-alpha/index.html)    [0.2.0](http://www.mindspore.cn/golden_stick/docs/en/r0.2/index.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/en/r0.1/index.html)    [master](http://www.mindspore.cn/golden_stick/docs/en/master/index.html)| | |MindSpore XAI | [1.8.1](https://www.mindspore.cn/xai/docs/en/r1.8/index.html)    [1.5.0](https://www.mindspore.cn/xai/docs/en/r1.5/index.html)    [master](https://www.mindspore.cn/xai/docs/en/master/index.html) | | |MindSpore Recommender | [0.3.0](https://mindspore.cn/recommender/docs/en/r0.3/index.html)    [0.2.0](https://mindspore.cn/recommender/docs/en/r0.2/index.html)    [master](https://mindspore.cn/recommender/docs/en/master/index.html) | | |MindSpore Dev Toolkit(IDE_PLUGING_VERSION_URL) | [2.2.0](https://www.mindspore.cn/devtoolkit/docs/en/r2.2/index.html)    [2.1.0](https://www.mindspore.cn/devtoolkit/docs/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/devtoolkit/docs/en/r2.0/index.html)    [1.8.0](http://www.mindspore.cn/devtoolkit/docs/en/r1.8/index.html)    [master](http://www.mindspore.cn/devtoolkit/docs/en/master/index.html)| | |MindSpore Pandas | [0.2.0](https://www.mindspore.cn/mindpandas/docs/en/r0.2/index.html)    [0.1.0](https://www.mindspore.cn/mindpandas/docs/en/r0.1/index.html)    [master](https://www.mindspore.cn//mindpandas/docs/en/master/index.html) | | |MindSpore Vision | [0.1.0](http://www.mindspore.cn/vision/docs/en/r0.1/index.html) | -| API |MindSpore | [2.3.0](https://www.mindspore.cn/docs/en/r2.3.0/api_python/mindspore.html)    [2.3.0rc2](https://www.mindspore.cn/docs/en/r2.3.0rc2/api_python/mindspore.html)    [2.3.0rc1](https://www.mindspore.cn/docs/en/r2.3.0rc1/api_python/mindspore.html)    [2.2.14](https://www.mindspore.cn/docs/en/r2.2/api_python/mindspore.html)    [2.1.1](https://www.mindspore.cn/docs/en/r2.1/api_python/mindspore.html)    [2.0.0](https://www.mindspore.cn/docs/en/r2.0/api_python/mindspore.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/en/r2.0.0-alpha/api_python/mindspore.html)    [1.10.1](https://www.mindspore.cn/docs/en/r1.10/api_python/mindspore.html)    [1.9.0](https://www.mindspore.cn/docs/en/r1.9/api_python/mindspore.html)    [1.8.1](https://www.mindspore.cn/docs/en/r1.8/api_python/mindspore.html)   
    [1.7.1](https://www.mindspore.cn/docs/en/r1.7/api_python/mindspore.html)    [1.6.2](https://www.mindspore.cn/docs/api/en/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/api/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/api/en/r1.3/index.html)    [1.2.1](https://www.mindspore.cn/doc/api_python/en/r1.2/index.html)    [1.1.1](https://www.mindspore.cn/doc/api_python/en/r1.1/index.html)    [1.0.1](https://www.mindspore.cn/doc/api_python/en/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/api/en/r0.7/index.html)   
    [0.6.0-beta](https://www.mindspore.cn/api/en/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/api/en/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/api/en/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/api/en/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/api/en/0.1.0-alpha/index.html)   
    [master](https://www.mindspore.cn/docs/en/master/api_python/mindspore.html) | -| |MindSpore Lite | [2.3.0](https://www.mindspore.cn/lite/api/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/api/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/api/en/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/api/en/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/api/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/api/en/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/api/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/api/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/api/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/api/en/r1.8/index.html)   
    [1.7.0](https://www.mindspore.cn/lite/api/en/r1.7/index.html)    [1.6.1](https://www.mindspore.cn/lite/api/en/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/api/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/api/en/r1.3/index.html)    [1.2.1-C++](https://www.mindspore.cn/doc/api_cpp/en/r1.2/index.html)    [1.2.1-Java](https://www.mindspore.cn/doc/api_java/en/r1.2/index.html)    [1.1.1-C++](https://www.mindspore.cn/doc/api_cpp/en/r1.1/index.html)   
    [1.1.1-Java](https://www.mindspore.cn/doc/api_java/en/r1.1/index.html)    [1.0.0](https://www.mindspore.cn/doc/api_cpp/en/r1.0/index.html)    [master](https://www.mindspore.cn/lite/api/en/master/index.html) | +| API |MindSpore | [2.3.1](https://www.mindspore.cn/docs/en/r2.3.1/api_python/mindspore.html)    [2.3.0](https://www.mindspore.cn/docs/en/r2.3.0/api_python/mindspore.html)    [2.3.0rc2](https://www.mindspore.cn/docs/en/r2.3.0rc2/api_python/mindspore.html)    [2.3.0rc1](https://www.mindspore.cn/docs/en/r2.3.0rc1/api_python/mindspore.html)    [2.2.14](https://www.mindspore.cn/docs/en/r2.2/api_python/mindspore.html)    [2.1.1](https://www.mindspore.cn/docs/en/r2.1/api_python/mindspore.html)    [2.0.0](https://www.mindspore.cn/docs/en/r2.0/api_python/mindspore.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/en/r2.0.0-alpha/api_python/mindspore.html)    [1.10.1](https://www.mindspore.cn/docs/en/r1.10/api_python/mindspore.html)    [1.9.0](https://www.mindspore.cn/docs/en/r1.9/api_python/mindspore.html)    [1.8.1](https://www.mindspore.cn/docs/en/r1.8/api_python/mindspore.html)   
    [1.7.1](https://www.mindspore.cn/docs/en/r1.7/api_python/mindspore.html)    [1.6.2](https://www.mindspore.cn/docs/api/en/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/api/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/api/en/r1.3/index.html)    [1.2.1](https://www.mindspore.cn/doc/api_python/en/r1.2/index.html)    [1.1.1](https://www.mindspore.cn/doc/api_python/en/r1.1/index.html)    [1.0.1](https://www.mindspore.cn/doc/api_python/en/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/api/en/r0.7/index.html)   
    [0.6.0-beta](https://www.mindspore.cn/api/en/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/api/en/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/api/en/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/api/en/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/api/en/0.1.0-alpha/index.html)   
    [master](https://www.mindspore.cn/docs/en/master/api_python/mindspore.html) | +| |MindSpore Lite |[2.3.1](https://www.mindspore.cn/lite/api/en/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/lite/api/en/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/api/en/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/api/en/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/api/en/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/api/en/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/api/en/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/api/en/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/api/en/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/api/en/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/api/en/r1.8/index.html)   
    [1.7.0](https://www.mindspore.cn/lite/api/en/r1.7/index.html)    [1.6.1](https://www.mindspore.cn/lite/api/en/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/api/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/api/en/r1.3/index.html)    [1.2.1-C++](https://www.mindspore.cn/doc/api_cpp/en/r1.2/index.html)    [1.2.1-Java](https://www.mindspore.cn/doc/api_java/en/r1.2/index.html)    [1.1.1-C++](https://www.mindspore.cn/doc/api_cpp/en/r1.1/index.html)   
    [1.1.1-Java](https://www.mindspore.cn/doc/api_java/en/r1.1/index.html)    [1.0.0](https://www.mindspore.cn/doc/api_cpp/en/r1.0/index.html)    [master](https://www.mindspore.cn/lite/api/en/master/index.html) | | |MindSpore Insight | [2.3.0](https://www.mindspore.cn/mindinsight/docs/en/r2.3/mindinsight.debugger.html)    [2.2.10](https://www.mindspore.cn/mindinsight/docs/en/r2.2/mindinsight.debugger.html)    [2.1.0](https://www.mindspore.cn/mindinsight/docs/en/r2.1/mindinsight.debugger.html)    [2.0.0](https://www.mindspore.cn/mindinsight/docs/en/r2.0/mindinsight.debugger.html)    [2.0.0-alpha](https://www.mindspore.cn/mindinsight/docs/en/r2.0.0-alpha/mindinsight.debugger.html)    [1.10.1](https://www.mindspore.cn/mindinsight/docs/en/r1.10/mindinsight.debugger.html)    [1.9.0](https://www.mindspore.cn/mindinsight/docs/en/r1.9/mindinsight.debugger.html)    [1.8.0](https://www.mindspore.cn/mindinsight/docs/en/r1.8/mindinsight.debugger.html)   
    [1.7.0](https://www.mindspore.cn/mindinsight/docs/en/r1.7/mindinsight.debugger.html)    [1.6.1](https://www.mindspore.cn/mindinsight/docs/en/r1.6/mindinsight.debugger.html) | | |MindSpore Hub | [1.9.0](https://www.mindspore.cn/hub/docs/en/r1.9/hub.html)    [1.6.0](https://www.mindspore.cn/hub/docs/en/r1.6/hub.html)    [1.5.0](https://www.mindspore.cn/hub/api/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/hub/api/en/r1.3/index.html)    [1.2.0](https://www.mindspore.cn/doc/api_python/en/r1.2/mindspore_hub/mindspore_hub.html)    [1.1.1](https://www.mindspore.cn/doc/api_python/en/r1.1/mindspore_hub/mindspore_hub.html)    [1.0.1](https://www.mindspore.cn/doc/api_python/en/r1.0/mindspore_hub/mindspore_hub.html)    [master](https://www.mindspore.cn/hub/docs/en/master/hub.html) | | |MindSpore Armour | [2.0.0](https://www.mindspore.cn/mindarmour/docs/en/r2.0/mindarmour.html)    [1.9.0](https://www.mindspore.cn/mindarmour/docs/en/r1.9/mindarmour.html)    [1.8.1](https://www.mindspore.cn/mindarmour/docs/en/r1.8/mindarmour.html)    [1.7.0](https://www.mindspore.cn/mindarmour/docs/en/r1.7/mindarmour.html)    [1.6.0](https://www.mindspore.cn/mindarmour/docs/en/r1.6/mindarmour.html)    [1.5.0](https://www.mindspore.cn/mindarmour/api/en/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/mindarmour/api/en/r1.3/index.html)    [1.2.1](https://www.mindspore.cn/doc/api_python/en/r1.2/mindarmour/mindarmour.html)   
    [1.1.1](https://www.mindspore.cn/doc/api_python/en/r1.1/mindarmour/mindarmour.html)    [1.0.1](https://www.mindspore.cn/doc/api_python/en/r1.0/mindarmour/mindarmour.html)    [0.7.0-beta](https://www.mindspore.cn/api/en/r0.7/api/python/mindarmour/mindarmour.html)    [0.6.0-beta](https://www.mindspore.cn/api/en/r0.6/api/python/mindarmour/mindarmour.html)    [0.5.0-beta](https://www.mindspore.cn/api/en/r0.5/api/python/mindarmour/mindarmour.html)    [0.3.0-alpha](https://www.mindspore.cn/api/en/0.3.0-alpha/api/python/mindarmour/mindarmour.html)   
    [0.2.0-alpha](https://www.mindspore.cn/api/en/0.2.0-alpha/api/python/mindarmour/mindarmour.html)    [0.1.0-alpha](https://www.mindspore.cn/api/en/0.1.0-alpha/api/python/mindarmour/mindarmour.html)    [master](https://www.mindspore.cn/mindarmour/docs/en/master/mindarmour.html) | @@ -104,7 +105,7 @@ | |MindSpore Flow | [0.2.0](https://mindspore.cn/mindflow/docs/en/r0.2/mindflow.cell.html)    [0.1.0](https://mindspore.cn/mindflow/docs/en/r0.1/mindflow.cell.html)    [0.1.0-alpha](https://mindspore.cn/mindflow/docs/en/r0.1.0-alpha/mindflow.cell.html)    [master](https://mindspore.cn/mindflow/docs/en/master/mindflow.cell.html) | | |MindSpore Reinforcement | [0.7.0](https://www.mindspore.cn/reinforcement/docs/en/r0.7/reinforcement.html)    [0.6.0](https://www.mindspore.cn/reinforcement/docs/en/r0.6/reinforcement.html)    [0.6.0-alpha](https://www.mindspore.cn/reinforcement/docs/en/r0.6.0-alpha/reinforcement.html)    [0.5.0](https://www.mindspore.cn/reinforcement/docs/en/r0.5/reinforcement.html)    [0.3.0](https://www.mindspore.cn/reinforcement/docs/en/r0.3/reinforcement.html)    [0.2.1](https://www.mindspore.cn/reinforcement/docs/en/r0.2/reinforcement.html)    [0.1.0](https://www.mindspore.cn/reinforcement/api/en/r0.1/index.html)    [master](https://www.mindspore.cn/reinforcement/docs/en/master/reinforcement.html) | | |MindSpore Graph Learning | [0.2.0](https://www.mindspore.cn/graphlearning/docs/en/r0.2/mindspore_gl.dataset.html)    [0.2.0-alpha](https://www.mindspore.cn/graphlearning/docs/en/r0.2.0-alpha/mindspore_gl.dataset.html)    [0.1.0](https://www.mindspore.cn/graphlearning/docs/en/r0.1/mindspore_gl.dataset.html)    [master](https://www.mindspore.cn/graphlearning/docs/en/master/mindspore_gl.dataset.html) | -| |MindSpore Golden Stick | [0.4.0](https://www.mindspore.cn/golden_stick/docs/en/r0.4/mindspore_gs.quantization.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/en/r0.3/mindspore_gs.quantization.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/en/r0.3.0-alpha/mindspore_gs.quantization.html)    [0.2.0](http://www.mindspore.cn/golden_stick/docs/en/r0.2/mindspore_gs.quantization.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/en/r0.1/mindspore_gs.html)    [master](http://www.mindspore.cn/golden_stick/docs/en/master/mindspore_gs.html)| +| |MindSpore Golden Stick | [0.5.0](https://www.mindspore.cn/golden_stick/docs/en/r0.5.0/mindspore_gs.quantization.html)    [0.4.0](https://www.mindspore.cn/golden_stick/docs/en/r0.4/mindspore_gs.quantization.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/en/r0.3/mindspore_gs.quantization.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/en/r0.3.0-alpha/mindspore_gs.quantization.html)    [0.2.0](http://www.mindspore.cn/golden_stick/docs/en/r0.2/mindspore_gs.quantization.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/en/r0.1/mindspore_gs.html)    [master](http://www.mindspore.cn/golden_stick/docs/en/master/mindspore_gs.html)| | |MindSpore XAI | [1.8.1](https://www.mindspore.cn/xai/docs/en/r1.8/mindspore_xai.explainer.html)    [1.5.0](https://www.mindspore.cn/xai/api/en/r1.5/index.html)    [master](https://www.mindspore.cn/xai/docs/en/master/mindspore_xai.explainer.html) | | |MindSpore Recommender | [0.3.0](https://www.mindspore.cn/recommender/docs/en/r0.3/recommender.html)    [0.2.0](https://www.mindspore.cn/recommender/docs/en/r0.2/recommender.html)    [master](https://www.mindspore.cn/recommender/docs/en/master/recommender.html) | | |MindSpore Pandas | [0.2.0](https://www.mindspore.cn/mindpandas/docs/en/r0.2/mindpandas.config.html)    [0.1.0](https://www.mindspore.cn/mindpandas/docs/en/r0.1/mindpandas.config.html)    [master](https://www.mindspore.cn//mindpandas/docs/en/master/mindpandas.config.html) | @@ -114,6 +115,7 @@ | MindSpore Version | Hardware Platform | Commercial edition Installation Guide | Community edition download link (refer to commercial edition for instructions) | |-------------|--------|-----------|------------------| +| 2.3.1 | Ascend | TBD | [CANN 8.0.RC2.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [firmware and driver](https://www.hiascend.com/hardware/firmware-drivers/community) | | 2.3.0 | Ascend | TBD | [CANN 8.0.RC2.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [firmware and driver](https://www.hiascend.com/hardware/firmware-drivers/community) | | 2.3.0-rc2 | Ascend | [Ascend Training Solution 24.0.RC1](https://support.huawei.com/enterprise/zh/doc/EDOC1100373131) | [CANN 8.0.RC1.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [firmware and driver](https://www.hiascend.com/hardware/firmware-drivers/community) | | 2.3.0-rc1 | Ascend | [Ascend Training Solution 24.0.RC1](https://support.huawei.com/enterprise/zh/doc/EDOC1100373131) | [CANN 8.0.RC1.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [firmware and driver](https://www.hiascend.com/hardware/firmware-drivers/community) | @@ -167,6 +169,19 @@ ## Downloads +### 2.3.1 + +| Module Name | Hardware Platform | Operating System | Python Version | Download Links | SHA-256 | +|------------------------------|--------|---------------|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------| +| MindSpore | Ascend | Linux-aarch64 | Python3.8 | [mindspore-2.3.1-cp38-cp38-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/aarch64/mindspore-2.3.1-cp38-cp38-linux_aarch64.whl) | 976854b9e0c2535541cacb6e1b0b887595fd7aaa03572670b148d1846b08d339 | +| | | | Python3.9 | [mindspore-2.3.1-cp39-cp39-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/aarch64/mindspore-2.3.1-cp39-cp39-linux_aarch64.whl) | 5fe6a476a7a718c413ac66db71ba93bfe2d6870e13ef90f10652a27170ed338e | +| | | | Python3.10 | [mindspore-2.3.1-cp310-cp310-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/aarch64/mindspore-2.3.1-cp310-cp310-linux_aarch64.whl) | d9be757fa42b30e546920b5dffe76527f3f94e9aac88b262174ecd2a0f32c2e0 | +| | Ascend | Linux-x86_64 | Python3.8 | [mindspore-2.3.1-cp38-cp38-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/x86_64/mindspore-2.3.1-cp38-cp38-linux_x86_64.whl) | f7d19669517be1624d3475a6b22b54f2bc730b998eefd6020a9c9d6ef9d09dee | +| | | | Python3.9 | [mindspore-2.3.1-cp39-cp39-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/x86_64/mindspore-2.3.1-cp39-cp39-linux_x86_64.whl) | 291ce96deb150445dfb6648998276fa0389264c822abddce58bd93ef65fdd993 | +| | | | Python3.10 | [mindspore-2.3.1-cp310-cp310-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/x86_64/mindspore-2.3.1-cp310-cp310-linux_x86_64.whl) | 568fc4a52e60f3087e9e0399fa9eed9ff0338bd08ecbcd9c101f2db39ee5fb01 | +|MindSpore
    Lite | | | | [Installation Packages Links](https://www.mindspore.cn/lite/docs/en/r2.3.1/use/downloads.html#2-3-1) | | +| MindSpore
    Golden
    Stick | | any | Python3 | [mindspore_gs-0.5.0-py3-none-any.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/GoldenStick/any/mindspore_gs-0.5.0-py3-none-any.whl) | eb1c37e35468fef1e4ff1237ab88b1d718acd47f65117ec532bdb04da9d5372b | + ### 2.3.0 | Module Name | Hardware Platform | Operating System | Python Version | Download Links | SHA-256 | diff --git a/resource/release/release_list_zh_cn.md b/resource/release/release_list_zh_cn.md index 81ab11fb85e4a589292fa3b44e608b3b8f27f3fe..2067c943c8bbbb1058fe945c66f42dfb1c3e5aaf 100644 --- a/resource/release/release_list_zh_cn.md +++ b/resource/release/release_list_zh_cn.md @@ -6,6 +6,7 @@ - [配套资料](#配套资料) - [Ascend配套软件包](#ascend配套软件包) - [下载地址](#下载地址) + - [2.3.1](#231) - [2.3.0](#230) - [2.3.0-rc2](#230-rc2) - [2.3.0-rc1](#230-rc1) @@ -61,11 +62,11 @@ | 类别 | 子类别 | 版本 | | --- | --- | --- | -| 版本说明和接口变更 | | [2.3.0](https://gitee.com/mindspore/mindspore/blob/master/RELEASE_CN.md#mindspore-230-release-notes)    [2.3.0-rc2](https://gitee.com/mindspore/mindspore/blob/master/RELEASE_CN.md#mindspore-230-rc2-release-notes)    [2.3.0-rc1](https://gitee.com/mindspore/mindspore/blob/master/RELEASE_CN.md#mindspore-230-rc1-release-notes)    [2.2.14](https://gitee.com/mindspore/mindspore/blob/r2.2/RELEASE_CN.md#)    [2.1.1](https://gitee.com/mindspore/mindspore/blob/r2.1/RELEASE_CN.md#)    [2.0.0](https://gitee.com/mindspore/mindspore/blob/r2.0/RELEASE_CN.md#)    [2.0.0-alpha](https://gitee.com/mindspore/mindspore/blob/r2.0.0-alpha/RELEASE_CN.md#)    [1.10.1](https://gitee.com/mindspore/mindspore/blob/r1.10/RELEASE_CN.md#)    [1.9.0](https://gitee.com/mindspore/mindspore/blob/r1.9/RELEASE_CN.md#)    [1.8.1](https://gitee.com/mindspore/mindspore/blob/r1.8/RELEASE_CN.md#)    [1.7.1](https://gitee.com/mindspore/mindspore/blob/r1.7/RELEASE_CN.md#)   
    [1.6.2](https://gitee.com/mindspore/mindspore/blob/r1.6/RELEASE.md#)    [1.5.2](https://gitee.com/mindspore/mindspore/blob/r1.5/RELEASE.md#)    [1.3.0](https://gitee.com/mindspore/mindspore/blob/r1.3/RELEASE.md#)    [1.2.1](https://gitee.com/mindspore/mindspore/blob/r1.2/RELEASE.md#)    [1.1.1](https://gitee.com/mindspore/mindspore/blob/r1.1/RELEASE.md#)    [1.0.1](https://gitee.com/mindspore/mindspore/blob/r1.0/RELEASE.md#)    [0.7.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.7/RELEASE.md#)    [0.6.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.6/RELEASE.md#)   
    [0.5.2-beta](https://gitee.com/mindspore/mindspore/blob/r0.5/RELEASE.md#)    [0.3.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.3/RELEASE.md#)    [0.2.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.2/RELEASE.md#)    [0.1.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.1/RELEASE.md#)| -| 安装 | | [2.3.0](https://gitee.com/mindspore/docs/tree/r2.3.0/install)    [2.3.0-rc2](https://gitee.com/mindspore/docs/tree/r2.3.0rc2/install)   [2.3.0-rc1](https://gitee.com/mindspore/docs/tree/r2.3.q1/install)    [2.2.14](https://gitee.com/mindspore/docs/tree/r2.2/install)    [2.1.1](https://gitee.com/mindspore/docs/tree/r2.1/install)    [2.0.0](https://gitee.com/mindspore/docs/tree/r2.0/install)    [2.0.0-alpha](https://gitee.com/mindspore/docs/tree/r2.0.0-alpha/install)    [1.10.1](https://gitee.com/mindspore/docs/tree/r1.10/install)    [1.9.0](https://gitee.com/mindspore/docs/tree/r1.9/install)    [1.8.1](https://gitee.com/mindspore/docs/tree/r1.8/install)    [1.7.1](https://gitee.com/mindspore/docs/tree/r1.7/install)   
    [1.6.2](https://gitee.com/mindspore/docs/tree/r1.6/install)    [1.5.2](https://gitee.com/mindspore/docs/tree/r1.5/install)    [1.3.0](https://gitee.com/mindspore/docs/tree/r1.3/install)    [1.2.1](https://gitee.com/mindspore/docs/tree/r1.2/install)    [1.1.1](https://gitee.com/mindspore/docs/tree/r1.1/install)    [1.0.1](https://gitee.com/mindspore/docs/tree/r1.0/install)    [0.7.0-beta](https://gitee.com/mindspore/docs/tree/r0.7/install)    [0.6.0-beta](https://gitee.com/mindspore/docs/tree/r0.6/install)   
    [0.5.2-beta](https://gitee.com/mindspore/docs/tree/r0.5/install)    [0.3.0-alpha](https://gitee.com/mindspore/docs/tree/r0.3/install)    [0.2.0-alpha](https://gitee.com/mindspore/docs/tree/r0.2/install)    [0.1.0-alpha](https://gitee.com/mindspore/docs/tree/r0.1/install)| -| 教程 | | [2.3.0](https://www.mindspore.cn/tutorials/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/tutorials/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/tutorials/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/tutorials/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/tutorials/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/tutorials/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/tutorials/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/tutorials/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/tutorials/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/tutorials/zh-CN/r1.8/index.html)    [1.7.1](https://www.mindspore.cn/tutorials/zh-CN/r1.7/index.html)   
    [1.6.2](https://www.mindspore.cn/tutorials/zh-CN/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/tutorials/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/tutorials/zh-CN/r1.3/index.html)    [1.2.1-训练](https://www.mindspore.cn/tutorial/training/zh-CN/r1.2/index.html)    [1.2.1-推理](https://www.mindspore.cn/tutorial/inference/zh-CN/r1.2/index.html)    [1.2.1-手机&IoT](https://www.mindspore.cn/tutorial/lite/zh-CN/r1.2/index.html)    [1.1.1-训练](https://www.mindspore.cn/tutorial/training/zh-CN/r1.1/index.html)   
    [1.1.1-推理](https://www.mindspore.cn/tutorial/inference/zh-CN/r1.1/index.html)    [1.1.1-手机&IoT](https://www.mindspore.cn/tutorial/lite/zh-CN/r1.1/index.html)    [1.0.1-训练](https://www.mindspore.cn/tutorial/training/zh-CN/r1.0/index.html)    [1.0.1-推理](https://www.mindspore.cn/tutorial/inference/zh-CN/r1.0/index.html)    [1.0.0-手机&IoT](https://www.mindspore.cn/tutorial/lite/zh-CN/r1.0/index.html)  
    [0.7.0-beta](https://www.mindspore.cn/tutorial/zh-CN/r0.7/index.html)    [0.7.0-beta手机&IoT](https://www.mindspore.cn/lite/tutorial/zh-CN/r0.7/index.html)    [0.6.0-beta](https://www.mindspore.cn/tutorial/zh-CN/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/tutorial/zh-CN/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/tutorial/zh-CN/0.3.0-alpha/index.html)   
    [0.2.0-alpha](https://www.mindspore.cn/tutorial/zh-CN/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/tutorial/zh-CN/0.1.0-alpha/index.html)    [master](https://www.mindspore.cn/tutorials/zh-CN/master/index.html) | -| 文档 |MindSpore | [2.3.0](https://www.mindspore.cn/docs/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/docs/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/docs/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/docs/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/docs/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/docs/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/docs/zh-CN/r1.8/index.html)    [1.7.1](https://www.mindspore.cn/docs/zh-CN/r1.7/index.html)   
    [1.6.2](https://www.mindspore.cn/docs/programming_guide/zh-CN/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/programming_guide/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/programming_guide/zh-CN/r1.3/index.html)    [1.2.1-编程指南](https://www.mindspore.cn/doc/programming_guide/zh-CN/r1.2/index.html)    [1.2.1-设计和规格](https://www.mindspore.cn/doc/note/zh-CN/r1.2/index.html)    [1.2.1-FAQ](https://www.mindspore.cn/doc/faq/zh-CN/r1.2/index.html)   
    [1.1.1-编程指南](https://www.mindspore.cn/doc/programming_guide/zh-CN/r1.1/index.html)    [1.1.1-设计和规格](https://www.mindspore.cn/doc/note/zh-CN/r1.1/index.html)    [1.1.1-FAQ](https://www.mindspore.cn/doc/faq/zh-CN/r1.1/index.html)    [1.0.1-编程指南](https://www.mindspore.cn/doc/programming_guide/zh-CN/r1.0/index.html)   
    [1.0.1-设计和规格](https://www.mindspore.cn/doc/note/zh-CN/r1.0/index.html)    [1.0.1-FAQ](https://www.mindspore.cn/doc/faq/zh-CN/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/docs/zh-CN/r0.7/index.html)    [0.6.0-beta](https://www.mindspore.cn/docs/zh-CN/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/docs/zh-CN/r0.5/index.html)   
    [0.3.0-alpha](https://www.mindspore.cn/docs/zh-CN/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/docs/zh-CN/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/docs/zh-CN/0.1.0-alpha/index.html)    [master](https://www.mindspore.cn/docs/zh-CN/master/index.html) | -| |MindSpore Lite | [2.3.0](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/docs/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/docs/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/docs/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/docs/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/docs/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/docs/zh-CN/r1.8/index.html)    [1.7.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.7/index.html)   
    [1.6.1](https://www.mindspore.cn/lite/docs/zh-CN/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.3/index.html)    [0.7.0-beta](https://www.mindspore.cn/lite/docs/zh-CN/r0.7/index.html)    [master](https://www.mindspore.cn/lite/docs/zh-CN/master/index.html) | +| 版本说明和接口变更 | |[2.3.1](https://gitee.com/mindspore/mindspore/blob/master/RELEASE_CN.md#mindspore-231-release-notes)    [2.3.0](https://gitee.com/mindspore/mindspore/blob/master/RELEASE_CN.md#mindspore-230-release-notes)    [2.3.0-rc2](https://gitee.com/mindspore/mindspore/blob/master/RELEASE_CN.md#mindspore-230-rc2-release-notes)    [2.3.0-rc1](https://gitee.com/mindspore/mindspore/blob/master/RELEASE_CN.md#mindspore-230-rc1-release-notes)    [2.2.14](https://gitee.com/mindspore/mindspore/blob/r2.2/RELEASE_CN.md#)    [2.1.1](https://gitee.com/mindspore/mindspore/blob/r2.1/RELEASE_CN.md#)    [2.0.0](https://gitee.com/mindspore/mindspore/blob/r2.0/RELEASE_CN.md#)    [2.0.0-alpha](https://gitee.com/mindspore/mindspore/blob/r2.0.0-alpha/RELEASE_CN.md#)    [1.10.1](https://gitee.com/mindspore/mindspore/blob/r1.10/RELEASE_CN.md#)    [1.9.0](https://gitee.com/mindspore/mindspore/blob/r1.9/RELEASE_CN.md#)    [1.8.1](https://gitee.com/mindspore/mindspore/blob/r1.8/RELEASE_CN.md#)    [1.7.1](https://gitee.com/mindspore/mindspore/blob/r1.7/RELEASE_CN.md#)   
    [1.6.2](https://gitee.com/mindspore/mindspore/blob/r1.6/RELEASE.md#)    [1.5.2](https://gitee.com/mindspore/mindspore/blob/r1.5/RELEASE.md#)    [1.3.0](https://gitee.com/mindspore/mindspore/blob/r1.3/RELEASE.md#)    [1.2.1](https://gitee.com/mindspore/mindspore/blob/r1.2/RELEASE.md#)    [1.1.1](https://gitee.com/mindspore/mindspore/blob/r1.1/RELEASE.md#)    [1.0.1](https://gitee.com/mindspore/mindspore/blob/r1.0/RELEASE.md#)    [0.7.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.7/RELEASE.md#)    [0.6.0-beta](https://gitee.com/mindspore/mindspore/blob/r0.6/RELEASE.md#)   
    [0.5.2-beta](https://gitee.com/mindspore/mindspore/blob/r0.5/RELEASE.md#)    [0.3.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.3/RELEASE.md#)    [0.2.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.2/RELEASE.md#)    [0.1.0-alpha](https://gitee.com/mindspore/mindspore/blob/r0.1/RELEASE.md#)| +| 安装 | | [2.3.1](https://gitee.com/mindspore/docs/tree/r2.3.1/install)    [2.3.0](https://gitee.com/mindspore/docs/tree/r2.3.0/install)    [2.3.0-rc2](https://gitee.com/mindspore/docs/tree/r2.3.0rc2/install)   [2.3.0-rc1](https://gitee.com/mindspore/docs/tree/r2.3.q1/install)    [2.2.14](https://gitee.com/mindspore/docs/tree/r2.2/install)    [2.1.1](https://gitee.com/mindspore/docs/tree/r2.1/install)    [2.0.0](https://gitee.com/mindspore/docs/tree/r2.0/install)    [2.0.0-alpha](https://gitee.com/mindspore/docs/tree/r2.0.0-alpha/install)    [1.10.1](https://gitee.com/mindspore/docs/tree/r1.10/install)    [1.9.0](https://gitee.com/mindspore/docs/tree/r1.9/install)    [1.8.1](https://gitee.com/mindspore/docs/tree/r1.8/install)    [1.7.1](https://gitee.com/mindspore/docs/tree/r1.7/install)   
    [1.6.2](https://gitee.com/mindspore/docs/tree/r1.6/install)    [1.5.2](https://gitee.com/mindspore/docs/tree/r1.5/install)    [1.3.0](https://gitee.com/mindspore/docs/tree/r1.3/install)    [1.2.1](https://gitee.com/mindspore/docs/tree/r1.2/install)    [1.1.1](https://gitee.com/mindspore/docs/tree/r1.1/install)    [1.0.1](https://gitee.com/mindspore/docs/tree/r1.0/install)    [0.7.0-beta](https://gitee.com/mindspore/docs/tree/r0.7/install)    [0.6.0-beta](https://gitee.com/mindspore/docs/tree/r0.6/install)   
    [0.5.2-beta](https://gitee.com/mindspore/docs/tree/r0.5/install)    [0.3.0-alpha](https://gitee.com/mindspore/docs/tree/r0.3/install)    [0.2.0-alpha](https://gitee.com/mindspore/docs/tree/r0.2/install)    [0.1.0-alpha](https://gitee.com/mindspore/docs/tree/r0.1/install)| +| 教程 | | [2.3.1](https://www.mindspore.cn/tutorials/zh-CN/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/tutorials/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/tutorials/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/tutorials/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/tutorials/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/tutorials/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/tutorials/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/tutorials/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/tutorials/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/tutorials/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/tutorials/zh-CN/r1.8/index.html)    [1.7.1](https://www.mindspore.cn/tutorials/zh-CN/r1.7/index.html)   
    [1.6.2](https://www.mindspore.cn/tutorials/zh-CN/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/tutorials/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/tutorials/zh-CN/r1.3/index.html)    [1.2.1-训练](https://www.mindspore.cn/tutorial/training/zh-CN/r1.2/index.html)    [1.2.1-推理](https://www.mindspore.cn/tutorial/inference/zh-CN/r1.2/index.html)    [1.2.1-手机&IoT](https://www.mindspore.cn/tutorial/lite/zh-CN/r1.2/index.html)    [1.1.1-训练](https://www.mindspore.cn/tutorial/training/zh-CN/r1.1/index.html)   
    [1.1.1-推理](https://www.mindspore.cn/tutorial/inference/zh-CN/r1.1/index.html)    [1.1.1-手机&IoT](https://www.mindspore.cn/tutorial/lite/zh-CN/r1.1/index.html)    [1.0.1-训练](https://www.mindspore.cn/tutorial/training/zh-CN/r1.0/index.html)    [1.0.1-推理](https://www.mindspore.cn/tutorial/inference/zh-CN/r1.0/index.html)    [1.0.0-手机&IoT](https://www.mindspore.cn/tutorial/lite/zh-CN/r1.0/index.html)  
    [0.7.0-beta](https://www.mindspore.cn/tutorial/zh-CN/r0.7/index.html)    [0.7.0-beta手机&IoT](https://www.mindspore.cn/lite/tutorial/zh-CN/r0.7/index.html)    [0.6.0-beta](https://www.mindspore.cn/tutorial/zh-CN/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/tutorial/zh-CN/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/tutorial/zh-CN/0.3.0-alpha/index.html)   
    [0.2.0-alpha](https://www.mindspore.cn/tutorial/zh-CN/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/tutorial/zh-CN/0.1.0-alpha/index.html)    [master](https://www.mindspore.cn/tutorials/zh-CN/master/index.html) | +| 文档 |MindSpore | [2.3.1](https://www.mindspore.cn/docs/zh-CN/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/docs/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/docs/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/docs/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/docs/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/docs/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/docs/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/docs/zh-CN/r1.8/index.html)    [1.7.1](https://www.mindspore.cn/docs/zh-CN/r1.7/index.html)   
    [1.6.2](https://www.mindspore.cn/docs/programming_guide/zh-CN/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/programming_guide/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/programming_guide/zh-CN/r1.3/index.html)    [1.2.1-编程指南](https://www.mindspore.cn/doc/programming_guide/zh-CN/r1.2/index.html)    [1.2.1-设计和规格](https://www.mindspore.cn/doc/note/zh-CN/r1.2/index.html)    [1.2.1-FAQ](https://www.mindspore.cn/doc/faq/zh-CN/r1.2/index.html)   
    [1.1.1-编程指南](https://www.mindspore.cn/doc/programming_guide/zh-CN/r1.1/index.html)    [1.1.1-设计和规格](https://www.mindspore.cn/doc/note/zh-CN/r1.1/index.html)    [1.1.1-FAQ](https://www.mindspore.cn/doc/faq/zh-CN/r1.1/index.html)    [1.0.1-编程指南](https://www.mindspore.cn/doc/programming_guide/zh-CN/r1.0/index.html)   
    [1.0.1-设计和规格](https://www.mindspore.cn/doc/note/zh-CN/r1.0/index.html)    [1.0.1-FAQ](https://www.mindspore.cn/doc/faq/zh-CN/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/docs/zh-CN/r0.7/index.html)    [0.6.0-beta](https://www.mindspore.cn/docs/zh-CN/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/docs/zh-CN/r0.5/index.html)   
    [0.3.0-alpha](https://www.mindspore.cn/docs/zh-CN/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/docs/zh-CN/0.2.0-alpha/index.html)    [0.1.0-alpha](https://www.mindspore.cn/docs/zh-CN/0.1.0-alpha/index.html)    [master](https://www.mindspore.cn/docs/zh-CN/master/index.html) | +| |MindSpore Lite | [2.3.1](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/docs/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/docs/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/docs/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/docs/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/docs/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/docs/zh-CN/r1.8/index.html)    [1.7.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.7/index.html)   
    [1.6.1](https://www.mindspore.cn/lite/docs/zh-CN/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/docs/zh-CN/r1.3/index.html)    [0.7.0-beta](https://www.mindspore.cn/lite/docs/zh-CN/r0.7/index.html)    [master](https://www.mindspore.cn/lite/docs/zh-CN/master/index.html) | | |MindSpore Insight | [2.3.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.3/index.html)    [2.2.10](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.2/index.html)    [2.1.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.9/index.html)    [1.8.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.8/index.html)    [1.7.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.7/index.html)   
    [1.6.1](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.3/index.html)    [master](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/index.html) | | |MindSpore Hub | [1.9.0](https://www.mindspore.cn/hub/docs/zh-CN/r1.9/index.html)    [1.6.0](https://www.mindspore.cn/hub/docs/zh-CN/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/hub/docs/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/hub/docs/zh-CN/r1.3/index.html)    [master](https://www.mindspore.cn/hub/docs/zh-CN/master/index.html) | | |MindSpore Armour | [2.0.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r2.0/index.html)    [1.9.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.8/index.html)    [1.7.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.7/index.html)    [1.6.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.3/index.html)   
    [master](https://www.mindspore.cn/mindarmour/docs/zh-CN/master/index.html) | @@ -81,15 +82,15 @@ | |MindSpore Flow | [0.2.0](https://mindspore.cn/mindflow/docs/zh-CN/r0.2/index.html)    [0.1.0](https://mindspore.cn/mindflow/docs/zh-CN/r0.1/index.html)    [0.1.0-alpha](https://mindspore.cn/mindflow/docs/zh-CN/r0.1.0-alpha/index.html)    [master](https://mindspore.cn/mindflow/docs/zh-CN/master/index.html) | | |MindSpore Reinforcement | [0.7.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.7/index.html)    [0.6.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.6/index.html)    [0.6.0-alpha](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.6.0-alpha/index.html)    [0.5.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.5/index.html)    [0.3.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.3/index.html)    [0.2.1](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.2/index.html)    [0.1.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.1/index.html)    [master](https://www.mindspore.cn/reinforcement/docs/zh-CN/master/index.html) | | |MindSpore Graph Learning | [0.2.0](https://www.mindspore.cn/graphlearning/docs/zh-CN/r0.2/index.html)    [0.2.0-alpha](https://www.mindspore.cn/graphlearning/docs/zh-CN/r0.2.0-alpha/index.html)    [0.1.0](https://www.mindspore.cn/graphlearning/docs/zh-CN/r0.1/index.html)    [master](https://www.mindspore.cn/graphlearning/docs/zh-CN/master/index.html) | -| |MindSpore Golden Stick | [0.4.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.4/index.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3/index.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3.0-alpha/index.html)    [0.2.0](http://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/index.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/zh-CN/r0.1/index.html)    [master](http://www.mindspore.cn/golden_stick/docs/zh-CN/master/index.html)| +| |MindSpore Golden Stick | [0.5.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.5.0/index.html)    [0.4.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.4/index.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3/index.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3.0-alpha/index.html)    [0.2.0](http://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/index.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/zh-CN/r0.1/index.html)    [master](http://www.mindspore.cn/golden_stick/docs/zh-CN/master/index.html)| | |MindSpore XAI | [1.8.1](https://www.mindspore.cn/xai/docs/zh-CN/r1.8/index.html)    [1.5.0](https://www.mindspore.cn/xai/docs/zh-CN/r1.5/index.html)    [master](https://www.mindspore.cn/xai/docs/zh-CN/master/index.html) | | |MindSpore Recommender | [0.3.0](https://www.mindspore.cn/recommender/docs/zh-CN/r0.3/index.html)    [0.2.0](https://www.mindspore.cn/recommender/docs/zh-CN/r0.2/index.html)    [master](https://www.mindspore.cn/recommender/docs/zh-CN/master/index.html) | | |MindSpore Dev Toolkit(IDE_PLUGING_VERSION_URL) | [2.2.0](https://www.mindspore.cn/devtoolkit/docs/zh-CN/r2.2/index.html)    [2.1.0](https://www.mindspore.cn/devtoolkit/docs/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/devtoolkit/docs/zh-CN/r2.0/index.html)    [1.8.0](http://www.mindspore.cn/devtoolkit/docs/zh-CN/r1.8/index.html)    [master](http://www.mindspore.cn/devtoolkit/docs/zh-CN/master/index.html)| | |MindSpore Pandas | [0.2.0](https://www.mindspore.cn/mindpandas/docs/zh-CN/r0.2/index.html)    [0.1.0](https://www.mindspore.cn/mindpandas/docs/zh-CN/r0.1/index.html)    [master](https://www.mindspore.cn//mindpandas/docs/zh-CN/master/index.html) | | |MindSpore Vision | [0.1.0](http://www.mindspore.cn/vision/docs/zh-CN/r0.1/index.html) | -| API |MindSpore | [2.3.0](https://www.mindspore.cn/docs/zh-CN/r2.3.0/api_python/mindspore.html)    [2.3.0rc2](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc2/api_python/mindspore.html)    [2.3.0rc1](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc1/api_python/mindspore.html)    [2.2.14](https://www.mindspore.cn/docs/zh-CN/r2.2/api_python/mindspore.html)    [2.1.1](https://www.mindspore.cn/docs/zh-CN/r2.1/api_python/mindspore.html)    [2.0.0](https://www.mindspore.cn/docs/zh-CN/r2.0/api_python/mindspore.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/zh-CN/r2.0.0-alpha/api_python/mindspore.html)    [1.10.1](https://www.mindspore.cn/docs/zh-CN/r1.10/api_python/mindspore.html)    [1.9.0](https://www.mindspore.cn/docs/zh-CN/r1.9/api_python/mindspore.html)    [1.8.1](https://www.mindspore.cn/docs/zh-CN/r1.8/api_python/mindspore.html)    [1.7.1](https://www.mindspore.cn/docs/zh-CN/r1.7/api_python/mindspore.html)   
    [1.6.2](https://www.mindspore.cn/docs/api/zh-CN/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/api/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/api/zh-CN/r1.3/index.html)    [1.2.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.2/index.html)    [1.1.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.1/index.html)    [1.0.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/api/zh-CN/r0.7/index.html)   
    [0.6.0-beta](https://www.mindspore.cn/api/zh-CN/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/api/zh-CN/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/api/zh-CN/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/api/zh-CN/0.2.0-alpha/index.html)   
    [0.1.0-alpha](https://www.mindspore.cn/api/zh-CN/0.1.0-alpha/index.html)   [master](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.html) | -| |MindSpore Lite | [2.3.0](https://www.mindspore.cn/lite/api/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/api/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/api/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/api/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/api/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/api/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/api/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/api/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/api/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/api/zh-CN/r1.8/index.html)    [1.7.0](https://www.mindspore.cn/lite/api/zh-CN/r1.7/index.html)   
    [1.6.1](https://www.mindspore.cn/lite/api/zh-CN/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/api/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/api/zh-CN/r1.3/index.html)    [1.2.1-C++](https://www.mindspore.cn/doc/api_cpp/zh-CN/r1.2/index.html)    [1.2.1-Java](https://www.mindspore.cn/doc/api_java/zh-CN/r1.2/index.html)    [1.1.1-C++](https://www.mindspore.cn/doc/api_cpp/zh-CN/r1.1/index.html)   
    [1.1.1-Java](https://www.mindspore.cn/doc/api_java/zh-CN/r1.1/index.html)    [1.0.0](https://www.mindspore.cn/doc/api_cpp/zh-CN/r1.0/index.html)    [master](https://www.mindspore.cn/lite/api/zh-CN/master/index.html) | -| |MindSpore Insight | [2.3.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.3/mindinsight.debugger.html)    [2.2.10](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.2/mindinsight.debugger.html)    [2.1.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.1/mindinsight.debugger.html)    [2.0.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.0/mindinsight.debugger.html)    [2.0.0-alpha](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.0.0-alpha/mindinsight.debugger.html)    [1.10.1](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.10/mindinsight.debugger.html)    [1.9.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.9/mindinsight.debugger.html)    [1.8.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.8/mindinsight.debugger.html)    [1.7.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.7/mindinsight.debugger.html)   
    [1.6.1](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.6/mindinsight.debugger.html)    [master](https://www.mindspore.cn/mindinsight/docs/zh-CN/master/mindinsight.debugger.html) | +| API |MindSpore | [2.3.1](https://www.mindspore.cn/docs/zh-CN/r2.3.1/api_python/mindspore.html)    [2.3.0](https://www.mindspore.cn/docs/zh-CN/r2.3.0/api_python/mindspore.html)    [2.3.0rc2](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc2/api_python/mindspore.html)    [2.3.0rc1](https://www.mindspore.cn/docs/zh-CN/r2.3.0rc1/api_python/mindspore.html)    [2.2.14](https://www.mindspore.cn/docs/zh-CN/r2.2/api_python/mindspore.html)    [2.1.1](https://www.mindspore.cn/docs/zh-CN/r2.1/api_python/mindspore.html)    [2.0.0](https://www.mindspore.cn/docs/zh-CN/r2.0/api_python/mindspore.html)    [2.0.0-alpha](https://www.mindspore.cn/docs/zh-CN/r2.0.0-alpha/api_python/mindspore.html)    [1.10.1](https://www.mindspore.cn/docs/zh-CN/r1.10/api_python/mindspore.html)    [1.9.0](https://www.mindspore.cn/docs/zh-CN/r1.9/api_python/mindspore.html)    [1.8.1](https://www.mindspore.cn/docs/zh-CN/r1.8/api_python/mindspore.html)    [1.7.1](https://www.mindspore.cn/docs/zh-CN/r1.7/api_python/mindspore.html)   
    [1.6.2](https://www.mindspore.cn/docs/api/zh-CN/r1.6/index.html)    [1.5.2](https://www.mindspore.cn/docs/api/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/docs/api/zh-CN/r1.3/index.html)    [1.2.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.2/index.html)    [1.1.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.1/index.html)    [1.0.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.0/index.html)    [0.7.0-beta](https://www.mindspore.cn/api/zh-CN/r0.7/index.html)   
    [0.6.0-beta](https://www.mindspore.cn/api/zh-CN/r0.6/index.html)    [0.5.2-beta](https://www.mindspore.cn/api/zh-CN/r0.5/index.html)    [0.3.0-alpha](https://www.mindspore.cn/api/zh-CN/0.3.0-alpha/index.html)    [0.2.0-alpha](https://www.mindspore.cn/api/zh-CN/0.2.0-alpha/index.html)   
    [0.1.0-alpha](https://www.mindspore.cn/api/zh-CN/0.1.0-alpha/index.html)   [master](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.html) | +| |MindSpore Lite |[2.3.1](https://www.mindspore.cn/lite/api/zh-CN/r2.3.1/index.html)    [2.3.0](https://www.mindspore.cn/lite/api/zh-CN/r2.3.0/index.html)    [2.3.0-rc2](https://www.mindspore.cn/lite/api/zh-CN/r2.3.0rc2/index.html)    [2.3.0-rc1](https://www.mindspore.cn/lite/api/zh-CN/r2.3.0rc1/index.html)    [2.2.14](https://www.mindspore.cn/lite/api/zh-CN/r2.2/index.html)    [2.1.1](https://www.mindspore.cn/lite/api/zh-CN/r2.1/index.html)    [2.0.0](https://www.mindspore.cn/lite/api/zh-CN/r2.0/index.html)    [2.0.0-alpha](https://www.mindspore.cn/lite/api/zh-CN/r2.0.0-alpha/index.html)    [1.10.1](https://www.mindspore.cn/lite/api/zh-CN/r1.10/index.html)    [1.9.0](https://www.mindspore.cn/lite/api/zh-CN/r1.9/index.html)    [1.8.1](https://www.mindspore.cn/lite/api/zh-CN/r1.8/index.html)    [1.7.0](https://www.mindspore.cn/lite/api/zh-CN/r1.7/index.html)   
    [1.6.1](https://www.mindspore.cn/lite/api/zh-CN/r1.6/index.html)    [1.5.0](https://www.mindspore.cn/lite/api/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/lite/api/zh-CN/r1.3/index.html)    [1.2.1-C++](https://www.mindspore.cn/doc/api_cpp/zh-CN/r1.2/index.html)    [1.2.1-Java](https://www.mindspore.cn/doc/api_java/zh-CN/r1.2/index.html)    [1.1.1-C++](https://www.mindspore.cn/doc/api_cpp/zh-CN/r1.1/index.html)   
    [1.1.1-Java](https://www.mindspore.cn/doc/api_java/zh-CN/r1.1/index.html)    [1.0.0](https://www.mindspore.cn/doc/api_cpp/zh-CN/r1.0/index.html)    [master](https://www.mindspore.cn/lite/api/zh-CN/master/index.html) | +| |MindSpore Insight | [2.3.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.3/mindinsight.debugger.html)    [2.2.10](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.2/mindinsight.debugger.html)    [2.1.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.1/mindinsight.debugger.html)    [2.0.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.0/mindinsight.debugger.html)    [2.0.0-alpha](https://www.mindspore.cn/mindinsight/docs/zh-CN/r2.0.0-alpha/mindinsight.debugger.html)    [1.10.1](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.10/mindinsight.debugger.html)    [1.9.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.9/mindinsight.debugger.html)    [1.8.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.8/mindinsight.debugger.html)    [1.7.0](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.7/mindinsight.debugger.html)   
    [1.6.1](https://www.mindspore.cn/mindinsight/docs/zh-CN/r1.6/mindinsight.debugger.html) | | |MindSpore Hub | [1.9.0](https://www.mindspore.cn/hub/docs/zh-CN/r1.9/hub.html)    [1.6.0](https://www.mindspore.cn/hub/docs/zh-CN/r1.6/hub.html)    [1.5.0](https://www.mindspore.cn/hub/api/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/hub/api/zh-CN/r1.3/index.html)    [1.2.0](https://www.mindspore.cn/doc/api_python/zh-CN/r1.2/mindspore_hub/mindspore_hub.html)    [1.1.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.1/mindspore_hub/mindspore_hub.html)   
    [1.0.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.0/mindspore_hub/mindspore_hub.html)    [master](https://www.mindspore.cn/hub/docs/zh-CN/master/hub.html) | | |MindSpore Armour | [2.0.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r2.0/mindarmour.html)    [1.9.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.9/mindarmour.html)    [1.8.1](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.8/mindarmour.html)    [1.7.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.7/mindarmour.html)    [1.6.0](https://www.mindspore.cn/mindarmour/docs/zh-CN/r1.6/mindarmour.html)    [1.5.0](https://www.mindspore.cn/mindarmour/api/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/mindarmour/api/zh-CN/r1.3/index.html)   
    [1.2.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.2/mindarmour/mindarmour.html)    [1.1.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.1/mindarmour/mindarmour.html)    [1.0.1](https://www.mindspore.cn/doc/api_python/zh-CN/r1.0/mindarmour/mindarmour.html)    [0.7.0-beta](https://www.mindspore.cn/api/zh-CN/r0.7/api/python/mindarmour/mindarmour.html)    [0.6.0-beta](https://www.mindspore.cn/api/zh-CN/r0.6/api/python/mindarmour/mindarmour.html)    [0.5.0-beta](https://www.mindspore.cn/api/zh-CN/r0.5/api/python/mindarmour/mindarmour.html)   
    [0.3.0-alpha](https://www.mindspore.cn/api/zh-CN/0.3.0-alpha/api/python/mindarmour/mindarmour.html)    [0.2.0-alpha](https://www.mindspore.cn/api/zh-CN/0.2.0-alpha/api/python/mindarmour/mindarmour.html)    [0.1.0-alpha](https://www.mindspore.cn/api/zh-CN/0.1.0-alpha/api/python/mindarmour/mindarmour.html)    [master](https://www.mindspore.cn/mindarmour/docs/zh-CN/master/mindarmour.html) | | |MindSpore Federated | [new-0.1.0](https://www.mindspore.cn/federated/docs/zh-CN/r0.1/horizontal/federated_server.html)    [1.7.0](https://www.mindspore.cn/federated/docs/zh-CN/r1.7/federated_server.html)    [1.6.0](https://www.mindspore.cn/federated/docs/zh-CN/r1.6/federated_server.html)    [1.5.0](https://www.mindspore.cn/federated/api/zh-CN/r1.5/index.html)    [1.3.0](https://www.mindspore.cn/federated/api/zh-CN/r1.3/index.html)    [master](https://www.mindspore.cn/federated/docs/zh-CN/master/horizontal/federated_server.html) | @@ -104,7 +105,7 @@ | |MindSpore Flow | [0.2.0](https://mindspore.cn/mindflow/docs/zh-CN/r0.2/mindflow.cell.html)    [0.1.0](https://mindspore.cn/mindflow/docs/zh-CN/r0.1/mindflow.cell.html)    [0.1.0-alpha](https://mindspore.cn/mindflow/docs/zh-CN/r0.1.0-alpha/mindflow.cell.html)    [master](https://mindspore.cn/mindflow/docs/zh-CN/master/mindflow.cell.html) | | |MindSpore Reinforcement | [0.7.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.7/reinforcement.html)    [0.6.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.6/reinforcement.html)    [0.6.0-alpha](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.6.0-alpha/reinforcement.html)    [0.5.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.5/reinforcement.html)    [0.3.0](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.3/reinforcement.html)    [0.2.1](https://www.mindspore.cn/reinforcement/docs/zh-CN/r0.2/reinforcement.html)    [0.1.0](https://www.mindspore.cn/reinforcement/api/zh-CN/r0.1/index.html)    [master](https://www.mindspore.cn/reinforcement/docs/zh-CN/master/reinforcement.html) | | |MindSpore Graph Learning | [0.2.0](https://www.mindspore.cn/graphlearning/docs/zh-CN/r0.2/mindspore_gl.dataset.html)    [0.2.0-alpha](https://www.mindspore.cn/graphlearning/docs/zh-CN/r0.2.0-alpha/mindspore_gl.dataset.html)    [0.1.0](https://www.mindspore.cn/graphlearning/docs/zh-CN/r0.1/mindspore_gl.dataset.html)    [master](https://www.mindspore.cn/graphlearning/docs/zh-CN/master/mindspore_gl.dataset.html) | -| |MindSpore Golden Stick | [0.4.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.4/mindspore_gs.quantization.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3/mindspore_gs.quantization.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3.0-alpha/mindspore_gs.quantization.html)    [0.2.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/mindspore_gs.quantization.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/zh-CN/r0.1/mindspore_gs.html)    [master](http://www.mindspore.cn/golden_stick/docs/zh-CN/master/mindspore_gs.html)| +| |MindSpore Golden Stick | [0.5.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.5.0/mindspore_gs.quantization.html)    [0.4.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.4/mindspore_gs.quantization.html)    [0.3.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3/mindspore_gs.quantization.html)    [0.3.0-alpha](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.3.0-alpha/mindspore_gs.quantization.html)    [0.2.0](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/mindspore_gs.quantization.html)    [0.1.0](http://www.mindspore.cn/golden_stick/docs/zh-CN/r0.1/mindspore_gs.html)    [master](http://www.mindspore.cn/golden_stick/docs/zh-CN/master/mindspore_gs.html)| | |MindSpore XAI | [1.8.1](https://www.mindspore.cn/xai/docs/zh-CN/r1.8/mindspore_xai.explainer.html)    [1.5.0](https://www.mindspore.cn/xai/api/zh-CN/r1.5/index.html)    [master](https://www.mindspore.cn/xai/docs/zh-CN/master/mindspore_xai.explainer.html) | | |MindSpore Recommender | [0.3.0](https://mindspore.cn/recommender/docs/zh-CN/r0.3/recommender.html)    [0.2.0](https://mindspore.cn/recommender/docs/zh-CN/r0.2/recommender.html)    [master](https://mindspore.cn/recommender/docs/zh-CN/master/recommender.html) | | |MindSpore Pandas | [0.2.0](https://www.mindspore.cn/mindpandas/docs/zh-CN/r0.2/mindpandas.config.html)    [0.1.0](https://www.mindspore.cn/mindpandas/docs/zh-CN/r0.1/mindpandas.config.html)    [master](https://www.mindspore.cn//mindpandas/docs/zh-CN/master/mindpandas.config.html) | @@ -114,6 +115,7 @@ | MindSpore版本 | 硬件平台 | 商用版安装指引文档 | 社区版下载地址(安装参考商用版) | |-------------|--------|-----------|------------------| +| 2.3.1 | Ascend | TBD | [CANN 8.0.RC2.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [固件与驱动](https://www.hiascend.com/hardware/firmware-drivers/community) | | 2.3.0 | Ascend | TBD | [CANN 8.0.RC2.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [固件与驱动](https://www.hiascend.com/hardware/firmware-drivers/community) | | 2.3.0-rc2 | Ascend | [Ascend Training Solution 24.0.RC1](https://support.huawei.com/enterprise/zh/doc/EDOC1100373131) | [CANN 8.0.RC1.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [固件与驱动](https://www.hiascend.com/hardware/firmware-drivers/community) | | 2.3.0-rc1 | Ascend | [Ascend Training Solution 24.0.RC1](https://support.huawei.com/enterprise/zh/doc/EDOC1100373131) | [CANN 8.0.RC1.beta1](https://www.hiascend.com/developer/download/community/result?module=cann)
    [固件与驱动](https://www.hiascend.com/hardware/firmware-drivers/community) | @@ -167,6 +169,19 @@ ## 下载地址 +### 2.3.1 + +| 组件 | 硬件平台 | 操作系统 | Python版本 | 链接 | SHA-256 | +|------------------------------|--------|---------------|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------| +| MindSpore | Ascend | Linux-aarch64 | Python3.8 | [mindspore-2.3.1-cp38-cp38-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/aarch64/mindspore-2.3.1-cp38-cp38-linux_aarch64.whl) | 976854b9e0c2535541cacb6e1b0b887595fd7aaa03572670b148d1846b08d339 | +| | | | Python3.9 | [mindspore-2.3.1-cp39-cp39-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/aarch64/mindspore-2.3.1-cp39-cp39-linux_aarch64.whl) | 5fe6a476a7a718c413ac66db71ba93bfe2d6870e13ef90f10652a27170ed338e | +| | | | Python3.10 | [mindspore-2.3.1-cp310-cp310-linux_aarch64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/aarch64/mindspore-2.3.1-cp310-cp310-linux_aarch64.whl) | d9be757fa42b30e546920b5dffe76527f3f94e9aac88b262174ecd2a0f32c2e0 | +| | Ascend | Linux-x86_64 | Python3.8 | [mindspore-2.3.1-cp38-cp38-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/x86_64/mindspore-2.3.1-cp38-cp38-linux_x86_64.whl) | f7d19669517be1624d3475a6b22b54f2bc730b998eefd6020a9c9d6ef9d09dee | +| | | | Python3.9 | [mindspore-2.3.1-cp39-cp39-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/x86_64/mindspore-2.3.1-cp39-cp39-linux_x86_64.whl) | 291ce96deb150445dfb6648998276fa0389264c822abddce58bd93ef65fdd993 | +| | | | Python3.10 | [mindspore-2.3.1-cp310-cp310-linux_x86_64.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/MindSpore/unified/x86_64/mindspore-2.3.1-cp310-cp310-linux_x86_64.whl) | 568fc4a52e60f3087e9e0399fa9eed9ff0338bd08ecbcd9c101f2db39ee5fb01 | +|MindSpore
    Lite | | | | [安装包汇总链接](https://www.mindspore.cn/lite/docs/zh-CN/r2.3.1/use/downloads.html#2-3-1) | | +| MindSpore
    Golden
    Stick | | any | Python3 | [mindspore_gs-0.5.0-py3-none-any.whl](https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.3.1/GoldenStick/any/mindspore_gs-0.5.0-py3-none-any.whl) | eb1c37e35468fef1e4ff1237ab88b1d718acd47f65117ec532bdb04da9d5372b | + ### 2.3.0 | 组件 | 硬件平台 | 操作系统 | Python版本 | 链接 | SHA-256 | diff --git a/tools/ci_pipeline_gate_APIView/base_version.json b/tools/ci_pipeline_gate_APIView/base_version.json index 55a479fc365f7ff6e3cbed244c20d4bb84999e83..0a021e5862a99def4f836e0bc26aa6c5e97da32f 100644 --- a/tools/ci_pipeline_gate_APIView/base_version.json +++ b/tools/ci_pipeline_gate_APIView/base_version.json @@ -1,54 +1,108 @@ [ { "version": "master", - "versionAlias": "", "label": { "zh": "MindSpore", "en": "MindSpore" }, "repo_name": "mindspore", - "theme": "theme-docs" - }, - { - "version": "master", - "versionAlias": "", - "label": { - "zh": "教程", - "en": "Tutorials" - }, - "repo_name": "tutorials", "submenu": { "zh": [ { - "label": "初学入门", - "url": "/tutorials/zh-CN/master/index.html" + "label": "设计理念", + "url": "/docs/zh-CN/master/design/index.html" + }, + { + "label": "模型构建与训练", + "url": "/docs/zh-CN/master/model_train/index.html" }, { - "label": "应用实践", - "url": "/tutorials/application/zh-CN/master/index.html" + "label": "模型推理", + "url": "/docs/zh-CN/master/model_infer/index.html" + }, + { + "label": "模型迁移", + "url": "/docs/zh-CN/master/migration_guide/index.html" + }, + { + "label": "API文档", + "url": "/docs/zh-CN/master/api_python/index.html" + }, + { + "label": "大模型开发", + "url": "/docs/zh-CN/master/mindformers/index.html" + }, + { + "label": "香橙派开发", + "url": "/docs/zh-CN/master/orange_pi/index.html" + }, + { + "label": "模型与套件", + "url": "/docs/zh-CN/master/kits_tools/overview.html" + }, + { + "label": "FAQ", + "url": "/docs/zh-CN/master/faq/index.html" }, { - "label": "深度开发", - "url": "/tutorials/experts/zh-CN/master/index.html" + "label": "RELEASE NOTES", + "url": "/docs/zh-CN/master/RELEASE.html" } ], "en": [ { - "label": "Quickstart", - "url": "/tutorials/en/master/index.html" + "label": "Design Concept", + "url": "/docs/en/master/design/index.html" }, { - "label": "Application", - "url": "/tutorials/application/en/master/index.html" + "label": "Model Building and Training", + "url": "/docs/en/master/model_train/index.html" }, { - "label": "Experts", - "url": "/tutorials/experts/en/master/index.html" + "label": "Model Inference", + "url": "/docs/en/master/model_infer/index.html" + }, + { + "label": "Model Migration", + "url": "/docs/en/master/migration_guide/index.html" + }, + { + "label": "API", + "url": "/docs/en/master/api_python/index.html" + }, + { + "label": "Large Model Development", + "url": "/docs/en/master/mindformers/index.html" + }, + { + "label": "Orange Pi Development", + "url": "/docs/en/master/orange_pi/index.html" + }, + { + "label": "Models and Kits", + "url": "/docs/en/master/kits_tools/overview.html" + }, + { + "label": "FAQ", + "url": "/docs/en/master/faq/index.html" + }, + { + "label": "RELEASE NOTES", + "url": "/docs/en/master/RELEASE.html" } ] }, "theme": "theme-tutorials" }, + { + "version": "master", + "label": { + "zh": "教程", + "en": "Tutorials" + }, + "repo_name": "tutorials", + "theme": "theme-docs" + }, { "version": "master", "versionAlias": "", diff --git a/tools/generate_html/base_version.json b/tools/generate_html/base_version.json index 656a36f876c2c88153300e9b209a001dc1ec343e..201665829b8dd2f3a19b3e58f9f216886649438c 100644 --- a/tools/generate_html/base_version.json +++ b/tools/generate_html/base_version.json @@ -6,47 +6,103 @@ "en": "MindSpore" }, "repo_name": "mindspore", - "theme": "theme-docs" - }, - { - "version": "master", - "label": { - "zh": "教程", - "en": "Tutorials" - }, - "repo_name": "tutorials", "submenu": { "zh": [ { - "label": "初学入门", - "url": "/tutorials/zh-CN/master/index.html" + "label": "设计理念", + "url": "/docs/zh-CN/master/design/index.html" + }, + { + "label": "模型构建与训练", + "url": "/docs/zh-CN/master/model_train/index.html" + }, + { + "label": "模型推理", + "url": "/docs/zh-CN/master/model_infer/index.html" + }, + { + "label": "模型迁移", + "url": "/docs/zh-CN/master/migration_guide/index.html" + }, + { + "label": "API文档", + "url": "/docs/zh-CN/master/api_python/index.html" + }, + { + "label": "大模型开发", + "url": "/docs/zh-CN/master/mindformers/index.html" + }, + { + "label": "香橙派开发", + "url": "/docs/zh-CN/master/orange_pi/index.html" }, { - "label": "应用实践", - "url": "/tutorials/application/zh-CN/master/index.html" + "label": "模型与套件", + "url": "/docs/zh-CN/master/kits_tools/overview.html" }, { - "label": "深度开发", - "url": "/tutorials/experts/zh-CN/master/index.html" + "label": "FAQ", + "url": "/docs/zh-CN/master/faq/index.html" + }, + { + "label": "RELEASE NOTES", + "url": "/docs/zh-CN/master/RELEASE.html" } ], "en": [ { - "label": "Quickstart", - "url": "/tutorials/en/master/index.html" + "label": "Design Concept", + "url": "/docs/en/master/design/index.html" + }, + { + "label": "Model Building and Training", + "url": "/docs/en/master/model_train/index.html" + }, + { + "label": "Model Inference", + "url": "/docs/en/master/model_infer/index.html" }, { - "label": "Application", - "url": "/tutorials/application/en/master/index.html" + "label": "Model Migration", + "url": "/docs/en/master/migration_guide/index.html" }, { - "label": "Experts", - "url": "/tutorials/experts/en/master/index.html" + "label": "API", + "url": "/docs/en/master/api_python/index.html" + }, + { + "label": "Large Model Development", + "url": "/docs/en/master/mindformers/index.html" + }, + { + "label": "Orange Pi Development", + "url": "/docs/en/master/orange_pi/index.html" + }, + { + "label": "Models and Kits", + "url": "/docs/en/master/kits_tools/overview.html" + }, + { + "label": "FAQ", + "url": "/docs/en/master/faq/index.html" + }, + { + "label": "RELEASE NOTES", + "url": "/docs/en/master/RELEASE.html" } ] }, "theme": "theme-tutorials" }, + { + "version": "master", + "label": { + "zh": "教程", + "en": "Tutorials" + }, + "repo_name": "tutorials", + "theme": "theme-docs" + }, { "version": "master", "label": { @@ -288,5 +344,14 @@ }, "repo_name": "xai", "theme": "theme-docs" + }, + { + "version": "master", + "label": { + "zh": "MindSpore Chemistry", + "en": "MindSpore Chemistry" + }, + "repo_name": "mindchemistry", + "theme": "theme-docs" } ] \ No newline at end of file diff --git a/tools/generate_html/daily.json b/tools/generate_html/daily.json index 7ce2c85dcb0f638b2cdf30c996a300ff5a574642..07bcee3fe85679301bcf122a8b1c2fdf3fb86acd 100644 --- a/tools/generate_html/daily.json +++ b/tools/generate_html/daily.json @@ -3,21 +3,21 @@ "id" : 1 , "name" : "lite", "branch" : "master", - "whl_path" : "/mindspore/website/master/lite/centos_x86/cloud_fusion/python37", - "whl_name" : "mindspore_lite-.*-cp37-cp37m-linux_x86_64.whl$", + "whl_path" : "/mindspore/website/master/lite/centos_x86/cloud_fusion/python39", + "whl_name" : "mindspore_lite-.*-cp39-cp39-linux_x86_64.whl$", "environ" : "MS_PATH", "uninstall_name" : "mindspore_lite", - "tar_path" : "/mindspore/website/master/lite/centos_x86/cloud_fusion/python37", + "tar_path" : "/mindspore/website/master/lite/centos_x86/cloud_fusion/python39", "tar_name" : "mindspore-lite-.*-linux-x64.tar.gz$", "extra_whl_path" : "/mindspore/website/master/cpu/x86_64", - "extra_whl_name" : "mindspore-.*-cp37-cp37m-linux_x86_64.whl$" + "extra_whl_name" : "mindspore-.*-cp39-cp39-linux_x86_64.whl$" }, { "id" : 2 , "name" : "mindspore", "branch" : "master", "whl_path" : "/mindspore/website/master/cpu/x86_64", - "whl_name" : "mindspore-.*-cp37-cp37m-linux_x86_64.whl$", + "whl_name" : "mindspore-.*-cp39-cp39-linux_x86_64.whl$", "environ" : "MS_PATH", "uninstall_name" : "mindspore" }, @@ -35,7 +35,7 @@ "name" : "mindquantum", "branch" : "master", "whl_path" : "/mindquantum/website/gpu/x86_64/cuda-11.1/", - "whl_name" : "mindquantum-.*-cp37-cp37m-linux_x86_64.whl$", + "whl_name" : "mindquantum-.*-cp39-cp39-linux_x86_64.whl$", "environ" : "MQ_PATH", "uninstall_name" : "mindquantum" }, @@ -88,10 +88,10 @@ "id" : 10 , "name" : "mindinsight", "branch" : "master", - "whl_path" : "/mindinsight/website/any", - "whl_name" : "mindinsight-.*.whl$", + "whl_path" : "", + "whl_name" : "", "environ" : "MI_PATH", - "uninstall_name" : "mindinsight" + "uninstall_name" : "" }, { "id" : 11 , @@ -110,5 +110,14 @@ "whl_name" : "mindformers-.*-py3-none-any.whl$", "environ" : "", "uninstall_name" : "mindformers" +}, +{ + "id" : 13 , + "name" : "golden_stick", + "branch" : "master", + "whl_path" : "/golden-stick/newest/any/", + "whl_name" : "mindspore_gs-.*-py3-none-any.whl$", + "environ" : "GS_PATH", + "uninstall_name" : "mindspore_gs" } ] \ No newline at end of file diff --git a/tools/generate_html/replace_html_menu.py b/tools/generate_html/replace_html_menu.py new file mode 100644 index 0000000000000000000000000000000000000000..f853a9d956b70846abed8b56658ca8c20c1c0fd4 --- /dev/null +++ b/tools/generate_html/replace_html_menu.py @@ -0,0 +1,201 @@ +"""修改文档页面左侧大纲目录""" +import re +import os + +# pylint: disable=C0301 + +# 为有index的目录生成基础大纲目录 --> dict +def replace_html_menu(html_path, hm_ds_path): + """替换左侧目录内容""" + rp_dict = dict() + # pylint: disable=W0621 + # pylint: disable=R1702 + # pylint: disable=W0612 + for root, dirs, files in os.walk(hm_ds_path): + for file in files: + if file == 'index.rst' and root != hm_ds_path: + with open(os.path.join(root, file), 'r', encoding='utf-8') as f: + content = f.read() + with open(os.path.join(root.replace(hm_ds_path, html_path), 'index.html'), 'r', encoding='utf-8') as g: + h_content = g.read() + rp_str = '' + if len(re.findall('.. toctree::', content)) == 1: + toc_docs = re.findall('.. toctree::(?:.|\n|)+?\n\n((?:.|\n|)+?)\n\n', content+'\n\n')[0] + toc_list = [i.strip() for i in toc_docs.split('\n') if i.strip() != ''] + for i in toc_list: + title_name = re.findall( + f'
  • (.*?)
  • ', + h_content) + if title_name: + rp_str += f'
  • ' +\ + title_name[0]+'
  • \n' + # 特殊页面处理 + if '/migration_guide' in root: + rp_dict[os.path.join(html_path, 'note', 'api_mapping')] = rp_str + elif '/api_python' in root: + rp_dict[os.path.join(html_path, 'note')] = rp_str + else: + toc_docs = re.findall('.. toctree::(?:.|\n|)+?:caption: (.*)\n\n((?:.|\n|)+?)\n\n', content+'\n') + for title, toc_doc in toc_docs: + toc_list = [i.strip() for i in toc_doc.split('\n') if i.strip() != ''] + rp_str += '

    '+\ + title + '

    \n
      \n' + for i in toc_list: + if '.html' in i: + spec_html = re.findall(r'\<(.*?)\>', i)[0] + spec_title = i.split(' ')[0] + rp_str += f'
    • '+\ + spec_title + '
    • \n' + continue + url_title = re.findall( + f'
    • (.*?)
    • ', + h_content) + if url_title: + title_name = url_title[0][1] + rp_str += f'
    • '+\ + title_name + '
    • \n' + rp_str += '
    \n' + + rp_dict[root.replace(hm_ds_path, html_path)] = rp_str + + # 遍历html页面,替换目录部分 + # pylint: disable=W0621 + for root, dirs, files in os.walk(html_path): + for file in files: + if not file.endswith('.html'): + continue + if file == 'RELEASE.html': + with open(os.path.join(root, file), 'r', encoding='utf-8') as f: + h_content = f.read() + release_str = '
  • Release Notes
  • ' + new_content = re.sub( + '
      (?:.|\n|)+?
    \n\n', f'
      \n{release_str}
    \n\n', + h_content) + with open(os.path.join(root, file), 'w', encoding='utf-8') as f: + f.write(new_content) + continue + for p in rp_dict: + if p in root: + p_key = p + if 'note/api_mapping' in root and p_key+'/api_mapping' in rp_dict: + p_key = p+'/api_mapping' + with open(os.path.join(root, file), 'r', encoding='utf-8') as f: + h_content = f.read() + rp_str = rp_dict[p_key] + # 将每个页面的链接修正成正确的相对路径 + for href in re.findall('href="(.*?)"', rp_str): + if href.startswith('https://'): + continue + abs_p1 = os.path.join(p_key, href) + if 'note/api_mapping' in p_key: + abs_p1 = os.path.join(html_path, 'migration_guide', href) + elif '/note' in p_key and 'api_mapping' not in root: + abs_p1 = os.path.join(html_path, 'api_python', href) + rel_p = os.path.relpath(abs_p1, root) + rel_p = rel_p.replace('\\', '/') + rp_str = re.sub(f'href="{href}"', f'href="{rel_p}"', rp_str) + + current_herf = re.findall( + '
  • )', + h_content) + if 'api_python' in root and file.startswith('mindspore.') and current_herf: + rp_str = re.sub( + f'
  • ', + f'
  • (.*?)', rp_str) + if file_title and file != 'index.html': + toctree_lev = re.findall(f'
  • {file_title[0]}\n
  • \n
  • {file_title[0]}(
      (?:.|\n|)+?
    )\n
  • \n\n\n\n\n', h_content) + if extra_re: + extra_ul = '
      \n' + '\n'.join(re.findall('
    • .*?href="[^#].*?
    • ', extra_re[0])) + '\n
    ' + + extra_ul = re.sub('toctree-l[0-9]', 'toctree-l2', extra_ul) + rp_str = rp_str.replace(f'
  • {file_title[0]}
  • ', + f'
  • {file_title[0]}{extra_ul}
  • ') + # 子目录文件的特殊处理 + elif file != 'index.html': + toctree_lev = re.findall( + '
  • .*?