diff --git a/.gitignore b/.gitignore index 41d507e490f845838dca5d90720263a1cb5297c7..2137a234ab558e3933dbaf0a0d9b9167bc39e866 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ rank_0/ dataset/ *.ckpt -*.mindir \ No newline at end of file +*.mindir +*.meta \ No newline at end of file diff --git a/CONTRIBUTING_DOC.md b/CONTRIBUTING_DOC.md index 4f1cea10966e29fb01bb47b65162c823e8a49444..9e67f81a3bba7f51b16364e26a28f5e87e157897 100644 --- a/CONTRIBUTING_DOC.md +++ b/CONTRIBUTING_DOC.md @@ -16,7 +16,7 @@ MindSpore docs repository provides [Document Writing Specifications](https://git If you want to update an existing document, click `View source on Gitee` (as shown in the following figure) on the top of the page to go to the source file. Modify the document and commit changes to a PR to make the contribution. -![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.png) +![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/r1.9/resource/_static/logo_source_en.png) #### Adding a Document @@ -112,7 +112,7 @@ If you want to add an API, check whether the API has been added to an existing m - `mindspore.nn`: [中文](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.nn.rst) | [English](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.nn.rst) - `mindspore.nn.probability`: [中文](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.nn.probability.rst) | [English](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.nn.probability.rst) - `mindspore.ops`: [中文](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.ops.rst) | [English](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.ops.rst) - - `mindspore.ops.functional`: [中文](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.ops.functional.rst) | [English](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.ops.functional.rst) + - `mindspore.ops.function`: [中文](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.ops.function.rst) | [English](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.ops.function.rst) - If the API does not belong to the existing module, add an API project file of the MindSpore docs repository. Please add modules to the [directory structure](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_en/index.rst) in alphabetical order. To add the API of the `mindspore.mindrecord` module, you need to create the [mindspore.mindrecord.rst](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.mindrecord.rst) file in the `docs/docs/api_python/source_en/mindspore` directory and add the file to the directory structure. @@ -152,7 +152,7 @@ For specific image requirements and specifications, please refer to [Image Speci ### Updating or Adding an Image -If you want to update an existing image or adding a new image, click ![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source_en.png) on the top of the page to go to the source file. Usually the images will be stored in the directory ./images. You only need to put the new images into this directory, or replace the modified images with the original ones, and commit changes to a PR to make the contribution. +If you want to update an existing image or adding a new image, click ![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/r1.9/resource/_static/logo_source_en.png) on the top of the page to go to the source file. Usually the images will be stored in the directory ./images. You only need to put the new images into this directory, or replace the modified images with the original ones, and commit changes to a PR to make the contribution. > Please submit the original image to Gitee at the same time, and put it in the same path as the image for subsequent modification. diff --git a/CONTRIBUTING_DOC_CN.md b/CONTRIBUTING_DOC_CN.md index 93c01c19248547ce0470c59c8efe0a7006f74361..faca249c69da1b825ddde123446f52c83dd81650 100644 --- a/CONTRIBUTING_DOC_CN.md +++ b/CONTRIBUTING_DOC_CN.md @@ -16,7 +16,7 @@ MindSpore docs仓提供了[文档写作要求](https://gitee.com/mindspore/docs/ 如果您发现现有文档需要刷新,可点击页面上方的“View Source on Gitee”(如下图所示),跳转至源文件。修改该文件,并提交PR即可参与贡献。 -![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.png) +![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/r1.9/resource/_static/logo_source.png) #### 新增文档 @@ -112,7 +112,7 @@ MindSpore docs仓提供了[API注释写作要求](https://gitee.com/mindspore/do - `mindspore.nn`:[中文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.nn.rst) | [英文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.nn.rst) - `mindspore.nn.probability`:[中文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.nn.probability.rst) | [英文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.nn.probability.rst) - `mindspore.ops`:[中文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.ops.rst) | [英文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.ops.rst) - - `mindspore.ops.functional`:[中文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.ops.functional.rst) | [英文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.ops.functional.rst) + - `mindspore.ops.function`:[中文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.ops.function.rst) | [英文页面列表](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python_en/mindspore.ops.function.rst) - 如果不属于已有模块,需新增MindSpore docs仓的接口工程文件,并按字母序添加模块到[目录结构](https://gitee.com/mindspore/docs/blob/master/docs/mindspore/source_zh_cn/index.rst)中。如需新增`mindspore.mindrecord`模块接口,需在`docs/docs/api_python/source_zh_cn/mindspore`目录下新增[mindspore.mindrecord.rst](https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mindspore.mindrecord.rst)文件,并将其添加到目录结构中。同时,在`docs/docs/api_python/source_en/mindspore`目录下做相应修改,即可生成英文页面内容。 @@ -152,7 +152,7 @@ PR合入后次日,即可在MindSpore官网[Python API页面](https://www.minds ### 更新/新增图片 -如果您发现现有文档中的图片需要更新/新增,可点击页面上方的![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.png),跳转至源文件。通常图片会存放在./images目录中,只需将需要新增的图片放进这个目录,或将修改后的图片替换原图,并提交PR即可参与贡献。 +如果您发现现有文档中的图片需要更新/新增,可点击页面上方的![View Source on Gitee](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/r1.9/resource/_static/logo_source.png),跳转至源文件。通常图片会存放在./images目录中,只需将需要新增的图片放进这个目录,或将修改后的图片替换原图,并提交PR即可参与贡献。 > 请同时把原图一并提交到Gitee,放在与存放图片相同的路径下,方便后续修改。 diff --git a/docs/devtoolkit/docs/Makefile b/docs/devtoolkit/docs/Makefile deleted file mode 100644 index 1eff8952707bdfa503c8d60c1e9a903053170ba2..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/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/devtoolkit/docs/requirements.txt b/docs/devtoolkit/docs/requirements.txt deleted file mode 100644 index 49a77fdec3a5c745edd40eaa223883c31500e975..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -sphinx >= 2.2.1, <= 2.4.4 -docutils == 0.16 -myst_parser == 0.14.0 -sphinx-markdown-tables -sphinx_rtd_theme == 0.5.2 -numpy -nbsphinx -IPython -ipykernel -jieba diff --git a/docs/devtoolkit/docs/source_en/compiling.md b/docs/devtoolkit/docs/source_en/compiling.md deleted file mode 100644 index a46388ee493d4fffb7d0722541b4cebef88b1510..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_en/compiling.md +++ /dev/null @@ -1,87 +0,0 @@ -# Source Code Compilation Guide - - - -The following describes how to compile the MindSpore Dev ToolKit project based on the IntelliJ IDEA source code. - -## Background - -* MindSpore Dev ToolKit is a PyCharm plug-in developed using IntelliJ IDEA. [IntelliJ IDEA](https://www.jetbrains.com/idea/download) and PyCharm are IDEs developed by JetBrains. -* MindSpore Dev ToolKit is developed based on JDK 11. To learn JDK- and Java-related knowledge, visit [https://jdk.java.net/](https://jdk.java.net/). -* [Gradle 6.6.1](https://gradle.org) is used to build MindSpore Dev Toolkit and it does not need to be installed in advance. IntelliJ IDEA automatically uses the "gradle wrapper" mechanism to configure the required Gradle based on the code. - -## Required Software - -* [IntelliJ IDEA](https://www.jetbrains.com/idea/download) - -* JDK 11 - - Note: IntelliJ IDEA 2021.3 contains a built-in JDK named **jbr-11 JetBrains Runtime version 11.0.10**, which can be used directly. - - ![img](images/clip_image031.jpg) - -## Compilation - -1. Verify that the required software has been successfully configured. - -2. Download the [project](https://gitee.com/mindspore/ide-plugin) source code from the code repository. - - * Download the ZIP package. - - ![img](images/clip_image032.jpg) - - * Run the git command to download the package. - - ``` - git clone https://gitee.com/mindspore/ide-plugin.git - ``` - -3. Use IntelliJ IDEA to open the project. - - 3.1 Choose **File** > **Open**. - - ![img](images/clip_image033.jpg) - - 3.2 Go to the directory for storing the project. - - ![img](images/clip_image034.jpg) - - 3.3 Click **Load** in the dialog box that is displayed in the lower right corner. Alternatively, click **pycharm**, right-click the **settings.gradle** file, and choose **Link Gradle Project** from the shortcut menu. - - ![img](images/clip_image035.jpg) - - ![img](images/clip_image036.jpg) - -4. If the system displays a message indicating that no JDK is available, select a JDK. ***Skip this step if the JDK is available.*** - - 4.1 The following figure shows the situation when the JDK is not available. - - ![img](images/clip_image037.jpg) - - 4.2 Choose **File** > **Project Structure**. - - ![img](images/clip_image038.jpg) - - 4.3 Select JDK 11. - - ![img](images/clip_image039.jpg) - -5. Wait until the synchronization is complete. - - ![img](images/clip_image040.jpg) - -6. Build a project. - - ![img](images/clip_image042.jpg) - -7. Wait till the build is complete. - - ![img](images/clip_image044.jpg) - -8. Obtain the plug-in installation package from the **/pycharm/build/distributions** directory in the project directory. - - ![img](images/clip_image046.jpg) - -## References - -* This project is built based on section [Building Plugins with Gradle](https://plugins.jetbrains.com/docs/intellij/gradle-build-system.html) in *IntelliJ Platform Plugin SDK*. For details about advanced functions such as debugging, see the official document. diff --git a/docs/devtoolkit/docs/source_en/conf.py b/docs/devtoolkit/docs/source_en/conf.py deleted file mode 100644 index 6d5d74a2f9cea9eea4a424c50206f4d903598115..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_en/conf.py +++ /dev/null @@ -1,71 +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 re - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = '2022, 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. -extensions = [ - 'sphinx_markdown_tables', - 'myst_parser', - 'sphinx.ext.autodoc' -] - -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. -exclude_patterns = [] - -pygments_style = 'sphinx' - -# -- 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' - -html_search_options = {'dict': '../../../resource/jieba.txt'} - -html_static_path = ['_static'] - -src_release = os.path.join(os.getenv("DT_PATH"), 'RELEASE.md') -des_release = "./RELEASE.md" -with open(src_release, "r", encoding="utf-8") as f: - data = f.read() -content = re.findall("## [\s\S\n]*", data) -result = content[0].replace('# MindSpore Dev Toolkit', '#', 1) -with open(des_release, "w", encoding="utf-8") as p: - p.write("# Release Notes"+"\n\n") - p.write(result) \ No newline at end of file diff --git a/docs/devtoolkit/docs/source_en/images/clip_image002.jpg b/docs/devtoolkit/docs/source_en/images/clip_image002.jpg deleted file mode 100644 index 24132302f1552bed6be56b7dd660625448774680..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image002.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image004.jpg b/docs/devtoolkit/docs/source_en/images/clip_image004.jpg deleted file mode 100644 index 7ed0e3729940f514a7bfd61c1a7be22166c0bb02..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image004.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image006.jpg b/docs/devtoolkit/docs/source_en/images/clip_image006.jpg deleted file mode 100644 index e0c323eec249024fe19126ce4c931133564cf7b7..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image006.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image008.jpg b/docs/devtoolkit/docs/source_en/images/clip_image008.jpg deleted file mode 100644 index a071ad67222931372d4b62f7b0cf334a4015e70d..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image008.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image010.jpg b/docs/devtoolkit/docs/source_en/images/clip_image010.jpg deleted file mode 100644 index 43ca88d40bc56d5a5113bc29b97a7b559ef659af..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image010.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image012.jpg b/docs/devtoolkit/docs/source_en/images/clip_image012.jpg deleted file mode 100644 index 0e35c9f219292913a51f1f0d5b7a5e154008620f..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image012.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image014.jpg b/docs/devtoolkit/docs/source_en/images/clip_image014.jpg deleted file mode 100644 index 794de60c7d7e76a58e8d7212e449a1bd8e194b21..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image014.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image015.jpg b/docs/devtoolkit/docs/source_en/images/clip_image015.jpg deleted file mode 100644 index 8172e21f871bed6866b3a91b83252838228d257a..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image015.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image016.jpg b/docs/devtoolkit/docs/source_en/images/clip_image016.jpg deleted file mode 100644 index c836c0cf7898e4757ddb3410dde18e754894dd25..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image016.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image018.jpg b/docs/devtoolkit/docs/source_en/images/clip_image018.jpg deleted file mode 100644 index 777738f7cf60454b7b5f26e6c5a29ba5d55750ff..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image018.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image019.jpg b/docs/devtoolkit/docs/source_en/images/clip_image019.jpg deleted file mode 100644 index ab02b702bfd1c0986adb4a15c1f455b56df0a4a1..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image019.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image020.jpg b/docs/devtoolkit/docs/source_en/images/clip_image020.jpg deleted file mode 100644 index d946c3cb3a851f690a5643b5afe119597aed5b22..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image020.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image021.jpg b/docs/devtoolkit/docs/source_en/images/clip_image021.jpg deleted file mode 100644 index 74672d9513f4a60f77450ae5516cee2060215241..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image021.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image022.jpg b/docs/devtoolkit/docs/source_en/images/clip_image022.jpg deleted file mode 100644 index 6b26f18c7d8bb43db0beb8a8d2bd386489192922..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image022.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image023.jpg b/docs/devtoolkit/docs/source_en/images/clip_image023.jpg deleted file mode 100644 index 5981a0fb25c681417a0bdf24d2392411b41f0faf..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image023.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image024.jpg b/docs/devtoolkit/docs/source_en/images/clip_image024.jpg deleted file mode 100644 index 505e8b6c5c4d81dfd67d91b1dad08f938444368a..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image024.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image025.jpg b/docs/devtoolkit/docs/source_en/images/clip_image025.jpg deleted file mode 100644 index 946e276b6a982303b6b146266037a739e6c2639a..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image025.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image026.jpg b/docs/devtoolkit/docs/source_en/images/clip_image026.jpg deleted file mode 100644 index 8b787215af5cf9ae223c2b33121c3171923d2de2..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image026.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image027.jpg b/docs/devtoolkit/docs/source_en/images/clip_image027.jpg deleted file mode 100644 index aa4d7d4a8a6b503fe29885368547daa535e34796..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image027.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image028.jpg b/docs/devtoolkit/docs/source_en/images/clip_image028.jpg deleted file mode 100644 index 3126f80aecac28e8beaa54dc393122c60dbe1357..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image028.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image029.jpg b/docs/devtoolkit/docs/source_en/images/clip_image029.jpg deleted file mode 100644 index 6587240e4a456f3792fece52bcdcbbed077ca67b..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image029.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image031.jpg b/docs/devtoolkit/docs/source_en/images/clip_image031.jpg deleted file mode 100644 index 2f829b48e72e62525860cfe599e0a4ada82010ca..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image031.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image032.jpg b/docs/devtoolkit/docs/source_en/images/clip_image032.jpg deleted file mode 100644 index 37589efbe0f57c442f665824831a2685d81c8713..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image032.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image033.jpg b/docs/devtoolkit/docs/source_en/images/clip_image033.jpg deleted file mode 100644 index bdca68324cf7ee8f4e9bd18817a82954910e52c9..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image033.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image034.jpg b/docs/devtoolkit/docs/source_en/images/clip_image034.jpg deleted file mode 100644 index 874b10d4b2ca476da16a4d1e749cdb6b31ecb59e..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image034.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image035.jpg b/docs/devtoolkit/docs/source_en/images/clip_image035.jpg deleted file mode 100644 index 0b0465169553e57795320255295b8fa789950522..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image035.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image036.jpg b/docs/devtoolkit/docs/source_en/images/clip_image036.jpg deleted file mode 100644 index c7c6c72819b655884d97637b696d1814e5a7fdbf..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image036.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image037.jpg b/docs/devtoolkit/docs/source_en/images/clip_image037.jpg deleted file mode 100644 index 531e8184e02c43aa177a51c3cc32355cc3df9d42..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image037.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image038.jpg b/docs/devtoolkit/docs/source_en/images/clip_image038.jpg deleted file mode 100644 index a8b4d88190c626139bad49cd42a9f7e908b4d0e4..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image038.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image039.jpg b/docs/devtoolkit/docs/source_en/images/clip_image039.jpg deleted file mode 100644 index 2eab0ceac9c1bd5d8b6ade3d65a6a3ce8b1f8fd4..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image039.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image040.jpg b/docs/devtoolkit/docs/source_en/images/clip_image040.jpg deleted file mode 100644 index a879fb1f12d8b6c4bd02332abf9b3bd734207763..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image040.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image042.jpg b/docs/devtoolkit/docs/source_en/images/clip_image042.jpg deleted file mode 100644 index 2454ade258da6d428c9e23ece2adf7f0291d1a12..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image042.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image044.jpg b/docs/devtoolkit/docs/source_en/images/clip_image044.jpg deleted file mode 100644 index cbff652015c36a5856afc909518f3c0fd22f23ff..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image044.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image046.jpg b/docs/devtoolkit/docs/source_en/images/clip_image046.jpg deleted file mode 100644 index 58a493ea4f69b264fc69cfd3e34f32d5a171c303..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image046.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image050.jpg b/docs/devtoolkit/docs/source_en/images/clip_image050.jpg deleted file mode 100644 index 35cc26d483358550c9a53ce855c2ae483eddb7e1..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image050.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image052.jpg b/docs/devtoolkit/docs/source_en/images/clip_image052.jpg deleted file mode 100644 index caa3dde40ee7e6815f603ff1849d275c416b8e38..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image052.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image054.jpg b/docs/devtoolkit/docs/source_en/images/clip_image054.jpg deleted file mode 100644 index 3a562120b8905cf577035fa4b28dfc35bad324bb..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image054.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image060.jpg b/docs/devtoolkit/docs/source_en/images/clip_image060.jpg deleted file mode 100644 index 7723975694f7f56d88187a69626343af11efbd23..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image060.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image062.jpg b/docs/devtoolkit/docs/source_en/images/clip_image062.jpg deleted file mode 100644 index 838bc48ab8d77f7dbba9ca02925838a49b19ce53..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image062.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image064.jpg b/docs/devtoolkit/docs/source_en/images/clip_image064.jpg deleted file mode 100644 index fb39e70b78b45af301973ea802a219c482a21590..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image064.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image066.jpg b/docs/devtoolkit/docs/source_en/images/clip_image066.jpg deleted file mode 100644 index 0a596cfb3ef7a79674ff33a7be5c97859cc2b9c4..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image066.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image068.jpg b/docs/devtoolkit/docs/source_en/images/clip_image068.jpg deleted file mode 100644 index 0023ba9236a768001e462d6a10434719f3f733fd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image068.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image072.jpg b/docs/devtoolkit/docs/source_en/images/clip_image072.jpg deleted file mode 100644 index d1e5fad4192d4cb5821cafe4031dbc4ff599eccd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image072.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image074.jpg b/docs/devtoolkit/docs/source_en/images/clip_image074.jpg deleted file mode 100644 index 97fa2b21b4029ff75156893f8abdff2e77aa38bd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image074.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image076.jpg b/docs/devtoolkit/docs/source_en/images/clip_image076.jpg deleted file mode 100644 index e754c7dcd30ee6fa82ab20bde4d66f69aabe2fa7..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image076.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image088.jpg b/docs/devtoolkit/docs/source_en/images/clip_image088.jpg deleted file mode 100644 index 8b85f0727893c4cf6cd258550466ca4f4a340e6e..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image088.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image090.jpg b/docs/devtoolkit/docs/source_en/images/clip_image090.jpg deleted file mode 100644 index a3f405388fd75b23b652bc86475be5fd5e1f48ac..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image090.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image092.jpg b/docs/devtoolkit/docs/source_en/images/clip_image092.jpg deleted file mode 100644 index 68ca9c66fc3f03760873075af20c8a9e28aaab48..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image092.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image093.jpg b/docs/devtoolkit/docs/source_en/images/clip_image093.jpg deleted file mode 100644 index 594b2ceadb2c27290e0339e14b298fa2feffe6a9..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image093.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image094.jpg b/docs/devtoolkit/docs/source_en/images/clip_image094.jpg deleted file mode 100644 index e931a95180d27d55590e73948ebe80a1f81bede1..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image094.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/images/clip_image096.jpg b/docs/devtoolkit/docs/source_en/images/clip_image096.jpg deleted file mode 100644 index 3ed0c88500bb4caffccea4d08aaa3a6310e177bd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_en/images/clip_image096.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_en/index.rst b/docs/devtoolkit/docs/source_en/index.rst deleted file mode 100644 index 8441ac72835a9905708085aa5e7d042ec7781591..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_en/index.rst +++ /dev/null @@ -1,75 +0,0 @@ -MindSpore Dev Toolkit -============================ - -MindSpore Dev Toolkit is a development kit for MindSpore developers. It uses technologies such as deep learning, intelligent search, and intelligent recommendation to build the best intelligent computing experience, improve the usability of the MindSpore framework, and facilitate the promotion of the MindSpore ecosystem. - -MindSpore Dev Toolkit currently provides `Project creation `_, `Code completion `_, `API search `_, `Document search `_. - -System Requirements ------------------------------- - -MindSpore Dev Toolkit is a `PyCharm `_ plug-in. PyCharm is a cross-platform Python IDE. - -- Operating systems supported by the plug-in: - - - Windows 10 - - - Linux - - - macOS (Only the x86 architecture is supported. The code completion function is not available currently.) - -- PyCharm versions supported by the plug-in: - - - 2020.3 - - - 2021.1 - - - 2021.2 - - - 2021.3 - -Installation ----------------------------- - -1. Obtain the plug-in installation package. - - 1.1 Download the `plug-in ZIP package `_. - - 1.2 See the following section "Source Code Build." - -2. Start the PyCharm. On the menu bar in the upper left corner, choose **File** > **Settings** > **Plugins** > **Install Plugin from Disk**. - See the following figure: - - .. image:: ./images/clip_image050.jpg - -3. Select the ZIP package of the plug-in (take version 1.7 as an example). - - .. image:: ./images/clip_image052.jpg - -4. The plug-in is installed successfully. - - .. image:: ./images/clip_image054.jpg - -Source Code Build ----------------------------- - -See the `Source Code Compilation Guide `_. - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: operating guide - :hidden: - - compiling - mindspore_project_wizard - operator_search - knowledge_search - smart_completion - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: RELEASE NOTES - - RELEASE diff --git a/docs/devtoolkit/docs/source_en/knowledge_search.md b/docs/devtoolkit/docs/source_en/knowledge_search.md deleted file mode 100644 index e5d838ffe4fd6f03fce52aacd48bb02afbe96cd9..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_en/knowledge_search.md +++ /dev/null @@ -1,22 +0,0 @@ -# Document Search - - - -## Functions - -* Recommendation: It provides exact search results based on user habits. -* It provides immersive document search experience to avoid switching between the IDE and browser. It resides on the sidebar to adapt to the page layout. - -## Procedure - -1. Click the sidebar to display the search page. - - ![img](images/clip_image072.jpg) - -2. Enter **API Mapping** and click the search icon to view the result. - - ![img](images/clip_image074.jpg) - -3. Click the home icon to return to the search page. - - ![img](images/clip_image076.jpg) diff --git a/docs/devtoolkit/docs/source_en/mindspore_project_wizard.md b/docs/devtoolkit/docs/source_en/mindspore_project_wizard.md deleted file mode 100644 index 6612f8d0c334cf50346ac65b30dfd48c4df7e5b8..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_en/mindspore_project_wizard.md +++ /dev/null @@ -1,103 +0,0 @@ -# Creating a Project - - - -## Background - -This function is implemented based on the [conda](https://conda.io). Conda is a package management and environment management system. It is one of the recommended installation modes for MindSpore. - -## Functions - -* It creates a conda environment or selects an existing conda environment, and installs the MindSpore binary package in the conda environment. -* It deploys the best practice template. In addition to testing whether the environment is successfully installed, it also provides a tutorial for MindSpore beginners. -* When the network condition is good, the environment can be installed within 10 minutes and you can experience MindSpore immediately. It reduces up to 80% environment configuration time for beginners. - -## Procedure - -1. Choose **File** > **New Project**. - - ![img](images/clip_image002.jpg) - -2. Select **MindSpore**. - - ![img](images/clip_image004.jpg) - -3. Download and install Miniconda. ***If conda has been installed, skip this step.*** - - 3.1 Click **Install Miniconda Automatically**. - - ![img](images/clip_image006.jpg) - - 3.2 Select an installation folder. **You are advised to use the default path to install conda.** - - ![img](images/clip_image008.jpg) - - 3.3 Click **Install**. - - ![img](images/clip_image010.jpg) - - ![img](images/clip_image012.jpg) - - 3.4 Wait for the installation to complete. - - ![img](images/clip_image014.jpg) - - 3.5 Restart PyCharm as prompted or restart PyCharm later. **Note: The following steps can be performed only after PyCharm is restarted.** - - ![img](images/clip_image015.jpg) - -4. If **Conda executable** is not automatically filled, select the path of the installed conda. - - ![img](images/clip_image016.jpg) - -5. Create a conda environment or select an existing conda environment. - - * Create a conda environment. **You are advised to use the default path to create the conda environment. Due to PyCharm restrictions on Linux, you can only select the default directory.** - - ![img](images/clip_image018.jpg) - - * Select an existing conda environment in PyCharm. - - ![img](images/clip_image019.jpg) - -6. Select a hardware environment and a MindSpore best practice template. - - 6.1 Select a hardware environment. - - ![img](images/clip_image020.jpg) - - 6.2 Select a best practice template. The best practice template provides some sample projects for beginners to get familiar with MindSpore. The best practice template can be run directly. - - ![img](images/clip_image021.jpg) - -7. Click **Create** to create a project and wait until MindSpore is successfully downloaded and installed. - - 7.1 Click **Create** to create a MindSpore project. - - ![img](images/clip_image022.jpg) - - 7.2 The conda environment is being created. - - ![img](images/clip_image023.jpg) - - 7.3 MindSpore is being configured through conda. - - ![img](images/clip_image024.jpg) - -8. Wait till the MindSpore project is created. - - ![img](images/clip_image025.jpg) - -9. Check whether the MindSpore project is successfully created. - - * Click **Terminal**, enter **python -c "import mindspore;mindspore.run_check()"**, and check the output. If the version number shown in the following figure is displayed, the MindSpore environment is available. - - ![img](images/clip_image026.jpg) - - * If you select a best practice template, you can run the best practice to test the MindSpore environment. - - ![img](images/clip_image027.jpg) - - ![img](images/clip_image028.jpg) - - ![img](images/clip_image029.jpg) diff --git a/docs/devtoolkit/docs/source_en/operator_search.md b/docs/devtoolkit/docs/source_en/operator_search.md deleted file mode 100644 index 8e2df4012410373c3e6cbfc0f18a7bbd9d44abbb..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_en/operator_search.md +++ /dev/null @@ -1,28 +0,0 @@ -# API Search - - - -## Functions - -* You can quickly search for MindSpore APIs and view API details in the sidebar. -* If you use other machine learning frameworks, you can search for APIs of other mainstream frameworks to match MindSpore APIs. - -## Procedure - -1. Press **Shift** twice. The global search page is displayed. - - ![img](images/clip_image060.jpg) - -2. Click **MindSpore**. - - ![img](images/clip_image062.jpg) - -3. Search for a PyTorch or TensorFlow API to obtain the mapping between the PyTorch or TensorFlow API and the MindSpore API. - - ![img](images/clip_image064.jpg) - - ![img](images/clip_image066.jpg) - -4. Click an item in the list to view its official document in the sidebar. - - ![img](images/clip_image068.jpg) diff --git a/docs/devtoolkit/docs/source_en/smart_completion.md b/docs/devtoolkit/docs/source_en/smart_completion.md deleted file mode 100644 index 87f9bb853538ebcb7f44a43f7168d4e84361d195..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_en/smart_completion.md +++ /dev/null @@ -1,36 +0,0 @@ -# Code Completion - - - -## Functions - -* It completes code based on AI for the MindSpore project. -* You can easily develop MindSpore without installing the MindSpore environment. - -## Procedure - -1. Open a Python file and write code. - - ![img](images/clip_image088.jpg) - -2. During encoding, the code completion function is enabled automatically. Code lines with the "MindSpore" identifier are automatically completed by MindSpore Dev Toolkit. - - ![img](images/clip_image090.jpg) - - ![img](images/clip_image092.jpg) - -## Description - -1. In versions later than PyCharm 2021, the completed code will be rearranged based on machine learning. This behavior may cause the plug-in's completed code to be displayed with lower priority. You can disable this function in **Settings** and use MindSpore Dev Toolkit to sort code. - - ![img](images/clip_image093.jpg) - -2. Comparison before and after this function is disabled. - - * Function disabled - - ![img](images/clip_image094.jpg) - - * Function enabled - - ![img](images/clip_image096.jpg) diff --git a/docs/devtoolkit/docs/source_zh_cn/compiling.md b/docs/devtoolkit/docs/source_zh_cn/compiling.md deleted file mode 100644 index 06035288ee06dac20071eded2a5d0e5e3b1900c7..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_zh_cn/compiling.md +++ /dev/null @@ -1,86 +0,0 @@ -# 源码编译指导 - - - -本文档介绍如何基于IntelliJ IDEA源码编译MindSpore Dev ToolKit项目。 - -## 背景介绍 - -* MindSpore Dev ToolKit是一个PyCharm插件,需使用IntelliJ IDEA开发。[IntelliJ IDEA](https://www.jetbrains.com/idea/download)与Pycharm均为JetBrains公司开发的IDE。 -* MindSpore Dev ToolKit 基于JDK 11开发。 如果您不了解JDK,请访问[https://jdk.java.net/](https://jdk.java.net/)了解并学习JDK以及java的相关知识。 -* MindSpore Dev ToolKit使用[Gradle](https://gradle.org)6.6.1构建,但无需提前安装。IntelliJ IDEA会自动根据代码使用"gradle wrapper"机制配置好所需的gradle。 - -## 依赖软件 - -* 确认安装[IntelliJ IDEA](https://www.jetbrains.com/idea/download)。 - -* 确认安装JDK 11版本。 - 注:2021.3版本的IntelliJ IDEA自带一个名为jbr-11 JetBrains Runtime version 11.0.10的JDK,可以直接使用。 - - ![img](images/clip_image031.jpg) - -## 编译 - -1. 保证依赖软件均已成功配置。 - -2. 从代码仓下载[本项目](https://gitee.com/mindspore/ide-plugin)源码。 - - * 直接下载代码的zip包。 - - ![img](images/clip_image032.jpg) - - * 使用git下载。 - - ``` - git clone https://gitee.com/mindspore/ide-plugin.git - ``` - -3. 使用IntelliJ IDEA打开项目。 - - 3.1 选择File选项卡下的Open选项。***File -> Open*** - - ![img](images/clip_image033.jpg) - - 3.2 打开下载项目文件位置。 - - ![img](images/clip_image034.jpg) - - 3.3 点击右下角弹窗中的load或右键pycharm/settings.gradle文件选中Link Gradle Project。 - - ![img](images/clip_image035.jpg) - - ![img](images/clip_image036.jpg) - -4. 如果提示没有JDK,请选择一个JDK。***有JDK可以跳过此步骤*** - - 4.1 没有JDK情况下,页面如下图显示。 - - ![img](images/clip_image037.jpg) - - 4.2 File->Project Structure。 - - ![img](images/clip_image038.jpg) - - 4.3 选择JDK11。 - - ![img](images/clip_image039.jpg) - -5. 等待同步完成。 - - ![img](images/clip_image040.jpg) - -6. 构建项目。 - - ![img](images/clip_image042.jpg) - -7. 构建完成。 - - ![img](images/clip_image044.jpg) - -8. 构建完成后至项目目录下/pycharm/build/distributions目录下获取插件安装包。 - - ![img](images/clip_image046.jpg) - -## 相关参考文档 - -* 本项目构建基于IntelliJ Platform Plugin SDK之[Building Plugins with Gradle](https://plugins.jetbrains.com/docs/intellij/gradle-build-system.html)章节。如需了解调试等进阶功能,请阅读官方文档。 \ No newline at end of file diff --git a/docs/devtoolkit/docs/source_zh_cn/conf.py b/docs/devtoolkit/docs/source_zh_cn/conf.py deleted file mode 100644 index 7b893b2ecbc2d8d3c07b19401dad7c192c0c3366..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_zh_cn/conf.py +++ /dev/null @@ -1,71 +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 re - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = '2022, 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. -extensions = [ - 'sphinx_markdown_tables', - 'myst_parser', - 'sphinx.ext.autodoc' -] - -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. -exclude_patterns = [] - -pygments_style = 'sphinx' - -# -- 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' - -html_search_options = {'dict': '../../../resource/jieba.txt'} - -html_static_path = ['_static'] - -src_release = os.path.join(os.getenv("DT_PATH"), 'RELEASE_CN.md') -des_release = "./RELEASE.md" -with open(src_release, "r", encoding="utf-8") as f: - data = f.read() -content = re.findall("## [\s\S\n]*", data) -result = content[0].replace('# MindSpore Dev Toolkit', '#', 1) -with open(des_release, "w", encoding="utf-8") as p: - p.write("# Release Notes"+"\n\n") - p.write(result) \ No newline at end of file diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image002.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image002.jpg deleted file mode 100644 index 24132302f1552bed6be56b7dd660625448774680..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image002.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image004.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image004.jpg deleted file mode 100644 index 7ed0e3729940f514a7bfd61c1a7be22166c0bb02..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image004.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image006.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image006.jpg deleted file mode 100644 index e0c323eec249024fe19126ce4c931133564cf7b7..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image006.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image008.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image008.jpg deleted file mode 100644 index a071ad67222931372d4b62f7b0cf334a4015e70d..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image008.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image010.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image010.jpg deleted file mode 100644 index 43ca88d40bc56d5a5113bc29b97a7b559ef659af..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image010.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image012.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image012.jpg deleted file mode 100644 index 0e35c9f219292913a51f1f0d5b7a5e154008620f..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image012.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image014.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image014.jpg deleted file mode 100644 index 794de60c7d7e76a58e8d7212e449a1bd8e194b21..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image014.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image015.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image015.jpg deleted file mode 100644 index 8172e21f871bed6866b3a91b83252838228d257a..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image015.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image016.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image016.jpg deleted file mode 100644 index c836c0cf7898e4757ddb3410dde18e754894dd25..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image016.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image018.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image018.jpg deleted file mode 100644 index 777738f7cf60454b7b5f26e6c5a29ba5d55750ff..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image018.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image019.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image019.jpg deleted file mode 100644 index ab02b702bfd1c0986adb4a15c1f455b56df0a4a1..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image019.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image020.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image020.jpg deleted file mode 100644 index d946c3cb3a851f690a5643b5afe119597aed5b22..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image020.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image021.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image021.jpg deleted file mode 100644 index 74672d9513f4a60f77450ae5516cee2060215241..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image021.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image022.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image022.jpg deleted file mode 100644 index 6b26f18c7d8bb43db0beb8a8d2bd386489192922..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image022.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image023.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image023.jpg deleted file mode 100644 index 5981a0fb25c681417a0bdf24d2392411b41f0faf..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image023.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image024.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image024.jpg deleted file mode 100644 index 505e8b6c5c4d81dfd67d91b1dad08f938444368a..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image024.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image025.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image025.jpg deleted file mode 100644 index 946e276b6a982303b6b146266037a739e6c2639a..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image025.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image026.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image026.jpg deleted file mode 100644 index 8b787215af5cf9ae223c2b33121c3171923d2de2..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image026.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image027.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image027.jpg deleted file mode 100644 index aa4d7d4a8a6b503fe29885368547daa535e34796..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image027.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image028.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image028.jpg deleted file mode 100644 index 3126f80aecac28e8beaa54dc393122c60dbe1357..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image028.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image029.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image029.jpg deleted file mode 100644 index 6587240e4a456f3792fece52bcdcbbed077ca67b..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image029.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image031.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image031.jpg deleted file mode 100644 index 2f829b48e72e62525860cfe599e0a4ada82010ca..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image031.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image032.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image032.jpg deleted file mode 100644 index 37589efbe0f57c442f665824831a2685d81c8713..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image032.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image033.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image033.jpg deleted file mode 100644 index bdca68324cf7ee8f4e9bd18817a82954910e52c9..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image033.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image034.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image034.jpg deleted file mode 100644 index 874b10d4b2ca476da16a4d1e749cdb6b31ecb59e..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image034.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image035.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image035.jpg deleted file mode 100644 index 0b0465169553e57795320255295b8fa789950522..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image035.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image036.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image036.jpg deleted file mode 100644 index c7c6c72819b655884d97637b696d1814e5a7fdbf..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image036.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image037.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image037.jpg deleted file mode 100644 index 531e8184e02c43aa177a51c3cc32355cc3df9d42..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image037.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image038.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image038.jpg deleted file mode 100644 index a8b4d88190c626139bad49cd42a9f7e908b4d0e4..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image038.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image039.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image039.jpg deleted file mode 100644 index 2eab0ceac9c1bd5d8b6ade3d65a6a3ce8b1f8fd4..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image039.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image040.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image040.jpg deleted file mode 100644 index a879fb1f12d8b6c4bd02332abf9b3bd734207763..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image040.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image042.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image042.jpg deleted file mode 100644 index 2454ade258da6d428c9e23ece2adf7f0291d1a12..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image042.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image044.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image044.jpg deleted file mode 100644 index cbff652015c36a5856afc909518f3c0fd22f23ff..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image044.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image046.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image046.jpg deleted file mode 100644 index 58a493ea4f69b264fc69cfd3e34f32d5a171c303..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image046.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image050.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image050.jpg deleted file mode 100644 index 35cc26d483358550c9a53ce855c2ae483eddb7e1..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image050.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image052.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image052.jpg deleted file mode 100644 index caa3dde40ee7e6815f603ff1849d275c416b8e38..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image052.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image054.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image054.jpg deleted file mode 100644 index 3a562120b8905cf577035fa4b28dfc35bad324bb..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image054.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image060.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image060.jpg deleted file mode 100644 index 7723975694f7f56d88187a69626343af11efbd23..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image060.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image062.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image062.jpg deleted file mode 100644 index 838bc48ab8d77f7dbba9ca02925838a49b19ce53..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image062.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image064.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image064.jpg deleted file mode 100644 index fb39e70b78b45af301973ea802a219c482a21590..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image064.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image066.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image066.jpg deleted file mode 100644 index 0a596cfb3ef7a79674ff33a7be5c97859cc2b9c4..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image066.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image068.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image068.jpg deleted file mode 100644 index 0023ba9236a768001e462d6a10434719f3f733fd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image068.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image072.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image072.jpg deleted file mode 100644 index d1e5fad4192d4cb5821cafe4031dbc4ff599eccd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image072.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image074.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image074.jpg deleted file mode 100644 index 97fa2b21b4029ff75156893f8abdff2e77aa38bd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image074.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image076.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image076.jpg deleted file mode 100644 index e754c7dcd30ee6fa82ab20bde4d66f69aabe2fa7..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image076.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image088.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image088.jpg deleted file mode 100644 index 8b85f0727893c4cf6cd258550466ca4f4a340e6e..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image088.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image090.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image090.jpg deleted file mode 100644 index a3f405388fd75b23b652bc86475be5fd5e1f48ac..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image090.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image092.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image092.jpg deleted file mode 100644 index 68ca9c66fc3f03760873075af20c8a9e28aaab48..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image092.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image093.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image093.jpg deleted file mode 100644 index 594b2ceadb2c27290e0339e14b298fa2feffe6a9..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image093.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image094.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image094.jpg deleted file mode 100644 index e931a95180d27d55590e73948ebe80a1f81bede1..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image094.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/images/clip_image096.jpg b/docs/devtoolkit/docs/source_zh_cn/images/clip_image096.jpg deleted file mode 100644 index 3ed0c88500bb4caffccea4d08aaa3a6310e177bd..0000000000000000000000000000000000000000 Binary files a/docs/devtoolkit/docs/source_zh_cn/images/clip_image096.jpg and /dev/null differ diff --git a/docs/devtoolkit/docs/source_zh_cn/index.rst b/docs/devtoolkit/docs/source_zh_cn/index.rst deleted file mode 100644 index 6cf624761a90899a4c65f87b9b63b7162618cdd1..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_zh_cn/index.rst +++ /dev/null @@ -1,75 +0,0 @@ -MindSpore Dev Toolkit文档 -============================ - -MindSpore Dev Toolkit是一款面向MindSpore开发者的开发套件。通过深度学习、智能搜索及智能推荐等技术,打造智能计算最佳体验,致力于全面提升MindSpore框架的易用性,助力MindSpore生态推广。 - -MindSpore Dev Toolkit目前提供 `创建项目 `_ 、`智能补全 `_ 、`API互搜 `_ 和 `文档搜索 `_ 四项功能。 - -系统需求 ------------------------------- - -MindSpore Dev Toolkit 是一款 `PyCharm `_ 插件。PyCharm是一款多平台Python IDE。 - -- 插件支持的操作系统: - - - Windows 10 - - - Linux - - - MacOS(仅支持x86架构,补全功能暂未上线) - -- 插件支持的PyCharm版本: - - - 2020.3 - - - 2021.1 - - - 2021.2 - - - 2021.3 - -安装 ----------------------------- - -1. 获取插件安装包 - - 1.1 下载 `插件Zip包 `_ 。 - - 1.2 参见下文源码构建章节 - -2. 启动Pycharm单击左上菜单栏,选择File->Settings->Plugins->Install Plugin from Disk。 - 如图: - - .. image:: ./images/clip_image050.jpg - -3. 选择下载好的插件包(以1.7版本安装包为例)。 - - .. image:: ./images/clip_image052.jpg - -4. 插件安装成功。 - - .. image:: ./images/clip_image054.jpg - -源码构建 ----------------------------- - -请阅读 `源码编译指导 `_ 。 - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: 使用指南 - :hidden: - - compiling - mindspore_project_wizard - operator_search - knowledge_search - smart_completion - -.. toctree:: - :glob: - :maxdepth: 1 - :caption: RELEASE NOTES - - RELEASE diff --git a/docs/devtoolkit/docs/source_zh_cn/knowledge_search.md b/docs/devtoolkit/docs/source_zh_cn/knowledge_search.md deleted file mode 100644 index df76ff5d2fecc8bc2642ec738cea40330b781b69..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_zh_cn/knowledge_search.md +++ /dev/null @@ -1,22 +0,0 @@ -# 智能知识搜索 - - - -## 功能介绍 - -* 定向推荐:根据用户使用习惯,提供更精准的搜索结果。 -* 沉浸式资料检索体验,避免在IDE和浏览器之间的互相切换。适配侧边栏,提供窄屏适配界面。 - -## 使用步骤 - -1. 打开侧边栏,显示搜索主页。 - - ![img](images/clip_image072.jpg) - -2. 输入"api映射",点击搜索,查看结果。 - - ![img](images/clip_image074.jpg) - -3. 点击home按钮回到主页。 - - ![img](images/clip_image076.jpg) \ No newline at end of file diff --git a/docs/devtoolkit/docs/source_zh_cn/mindspore_project_wizard.md b/docs/devtoolkit/docs/source_zh_cn/mindspore_project_wizard.md deleted file mode 100644 index 1e8afc3440365459edbe8585e904f9021fcac9fa..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_zh_cn/mindspore_project_wizard.md +++ /dev/null @@ -1,103 +0,0 @@ -# 创建项目 - - - -## 技术背景 - -本功能的实现基于[conda](https://conda.io)。Conda是一个包管理和环境管理系统,是MindSpore推荐的安装方式之一。 - -## 功能介绍 - -* 创建conda环境或选择已有conda环境,并安装MindSpore二进制包至conda环境。 -* 部署最佳实践模版。不仅可以测试环境是否安装成功,对新用户也提供了一个MindSpore的入门介绍。 -* 在网络状况良好时,10分钟之内即可完成环境安装,开始体验MindSpore。最大可节约新用户80%的环境配置时间。 - -## 使用步骤 - -1. 选择File -> New Project。 - - ![img](images/clip_image002.jpg) - -2. 选择MindSpore。 - - ![img](images/clip_image004.jpg) - -3. Miniconda下载安装。***已经安装过conda的可以跳过此步骤。*** - - 3.1 点击Install Miniconda Automatically按钮。 - - ![img](images/clip_image006.jpg) - - 3.2 选择下载安装文件夹。**建议不修改路径,使用默认路径安装conda。** - - ![img](images/clip_image008.jpg) - - 3.3 点击Install按钮,等待下载安装。 - - ![img](images/clip_image010.jpg) - - ![img](images/clip_image012.jpg) - - 3.4 Miniconda下载安装完成。 - - ![img](images/clip_image014.jpg) - - 3.5 根据提示重新启动PyCharm或者稍后自行重新启动PyCharm。***注意:接下来的步骤必须重启PyCharm后方可继续*** - - ![img](images/clip_image015.jpg) - -4. 确认Conda executable路径已正确填充。 如果Conda executable没有自动填充,点击文件夹按钮,选择本地已安装的conda的路径。 - - ![img](images/clip_image016.jpg) - -5. 创建或选择已有的conda环境。 - - * 创建新的conda环境。 **建议不修改路径,使用默认路径创建conda环境。由于PyCharm限制,Linux系统下暂时无法选择默认目录以外的地址。** - - ![img](images/clip_image018.jpg) - - * 选择PyCharm中已有的conda环境。 - - ![img](images/clip_image019.jpg) - -6. 选择硬件环境和MindSpore项目最佳实践模板。 - - 6.1 选择硬件环境。 - - ![img](images/clip_image020.jpg) - - 6.2 选择最佳实践模板。最佳实践模版是MindSpore提供一些样例项目,以供新用户熟悉MindSpore。最佳实践模版可以直接运行。 - - ![img](images/clip_image021.jpg) - -7. 点击Create按钮新建项目,等待MindSpore下载安装成功。 - - 7.1 点击Create按钮创建MindSpore新项目。 - - ![img](images/clip_image022.jpg) - - 7.2 正在创建创建conda环境。 - - ![img](images/clip_image023.jpg) - - 7.3 正在通过conda配置MindSpore。 - - ![img](images/clip_image024.jpg) - -8. 创建MindSpore项目完成。 - - ![img](images/clip_image025.jpg) - -9. 验证MindSpore项目是否创建成功。 - - * 点击下方Terminal,输入 python -c "import mindspore;mindspore.run_check()" ,查看输出。 如下图,显示了版本号等,表示MindSpore环境可用。 - - ![img](images/clip_image026.jpg) - - * 如果选择了最佳实践模版,可以通过运行最佳实践,测试MindSpore环境。 - - ![img](images/clip_image027.jpg) - - ![img](images/clip_image028.jpg) - - ![img](images/clip_image029.jpg) \ No newline at end of file diff --git a/docs/devtoolkit/docs/source_zh_cn/operator_search.md b/docs/devtoolkit/docs/source_zh_cn/operator_search.md deleted file mode 100644 index 40171d186cfc0a5daa44e88d01161ff22d213e6b..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_zh_cn/operator_search.md +++ /dev/null @@ -1,28 +0,0 @@ -# API互搜 - - - -## 功能介绍 - -* 快速搜索MindSpore API,在侧边栏直接展示API详情。 -* 为方便其他机器学习框架用户,通过搜索其他主流框架API,联想匹配对应MindSpore API。 - -## 使用步骤 - -1. 双击shift弹出全局搜索页面。 - - ![img](images/clip_image060.jpg) - -2. 选择MindSpore。 - - ![img](images/clip_image062.jpg) - -3. 输入要搜索的PyTorch或TensorFlow的API,获取与MindSpore API的对应关系列表。 - - ![img](images/clip_image064.jpg) - - ![img](images/clip_image066.jpg) - -4. 点击列表中的条目,可以在右边侧边栏浏览对应条目的官网文档。 - - ![img](images/clip_image068.jpg) diff --git a/docs/devtoolkit/docs/source_zh_cn/smart_completion.md b/docs/devtoolkit/docs/source_zh_cn/smart_completion.md deleted file mode 100644 index 986be5152062b6481062eb053162929a421cf422..0000000000000000000000000000000000000000 --- a/docs/devtoolkit/docs/source_zh_cn/smart_completion.md +++ /dev/null @@ -1,36 +0,0 @@ -# 代码补全 - - - -## 功能介绍 - -* 提供基于MindSpore项目的AI代码补全。 -* 无需安装MindSpore环境,也可轻松开发MindSpore。 - -## 使用步骤 - -1. 打开Python文件编写代码。 - - ![img](images/clip_image088.jpg) - -2. 编码时,补全会自动生效。有MindSpore图标的条目为MindSpore Dev Toolkit智能补全提供的代码。 - - ![img](images/clip_image090.jpg) - - ![img](images/clip_image092.jpg) - -## 备注 - -1. PyCharm的2021以后版本,会根据机器学习重新排列补全内容。此行为可能导致插件的补全条目排序靠后。可以在设置中停用此功能,使用MindSpore Dev Toolkit提供的排序。 - - ![img](images/clip_image093.jpg) - -2. 关闭此选项前后的对比。 - - * 关闭后。 - - ![img](images/clip_image094.jpg) - - * 关闭前。 - - ![img](images/clip_image096.jpg) \ No newline at end of file diff --git a/docs/federated/docs/Makefile b/docs/federated/docs/Makefile deleted file mode 100644 index 1eff8952707bdfa503c8d60c1e9a903053170ba2..0000000000000000000000000000000000000000 --- a/docs/federated/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/federated/docs/_ext/overwriteobjectiondirective.txt b/docs/federated/docs/_ext/overwriteobjectiondirective.txt deleted file mode 100644 index 3f4ad0e7d157af88949eb8ca39bbd9916639caf3..0000000000000000000000000000000000000000 --- a/docs/federated/docs/_ext/overwriteobjectiondirective.txt +++ /dev/null @@ -1,392 +0,0 @@ -import re -import inspect -import importlib -from typing import Any, Dict, List, Tuple -from typing import 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 RemovedInSphinx40Warning, 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 DirectiveOption - -if False: - # For type annotation - from sphinx.application import Sphinx - - -# RE to strip backslash escapes -nl_escape_re = re.compile(r'\\\n') -strip_backslash_re = re.compile(r'\\(.)') - -logger = logging.getLogger(__name__) - -def optional_int(argument): - """ - 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 [] - -def get_side_effect(name: str): - try: - api_doc = inspect.getdoc(get_api(name)) - side_effect_str = re.findall(r'Side Effects Form:\n\s+(.*?)\n\n', api_doc) - side_effect_str = side_effect_str[0].strip() - side_effect_list = side_effect_str.split('\n') - return ["", "**副作用:**", ""] + side_effect_list + [""] - except: - return [] - -class ObjectDescription(SphinxDirective): - """ - 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 = { - 'noindex': directives.flag, - } # type: Dict[str, DirectiveOption] - - # types of doc fields that this directive handles, see sphinx.util.docfields - doc_field_types = [] # type: List[Field] - domain = None # type: str - objtype = None # type: str - indexnode = None # type: addnodes.index - - # 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') - # remove backslashes to support (dummy) escapes; helps Vim highlighting - return [strip_backslash_re.sub(r'\1', 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 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) - - self.names = [] # type: List[Any] - signatures = self.get_signatures() - for i, sig in enumerate(signatures): - # add a signature node for each signature in the current unit - # and add a reference target for it - signode = addnodes.desc_signature(sig, '') - signode['first'] = False - 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]) - side_effect = get_side_effect(self.names[0][0]) - except IndexError: - example = '' - platforms = '' - side_effect = '' - logger.warning(f'Error API names in {self.arguments[0]}.') - extra = side_effect + 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 IndexError: - logger.warning(f'{self.names[0][0]} has error format.') - self.state.nested_parse(self.content, self.content_offset, 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 [] - -from sphinx.directives.code import ( # noqa - Highlight, CodeBlock, LiteralInclude -) -from sphinx.directives.other import ( # noqa - TocTree, Author, VersionChange, SeeAlso, - TabularColumns, Centered, Acks, HList, Only, Include, Class -) -from sphinx.directives.patches import ( # noqa - Figure, Meta -) -from sphinx.domains.index import IndexDirective # noqa - -deprecated_alias('sphinx.directives', - { - 'Highlight': Highlight, - 'CodeBlock': CodeBlock, - 'LiteralInclude': LiteralInclude, - 'TocTree': TocTree, - 'Author': Author, - 'Index': IndexDirective, - 'VersionChange': VersionChange, - 'SeeAlso': SeeAlso, - 'TabularColumns': TabularColumns, - 'Centered': Centered, - 'Acks': Acks, - 'HList': HList, - 'Only': Only, - 'Include': Include, - 'Class': Class, - 'Figure': Figure, - 'Meta': Meta, - }, - RemovedInSphinx40Warning) - - -# backwards compatible old name (will be marked deprecated in 3.0) -DescDirective = ObjectDescription - - -def setup(app: "Sphinx") -> Dict[str, Any]: - 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/federated/docs/_ext/overwriteviewcode.txt b/docs/federated/docs/_ext/overwriteviewcode.txt deleted file mode 100644 index 130defb02fa41468e2bfda3b3843314c8cd0dcce..0000000000000000000000000000000000000000 --- a/docs/federated/docs/_ext/overwriteviewcode.txt +++ /dev/null @@ -1,274 +0,0 @@ -""" - sphinx.ext.viewcode - ~~~~~~~~~~~~~~~~~~~ - - Add links to module code in Python object descriptions. - - :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -import traceback -import warnings -from typing import Any, Dict, Iterable, Iterator, Set, Tuple - -from docutils import nodes -from docutils.nodes import Element, Node - -import sphinx -from sphinx import addnodes -from sphinx.application import Sphinx -from sphinx.config import Config -from sphinx.deprecation import RemovedInSphinx30Warning -from sphinx.environment import BuildEnvironment -from sphinx.locale import _, __ -from sphinx.pycode import ModuleAnalyzer -from sphinx.util import get_full_modname, logging, status_iterator -from sphinx.util.nodes import make_refnode - - -logger = logging.getLogger(__name__) - - -def _get_full_modname(app: Sphinx, modname: str, attribute: str) -> 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 doctree_read(app: Sphinx, doctree: Node) -> None: - env = app.builder.env - if not hasattr(env, '_viewcode_modules'): - env._viewcode_modules = {} # type: ignore - if app.builder.name == "singlehtml": - return - if app.builder.name.startswith("epub") and not env.config.viewcode_enable_epub: - return - - def has_tag(modname, fullname, docname, refname): - entry = env._viewcode_modules.get(modname, None) # type: ignore - if entry is False: - return - - 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 - - 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 - - for objnode in doctree.traverse(addnodes.desc): - if objnode.get('domain') != 'py': - continue - names = set() # type: Set[str] - for signode in objnode: - if not isinstance(signode, addnodes.desc_signature): - continue - modname = signode.get('module') - fullname = signode.get('fullname') - 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 - # logger.warning(f'modename:{modname}') - # logger.warning(f'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 = '_modules/' + modname.replace('.', '/') - inline = nodes.inline('', _('[源代码]'), classes=['viewcode-link']) - onlynode = addnodes.only(expr='html') - onlynode += addnodes.pending_xref('', inline, reftype='viewcode', refdomain='std', - refexplicit=False, reftarget=pagename, - refid=fullname, refdoc=env.docname) - signode += onlynode - - -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 - env._viewcode_modules.update(other._viewcode_modules) # type: ignore - - -def missing_reference(app: Sphinx, env: BuildEnvironment, node: Element, contnode: Node - ) -> Node: - # resolve our "viewcode" reference nodes -- they need special treatment - if node['reftype'] == 'viewcode': - return make_refnode(app.builder, node['refdoc'], node['reftarget'], - node['refid'], contnode) - - return None - - -def collect_pages(app: Sphinx) -> Iterator[Tuple[str, Dict[str, Any], str]]: - env = app.builder.env - if not hasattr(env, '_viewcode_modules'): - 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 - code, tags, used, refname = entry - # construct a page name for the highlighted source - pagename = '_modules/' + 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, '_modules/' + - parent.replace('.', '/')), - 'title': parent}) - parents.append({'link': urito(pagename, '_modules/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('_modules/index', '_modules/' + modname.replace('.', '/')), - modname)) - html.append('' * (len(stack) - 1)) - context = { - 'title': _('Overview: module code'), - 'body': (_('

    All modules for which code is available

    ') + - ''.join(html)), - } - - yield ('_modules/index', context, 'page.html') - - -def migrate_viewcode_import(app: Sphinx, config: Config) -> None: - if config.viewcode_import is not None: - warnings.warn('viewcode_import was renamed to viewcode_follow_imported_members. ' - 'Please update your configuration.', - RemovedInSphinx30Warning, stacklevel=2) - - -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('config-inited', migrate_viewcode_import) - app.connect('doctree-read', doctree_read) - app.connect('env-merge-info', env_merge_info) - 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') - return { - 'version': sphinx.__display_version__, - 'env_version': 1, - 'parallel_read_safe': True - } diff --git a/docs/federated/docs/requirements.txt b/docs/federated/docs/requirements.txt deleted file mode 100644 index 49a77fdec3a5c745edd40eaa223883c31500e975..0000000000000000000000000000000000000000 --- a/docs/federated/docs/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -sphinx >= 2.2.1, <= 2.4.4 -docutils == 0.16 -myst_parser == 0.14.0 -sphinx-markdown-tables -sphinx_rtd_theme == 0.5.2 -numpy -nbsphinx -IPython -ipykernel -jieba diff --git a/docs/federated/docs/source_en/conf.py b/docs/federated/docs/source_en/conf.py deleted file mode 100644 index d095c00a749e48ba243f650eaa74a176f7bb3669..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/conf.py +++ /dev/null @@ -1,123 +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 sys -import IPython -import re -from sphinx.ext import autodoc as sphinx_autodoc - -import mindspore - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = '2021, 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. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'sphinx_markdown_tables', - 'myst_parser', - 'nbsphinx', - 'sphinx.ext.mathjax', - 'IPython.sphinxext.ipython_console_highlighting' -] - -source_suffix = { - '.rst': 'restructuredtext', - '.md': 'markdown', -} - -# 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. -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' - -html_search_language = 'en' - -# 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'), -} - -# 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/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) diff --git a/docs/federated/docs/source_en/cross_device.rst b/docs/federated/docs/source_en/cross_device.rst deleted file mode 100644 index 4dac8aef128a54f1c1dd749e6e8312e64dac82ab..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/cross_device.rst +++ /dev/null @@ -1,13 +0,0 @@ -Cross-Device -====================== - -.. toctree:: - :maxdepth: 1 - - java_api_callback - java_api_client - java_api_clientmanager - java_api_dataset - java_api_flparameter - java_api_syncfljob - interface_description_federated_client diff --git a/docs/federated/docs/source_en/cross_silo.rst b/docs/federated/docs/source_en/cross_silo.rst deleted file mode 100644 index c1e4bc809d6cc791c5f0f48747e36961a76906c7..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/cross_silo.rst +++ /dev/null @@ -1,5 +0,0 @@ -Cross-Silo -=========== - -.. autoclass:: mindspore.FederatedLearningManager - :members: diff --git a/docs/federated/docs/source_en/deploy_federated_client.md b/docs/federated/docs/source_en/deploy_federated_client.md deleted file mode 100644 index 5ba2d289d4489645569274ba56bb38f836c9ce28..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/deploy_federated_client.md +++ /dev/null @@ -1,198 +0,0 @@ -# On-Device Deployment - - - -The following describes how to deploy the Federated-Client in the Android aarch and Linux x86_64 environments: - -## Android aarch - -### Building a Package - -1. Configure the build environment. - - Currently, only the Linux build environment is supported. For details about how to configure the Linux build environment, click [here](https://www.mindspore.cn/lite/docs/en/master/use/build.html#linux-environment-compilation). - -2. Build the x86-related architecture package in the mindspore home directory. - - ```sh - bash build.sh -I x86_64 -j32 - ``` - - And the x86 architecture package will be generated in the path `mindspore/output/`after compiling ( please backup it to avoid auto-deletion while next compile): - - ```sh - mindspore-lite-{version}-linux-x64.tar.gz - ``` - -3. Turn on Federated-Client compile option and build the AAR package that contains aarch64 and aarch32 in the mindspore home directory. - - ```sh - export MSLITE_ENABLE_FL=on - bash build.sh -A on -j32 - ``` - - The Android AAR package will be generated in the path `mindspore/output/` after compiling ( please backup it to avoid auto-deletion while next compile): - - ```sh - mindspore-lite-full-{version}.aar - ``` - -4. Since the device-side framework and the model are decoupled, we provide Android AAR package `mindspore-lite-full-{version}.aar` that does not contain model-related scripts, so users need to generate the model script corresponding to the jar package. We provide two types of model scripts for your reference ([Supervised sentiment Classification Task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert), [LeNet image classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)). Users can refer to these two types of model scripts, and generate the corresponding jar package (assuming the name is `quick_start_flclient.jar`) after customizing the model script. The jar packages corresponding to the model scripts we provide can be obtained in the following ways: - - After downloading the latest code on [MindSpore Open Source Warehouse](https://gitee.com/mindspore/mindspore), perform the following operations: - - ```sh - cd mindspore/mindspore/lite/examples/quick_start_flclient - sh build.sh -r "mindspore-lite-{version}-linux-x64.tar.gz" # After -r, give the absolute path of the latest x86 architecture package that generate at step 2 - ``` - - After running the above command, the path of the jar package generated is: `mindspore/mindspore/lite/examples/quick_start_flclient/target/quick_start_flclient.jar`. - -### Running Dependencies - -- [Android Studio](https://developer.android.google.cn/studio) >= 4.0 -- [Android SDK](https://developer.android.com/studio?hl=zh-cn#cmdline-tools) >= 29 - -### Building a Dependency Environment - -Renaming `mindspore-lite-full-{version}.aar` to `mindspore-lite-full-{version}.zip`. After the `mindspore-lite-full-{version}.zip` file is decompressed, the following directory structure is obtained: - -```text -mindspore-lite-full-{version} -├── jni -│ ├── arm64-v8a -│ │ ├── libjpeg.so # Dynamic library file for image processing -│ │ ├── libminddata-lite.so # Dynamic library file for image processing -│ │ ├── libmindspore-lite.so # Dynamic library on which the MindSpore Lite inference framework depends -│ │ ├── libmindspore-lite-jni.so # JNI dynamic library on which the MindSpore Lite inference framework depends -│ │ ├── libmindspore-lite-train.so # Dynamic library on which the MindSpore Lite training framework depends -│ │ ├── libmindspore-lite-train-jni.so # JNI dynamic library on which the MindSpore Lite training framework depends -│ │ └── libturbojpeg.so # Dynamic library file for image processing -│ └── armeabi-v7a - │ ├── libjpeg.so # Dynamic library file for image processing -│ ├── libminddata-lite.so # Dynamic library file for image processing -│ ├── libmindspore-lite.so # Dynamic library on which the MindSpore Lite inference framework depends -│ ├── libmindspore-lite-jni.so # JNI dynamic library on which the MindSpore Lite inference framework depends -│ ├── libmindspore-lite-train.so # Dynamic library on which the MindSpore Lite training framework depends -│ ├── libmindspore-lite-train-jni.so # JNI dynamic library on which the MindSpore Lite training framework depends -│ └── libturbojpeg.so # Dynamic library file for image processing -├── libs -│ ├── mindspore-lite-java-common.jar # MindSpore Lite training framework JAR package -│ └── mindspore-lite-java-flclient.jar # Federated learning framework JAR package -└── classes.jar # MindSpore Lite training framework JAR package -``` - -Note 1: since the federated learning jar package in the Android environment does not contain the dependent third-party open source software packages, in the Android environment, before using the AAR package, the user needs to add related dependency statements in the dependencies{} field to load the three open source software that Federated Learning depends on, and the dependencies{} field is in the app/build.gradle file under the Android project, as shown below: - -```text -dependencies { - -// Add third-party open source software that federated learning relies on -implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.14.9' -implementation group: 'com.google.flatbuffers', name: 'flatbuffers-java', version: '2.0.0' -implementation(group: 'org.bouncycastle',name: 'bcprov-jdk15on', version: '1.68') -} -``` - -For specific implementation, please refer to the example of `app/build.gradle` provided in the `Android project configuration dependencies` section in the document [sentiment classification application](https://www.mindspore.cn/federated/docs/en/master/sentiment_classification_application.html). - -Note 2: since the third-party open source software `bcprov-jdk15on` that Federated Learning relies on contains multi-version class files, in order to prevent errors in compiling high-version class files with lower version jdk, the following setting statement can be added to the `gradle.properties` file of the Android project: - -```java -android.jetifier.blacklist=bcprov -``` - -After setting up the dependencies shown above in the Android project, you only need to rely on the AAR package and the jar package corresponding to the model script `quick_start_flclient.jar` to call APIs provided by federated learning. For details about how to call and run the APIs, see the API description of federated learning. - -## Linux x86_64 - -### Building a Package - -1. Configure the build environment. - - Currently, only the Linux build environment is supported. For details about how to configure the Linux build environment, click [here](https://www.mindspore.cn/lite/docs/en/master/use/build.html#linux-environment-compilation). - -2. Build the x86-related architecture package in the mindspore home directory - - ```sh - bash build.sh -I x86_64 -j32 - ``` - - And the x86 architecture package will be generated in the path `mindspore/output/` after compiling ( please backup it to avoid auto-deletion while next compile): - - ```sh - mindspore-lite-{version}-linux-x64.tar.gz - ``` - -3. Since the device-side framework and the model are decoupled, we provide x86 architecture package `mindspore-lite-{version}-linux-x64.tar.gz` that does not contain model-related scripts, so users need to generate the model script corresponding to the jar package. We provide two types of model scripts for your reference ([Supervised sentiment Classification Task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert), [LeNet image classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)). Users can refer to these two types of model scripts, and generate the corresponding jar package (assuming the name is `quick_start_flclient.jar`) after customizing the model script. The jar packages corresponding to the model scripts we provide can be obtained in the following ways: - - After downloading the latest code on [MindSpore Open Source Warehouse](https://gitee.com/mindspore/mindspore), perform the following operations: - - ```sh - cd mindspore/mindspore/lite/examples/quick_start_flclient - sh build.sh -r "mindspore-lite-{version}-linux-x64.tar.gz" # After -r, give the absolute path of the latest x86 architecture package that generate at step 2 - ``` - - After running the above command, the path of the jar package generated is: `mindspore/mindspore/lite/examples/quick_start_flclient/target/quick_start_flclient.jar`. - -### Running Dependencies - -- [Python](https://www.python.org/downloads/) >= 3.7.0 -- [OpenJDK](https://openjdk.java.net/install/) 1.8 to 1.15 - -### Building a Dependency Environment - -After the `mindspore/output/mindspore-lite-{version}-linux-x64.tar.gz` file is decompressed, the following directory structure is obtained: - -```sh -mindspore-lite-{version}-linux-x64 -├── tools -│ ├── benchmark_train # Tool for commissioning the performance and accuracy of the training model -│ ├── converter # Model conversion tool -│ └── cropper # Library cropping tool -│ ├── cropper # Executable file of the library cropping tool -│ └── cropper_mapping_cpu.cfg # Configuration file required for cropping the CPU library -└── runtime - ├── include # Header file of the training framework - │ └── registry # Header file for custom operator registration - ├── lib # Training framework library - │ ├── libminddata-lite.a # Static library file for image processing - │ ├── libminddata-lite.so # Dynamic library file for image processing - │ ├── libmindspore-lite-jni.so # JNI dynamic library on which the MindSpore Lite inference framework depends - │ ├── libmindspore-lite-train.a # Static library on which the MindSpore Lite training framework depends - │ ├── libmindspore-lite-train.so # Dynamic library on which the MindSpore Lite training framework depends - │ ├── libmindspore-lite-train-jni.so # JNI dynamic library on which the MindSpore Lite training framework depends - │ ├── libmindspore-lite.a # Static library on which the MindSpore Lite inference framework depends - │ ├── libmindspore-lite.so # Dynamic library on which the MindSpore Lite inference framework depends - │ ├── mindspore-lite-java.jar # MindSpore Lite training framework JAR package - │ └── mindspore-lite-java-flclient.jar # Federated learning framework JAR package - └── third_party - └── libjpeg-turbo - └── lib - ├── libjpeg.so.62 # Dynamic library file for image processing - └── libturbojpeg.so.0 # Dynamic library file for image processing -``` - -The x86 packages required for federated learning are as follows: - -```sh -libjpeg.so.62 # Dynamic library file for image processing -libminddata-lite.so # Dynamic library file for image processing -libmindspore-lite.so # Dynamic library on which the MindSpore Lite inference framework depends -libmindspore-lite-jni.so # JNI dynamic library on which the MindSpore Lite inference framework depends -libmindspore-lite-train.so # Dynamic library on which the MindSpore Lite training framework depends -libmindspore-lite-train-jni.so # JNI dynamic library on which the MindSpore Lite training framework depends -libturbojpeg.so.0 # Dynamic library file for image processing -mindspore-lite-java-flclient.jar # Federated learning framework JAR package -quick_start_flclient.jar # The jar package corresponding to the model script -``` - -Find the seven .so files on which federated learning depends in the directories `mindspore/output/mindspore-lite-{version}-linux-x64/runtime/lib/` and `mindspore/output/mindspore-lite-{version}-linux-x64/runtime/third_party/libjpeg-turbo/lib`. Then, place these .so files in a folder, for example, `/resource/x86libs/`. - -Set environment variables in the x86 system (an absolute path must be provided): - -```sh -export LD_LIBRARY_PATH=/resource/x86libs/:$LD_LIBRARY_PATH -``` - -After the dependency environment is set, you can simulate the startup of multiple clients in the x86 environment for federated learning. For details, click [here](https://www.mindspore.cn/federated/docs/en/master/image_classification_application.html). diff --git a/docs/federated/docs/source_en/deploy_federated_server.md b/docs/federated/docs/source_en/deploy_federated_server.md deleted file mode 100644 index 786431e99765f6ee17c7204f82bfc353cd9406f0..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/deploy_federated_server.md +++ /dev/null @@ -1,334 +0,0 @@ -# Cloud-based Deployment - - - -The following uses LeNet as an example to describe how to use MindSpore to deploy a federated learning cluster. - -> You can download the complete demo from [here](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/mobile). - -The following figure shows the physical architecture of the MindSpore Federated Learning (FL) Server cluster: - -![mindspore-federated-networking](./images/mindspore_federated_networking.png) - -As shown in the preceding figure, in the federated learning cloud cluster, there are two MindSpore process roles: `Federated Learning Scheduler` and `Federated Learning Server`: - -- Federated Learning Scheduler - - `Scheduler` provides the following functions: - - 1. Cluster networking assistance: During cluster initialization, the `Scheduler` collects server information and ensures cluster consistency. - 2. Open management plane: You can manage clusters through the `RESTful` APIs. - - In a federated learning task, there is only one `Scheduler`, which communicates with the `Server` using the TCP proprietary protocol. - -- Federated Learning Server - - `Server` executes federated learning tasks, receives and parses data from devices, and provides capabilities such as secure aggregation, time-limited communication, and model storage. In a federated learning task, users can configure multiple `Servers` which communicate with each other through the TCP proprietary protocol and open HTTP ports for device-side connection. - - > In the MindSpore federated learning framework, `Server` also supports auto scaling and disaster recovery, and can dynamically schedule hardware resources without interrupting training tasks. - -`Scheduler` and `Server` must be deployed on a server or container with a single NIC and in the same network segment. MindSpore automatically obtains the first available IP address as the `Server` IP address. - -> The servers will verify the timestamp carried by the clients. It is necessary to eunsure the servers are periodically time synchronized to avoid a large time offset. - -## Preparations - -### Installing MindSpore - -The MindSpore federated learning cloud cluster supports deployment on x86 CPU and GPU CUDA hardware platforms. Run commands provided by the [MindSpore Installation Guide](https://www.mindspore.cn/install) to install the latest MindSpore. - -## Defining a Model - -To facilitate deployment, the `Scheduler` and `Server` processes of MindSpore federated learning can reuse the training script. You can select different startup modes by referring to [Configuring Parameters](#configuring-parameters). - -This tutorial uses LeNet as an example. For details about the network structure, loss function, and optimizer definition, see [LeNet sample code](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/lenet/lenet.py). - -## Configuring Parameters - -The MindSpore federated learning task process reuses the training script. You only need to use the same script to transfer different parameters through the Python API `set_fl_context` and start different MindSpore process roles. For details about the parameter configuration, see [MindSpore API](https://www.mindspore.cn/federated/docs/en/master/federated_server.html#mindspore.set_fl_context). - -After parameter configuration and before training, call the `set_fl_context` API as follows: - -```python -import mindspore as ms -... - -enable_fl = True -server_mode = "FEDERATED_LEARNING" -ms_role = "MS_SERVER" -server_num = 4 -scheduler_ip = "192.168.216.124" -scheduler_port = 6667 -fl_server_port = 6668 -fl_name = "LeNet" -scheduler_manage_port = 11202 -config_file_path = "./config.json" - -fl_ctx = { - "enable_fl": enable_fl, - "server_mode": server_mode, - "ms_role": ms_role, - "server_num": server_num, - "scheduler_ip": scheduler_ip, - "scheduler_port": scheduler_port, - "fl_server_port": fl_server_port, - "fl_name": fl_name, - "scheduler_manage_port": scheduler_manage_port, - "config_file_path": config_file_path -} -ms.set_fl_context(**fl_ctx) -... - -model.train() -``` - -In this example, the training task mode is set to `federated learning` (`FEDERATED_LEARNING`), and the training process role is `Server`. In this task, `4` `Servers` need to be started to complete the cluster networking. The IP address of the cluster `Scheduler` is `192.168.216.124`, the cluster `Scheduler` port number is `6667`, the `HTTP service port number` of federated learning is `6668` (connected by the device), the task name is `LeNet`, and the cluster `Scheduler` management port number is `11202`. - -> Some parameters are used by either `Scheduler` (for example, scheduler_manage_port) or `Server` (for example, fl_server_port). To facilitate deployment, transfer these parameters together to MindSpore. MindSpore reads different parameters based on process roles. -> You are advised to import the parameter configuration through the Python `argparse` module: - -```python -import argparse - -parser = argparse.ArgumentParser() -parser.add_argument("--server_mode", type=str, default="FEDERATED_LEARNING") -parser.add_argument("--ms_role", type=str, default="MS_SERVER") -parser.add_argument("--server_num", type=int, default=4) -parser.add_argument("--scheduler_ip", type=str, default="192.168.216.124") -parser.add_argument("--scheduler_port", type=int, default=6667) -parser.add_argument("--fl_server_port", type=int, default=6668) -parser.add_argument("--fl_name", type=str, default="LeNet") -parser.add_argument("--scheduler_manage_port", type=int, default=11202) -parser.add_argument("--config_file_path", type=str, default="") - -args, t = parser.parse_known_args() -server_mode = args.server_mode -ms_role = args.ms_role -server_num = args.server_num -scheduler_ip = args.scheduler_ip -scheduler_port = args.scheduler_port -fl_server_port = args.fl_server_port -fl_name = args.fl_name -scheduler_manage_port = args.scheduler_manage_port -config_file_path = args.config_file_path -``` - -> Each Python script corresponds to a process. If multiple `Server` roles need to be deployed on different hosts, you can use shell commands and Python to quickly start multiple `Server` processes. You can refer to the [examples](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/mobile). -> -> Each `Server` process needs a unique identifier `MS_NODE_ID` which should be set by environment variable. In this tutorial, this environment variable has been set in the script [run_mobile_server.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/mobile/run_mobile_server.py). - -## Starting a Cluster - -Start the cluster by referring to the [examples](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/mobile). An example directory structure is as follows: - -```text -mobile/ -├── config.json -├── finish_mobile.py -├── run_mobile_sched.py -├── run_mobile_server.py -├── src -│ └── model.py -└── test_mobile_lenet.py -``` - -Descriptions of the documents: - -- config.json: The config file, which is used to configure security, disaster recovery, etc. -- finish_mobile.py: This script is used to stop the cluster. -- run_mobile_sched.py: Launch scheduler. -- run_mobile_server.py: Launch server. -- model.py: The model. -- test_mobile_lenet.py: Training script. - -1. Start the `Scheduler`. - - `run_mobile_sched.py` is a Python script provided for you to start `Scheduler` and supports configuration modification through passing the `argparse` parameter. Run the following command to start the `Scheduler` of the federated learning task. The TCP port number is `6667`, the HTTP service port number starts with `6668`, the number of `Server` is `4`, and the management port number of the cluster `Scheduler` is `11202`: - - ```sh - python run_mobile_sched.py --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --scheduler_manage_port=11202 --config_file_path=$PWD/config.json - ``` - -2. Start the `Servers`. - - `run_mobile_server.py` is a Python script provided for you to start multiple `Servers` and supports configuration modification through passing the `argparse` parameter. Run the following command to start the `Servers` of the federated learning task. The TCP port number is `6667`, the HTTP service port number starts with `6668`, the number of `Server` is `4`, and the number of devices required for the federated learning task is `8`. - - ```sh - python run_mobile_server.py --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --start_fl_job_threshold=8 --config_file_path=$PWD/config.json - ``` - - The preceding command is equivalent to starting four `Server` processes, of which the federated learning service port numbers are `6668`, `6669`, `6670`, and `6671`. For details, see [run_mobile_server.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/mobile/run_mobile_server.py). - - > If you only want to deploy `Scheduler` and `Server` in a standalone system, change the `scheduler_ip` to `127.0.0.1`. - - To distribute the `Servers` on different physical nodes, you can use the `local_server_num` parameter to specify the number of `Server` processes to be executed on **the current node**. - - ```sh - #Start three `Server` processes on node 1. - python run_mobile_server.py --scheduler_ip={ip_address_node_1} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --start_fl_job_threshold=8 --local_server_num=3 --config_file_path=$PWD/config.json - ``` - - ```sh - #Start one `Server` process on node 2. - python run_mobile_server.py --scheduler_ip={ip_address_node_2} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --start_fl_job_threshold=8 --local_server_num=1 --config_file_path=$PWD/config.json - ``` - - The log is displayed as follows: - - ```sh - Server started successfully. - ``` - - If the preceding information is displayed, it indicates that the startup is successful. - - > In the preceding commands for distributed deployment, all values of `server_num` are set to 4. This is because this parameter indicates the number of global `Servers` in the cluster and should not change with the number of physical nodes. `Servers` on different nodes do not need to be aware of their own IP addresses. The cluster consistency and node discovery are scheduled by `Scheduler`. - -3. Stop federated learning. - - Currently, `finish_mobile.py` is used to stop the federated learning server. Run the following command to stop the federated learning cluster. The value of the `scheduler_port` parameter is the same as that passed when the server is started. - - ```sh - python finish_mobile.py --scheduler_port=6667 - ``` - - The result is as follows: - - ```sh - killed $PID1 - killed $PID2 - killed $PID3 - killed $PID4 - killed $PID5 - killed $PID6 - killed $PID7 - killed $PID8 - ``` - - The services are stopped successfully. - -## Auto Scaling - -The MindSpore federated learning framework supports auto scaling of `Server` and provides the `RESTful` service through the `Scheduler` management port. In this way, you can dynamically schedule hardware resources without interrupting training tasks. Currently, MindSpore supports only horizontal scaling (scale-out or scale-in) and does not support vertical scaling (scale-up or scale-down). In the auto scaling scenario, the number of `Server` processes either increases or decreases according to user settings. - -The following describes how to control cluster scale-in and scale-out using the native RESTful APIs. - -1. Scale-out - - After the cluster is started, enter the machine where the scheduler node is deployed and send a scale-out request to `Scheduler`. Use the `curl` instruction to construct a `RESTful` scale-out request, indicating that two `Server` nodes need to be added to the cluster. - - ```sh - curl -i -X POST \ - -H "Content-Type:application/json" \ - -d \ - '{ - "worker_num":0, - "server_num":2 - }' \ - 'http://127.0.0.1:11202/scaleout' - ``` - - Start `2` new `Server` processes and the `node_id` of the expanded `Server` cannot be the same as the `node_id` of the existing `Server`, add up the values of `server_num` to ensure that the global networking information is correct. After the scale-out, the value of `server_num` should be `6`. - - ```sh - python run_mobile_server.py --node_id=scale_node --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6672 --server_num=6 --start_fl_job_threshold=8 --local_server_num=2 --config_file_path=$PWD/config.json - ``` - - This command is used to start two `Server` nodes. The port numbers of the federated learning services are `6672` and `6673`, and the total number of `Servers` is `6`. - -2. Scale-in - - After the cluster is started, enter the machine where the scheduler node is deployed and send a scale-in request to `Scheduler`. Obtain the node information to perform the scale-in operation on specific nodes. - - ```sh - curl -i -X GET \ - 'http://127.0.0.1:11202/nodes' - ``` - - The `scheduler` will return the query results in the `json` format: - - ```json - { - "message": "Get nodes info successful.", - "nodeIds": [ - { - "alive": "true", - "nodeId": "3", - "rankId": "3", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "0", - "rankId": "0", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "2", - "rankId": "2", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "1", - "rankId": "1", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "20", - "rankId": "0", - "role": "SCHEDULER" - } - ] - } - ``` - - Select `Rank3` and `Rank2` for scale-in. - - ```sh - curl -i -X POST \ - -H "Content-Type:application/json" \ - -d \ - '{ - "node_ids": ["2", "3"] - }' \ - 'http://127.0.0.1:11202/scalein' - ``` - -> - After the cluster scale-out or scale-in is successful, the training task is automatically restored. No manual intervention is required. -> -> - You can use a cluster management tool (such as Kubernetes) to create or release `Server` resources. -> -> - After scale-in, the process scaled in will not exit. You need to use the cluster management tool (such as Kubernetes) or command `kill -15 $PID` to control the process to exit. Please note that you need to query the cluster status from the 'scheduler' node and wait for the cluster status to be set to `CLUSTER_READY`, the reduced node can be recycled. - -## Disaster Recovery - -After a node in the MindSpore federated learning cluster goes offline, you can keep the cluster online without exiting the training task. After the node is restarted, you can resume the training task. Currently, MindSpore supports disaster recovery for `Server` nodes (except Server 0). - -To enable disaster recovery, the fields below should be added to the config.json set by config_file_path: - -```json -{ - "recovery": { - "storage_type": 1, - "storge_file_path": "config.json" - } -} -``` - -- recovery: If this field is set, the disaster recovery feature is enabled. -- storage_type: Persistent storage type. Only `1` is supported currently which represents file storage. -- storage_file_path: The recovery file path. - -The node restart command is similar to the scale-out command. After the node is manually brought offline, run the following command: - -```sh -python run_mobile_server.py --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6673 --server_num=6 --start_fl_job_threshold=8 --local_server_num=1 --config_file_path=$PWD/config.json -``` - -This command indicates that the `Server` is restarted. The federated learning service port number is `6673`. - -> MindSpore does not support disaster recovery after the auto scaling command is successfully delivered and before the scaling service is complete. -> -> After recovery, the restarted node's `MS_NODE_ID` variable should be the same as the one which exited in exception to ensure the networking recovery. diff --git a/docs/federated/docs/source_en/faq.md b/docs/federated/docs/source_en/faq.md deleted file mode 100644 index f38763411f04092ef2cbbd7fbb0ed8d54c54daa8..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/faq.md +++ /dev/null @@ -1,9 +0,0 @@ -# FAQ - - - -**Q: If the cluster networking is unsuccessful, how to locate the cause?** - -A: Please check the server's network conditions, for example, check whether the firewall prohibits port access, please set the firewall to allow port access. - -
    \ No newline at end of file diff --git a/docs/federated/docs/source_en/federated_client.rst b/docs/federated/docs/source_en/federated_client.rst deleted file mode 100644 index d7d06a57c8d0679d072c3fc7cc3c0f72a9d3a49f..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/federated_client.rst +++ /dev/null @@ -1,8 +0,0 @@ -Federated-Client -================ - -.. toctree:: - :maxdepth: 1 - - cross_device - cross_silo diff --git a/docs/federated/docs/source_en/federated_install.md b/docs/federated/docs/source_en/federated_install.md deleted file mode 100644 index 4578d878bbc85ace72ad95ba2876a133f88aa2d0..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/federated_install.md +++ /dev/null @@ -1,19 +0,0 @@ -# Obtaining MindSpore Federated - - - -## Installation Overview - -Currently, the MindSpore Federated framework code has been integrated into the MindSpore framework on the cloud and the MindSpore Lite framework on the device. Therefore, you need to obtain the MindSpore WHL package and MindSpore Lite Java installation package separately. The MindSpore WHL package is used for cluster aggregation training on the cloud and communication with Lite. The MindSpore Lite Java package contains two parts. One is the MindSpore Lite training installation package, which is used for bottom-layer model training. The other is the Federated-Client installation package, which is used for model delivery, encryption, and interaction with the MindSpore service on the cloud. - -### Obtaining the MindSpore WHL Package - -You can use the source code or download the release version to install MindSpore on hardware platforms such as the x86 CPU and GPU CUDA. For details about the installation process, see [Install](https://www.mindspore.cn/install/en) on the MindSpore website. - -### Obtaining the MindSpore Lite Java Package - -You can use the source code or download the release version. Currently, only the Linux and Android platforms are supported, and only the CPU hardware architecture is supported. For details about the installation process, see [Downloading MindSpore Lite](https://www.mindspore.cn/lite/docs/en/master/use/downloads.html) and [Building MindSpore Lite](https://www.mindspore.cn/lite/docs/en/master/use/build.html). For details, see "Deploying Federated-Client." - -### Requirements for Building the Linux Environment - -Currently, the source code build is supported only in the Linux environment. For details about the environment requirements, see [MindSpore Source Code Build](https://www.mindspore.cn/install/en) and [MindSpore Lite Source Code Build](https://www.mindspore.cn/lite/docs/en/master/use/build.html). diff --git a/docs/federated/docs/source_en/federated_server.rst b/docs/federated/docs/source_en/federated_server.rst deleted file mode 100644 index a062cc5f2ba347f9c4e875e6ef701b2a84107d4a..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/federated_server.rst +++ /dev/null @@ -1,6 +0,0 @@ -Federated-Server -================= - -.. autofunction:: mindspore.set_fl_context - -.. autofunction:: mindspore.get_fl_context diff --git a/docs/federated/docs/source_en/image_classification_application.md b/docs/federated/docs/source_en/image_classification_application.md deleted file mode 100644 index 094bb9a2162b0ed310f46c3d24d84b650df48cb8..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/image_classification_application.md +++ /dev/null @@ -1,309 +0,0 @@ -# Implementing an Image Classification Application of Cross-device Federated Learning (x86) - - - -Federated learning can be divided into cross-silo federated learning and cross-device federated learning according to different participating customers. In the cross-silo federation learning scenario, the customers participating in federated learning are different organizations (for example, medical or financial) or geographically distributed data centers, that is, training models on multiple data islands. The clients participating in the cross-device federation learning scenario are a large number of mobiles or IoT devices. This framework will introduce how to use the network LeNet to implement an image classification application on the MindSpore cross-silo federation framework, and provides related tutorials for simulating to start multi-client participation in federated learning in the x86 environment. - -Before you start, check whether MindSpore has been correctly installed. If not, install MindSpore on your computer by referring to [Install](https://www.mindspore.cn/install/en) on the MindSpore website. - -## Preparatory Work - -We provide [Federated Learning Image Classification Dataset FEMNIST](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/federated/3500_clients_bin.zip) and the [device-side model file](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/models/lenet_train.ms) of the `.ms` format for users to use directly. Users can also refer to the following tutorials to generate the datasets and models based on actual needs. - -### Data Processing - -In this example, the federated learning dataset `FEMNIST` in the `leaf` dataset is used. For the specific acquisition method of the dataset, please refer to the document [Device-cloud federation learning image classification dataset processing](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/client/image_classfication_dataset_process_en.md#). - -Users can also define the dataset by themselves. Note that the dataset must be a `.bin` format file, and the data dimension in the file must be consistent with the input dimension of the network. - -### Generating a Device Model File - -1. **Define the network and training process** - - For the definition of the specific network and training process, please refer to [Beginners Getting Started](https://www.mindspore.cn/tutorials/en/master/beginner/quick_start.html). - - We provide the network definition file [model.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/mobile/src/model.py) and the training process definition file [run_export_lenet.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/cloud/run_export_lenet.py) for your reference. - -2. **Export a model as a MindIR file.** - - Run the script `run_export_lenet.py` to obtain the MindIR format model file, the code snippet is as follows: - - ```python - import mindspore as ms - ... - - parser = argparse.ArgumentParser(description="export mindir for lenet") - parser.add_argument("--device_target", type=str, default="CPU") - parser.add_argument("--mindir_path", type=str, default="lenet_train.mindir") # The path for the file in MindIR format. - ... - - for _ in range(epoch): - data = Tensor(np.random.rand(32, 3, 32, 32).astype(np.float32)) - label = Tensor(np.random.randint(0, 61, (32)).astype(np.int32)) - loss = train_network(data, label).asnumpy() - losses.append(loss) - ms.export(train_network, data, label, file_name= mindir_path, file_format='MINDIR') # Add the export statement to obtain the model file in MindIR format. - print(losses) - ``` - - The specific operating instructions are as follows: - - ```sh - python run_export_lenet.py --mindir_path="ms/lenet/lenet_train.mindir" - ``` - - The parameter `--mindir_path` is used to set the path of the generated file in MindIR format. - -3. **Convert the MindIR file into an .ms file that can be used by the federated learning framework on the device.** - - For details about model conversion, see [Training Model Conversion Tutorial](https://www.mindspore.cn/lite/docs/en/master/use/converter_train.html). - - The following is an example of model conversion: - - Assume that the model file to be converted is `lenet_train.mindir`. Run the following command: - - ```sh - ./converter_lite --fmk=MINDIR --trainModel=true --modelFile=lenet_train.mindir --outputFile=lenet_train - ``` - - If the conversion is successful, the following information is displayed: - - ```sh - CONVERTER RESULT SUCCESS:0 - ``` - - This indicates that the MindSpore model is successfully converted to the MindSpore device model and the new file `lenet_train.ms` is generated. If the conversion fails, the following information is displayed: - - ```sh - CONVERT RESULT FAILED: - ``` - - Save the generated model file in `.ms` format to a path. When the federated learning API is called, FLParameter.trainModelPath can be set to the path of the model file. - -## Simulating Multi-client Participation in Federated Learning - -1. **Prepare a model file for the client.** - - In the actual scenario, a client contains a model file in .ms format. In the simulation scenario, you need to copy multiple .ms files and name them in `lenet_train{i}.ms` format. In the format, i indicates the client ID. Due to the script settings in `run.py`, i must be set to a number, such as `0, 1, 2, 3, 4, 5...`. Each client uses an .ms file. - - You can copy and name the original .ms file by referring to the following steps: - - ```python - import shutil - import os - - def copy_file(raw_path,new_path,copy_num): - # Copy the specified number of files from the raw path to the new path - for i in range(copy_num): - file_name = "lenet_train" + str(i) + ".ms" - new_file_path = os.path.join(new_path, file_name) - shutil.copy(raw_path ,new_file_path) - print('====== copying ',i, ' file ======') - print("the number of copy .ms files: ", len(os.listdir(new_path))) - - if __name__ == "__main__": - raw_path = "lenet_train.ms" - new_path = "ms/lenet" - num = 8 - copy_file(raw_path, new_path, num) - ``` - - Set `raw_path` to the path of the original .ms file, `new_path` to the path of the .ms file to be copied, and `num` to the number of copies. Generally, you need to simulate the number of started clients. - - For example, in the preceding script, the .ms file is generated in the `ms/lenet` directory for eight clients. The directory structure is as follows: - - ```sh - ms/lenet - ├── lenet_train0.ms # .ms file used by client 0. - ├── lenet_train1.ms # .ms file used by client 1. - ├── lenet_train2.ms # .ms file used by client 2. - ├── lenet_train3.ms # .ms file used by client 3. - │ - │ ...... - │ - └── lenet_train7.ms # .ms file used by client 7. - ``` - -2. **Start the cloud side service** - - Users can first refer to [cloud-side deployment tutorial](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_server.html) to deploy the cloud-side environment and start the cloud-side service. - -3. **Start the client** - - Before starting the client, please refer to the section [x86](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_client.html) in the Federated-Client deployment tutorial for deployment of device environment. - - Our framework provides three types of federated learning interfaces for users to call. For specific interface introduction, please refer to [API file](https://www.mindspore.cn/federated/docs/en/master/java_api_syncfljob.html) : - - - `SyncFLJob.flJobRun()` - - Used to start the client to participate in the federated learning training task, and to obtain the final trained aggregation model. - - - `SyncFLJob.modelInfer()` - - Used to obtain the inference result of a given dataset. - - - `SyncFLJob.getModel()` - - Used to get the latest model on the cloud side. - - After the cloud-side service starts successfully, you can write a Python script to call the federated learning framework jar package `mindspore-lite-java-flclient.jar` and the jar package corresponding to the model script `quick_start_flclient.jar` (refer to [Building a Package](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_client.html) in the Federated-Client deployment tutorial) to simulate multi-client participation in federated learning tasks. - - We provide a reference script [run_client_x86.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/client/run_client_x86.py), users can set relevant parameters to start different federated learning interfaces. - - Taking the LeNet network as an example, some of the input parameters in the `run_client_x86.py` script have the following meanings, and users can set them according to the actual situation: - - - **`--jarPath`** - - Specifies the path of the JAR package of the federated learning framework. For details about how to obtain the JAR package in the x86 environment, see [Building a Package](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_client.html) in the Federated-Client deployment tutorial. - - Note, please make sure that only the JAR package is included in the path. For example, in the above reference script, `--jarPath` is set to `"libs/jarX86/mindspore-lite-java-flclient.jar"`, you need to make sure that the `jarX86` folder contains only one JAR package `mindspore-lite-java-flclient.jar`. - - - **`--case_jarPath`** - - Specifies the path of the JAR package `quick_start_flclient.jar` corresponding to the model script. For details about how to obtain the JAR package in the x86 environment, see [Building a Package](https://gitee.com/mindspore/docs/blob/master/docs/federated/docs/source_en/deploy_federated_client.md#) in the Federated-Client deployment tutorial. - - Note, please make sure that only the JAR package is included in the path. For example, in the above reference script, `--case_jarPath` is set to `"case_jar/quick_start_flclient.jar"`, you need to make sure that the `case_jar` folder contains only one JAR package `quick_start_flclient.jar`. - - - **`--train_dataset`** - - Specifies the root path of the training dataset.The sentiment classification task stores the training data (in .txt format) of each client. The LeNet image classification task stores the training files data.bin and label.bin of each client, for example, `data/femnist/3500_clients_bin/`. - - - **`--flName`** - - Specifies the package path of model script used by federated learning. We provide two types of model scripts for your reference ([Supervised sentiment classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert), [Lenet image classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)). For supervised sentiment classification tasks, this parameter can be set to the package path of the provided script file [AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java), like as `com.mindspore.flclient.demo.albert.AlbertClient`; for Lenet image classification tasks, this parameter can be set to the package path of the provided script file [LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java), like as `com.mindspore.flclient.demo.lenet.LenetClient`. At the same time, users can refer to these two types of model scripts, define the model script by themselves, and then set the parameter to the package path of the customized model file ModelClient.java (which needs to inherit from the class [Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java)). - - - **`--train_model_path`** - - Specifies the training model path used for federated learning. The path is the directory where multiple .ms files copied in the preceding tutorial are stored, for example, `ms/lenet`. The path must be an absolute path. - - - **`--train_ms_name`** - - Set the same part of the multi-client training model file name. The model file name must be in the format `{train_ms_name}1.ms`, `{train_ms_name}2.ms`, `{train_ms_name}3.ms`, etc. - - - **`--domain_name`** - - Used to set the url for device-cloud communication. Currently, https and http communication are supported, the corresponding formats are like as: https://......, http://......, and when `if_use_elb` is set to true, the format must be: https://127.0.0.1:6666 or http://127.0.0.1:6666 , where `127.0.0.1` corresponds to the ip of the machine providing cloud-side services (corresponding to the cloud-side parameter `--scheduler_ip`), and `6666` corresponds to the cloud-side parameter `--fl_server_port`. - - - **`--task`** - - Specifies the type of the task to be started. `train` indicates that a training task is started. `inference` indicates that multiple data inference tasks are started. `getModel` indicates that the task for obtaining the cloud model is started. Other character strings indicate that the inference task of a single data record is started. The default value is `train`. The initial model file (.ms file) is not trained. Therefore, you are advised to start the training task first. After the training is complete, start the inference task. (Note that the values of client_num in the two startups must be the same to ensure that the model file used by `inference` is the same as that used by `train`.) - - - **`--batch_size`** - - Specifies the number of single-step training samples used in federated learning training and inference, that is, batch size. It needs to be consistent with the batch size of the input data of the model. - - - **`--client_num`** - - Specifies the number of clients. The value must be the same as that of `start_fl_job_cnt` when the server is started. This parameter is not required in actual scenarios. - - If you want to know more about the meaning of other parameters in the `run_client_x86.py` script, you can refer to the comments in the script. - - The basic startup instructions of the federated learning interface are as follows: - - ```sh - python run_client_x86.py --jarPath="libs/jarX86/mindspore-lite-java-flclient.jar" --case_jarPath="case_jar/quick_start_flclient.jar" --train_dataset="data/femnist/3500_clients_bin/" --test_dataset="null" --vocal_file="null" --ids_file="null" --flName="com.mindspore.flclient.demo.lenet.LenetClient" --train_model_path="ms/lenet/" --infer_model_path="ms/lenet/" --train_ms_name="lenet_train" --infer_ms_name="lenet_train" --domain_name="http://127.0.0.1:6666" --cert_path="certs/https_signature_certificate/client/CARoot.pem" --use_elb="true" --server_num=4 --client_num=8 --thread_num=1 --server_mode="FEDERATED_LEARNING" --batch_size=32 --task="train" - ``` - - Note that the path-related parameters must give an absolute path. - - The above commands indicate that eight clients are started to participate in federated learning. If the startup is successful, log files corresponding to the eight clients are generated in the current folder. You can view the log files to learn the running status of each client. - - ```sh - ./ - ├── client_0 - │ └── client.log # Log file of client 0. - │ ...... - └── client_7 - └── client.log # Log file of client 7. - ``` - - For different interfaces and scenarios, you only need to modify specific parameter values according to the meaning of the parameters, such as: - - - Start federated learning and training tasks: SyncFLJob.flJobRun() - - When `--task` in `Basic Start Command` is set to `train`, it means to start the task. - - You can use the command `grep -r "average loss:" client_0/client.log` to view the average loss of each epoch of `client_0` during the training process. It will be printed as follows: - - ```sh - INFO: ----------epoch:0,average loss:4.1258564 ---------- - ...... - ``` - - You can also use the command `grep -r "evaluate acc:" client_0/client.log` to view the verification accuracy of the model after the aggregation in each federated learning iteration for `client_0` . It will be printed like the following: - - ```sh - INFO: [evaluate] evaluate acc: 0.125 - ...... - ``` - - - Start the inference task: SyncFLJob.modelInference() - - When `--task` in `Basic Start Command` is set to `inference`, it means to start the task. - - You can view the inference result of `client_0` through the command `grep -r "the predicted labels:" client_0/client.log`: - - ```sh - INFO: [model inference] the predicted labels: [0, 0, 0, 1, 1, 1, 2, 2, 2] - ...... - ``` - - - Start the task of obtaining the latest model on the cloud side: SyncFLJob.getModel() - - When `--task` in `Basic Start Command` is set to `inference`, it means to start the task. - - If there is the following content in the log file, it means that the latest model on the cloud side is successfully obtained: - - ```sh - INFO: [getModel] get response from server ok! - ``` - -4. **Stop the client process.** - - For details, see the `finish.py` script. The details are as follows: - - ```python - import os - import argparse - import subprocess - - parser = argparse.ArgumentParser(description="Finish test_mobile_lenet.py case") - parser.add_argument("--kill_tag", type=str, default="mindspore-lite-java-flclient") - - args, _ = parser.parse_known_args() - kill_tag = args.kill_tag - - cmd = "pid=`ps -ef|grep " + kill_tag - cmd += " |grep -v \"grep\" | grep -v \"finish\" |awk '{print $2}'` && " - cmd += "for id in $pid; do kill -9 $id && echo \"killed $id\"; done" - - subprocess.call(['bash', '-c', cmd]) - ``` - - Run the following command to shut down the client: - - ```sh - python finish.py --kill_tag=mindspore-lite-java-flclient - ``` - - The parameter `--kill_tag` is used to search for the keyword to kill the client process. You only need to set the special keyword in `--jarPath`. The default value is `mindspore-lite-java-flclient`, that is, the name of the federated learning JAR package. - - The user can check whether the process still exists through the command `ps -ef |grep "mindspore-lite-java-flclient"`. - -5. **Experimental results of 50 clients participating in federated learning and training tasks. ** - - Currently, the **`3500_clients_bin`** folder contains data of 3500 clients. This script can simulate a maximum of 3500 clients to participate in federated learning. - - The following figure shows the accuracy of the test dataset for federated learning on 50 clients (set `server_num` to 16). - - ![lenet_50_clients_acc](images/lenet_50_clients_acc.png) - - The total number of federated learning iterations is 100, the number of epochs for local training on the client is 20, and the value of batchSize is 32. - - The test accuracy in the figure refers to the accuracy of each client test dataset on the aggregated model on the cloud for each federated learning iteration: - - AVG: average accuracy of 50 client test datasets - - TOP5: average accuracy of the five clients with the highest accuracy in the test dataset - - LOW5: average accuracy of the five clients with the lowest accuracy in the test dataset3 \ No newline at end of file diff --git a/docs/federated/docs/source_en/images/create_android_project.png b/docs/federated/docs/source_en/images/create_android_project.png deleted file mode 100644 index a519264c4158fba67eb1ff5f5fbc3eae65b32363..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_en/images/create_android_project.png and /dev/null differ diff --git a/docs/federated/docs/source_en/images/federated_en.png b/docs/federated/docs/source_en/images/federated_en.png deleted file mode 100644 index 7c6a040c57d87df5ecdc5fce318885d924e2e625..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_en/images/federated_en.png and /dev/null differ diff --git a/docs/federated/docs/source_en/images/lenet_50_clients_acc.png b/docs/federated/docs/source_en/images/lenet_50_clients_acc.png deleted file mode 100644 index c1282811f7161d77ec2ea563d96983ef293dbf43..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_en/images/lenet_50_clients_acc.png and /dev/null differ diff --git a/docs/federated/docs/source_en/images/mindspore_federated_networking.png b/docs/federated/docs/source_en/images/mindspore_federated_networking.png deleted file mode 100644 index 95865169bf5802e43a6ab2882912ff2ebce32bb1..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_en/images/mindspore_federated_networking.png and /dev/null differ diff --git a/docs/federated/docs/source_en/images/start_android_project.png b/docs/federated/docs/source_en/images/start_android_project.png deleted file mode 100644 index 3a9336add10acbbef60dc429b8a3bad1ca198c38..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_en/images/start_android_project.png and /dev/null differ diff --git a/docs/federated/docs/source_en/index.rst b/docs/federated/docs/source_en/index.rst deleted file mode 100644 index d37ebcc0dfb84935e7f8a3207b2f38eb6e39aa22..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/index.rst +++ /dev/null @@ -1,103 +0,0 @@ -.. MindSpore documentation master file, created by - sphinx-quickstart on Thu Mar 24 11:00:00 2020. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -MindSpore Federated Documents -================================ - -MindSpore Federated is an open-source federated learning framework that supports the commercial deployment of tens of millions of stateless devices. It enables all-scenario intelligent applications when user data is stored locally. - -The federated learning is an encrypted distributed machine learning technology that allows users participating in federated learning to build AI models without sharing local data. MindSpore Federated currently focuses on the large-scale participants in the horizontal federated learning scenarios. - -.. raw:: html - - - -Advantages of the MindSpore Federated ---------------------------------------- - -1. Privacy Protection - - The MindSpore Federated framework data is stored locally for training. The data itself is not exchanged. Instead, the updated model parameters are exchanged in encryption mode. - - It supports accuracy-lossless security aggregation solution based on secure multi-party computation (MPC) to prevent model theft. - - It supports performance-lossless encryption based on local differential privacy to prevent private data leakage from models. - -2. Distributed Federated Aggregation - - The loosely coupled cluster processing mode on the cloud supports the deployment of tens of millions of heterogeneous devices, implements high-performance and high-availability distributed federated aggregation computing, and can cope with network instability and sudden load changes. - -3. Federated Learning Efficiency Improvement - - The synchronous and asynchronous federation modes and multiple model compression algorithms are supported to improve the federated learning efficiency and saving bandwidth resources. - - Multiple federated aggregation policies are supported to improve the smoothness of federated learning convergence and optimize both global and local accuracies. - -4. Easy to Use - - Only one line of code is required to switch between the standalone training and federated learning modes. - - The network models, aggregation algorithms, and security algorithms are programmable, and the security level can be customized. - -MindSpore Federated Working Process ------------------------------------- - -1. `Scenario Identification and Data Accumulation `_ - - Identify scenarios where federated learning is used and accumulate local data for federated tasks on the client. - -2. `Model Selection and Client Deployment `_ - - Select or develop a model prototype and use a tool to generate a device model that is easy to deploy. - -3. `Application Deployment `_ - - Deploy the Federated-Client to the device application, and set the federated configuration task and deployment script on the cloud. - -Common Application Scenarios ----------------------------- - -1. `Image Classification `_ - - Use the federated learning to implement image classification applications. - -2. `Text Classification `_ - - Use the federated learning to implement text classification applications. - -.. toctree:: - :maxdepth: 1 - :caption: Deployment - - federated_install - deploy_federated_server - deploy_federated_client - -.. toctree:: - :maxdepth: 1 - :caption: Application - - image_classification_application - sentiment_classification_application - -.. toctree:: - :maxdepth: 1 - :caption: Security and Privacy - - local_differential_privacy_training_noise - pairwise_encryption_training - -.. toctree:: - :maxdepth: 1 - :caption: API References - - federated_server - federated_client - -.. toctree:: - :maxdepth: 1 - :caption: References - - faq \ No newline at end of file diff --git a/docs/federated/docs/source_en/interface_description_federated_client.md b/docs/federated/docs/source_en/interface_description_federated_client.md deleted file mode 100644 index 5d5e733a0feba84dd8c6b7f9a64592c32437128d..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/interface_description_federated_client.md +++ /dev/null @@ -1,350 +0,0 @@ -# Examples - - - -Note that before using the following interfaces, you can first refer to the document [on-device deployment](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_client.html) to deploy related environments. - -## flJobRun() for Starting Federated Learning - -Before calling the flJobRun() API, instantiate the parameter class FLParameter and set related parameters as follows: - -| Parameter | Type | Mandatory | Description | Remarks | -| -------------------- | ---------------------------- | --------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| dataMap | Map/> | Y | The path of Federated learning dataset. | The dataset of Map/> type, the key in the map is the RunType enumeration type, the value is the corresponding dataset list, when the key is RunType.TRAINMODE, the corresponding value is the training-related dataset list, when the key is RunType.EVALMODE, it means that the corresponding value is a list of verification-related datasets, and when the key is RunType.INFERMODE, it means that the corresponding value is a list of inference-related datasets. | -| flName | String | Y | The package path of model script used by federated learning. | We provide two types of model scripts for your reference ([Supervised sentiment classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert), [LeNet image classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)). For supervised sentiment classification tasks, this parameter can be set to the package path of the provided script file [AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java), like as `com.mindspore.flclient.demo.albert.AlbertClient`; for LeNet image classification tasks, this parameter can be set to the package path of the provided script file [LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java), like as `com.mindspore.flclient.demo.lenet.LenetClient`. At the same time, users can refer to these two types of model scripts, define the model script by themselves, and then set the parameter to the package path of the customized model file ModelClient.java (which needs to inherit from the class [Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java)). | -| trainModelPath | String | Y | Path of a training model used for federated learning, which is an absolute path of the .ms file. | It is recommended to set the path to the training App's own directory to protect the data access security of the model itself. | -| inferModelPath | String | Y | Path of an inference model used for federated learning, which is an absolute path of the .ms file. | For the normal federated learning mode (training and inference use the same model), the value of this parameter needs to be the same as that of `trainModelPath`; for the hybrid learning mode (training and inference use different models, and the server side also includes training process), this parameter is set to the path of actual inference model. It is recommended to set the path to the training App's own directory to protect the data access security of the model itself. | -| sslProtocol | String | N | The TLS protocol version used by the device-cloud HTTPS communication. | A whitelist is set, and currently only "TLSv1.3" or "TLSv1.2" is supported. Only need to set it up in the HTTPS communication scenario. | -| deployEnv | String | Y | The deployment environment for federated learning. | A whitelist is set, currently only "x86", "android" are supported. | -| certPath | String | N | The self-signed root certificate path used for device-cloud HTTPS communication. | When the deployment environment is "x86" and the device-cloud uses a self-signed certificate for HTTPS communication authentication, this parameter needs to be set. The certificate must be consistent with the CA root certificate used to generate the cloud-side self-signed certificate to pass the verification. This parameter is used for non-Android scenarios. | -| domainName | String | Y | The url for device-cloud communication. | Currently, https and http communication are supported, the corresponding formats are like: https://......, http://......, and when `useElb` is set to true, the format must be: https://127.0.0.0 : 6666 or http://127.0.0.0 : 6666 , where `127.0.0.0` corresponds to the ip of the machine providing cloud-side services (corresponding to the cloud-side parameter `--scheduler_ip`), and `6666` corresponds to the cloud-side parameter `--fl_server_port`. | -| ifUseElb | boolean | N | Used for multi-server scenarios to set whether to randomly send client requests to different servers within a certain range. | Setting to true means that the client will randomly send requests to a certain range of server addresses, and false means that the client's requests will be sent to a fixed server address. This parameter is used in non-Android scenarios, and the default value is false. | -| serverNum | int | N | The number of servers that the client can choose to connect to. | When `ifUseElb` is set to true, it can be set to be consistent with the `server_num` parameter when the server is started on the cloud side. It is used to randomly select different servers to send information. This parameter is used in non-Android scenarios. The default value is 1. | -| ifPkiVerify | boolean | N | The switch of device-cloud identity authentication. | Set to true to enable device-cloud security authentication, set to false to disable, and the default value is false. Identity authentication requires HUKS to provide a certificate. This parameter is only used in the Android environment (currently only supports HUAWEI phones). | -| threadNum | int | N | The number of threads used in federated learning training and inference. | The default value is 1. | -| cpuBindMode | BindMode | N | The cpu core that threads need to bind during federated learning training and inference. | It is the enumeration type `BindMode`, where BindMode.NOT_BINDING_CORE represents the unbound core, which is automatically assigned by the system, BindMode.BIND_LARGE_CORE represents the bound large core, and BindMode.BIND_MIDDLE_CORE represents the bound middle core. The default value is BindMode.NOT_BINDING_CORE. | -| batchSize | int | Y | The number of single-step training samples used in federated learning training and inference, that is, batch size. | It needs to be consistent with the batch size of the input data of the model. | -| iflJobResultCallback | IFLJobResultCallback | N | The federated learning callback function object `iflJobResultCallback`. | The user can implement the specific method of the interface class [IFLJobResultCallback.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/IFLJobResultCallback.java) in the project according to the needs of the actual scene, and set it as a callback function object in the federated learning task. We provide a simple implementation use case [FLJobResultCallback.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/FLJobResultCallback.java) as the default value of this parameter. | - -Note 1: When using HTTP communication, there may exist communication security risks, please be aware. - -Note 2: In the Android environment, the following parameters need to be set when using HTTPS communication. The setting examples are as follows: - -```java -FLParameter flParameter = FLParameter.getInstance(); -SecureSSLSocketFactory sslSocketFactory = SecureSSLSocketFactory.getInstance(applicationContext) -SecureX509TrustManager x509TrustManager = new SecureX509TrustManager(applicationContext); -flParameter.setSslSocketFactory(sslSocketFactory); -flParameter.setX509TrustManager(x509TrustManager); -``` - -Among them, the two objects `SecureSSLSocketFactory` and `SecureX509TrustManager` need to be implemented in the Android project, and users need to design by themselves according to the type of certificate in the mobile phone. - -Note 3: In the x86 environment, currently only self-signed certificate authentication is supported when using HTTPS communication, and the following parameters need to be set. The setting examples are as follows: - -```java -FLParameter flParameter = FLParameter.getInstance(); -String certPath = "CARoot.pem"; // the self-signed root certificate path used for device-cloud HTTPS communication. -flParameter.setCertPath(certPath); -``` - -Note 4: In the Android environment, when `pkiVerify` is set to true and encrypt_type is set to PW_ENCRYPT on the cloud side, the following parameters need to be set. The setting examples are as follows: - -```java -FLParameter flParameter = FLParameter.getInstance(); -String equipCrlPath = certPath; -long validIterInterval = 3600000; -flParameter.setEquipCrlPath(equipCrlPath); -flParameter.setValidInterval(validIterInterval); -``` - -Among them, `equipCrlPath` is the CRL certificate required for certificate verification among devices, that is, the certificate revocation list. Generally, the device certificate CRL in "Huawei CBG Certificate Revocation Lists" can be preset; `validIterInterval` which is used to help prevent replay attacks in PW_ENCRYPT mode can generally be set to the time required for each round of device-cloud aggregation (unit: milliseconds, the default value is 3600000). - -Note 5: Before each federated learning task is started, the FLParameter class will be instantiated for related parameter settings. When FLParameter is instantiated, a clientID is automatically generated randomly, which is used to uniquely identify the client during the interaction with the cloud side. If the user needs to set the clientID by himself, after instantiating the FLParameter class, call its setClientID method to set it, and then after starting the federated learning task, the clientID set by the user will be used. - -Create a SyncFLJob object and use the flJobRun() method of the SyncFLJob class to start a federated learning task. - -The sample code (basic http communication) is as follows: - -1. Sample code of a supervised sentiment classification task - - ```java - // create dataMap - String trainTxtPath = "data/albert/supervise/client/1.txt"; - String evalTxtPath = "data/albert/supervise/eval/eval.txt"; // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - String vocabFile = "data/albert/supervise/vocab.txt"; // Path of the dictionary file for data preprocessing. - String idsFile = "data/albert/supervise/vocab_map_ids.txt" // Path of the mapping ID file of a dictionary. - Map> dataMap = new HashMap<>(); - List trainPath = new ArrayList<>(); - trainPath.add(trainTxtPath); - trainPath.add(vocabFile); - trainPath.add(idsFile); - List evalPath = new ArrayList<>(); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(evalTxtPath); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(vocabFile); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(idsFile); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - dataMap.put(RunType.TRAINMODE, trainPath); - dataMap.put(RunType.EVALMODE, evalPath); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // The package path of AlBertClient.java - String trainModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - - // start FLJob - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.flJobRun(); - ``` - -2. Sample code of a LeNet image classification task - - ```java - // create dataMap - String trainImagePath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_9_train_data.bin"; - String trainLabelPath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_9_train_label.bin"; - String evalImagePath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_data.bin"; // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - String evalLabelPath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_label.bin"; // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - Map> dataMap = new HashMap<>(); - List trainPath = new ArrayList<>(); - trainPath.add(trainImagePath); - trainPath.add(trainLabelPath); - List evalPath = new ArrayList<>(); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(evalImagePath); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(evalLabelPath); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - dataMap.put(RunType.TRAINMODE, trainPath); - dataMap.put(RunType.EVALMODE, evalPath); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - - String flName = "com.mindspore.flclient.demo.lenet.LenetClient"; // The package path of LenetClient.java - String trainModelPath = "SyncFLClient/lenet_train.mindir0.ms"; // Absolute path - String inferModelPath = "SyncFLClient/lenet_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - flParameter.setBatchSize(batchSize); - - // start FLJob - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.flJobRun(); - ``` - -## modelInference() for Inferring Multiple Input Data Records - -Before calling the modelInference() API, instantiate the parameter class FLParameter and set related parameters as follows: - -| Parameter | Type | Mandatory | Description | Remarks | -| -------------- | ---------------------------- | --------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| flName | String | Y | The package path of model script used by federated learning. | We provide two types of model scripts for your reference ([Supervised sentiment classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert), [LeNet image classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)). For supervised sentiment classification tasks, this parameter can be set to the package path of the provided script file [AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java), like as `com.mindspore.flclient.demo.albert.AlbertClient`; for LeNet image classification tasks, this parameter can be set to the package path of the provided script file [LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java), like as `com.mindspore.flclient.demo.lenet.LenetClient`. At the same time, users can refer to these two types of model scripts, define the model script by themselves, and then set the parameter to the package path of the customized model file ModelClient.java (which needs to inherit from the class [Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java)). | -| dataMap | Map/> | Y | The path of Federated learning dataset. | The dataset of Map/> type, the key in the map is the RunType enumeration type, the value is the corresponding dataset list, when the key is RunType.TRAINMODE, the corresponding value is the training-related dataset list, when the key is RunType.EVALMODE, it means that the corresponding value is a list of verification-related datasets, and when the key is RunType.INFERMODE, it means that the corresponding value is a list of inference-related datasets. | -| inferModelPath | String | Y | Path of an inference model used for federated learning, which is an absolute path of the .ms file. | For the normal federated learning mode (training and inference use the same model), the value of this parameter needs to be the same as that of `trainModelPath`; for the hybrid learning mode (training and inference use different models, and the server side also includes training process), this parameter is set to the path of actual inference model. It is recommended to set the path to the training App's own directory to protect the data access security of the model itself. | -| threadNum | int | N | The number of threads used in federated learning training and inference. | The default value is 1. | -| cpuBindMode | BindMode | N | The cpu core that threads need to bind during federated learning training and inference. | It is the enumeration type `BindMode`, where BindMode.NOT_BINDING_CORE represents the unbound core, which is automatically assigned by the system, BindMode.BIND_LARGE_CORE represents the bound large core, and BindMode.BIND_MIDDLE_CORE represents the bound middle core. The default value is BindMode.NOT_BINDING_CORE. | -| batchSize | int | Y | The number of single-step training samples used in federated learning training and inference, that is, batch size. | It needs to be consistent with the batch size of the input data of the model. | - -Create a SyncFLJob object and use the modelInference() method of the SyncFLJob class to start an inference task on the device. The inferred label array is returned. - -The sample code is as follows: - -1. Sample code of a supervised sentiment classification task - - ```java - // create dataMap - String inferTxtPath = "data/albert/supervise/eval/eval.txt"; - String vocabFile = "data/albert/supervise/vocab.txt"; - String idsFile = "data/albert/supervise/vocab_map_ids.txt" - Map> dataMap = new HashMap<>(); - List inferPath = new ArrayList<>(); - inferPath.add(inferTxtPath); - inferPath.add(vocabFile); - inferPath.add(idsFile); - dataMap.put(RunType.INFERMODE, inferPath); - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // The package path of AlBertClient.java - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setInferModelPath(inferModelPath); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - flParameter.setBatchSize(batchSize); - - // inference - SyncFLJob syncFLJob = new SyncFLJob(); - int[] labels = syncFLJob.modelInference(); - ``` - -2. Sample code of a LeNet image classification - - ```java - // create dataMap - String inferImagePath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_data.bin"; - String inferLabelPath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_label.bin"; - Map> dataMap = new HashMap<>(); - List inferPath = new ArrayList<>(); - inferPath.add(inferImagePath); - inferPath.add(inferLabelPath); - dataMap.put(RunType.INFERMODE, inferPath); - - String flName = "com.mindspore.flclient.demo.lenet.LenetClient"; // The package path of LenetClient.java package - String inferModelPath = "SyncFLClient/lenet_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setInferModelPath(inferModelPath); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - flParameter.setBatchSize(batchSize); - - // inference - SyncFLJob syncFLJob = new SyncFLJob(); - int[] labels = syncFLJob.modelInference(); - ``` - -## getModel() for Obtaining the Latest Model on the Cloud - -Before calling the getModel() API, instantiate the parameter class FLParameter and set related parameters as follows: - -| Parameter | Type | Mandatory | Description | Remarks | -| -------------- | --------- | --------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| flName | String | Y | The package path of model script used by federated learning. | We provide two types of model scripts for your reference ([Supervised sentiment classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert), [LeNet image classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)). For supervised sentiment classification tasks, this parameter can be set to the package path of the provided script file [AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java), like as `com.mindspore.flclient.demo.albert.AlbertClient`; for LeNet image classification tasks, this parameter can be set to the package path of the provided script file [LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java), like as `com.mindspore.flclient.demo.lenet.LenetClient`. At the same time, users can refer to these two types of model scripts, define the model script by themselves, and then set the parameter to the package path of the customized model file ModelClient.java (which needs to inherit from the class [Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java)). | -| trainModelPath | String | Y | Path of a training model used for federated learning, which is an absolute path of the .ms file. | It is recommended to set the path to the training App's own directory to protect the data access security of the model itself. | -| inferModelPath | String | Y | Path of an inference model used for federated learning, which is an absolute path of the .ms file. | For the normal federated learning mode (training and inference use the same model), the value of this parameter needs to be the same as that of `trainModelPath`; for the hybrid learning mode (training and inference use different models, and the server side also includes training process), this parameter is set to the path of actual inference model. It is recommended to set the path to the training App's own directory to protect the data access security of the model itself. | -| sslProtocol | String | N | The TLS protocol version used by the device-cloud HTTPS communication. | A whitelist is set, and currently only "TLSv1.3" or "TLSv1.2" is supported. Only need to set it up in the HTTPS communication scenario. | -| deployEnv | String | Y | The deployment environment for federated learning. | A whitelist is set, currently only "x86", "android" are supported. | -| certPath | String | N | The self-signed root certificate path used for device-cloud HTTPS communication. | When the deployment environment is "x86" and the device-cloud uses a self-signed certificate for HTTPS communication authentication, this parameter needs to be set. The certificate must be consistent with the CA root certificate used to generate the cloud-side self-signed certificate to pass the verification. This parameter is used for non-Android scenarios. | -| domainName | String | Y | The url for device-cloud communication. | Currently, https and http communication are supported, the corresponding formats are like: https://......, http://......, and when `useElb` is set to true, the format must be: https://127.0.0.0 : 6666 or http://127.0.0.0 : 6666 , where `127.0.0.0` corresponds to the ip of the machine providing cloud-side services (corresponding to the cloud-side parameter `--scheduler_ip`), and `6666` corresponds to the cloud-side parameter `--fl_server_port`. | -| ifUseElb | boolean | N | Used for multi-server scenarios to set whether to randomly send client requests to different servers within a certain range. | Setting to true means that the client will randomly send requests to a certain range of server addresses, and false means that the client's requests will be sent to a fixed server address. This parameter is used in non-Android scenarios, and the default value is false. | -| serverNum | int | N | The number of servers that the client can choose to connect to. | When `ifUseElb` is set to true, it can be set to be consistent with the `server_num` parameter when the server is started on the cloud side. It is used to randomly select different servers to send information. This parameter is used in non-Android scenarios. The default value is 1. | -| serverMod | ServerMod | Y | The federated learning training mode. | The federated learning training mode of ServerMod enumeration type, where ServerMod.FEDERATED_LEARNING represents the normal federated learning mode (training and inference use the same model) ServerMod.HYBRID_TRAINING represents the hybrid learning mode (training and inference use different models, and the server side also includes training process). | - -Note 1: When using HTTP communication, there may exist communication security risks, please be aware. - -Note 2: In the Android environment, the following parameters need to be set when using HTTPS communication. The setting examples are as follows: - -```java -FLParameter flParameter = FLParameter.getInstance(); -SecureSSLSocketFactory sslSocketFactory = SecureSSLSocketFactory.getInstance(applicationContext) -SecureX509TrustManager x509TrustManager = new SecureX509TrustManager(applicationContext); -flParameter.setSslSocketFactory(sslSocketFactory); -flParameter.setX509TrustManager(x509TrustManager); -``` - -Among them, the two objects `SecureSSLSocketFactory` and `SecureX509TrustManager` need to be implemented in the Android project, and users need to design themselves according to the type of certificate in the mobile phone. - -Note 3: In the x86 environment, currently only self-signed certificate authentication is supported when using HTTPS communication, and the following parameters need to be set. The setting examples are as follows: - -```java -FLParameter flParameter = FLParameter.getInstance(); -String certPath = "CARoot.pem"; // the self-signed root certificate path used for device-cloud HTTPS communication. -flParameter.setCertPath(certPath); -``` - -Note 4: Before calling the getModel method, the FLParameter class will be instantiated for related parameter settings. When FLParameter is instantiated, a clientID is automatically generated randomly, which is used to uniquely identify the client during the interaction with the cloud side. If the user needs to set the clientID by himself, after instantiating the FLParameter class, call its setCertPath method to set it, and then after starting the getModel task, the clientID set by the user will be used. - -Create a SyncFLJob object and use the getModel() method of the SyncFLJob class to start an asynchronous inference task. The status code of the getModel request is returned. - -The sample code is as follows: - -1. Supervised sentiment classification task - - ```java - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // The package path of AlBertClient.java package - String trainModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - ServerMod serverMod = ServerMod.FEDERATED_LEARNING; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setServerMod(ServerMod.valueOf(serverMod)); - - // getModel - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.getModel(); - ``` - -2. LeNet image classification task - - ```java - String flName = "com.mindspore.flclient.demo.lenet.LenetClient"; // The package path of LenetClient.java package - String trainModelPath = "SyncFLClient/lenet_train.mindir0.ms"; // Absolute path - String inferModelPath = "SyncFLClient/lenet_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4 - ServerMod serverMod = ServerMod.FEDERATED_LEARNING; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setServerMod(ServerMod.valueOf(serverMod)); - - // getModel - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.getModel(); - ``` diff --git a/docs/federated/docs/source_en/java_api_callback.md b/docs/federated/docs/source_en/java_api_callback.md deleted file mode 100644 index 20e4403d6927dd09c423427f076e3f6549147055..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/java_api_callback.md +++ /dev/null @@ -1,66 +0,0 @@ -# Callback - - - -```java -import com.mindspore.flclient.model.Callback -``` - -Callback defines the hook function used to record training, evaluate and predict the results of different stages in end-to-side federated learning. - -## Public Member Functions - -| function | -| -------------------------------- | -| [abstract Status stepBegin()](#stepbegin) | -| [abstract Status stepEnd()](#stepend) | -| [abstract Status epochBegin()](#epochbegin) | -| [abstract Status epochEnd()](#epochend) | - -## stepBegin - -```java - public abstract Status stepBegin() -``` - -Execute step begin function. - -- Returns - - Whether the execution is successful. - -## stepEnd - -```java -public abstract Status stepEnd() -``` - -Execute step end function. - -- Returns - - Whether the execution is successful. - -## epochBegin - -```java -public abstract Status epochBegin() -``` - -Execute epoch begin function. - -- Returns - - Whether the execution is successful. - -## epochEnd - -```java -public abstract Status epochEnd() -``` - -Execute epoch end function. - -- Returns - - Whether the execution is successful. diff --git a/docs/federated/docs/source_en/java_api_client.md b/docs/federated/docs/source_en/java_api_client.md deleted file mode 100644 index 41192a42b0f64135a594b48340190a2a3b9bdecc..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/java_api_client.md +++ /dev/null @@ -1,227 +0,0 @@ -# Client - - - -```java -import com.mindspore.flclient.model.Client -``` - -Client defines the execution process object of the end-side federated learning algorithm. - -## Public Member Functions - -| function | -| -------------------------------- | -| [abstract List initCallbacks(RunType runType, DataSet dataSet)](#initcallbacks) | -| [abstract Map initDataSets(Map\> files)](#initdatasets) | -| [abstract float getEvalAccuracy(List evalCallbacks)](#getevalaccuracy) | -| [abstract List getInferResult(List inferCallbacks)](#getinferresult) | -| [Status initSessionAndInputs(String modelPath, MSConfig config)](#initsessionandinputs) | -| [Status trainModel(int epochs)](#trainmodel) | -| [evalModel()](#evalmodel) | -| [List inferModel()](#infermodel) | -| [Status saveModel(String modelPath)](#savemodel) | -| [List getFeatures()](#getfeatures) | -| [Status updateFeatures(String modelName, List featureMaps)](#updatefeatures) | -| [void free()](#free) | -| [Status setLearningRate(float lr)](#setlearningrate) | -| [void setBatchSize(int batchSize)](#setbatchsize) | - -## initCallbacks - -```java -public abstract List initCallbacks(RunType runType, DataSet dataSet) -``` - -Initialize the callback list. - -- Parameters - - - `runType`: Define run phase. - - `dataSet`: DataSet. - -- Returns - - The initialized callback list. - -## initDataSets - -```java -public abstract Map initDataSets(Map> files) -``` - -Initialize dataset list. - -- Parameters - - - `files`: Data files. - -- Returns - - Data counts in different run type. - -## getEvalAccuracy - -```java -public abstract float getEvalAccuracy(List evalCallbacks) -``` - -Get eval model accuracy. - -- Parameters - - - `evalCallbacks`: Callback used in eval phase. - -- Returns - - The accuracy in eval phase. - -## getInferResult - -```java -public abstract List getInferResult(List inferCallbacks) -``` - -Get infer phase result. - -- Parameters - - - `inferCallbacks`: Callback used in infer phase. - -- Returns - - predict results. - -## initSessionAndInputs - -```java -public Status initSessionAndInputs(String modelPath, MSConfig config) -``` - -Initialize client runtime session and input buffer. - -- Parameters - - - `modelPath`: Model file path. - - `config`: session config. - -- Returns - - Whether the Initialization is successful. - -## trainModel - -```java -public Status trainModel(int epochs) -``` - -Execute train model process. - -- Parameters - - - `epochs`: Epoch num used in train process. - -- Returns - - Whether the train model is successful. - -## evalModel - -```java -public float evalModel() -``` - -Execute eval model process. - -- Returns - - The accuracy in eval process. - -## inferModel - -```java -public List inferModel() -``` - -Execute infer model process. - -- Returns - - The infer result in infer process. - -## saveModel - -```java -public Status saveModel(String modelPath) -``` - -Save model. - -- Returns - - Whether the inference is successful. - -## getFeatures - -```java -public List getFeatures() -``` - -Get feature weights. - -- Returns - - The feature weights of model. - -## updateFeatures - -```java -public Status updateFeatures(String modelName, List featureMaps) -``` - -Update model feature weights. - -- Parameters - - - `modelName`: Model file name. - - `featureMaps`: New model weights. - -- Returns - - Whether the update is successful. - -## free - -```java -public void free() -``` - -free model. - -## setLearningRate - -```java -public Status setLearningRate(float lr) -``` - -Set learning rate. - -- Parameters - - - `lr`: Learning rate. - -- Returns - - Whether the set is successful. - -## setBatchSize - -```java -public void setBatchSize(int batchSize) -``` - -Set batch size. - -- Parameters - - - `batchSize`: batch size. diff --git a/docs/federated/docs/source_en/java_api_clientmanager.md b/docs/federated/docs/source_en/java_api_clientmanager.md deleted file mode 100644 index 219a4b5ba49dddbdd2ba4c80ec1eeed93ae6556a..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/java_api_clientmanager.md +++ /dev/null @@ -1,43 +0,0 @@ -# ClientManager - - - -```java -import com.mindspore.flclient.model.ClientManager -``` - -ClientManager defines end-side federated learning custom algorithm model management objects. - -## Public Member Functions - -| function | -| -------------------------------- | -| [static void registerClient(Client client)](#registerclient) | -| [static Client getClient(String name)](#getclient) | - -## registerClient - -```java -public static void registerClient(Client client) -``` - -Register client object. - -- Parameters - - - `client`: Need register client object. - -## getClient - -```java -public static Client getClient(String name) -``` - -Get client object. - -- Parameters - - - `name`: Client object name. -- Returns - - Client object. diff --git a/docs/federated/docs/source_en/java_api_dataset.md b/docs/federated/docs/source_en/java_api_dataset.md deleted file mode 100644 index 34744c396edad37059a870d922c0c36e4ad4f5e0..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/java_api_dataset.md +++ /dev/null @@ -1,63 +0,0 @@ -# DataSet - - - -```java -import com.mindspore.flclient.model.DataSet -``` - -DataSet defines end-side federated learning dataset object. - -## Public Member Functions - -| function | -| -------------------------------- | -| [abstract void fillInputBuffer(List var1, int var2)](#fillinputbuffer) | -| [abstract void shuffle()](#shuffle) | -| [abstract void padding()](#padding) | -| [abstract Status dataPreprocess(List var1)](#datapreprocess) | - -## fillInputBuffer - -```java -public abstract void fillInputBuffer(List var1, int var2) -``` - -Fill input buffer data. - -- Parameters - - - `var1`: Need fill buffer. - - `var2`: Need fill batch index. - -## shuffle - -```java - public abstract void shuffle() -``` - -Shuffle data. - -## padding - -```java - public abstract void padding() -``` - -Pad data. - -## dataPreprocess - -```java -public abstract Status dataPreprocess(List var1) -``` - -Data preprocess. - -- Parameters - - - `var1`: Data files. - -- Returns - - Whether the execution is successful. diff --git a/docs/federated/docs/source_en/java_api_flparameter.md b/docs/federated/docs/source_en/java_api_flparameter.md deleted file mode 100644 index 459342b3e52d70dc523914ca61d28b3bc0bf72f6..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/java_api_flparameter.md +++ /dev/null @@ -1,636 +0,0 @@ -# FLParameter - - - -```java -import com.mindspore.flclient.FLParameter -``` - -FLParameter is used to define parameters related to federated learning. - -## Public Member Functions - -| **function** | -| ------------------------------------------------------------ | -| public static synchronized FLParameter getInstance() | -| public String getDeployEnv() | -| public void setDeployEnv(String env) | -| public String getDomainName() | -| public void setDomainName(String domainName) | -| public String getClientID() | -| public void setClientID(String clientID) | -| public String getCertPath() | -| public void setCertPath(String certPath) | -| public SSLSocketFactory getSslSocketFactory() | -| public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) | -| public X509TrustManager getX509TrustManager( | -| public void setX509TrustManager(X509TrustManager x509TrustManager) | -| public IFLJobResultCallback getIflJobResultCallback() | -| public void setIflJobResultCallback(IFLJobResultCallback iflJobResultCallback) | -| public String getFlName() | -| public void setFlName(String flName) | -| public String getTrainModelPath() | -| public void setTrainModelPath(String trainModelPath) | -| public String getInferModelPath() | -| public void setInferModelPath(String inferModelPath) | -| public String getSslProtocol() | -| public void setSslProtocol(String sslProtocol) | -| public int getTimeOut() | -| public void setTimeOut(int timeOut) | -| public int getSleepTime() | -| public void setSleepTime(int sleepTime) | -| public boolean isUseElb() | -| public void setUseElb(boolean useElb) | -| public int getServerNum() | -| public void setServerNum(int serverNum) | -| public boolean isPkiVerify() | -| public void setPkiVerify(boolean ifPkiVerify) | -| public String getEquipCrlPath() | -| public void setEquipCrlPath(String certPath) | -| public long getValidInterval() | -| public void setValidInterval(long validInterval) | -| public int getThreadNum() | -| public void setThreadNum(int threadNum) | -| public int getCpuBindMode( | -| public void setCpuBindMode(BindMode cpuBindMode) | -| public List getHybridWeightName(RunType runType) | -| public void setHybridWeightName(List hybridWeightName, RunType runType) | -| public Map> getDataMap() | -| public void setDataMap(Map/> dataMap) | -| public ServerMod getServerMod() | -| public void setServerMod(ServerMod serverMod) | -| public int getBatchSize() | -| public void setBatchSize(int batchSize) | - -## getInstance - -```java -public static synchronized FLParameter getInstance() -``` - -Obtains a single FLParameter instance. - -- Return value - - Single object of the FLParameter type. - -## getDeployEnv - -```java -public String getDeployEnv() -``` - -Obtains the deployment environment for federated learning set by users. - -- Return value - - The deployment environment for federated learning of the string type. - -## setDeployEnv - -```java -public void setDeployEnv(String env) -``` - -Used to set the deployment environment for federated learning, a whitelist is set, currently only "x86", "android" are supported. - -- Parameter - - - `env`: the deployment environment for federated learning. - -## getDomainName - -```java -public String getDomainName() -``` - -Obtains the domain name set by a user. - -- Return value - - Domain name of the string type. - -## setDomainName - -```java -public void setDomainName(String domainName) -``` - -Used to set the url for device-cloud communication. Currently, https and http communication are supported, the corresponding formats are like: https://......, http://......, and when `useElb` is set to true, the format must be: https://127.0.0.0 : 6666 or http://127.0.0.0 : 6666 , where `127.0.0.0` corresponds to the ip of the machine providing cloud-side services (corresponding to the cloud-side parameter `--scheduler_ip`), and `6666` corresponds to the cloud-side parameter `--fl_server_port`. - -- Parameter - - - `domainName`: domain name. - -## getClientID - -```java -public String getClientID() -``` - -The method `getClientID` is used to obtain the unique ID of the client, the ID also can be used to generate related certificates in the device-cloud security authentication scenario. - -- Return value - - Unique ID of the client, which is of the string type. - -## setClientID - -```java -public void setClientID(String clientID) -``` - -Each time the federated learning task is started, a unique client ID will be automatically generated in the program, if the user needs to set the clientID by himself, he can set the ID by calling the method `setClientID` before starting the federated learning training task. - -- Parameter - - - `clientID`: unique ID of the client. - -## getCertPath - -```java -public String getCertPath() -``` - -Obtains the self-signed root certificate path used for device-cloud HTTPS communication. - -- Return value - - The self-signed root certificate pat of the string type. - -## setCertPath - -```java -public void setCertPath(String certPath) -``` - -Sets the self-signed root certificate path used for device-cloud HTTPS communication. When the deployment environment is "x86" and the device-cloud uses a self-signed certificate for HTTPS communication authentication, this parameter needs to be set. The certificate must be consistent with the CA root certificate used to generate the cloud-side self-signed certificate to pass the verification. This parameter is used for non-Android scenarios. - -- Parameter - - `certPath`: the self-signed root certificate path used for device-cloud HTTPS communication. - -## getSslSocketFactory - -```java -public SSLSocketFactory getSslSocketFactory() -``` - -Obtains the ssl certificate authentication library `sslSocketFactory` set by the user. - -- Return value - - The ssl certificate authentication library `sslSocketFactory` , which is of the SSLSocketFactory type. - -## setSslSocketFactory - -```java -public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) -``` - -Used to set the ssl certificate authentication library `sslSocketFactory`. - -- Parameter - - `sslSocketFactory`: the ssl certificate authentication library. - -## getX509TrustManager - -```java -public X509TrustManager getX509TrustManager() -``` - -Obtains the ssl certificate authentication manager `x509TrustManager` set by the user. - -- Return value - - the ssl certificate authentication manager `x509TrustManager`, which is of the X509TrustManager type. - -## setX509TrustManager - -```java -public void setX509TrustManager(X509TrustManager x509TrustManager) -``` - -Used to set the ssl certificate authentication manager `x509TrustManager`. - -- Parameter - - `x509TrustManager`: the ssl certificate authentication manager. - -## getIflJobResultCallback - -```java -public IFLJobResultCallback getIflJobResultCallback() -``` - -Obtains the federated learning callback function object `iflJobResultCallback` set by the user. - -- Return value - - The federated learning callback function object `iflJobResultCallback`, which is of the IFLJobResultCallback type. - -## setIflJobResultCallback - -```java -public void setIflJobResultCallback(IFLJobResultCallback iflJobResultCallback) -``` - -Used to set the federated learning callback function object `iflJobResultCallback`, the user can implement the specific method of the interface class [IFLJobResultCallback.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/IFLJobResultCallback.java) in the project according to the needs of the actual scene, and set it as a callback function object in the federated learning task. - -- Parameter - - `iflJobResultCallback`: the federated learning callback function object. - -## getFlName - -```java -public String getFlName() -``` - -Obtains the package path of model script set by a user. - -- Return value - - Name of the package path of model script of the string type. - -## setFlName - -```java -public void setFlName(String flName) -``` - -Sets the package path of model script . We provide two types of model scripts for your reference ([Supervised sentiment classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert), [Lenet image classification task](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)). For supervised sentiment classification tasks, this parameter can be set to the package path of the provided script file [AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java), like as `com.mindspore.flclient.demo.albert.AlbertClient`; for Lenet image classification tasks, this parameter can be set to the package path of the provided script file [LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java), like as `com.mindspore.flclient.demo.lenet.LenetClient`. At the same time, users can refer to these two types of model scripts, define the model script by themselves, and then set the parameter to the package path of the customized model file ModelClient.java (which needs to inherit from the class [Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java)). - -- Parameter - - `flName`: package path of model script. - -## getTrainModelPath - -```java -public String getTrainModelPath() -``` - -Obtains the path of the training model set by a user. - -- Return value - - Path of the training model of the string type. - -## setTrainModelPath - -```java -public void setTrainModelPath(String trainModelPath) -``` - -Sets the path of the training model. - -- Parameter - - `trainModelPath`: training model path. - -## getInferModelPath - -```java -public String getInferModelPath() -``` - -Obtains the path of the inference model set by a user. - -- Return value - - Path of the inference model of the string type. - -## setInferModelPath - -```java -public void setInferModelPath(String inferModelPath) -``` - -Sets the path of the inference model. - -- Parameter - - `inferModelPath`: path of the inference model. - -## getSslProtocol - -```java -public String getSslProtocol() -``` - -Obtains the TLS protocol version used by the device-cloud HTTPS communication. - -- Return value - - The TLS protocol version used by the device-cloud HTTPS communication of the string type. - -## setSslProtocol - -```java -public void setSslProtocol(String sslProtocol) -``` - -Used to set the TLS protocol version used by the device-cloud HTTPS communication, a whitelist is set, and currently only "TLSv1.3" or "TLSv1.2" is supported. Only need to set it up in the HTTPS communication scenario. - -- Parameter - - `sslProtocol`: the TLS protocol version used by the device-cloud HTTPS communication. - -## getTimeOut - -```java -public int getTimeOut() -``` - -Obtains the timeout interval set by a user for device-side communication. - -- Return value - - Timeout interval for communication on the device, which is an integer. - -## setTimeOut - -```java -public void setTimeOut(int timeOut) -``` - -Sets the timeout interval for communication on the device. - -- Parameter - - `timeOut`: timeout interval for communication on the device. - -## getSleepTime - -```java -public int getSleepTime() -``` - -Obtains the waiting time of repeated requests set by a user. - -- Return value - - Waiting time of repeated requests, which is an integer. - -## setSleepTime - -```java -public void setSleepTime(int sleepTime) -``` - -Sets the waiting time of repeated requests. - -- Parameter - - `sleepTime`: waiting time for repeated requests. - -## isUseElb - -```java -public boolean isUseElb() -``` - -Determines whether the elastic load balancing is simulated, that is, whether a client randomly sends requests to a server address within a specified range. - -- Return value - - The value is of the Boolean type. The value true indicates that the client sends requests to a random server address within a specified range. The value false indicates that the client sends a request to a fixed server address. - -## setUseElb - -```java -public void setUseElb(boolean useElb) -``` - -Determines whether to simulate the elastic load balancing, that is, whether a client randomly sends a request to a server address within a specified range. - -- Parameter - - `useElb`: determines whether to simulate the elastic load balancing. The default value is false. - -## getServerNum - -```java -public int getServerNum() -``` - -Obtains the number of servers that can send requests when simulating the elastic load balancing. - -- Return value - - Number of servers that can send requests during elastic load balancing simulation, which is an integer. - -## setServerNum - -```java -public void setServerNum(int serverNum) -``` - -Sets the number of servers that can send requests during elastic load balancing simulation. - -- Parameter - - `serverNum`: number of servers that can send requests during elastic load balancing simulation. The default value is 1. - -## isPkiVerify - -```java -public boolean isPkiVerify() -``` - -Whether to perform device-cloud security authentication. - -- Return value - - The value is of the Boolean type. The value true indicates that device-cloud security authentication is performed, and the value false indicates that device-cloud security authentication is not performed. - -## setPkiVerify - -```java -public void setPkiVerify(boolean pkiVerify) -``` - -Determines whether to perform device-cloud security authentication. - -- Parameter - - - `pkiVerify`: whether to perform device-cloud security authentication. - -## getEquipCrlPath - -```java -public String getEquipCrlPath() -``` - -Obtains the CRL certification path `equipCrlPath` of the device certificate set by the user. This parameter is used in the Android environment. - -- Return value - - The certification path of the string type. - -## setEquipCrlPath - -```java -public void setEquipCrlPath(String certPath) -``` - -Used to set the CRL certification path of the device certificate. It is used to verify whether the digital certificate is revoked. This parameter is used in the Android environment. - -- Parameter - - `certPath`: the certification path. - -## getValidInterval - -```java -public long getValidInterval() -``` - -Obtains the valid iteration interval validIterInterval set by the user. This parameter is used in the Android environment. - -- Return value - - The valid iteration interval validIterInterval of the long type. - -## setValidInterval - -```java -public void setValidInterval(long validInterval) -``` - -Used to set the valid iteration interval validIterInterval. The recommended duration is the duration of one training epoch between the device-cloud(unit: milliseconds). It is used to prevent replay attacks. This parameter is used in the Android environment. - -- Parameter - - `validInterval`: the valid iteration interval validIterInterval. - -## getThreadNum - -```java -public int getThreadNum() -``` - -Obtains the number of threads used in federated learning training and inference. The default value is 1. - -- Return value - - The number of threads used in federated learning training and inference, which is of the int type. - -## setThreadNum - -```java -public void setThreadNum(int threadNum) -``` - -Used to set the number of threads used in federated learning training and inference. - -- Parameter - - `threadNum`: the number of threads used in federated learning training and inference. - -## getCpuBindMode - -```java -public int getCpuBindMode() -``` - -Obtains the cpu core that threads need to bind during federated learning training and inference. - -- Return value - - Convert the enumerated type of cpu core to int type and return. - -## setCpuBindMode - -```java -public void setCpuBindMode(BindMode cpuBindMode) -``` - -Used to set the cpu core that threads need to bind during federated learning training and inference. - -- Parameter - - `cpuBindMode`: it is the enumeration type `BindMode`, where BindMode.NOT_BINDING_CORE represents the unbound core, which is automatically assigned by the system, BindMode.BIND_LARGE_CORE represents the bound large core, and BindMode.BIND_MIDDLE_CORE represents the bound middle core. - -## getHybridWeightName - -```java -public List getHybridWeightName(RunType runType) -``` - -Used in hybrid training mode. Get the training weight name and inference weight name set by the user. - -- Parameter - -- `runType`: RunType enumeration type, only supports to be set to RunType.TRAINMODE (representing the training weight name) , RunType.INFERMODE (representing the inference weight name). - -- Return value - - A list of corresponding weight names according to the parameter runType, which is of the List type. - -## setHybridWeightName - -```java -public void setHybridWeightName(List hybridWeightName, RunType runType) -``` - -Due to the hybrid training mode, part of the weights delivered by the server is imported into the training model, and part is imported into the inference model, but the framework itself cannot judge it, so the user needs to set the relevant training weight name and inference weight name by himself. This method is provided for the user to set. - -- Parameter - - `hybridWeightName`: a list of weight names of the List type. - - `runType`: RunType enumeration type, only supports setting to RunType.TRAINMODE (representing setting training weight name), RunType.INFERMODE (representing setting reasoning weight name). - -## getDataMap - -```java -public Map> getDataMap() -``` - -Obtains the federated learning dataset set by the user. - -- Return value - - the federated learning dataset set of the Map> type. - -## setDataMap - -```java -public void setDataMap(Map> dataMap) -``` - -Used to set the federated learning dataset set by the user. - -- Parameter - - `dataMap`: the dataset of Map> type, the key in the map is the RunType enumeration type, the value is the corresponding dataset list, when the key is RunType.TRAINMODE, the corresponding value is the training-related dataset list, when the key is RunType.EVALMODE, it means that the corresponding value is a list of verification-related datasets, and when the key is RunType.INFERMODE, it means that the corresponding value is a list of inference-related datasets. - -## getServerMod - -```java -public ServerMod getServerMod() -``` - - Obtains the federated learning training mode. - -- Return value - - The federated learning training mode of ServerMod enumeration type. - -## setServerMod - -```java -public void setServerMod(ServerMod serverMod) -``` - -Used to set the federated learning training mode. - -- Parameter - - `serverMod`: the federated learning training mode of ServerMod enumeration type, where ServerMod.FEDERATED_LEARNING represents the normal federated learning mode (training and inference use the same model) ServerMod.HYBRID_TRAINING represents the hybrid learning mode (training and inference use different models, and the server side also includes training process). - -## getBatchSize - -```java -public int getBatchSize() -``` - -Obtains the number of single-step training samples used in federated learning training and inference, that is, batch size. - -- Return value - - BatchSize, the number of single-step training samples of int type. - -## setBatchSize - -```java -public void setBatchSize(int batchSize) -``` - -Used to set the number of single-step training samples used in federated learning training and inference, that is, batch size. It needs to be consistent with the batch size of the input data of the model. - -- Parameter - - `batchSize`: the number of single-step training samples of int type. \ No newline at end of file diff --git a/docs/federated/docs/source_en/java_api_syncfljob.md b/docs/federated/docs/source_en/java_api_syncfljob.md deleted file mode 100644 index 83118199d3bccc9936a95a7175982dc47e2adb1b..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/java_api_syncfljob.md +++ /dev/null @@ -1,64 +0,0 @@ -# SyncFLJob - - - -```java -import com.mindspore.flclient.SyncFLJob -``` - -SyncFLJob defines the API flJobRun() for starting federated learning on the device, the API modelInference() for inference on the device, the API getModel() for obtaining the latest model on the cloud, and the API stopFLJob() for stopping federated learning training tasks. - -## Public Member Functions - -| **Function** | -| -------------------------------- | -| public FLClientStatus flJobRun() | -| public int[] modelInference() | -| public FLClientStatus getModel() | -| public void stopFLJob() | - -## flJobRun - -```java -public FLClientStatus flJobRun() -``` - -Starts a federated learning task on the device, for specific usage, please refer to the [interface introduction document](https://www.mindspore.cn/federated/docs/en/master/interface_description_federated_client.html). - -- Return value - - The status code of the flJobRun request. - -## modelInference - -```java -public int[] modelInference() -``` - -Starts an inference task on the device, for specific usage, please refer to the [interface introduction document](https://www.mindspore.cn/federated/docs/en/master/interface_description_federated_client.html). - -- Return value - - int[] composed of the labels inferred from the input. - -## getModel - -```java -public FLClientStatus getModel() -``` - -Obtains the latest model on the cloud, for specific usage, please refer to the [interface introduction document](https://www.mindspore.cn/federated/docs/en/master/interface_description_federated_client.html). - -- Return value - - The status code of the getModel request. - -## stopFLJob - -```java -public void stopFLJob() -``` - -The training task can be stopped by calling this interface during the federated learning training process. - -When a thread calls SyncFLJob.flJobRun(), it can use another thread to call SyncFLJob.stopFLJob() to stop the federated learning training task during the federated learning training process. \ No newline at end of file diff --git a/docs/federated/docs/source_en/local_differential_privacy_training_noise.md b/docs/federated/docs/source_en/local_differential_privacy_training_noise.md deleted file mode 100644 index 3f444cb815ac5da04b6c008897388b20d0d06808..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/local_differential_privacy_training_noise.md +++ /dev/null @@ -1,49 +0,0 @@ -# Local differential privacy perturbation training - - - -During federated learning, user data is used only for local device training and does not need to be uploaded to the central server. This prevents personal data leakage. -However, in the conventional federated learning framework, models are migrated to the cloud in plaintext. There is still a risk of indirect disclosure of user privacy. -After obtaining the plaintext model uploaded by a user, the attacker can restore the user's personal training data through attacks such as reconstruction and model inversion. As a result, user privacy is disclosed. - -As a federated learning framework, MindSpore Federated provides secure aggregation algorithms based on local differential privacy (LDP). -Noise addition is performed on local models before they are migrated to the cloud. On the premise of ensuring the model availability, the problem of privacy leakage in horizontal federated learning is solved. - -## Principles - -Differential privacy is a mechanism for protecting user data privacy. **Differential privacy** is defined as follows: - -$$ -Pr[\mathcal{K}(D)\in S] \le e^{\epsilon} Pr[\mathcal{K}(D') \in S]+\delta​ -$$ - -For datasets $D and D'$ that have only one record difference, the random algorithm $\mathcal{K}$ is used to compute the probability of the $S$ subset, which meets the preceding formula. $\epsilon$ is the differential privacy budget, and $\delta$ is the perturbation. The smaller the values of $\epsilon$ and $\delta$, the closer the data distribution of $\mathcal{K}$ on $D$ and $D'$. - -In horizontal federated learning, if the model weight matrix after local training on the client is $W$, the attacker can use $W$ to restore the training dataset[1] of the user because the model "remembers" the features of the training set during the training process. - -MindSpore Federated provides a LDP-based secure aggregation algorithm to prevent privacy data leakage when local models are migrated to the cloud. - -The MindSpore Federated client generates a differential noise matrix $G$ that has the same dimension as the local model $W$, and then adds the two to obtain a weight $W_p$ that meets the differential privacy definition: - -$$ -W_p=W+G -$$ - -The MindSpore Federated client uploads the noise-added model $W_p$ to the cloud server for federated aggregation. The noise matrix $G$ is equivalent to adding a layer of mask to the original model, which reduces the risk of sensitive data leakage from models and affects the convergence of model training. How to achieve a better balance between model privacy and usability is still a question worth studying. Experiments show that when the number of participants $n$ is large enough (generally more than 1000), most of the noises can cancel each other, and the LDP mechanism has no obvious impact on the accuracy and convergence of the aggregation model. - -## Usage - -Local differential privacy training currently only supports cross device scenarios. Enabling differential privacy training is simple. You only need to perform the following operation during the cloud service startup. -Use `set_fl_context()` to set `encrypt_type='DP_ENCRYPT'`. - -In addition, to control the effect of privacy protection, three parameters are provided: `dp_eps`, `dp_delta`, and `dp_norm_clip`. -They are also set through `set_fl_context()`. The valid value range of `dp_eps` and `dp_norm_clip` is greater than 0. - -The value of `dp_delta` ranges between 0 and 1. Generally, the smaller the values of `dp_eps` and `dp_delta`, the better the privacy protection effect. -However, the impact on model convergence is greater. It is recommended that `dp_delta` be set to the reciprocal of the number of clients and the value of `dp_eps` be greater than 50. - -`dp_norm_clip` is the adjustment coefficient of the model weight before noise is added to the model weight by the LDP mechanism. It affects the convergence of the model. The recommended value ranges from 0.5 to 2. - -## References - -[1] Ligeng Zhu, Zhijian Liu, and Song Han. [Deep Leakage from Gradients](http://arxiv.org/pdf/1906.08935.pdf). NeurIPS, 2019. diff --git a/docs/federated/docs/source_en/pairwise_encryption_training.md b/docs/federated/docs/source_en/pairwise_encryption_training.md deleted file mode 100644 index 9fd27e8438ecf13eae5af8e2c9c7ea356a2d3324..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/pairwise_encryption_training.md +++ /dev/null @@ -1,67 +0,0 @@ -# Pairwise encryption training - - - -During federated learning, user data is used only for local device training and does not need to be uploaded to the central server. This prevents personal data leakage. -However, in the conventional federated learning framework, models are migrated to the cloud in plaintext. There is still a risk of indirect disclosure of user privacy. -After obtaining the plaintext model uploaded by a user, the attacker can restore the user's personal training data through attacks such as reconstruction and model inversion. As a result, user privacy is disclosed. - -As a federated learning framework, MindSpore Federated provides secure aggregation algorithms based on local secure multi-party computation (MPC). -Secret noise addition is performed on local models before they are migrated to the cloud. On the premise of ensuring the model availability, the problem of privacy leakage and model theft in horizontal federated learning are solved. - -## Principles - -Although the LDP technology can properly protect user data privacy, when there are a relatively small quantity of participating clients or a Gaussian noise amplitude is relatively large, the model accuracy is greatly affected. -To meet both model protection and model convergence requirements, we provide the MPC-based secure aggregation solution. - -In this training mode, assuming that the participating client set is $U$, for any client $u$ and $v$, they negotiate a pair of random perturbations $p_{uv}$ and $p_{vu}$, which meet the following condition: - -$$ -p_{uv}=\begin{cases} -p_{vu}, &u{\neq}v\\\\ 0, &u=v \end{cases} -$$ - -Therefore, each client $u$ adds the perturbation negotiated with other users to the original model weight $x_u$ before uploading the model to the server: - -$$ -x_{encrypt}=x_u+\sum\limits_{v{\in}U}p_{uv} -$$ - -Therefore, the Server aggregation result $\overline{x}$ is as follows: - -$$ -\begin{align} -\overline{x}&=\sum\limits_{u{\in}U}(x_{u}+\sum\limits_{v{\in}U}p_{uv})\\\\ -&=\sum\limits_{u{\in}U}x_{u}+\sum\limits_{u{\in}U}\sum\limits_{v{\in}U}p_{uv}\\\\ -&=\sum\limits_{u{\in}U}x_{u} -\end{align} -$$ - -The preceding process describes only the main idea of the aggregation algorithm. The MPC-based aggregation solution is accuracy-lossless but increases the number of communication rounds. -If you are interested in the specific steps of the algorithm, refer to the paper[1]. - -## Usage - -### Cross device scenario - -Enabling pairwise encryption training is simple. You only need to set `encrypt_type='PW_ENCRYPT'` in `set_fl_context()`. - -In addition, most of the workers participating in the training are unstable edge computing nodes such as mobile phones, so the problems of dropping the line and secret key reconstruction should be considered. Related parameters are `share_secrets_ratio`, `reconstruct_secrets_threshold`, and `cipher_time_window`. - -`share_client_ratio` indicates the client threshold decrease ratio of public key broadcast round, secret sharing round and secret reconstruction round. The value must be less than or equal to 1. - -`reconstruct_secrets_threshold` indicates the number of secret shares required to reconstruct a secret. The value must be less than the number of clients that participate in updateModel, which is start_fl_job_threshold*update_model_ratio (those two parameters can refer to 'set_fl_context' in [this file](https://gitee.com/mindspore/mindspore/blob/master/mindspore/python/mindspore/context.py)). - -To ensure system security, the value of `reconstruct_secrets_threshold` must be greater than half of the number of federated learning clients when the server and client are not colluded. -When the server and client are colluded, the value of `reconstruct_secrets_threshold` must be greater than two thirds of the number of federated learning clients. - -`cipher_time_window` indicates the duration limit of each communication round for secure aggregation. It is used to ensure that the server can start a new round of iteration when some clients are offline. - -### Cross silo scenario - -In cross silo scenario, you only need to set `encrypt_type='STABLE_PW_ENCRYPT'` in `set_fl_context()` for both server startup script and client startup script. - -Different from cross silo scenario, all of the workers are stable computing nodes in cross silo scenario. You only need to set the parameter `cipher_time_window`. - -## References - -[1] Keith Bonawitz, Vladimir Ivanov, Ben Kreuter, et al. [Practical Secure Aggregationfor Privacy-Preserving Machine Learning](https://dl.acm.org/doi/pdf/10.1145/3133956.3133982). NeurIPS, 2016. diff --git a/docs/federated/docs/source_en/sentiment_classification_application.md b/docs/federated/docs/source_en/sentiment_classification_application.md deleted file mode 100644 index 9cddf18a1151e9755200a8133b988149834ceefa..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_en/sentiment_classification_application.md +++ /dev/null @@ -1,454 +0,0 @@ -# Implementing a Sentiment Classification Application (Android) - - - -In privacy compliance scenarios, the federated learning modeling mode based on device-cloud synergy can make full use of the advantages of device data and prevent sensitive user data from being directly reported to the cloud. When exploring the application scenarios of federated learning, we notice the input method scenario. Users attach great importance to their text privacy and intelligent functions on the input method. Therefore, federated learning is naturally applicable to the input method scenario. MindSpore Federated applies the federated language model to the emoji prediction function of the input method. The federated language model recommends emojis suitable for the current context based on the chat text data. During federated learning modeling, each emoji is defined as a sentiment label category, and each chat phrase corresponds to an emoji. MindSpore Federated defines the emoji prediction task as a federated sentiment classification task. - -## Preparations - -### Environment - -For details, see [Server Environment Configuration](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_server.html) and [Client Environment Configuration](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_client.html). - -### Data - -The [training data](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/supervise/client.tar.gz) contains 20 user chat files. The directory structure is as follows: - -```text -mobile/datasets/train/ -├── 0.tsv # Training data of user 0 -├── 1.tsv # Training data of user 1 -│ -│ ...... -│ -└── 19.tsv # Training data of user 19 -``` - -The [validation data](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/supervise/eval.tar.gz) contains one chat file. The directory structure is as follows: - -```text -datasets/supervise/eval/ -└── eval.txt # Validation data -``` - -The labels in the training data and validation data correspond to four types of emojis: `good`, `leimu`, `xiaoku`, `xin`. - -### Model-related Files - -The directory structures of the [dictionary](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/vocab.txt) and the [mapping file of dictionary ID](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/vocab_map_ids.txt) related to the model file are as follows: - -```text -mobile/models/ -├── vocab.txt # Dictionary -└── vocab_map_ids.txt # mapping file of Dictionary ID -``` - -## Defining the Network - -The ALBERT language model[1] is used in federated learning. The ALBERT model on the client includes the embedding layer, encoder layer, and classifier layer. - -For details about the network definition, see [source code](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/mobile/src/model.py). - -### Generating a Device Model File - -#### Exporting a Model as a MindIR File - -The sample code is as follows: - -```python -import numpy as np -import mindspore as ms -from src.config import train_cfg, client_net_cfg -from src.cell_wrapper import NetworkTrainCell - -# Build a model. -client_network_train_cell = NetworkTrainCell(client_net_cfg) - -# Build input data. -input_ids = ms.Tensor(np.zeros((train_cfg.batch_size, client_net_cfg.seq_length), dtype=np.int32)) -attention_mask = ms.Tensor(np.zeros((train_cfg.batch_size, client_net_cfg.seq_length), dtype=np.int32)) -token_type_ids = ms.Tensor(np.zeros((train_cfg.batch_size, client_net_cfg.seq_length), dtype=np.int32)) -label_ids = ms.Tensor(np.zeros((train_cfg.batch_size, client_net_cfg.num_labels), dtype=np.int32)) - -# Export the model. -ms.export(client_network_train_cell, input_ids, attention_mask, token_type_ids, label_ids, file_name='albert_train.mindir', file_format='MINDIR') -``` - -#### Converting the MindIR File into an MS File that Can Be Used by the Federated Learning Framework on the Device - -For details about how to generate a model file on the device, see [Implementing an Image Classification Application](https://www.mindspore.cn/federated/docs/en/master/image_classification_application.html). - -## Starting the Federated Learning Process - -Start the script on the server. For details, see [Cloud-based Deployment](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_server.html) - -Based on the training and inference tasks of the ALBERT model, the overall process is as follows: - -1. Create an Android project. - -2. Build the MindSpore Lite AAR package. - -3. Describe the Android instance program structure. - -4. Write code. - -5. Configure Android project dependencies. - -6. Build and run on Android. - -### Creating an Android Project - -Create a project in Android Studio and install the corresponding SDK. (After the SDK version is specified, Android Studio automatically installs the SDK.) - -![New project](./images/create_android_project.png) - -### Building the MindSpore Lite AAR Package - -- For details, see [Federated Learning Deployment](https://www.mindspore.cn/federated/docs/en/master/deploy_federated_client.html). - -- Name of the generated Android AAR package: - - ```sh - mindspore-lite-full-{version}.aar - ``` - -- Place the AAR package in the app/libs/ directory of the Android project. - -### Android Instance Program Structure - -```text -app -│ ├── libs # Binary archive file of the Android library project -| | └── mindspore-lite-full-{version}.aar # MindSpore Lite archive file of the Android version -├── src/main -│ ├── assets # Resource directory -| | └── model # Model directory -| | └── albert_ad_train.mindir.ms # Pre-trained model file -│ | └── albert_ad_infer.mindir.ms # Inference model file -│ | └── data # Data directory -| | └── 0.txt # training data file -| | └── vocab.txt # Dictionary file -| | └── vocab_map_ids.txt # Dictionary ID mapping file -| | └── eval.txt # Training result evaluation file -| | └── eval_no_label.txt # Inference data file -│ | -│ ├── java # Application code at the Java layer -│ │ └── ... Storing Android code files. Related directories can be customized. -│ │ -│ ├── res # Resource files related to Android -│ └── AndroidManifest.xml # Android configuration file -│ -│ -├── build.gradle # Android project build file -├── download.gradle # Downloading the project dependency files -└── ... -``` - -### Writing Code - -1. AssetCopyer.java: This code file is used to store the resource files in the app/src/main/assets directory of the Android project to the disk of the Android system. In this way, the federated learning framework API can read the resource files based on the absolute path during model training and inference. - - ```java - import android.content.Context; - - import java.io.File; - import java.io.FileOutputStream; - import java.io.InputStream; - import java.util.logging.Logger; - - public class AssetCopyer { - private static final Logger LOGGER = Logger.getLogger(AssetCopyer.class.toString()); - public static void copyAllAssets(Context context,String destination) { - LOGGER.info("destination: " + destination); - copyAssetsToDst(context,"",destination); - } - // Copy the resource files in the assets directory to the disk of the Android system. You can view the specific path by printing destination. - private static void copyAssetsToDst(Context context,String srcPath, String dstPath) { - try { - // Recursively obtain all file names in the assets directory. - String[] fileNames =context.getAssets().list(srcPath); - if (fileNames.length > 0) { - // Build the destination file object. - File file = new File(dstPath); - // Create a destination directory. - file.mkdirs(); - for (String fileName : fileNames) { - // Copy the file to the specified disk. - if(!srcPath.equals("")) { - copyAssetsToDst(context,srcPath + "/" + fileName,dstPath+"/"+fileName); - }else{ - copyAssetsToDst(context, fileName,dstPath+"/"+fileName); - } - } - } else { - // Build the input stream of the source file. - InputStream is = context.getAssets().open(srcPath); - // Build the output stream of the destination file. - FileOutputStream fos = new FileOutputStream(new File(dstPath)); - // Define a 1024-byte buffer array. - byte[] buffer = new byte[1024]; - int byteCount=0; - // Write the source file to the destination file. - while((byteCount=is.read(buffer))!=-1) { - fos.write(buffer, 0, byteCount); - } - // Refresh the output stream. - fos.flush(); - // Close the input stream. - is.close(); - // Close the output stream. - fos.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - ``` - -2. FlJob.java: This code file is used to define training and inference tasks. For details about federated learning APIs, see [Federal Learning APIs](https://www.mindspore.cn/federated/docs/en/master/interface_description_federated_client.html). - - ```java - import android.annotation.SuppressLint; - import android.os.Build; - import androidx.annotation.RequiresApi; - import com.mindspore.flAndroid.utils.AssetCopyer; - import com.mindspore.flclient.FLParameter; - import com.mindspore.flclient.SyncFLJob; - import java.util.Arrays; - import java.util.UUID; - import java.util.logging.Logger; - public class FlJob { - private static final Logger LOGGER = Logger.getLogger(AssetCopyer.class.toString()); - private final String parentPath; - public FlJob(String parentPath) { - this.parentPath = parentPath; - } - // Android federated learning training task - @SuppressLint("NewApi") - @RequiresApi(api = Build.VERSION_CODES.M) - public void syncJobTrain() { - // create dataMap - String trainTxtPath = "data/albert/supervise/client/1.txt"; - String evalTxtPath = "data/albert/supervise/eval/eval.txt"; // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - String vocabFile = "data/albert/supervise/vocab.txt"; // Path of the dictionary file for data preprocessing. - String idsFile = "data/albert/supervise/vocab_map_ids.txt" // Path of the mapping ID file of a dictionary. - Map> dataMap = new HashMap<>(); - List trainPath = new ArrayList<>(); - trainPath.add(trainTxtPath); - trainPath.add(vocabFile); - trainPath.add(idsFile); - List evalPath = new ArrayList<>(); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(evalTxtPath); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(vocabFile); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - evalPath.add(idsFile); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - dataMap.put(RunType.TRAINMODE, trainPath); - dataMap.put(RunType.EVALMODE, evalPath); // Not necessary, if you don't need verify model accuracy after getModel, you don't need to set this parameter - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // The package path of AlBertClient.java - String trainModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - - // The url for device-cloud communication. Ensure that the Android device can access the server. Otherwise, the message "connection failed" is displayed. - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(ifUseElb); - flParameter.setServerNum(serverNum); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - - // start FLJob - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.flJobRun(); - } - // Android federated learning inference task - public void syncJobPredict() { - // create dataMap - String inferTxtPath = "data/albert/supervise/eval/eval.txt"; - String vocabFile = "data/albert/supervise/vocab.txt"; - String idsFile = "data/albert/supervise/vocab_map_ids.txt"; - Map> dataMap = new HashMap<>(); - List inferPath = new ArrayList<>(); - inferPath.add(inferTxtPath); - inferPath.add(vocabFile); - inferPath.add(idsFile); - dataMap.put(RunType.INFERMODE, inferPath); - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // The package path of AlBertClient.java - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // Absolute path, consistent with trainModelPath - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setInferModelPath(inferModelPath); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(cpuBindMode); - flParameter.setBatchSize(batchSize); - - // inference - SyncFLJob syncFLJob = new SyncFLJob(); - int[] labels = syncFLJob.modelInference(); - LOGGER.info("labels = " + Arrays.toString(labels)); - } - } - ``` - -3. MainActivity.java: This code file is used to start federated learning training and inference tasks. - - ```java - import android.os.Build; - import android.os.Bundle; - - import androidx.annotation.RequiresApi; - import androidx.appcompat.app.AppCompatActivity; - - import com.huawei.flAndroid.job.FlJob; - import com.huawei.flAndroid.utils.AssetCopyer; - - @RequiresApi(api = Build.VERSION_CODES.P) - public class MainActivity extends AppCompatActivity { - private String parentPath; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // Obtain the disk path of the application in the Android system. - this.parentPath = this.getExternalFilesDir(null).getAbsolutePath(); - // Copy the resource files in the assets directory to the disk of the Android system. - AssetCopyer.copyAllAssets(this.getApplicationContext(), parentPath); - // Create a thread and start the federated learning training and inference tasks. - new Thread(() -> { - FlJob flJob = new FlJob(parentPath); - - flJob.syncJobTrain(); - flJob.syncJobPredict(); - }).start(); - } - } - ``` - -### Configuring Android Project Dependencies - -1. AndroidManifest.xml - - ```xml - - - - - - - - - - - - - - - ``` - -2. app/build.gradle - - ```text - plugins { - id 'com.android.application' - } - android { - // Android SDK build version. It is recommended that the version be later than 27. - compileSdkVersion 30 - buildToolsVersion "30.0.3" - defaultConfig { - applicationId "com.huawei.flAndroid" - minSdkVersion 27 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" - multiDexEnabled true - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - ndk { - // Different mobile phone models correspond to different NDKs. Mate 20 corresponds to 'armeabi-v7a'. - abiFilters 'armeabi-v7a' - } - } - // Specified NDK version - ndkVersion '21.3.6528147' - sourceSets{ - main { - // Specified JNI directory - jniLibs.srcDirs = ['libs'] - jni.srcDirs = [] - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - } - dependencies { - // AAR package to be scanned in the libs directory - implementation fileTree(dir:'libs',include:['*.aar']) - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation 'com.android.support:multidex:1.0.3' - - // Add third-party open source software that federated learning relies on - implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.14.9' - implementation group: 'com.google.flatbuffers', name: 'flatbuffers-java', version: '2.0.0' - implementation(group: 'org.bouncycastle',name: 'bcprov-jdk15on', version: '1.68') - } - ``` - -### Building and Running on Android - -1. Connect to the Android device and run federated learning training and inference applications. Connect to the Android device through a USB cable for debugging. Click `Run 'app'` to run the federated learning task on your device. - - ![run_app](./images/start_android_project.png) - -2. For details about how to connect the Android Studio to a device for debugging, see . Android Studio can identify the mobile phone only when USB debugging mode is enabled on the mobile phone. For Huawei phones, enable USB debugging mode by choosing Settings > System & updates > Developer options > USB debugging. - -3. Continue the installation on the Android device. After the installation is complete, you can start the app to train and infer the ALBERT model for federated learning. - -4. The program running result is as follows: - - ```text - I/SyncFLJob: [model inference] inference finish - I/SyncFLJob: labels = [2, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4] - ``` - -## Experiment Result - -The total number of federated learning iterations is 5, the number of epochs for local training on the client is 10, and the value of batchSize is 16. - -| | Top 1 Accuracy| Top 5 Accuracy| -| ------ | -------- | -------- | -| ALBERT | 24% | 70% | - -## References - -[1] Lan Z , Chen M , Goodman S , et al. ALBERT: A Lite BERT for Self-supervised Learning of Language Representations[J]. 2019. diff --git a/docs/federated/docs/source_zh_cn/_ext/__pycache__/my_signature.cpython-37.pyc b/docs/federated/docs/source_zh_cn/_ext/__pycache__/my_signature.cpython-37.pyc deleted file mode 100644 index 516af30c9a197f89a41eb556f5f38d22e72d6668..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/_ext/__pycache__/my_signature.cpython-37.pyc and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/comunication_compression.md b/docs/federated/docs/source_zh_cn/comunication_compression.md deleted file mode 100644 index 7a02a958cdaf791adb2ee581f9194bb1ee7d80fb..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/comunication_compression.md +++ /dev/null @@ -1,146 +0,0 @@ -# 端云联邦学习通信压缩 - - - -在端云联邦学习训练过程中,通信量会影响端侧用户体验(用户流量、通信时延、FL-Client 参与数量),并受云侧性能约束(内存、带宽、CPU 占用率)限制。为了提高用户体验和减少性能瓶颈,MindSpore联邦学习框架在端云联邦场景中,提供上传和下载的通信量压缩功能。 - -## 压缩方法 - -### 上传压缩方法 - -上传压缩方法可以分为三个主要部分:权重差编解码、稀疏编解码和量化编解码,下面给出了FL-Client和FL-Server上的流程图。 - -![上传压缩client执行顺序](./images/upload_compression_client.png) - -图1 上传压缩方法在FL-Client上的流程图 - -![上传压缩server执行顺序](./images/upload_compression_server.png) - -图2 上传压缩方法在FL-Server上的流程图 - -### 权重差编解码 - -权重差即为端侧训练前后的权重矩阵的向量差。相较于原始权重而言,权重差的分布更符合高斯分布,因此更适合被压缩。FL-Client对权重差进行编码操作,FL-Server对权重差进行解码操作。值得注意的是,为了在FL-Server聚合权重前就将权重差还原为权重,FL-Client在上传权重时,不将权重乘以数据量。FL-Server解码时,需要将权重乘以数据量。 - -![权重差编码](./images/weight_diff_encode.png) - -图3 权重差编码在FL-Client上的流程图 - -![权重差解码](./images/weight_diff_decode.png) - -图4 权重差解码在FL-Server上的流程图 - -### 稀疏编解码 - -端云都遵循同样的随机算法生成稀疏掩码矩阵,该掩码矩阵和原本需要上传的权重形状相同。掩码矩阵只包含0或1两个值。每个FL-Client只上传和掩码矩阵非零值位置相同的权重的数据到FL-Server上。 - -以稀疏率sparse_rate=0.08的稀疏方法为例。FL-Client原本需要上传的参数: - -| 参数名 | 长度 | -| -------------------- | ----- | -| albert.pooler.weight | 97344 | -| albert.pooler.bias | 312 | -| classifier.weight | 1560 | -| classifier.bias | 5 | - -将所有参数接为一维向量: - -| 参数名 | 长度 | -| ----------- | ---------------------- | -| merged_data | 97344+312+1560+5=99221 | - -生成和拼接后参数长度一样的mask向量,其中,有7937 = int(sparse_rate*拼接后参数长度)个值为1,其余值为0(即mask_vector = (1,1,1,...,0,0,0,...)): - -| 参数名 | 长度 | -| ----------- | ----- | -| mask_vector | 99221 | - -使用伪随机算法,将mask_vector随机打乱。随机种子为当前的iteration数。取出mask_vector中值为1的索引indexes。取出merged_data[indexes]的值,即压缩后的向量: - -| 参数名 | 长度 | -| ----------------- | ---- | -| compressed_vector | 7937 | - -稀疏压缩后,FL-Client需要上传的参数即为compressed_vector。 - -FL-Server在收到compressed_vector后,首先会用和FL-Client同样的伪随机算法和随机种子,构造出掩码向量mask_vector。然后取出mask_vector中值为1的索引indexes。再然后,生成和模型相同shape的全零矩阵weight_vector。依次将compressed_vector中的值放入weight_vector[indexes]中。weight_vector即为稀疏解码后的向量。 - -### 量化编解码 - -量化压缩方法即将浮点型的通信数据定点近似为有限多个离散值。 - -以8-bit量化举例来讲: - -量化位数num_bits = 8 - -压缩前的浮点型数据为: - -data = [0.03356021, -0.01842778, -0.009684053, 0.025363436, -0.027571501, 0.0077043395, 0.016391572, -0.03598478, -0.0009508357] - -计算最大和最小值: - -min_val = -0.03598478 - -max_val = 0.03356021 - -计算缩放系数: - -scale = (max_val - min_val ) / (2 ^ num_bits - 1) = 0.000272725450980392 - -将压缩前数据转换为-128到127之间的整数,转换公式为quant_data = round((data - min_val) / scale) - 2 ^ (num_bits - 1)。并强转数据类型到int8: - -quant_data = [127, -64, -32, 97, -97, 32, 64, -128, 0] - -量化编码后,FL-Client需要上传的参数即为quant_data以及最小和最大值min_val和max_val。 - -FL-Server在收到quant_data、min_val和max_val后,使用反量化公式(quant_data + 2 ^ (num_bits - 1)) * (max_val - min_val) / (2 ^ num_bits - 1) + min_val,还原出权重。 - -## 下载压缩方法 - -下载压缩方法主要为量化编解码操作,下面给出了FL-Server和FL-Client上的流程图。 - -![下载压缩server执行顺序](./images/download_compression_server.png) - -图5 下载压缩方法在FL-Server上的流程图 - -![下载压缩client执行顺序](./images/download_compression_client.png) - -图6 下载压缩方法在FL-Client上的流程图 - -### 量化编解码 - -量化的编解码方法和上传压缩中一样。 - -## 代码实现准备工作 - -若要使用上传和下载压缩方法,首先需要成功完成任一端云联邦场景的训练聚合过程,如[实现一个情感分类应用(Android)](https://www.mindspore.cn/federated/docs/zh-CN/master/sentiment_classification_application.html)。在该文档中详细介绍了包括数据集和网络模型等准备工作和模拟启动多客户端参与联邦学习的流程。 - -## 算法开启脚本 - -上传和下载压缩方法目前只支持端云联邦学习场景。开启方式需要在启动云侧服务时,在server启动脚本中使用`set_fl_context()`设置`upload_compress_type='DIFF_SPARSE_QUANT'`和`download_compress_type='QUANT'`。上述两个超参数即可分别控制上传和下载压缩方法的开启和关闭。云侧完整启动脚本可参考ALBERT中云侧部署的[run_hybrid_train_server.py脚本](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/albert/run_hybrid_train_server.py),这里给出启动该算法的相关参数配置。确定参数配置后,用户需要在执行训练前调用`set_fl_context`接口,传入算法参数,调用方式如下: - -```python -# 打开上传压缩开关 -parser.add_argument("--upload_compress_type", type=str, default="DIFF_SPARSE_QUANT") -# 上传压缩方法中稀疏率超参数 -parser.add_argument("--upload_sparse_rate", type=float, default=0.4) -# 打开下载压缩开关 -parser.add_argument("--download_compress_type", type=str, default="QUANT") -args, _ = parser.parse_known_args() -ctx = { - "upload_compress_type": args.upload_compress_type, - "upload_sparse_rate": args.upload_sparse_rate, - "download_compress_type": args.download_compress_type, -} -set_fl_context(**fl_ctx) -``` - -| 超参名称&参考值 | 超参描述 | -| ----------------------------------------- | ------------------------------------------------------------ | -| "upload_compress_type": "NO_COMPRESS" | 上传压缩类型,string类型,包括:"NO_COMPRESS", "DIFF_SPARSE_QUANT" | -| "upload_sparse_rate": 0.5 | 稀疏率,即权重保留率,float类型,定义域在(0, 1]内 | -| "download_compress_type": "NO_COMPRESS" | 下载压缩类型,string类型,包括:"NO_COMPRESS", "QUANT" | - -## ALBERT实验结果 - -联邦学习总迭代数为100,客户端本地训练epoch数为1,客户端数量为20,batchSize设置为16,学习率为1e-5,同时开启上传和下载压缩方法,上传稀疏率为0.4。最终在验证集上的准确率为72.5%,不压缩的普通联邦场景为72.3%。 \ No newline at end of file diff --git a/docs/federated/docs/source_zh_cn/conf.py b/docs/federated/docs/source_zh_cn/conf.py deleted file mode 100644 index 510deea5a33d13f2453de42d446e33c029126e23..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/conf.py +++ /dev/null @@ -1,143 +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. -# -from genericpath import exists -import os -import shutil -import sys -import IPython -import re -from sphinx.ext import autodoc as sphinx_autodoc - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = '2021, 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. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'sphinx_markdown_tables', - 'myst_parser', - 'nbsphinx', - 'sphinx.ext.mathjax', - 'IPython.sphinxext.ipython_console_highlighting' -] - -source_suffix = { - '.rst': 'restructuredtext', - '.md': 'markdown', -} - -# 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. -exclude_patterns = [] - -pygments_style = 'sphinx' - -# -- 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' - -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'), -} - -from sphinx import directives -with open('../_ext/overwriteobjectiondirective.txt', 'r', encoding="utf8") 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__) - -# 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__) - -# Copy source files of chinese python api from mindspore repository. -from sphinx.util import logging -logger = logging.getLogger(__name__) - -src_dir = os.path.join(os.getenv("MS_PATH"), 'docs/api/api_python/federated') - -for i in os.listdir(src_dir): - if os.path.exists('./'+i): - os.remove('./'+i) - shutil.copy(os.path.join(src_dir,i),'./'+i) - -import 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) diff --git a/docs/federated/docs/source_zh_cn/cross_device.rst b/docs/federated/docs/source_zh_cn/cross_device.rst deleted file mode 100644 index 9662faf80074f785d53a669c5f84d1d839b97eee..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/cross_device.rst +++ /dev/null @@ -1,13 +0,0 @@ -端云联邦学习 -============ - -.. toctree:: - :maxdepth: 1 - - java_api_callback - java_api_client - java_api_clientmanager - java_api_dataset - java_api_flparameter - java_api_syncfljob - interface_description_federated_client \ No newline at end of file diff --git a/docs/federated/docs/source_zh_cn/deploy_federated_client.md b/docs/federated/docs/source_zh_cn/deploy_federated_client.md deleted file mode 100644 index 8ee85fb2119b12256945d4b0e25985a290402c27..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/deploy_federated_client.md +++ /dev/null @@ -1,196 +0,0 @@ -# 端侧部署 - - - -本文档分别介绍如何面向Android aarch环境和Linux x86_64环境,部署Federated-Client。 - -## Android aarch环境 - -### 编译出包 - -1. 配置编译环境。 - - 目前只支持Linux环境编译,Linux编译环境配置可参考[这里](https://www.mindspore.cn/lite/docs/zh-CN/master/use/build.html#linux环境编译)。 - -2. 在mindspore根目录进行编译,编译x86架构相关包。 - - ```sh - bash build.sh -I x86_64 -j32 - ``` - - 编译完成后在`mindspore/output`路径下将生成x86架构包,请备份备用(`mindspore/output`每次编译均会进行清理) - - ```text - mindspore-lite-{version}-linux-x64.tar.gz - ``` - -3. 开启联邦编译选项,在mindspore根目录进行编译,编译包含aarch64和aarch32的AAR包。 - - ```sh - export MSLITE_ENABLE_FL=on - bash build.sh -A on -j32 - ``` - - 编译完成后在`mindspore/output`路径下将生成Android AAR包,请备份备用(`mindspore/output`每次编译均会进行清理) - - ```text - mindspore-lite-full-{version}.aar - ``` - -4. 由于端侧框架和模型是解耦的,我们提供的Android AAR包不包含模型相关脚本,因此需要用户自行生成模型脚本对应的jar包,我们提供了两个类型的模型脚本供大家参考([有监督情感分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert)、[LeNet图片分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet))。用户可参考这两个类型的模型脚本,自定义模型脚本后,生成对应的jar包(假设命名为`quick_start_flclient.jar`)。我们提供的模型脚本对应jar包可采用如下方式获取: - - 下载[MindSpore开源仓](https://gitee.com/mindspore/mindspore)最新代码后,执行以下操作: - - ```sh - cd mindspore/mindspore/lite/examples/quick_start_flclient - sh build.sh -r "mindspore-lite-{version}-linux-x64.tar.gz" # -r 后需给出最新x86版本架构包绝对路径(步骤2生成) - ``` - - 运行以上指令后生成jar包路径为:`mindspore/mindspore/lite/examples/quick_start_flclient/target/quick_start_flclient.jar`。 - -### 运行依赖 - -- [Android Studio](https://developer.android.google.cn/studio) >= 4.0 -- [Android SDK](https://developer.android.com/studio?hl=zh-cn#cmdline-tools) >= 29 - -### 构建依赖环境 - -将文件`mindspore-lite-full-{version}.aar`重命名为`mindspore-lite-full-{version}.zip`,解压后,所得到的目录结构如下所示: - -```text -mindspore-lite-full-{version} -├── jni -│ ├── arm64-v8a -│ │ ├── libjpeg.so # 图像处理动态库文件 -│ │ ├── libminddata-lite.so # 图像处理动态库文件 -│ │ ├── libmindspore-lite.so # MindSpore Lite推理框架依赖的动态库 -│ │ ├── libmindspore-lite-jni.so # MindSpore Lite推理框架依赖的jni动态库 -│ │ ├── libmindspore-lite-train.so # MindSpore Lite训练框架依赖的动态库 -│ │ ├── libmindspore-lite-train-jni.so # MindSpore Lite训练框架依赖的jni动态库 -│ │ └── libturbojpeg.so # 图像处理动态库文件 -│ └── armeabi-v7a -│ ├── libjpeg.so # 图像处理动态库文件 -│ ├── libminddata-lite.so # 图像处理动态库文件 -│ ├── libmindspore-lite.so # MindSpore Lite推理框架依赖的动态库 -│ ├── libmindspore-lite-jni.so # MindSpore Lite推理框架依赖的jni动态库 -│ ├── libmindspore-lite-train.so # MindSpore Lite训练框架依赖的动态库 -│ ├── libmindspore-lite-train-jni.so # MindSpore Lite训练框架依赖的jni动态库 -│ └── libturbojpeg.so # 图像处理动态库文件 -├── libs -│ ├── mindspore-lite-java-common.jar # MindSpore Lite训练框架jar包 -│ └── mindspore-lite-java-flclient.jar # 联邦学习框架jar包 -└── classes.jar # MindSpore Lite训练框架jar包 -``` - -注意1,由于生成Android环境中的联邦学习jar包时未包含所依赖的第三方开源软件包,因此在Android环境中,使用AAR包前,需要用户在Android工程下的app/build.gradle文件中,为dependencies{}字段添加相关依赖语句,用于加载联邦学习所依赖的三个开源软件,如下所示: - -```text -dependencies { - -//添加联邦学习所依赖第三方开源软件 -implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.14.9' -implementation group: 'com.google.flatbuffers', name: 'flatbuffers-java', version: '2.0.0' -implementation(group: 'org.bouncycastle',name: 'bcprov-jdk15on', version: '1.68') -} -``` - -具体实现可参考文档[情感分类应用](https://www.mindspore.cn/federated/docs/zh-CN/master/sentiment_classification_application.html)中 `Android工程配置依赖项`部分提供的`app/build.gradle` 文件示例。 - -注意2,由于联邦学习依赖的第三方开源软件`bcprov-jdk15on`包含多版本class文件,为防止低版本jdk编译高版本class文件出错,在Android工程的`gradle.properties`文件中可添加如下设置语句: - -```java -android.jetifier.blacklist=bcprov -``` - -在Android工程中设置好了如上所示依赖之后,只需依赖AAR包和模型脚本对应的jar包`quick_start_flclient.jar`即可调用联邦学习提供的相关接口,接口的具体调用和运行方式可参考[联邦学习接口介绍部分](https://www.mindspore.cn/federated/docs/zh-CN/master/index.html)。 - -## Linux x86_64环境 - -### 编译出包 - -1. 配置编译环境。 - - 目前只支持Linux环境编译,Linux编译环境配置可参考[这里](https://www.mindspore.cn/lite/docs/zh-CN/master/use/build.html#linux环境编译)。 - -2. 在mindspore根目录进行编译,编译x86架构相关包。 - - ```sh - bash build.sh -I x86_64 -j32 - ``` - - 编译完成后在`mindspore/output`路径下将生成x86架构包,请备份备用(`mindspore/output`每次编译均会进行清理)。 - - ```text - mindspore-lite-{version}-linux-x64.tar.gz - ``` - -3. 由于端侧框架和模型是解耦的,我们提供的x86架构包`mindspore-lite-{version}-linux-x64.tar.gz`不包含模型相关脚本,因此需要用户自行生成模型脚本对应的jar包,我们提供了两个类型的模型脚本供大家参考([有监督情感分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert)、[LeNet图片分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet))。同时,用户可参考这两个类型的模型脚本,自定义模型脚本后生成对应的jar包(假设命名为`quick_start_flclient.jar`)。我们提供的模型脚本对应jar包可采用如下方式获取: - - 下载[MindSpore开源仓](https://gitee.com/mindspore/mindspore)最新代码后,进行以下操作: - - ```sh - cd mindspore/mindspore/lite/examples/quick_start_flclient - sh build.sh -r "mindspore-lite-{version}-linux-x64.tar.gz" # -r 后需给出最新x86架构包绝对路径(步骤2生成) - ``` - - 运行以上指令后生成jar包路径为:`mindspore/mindspore/lite/examples/quick_start_flclient/target/quick_start_flclient.jar`。 - -### 运行依赖 - -- [Python](https://www.python.org/downloads/)>=3.7.0 -- [OpenJDK](https://openjdk.java.net/install/) 1.8 到 1.15 - -### 构建依赖环境 - -将文件`mindspore/output/mindspore-lite-{version}-linux-x64.tar.gz`解压后,所得到的目录结构如下所示: - -```sh -mindspore-lite-{version}-linux-x64 -├── tools -│ ├── benchmark_train # 训练模型性能与精度调测工具 -│ ├── converter # 模型转换工具 -│ └── cropper # 库裁剪工具 -│ ├── cropper # 库裁剪工具可执行文件 -│ └── cropper_mapping_cpu.cfg # 裁剪cpu库所需的配置文件 -└── runtime - ├── include # 训练框架头文件 - │ └── registry # 自定义算子注册头文件 - ├── lib # 训练框架库 - │ ├── libminddata-lite.a # 图像处理静态库文件 - │ ├── libminddata-lite.so # 图像处理动态库文件 - │ ├── libmindspore-lite-jni.so # MindSpore Lite推理框架依赖的jni动态库 - │ ├── libmindspore-lite-train.a # MindSpore Lite训练框架依赖的静态库 - │ ├── libmindspore-lite-train.so # MindSpore Lite训练框架依赖的动态库 - │ ├── libmindspore-lite-train-jni.so # MindSpore Lite训练框架依赖的jni动态库 - │ ├── libmindspore-lite.a # MindSpore Lite推理框架依赖的静态库 - │ ├── libmindspore-lite.so # MindSpore Lite推理依赖的动态库 - │ ├── mindspore-lite-java.jar # MindSpore Lite训练框架jar包 - │ └── mindspore-lite-java-flclient.jar # 联邦学习框架jar包 - └── third_party - └── libjpeg-turbo - └── lib - ├── libjpeg.so.62 # 图像处理动态库文件 - └── libturbojpeg.so.0 # 图像处理动态库文件 -``` - -其中联邦学习所需的相关x86包名如下: - -```sh -libjpeg.so.62 # 图像处理动态库文件 -libminddata-lite.so # 图像处理动态库文件 -libmindspore-lite.so # MindSpore Lite推理框架依赖的动态库 -libmindspore-lite-jni.so # MindSpore Lite推理框架依赖的jni动态库 -libmindspore-lite-train.so # MindSpore Lite训练框架依赖的动态库 -libmindspore-lite-train-jni.so # MindSpore Lite训练框架的jni动态库 -libturbojpeg.so.0 # 图像处理动态库文件 -mindspore-lite-java-flclient.jar # 联邦学习框架jar包 -quick_start_flclient.jar # 模型脚本对应的jar包 -``` - -可将路径`mindspore/output/mindspore-lite-{version}-linux-x64/runtime/lib/`以及`mindspore/output/mindspore-lite-{version}-linux-x64/runtime/third_party/libjpeg-turbo/lib`中联邦学习所依赖的so文件(共7个)放入一个文件夹,比如`/resource/x86libs/`。然后在x86中设置环境变量(下面需提供绝对路径): - -```sh -export LD_LIBRARY_PATH=/resource/x86libs/:$LD_LIBRARY_PATH -``` - -设置好依赖环境之后,可参考应用实践教程[实现一个端云联邦的图像分类应用(x86)](https://www.mindspore.cn/federated/docs/zh-CN/master/image_classification_application.html)在x86环境中模拟启动多个客户端进行联邦学习。 diff --git a/docs/federated/docs/source_zh_cn/deploy_federated_server.md b/docs/federated/docs/source_zh_cn/deploy_federated_server.md deleted file mode 100644 index 0a6aeeff3117ab978fb1fcd284db5fb8eec2a266..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/deploy_federated_server.md +++ /dev/null @@ -1,358 +0,0 @@ -# 云侧部署 - - - -本文档以LeNet网络为例,讲解如何使用MindSpore部署联邦学习集群。 - -> 可以在[这里](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/mobile)下载本文档中的完整Demo。 - -MindSpore Federated Learning (FL) Server集群物理架构如图所示: - -![](./images/mindspore_federated_networking.png) - -如上图所示,在联邦学习云侧集群中,有两种角色的MindSpore进程:`Federated Learning Scheduler`和`Federated Learning Server`: - -- Federated Learning Scheduler - - `Scheduler`的功能主要包括: - - 1. 协助集群组网:在集群初始化阶段,由`Scheduler`负责收集`Server`信息,并保障集群一致性。` - 2. 开放管理面:向用户提供`RESTful`接口,实现对集群的管理。 - - 在一个联邦学习任务中,只有一个`Scheduler`,其与`Server`通过TCP协议通信。 - -- Federated Learning Server - - `Server`为执行联邦学习任务的主体,用于接收和解析端侧设备上传的数据,具有执行安全聚合、限时通信、模型存储等能力。在一个联邦学习任务中,`Server`可以有多个(用户可配置),`Server`间通过TCP协议通信,对外开放HTTP端口与端侧设备连接。 - - 在MindSpore联邦学习框架中,`Server`还支持弹性伸缩以及容灾,能够在训练任务不中断的情况下,动态调配硬件资源。 - -`Scheduler`和`Server`需部署在单网卡的服务器或者容器中,且处于相同网段。MindSpore自动获取首个可用IP地址作为`Server`地址。 - -> 服务器会校验客户端携带的时间戳,需要确保服务器定期同步时钟,避免服务器出现较大的时钟偏移。 - -## 准备环节 - -### 安装MindSpore - -MindSpore联邦学习云侧集群支持在x86 CPU和GPU CUDA硬件平台上部署。可参考[MindSpore安装指南](https://www.mindspore.cn/install)安装MindSpore最新版本。 - -## 定义模型 - -为便于部署,MindSpore联邦学习的`Scheduler`和`Server`进程可以复用训练脚本,仅通过[参数配置](#参数配置)选择以不同的角色启动。 - -本教程选择LeNet网络作为示例,具体的网络结构、损失函数和优化器定义请参考[LeNet网络样例脚本](https://gitee.com/mindspore/docs/blob/master/docs/sample_code/lenet/lenet.py)。 - -## 参数配置 - -MindSpore联邦学习任务进程复用了训练脚本,用户只需要使用相同的脚本,并通过Python接口`set_fl_context`传递不同的参数,启动不同角色的MindSpore进程。参数配置说明请参考[API文档](https://www.mindspore.cn/federated/docs/zh-CN/master/federated_server.html#mindspore.set_fl_context)。 - -在确定参数配置后,用户需要在执行训练前调用`set_fl_context`接口,调用方式的示例如下: - -```python -import mindspore as ms -... - -enable_fl = True -server_mode = "FEDERATED_LEARNING" -ms_role = "MS_SERVER" -server_num = 4 -scheduler_ip = "192.168.216.124" -scheduler_port = 6667 -fl_server_port = 6668 -fl_name = "LeNet" -scheduler_manage_port = 11202 -config_file_path = "./config.json" - -fl_ctx = { - "enable_fl": enable_fl, - "server_mode": server_mode, - "ms_role": ms_role, - "server_num": server_num, - "scheduler_ip": scheduler_ip, - "scheduler_port": scheduler_port, - "fl_server_port": fl_server_port, - "fl_name": fl_name, - "scheduler_manage_port": scheduler_manage_port, - "config_file_path": config_file_path -} -ms.set_fl_context(**fl_ctx) -... - -model.train() -``` - -本示例设置了训练任务的模式为`联邦学习`(即`FEDERATED_LEARNING`),训练进程角色为`Server`,需要启动`4`个`Server`进行集群组网,集群`Scheduler`的IP地址为`192.168.216.124`,集群`Scheduler`端口为`6667`,联邦学习`HTTP服务端口`为`6668`(由端侧设备连接),任务名为`LeNet`,集群`Scheduler`管理端口为`11202`。 - -> 示例中的参数,部分仅被`Scheduler`使用,如`scheduler_manage_port`;部分仅被`Server`使用,如`fl_server_port`。为了方便部署,可将这些参数配置统一传入,MindSpore会根据进程角色,选择读取所需的参数配置。 - -建议将参数配置通过Python `argparse`模块传入,以下是部分关键参数传入脚本的示例: - -```python -import argparse - -parser = argparse.ArgumentParser() -parser.add_argument("--server_mode", type=str, default="FEDERATED_LEARNING") -parser.add_argument("--ms_role", type=str, default="MS_SERVER") -parser.add_argument("--server_num", type=int, default=4) -parser.add_argument("--scheduler_ip", type=str, default="192.168.216.124") -parser.add_argument("--scheduler_port", type=int, default=6667) -parser.add_argument("--fl_server_port", type=int, default=6668) -parser.add_argument("--fl_name", type=str, default="LeNet") -parser.add_argument("--scheduler_manage_port", type=int, default=11202) -parser.add_argument("--config_file_path", type=str, default="") - -args, t = parser.parse_known_args() -server_mode = args.server_mode -ms_role = args.ms_role -server_num = args.server_num -scheduler_ip = args.scheduler_ip -scheduler_port = args.scheduler_port -fl_server_port = args.fl_server_port -fl_name = args.fl_name -scheduler_manage_port = args.scheduler_manage_port -config_file_path = args.config_file_path -``` - -> 每个Python脚本对应一个进程,若要在不同主机部署多个`Server`角色,则需要分别建立多个进程,可以通过shell指令配合Python的方式快速启动多`Server`。可参考**[示例](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/mobile)**。 -> -> 每个`Server`进程需要有一个集群内唯一标志`MS_NODE_ID`,需要通过环境变量设置此字段。本部署教程中,此变量已在[脚本run_mobile_server.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/mobile/run_mobile_server.py)中设置。 - -## 启动集群 - -参考[示例](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/mobile),启动集群。参考示例关键目录结构如下: - -```text -mobile/ -├── config.json -├── finish_mobile.py -├── run_mobile_sched.py -├── run_mobile_server.py -├── src -│ └── model.py -└── test_mobile_lenet.py -``` - -- config.json:配置文件,用于安全能力配置,容灾等。 -- finish_mobile.py:由于Server集群为常驻进程,使用本文件手动退出集群。 -- run_mobile_sched.py:启动Scheduler。 -- run_mobile_server.py:启动Server。 -- model.py:网络模型。 -- test_mobile_lenet.py:训练脚本 - -1. 启动Scheduler - - `run_mobile_sched.py`是用于启动`Scheduler`的Python脚本,并支持通过`argparse`传参修改配置。执行指令的示例如下,代表启动本次联邦学习任务的`Scheduler`,其TCP端口为`6667`,联邦学习HTTP服务起始端口为`6668`,`Server`数量为`4`个,集群`Scheduler`管理端口为`11202`: - - ```sh - python run_mobile_sched.py --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --scheduler_manage_port=11202 --config_file_path=$PWD/config.json - ``` - -2. 启动Server - - `run_mobile_server.py`是用于启动若干`Server`的Python脚本,并支持通过`argparse`传参修改配置。执行指令的示例如下,代表启动本次联邦学习任务的`Server`,其TCP端口为`6667`,联邦学习HTTP服务起始端口为`6668`,`Server`数量为`4`个,联邦学习任务正常进行需要的端侧设备数量为`8`个: - - ```sh - python run_mobile_server.py --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --start_fl_job_threshold=8 --config_file_path=$PWD/config.json - ``` - - 以上指令将启动了4个`Server`进程,各`Server`进程的联邦学习服务端口依次为`6668`、`6669`、`6670`和`6671`,具体实现详见[脚本run_mobile_server.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/mobile/run_mobile_server.py)。 - - > 若只想在单机部署`Scheduler`以及`Server`,只需将`scheduler_ip`配置项修改为`127.0.0.1`即可。 - - 若想让`Server`分布式部署在不同物理节点,可以使用`local_server_num`参数,代表在**本节点**需要执行的`Server`进程数量: - - ```sh - # 在节点1启动3个Server进程 - python run_mobile_server.py --scheduler_ip={ip_address_node_1} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --start_fl_job_threshold=8 --local_server_num=3 --config_file_path=$PWD/config.json - ``` - - ```sh - # 在节点2启动1个Server进程 - python run_mobile_server.py --scheduler_ip={ip_address_node_2} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --start_fl_job_threshold=8 --local_server_num=1 --config_file_path=$PWD/config.json - ``` - - 若`Server`日志中包含以下内容: - - ```sh - Server started successfully. - ``` - - 则表明启动成功。 - - > 以上分布式部署的指令中,`server_num`均为4,这是因为该参数代表集群全局的`Server`数量,其不应随物理节点的数量而改变。对于不同节点上的`Server`而言,其无需感知各自的IP地址,集群的一致性保障和节点发现均由`Scheduler`完成。 - -3. 停止联邦学习 - 当前版本联邦学习集群为常驻进程,可执行`finish_mobile.py`脚本,以终止联邦学习服务。执行指令的示例如下,其中`scheduler_port`传参,需与启动服务器时的传参保持一致,代表停止此`Scheduler`对应的集群。 - - ```sh - python finish_mobile.py --scheduler_port=6667 - ``` - - 若console打印如下内容: - - ```sh - killed $PID1 - killed $PID2 - killed $PID3 - killed $PID4 - killed $PID5 - killed $PID6 - killed $PID7 - killed $PID8 - ``` - - 则表明停止服务成功。 - -## 弹性伸缩 - -MindSpore联邦学习框架支持`Server`的弹性伸缩,对外通过`Scheduler`管理端口提供`RESTful`服务,使得用户在不中断训练任务的情况下,对硬件资源进行动态调度。目前MindSpore的弹性伸缩仅支持水平伸缩(Scale Out/In),暂不支持垂直伸缩(Scale Up/Down)。在弹性伸缩场景下,`Server`进程数量将根据用户设置增加/减少。 - -以下示例介绍了如何通过RESTful原生接口,对控制集群扩容/缩容。 - -1. 扩容 - - 在集群启动后,进入部署scheduler节点的机器,向`Scheduler`发起扩容请求,可使用`curl`指令构造`RESTful`扩容请求,代表集群需要扩容2个`Server`节点: - - ```sh - curl -i -X POST \ - -H "Content-Type:application/json" \ - -d \ - '{ - "worker_num":0, - "server_num":2 - }' \ - 'http://127.0.0.1:11202/scaleout' - ``` - - 需要拉起`2`个新的`Server`进程,扩容`Server`的`node_id`不能与已有`Server`的`node_id`相同,并将`server_num`参数累加扩容的个数,从而保证全局组网信息的正确性,即扩容后,`server_num`的数量应为`6`,执行指令的示例如下: - - ```sh - python run_mobile_server.py --node_id=scale_node --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6672 --server_num=6 --start_fl_job_threshold=8 --local_server_num=2 --config_file_path=$PWD/config.json - ``` - - 该指令代表启动两个`Server`节点,其联邦学习服务端口分别为`6672`和`6673`,总`Server`数量为`6`。 - -2. 缩容 - - 在集群启动后,进入部署scheduler节点的机器,向`Scheduler`发起缩容请求。由于缩容需要对具体节点进行操作,因此需要先查询节点信息: - - ```sh - curl -i -X GET \ - 'http://127.0.0.1:11202/nodes' - ``` - - `Scheduler`将返回`json`格式的查询结果: - - ```json - { - "code": 0, - "message": "Get nodes info successful.", - "nodeIds": [ - { - "alive": "true", - "nodeId": "3", - "rankId": "3", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "0", - "rankId": "0", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "2", - "rankId": "2", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "1", - "rankId": "1", - "role": "SERVER" - }, - { - "alive": "true", - "nodeId": "20", - "rankId": "0", - "role": "SCHEDULER" - } - ] - } - ``` - - 选择`Rank3`和`Rank2`进行缩容: - - ```sh - curl -i -X POST \ - -H "Content-Type:application/json" \ - -d \ - '{ - "node_ids": ["2", "3"] - }' \ - 'http://127.0.0.1:11202/scalein' - ``` - -> - 在集群扩容/缩容成功后,训练任务会自动恢复,不需要用户进行额外干预。 -> -> - 可以通过集群管理工具(如Kubernetes)创建或者释放`Server`资源。 -> -> - 缩容后,被缩容节点进程不会退出,需要集群管理工具(如Kubernetes)释放`Server`资源或者执行`kill -15 $PID`来控制进程退出。请注意需要向`scheduler`节点查询集群状态,等待集群的状态置为`CLUSTER_READY`,才可以回收被缩容的节点。 - -## 容灾 - -在MindSpore联邦学习集群中某节点下线后,可以保持集群在线而不退出训练任务,在该节点重新被启动后,可以恢复训练任务。目前MindSpore暂时支持Server节点的容灾(Server 0除外)。 - -想要支持容灾,config_file_path指定的config.json配置文件需要添加如下字段: - -```json -{ - "recovery": { - "storage_type": 1, - "storge_file_path": "config.json" - } -} -``` - -- recovery:有此字段则代表需要支持容灾。 -- storage_type:持久化存储类型,目前只支持值为`1`,代表文件存储。 -- storage_file_path:容灾恢复文件路径。 - -节点重新启动的指令类似扩容指令,在节点被手动下线之后,执行如下指令: - -```sh -python run_mobile_server.py --scheduler_ip=192.168.216.124 --scheduler_port=6667 --fl_server_port=6673 --server_num=6 --start_fl_job_threshold=8 --local_server_num=1 --config_file_path=$PWD/config.json -``` - -此指令代表重新启动了`Server`,其联邦学习服务端口为`6673`。 - -> 在弹性伸缩命令下发成功后,在扩缩容业务执行完毕前,不支持容灾。 -> -> 容灾后,重新启动节点的`MS_NODE_ID`变量需要和异常退出的节点保持一致,以保证能够恢复组网。 - -## 安全 - -MindSpore联邦学习框架支持`Server`的SSL安全认证,要开启安全认证,需要在启动命令加上`enable_ssl=True`,config_file_path指定的config.json配置文件需要添加如下字段: - -```json -{ - "server_cert_path": "server.p12", - "crl_path": "", - "client_cert_path": "client.p12", - "ca_cert_path": "ca.crt", - "cert_expire_warning_time_in_day": 90, - "cipher_list": "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK", - "connection_num":10000 -} -``` - -- server_cert_path:服务端包含证书和密钥的密文的p12文件路径。 -- crl_path:吊销列表的文件。 -- client_cert_path:客户端包含证书和密钥的密文的p12文件路径。 -- ca_cert_path:根证书。 -- cipher_list:密码套件。 -- cert_expire_warning_time_in_day:证书过期的告警时间。 - -p12文件中的密钥为密文存储,在启动时需要传入密码,具体参数请参考Python API `mindspore.set_fl_context`中的`client_password`以及`server_password`字段。 diff --git a/docs/federated/docs/source_zh_cn/faq.md b/docs/federated/docs/source_zh_cn/faq.md deleted file mode 100644 index cf1d5be94e9a02f996aaa2e8aaecbea9311f726d..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/faq.md +++ /dev/null @@ -1,9 +0,0 @@ -# FAQ - - - -**Q: 请问如果集群组网不成功,怎么定位原因?** - -A: 请查看服务器的网络情况,譬如请查看防火墙是否禁止端口访问,请设置防火墙允许端口访问。 - -
    diff --git a/docs/federated/docs/source_zh_cn/federated_client.rst b/docs/federated/docs/source_zh_cn/federated_client.rst deleted file mode 100644 index 0bad6fed68b555024a6d849ab7049c6157640723..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/federated_client.rst +++ /dev/null @@ -1,8 +0,0 @@ -Federated-Client -================= - -.. toctree:: - :maxdepth: 1 - - cross_device - cross_silo diff --git a/docs/federated/docs/source_zh_cn/federated_install.md b/docs/federated/docs/source_zh_cn/federated_install.md deleted file mode 100644 index 267c512dfb9100aff134246994079079b58d12ca..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/federated_install.md +++ /dev/null @@ -1,17 +0,0 @@ -# 获取MindSpore Federated - - - -MindSpore Federated框架代码集成在云侧MindSpore和端侧MindSpore Lite框架中,因此需要分别获取MindSpore whl包和MindSpore Lite java安装包。其中,MindSpore Whl包负责云侧集群聚合训练,以及与Lite的通信。MindSpore Lite java安装包中包括两部分,一部分是MindSpore Lite训练安装包,负责模型的端侧本地训练,另一部分是Federated-Client安装包,负责模型的下发、加密以及与云侧MindSpore服务的交互。 - -## 获取MindSpore whl包 - -包括源码编译和下载发布版两种方式,支持x86 CPU、GPU CUDA等硬件平台,根据硬件平台类型,选择进行安装即可。MindSpore从1.3.0版本开始支持联邦学习。安装步骤可参考[MindSpore安装指南](https://www.mindspore.cn/install)。 - -## 获取MindSpore Lite java包 - -包括源码编译和下载发布版两种方式。MindSpore Lite从1.3.0版本开始支持联邦学习。目前,MindSpore Lite联邦学习功能只支持Linux和Android平台,且只支持CPU。安装步骤可参考[下载MindSpore Lite](https://www.mindspore.cn/lite/docs/zh-CN/master/use/downloads.html)和[编译MindSpore Lite](https://www.mindspore.cn/lite/docs/zh-CN/master/use/build.html)。 - -## Linux编译环境要求 - -目前源码编译只支持Linux,编译环境要求可参考[MindSpore源码编译](https://www.mindspore.cn/install)和[MindSpore Lite源码编译](https://www.mindspore.cn/lite/docs/zh-CN/master/use/build.html)。 diff --git a/docs/federated/docs/source_zh_cn/image_classification_application.md b/docs/federated/docs/source_zh_cn/image_classification_application.md deleted file mode 100644 index 6e4c6743a3bdbc4afdead09a4d47c93564a65c91..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/image_classification_application.md +++ /dev/null @@ -1,307 +0,0 @@ -# 实现一个端云联邦的图像分类应用(x86) - - - -根据参与客户端的类型,联邦学习可分为云云联邦学习(cross-silo)和端云联邦学习(cross-device)。在云云联邦学习场景中,参与联邦学习的客户端是不同的组织(例如,医疗或金融)或地理分布的数据中心,即在多个数据孤岛上训练模型。在端云联邦学习场景中,参与的客户端为大量的移动或物联网设备。本框架将介绍如何在MindSpore端云联邦框架上使用网络LeNet实现一个图片分类应用,并提供在x86环境中模拟启动多客户端参与联邦学习的相关教程。 - -在动手进行实践之前,确保你已经正确安装了MindSpore。如果没有,可以参考[MindSpore安装页面](https://www.mindspore.cn/install)完成安装。 - -## 准备工作 - -我们提供了可供用户直接使用的[联邦学习图像分类数据集FEMNIST](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/federated/3500_clients_bin.zip),以及`.ms`格式的[端侧模型文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/models/lenet_train.ms)。用户也可以根据实际需求,参考以下教程自行生成数据集和模型。 - -### 数据处理 - -本示例采用`leaf`数据集中的联邦学习数据集`FEMNIST`, 数据集的具体获取方式可参考文档[端云联邦学习图像分类数据集处理](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/client/image_classfication_dataset_process.md#)。 - -用户也可自行定义数据集,注意,数据集必须为`.bin`格式文件,且文件中数据维度必须与网络的输入维度保持一致。 - -### 生成端侧模型文件 - -1. 定义网络和训练过程 - - 具体网络和训练过程的定义可参考[进阶案例:手写数字识别](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/lenet_mnist.html#创建模型)。 - - 我们提供了网络定义文件[model.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/mobile/src/model.py)和训练过程定义文件[run_export_lenet.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/cloud/run_export_lenet.py)供大家参考。 - -2. 将模型导出为MindIR格式文件。 - - 运行脚本`run_export_lenet.py`获取MindIR格式模型文件,其中代码片段如下: - - ```python - import mindspore as ms - ... - - parser = argparse.ArgumentParser(description="export mindir for lenet") - parser.add_argument("--device_target", type=str, default="CPU") - parser.add_argument("--mindir_path", type=str, default="lenet_train.mindir") # MindIR格式文件路径 - ... - - for _ in range(epoch): - data = Tensor(np.random.rand(32, 3, 32, 32).astype(np.float32)) - label = Tensor(np.random.randint(0, 61, (32)).astype(np.int32)) - loss = train_network(data, label).asnumpy() - losses.append(loss) - ms.export(train_network, data, label, file_name= mindir_path, file_format='MINDIR') # 在训练过程中添加export语句获取MindIR格式模型文件 - print(losses) - ``` - - 具体运行指令如下: - - ```sh - python run_export_lenet.py --mindir_path="ms/lenet/lenet_train.mindir" - ``` - - 参数`--mindir_path`用于设置生成的MindIR格式文件路径。 - -3. 将MindIR文件转化为联邦学习端侧框架可用的ms文件。 - - 模型转换可参考[训练模型转换教程](https://www.mindspore.cn/lite/docs/zh-CN/master/use/converter_train.html )。 - - 模型转换示例如下: - - 假设待转换的模型文件为`lenet_train.mindir`,执行如下转换命令: - - ```sh - ./converter_lite --fmk=MINDIR --trainModel=true --modelFile=lenet_train.mindir --outputFile=lenet_train - ``` - - 转换成功输出如下: - - ```sh - CONVERTER RESULT SUCCESS:0 - ``` - - 这表明MindSpore模型成功转换为MindSpore端侧模型,并生成了新文件`lenet_train.ms`。如果转换失败输出如下: - - ```sh - CONVERT RESULT FAILED: - ``` - - 将生成的`.ms`格式的模型文件放在某个路径上,在调用联邦学习接口时可设置`FLParameter.trainModelPath`为该模型文件的路径。 - -## 模拟启动多客户端参与联邦学习 - -1. 为客户端准备好模型文件。 - - 由于真实场景一个客户端只包含一个.ms格式的模型文件,在模拟场景中,需要拷贝多份.ms文件,并按照`lenet_train{i}.ms`格式进行命名。其中i代表客户端编号,由于`run_client_x86.py`中代码逻辑,i需要设置为`0, 1, 2, 3, 4, 5 .....`等数字。每个客户端各使用一份.ms文件。 - - 可参考下面脚本,对原始.ms文件进行拷贝和命名: - - ```python - import shutil - import os - - def copy_file(raw_path,new_path,copy_num): - # Copy the specified number of files from the raw path to the new path - for i in range(copy_num): - file_name = "lenet_train" + str(i) + ".ms" - new_file_path = os.path.join(new_path, file_name) - shutil.copy(raw_path ,new_file_path) - print('====== copying ',i, ' file ======') - print("the number of copy .ms files: ", len(os.listdir(new_path))) - - if __name__ == "__main__": - raw_path = "lenet_train.ms" - new_path = "ms/lenet" - num = 8 - copy_file(raw_path, new_path, num) - ``` - - 其中`raw_path`设置原始.ms文件路径,`new_path`设置拷贝的.ms文件需要放置的路径,`num`设置拷贝的份数,一般需要模拟启动客户端的数量。 - - 比如以上脚本中设置,在路径`ms/lenet`中生成了供8个客户端使用的.ms文件,其目录结构如下: - - ```sh - ms/lenet - ├── lenet_train0.ms # 客户端0使用的.ms文件 - ├── lenet_train1.ms # 客户端1使用的.ms文件 - ├── lenet_train2.ms # 客户端2使用的.ms文件 - │ - │ ...... - │ - └── lenet_train7.ms # 客户端4使用的.ms文件 - ``` - -2. 启动云侧服务 - - 用户可先参考[云侧部署教程](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_server.html)部署云侧环境,并启动云侧服务。 - -3. 启动客户端。 - - 启动客户端之前请先参照端侧部署教程中[x86环境部分](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_client.html)进行端侧环境部署。 - - 我们框架提供了三个类型的联邦学习接口供用户调用,具体的接口介绍可参考[API文件](https://www.mindspore.cn/federated/docs/zh-CN/master/java_api_syncfljob.html): - - - `SyncFLJob.flJobRun()` - - 用于启动客户端参与到联邦学习训练任务中,并获取最终训练好的聚合模型。 - - - `SyncFLJob.modelInfer()` - - 用于获取给定数据集的推理结果。 - - - `SyncFLJob.getModel()` - - 用于获取云侧最新的模型。 - - 待云侧服务启动成功之后,可编写一个Python脚本,调用联邦学习框架jar包`mindspore-lite-java-flclient.jar` 和模型脚本对应的jar包`quick_start_flclient.jar`(可参考[端侧部署中编译出包流程](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_client.html)获取)来模拟启动多客户端参与联邦学习任务。 - - 我们提供了参考脚本[run_client_x86.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/client/run_client_x86.py),可通过相关参数的设置,来启动不同的联邦学习接口。 - - 以LeNet网络为例,`run_client_x86.py`脚本中部分入参含义如下,用户可根据实际情况进行设置: - - - `--jarPath` - - 设置联邦学习jar包路径,x86环境联邦学习jar包获取可参考[端侧部署中编译出包流程](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_client.html)。 - - 注意,请确保该路径下仅包含该jar包。例如,在上面示例代码中,`--jarPath`设置为`"libs/jarX86/mindspore-lite-java-flclient.jar"`,则需确保`jarX86`文件夹下仅包含一个jar包`mindspore-lite-java-flclient.jar`。 - - - `--case_jarPath` - - 设置模型脚本所生成的jar包`quick_start_flclient.jar`的路径,x86环境联邦学习jar包获取可参考[端侧部署中编译出包流程](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_client.html)。 - - 注意,请确保该路径下仅包含该jar包。例如,在上面示例代码中,`--case_jarPath`设置为`"case_jar/quick_start_flclient.jar"`,则需确保`case_jar`文件夹下仅包含一个jar包`quick_start_flclient.jar`。 - - - `--train_dataset` - - 训练数据集root路径,LeNet图片分类任务在该root路径中存放的是每个客户端的训练data.bin文件与label.bin文件,例如`data/femnist/3500_clients_bin/`。 - - - `--flName` - - 联邦学习使用的模型脚本包路径。我们提供了两个类型的模型脚本供大家参考([有监督情感分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert)、[LeNet图片分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)),对于有监督情感分类任务,该参数可设置为所提供的脚本文件[AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java) 的包路径`com.mindspore.flclient.demo.albert.AlbertClient`;对于LeNet图片分类任务,该参数可设置为所提供的脚本文件[LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java) 的包路径`com.mindspore.flclient.demo.lenet.LenetClient`。同时,用户可参考这两个类型的模型脚本,自定义模型脚本,然后将该参数设置为自定义的模型文件ModelClient.java(需继承于类[Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java))的包路径即可。 - - - `--train_model_path` - - 设置联邦学习使用的训练模型路径,为上面教程中拷贝的多份.ms文件所存放的目录,比如`ms/lenet`,必须为绝对路径。 - - - `--train_ms_name` - - 设置多客户端训练模型文件名称相同部分,模型文件名需为格式`{train_ms_name}1.ms`,`{train_ms_name}2.ms`, `{train_ms_name}3.ms` 等。 - - - `--domain_name` - - 用于设置端云通信url,目前,可支持https和http通信,对应格式分别为:https://......、http://......,当`if_use_elb`设置为true时,格式必须为:https://127.0.0.1:6666 或者http://127.0.0.1:6666 ,其中`127.0.0.1`对应提供云侧服务的机器ip(即云侧参数`--scheduler_ip`),`6666`对应云侧参数`--fl_server_port`。 - - 注意1,当该参数设置为`http://......`时代表使用HTTP通信,可能会存在通信安全风险,请知悉。 - - 注意2,当该参数设置为`https://......`代表使用HTTPS通信。此时必须进行SSL证书认证,需要通过参数`--cert_path`设置证书路径。 - - - `--task` - - 用于设置本此启动的任务类型,为`train`代表启动训练任务,为`inference`代表启动多条数据推理任务,为`getModel`代表启动获取云侧模型的任务,设置其他字符串代表启动单条数据推理任务。默认为`train`。由于初始的模型文件(.ms文件)是未训练过的,建议先启动训练任务,待训练完成之后,再启动推理任务(注意两次启动的`client_num`保持一致,以保证`inference`使用的模型文件与`train`保持一致)。 - - - `--batch_size` - - 设置联邦学习训练和推理时使用的单步训练样本数,即batch size。需与模型的输入数据的batch size保持一致。 - - - `--client_num` - - 设置client数量, 与启动server端时的`start_fl_job_cnt`保持一致,真实场景不需要此参数。 - - 若想进一步了解`run_client_x86.py`脚本中其他参数含义,可参考脚本中注释部分。 - - 联邦学习接口基本启动指令示例如下: - - ```sh - python run_client_x86.py --jarPath="libs/jarX86/mindspore-lite-java-flclient.jar" --case_jarPath="case_jar/quick_start_flclient.jar" --train_dataset="data/femnist/3500_clients_bin/" --test_dataset="null" --vocal_file="null" --ids_file="null" --flName="com.mindspore.flclient.demo.lenet.LenetClient" --train_model_path="ms/lenet/" --infer_model_path="ms/lenet/" --train_ms_name="lenet_train" --infer_ms_name="lenet_train" --domain_name="http://127.0.0.1:6666" --cert_path="certs/https_signature_certificate/client/CARoot.pem" --use_elb="true" --server_num=4 --client_num=8 --thread_num=1 --server_mode="FEDERATED_LEARNING" --batch_size=32 --task="train" - ``` - - 注意,启动指令中涉及路径的必须给出绝对路径。 - - 以上指令代表启动8个客户端参与联邦学习训练任务,若启动成功,会在当前文件夹生成8个客户端对应的日志文件,查看日志文件内容可了解每个客户端的运行情况: - - ```text - ./ - ├── client_0 - │ └── client.log # 客户端0的日志文件 - │ ...... - └── client_7 - └── client.log # 客户端4的日志文件 - ``` - - 针对不同的接口和场景,只需根据参数含义,修改特定参数值即可,比如: - - - 启动联邦学习训练任务SyncFLJob.flJobRun() - - 当`基本启动指令`中 `--task`设置为`train`时代表启动该任务。 - - 可通过指令`grep -r "average loss:" client_0/client.log`查看`client_0`在训练过程中每个epoch的平均loss,会有类似如下打印: - - ```sh - INFO: ----------epoch:0,average loss:4.1258564 ---------- - ...... - ``` - - 也可通过指令`grep -r "evaluate acc:" client_0/client.log`查看`client_0`在每个联邦学习迭代中聚合后模型的验证精度,会有类似如下打印: - - ```sh - INFO: [evaluate] evaluate acc: 0.125 - ...... - ``` - - - 启动推理任务SyncFLJob.modelInference() - - 当`基本启动指令`中 `--task`设置为`inference`时代表启动该任务。 - - 可通过指令`grep -r "the predicted labels:" client_0/client.log`查看`client_0`的推理结果: - - ```sh - INFO: [model inference] the predicted labels: [0, 0, 0, 1, 1, 1, 2, 2, 2] - ...... - ``` - - - 启动获取云侧最新模型任务SyncFLJob.getModel() - - 当`基本启动指令`中 `--task`设置为`getModel`时代表启动该任务。 - - 在日志文件中若有如下内容代表获取云侧最新模型成功: - - ```sh - INFO: [getModel] get response from server ok! - ``` - -4. 关闭客户端进程。 - - 可参考[finish.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/client/finish.py)脚本,具体如下: - - ```python - import argparse - import subprocess - parser = argparse.ArgumentParser(description="Finish client process") - # The parameter `--kill_tag` is used to search for the keyword to kill the client process. - parser.add_argument("--kill_tag", type=str, default="mindspore-lite-java-flclient") - args, _ = parser.parse_known_args() - kill_tag = args.kill_tag - cmd = "pid=`ps -ef|grep " + kill_tag - cmd += " |grep -v \"grep\" | grep -v \"finish\" |awk '{print $2}'` && " - cmd += "for id in $pid; do kill -9 $id && echo \"killed $id\"; done" - subprocess.call(['bash', '-c', cmd]) - ``` - - 关闭客户端指令如下: - - ```sh - python finish.py --kill_tag=mindspore-lite-java-flclient - ``` - - 其中参数`--kill_tag`用于搜索该关键字对客户端进程进行kill,只需要设置`--jarPath`中的特殊关键字即可。默认为`mindspore-lite-java-flclient`,即联邦学习jar包名。 - 用户可通过指令`ps -ef |grep "mindspore-lite-java-flclient"`查看进程是否还存在。 - -5. 50个客户端参与联邦学习训练任务实验结果。 - - 目前`3500_clients_bin`文件夹中包含3500个客户端的数据,本脚本最多可模拟3500个客户端参与联邦学习。 - - 下图给出了50个客户端(设置`server_num`为16)进行联邦学习的测试集精度: - - ![lenet_50_clients_acc](images/lenet_50_clients_acc.png) - - 其中联邦学习总迭代数为100,客户端本地训练epoch数为20,batchSize设置为32。 - - 图中测试精度指对于每个联邦学习迭代,各客户端测试集在云侧聚合后的模型上的精度。 - - AVG:对于每个联邦学习迭代,50个客户端测试集精度的平均值。 - - TOP5:对于每个联邦学习迭代,测试集精度最高的5个客户端的精度平均值。 - - LOW5:对于每个联邦学习迭代,测试集精度最低的5个客户端的精度平均值。 diff --git a/docs/federated/docs/source_zh_cn/image_classification_application_in_cross_silo.md b/docs/federated/docs/source_zh_cn/image_classification_application_in_cross_silo.md deleted file mode 100644 index ca0d7a6724d9d01b4b632021af87c297d64014e9..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/image_classification_application_in_cross_silo.md +++ /dev/null @@ -1,323 +0,0 @@ -# 实现一个云云联邦的图像分类应用(x86) - - - -根据参与客户端的类型,联邦学习可分为云云联邦学习(cross-silo)和端云联邦学习(cross-device)。在云云联邦学习场景中,参与联邦学习的客户端是不同的组织(例如,医疗或金融)或地理分布的数据中心,即在多个数据孤岛上训练模型。在端云联邦学习场景中,参与的客户端为大量的移动或物联网设备。本框架将介绍如何在MindSpore云云联邦框架上,使用网络LeNet实现一个图片分类应用。 - -启动云云联邦的图像分类应用的完整脚本可参考[这里](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/cross_silo_femnist)。 - -## 下载数据集 - -本示例采用[leaf数据集](https://github.com/TalwalkarLab/leaf)中的联邦学习数据集`FEMNIST`, 该数据集包含62个不同类别的手写数字和字母(数字0~9、26个小写字母、26个大写字母),图像大小为`28 x 28`像素,数据集包含3500个用户的手写数字和字母(最多可模拟3500个客户端参与联邦学习),总数据量为805263,平均每个用户包含数据量为226.83,所有用户数据量的方差为88.94。 - -可参考文档[端云联邦学习图像分类数据集处理](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_device_lenet/client/image_classfication_dataset_process.md#)中步骤1~7获取图片形式的3500个用户数据集`3500_client_img`。 - -由于原始3500个用户数据集中每个用户数据量比较少,在云云联邦任务中会收敛太快,无法明显体现云云联邦框架的收敛效果,下面提供一个参考脚本,将指定数量的用户数据集合并为一个用户,以增加参与云云联邦任务的单个用户数据量,更好地模拟云云联邦框架实验。 - -```python -import os -import shutil - - -def mkdir(path): - if not os.path.exists(path): - os.mkdir(path) - - -def combine_users(root_data_path, new_data_path, raw_user_num, new_user_num): - mkdir(new_data_path) - user_list = os.listdir(root_data_path) - num_per_user = int(raw_user_num / new_user_num) - for i in range(new_user_num): - print( - "========================== combine the raw {}~{} users to the new user: dataset_{} ==========================".format( - i * num_per_user, i * num_per_user + num_per_user - 1, i)) - new_user = "dataset_" + str(i) - new_user_path = os.path.join(new_data_path, new_user) - mkdir(new_user_path) - for j in range(num_per_user): - index = i * new_user_num + j - user = user_list[index] - user_path = os.path.join(root_data_path, user) - tags = os.listdir(user_path) - print("------------- process the raw user: {} -------------".format(user)) - for t in tags: - tag_path = os.path.join(user_path, t) - label_list = os.listdir(tag_path) - new_tag_path = os.path.join(new_user_path, t) - mkdir(new_tag_path) - for label in label_list: - label_path = os.path.join(tag_path, label) - img_list = os.listdir(label_path) - new_label_path = os.path.join(new_tag_path, label) - mkdir(new_label_path) - - for img in img_list: - img_path = os.path.join(label_path, img) - new_img_name = user + "_" + img - new_img_path = os.path.join(new_label_path, new_img_name) - shutil.copy(img_path, new_img_path) - -if __name__ == "__main__": - root_data_path = "cross_silo_femnist/femnist/3500_clients_img" - new_data_path = "cross_silo_femnist/femnist/35_7_client_img" - raw_user_num = 35 - new_user_num = 7 - combine_users(root_data_path, new_data_path, raw_user_num, new_user_num) -``` - -其中`root_data_path`为原始3500个用户数据集路径,`new_data_path`为合并后数据集的路径,`raw_user_num`指定用于合并的用户数据集总数(需<=3500),`new_user_num`用于设置将原始数据集合并为多少个用户。如示例代码中将从`cross_silo_femnist/femnist/3500_clients_img`中选取前35个用户,合并为7个用户数据集后存放在路径`cross_silo_femnist/femnist/35_7_client_img`(合并后的7个用户,每个用户包含原始的5个用户数据集)。 - -如下打印代表合并数据集成功: - -```sh -========================== combine the raw 0~4 users to the new user: dataset_0 ========================== -------------- process the raw user: f1798_42 ------------- -------------- process the raw user: f2149_81 ------------- -------------- process the raw user: f4046_46 ------------- -------------- process the raw user: f1093_13 ------------- -------------- process the raw user: f1124_24 ------------- -========================== combine the raw 5~9 users to the new user: dataset_1 ========================== -------------- process the raw user: f0586_11 ------------- -------------- process the raw user: f0721_31 ------------- -------------- process the raw user: f3527_33 ------------- -------------- process the raw user: f0146_33 ------------- -------------- process the raw user: f1272_09 ------------- -========================== combine the raw 10~14 users to the new user: dataset_2 ========================== -------------- process the raw user: f0245_40 ------------- -------------- process the raw user: f2363_77 ------------- -------------- process the raw user: f3596_19 ------------- -------------- process the raw user: f2418_82 ------------- -------------- process the raw user: f2288_58 ------------- -========================== combine the raw 15~19 users to the new user: dataset_3 ========================== -------------- process the raw user: f2249_75 ------------- -------------- process the raw user: f3681_31 ------------- -------------- process the raw user: f3766_48 ------------- -------------- process the raw user: f0537_35 ------------- -------------- process the raw user: f0614_14 ------------- -========================== combine the raw 20~24 users to the new user: dataset_4 ========================== -------------- process the raw user: f2302_58 ------------- -------------- process the raw user: f3472_19 ------------- -------------- process the raw user: f3327_11 ------------- -------------- process the raw user: f1892_07 ------------- -------------- process the raw user: f3184_11 ------------- -========================== combine the raw 25~29 users to the new user: dataset_5 ========================== -------------- process the raw user: f1692_18 ------------- -------------- process the raw user: f1473_30 ------------- -------------- process the raw user: f0909_04 ------------- -------------- process the raw user: f1956_19 ------------- -------------- process the raw user: f1234_26 ------------- -========================== combine the raw 30~34 users to the new user: dataset_6 ========================== -------------- process the raw user: f0031_02 ------------- -------------- process the raw user: f0300_24 ------------- -------------- process the raw user: f4064_46 ------------- -------------- process the raw user: f2439_77 ------------- -------------- process the raw user: f1717_16 ------------- -``` - -文件夹 `cross_silo_femnist/femnist/35_7_client_img`目录结构如下: - -```text -35_7_client_img # 将FeMnist数据集中35个用户合并为7个客户端数据(各包含5个用户数据) -├── dataset_0 # 客户端0的数据集 -│ ├── train # 训练数据集 -│ │ ├── 0 # 存放类别0对应的图片数据 -│ │ ├── 1 # 存放类别1对应的图片数据 -│ │ │ ...... -│ │ └── 61 # 存放类别61对应的图片数据 -│ └── test # 测试数据集,目录结构同train -│ ...... -│ -└── dataset_6 # 客户端6的数据集 - ├── train # 训练数据集 - │ ├── 0 # 存放类别0对应的图片数据 - │ ├── 1 # 存放类别1对应的图片数据 - │ │ ...... - │ └── 61 # 存放类别61对应的图片数据 - └── test # 测试数据集,目录结构同train -``` - -## 定义网络 - -我们选择相对简单的LeNet网络。LeNet网络不包括输入层的情况下,共有7层:2个卷积层、2个下采样层(池化层)、3个全连接层。每层都包含不同数量的训练参数,如下图所示: - -![LeNet5](images/LeNet_5.jpg) - -> 更多的LeNet网络的介绍不在此赘述,希望详细了解LeNet网络,可以查询。 - -本任务使用的网络可参考脚本[test_cross_silo_femnist.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_silo_femnist/test_cross_silo_femnist.py)。 - -若想具体了解MindSpore中网络定义流程可参考[进阶案例:手写数字识别](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/lenet_mnist.html#创建模型)。 - -## 定义训练过程 - -本任务使用的训练过程可参考脚本[test_cross_silo_femnist.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_silo_femnist/test_cross_silo_femnist.py)。 - -脚本中字典`ctx`中参数`enable_fl`用于设置是否启动联邦学习训练流程,为`true`代表启动联邦学习流程,为`false`代表启动普通训练流程,其他参数可以根据实际情况进行设置。 - -## 启动云云联邦任务 - -### 安装MindSpore - -包括源码和下载发布版两种方式,支持CPU、GPU硬件平台,根据硬件平台选择安装即可。安装步骤可参考[MindSpore安装指南](https://www.mindspore.cn/install)。 - -目前联邦学习框架只支持Linux环境中部署,cross-silo联邦学习框架需要MindSpore版本号>=1.5.0。 - -### 启动任务 - -参考[示例](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/cross_silo_femnist),启动集群。参考示例目录结构如下: - -```text -cross_silo_femnist/ -├── config.json # 配置文件 -├── finish_cross_silo_femnist.py # 关闭云云联邦任务脚本 -├── run_cross_silo_femnist_sched.py # 启动云云联邦scheduler脚本 -├── run_cross_silo_femnist_server.py # 启动云云联邦server脚本 -├── run_cross_silo_femnist_worker.py # 启动云云联邦worker脚本 -└── test_cross_silo_femnist.py # 客户端使用的训练脚本 -``` - -1. 启动Scheduler - - `run_cross_silo_femnist_sched.py`是为用户启动`Scheduler`而提供的Python脚本,并支持通过`argparse`传参修改配置。执行指令如下,代表启动本次联邦学习任务的`Scheduler`,其TCP端口为`6667`,联邦学习HTTP服务端口为`6668`,`Server`数量为`4`个,集群`Scheduler`管理端口为`11202`,`--config_file_path`用于设置配置文件路径,`--dataset_path`用于设置数据集绝对路径: - - ```sh - python run_cross_silo_femnist_sched.py --scheduler_ip=10.113.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=7 --scheduler_manage_port=11202 --config_file_path=$PWD/config.json --dataset_path=$PWD/femnist/35_7_client_img - ``` - - 打印如下代表启动成功: - - ```sh - [INFO] PS(631,2b316a813700,python):2021-08-31-19:49:42.784.715 [mindspore/ccsrc/ps/core/communicator/http_request_handler.cc:92] Run] Start http server! - [INFO] PS(631,2b3084633a80,python):2021-08-31-19:49:42.796.904 [mindspore/ccsrc/ps/core/scheduler_node.cc:97] Initialize] [Scheduler start]: 2. The node role is:SCHEDULER, the node id is:e4b3c983-6d0c-470b-b487-1a247af97575 create a tcp server. - [INFO] PS(631,2b316a411700,python):2021-08-31-19:49:42.796.929 [mindspore/ccsrc/ps/core/scheduler_node.cc:129] operator()] The scheduler node start a tcp server! - [INFO] PS(631,2b3084633a80,python):2021-08-31-19:49:42.796.935 [mindspore/ccsrc/ps/core/scheduler_node.cc:410] StartUpdateClusterStateTimer] [Scheduler start]: 3. The scheduler start a heartbeat timer! - [INFO] PS(631,2b316a411700,python):2021-08-31-19:49:42.796.979 [mindspore/ccsrc/ps/core/communicator/tcp_server.cc:192] Start] Start tcp server! - ``` - -2. 启动Server - - `run_cross_silo_femnist_server.py`是为用户启动若干`Server`而提供的Python脚本,并支持通过`argparse`传参修改配置。执行指令如下,代表启动本次联邦学习任务的`Server`,其TCP端口为`6667`,联邦学习HTTP服务起始端口为`6668`,`Server`数量为`4`个,联邦学习任务正常进行需要的`worker`数量为`7`个: - - ```sh - python run_cross_silo_femnist_server.py --scheduler_ip=10.113.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=7 --start_fl_job_threshold=7 --update_model_ratio=1 --fl_iteration_num=20 --start_fl_job_time_window=30000 --update_model_time_window=30000 --config_file_path=$PWD/config.json --dataset_path=$PWD/femnist/35_7_client_img - ``` - - 以上指令等价于启动了4个`Server`进程,每个`Server`的联邦学习服务端口分别为`6668`、`6669`、`6670`和`6671`,具体实现详见[脚本run_cross_silo_femnist_server.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_silo_femnist/run_cross_silo_femnist_server.py)。 - - > 若只想在单机部署`Scheduler`以及`Server`,只需将`scheduler_ip`配置项修改为`127.0.0.1`即可。 - - 若想让`Server`分布式部署在不同物理节点,可以使用`local_server_num`参数,代表在**本节点**需要执行的`Server`进程数量: - - ```sh - # 在节点1启动3个Server进程 - python run_cross_silo_femnist_server.py --scheduler_ip={ip_address_node_1} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=7 --start_fl_job_threshold=7 --update_model_ratio=1 --fl_iteration_num=20 --start_fl_job_time_window=30000 --update_model_time_window=30000 --config_file_path=$PWD/config.json --dataset_path=$PWD/femnist/35_7_client_img --local_server_num=3 - ``` - - ```sh - # 在节点2启动1个Server进程 - python run_cross_silo_femnist_server.py --scheduler_ip={ip_address_node_2} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=7 --start_fl_job_threshold=7 --update_model_ratio=1 --fl_iteration_num=20 --start_fl_job_time_window=30000 --update_model_time_window=30000 --config_file_path=$PWD/config.json --dataset_path=$PWD/femnist/35_7_client_img --local_server_num=1 - ``` - -3. 启动Worker - - `run_cross_silo_femnist_worker.py`是为用户启动若干`worker`而提供的Python脚本,并支持通过`argparse`传参修改配置。执行指令如下,代表启动本次联邦学习任务的`worker`,联邦学习任务正常进行需要的`worker`数量为`7`个: - - ```sh - python run_cross_silo_femnist_worker.py --scheduler_ip=10.113.216.40 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=7 --fl_iteration_num=20 --client_epoch_num=1 --config_file_path=$PWD/config.json --dataset_path=$PWD/femnist/35_7_client_img - ``` - -当执行以上三个指令之后,进入当前目录下`worker_0`文件夹,通过指令`grep -rn "test acc" *`查看`worker_0`日志,可看到如下类似打印: - -```sh -local epoch: 0, loss: 3.787421340711655, trian acc: 0.05342741935483871, test acc: 0.075 -``` - -则说明云云联邦启动成功,`worker_0`正在训练,其他worker可通过类似方式查看。 - -以上脚本中参数配置说明请参考[API文档](https://www.mindspore.cn/federated/docs/zh-CN/master/federated_server.html#mindspore.set_fl_context)。 - -### 日志查看 - -成功启动任务之后,会在当前目录`cross_silo_femnist`下生成相应日志文件,日志文件目录结构如下: - -```text -cross_silo_femnist -├── scheduler -│ └── scheduler.log # 运行scheduler过程中打印日志 -├── server_0 -│ └── server.log # server_0运行过程中打印日志 -├── server_1 -│ └── server.log # server_1运行过程中打印日志 -├── server_2 -│ └── server.log # server_2运行过程中打印日志 -├── server_3 -│ └── server.log # server_3运行过程中打印日志 -├── worker_0 -│ ├── ckpt # 存放worker_0在每个联邦学习迭代结束时获取的聚合后的模型ckpt -│ │ ├── 0-fl-ms-bs32-0epoch.ckpt -│ │ ├── 0-fl-ms-bs32-1epoch.ckpt -│ │ │ -│ │ │ ...... -│ │ │ -│ │ └── 0-fl-ms-bs32-19epoch.ckpt -│ └── worker.log # 记录worker_0参与联邦学习任务过程中输出日志 -└── worker_1 - ├── ckpt # 存放worker_1在每个联邦学习迭代结束时获取的聚合后的模型ckpt - │ ├── 1-fl-ms-bs32-0epoch.ckpt - │ ├── 1-fl-ms-bs32-1epoch.ckpt - │ │ - │ │ ...... - │ │ - │ └── 1-fl-ms-bs32-19epoch.ckpt - └── worker.log # 记录worker_1参与联邦学习任务过程中输出日志 -``` - -### 关闭任务 - -若想中途退出,则可用以下指令: - -```sh -python finish_cross_silo_femnist.py --scheduler_port=6667 -``` - -或者等待训练任务结束之后集群会自动退出,不需要手动关闭。 - -### 实验结果 - -- 使用数据: - - 上面`下载数据集`部分生成的`35_7_client_img/`数据集 - -- 客户端本地训练epoch数:20 - -- 云云联邦学习总迭代数: 20 - -- 实验结果(每个迭代聚合后模型在客户端的测试集上精度) - -`worker_0`测试结果: - -```sh -worker_0/worker.log:7409:local epoch: 0, loss: 3.787421340711655, trian acc: 0.05342741935483871, test acc: 0.075 -worker_0/worker.log:14419:local epoch: 1, loss: 3.725699281115686, trian acc: 0.05342741935483871, test acc: 0.075 -worker_0/worker.log:21429:local epoch: 2, loss: 3.5285709657335795, trian acc: 0.19556451612903225, test acc: 0.16875 -worker_0/worker.log:28439:local epoch: 3, loss: 3.0393165519160608, trian acc: 0.4889112903225806, test acc: 0.4875 -worker_0/worker.log:35449:local epoch: 4, loss: 2.575952764115026, trian acc: 0.6854838709677419, test acc: 0.60625 -worker_0/worker.log:42459:local epoch: 5, loss: 2.2081101375296512, trian acc: 0.7782258064516129, test acc: 0.6875 -worker_0/worker.log:49470:local epoch: 6, loss: 1.9229739431736557, trian acc: 0.8054435483870968, test acc: 0.69375 -worker_0/worker.log:56480:local epoch: 7, loss: 1.7005576549999293, trian acc: 0.8296370967741935, test acc: 0.65625 -worker_0/worker.log:63490:local epoch: 8, loss: 1.5248727620766704, trian acc: 0.8407258064516129, test acc: 0.6375 -worker_0/worker.log:70500:local epoch: 9, loss: 1.3838803705352127, trian acc: 0.8568548387096774, test acc: 0.7 -worker_0/worker.log:77510:local epoch: 10, loss: 1.265225578921041, trian acc: 0.8679435483870968, test acc: 0.7125 -worker_0/worker.log:84520:local epoch: 11, loss: 1.167484122101638, trian acc: 0.8659274193548387, test acc: 0.70625 -worker_0/worker.log:91530:local epoch: 12, loss: 1.082880981700859, trian acc: 0.8770161290322581, test acc: 0.65625 -worker_0/worker.log:98540:local epoch: 13, loss: 1.0097520119572772, trian acc: 0.8840725806451613, test acc: 0.64375 -worker_0/worker.log:105550:local epoch: 14, loss: 0.9469810053708015, trian acc: 0.9022177419354839, test acc: 0.7 -worker_0/worker.log:112560:local epoch: 15, loss: 0.8907848935604703, trian acc: 0.9022177419354839, test acc: 0.6625 -worker_0/worker.log:119570:local epoch: 16, loss: 0.8416629644123349, trian acc: 0.9082661290322581, test acc: 0.70625 -worker_0/worker.log:126580:local epoch: 17, loss: 0.798475691030866, trian acc: 0.9122983870967742, test acc: 0.70625 -worker_0/worker.log:133591:local epoch: 18, loss: 0.7599438544427897, trian acc: 0.9243951612903226, test acc: 0.6875 -worker_0/worker.log:140599:local epoch: 19, loss: 0.7250227383907605, trian acc: 0.9294354838709677, test acc: 0.7125 -``` - -其他客户端的测试结果基本相同,不再一一列出。 \ No newline at end of file diff --git a/docs/federated/docs/source_zh_cn/images/LeNet_5.jpg b/docs/federated/docs/source_zh_cn/images/LeNet_5.jpg deleted file mode 100644 index 7894b0e181d965c5e9cbba91fe240c1890d37bda..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/LeNet_5.jpg and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/create_android_project.png b/docs/federated/docs/source_zh_cn/images/create_android_project.png deleted file mode 100644 index a519264c4158fba67eb1ff5f5fbc3eae65b32363..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/create_android_project.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/cross-silo_fastrcnn-2workers-loss.png b/docs/federated/docs/source_zh_cn/images/cross-silo_fastrcnn-2workers-loss.png deleted file mode 100644 index c8be83d387fc0df853616dca972e169dfe8e4b31..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/cross-silo_fastrcnn-2workers-loss.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/download_compression_client.png b/docs/federated/docs/source_zh_cn/images/download_compression_client.png deleted file mode 100644 index 7953b4579f3b31210b4b0556828a18652d27d6ae..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/download_compression_client.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/download_compression_server.png b/docs/federated/docs/source_zh_cn/images/download_compression_server.png deleted file mode 100644 index 6e77f1daf39e7c444b2744c7fb0e1c16fd7006ef..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/download_compression_server.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/federated_cn.png b/docs/federated/docs/source_zh_cn/images/federated_cn.png deleted file mode 100644 index 7c6a040c57d87df5ecdc5fce318885d924e2e625..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/federated_cn.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/lenet_50_clients_acc.png b/docs/federated/docs/source_zh_cn/images/lenet_50_clients_acc.png deleted file mode 100644 index c1282811f7161d77ec2ea563d96983ef293dbf43..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/lenet_50_clients_acc.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/mindspore_federated_networking.png b/docs/federated/docs/source_zh_cn/images/mindspore_federated_networking.png deleted file mode 100644 index 95865169bf5802e43a6ab2882912ff2ebce32bb1..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/mindspore_federated_networking.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/start_android_project.png b/docs/federated/docs/source_zh_cn/images/start_android_project.png deleted file mode 100644 index 3a9336add10acbbef60dc429b8a3bad1ca198c38..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/start_android_project.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/upload_compression_client.png b/docs/federated/docs/source_zh_cn/images/upload_compression_client.png deleted file mode 100644 index bf7f72cec5c0e8d4c036c2c2a5e71861da3e0abe..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/upload_compression_client.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/upload_compression_server.png b/docs/federated/docs/source_zh_cn/images/upload_compression_server.png deleted file mode 100644 index 42ba9dc14f6305bebb05e43c531378a02f84f3d8..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/upload_compression_server.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/weight_diff_decode.png b/docs/federated/docs/source_zh_cn/images/weight_diff_decode.png deleted file mode 100644 index fc7c07cbd48813b259b27dcb8e158976a90025f2..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/weight_diff_decode.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/images/weight_diff_encode.png b/docs/federated/docs/source_zh_cn/images/weight_diff_encode.png deleted file mode 100644 index 1103b9c6f1349699eb2d48cbb00fe8557660dba8..0000000000000000000000000000000000000000 Binary files a/docs/federated/docs/source_zh_cn/images/weight_diff_encode.png and /dev/null differ diff --git a/docs/federated/docs/source_zh_cn/index.rst b/docs/federated/docs/source_zh_cn/index.rst deleted file mode 100644 index bc74e2426009507557d089528ce6bcae2815dfd2..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/index.rst +++ /dev/null @@ -1,112 +0,0 @@ -.. MindSpore documentation master file, created by - sphinx-quickstart on Thu Mar 24 11:00:00 2020. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -MindSpore Federated 文档 -========================= - -MindSpore Federated是一款开源联邦学习框架,支持面向千万级无状态终端设备的商用化部署,可在用户数据不出本地的前提下,使能全场景智能应用。 - -联邦学习是一种加密的分布式机器学习技术,其支持机器学习的各参与方在不直接共享本地数据的前提下,共建AI模型。MindSpore Federated目前优先专注于参与方数量规模较大的横向联邦学习应用场景。 - -.. raw:: html - - - -使用MindSpore Federated框架的优势 ----------------------------------- - -1. 隐私安全 - - 支持参与方数据留存本地进行协同训练,不交换数据本身,而是用加密方式交换更新的模型参数。 - - 支持基于多方安全计算(MPC)的精度无损的安全聚合方案,防止模型窃取。 - - 支持基于本地差分隐私的性能无损的加密方案,防止模型泄漏隐私数据。 - -2. 分布式联邦聚合 - - 云侧松耦合集群化处理方式,支持千万级数量的大规模异构终端部署场景,实现高性能、高可用的分布式联邦聚合计算,可应对网络不稳定,负载突变等问题。 - -3. 联邦效率提升 - - 支持同步和异步的联邦模式,支持多种模型压缩算法,提高联邦学习效率,节省带宽资源。 - - 支持多种联邦聚合策略,提高联邦收敛的平滑度,兼顾全局和局部的精度最优化。 - -4. 灵活易用 - - 仅一行代码即可切换单机训练与联邦学习模式。 - - 网络模型可编程,聚合算法可编程,安全算法可编程,安全等级可定制。 - -使用MindSpore Federated的工作流程 ----------------------------------- - -1. `识别场景、积累数据 `_ - - 识别出可使用联邦学习的业务场景,在客户端为联邦任务积累本地数据。 - -2. `模型选型、客户端部署 `_ - - 进行模型原型的选型或开发,并使用工具生成方便部署的端侧模型。 - -3. `应用部署 `_ - - 将Federated-Client部署到端侧应用中,并在云侧设置联邦配置任务和部署脚本。 - -常见应用场景 ------------------ - -1. `图像分类 `_ - - 使用联邦学习实现图像分类应用。 - -2. `文本分类 `_ - - 使用联邦学习实现文本分类应用。 - -.. toctree:: - :maxdepth: 1 - :caption: 安装部署 - - federated_install - deploy_federated_server - deploy_federated_client - -.. toctree:: - :maxdepth: 1 - :caption: 应用实践 - - image_classification_application - sentiment_classification_application - image_classification_application_in_cross_silo - object_detection_application_in_cross_silo - -.. toctree:: - :maxdepth: 1 - :caption: 安全和隐私 - - local_differential_privacy_training_noise - local_differential_privacy_training_signds - pairwise_encryption_training - -.. toctree:: - :maxdepth: 1 - :caption: 通信压缩 - - comunication_compression - -.. toctree:: - :maxdepth: 1 - :caption: API参考 - - federated_server - federated_client - -.. toctree:: - :maxdepth: 1 - :caption: 参考文档 - - faq diff --git a/docs/federated/docs/source_zh_cn/interface_description_federated_client.md b/docs/federated/docs/source_zh_cn/interface_description_federated_client.md deleted file mode 100644 index 3469e66544b7a2b94a9fb5532fd508a7beeb666a..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/interface_description_federated_client.md +++ /dev/null @@ -1,350 +0,0 @@ -# 使用示例 - - - -注意,在使用以下接口前,可先参照文档[端侧部署](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_client.html)进行相关环境的部署。 - -## 联邦学习启动接口flJobRun() - -调用flJobRun()接口前,需先实例化参数类FLParameter,进行相关参数设置, 相关参数如下: - -| 参数名称 | 参数类型 | 是否必须 | 描述信息 | 备注 | -| -------------------- | -------------------------- | -------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| dataMap | Map/> | Y | 联邦学习数据集路径 | Map/>类型的数据集,map中key为RunType枚举类型,value为对应的数据集列表,key为RunType.TRAINMODE时代表对应的value为训练相关的数据集列表,key为RunType.EVALMODE时代表对应的value为验证相关的数据集列表, key为RunType.INFERMODE时代表对应的value为推理相关的数据集列表。 | -| flName | String | Y | 联邦学习使用的模型脚本包路径 | 我们提供了两个类型的模型脚本供大家参考([有监督情感分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert)、[LeNet图片分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)),对于有监督情感分类任务,该参数可设置为所提供的脚本文件[AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java) 的包路径`com.mindspore.flclient.demo.albert.AlbertClient`;对于LeNet图片分类任务,该参数可设置为所提供的脚本文件[LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java) 的包路径`com.mindspore.flclient.demo.lenet.LenetClient`。同时,用户可参考这两个类型的模型脚本,自定义模型脚本,然后将该参数设置为自定义的模型文件ModelClient.java(需继承于类[Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java))的包路径即可。 | -| trainModelPath | String | Y | 联邦学习使用的训练模型路径,为.ms文件的绝对路径 | 建议将路径设置到训练App自身目录下,保护模型本身的数据访问安全性。 | -| inferModelPath | String | Y | 联邦学习使用的推理模型路径,为.ms文件的绝对路径 | 对于普通联邦学习模式(训练和推理使用同一个模型),该参数需设置为与trainModelPath相同;对于混合学习模式(训练和推理使用不同的模型,且云侧也包含训练过程),该参数设置为实际的推理模型路径。建议将路径设置到训练App自身目录下,保护模型本身的数据访问安全性。 | -| sslProtocol | String | N | 端云HTTPS通信所使用的TLS协议版本 | 设置了白名单,目前只支持"TLSv1.3"或者"TLSv1.2"。非必须设置,默认值为"TLSv1.2"。只在HTTPS通信场景中使用。 | -| deployEnv | String | Y | 联邦学习的部署环境 | 设置了白名单,目前只支持"x86", "android"。 | -| certPath | String | N | 端云https通信所使用的自签名根证书路径 | 当部署环境为"x86",且端云采用自签名证书进行https通信认证时,需要设置该参数,该证书需与生成云侧自签名证书所使用的CA根证书一致才能验证通过,此参数用于非Android场景。 | -| domainName | String | Y | 端云通信url | 目前,https和http通信均支持,对应格式分别为:https://......、http://......,当`useElb`设置为true时,格式必须为:https://127.0.0.0:6666 或者http://127.0.0.0:6666 ,其中`127.0.0.0`对应提供云侧服务的机器ip(即云侧参数`--scheduler_ip`),`6666`对应云侧参数`--fl_server_port`。 | -| ifUseElb | boolean | N | 用于多server场景设置是否将客户端的请求随机发送给一定范围内的不同server | 设置为true代表客户端会将请求随机发给一定范围内的server地址,false代表客户端的请求会发给固定的server地址,此参数用于非Android场景,默认值为false。 | -| serverNum | int | N | 客户端可选择连接的server数量 | 当ifUseElb设置为true时,可设置为与云侧启动server端时的`server_num`参数保持一致,用于随机选择不同的server发送信息,此参数用于非Android场景,默认值为1。 | -| ifPkiVerify | boolean | N | 端云身份认证开关 | 设置为true代表开启端云安全认证,设置为false代表不开启,默认值为false。身份认证需要HUKS提供证书,该参数只在Android环境中使用(目前只支持华为手机)。 | -| threadNum | int | N | 联邦学习训练和推理时使用的线程数 | 默认值为1 | -| cpuBindMode | BindMode | N | 联邦学习训练和推理时线程所需绑定的cpu内核 | BindMode枚举类型,其中BindMode.NOT_BINDING_CORE代表不绑定内核,由系统自动分配,BindMode.BIND_LARGE_CORE代表绑定大核,BindMode.BIND_MIDDLE_CORE代表绑定中核。默认值为BindMode.NOT_BINDING_CORE。 | -| batchSize | int | Y | 联邦学习训练和推理时使用的单步训练样本数,即batch size | 需与模型的输入数据的batch size保持一致。 | -| iflJobResultCallback | IFLJobResultCallback | N | 联邦学习回调函数对象 | 用户可根据实际场景所需,实现工程中接口类[IFLJobResultCallback.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/IFLJobResultCallback.java)的具体方法后,作为回调函数对象设置到联邦学习任务中。我们提供了一个简单的实现用例[FLJobResultCallback.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/FLJobResultCallback.java)作为该参数默认值。 | - -注意1,当使用http通信时,可能会存在通信安全风险,请知悉。 - -注意2,在Android环境中,进行https通信时还需对以下参数进行设置,设置示例如下: - -```java -FLParameter flParameter = FLParameter.getInstance(); -SecureSSLSocketFactory sslSocketFactory = SecureSSLSocketFactory.getInstance(applicationContext) -SecureX509TrustManager x509TrustManager = new SecureX509TrustManager(applicationContext); -flParameter.setSslSocketFactory(sslSocketFactory); -flParameter.setX509TrustManager(x509TrustManager); -``` - -其中 `SecureSSLSocketFactory` 、`SecureX509TrustManager` 两个对象需在Android工程中实现,需要用户根据手机中证书种类自行进行设计。 - -注意3,在x86环境中,进行https通信时,目前只支持自签名证书认证,还需对以下参数进行设置,设置示例如下: - -```java -FLParameter flParameter = FLParameter.getInstance(); -String certPath = "CARoot.pem"; // 端云https通信所使用的自签名根证书路径 -flParameter.setCertPath(certPath); -``` - -注意4,在Android环境中, 当pkiVerify设置为true且云侧设置encrypt_type=PW_ENCRYPT时,还需要对以下参数进行设置,设置示例如下: - -```java -FLParameter flParameter = FLParameter.getInstance(); -String equipCrlPath = certPath; -long validIterInterval = 3600000; -flParameter.setEquipCrlPath(equipCrlPath); -flParameter.setValidInterval(validIterInterval); -``` - -其中`equipCrlPath`是设备之间证书校验需要的CRL证书,即证书吊销列表,一般可以预置 "Huawei CBG Certificate Revocation Lists" 中的设备证书CRL;`validIterInterval`一般可以设置为每轮端云聚合需要的时间(单位:毫秒,默认值为3600000),在PW_ENCRYPT模式下用来辅助防范重放攻击。 - -注意5,每次联邦学习任务启动前,会实例化类FLParameter进行相关参数设置。而实例化FLParameter时会自动随机生成一个clientID,用于与云侧交互过程中唯一标识该客户端,若用户需要自行设置clientID,可在实例化类FLParameter之后,调用其setClientID方法进行设置,则接着启动联邦学习任务后会使用用户设置的clientID。 - -创建SyncFLJob对象,并通过SyncFLJob类的flJobRun()方法启动同步联邦学习任务。 - -示例代码(基本http通信)如下: - -1. 有监督情感分类任务示例代码 - - ```java - // 构造dataMap - String trainTxtPath = "data/albert/supervise/client/1.txt"; - String evalTxtPath = "data/albert/supervise/eval/eval.txt"; // 非必须,getModel之后不进行验证可不设置 - String vocabFile = "data/albert/supervise/vocab.txt"; // 数据预处理的词典文件路径 - String idsFile = "data/albert/supervise/vocab_map_ids.txt" // 词典的映射id文件路径 - Map> dataMap = new HashMap<>(); - List trainPath = new ArrayList<>(); - trainPath.add(trainTxtPath); - trainPath.add(vocabFile); - trainPath.add(idsFile); - List evalPath = new ArrayList<>(); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(evalTxtPath); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(vocabFile); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(idsFile); // 非必须,getModel之后不进行验证可不设置 - dataMap.put(RunType.TRAINMODE, trainPath); - dataMap.put(RunType.EVALMODE, evalPath); // 非必须,getModel之后不进行验证可不设置 - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // AlBertClient.java 包路径 - String trainModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // 绝对路径 - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // 绝对路径, 和trainModelPath保持一致 - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - - // start FLJob - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.flJobRun(); - ``` - -2. LeNet图片分类任务示例代码 - - ```java - // 构造dataMap - String trainImagePath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_9_train_data.bin"; - String trainLabelPath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_9_train_label.bin"; - String evalImagePath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_data.bin"; // 非必须,getModel之后不进行验证可不设置 - String evalLabelPath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_label.bin"; // 非必须,getModel之后不进行验证可不设置 - Map> dataMap = new HashMap<>(); - List trainPath = new ArrayList<>(); - trainPath.add(trainImagePath); - trainPath.add(trainLabelPath); - List evalPath = new ArrayList<>(); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(evalImagePath); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(evalLabelPath); // 非必须,getModel之后不进行验证可不设置 - dataMap.put(RunType.TRAINMODE, trainPath); - dataMap.put(RunType.EVALMODE, evalPath); // 非必须,getModel之后不进行验证可不设置 - - String flName = "com.mindspore.flclient.demo.lenet.LenetClient"; // LenetClient.java 包路径 - String trainModelPath = "SyncFLClient/lenet_train.mindir0.ms"; //绝对路径 - String inferModelPath = "SyncFLClient/lenet_train.mindir0.ms"; //绝对路径 - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - flParameter.setBatchSize(batchSize); - - // start FLJob - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.flJobRun(); - ``` - -## 多条数据输入推理接口modelInference() - -调用modelInference()接口前,需先实例化参数类FLParameter,进行相关参数设置, 相关参数如下: - -| 参数名称 | 参数类型 | 是否必须 | 描述信息 | 适应API版本 | -| -------------- | -------------------------- | -------- | ------------------------------------------------------ | ------------------------------------------------------------ | -| flName | String | Y | 联邦学习使用的模型脚本包路径 | 我们提供了两个类型的模型脚本供大家参考([有监督情感分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert)、[LeNet图片分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)),对于有监督情感分类任务,该参数可设置为所提供的脚本文件[AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java) 的包路径`com.mindspore.flclient.demo.albert.AlbertClient`;对于LeNet图片分类任务,该参数可设置为所提供的脚本文件[LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java) 的包路径`com.mindspore.flclient.demo.lenet.LenetClient`。同时,用户可参考这两个类型的模型脚本,自定义模型脚本,然后将该参数设置为自定义的模型文件ModelClient.java(需继承于类[Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java))的包路径即可。 | -| dataMap | Map/> | Y | 联邦学习数据集路径 | Map/>类型的数据集,map中key为RunType枚举类型,value为对应的数据集列表,key为RunType.TRAINMODE时代表对应的value为训练相关的数据集列表,key为RunType.EVALMODE时代表对应的value为验证相关的数据集列表, key为RunType.INFERMODE时代表对应的value为推理相关的数据集列表。 | -| inferModelPath | String | Y | 联邦学习推理模型路径,为.ms文件的绝对路径 | 对于普通联邦学习模式(训练和推理使用同一个模型),该参数需设置为与trainModelPath相同;对于混合学习模式(训练和推理使用不同的模型,且云侧也包含训练过程),该参数设置为实际的推理模型路径。建议将路径设置到训练App自身目录下,保护模型本身的数据访问安全性。 | -| threadNum | int | N | 联邦学习训练和推理时使用的线程数 | 默认值为1 | -| cpuBindMode | BindMode | N | 联邦学习训练和推理时线程所需绑定的cpu内核 | BindMode枚举类型,其中BindMode.NOT_BINDING_CORE代表不绑定内核,由系统自动分配,BindMode.BIND_LARGE_CORE代表绑定大核,BindMode.BIND_MIDDLE_CORE代表绑定中核。默认值为BindMode.NOT_BINDING_CORE。 | -| batchSize | int | Y | 联邦学习训练和推理时使用的单步训练样本数,即batch size | 需与模型的输入数据的batch size保持一致。 | - -创建SyncFLJob对象,并通过SyncFLJob类的modelInference()方法启动端侧推理任务,返回推理的标签数组。 - -示例代码如下: - -1. 有监督情感分类任务示例代码 - - ```java - // 构造dataMap - String inferTxtPath = "data/albert/supervise/eval/eval.txt"; - String vocabFile = "data/albert/supervise/vocab.txt"; - String idsFile = "data/albert/supervise/vocab_map_ids.txt" - Map> dataMap = new HashMap<>(); - List inferPath = new ArrayList<>(); - inferPath.add(inferTxtPath); - inferPath.add(vocabFile); - inferPath.add(idsFile); - dataMap.put(RunType.INFERMODE, inferPath); - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // AlBertClient.java 包路径 - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // 绝对路径, 和trainModelPath保持一致; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setInferModelPath(inferModelPath); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - flParameter.setBatchSize(batchSize); - - // inference - SyncFLJob syncFLJob = new SyncFLJob(); - int[] labels = syncFLJob.modelInference(); - ``` - -2. LeNet图片分类示例代码 - - ```java - // 构造dataMap - String inferImagePath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_data.bin"; - String inferLabelPath = "SyncFLClient/data/3500_clients_bin/f0178_39/f0178_39_bn_1_test_label.bin"; - Map> dataMap = new HashMap<>(); - List inferPath = new ArrayList<>(); - inferPath.add(inferImagePath); - inferPath.add(inferLabelPath); - dataMap.put(RunType.INFERMODE, inferPath); - - String flName = "com.mindspore.flclient.demo.lenet.LenetClient"; // LenetClient.java 包路径 - String inferModelPath = "SyncFLClient/lenet_train.mindir0.ms"; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setInferModelPath(inferModelPath); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - flParameter.setBatchSize(batchSize); - - // inference - SyncFLJob syncFLJob = new SyncFLJob(); - int[] labels = syncFLJob.modelInference(); - ``` - -## 获取云侧最新模型接口getModel () - -调用getModel()接口前,需先实例化参数类FLParameter,进行相关参数设置, 相关参数如下: - -| 参数名称 | 参数类型 | 是否必须 | 描述信息 | 备注 | -| -------------- | --------- | -------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| flName | String | Y | 联邦学习使用的模型脚本包路径 | 我们提供了两个类型的模型脚本供大家参考([有监督情感分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert)、[LeNet图片分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)),对于有监督情感分类任务,该参数可设置为所提供的脚本文件[AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java) 的包路径`com.mindspore.flclient.demo.albert.AlbertClient`;对于LeNet图片分类任务,该参数可设置为所提供的脚本文件[LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java) 的包路径`com.mindspore.flclient.demo.lenet.LenetClient`。同时,用户可参考这两个类型的模型脚本,自定义模型脚本,然后将该参数设置为自定义的模型文件ModelClient.java(需继承于类[Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java))的包路径即可。 | -| trainModelPath | String | Y | 联邦学习使用的训练模型路径,为.ms文件的绝对路径 | 建议将路径设置到训练App自身目录下,保护模型本身的数据访问安全性。 | -| inferModelPath | String | Y | 联邦学习推理模型路径,为.ms文件的绝对路径 | 对于普通联邦学习模式(训练和推理使用同一个模型),该参数需设置为与trainModelPath相同;对于混合学习模式(训练和推理使用不同的模型,且云侧也包含训练过程),该参数设置为实际的推理模型路径。建议将路径设置到训练App自身目录下,保护模型本身的数据访问安全性。 | -| sslProtocol | String | N | 端云HTTPS通信所使用的TLS协议版本 | 设置了白名单,目前只支持"TLSv1.3"或者"TLSv1.2"。非必须设置,默认值为"TLSv1.2"。只在HTTPS通信场景中使用。 | -| deployEnv | String | Y | 联邦学习的部署环境 | 设置了白名单,目前只支持"x86", "android"。 | -| certPath | String | N | 端云https通信所使用的自签名根证书路径 | 当部署环境为"x86",且端云采用自签名证书进行https通信认证时,需要设置该参数,该证书需与生成云侧自签名证书所使用的CA根证书一致才能验证通过,此参数用于非Android场景。 | -| domainName | String | Y | 端云通信url | 目前,https和http通信均支持,对应格式分别为:https://......、http://......,当`useElb`设置为true时,格式必须为:https://127.0.0.0:6666 或者http://127.0.0.0:6666 ,其中`127.0.0.0`对应提供云侧服务的机器ip(即云侧参数`--scheduler_ip`),`6666`对应云侧参数`--fl_server_port`。 | -| ifUseElb | boolean | N | 用于多server场景设置是否将客户端的请求随机发送给一定范围内的不同server | 设置为true代表客户端会将请求随机发给一定范围内的server地址,false代表客户端的请求会发给固定的server地址,此参数用于非Android场景,默认值为false。 | -| serverNum | int | N | 客户端可选择连接的server数量 | 当ifUseElb设置为true时,可设置为与云侧启动server端时的`server_num`参数保持一致,用于随机选择不同的server发送信息,此参数用于非Android场景,默认值为1。 | -| serverMod | ServerMod | Y | 联邦学习训练模式。 | ServerMod枚举类型的联邦学习训练模式,其中ServerMod.FEDERATED_LEARNING代表普通联邦学习模式(训练和推理使用同一个模型)ServerMod.HYBRID_TRAINING代表混合学习模式(训练和推理使用不同的模型,且云侧也包含训练过程)。 | - -注意1,当使用http通信时,可能会存在通信安全风险,请知悉。 - -注意2,在Android环境中,进行https通信时还需对以下参数进行设置,设置示例如下: - -```java -FLParameter flParameter = FLParameter.getInstance(); -SecureSSLSocketFactory sslSocketFactory = SecureSSLSocketFactory.getInstance(applicationContext) -SecureX509TrustManager x509TrustManager = new SecureX509TrustManager(applicationContext); -flParameter.setSslSocketFactory(sslSocketFactory); -flParameter.setX509TrustManager(x509TrustManager); -``` - -其中 `SecureSSLSocketFactory` 、`SecureX509TrustManager` 两个对象需在Android工程中实现,需要用户根据手机中证书种类自行进行设计。 - -注意3,在X86环境中,进行https通信时,目前只支持自签名证书认证,还需对以下参数进行设置,设置示例如下: - -```java -FLParameter flParameter = FLParameter.getInstance(); -String certPath = "CARoot.pem"; // 端云https通信所使用的自签名根证书路径 -flParameter.setCertPath(certPath); -``` - -注意4,在调用getModel方法前,会实例化类FLParameter进行相关参数设置。而实例化FLParameter时会自动随机生成一个clientID,用于与云侧交互过程中唯一标识该客户端,若用户需要自行设置clientID,可在实例化类FLParameter之后,调用其setCertPath方法进行设置,则接着启动getModel任务后会使用用户设置的clientID。 - -创建SyncFLJob对象,并通过SyncFLJob类的getModel()方法启动异步推理任务,返回getModel请求状态码。 - -示例代码如下: - -1. 有监督情感分类任务版本 - - ```java - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // AlBertClient.java 包路径 - String trainModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; //绝对路径 - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; //绝对路径, 和trainModelPath保持一致 - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - ServerMod serverMod = ServerMod.FEDERATED_LEARNING; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setServerMod(ServerMod.valueOf(serverMod)); - - // getModel - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.getModel(); - ``` - -2. LeNet图片分类任务版本 - - ```java - String flName = "com.mindspore.flclient.demo.lenet.LenetClient"; // LenetClient.java 包路径 - String trainModelPath = "SyncFLClient/lenet_train.mindir0.ms"; //绝对路径 - String inferModelPath = "SyncFLClient/lenet_train.mindir0.ms"; //绝对路径, 和trainModelPath保持一致 - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - ServerMod serverMod = ServerMod.FEDERATED_LEARNING; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(useElb); - flParameter.setServerNum(serverNum); - flParameter.setServerMod(ServerMod.valueOf(serverMod)); - - // getModel - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.getModel(); - ``` diff --git a/docs/federated/docs/source_zh_cn/java_api_callback.md b/docs/federated/docs/source_zh_cn/java_api_callback.md deleted file mode 100644 index 3814435ab05a2def2a1d5992e19e02f5ac0d3dc3..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/java_api_callback.md +++ /dev/null @@ -1,66 +0,0 @@ -# Callback - - - -```java -import com.mindspore.flclient.model.Callback -``` - -Callback定义了端侧联邦学习中用于记录训练、评估和预测不同阶段结果的钩子函数。 - -## 公有成员函数 - -| function | -| -------------------------------- | -| [abstract Status stepBegin()](#stepbegin) | -| [abstract Status stepEnd()](#stepend) | -| [abstract Status epochBegin()](#epochbegin) | -| [abstract Status epochEnd()](#epochend) | - -## stepBegin - -```java - public abstract Status stepBegin() -``` - -单步执行前处理函数。 - -- 返回值 - - 前处理执行结果状态。 - -## stepEnd - -```java -public abstract Status stepEnd() -``` - -单步执行后处理函数。 - -- 返回值 - - 后处理执行结果状态。 - -## epochBegin - -```java -public abstract Status epochBegin() -``` - -epoch执行前处理函数。 - -- 返回值 - - 前处理执行结果状态。 - -## epochEnd - -```java -public abstract Status epochEnd() -``` - -epoch执行后处理函数。 - -- 返回值 - - 前处理执行结果状态。 diff --git a/docs/federated/docs/source_zh_cn/java_api_client.md b/docs/federated/docs/source_zh_cn/java_api_client.md deleted file mode 100644 index c8c03634c4fe2504cec03ccfeb492be8ec6feb4b..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/java_api_client.md +++ /dev/null @@ -1,227 +0,0 @@ -# Client - - - -```java -import com.mindspore.flclient.model.Client -``` - -Client定义了端侧联邦学习算法执行流程对象。 - -## 公有成员函数 - -| function | -| -------------------------------- | -| [abstract List initCallbacks(RunType runType, DataSet dataSet)](#initcallbacks) | -| [abstract Map initDataSets(Map\> files)](#initdatasets) | -| [abstract float getEvalAccuracy(List evalCallbacks)](#getevalaccuracy) | -| [abstract List getInferResult(List inferCallbacks)](#getinferresult) | -| [Status initSessionAndInputs(String modelPath, MSConfig config)](#initsessionandinputs) | -| [Status trainModel(int epochs)](#trainmodel) | -| [evalModel()](#evalmodel) | -| [List inferModel()](#infermodel) | -| [Status saveModel(String modelPath)](#savemodel) | -| [List getFeatures()](#getfeatures) | -| [Status updateFeatures(String modelName, List featureMaps)](#updatefeatures) | -| [void free()](#free) | -| [Status setLearningRate(float lr)](#setlearningrate) | -| [void setBatchSize(int batchSize)](#setbatchsize) | - -## initCallbacks - -```java -public abstract List initCallbacks(RunType runType, DataSet dataSet) -``` - -初始化callback列表。 - -- 参数 - - - `runType`: RunType类,标识训练、评估还是预测阶段。 - - `dataSet`: DataSet类,训练、评估还是预测阶段数据集。 - -- 返回值 - - 初始化的callback列表。 - -## initDataSets - -```java -public abstract Map initDataSets(Map> files) -``` - -初始化dataset列表。 - -- 参数 - - - `files`: 训练、评估和预测阶段使用的数据文件。 - -- 返回值 - - 训练、评估和预测阶段数据集样本量。 - -## getEvalAccuracy - -```java -public abstract float getEvalAccuracy(List evalCallbacks) -``` - -获取评估阶段的精度。 - -- 参数 - - - `evalCallbacks`: 评估阶段使用的callback列表。 - -- 返回值 - - 评估阶段精度。 - -## getInferResult - -```java -public abstract List getInferResult(List inferCallbacks) -``` - -获取预测结果。 - -- 参数 - - - `inferCallbacks`: 预测阶段使用的callback列表。 - -- 返回值 - - 预测结果。 - -## initSessionAndInputs - -```java -public Status initSessionAndInputs(String modelPath, MSConfig config) -``` - -初始化client底层会话和输入。 - -- 参数 - - - `modelPath`: 模型文件。 - - `config`: 会话配置。 - -- 返回值 - - 初始化状态结果。 - -## trainModel - -```java -public Status trainModel(int epochs) -``` - -开启模型训练。 - -- 参数 - - - `epochs`: 训练的epoch数。 - -- 返回值 - - 模型训练结果。 - -## evalModel - -```java -public float evalModel() -``` - -执行模型评估过程。 - -- 返回值 - - 模型评估精度。 - -## inferModel - -```java -public List inferModel() -``` - -执行模型预测过程。 - -- 返回值 - - 模型预测结果。 - -## saveModel - -```java -public Status saveModel(String modelPath) -``` - -保存模型。 - -- 返回值 - - 模型保存结果。 - -## getFeatures - -```java -public List getFeatures() -``` - -获取端侧权重。 - -- 返回值 - - 模型权重。 - -## updateFeatures - -```java -public Status updateFeatures(String modelName, List featureMaps) -``` - -更新端侧权重。 - -- 参数 - - - `modelName`: 待更新的模型文件。 - - `featureMaps`: 待更新的模型权重。 - -- 返回值 - - 模型权重。 - -## free - -```java -public void free() -``` - -释放模型。 - -## setLearningRate - -```java -public Status setLearningRate(float lr) -``` - -设置学习率。 - -- 参数 - - - `lr`: 学习率。 - -- 返回值 - - 设置结果。 - -## setBatchSize - -```java -public void setBatchSize(int batchSize) -``` - -设置执行批次数。 - -- 参数 - - - `batchSize`: 批次数。 diff --git a/docs/federated/docs/source_zh_cn/java_api_clientmanager.md b/docs/federated/docs/source_zh_cn/java_api_clientmanager.md deleted file mode 100644 index 7f2b9502658a53b02aa500352c3e5e40a452c219..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/java_api_clientmanager.md +++ /dev/null @@ -1,43 +0,0 @@ -# ClientManager - - - -```java -import com.mindspore.flclient.model.ClientManager -``` - -ClientManager定义了端侧联邦学习自定义算法模型注册接口。 - -## 公有成员函数 - -| function | -| -------------------------------- | -| [static void registerClient(Client client)](#registerclient) | -| [static Client getClient(String name)](#getclient) | - -## registerClient - -```java -public static void registerClient(Client client) -``` - -注册Client对象。 - -- 参数 - - - `client`: 需要注册的Client对象。 - -## getClient - -```java -public static Client getClient(String name) -``` - -获取Client对象。 - -- 参数 - - - `name`: Client对象名称。 -- 返回值 - - Client对象。 diff --git a/docs/federated/docs/source_zh_cn/java_api_dataset.md b/docs/federated/docs/source_zh_cn/java_api_dataset.md deleted file mode 100644 index 5674318eece924cfbc127d2acc212cabed32a430..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/java_api_dataset.md +++ /dev/null @@ -1,63 +0,0 @@ -# DataSet - - - -```java -import com.mindspore.flclient.model.DataSet -``` - -DataSet定义了端侧联邦学习数据集对象。 - -## 公有成员函数 - -| function | -| -------------------------------- | -| [abstract void fillInputBuffer(List var1, int var2)](#fillinputbuffer) | -| [abstract void shuffle()](#shuffle) | -| [abstract void padding()](#padding) | -| [abstract Status dataPreprocess(List var1)](#datapreprocess) | - -## fillInputBuffer - -```java -public abstract void fillInputBuffer(List var1, int var2) -``` - -填充输入buffer数据。 - -- 参数 - - - `var1`: 需要填充的buffer内存。 - - `var2`: 需要填充的batch索引。 - -## shuffle - -```java - public abstract void shuffle() -``` - -打乱数据。 - -## padding - -```java - public abstract void padding() -``` - -补齐数据。 - -## dataPreprocess - -```java -public abstract Status dataPreprocess(List var1) -``` - -数据前处理。 - -- 参数 - - - `var1`: 使用的训练、评估或推理数据集。 - -- 返回值 - - 数据处理结果。 diff --git a/docs/federated/docs/source_zh_cn/java_api_flparameter.md b/docs/federated/docs/source_zh_cn/java_api_flparameter.md deleted file mode 100644 index d5814ee041e118a136755cb3662ba442fb45c096..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/java_api_flparameter.md +++ /dev/null @@ -1,636 +0,0 @@ -# FLParameter - - - -```java -import com.mindspore.flclient.FLParameter -``` - -FLParameter定义联邦学习相关参数,供用户进行设置。 - -## 公有成员函数 - -| **function** | -| ------------------------------------------------------------ | -| public static synchronized FLParameter getInstance() | -| public String getDeployEnv() | -| public void setDeployEnv(String env) | -| public String getDomainName() | -| public void setDomainName(String domainName) | -| public String getClientID() | -| public void setClientID(String clientID) | -| public String getCertPath() | -| public void setCertPath(String certPath) | -| public SSLSocketFactory getSslSocketFactory() | -| public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) | -| public X509TrustManager getX509TrustManager( | -| public void setX509TrustManager(X509TrustManager x509TrustManager) | -| public IFLJobResultCallback getIflJobResultCallback() | -| public void setIflJobResultCallback(IFLJobResultCallback iflJobResultCallback) | -| public String getFlName() | -| public void setFlName(String flName) | -| public String getTrainModelPath() | -| public void setTrainModelPath(String trainModelPath) | -| public String getInferModelPath() | -| public void setInferModelPath(String inferModelPath) | -| public String getSslProtocol() | -| public void setSslProtocol(String sslProtocol) | -| public int getTimeOut() | -| public void setTimeOut(int timeOut) | -| public int getSleepTime() | -| public void setSleepTime(int sleepTime) | -| public boolean isUseElb() | -| public void setUseElb(boolean useElb) | -| public int getServerNum() | -| public void setServerNum(int serverNum) | -| public boolean isPkiVerify() | -| public void setPkiVerify(boolean ifPkiVerify) | -| public String getEquipCrlPath() | -| public void setEquipCrlPath(String certPath) | -| public long getValidInterval() | -| public void setValidInterval(long validInterval) | -| public int getThreadNum() | -| public void setThreadNum(int threadNum) | -| public int getCpuBindMode() | -| public void setCpuBindMode(BindMode cpuBindMode) | -| public List getHybridWeightName(RunType runType) | -| public void setHybridWeightName(List hybridWeightName, RunType runType) | -| public Map/> getDataMap() | -| public void setDataMap(Map/> dataMap) | -| public ServerMod getServerMod() | -| public void setServerMod(ServerMod serverMod) | -| public int getBatchSize() | -| public void setBatchSize(int batchSize) | - -## getInstance - -```java -public static synchronized FLParameter getInstance() -``` - -获取FLParameter单例。 - -- 返回值 - - FLParameter类型的单例对象。 - -## getDeployEnv - -```java -public String getDeployEnv() -``` - -获取用户设置联邦学习的部署环境。 - -- 返回值 - - String类型的联邦学习的部署环境。 - -## setDeployEnv - -```java -public void setDeployEnv(String env) -``` - -用于设置联邦学习的部署环境, 设置了白名单,目前只支持"x86", "android"。 - -- 参数 - - - `env`: 联邦学习的部署环境。 - -## getDomainName - -```java -public String getDomainName() -``` - -获取用户设置的域名domainName。 - -- 返回值 - - String类型的域名。 - -## setDomainName - -```java -public void setDomainName(String domainName) -``` - -用于设置端云通信url,目前,可支持https和http通信,对应格式分别为:https://......、http://......,当`useElb`设置为true时,格式必须为:https://127.0.0.0:6666 或者http://127.0.0.0:6666 ,其中`127.0.0.0`对应提供云侧服务的机器ip(即云侧参数`--scheduler_ip`),`6666`对应云侧参数`--fl_server_port`。 - -- 参数 - - - `domainName`: 域名。 - -## getClientID - -```java -public String getClientID() -``` - -每次联邦学习任务启动前会自动生成一个唯一标识客户端的clientID(若用户需要自行设置clientID,可在启动联邦学习训练任务前使用setClientID进行设置),该方法用于获取该ID,可用于端云安全认证场景中生成相关证书。 - -- 返回值 - - String类型的唯一标识客户端的clientID。 - -## setClientID - -```java -public void setClientID(String clientID) -``` - -用于用户设置唯一标识客户端的clientID。 - -- 参数 - - - `clientID`: 唯一标识客户端的clientID。 - -## getCertPath - -```java -public String getCertPath() -``` - -获取用户设置的端云https通信所使用的自签名根证书路径certPath。 - -- 返回值 - - String类型的自签名根证书路径certPath。 - -## setCertPath - -```java -public void setCertPath(String certPath) -``` - -用于设置端云HTTPS通信所使用的自签名根证书路径certPath。当部署环境为"x86",且端云采用自签名证书进行https通信认证时,需要设置该参数,该证书需与生成云侧自签名证书所使用的CA根证书一致才能验证通过,此参数用于非Android场景。 - -- 参数 - - `certPath`: 端云https通信所使用的自签名根证书路径。 - -## getSslSocketFactory - -```java -public SSLSocketFactory getSslSocketFactory() -``` - -获取用户设置的ssl证书认证库sslSocketFactory。 - -- 返回值 - - SSLSocketFactory类型的ssl证书认证库sslSocketFactory。 - -## setSslSocketFactory - -```java -public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) -``` - -用于设置ssl证书认证库sslSocketFactory。 - -- 参数 - - `sslSocketFactory`: ssl证书认证库。 - -## getX509TrustManager - -```java -public X509TrustManager getX509TrustManager() -``` - - 获取用户设置的ssl证书认证管理器x509TrustManager。 - -- 返回值 - - X509TrustManager类型的ssl证书认证管理器x509TrustManager。 - -## setX509TrustManager - -```java -public void setX509TrustManager(X509TrustManager x509TrustManager) -``` - -用于设置ssl证书认证管理器x509TrustManager。 - -- 参数 - - `x509TrustManager`:ssl证书认证管理器。 - -## getIflJobResultCallback - -```java -public IFLJobResultCallback getIflJobResultCallback() -``` - - 获取用户设置的联邦学习回调函数对象iflJobResultCallback。 - -- 返回值 - - IFLJobResultCallback类型的联邦学习回调函数对象iflJobResultCallback。 - -## setIflJobResultCallback - -```java -public void setIflJobResultCallback(IFLJobResultCallback iflJobResultCallback) -``` - -用于设置联邦学习回调函数对象iflJobResultCallback,用户可根据实际场景所需,实现工程中接口类[IFLJobResultCallback.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/IFLJobResultCallback.java)的具体方法后,作为回调函数对象设置到联邦学习任务中。 - -- 参数 - - `iflJobResultCallback`:联邦学习回调函数。 - -## getFlName - -```java -public String getFlName() -``` - -用于获取用户设置的模型脚本包路径。 - -- 返回值 - - String类型的模型脚本包路径。 - -## setFlName - -```java -public void setFlName(String flName) -``` - -设置模型脚本包路径。我们提供了两个类型的模型脚本供大家参考([有监督情感分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert)、[Lenet图片分类任务](https://gitee.com/mindspore/mindspore/tree/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet)),对于有监督情感分类任务,该参数可设置为所提供的脚本文件[AlBertClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/albert/AlbertClient.java) 的包路径`com.mindspore.flclient.demo.albert.AlbertClient`;对于Lenet图片分类任务,该参数可设置为所提供的脚本文件[LenetClient.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/examples/quick_start_flclient/src/main/java/com/mindspore/flclient/demo/lenet/LenetClient.java) 的包路径`com.mindspore.flclient.demo.lenet.LenetClient`。同时,用户可参考这两个类型的模型脚本,自定义模型脚本,然后将该参数设置为自定义的模型文件ModelClient.java(需继承于类[Client.java](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/java/fl_client/src/main/java/com/mindspore/flclient/model/Client.java))的包路径即可。 - -- 参数 - - `flName`: 模型脚本包路径。 - -## getTrainModelPath - -```java -public String getTrainModelPath() -``` - -用于获取用户设置的训练模型路径trainModelPath。 - -- 返回值 - - String类型的训练模型路径trainModelPath。 - -## setTrainModelPath - -```java -public void setTrainModelPath(String trainModelPath) -``` - -设置训练模型路径trainModelPath。 - -- 参数 - - `trainModelPath`: 训练模型路径。 - -## getInferModelPath - -```java -public String getInferModelPath() -``` - -用于获取用户设置的推理模型路径inferModelPath。 - -- 返回值 - - String类型的推理模型路径inferModelPath。 - -## setInferModelPath - -```java -public void setInferModelPath(String inferModelPath) -``` - -设置推理模型路径inferModelPath。 - -- 参数 - - `inferModelPath`: 推理模型路径。 - -## getSslProtocol - -```java -public String getSslProtocol() -``` - -用于获取用户设置的端云HTTPS通信所使用的TLS协议版本。 - -- 返回值 - - String类型的端云HTTPS通信所使用的TLS协议版本。 - -## setSslProtocol - -```java -public void setSslProtocol(String sslProtocol) -``` - -用于设置端云HTTPS通信所使用的TLS协议版本, 设置了白名单,目前只支持"TLSv1.3"或者"TLSv1.2"。只在HTTPS通信场景中使用。 - -- 参数 - - `sslProtocol`: 端云HTTPS通信所使用的TLS协议版本。 - -## getTimeOut - -```java -public int getTimeOut() -``` - -用于获取用户设置的端侧通信的超时时间timeOut。 - -- 返回值 - - int类型的端侧通信的超时时间timeOut。 - -## setTimeOut - -```java -public void setTimeOut(int timeOut) -``` - -用于设置端侧通信的超时时间timeOut。 - -- 参数 - - `timeOut`: 端侧通信的超时时间。 - -## getSleepTime - -```java -public int getSleepTime() -``` - -用于获取用户设置的重复请求的等待时间sleepTime。 - -- 返回值 - - int类型的重复请求的等待时间sleepTime。 - -## setSleepTime - -```java -public void setSleepTime(int sleepTime) -``` - -用于设置重复请求的等待时间sleepTime。 - -- 参数 - - `sleepTime`: 重复请求的等待时间。 - -## isUseElb - -```java -public boolean isUseElb() -``` - -是否模拟弹性负载均衡,即客户端将请求随机发给一定范围内的server地址。 - -- 返回值 - - boolean类型,true代表客户端会将请求随机发给一定范围内的server地址, false客户端的请求会发给固定的server地址。 - -## setUseElb - -```java -public void setUseElb(boolean useElb) -``` - -用于设置是否模拟弹性负载均衡,即客户端将请求随机发给一定范围内的server地址。 - -- 参数 - - `useElb`: 是否模拟弹性负载均衡,默认为false。 - -## getServerNum - -```java -public int getServerNum() -``` - -用于获取用户设置的模拟弹性负载均衡时可发送请求的server数量。 - -- 返回值 - - int类型的模拟弹性负载均衡时可发送请求的server数量。 - -## setServerNum - -```java -public void setServerNum(int serverNum) -``` - -用于设置模拟弹性负载均衡时可发送请求的server数量。 - -- 参数 - - `serverNum`: 模拟弹性负载均衡时可发送请求的server数量,默认为1。 - -## isPkiVerify - -```java -public boolean isPkiVerify() -``` - -是否进行端云认证。 - -- 返回值 - - boolean类型,true代表进行端云认证,false代表不进行端云认证。 - -## setPkiVerify - -```java -public void setPkiVerify(boolean pkiVerify) -``` - -用于设置是否进行端云认证。 - -- 参数 - - - `pkiVerify`: 是否进行端云认证。 - -## getEquipCrlPath - -```java -public String getEquipCrlPath() -``` - -获取用户设置的设备证书的CRL证书路径equipCrlPath,此参数用于Android环境。 - -- 返回值 - - String类型的证书路径equipCrlPath。 - -## setEquipCrlPath - -```java -public void setEquipCrlPath(String certPath) -``` - -用于设置设备证书的CRL证书路径,用于验证数字证书是否被吊销,此参数用于Android环境。 - -- 参数 - - `certPath`: 证书路径。 - -## getValidInterval - -```java -public long getValidInterval() -``` - -获取用户设置的有效迭代时间间隔validIterInterval,此参数用于Android环境。 - -- 返回值 - - long类型的有效迭代时间间隔validIterInterval。 - -## setValidInterval - -```java -public void setValidInterval(long validInterval) -``` - -用于设置有效迭代时间间隔validIterInterval,建议时长为端云间一个训练epoch的时长(单位:毫秒),用于防范重放攻击,此参数用于Android环境。 - -- 参数 - - `validInterval`: 有效迭代时间间隔。 - -## getThreadNum - -```java -public int getThreadNum() -``` - -获取联邦学习训练和推理时使用的线程数,默认值为1。 - -- 返回值 - - int类型的线程数threadNum。 - -## setThreadNum - -```java -public void setThreadNum(int threadNum) -``` - -设置联邦学习训练和推理时使用的线程数。 - -- 参数 - - `threadNum`: 线程数。 - -## getCpuBindMode - -```java -public int getCpuBindMode() -``` - -获取联邦学习训练和推理时线程所需绑定的cpu内核。 - -- 返回值 - - 将枚举类型的cpu内核cpuBindMode转换为int型返回。 - -## setCpuBindMode - -```java -public void setCpuBindMode(BindMode cpuBindMode) -``` - -设置联邦学习训练和推理时线程所需绑定的cpu内核。 - -- 参数 - - `cpuBindMode`: BindMode枚举类型,其中BindMode.NOT_BINDING_CORE代表不绑定内核,由系统自动分配,BindMode.BIND_LARGE_CORE代表绑定大核,BindMode.BIND_MIDDLE_CORE代表绑定中核。 - -## getHybridWeightName - -```java -public List getHybridWeightName(RunType runType) -``` - -混合学习模式时使用。获取用户设置的训练权重名和推理权重名。 - -- 参数 - - - `runType`: RunType枚举类型,只支持设置为RunType.TRAINMODE(代表获取训练权重名)、RunType.INFERMODE(代表获取推理权重名)。 - -- 返回值 - - List 类型,根据参数runType返回相应的权重名列表。 - -## setHybridWeightName - -```java -public void setHybridWeightName(List hybridWeightName, RunType runType) -``` - -由于混合学习模式时,云侧下发的权重,一部分导入到训练模型,一部分导入到推理模型,但框架本身无法判断,需要用户自行设置相关训练权重名和推理权重名。该方法提供给用户进行设置。 - -- 参数 - - `hybridWeightName`: List 类型的权重名列表。 - - `runType`: RunType枚举类型,只支持设置为RunType.TRAINMODE(代表设置训练权重名)、RunType.INFERMODE(代表设置推理权重名)。 - -## getDataMap - -```java -public Map> getDataMap() -``` - -获取用户设置的联邦学习数据集。 - -- 返回值 - - Map>类型的数据集。 - -## setDataMap - -```java -public void setDataMap(Map> dataMap) -``` - -设置联邦学习数据集。 - -- 参数 - - `dataMap`: Map>类型的数据集,map中key为RunType枚举类型,value为对应的数据集列表,key为RunType.TRAINMODE时代表对应的value为训练相关的数据集列表,key为RunType.EVALMODE时代表对应的value为验证相关的数据集列表, key为RunType.INFERMODE时代表对应的value为推理相关的数据集列表。 - -## getServerMod - -```java -public ServerMod getServerMod() -``` - -获取联邦学习训练模式。 - -- 返回值 - - ServerMod枚举类型的联邦学习训练模式。 - -## setServerMod - -```java -public void setServerMod(ServerMod serverMod) -``` - -设置联邦学习训练模式。 - -- 参数 - - `serverMod`: ServerMod枚举类型的联邦学习训练模式,其中ServerMod.FEDERATED_LEARNING代表普通联邦学习模式(训练和推理使用同一个模型)ServerMod.HYBRID_TRAINING代表混合学习模式(训练和推理使用不同的模型,且云侧也包含训练过程)。 - -## getBatchSize - -```java -public int getBatchSize() -``` - -获取联邦学习训练和推理时使用的单步训练样本数,即batch size。 - -- 返回值 - - int类型的单步训练样本数batchSize。 - -## setBatchSize - -```java -public void setBatchSize(int batchSize) -``` - -设置联邦学习训练和推理时使用的单步训练样本数,即batch size。需与模型的输入数据的batch size保持一致。 - -- 参数 - - `batchSize`: 单步训练样本数,即batch size。 \ No newline at end of file diff --git a/docs/federated/docs/source_zh_cn/java_api_syncfljob.md b/docs/federated/docs/source_zh_cn/java_api_syncfljob.md deleted file mode 100644 index e96943d0f0afab5747755f59a9ded9f2a515ac86..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/java_api_syncfljob.md +++ /dev/null @@ -1,64 +0,0 @@ -# SyncFLJob - - - -```java -import com.mindspore.flclient.SyncFLJob -``` - -SyncFLJob定义了端侧联邦学习启动接口flJobRun()、端侧推理接口modelInference()、获取云侧最新模型的接口getModel()、停止联邦学习训练任务的接口stopFLJob()。 - -## 公有成员函数 - -| **function** | -| -------------------------------- | -| public FLClientStatus flJobRun() | -| public int[] modelInference() | -| public FLClientStatus getModel() | -| public void stopFLJob() | - -## flJobRun - -```java -public FLClientStatus flJobRun() -``` - -启动端侧联邦学习任务,具体使用方法可参考[接口介绍文档](https://www.mindspore.cn/federated/docs/zh-CN/master/interface_description_federated_client.html)。 - -- 返回值 - - 返回flJobRun请求状态码。 - -## modelInference - -```java -public int[] modelInference() -``` - -启动端侧推理任务,具体使用方法可参考[接口介绍文档](https://www.mindspore.cn/federated/docs/zh-CN/master/interface_description_federated_client.html)。 - -- 返回值 - - 根据输入推理出的标签组成的int[]。 - -## getModel - -```java -public FLClientStatus getModel() -``` - -获取云侧最新模型,具体使用方法可参考[接口介绍文档](https://www.mindspore.cn/federated/docs/zh-CN/master/interface_description_federated_client.html)。 - -- 返回值 - - 返回getModel请求状态码。 - -## stopFLJob - -```java -public void stopFLJob() -``` - -在联邦学习训练任务中,可通过调用该接口停止训练任务。 - -当一个线程调用SyncFLJob.flJobRun()时,可在联邦学习训练过程中,使用另外一个线程调用SyncFLJob.stopFLJob()停止联邦学习训练任务。 diff --git a/docs/federated/docs/source_zh_cn/local_differential_privacy_training_noise.md b/docs/federated/docs/source_zh_cn/local_differential_privacy_training_noise.md deleted file mode 100644 index 80d9a2f9e2d9144502916df3a801db6cacb8cd04..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/local_differential_privacy_training_noise.md +++ /dev/null @@ -1,43 +0,0 @@ -# 局部差分隐私加噪训练 - - - -联邦学习过程中,用户数据仅用于客户端设备的本地训练,不需要上传至中心服务器,可以避免泄露用户个人数据。然而,传统联邦学习框架中,模型以明文形式上云,仍然存在间接泄露用户隐私的风险。攻击者获取到客户端上传的明文模型后,可以通过重构、模型逆向等攻击方式,恢复参与学习的用户个人数据,导致用户隐私泄露。 - -MindSpore Federated联邦学习框架,提供了基于本地差分隐私(LDP)算法,在客户端上传本地模型前对其进行加噪。在保证模型可用性的前提下,解决横向联邦学习中的隐私泄露问题。 - -## 原理概述 - -差分隐私(differential privacy)是一种保护用户数据隐私的机制。差分隐私定义为: - -$$ -Pr[\mathcal{K}(D)\in S] \le e^{\epsilon} Pr[\mathcal{K}(D’) \in S]+\delta​ -$$ - -对于两个差别只有一条记录的数据集$D, D’$,通过随机算法$\mathcal{K}$,输出结果为集合$S$子集的概率满足上述公式。$\epsilon$为差分隐私预算,$\delta$扰动,$\epsilon$和$\delta$越小,说明$\mathcal{K}$在$D$和$D’$上输出的数据分布越接近。 - -在横向联邦学习中,假设客户端本地训练之后的模型权重矩阵是$W$,由于模型在训练过程中会“记住”训练集的特征,所以攻击者可以借助$W$还原出用户的训练数据集[1]。 - -MindSpore Federated提供基于本地差分隐私的安全聚合算法,防止客户端上传本地模型时泄露用户隐私数据。 - -MindSpore Federated客户端会生成一个与本地模型$W$相同维度的差分噪声矩阵$G$,然后将二者相加,得到一个满足差分隐私定义的权重$W_p$: - -$$ -W_p=W+G -$$ - -MindSpore Federated客户端将加噪后的模型$W_p$上传至云侧服务器进行联邦聚合。噪声矩阵$G$相当于给原模型加上了一层掩码,在降低模型泄露敏感数据风险的同时,也会影响模型训练的收敛性。如何在模型隐私性和可用性之间取得更好的平衡,仍然是一个值得研究的问题。实验表明,当参与方的数量$n$足够大时(一般指1000以上),大部分噪声能够相互抵消,本地差分机制对聚合模型的精度和收敛性没有明显影响。 - -## 使用方式 - -本地差分隐私训练目前只支持端云联邦学习场景。开启差分隐私训练的方式很简单,只需要在启动云侧服务时,使用`set_fl_context()`设置`encrypt_type='DP_ENCRYPT'`即可。 - -此外,为了控制隐私保护的效果,我们还提供了3个参数:`dp_eps`,`dp_delta`以及`dp_norm_clip`,它们也是通过`set_fl_context()`设置。 - -`dp_eps`和`dp_norm_clip`的合法取值范围是大于0,`dp_delta`的合法取值范围是0<`dp_delta`<1。一般来说,`dp_eps`和`dp_delta`越小,隐私保护效果也越好,但是对模型收敛性的影响越大。建议`dp_delta`取成客户端数量的倒数,`dp_eps`大于50。 - -`dp_norm_clip`是差分隐私机制对模型权重加噪前对权重大小的调整系数,会影响模型的收敛性,一般建议取0.5~2。 - -## 参考文献 - -[1] Ligeng Zhu, Zhijian Liu, and Song Han. [Deep Leakage from Gradients](http://arxiv.org/pdf/1906.08935.pdf). NeurIPS, 2019. diff --git a/docs/federated/docs/source_zh_cn/local_differential_privacy_training_signds.md b/docs/federated/docs/source_zh_cn/local_differential_privacy_training_signds.md deleted file mode 100644 index abe9d2519e350dcefa095c0dbf51c6d83a7cf05b..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/local_differential_privacy_training_signds.md +++ /dev/null @@ -1,149 +0,0 @@ -# 局部差分隐私SignDS训练 - - - -## 隐私保护背景 - -联邦学习通过让参与方只上传本地训练后的新模型或更新模型的update信息,实现了client用户不上传原始数据集就能参与全局模型训练的目的,打通了数据孤岛。这种普通场景的联邦学习对应MindSpore联邦学习框架中的默认方案([云侧部署](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_server.html#云侧部署)启动`server`时,`encrypt_type`开关默认为`not_encrypt`,联邦学习教程中的`安装部署`与`应用实践`都默认使用这种方式),是没有任何加密扰动等保护隐私处理的普通联邦求均方案,为方便描述,下文以`not_encrypt`来特指这种默认方案。 - -这种联邦学习方案并不是毫无隐私泄漏的,使用上述`not_encrypt`方案进行训练,服务端Server收到客户端Client上传的本地训练模型,仍可通过一些攻击方法[1]重构用户训练数据,从而泄露用户隐私,所以`not_encrypt`方案需要进一步增加用户隐私保护机制。 - -联邦学习中客户端Client每轮接收的全局模型`oldModel`都是由服务端Server下发的,不涉及用户隐私问题。但各客户端Client本地训练若干epoch后得到的本地模型`newModel`拟合了其本地隐私数据,所以隐私保护重点是二者的权重差值`newModel`-`oldModel`=`update`。 - -MindSpore Federated框架中已实现的`DP_ENCRYPT`差分噪声方案通过向`update`迭加高斯随机噪声进行扰动,实现隐私保护。但随着模型维度增大,`update`范数增大会使噪声增大,从而需要较多的客户端Client参与同一轮聚合,以中和噪声影响,否则模型收敛性和精度会降低。如果设置的噪声过小,虽然收敛性和精度与`not_encrypt`方案性能接近,但隐私保护力度不够。同时每个客户端Client都需要发送扰动后的模型,随着模型增大,通信开销也会随之增大。我们期望手机为代表的客户端Client,以尽可能少的通信开销,即可实现全局模型的收敛。 - -## 算法流程介绍 - -SignDS[2]是Sign Dimension Select的缩写,处理对象是客户端Client的`update`。准备工作:把`update`的每一层Tensor拉平展开成一维向量,连接在一起,拼接向量维度数量记为$d$。 - -一句话概括算法:**选择`update`的$h(h50. default=0.01,`inputDim`是模型或update的拉平长度,若不满足,端侧警告。排序update,占比前k(%)的组成`topk`集合。减少k,则意味着要从更重要的维度中以较大概率挑选,输出的维度会减少,但维度更重要,无法确定收敛性的变化,用户需观察模型update稀疏度来确定该值,当比较稀疏时(update有很多0),则应取小一点。 -- `sign_eps`:(0,100],default=100。隐私保护预算,数序符号为$\epsilon$,简写为eps。eps减少,挑选不重要的维度概率会增大,隐私保护力度增强,输出维度减少,占比不变,精度降低。 -- `sign_thr_ratio`:[0.5,1],default=0.6。激活的维度中来自`topk`的维度占比阈值下界。增大会减少输出维度,但输出维度中来自`topk`的占比会增加,当过度增大该值,要求输出中更多的来自`topk`,为了满足要求只能减少总的输出维度,当client用户数量不够多时,精度下降。 -- `sign_global_lr`:(0,),default=1。该值乘上sign来代替update,直接影响收敛快慢与精度,适度增大该值会提高收敛速度,但有可能让模型震荡,梯度爆炸。如果每个client用户本地跑更多的epoch,且增大本地训练使用的学习率,那么需要相应提高该值;如果参与聚合的client用户数目增多,那么也需要提高该值,因为重构时需要把该值聚合再除以用户数目,只有增大该值,结果才保持不变。 -- `sign_dim_out`:[0,50],default=0。若给出非0值,client端直接使用该值,增大该值输出的维度增多,但来自`topk`的维度占比会减少;若为0,client用户要计算出最优的输出参数。eps不够大时,若增大该值,则会输出很多`non-topk`的不重要维度导致影响模型收敛,精度下降;当eps足够大时,增大该值会让更多的用户重要的维度信息离开本地,精度提升。 - -## LeNet实验结果 - -使用`3500_clients_bin`其中的100个client数据集,联邦聚合200个iteration,每个client本地运行20个epoch,端侧本地训练使用学习率为0.01,SignDS相关参数为`k=0.01,eps=100,ratio=0.6,lr=4,out=0`,最终所有用户的准确率为66.5%,不加密的普通联邦场景为69%。不加密场景中,端侧训练结束上传到云侧的数据长度为266084,但SignDS上传的数据长度仅为656。 - -## 参考文献 - -[1] Ligeng Zhu, Zhijian Liu, and Song Han. [Deep Leakage from Gradients](http://arxiv.org/pdf/1906.08935.pdf). NeurIPS, 2019. - -[2] Xue Jiang, Xuebing Zhou, and Jens Grossklags. "SignDS-FL: Local Differentially-Private Federated Learning with Sign-based Dimension Selection." ACM Transactions on Intelligent Systems and Technology, 2022. \ No newline at end of file diff --git a/docs/federated/docs/source_zh_cn/object_detection_application_in_cross_silo.md b/docs/federated/docs/source_zh_cn/object_detection_application_in_cross_silo.md deleted file mode 100644 index 3094062c350b51713aae3de757153f34ec01c400..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/object_detection_application_in_cross_silo.md +++ /dev/null @@ -1,248 +0,0 @@ -# 实现一个云云联邦的目标检测应用(x86) - - - -根据参与客户端的类型,联邦学习可分为云云联邦学习(cross-silo)和端云联邦学习(cross-device)。在云云联邦学习场景中,参与联邦学习的客户端是不同的组织(例如,医疗或金融)或地理分布的数据中心,即在多个数据孤岛上训练模型。在端云联邦学习场景中,参与的客户端为大量的移动或物联网设备。本框架将介绍如何在MindSpore云云联邦框架上使用网络Fast R-CNN实现一个目标检测应用。 - -启动云云联邦的目标检测应用的完整脚本可参考[这里](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/cross_silo_faster_rcnn)。 - -## 任务前准备 - -本教程基于MindSpore model_zoo中提供的的faster_rcnn网络部署云云联邦目标检测任务,请先根据官方[faster_rcnn教程及代码](https://gitee.com/mindspore/models/tree/master/official/cv/faster_rcnn)先了解COCO数据集、faster_rcnn网络结构、训练过程以及评估过程。由于COCO数据集已开源,请参照其[官网](https://cocodataset.org/#home)指引自行下载好数据集,并进行数据集切分(例如模拟100个客户端,可将数据集切分成100份,每份代表一个客户端所持有的数据)。 - -由于原始COCO数据集为json文件格式,云云联邦学习框架提供的目标检测脚本暂时只支持MindRecord格式输入数据,可根据以下步骤将json文件转换为MindRecord格式文件: - -- 首先在配置文件[default_config.yaml](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_silo_faster_rcnn/default_config.yaml)中设置以下参数: - - - 参数`mindrecord_dir` - - 用于设置生成的MindRecord格式文件保存路径,文件夹名称必须为mindrecord_{num}格式,数字num代表客户端标号0,1,2,3,...... - - ```sh - mindrecord_dir:"./datasets/coco_split/split_100/mindrecord_0" - ``` - - - 参数`instance_set` - - 用于设置原始json文件路径。 - - ```sh - instance_set: "./datasets/coco_split/split_100/train_0.json" - ``` - -- 运行脚本[generate_mindrecord.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_silo_faster_rcnn/generate_mindrecord.py)即可生成`train_0.json`对应的MindRecord文件,保存在路径`mindrecord_dir`中。 - -## 启动云云联邦任务 - -### 安装MindSpore - -包括源码和下载发布版两种方式,支持CPU、GPU硬件平台,根据硬件平台选择安装即可。安装步骤可参考[MindSpore安装指南](https://www.mindspore.cn/install)。 - -目前联邦学习框架只支持Linux环境中部署,云云联邦学习框架需要MindSpore版本号>=1.5.0。 - -## 启动任务 - -参考[示例](https://gitee.com/mindspore/mindspore/tree/master/tests/st/fl/cross_silo_faster_rcnn),启动集群。参考示例目录结构如下: - -```text -cross_silo_faster_rcnn -├── src -│ ├── FasterRcnn -│ │ ├── __init__.py // init文件 -│ │ ├── anchor_generator.py // 锚点生成器 -│ │ ├── bbox_assign_sample.py // 第一阶段采样器 -│ │ ├── bbox_assign_sample_stage2.py // 第二阶段采样器 -│ │ ├── faster_rcnn_resnet.py // Faster R-CNN网络 -│ │ ├── faster_rcnn_resnet50v1.py // 以Resnet50v1.0作为backbone的Faster R-CNN网络 -│ │ ├── fpn_neck.py // 特征金字塔网络 -│ │ ├── proposal_generator.py // 候选生成器 -│ │ ├── rcnn.py // R-CNN网络 -│ │ ├── resnet.py // 骨干网络 -│ │ ├── resnet50v1.py // Resnet50v1.0骨干网络 -│ │ ├── roi_align.py // ROI对齐网络 -│ │ └── rpn.py // 区域候选网络 -│ ├── dataset.py // 创建并处理数据集 -│ ├── lr_schedule.py // 学习率生成器 -│ ├── network_define.py // Faster R-CNN网络定义 -│ ├── util.py // 例行操作 -│ └── model_utils -│ ├── __init__.py // init文件 -│ ├── config.py // 获取.yaml配置参数 -│ ├── device_adapter.py // 获取云上id -│ ├── local_adapter.py // 获取本地id -│ └── moxing_adapter.py // 云上数据准备 -├── requirements.txt -├── mindspore_hub_conf.py -├── generate_mindrecord.py // 将.json格式的annotations文件转化为MindRecord格式,以便读取datasets -├── default_config.yaml // 网络结构、数据集地址、fl_plan所需配置文件 -├── config.json // 容灾所需配置文件 -├── finish_cross_silo_fasterrcnn.py // 关闭云云联邦任务脚本 -├── run_cross_silo_fasterrcnn_sched.py // 启动云云联邦scheduler脚本 -├── run_cross_silo_fasterrcnn_server.py // 启动云云联邦server脚本 -├── run_cross_silo_fasterrcnn_worker.py // 启动云云联邦worker脚本 -└── test_fl_fasterrcnn.py // 客户端使用的训练脚本 -``` - -1. 注意在`test_fl_fasterrcnn.py`文件中可通过设置参数`dataset_sink_mode`来选择是否记录每个step的loss值: - - ```python - model.train(config.client_epoch_num, dataset, callbacks=cb) # 不设置dataset_sink_mode代表只记录每个epoch中最后一个step的loss值,代码里默认为这种方式 - model.train(config.client_epoch_num, dataset, callbacks=cb, dataset_sink_mode=False) # 设置dataset_sink_mode=False代表记录每个step的loss值 - ``` - -2. 在配置文件[default_config.yaml](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_silo_faster_rcnn/default_config.yaml)中设置以下参数: - - - 参数`pre_trained` - - 用于设置预训练模型路径(.ckpt 格式) - - 本教程中实验的预训练模型是在ImageNet2012上训练的ResNet-50检查点。你可以使用ModelZoo中 [resnet50](https://gitee.com/mindspore/models/tree/master/official/cv/resnet) 脚本来训练,然后使用src/convert_checkpoint.py把训练好的resnet50的权重文件转换为可加载的权重文件。 - -3. 启动Scheduler - - `run_cross_silo_femnist_sched.py`是用于启动`Scheduler`的Python脚本,并支持通过`argparse`传参修改配置。执行指令如下,代表启动本次联邦学习任务的`Scheduler`,其TCP端口为`6667`,联邦学习HTTP服务端口为`6668`,`Server`数量为`4`个,集群`Scheduler`管理端口为`11202`,`--config_file_path`用于设置配置文件路径,`--dataset_path`用于设置数据集绝对路径: - - ```sh - python run_cross_silo_fasterrcnn_sched.py --scheduler_ip=10.113.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=2 --scheduler_manage_port=11202 --config_file_path=$PWD/config.json --dataset_path=$PWD/datasets/coco_split/split_100/ - ``` - - 打印如下代表启动成功: - - ```sh - [INFO] PS(631,2b316a813700,python):2021-08-31-19:49:42.784.715 [mindspore/ccsrc/ps/core/communicator/http_request_handler.cc:92] Run] Start http server! - [INFO] PS(631,2b3084633a80,python):2021-08-31-19:49:42.796.904 [mindspore/ccsrc/ps/core/scheduler_node.cc:97] Initialize] [Scheduler start]: 2. The node role is:SCHEDULER, the node id is:e4b3c983-6d0c-470b-b487-1a247af97575 create a tcp server. - [INFO] PS(631,2b316a411700,python):2021-08-31-19:49:42.796.929 [mindspore/ccsrc/ps/core/scheduler_node.cc:129] operator()] The scheduler node start a tcp server! - [INFO] PS(631,2b3084633a80,python):2021-08-31-19:49:42.796.935 [mindspore/ccsrc/ps/core/scheduler_node.cc:410] StartUpdateClusterStateTimer] [Scheduler start]: 3. The scheduler start a heartbeat timer! - [INFO] PS(631,2b316a411700,python):2021-08-31-19:49:42.796.979 [mindspore/ccsrc/ps/core/communicator/tcp_server.cc:192] Start] Start tcp server! - ``` - -4. 启动Server - - `run_cross_silo_femnist_server.py`是用于启动若干`Server`的Python脚本,并支持通过`argparse`传参修改配置。执行指令如下,代表启动本次联邦学习任务的`Server`,其TCP端口为`6667`,联邦学习HTTP服务起始端口为`6668`,`Server`数量为`4`个,联邦学习任务正常进行需要的`worker`数量为`2`个: - - ```sh - python run_cross_silo_fasterrcnn_server.py --scheduler_ip=10.113.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=2 --start_fl_job_threshold=2 --update_model_ratio=1 --fl_iteration_num=30 --start_fl_job_time_window=300000000000 --update_model_time_window=300000000000 --config_file_path=$PWD/config.json --dataset_path=$PWD/datasets/coco_split/split_100/ - ``` - - 以上指令等价于启动了4个`Server`进程,每个`Server`的联邦学习服务端口分别为`6668`、`6669`、`6670`和`6671`,具体实现详见[脚本run_cross_silo_femnist_server.py](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/cross_silo_femnist/run_cross_silo_femnist_server.py)。 - - > 若只想在单机部署`Scheduler`以及`Server`,只需将`scheduler_ip`配置项修改为`127.0.0.1`即可。 - - 若想让`Server`分布式部署在不同物理节点,可以使用`local_server_num`参数,代表在**本节点**需要执行的`Server`进程数量: - - ```sh - # 在节点1启动3个Server进程 - python run_cross_silo_fasterrcnn_server.py --scheduler_ip={ip_address_node1} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=2 --start_fl_job_threshold=2 --update_model_ratio=1 --fl_iteration_num=30 --start_fl_job_time_window=300000000000 --update_model_time_window=300000000000 --config_file_path=$PWD/config.json --dataset_path=$PWD/datasets/coco_split/split_100/ --local_server_num=3 - ``` - - ```sh - # 在节点2启动1个Server进程 - python run_cross_silo_fasterrcnn_server.py --scheduler_ip={ip_address_node2} --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=2 --start_fl_job_threshold=2 --update_model_ratio=1 --fl_iteration_num=30 --start_fl_job_time_window=300000000000 --update_model_time_window=300000000000 --config_file_path=$PWD/config.json --dataset_path=$PWD/datasets/coco_split/split_100/ --local_server_num=1 - ``` - -5. 启动Worker - - `run_cross_silo_femnist_worker.py`是用于启动若干`worker`的Python脚本,并支持通过`argparse`传参修改配置。执行指令如下,代表启动本次联邦学习任务的`worker`,联邦学习任务正常进行需要的`worker`数量为`2`个: - - ```sh - python run_cross_silo_fasterrcnn_worker.py --scheduler_ip=10.113.216.124 --scheduler_port=6667 --fl_server_port=6668 --server_num=4 --worker_num=2 --client_epoch_num=1 --fl_iteration_num=30 --config_file_path=$PWD/config.json --dataset_path=$PWD/datasets/coco_split/split_100/ - ``` - - 如上指令,`--worker_num=2`代表启动两个客户端,且两个客户端使用的数据集分别为`datasets/coco_split/split_100/mindrecord_0`和`datasets/coco_split/split_100/mindrecord_1`,请根据`任务前准备`教程准备好对应客户端所需数据集。 - -当执行以上三个指令之后,等待一段时间之后,进入当前目录下`worker_0`文件夹,通过指令`grep -rn "\]epoch:" *`查看`worker_0`日志,可看到类似如下内容的日志信息: - -```sh -epoch: 1 step: 1 total_loss: 0.6060338 -``` - -则说明云云联邦启动成功,`worker_0`正在训练,其他worker可通过类似方式查看。 - -以上脚本中参数配置说明请参考[API文档](https://www.mindspore.cn/federated/docs/zh-CN/master/federated_server.html#mindspore.set_fl_context)。 - -### 日志查看 - -成功启动任务之后,会在当前目录`cross_silo_faster_rcnn`下生成相应日志文件,日志文件目录结构如下: - -```text -cross_silo_faster_rcnn -├── scheduler -│ └── scheduler.log # 运行scheduler过程中打印日志 -├── server_0 -│ └── server.log # server_0运行过程中打印日志 -├── server_1 -│ └── server.log # server_1运行过程中打印日志 -├── server_2 -│ └── server.log # server_2运行过程中打印日志 -├── server_3 -│ └── server.log # server_3运行过程中打印日志 -├── worker_0 -│ ├── ckpt # 存放worker_0在每个联邦学习迭代结束时获取的聚合后的模型ckpt -│ │ └── mindrecord_0 -│ │ ├── mindrecord_0-fast-rcnn-0epoch.ckpt -│ │ ├── mindrecord_0-fast-rcnn-1epoch.ckpt -│ │ │ -│ │ │ ...... -│ │ │ -│ │ └── mindrecord_0-fast-rcnn-29epoch.ckpt -│ ├──loss_0.log # 记录worker_0训练过程中的每个step的loss值 -│ └── worker.log # 记录worker_0参与联邦学习任务过程中输出日志 -└── worker_1 - ├── ckpt # 存放worker_1在每个联邦学习迭代结束时获取的聚合后的模型ckpt - │ └── mindrecord_1 - │ ├── mindrecord_1-fast-rcnn-0epoch.ckpt - │ ├── mindrecord_1-fast-rcnn-1epoch.ckpt - │ │ - │ │ ...... - │ │ - │ └── mindrecord_1-fast-rcnn-29epoch.ckpt - ├──loss_0.log # 记录worker_1训练过程中的每个step的loss值 - └── worker.log # 记录worker_1参与联邦学习任务过程中输出日志 -``` - -### 关闭任务 - -若想中途退出,则可用以下指令: - -```sh -python finish_cross_silo_fasterrcnn.py --scheduler_port=6667 -``` - -或者等待训练任务结束之后集群会自动退出,不需要手动关闭。 - -### 实验结果 - -- 使用数据: - - COCO数据集,拆分为100份,取前两份分别作为两个worker的数据集 - -- 客户端本地训练epoch数:1 - -- 云云联邦学习总迭代数: 30 - -- 实验结果(记录客户端本地训练过程中的loss值): - - 进入当前目录下`worker_0`文件夹,通过指令`grep -rn "\]epoch:" *`查看`worker_0`日志,可看到每个step输出的loss值,如下所示: - - ```sh - epoch: 1 step: 1 total_loss: 5.249325 - epoch: 1 step: 2 total_loss: 4.0856013 - epoch: 1 step: 3 total_loss: 2.6916502 - epoch: 1 step: 4 total_loss: 1.3917351 - epoch: 1 step: 5 total_loss: 0.8109232 - epoch: 1 step: 6 total_loss: 0.99101084 - epoch: 1 step: 7 total_loss: 1.7741735 - epoch: 1 step: 8 total_loss: 0.9517553 - epoch: 1 step: 9 total_loss: 1.7988946 - epoch: 1 step: 10 total_loss: 1.0213892 - epoch: 1 step: 11 total_loss: 1.1700443 - . - . - . - ``` - -worker_0和worker_1在30个迭代的训练过程中,统计每个step的训练loss变换柱状图如下[1]和[2]: - -worker_0和worker_1在30个迭代的训练过程中,统计每个epoch的平均loss (一个epoch中包含的所有step的loss之和除以step数)的折线图如下[3]和[4]: - -![cross-silo_fastrcnn-2workers-loss.png](images/cross-silo_fastrcnn-2workers-loss.png) diff --git a/docs/federated/docs/source_zh_cn/pairwise_encryption_training.md b/docs/federated/docs/source_zh_cn/pairwise_encryption_training.md deleted file mode 100644 index 2f938292fa548eb5aace021da8856fd418851c07..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/pairwise_encryption_training.md +++ /dev/null @@ -1,64 +0,0 @@ -# 安全聚合训练 - - - -联邦学习过程中,用户数据仅用于本地设备训练,不需要上传至中心服务器,可以避免用户个人数据的直接泄露。然而传统联邦学习框架中,模型以明文形式上云,仍然存在间接泄露用户隐私的风险。攻击者获取到用户上传的明文模型后,可以通过重构、模型逆向等攻击方式恢复用户的个人训练数据,导致用户隐私泄露。 - -MindSpore Federated联邦学习框架,提供了基于多方安全计算(MPC)的安全聚合算法,在本地模型上云前加上秘密扰动。在保证模型可用性的前提下,解决横向联邦学习中的隐私泄露和模型窃取问题。 - -## 原理概述 - -尽管差分隐私技术可以适当保护用户数据隐私,但是当参与客户端数量比较少或者高斯噪声幅值较大时,模型精度会受较大影响。为了同时满足模型保护和模型收敛这两个要求,我们提供了基于MPC的安全聚合方案。 - -在这种训练模式下,假设参与的客户端集合为$U$,对于任意客户端Client $u$和$v$, -它们会两两协商出一对随机扰动$p_{uv}$、$p_{vu}$,满足 - -$$ -p_{uv}=\begin{cases} -p_{vu}, &u{\neq}v\\\\ 0, &u=v \end{cases} -$$ - -于是每个客户端Client $u$ 在上传模型至服务端Server前,会在原模型权重$x_u$加上它与其它用户协商的扰动: - -$$ -x_{encrypt}=x_u+\sum\limits_{v{\in}U}p_{uv} -$$ - -从而服务端Server聚合结果$\overline{x}$为: - -$$ -\begin{align} -\overline{x}&=\sum\limits_{u{\in}U}(x_{u}+\sum\limits_{v{\in}U}p_{uv})\\\\ -&=\sum\limits_{u{\in}U}x_{u}+\sum\limits_{u{\in}U}\sum\limits_{v{\in}U}p_{uv}\\\\ -&=\sum\limits_{u{\in}U}x_{u} -\end{align} -$$ - -上述过程仅介绍了聚合算法的主要思想,基于MPC的聚合方案是精度无损的,代价是通讯轮次的增加。 - -如果您对算法的具体步骤感兴趣,可以参考原论文[1]。 - -## 使用方式 - -### 端云联邦场景 - -开启安全聚合训练的方式很简单,只需要在启动云侧服务时,通过`set_fl_context()`设置`encrypt_type='PW_ENCRYPT'`即可。 - -此外,由于端云联邦场景下,参与训练的Worker大多是手机等不稳定的边缘计算节点,所以要考虑计算节点的掉线和密钥恢复问题。与之相关的参数有`share_secrets_ratio`、`reconstruct_secrets_threshold`和`cipher_time_window`。 - -`share_client_ratio`指代公钥分发轮次、秘密分享轮次、秘钥恢复轮次的客户端阈值衰减比例,取值需要小于等于1。 - -`reconstruct_secrets_threshold`指代恢复秘密需要的碎片数量,取值需要小于参与updateModel的客户端数量(start_fl_job_threshold*update_model_ratio,这两个参数的解释详见[该文件](https://gitee.com/mindspore/mindspore/blob/master/mindspore/python/mindspore/context.py)中的set_fl_context函数)。 - -通常为了保证系统安全,当不考虑Server和Client合谋的情况下,`reconstruct_secrets_threshold`需要大于联邦学习客户端数量的一半;当考虑Server和Client合谋,`reconstruct_secrets_threshold`需要大于联邦学习客户端数量的2/3。 - -`cipher_time_window`指代安全聚合各通讯轮次的时长限制,主要用来保证某些客户端掉线的情况下,Server可以开始新一轮迭代。 - -### 云云联邦场景 - -在云云联邦场景下,在云侧启动脚本和端侧启动脚本中通过`set_fl_context()`设置`encrypt_type='STABLE_PW_ENCRYPT'`即可。 - -此外,与端云联邦不同的是,在云云联邦场景中,每个Worker都是稳定的服务器,所以不需要考虑掉线问题,因此只需要设置`cipher_time_window`这一超参。 - -## 参考文献 - -[1] Keith Bonawitz, Vladimir Ivanov, Ben Kreuter, et al. [Practical Secure Aggregationfor Privacy-Preserving Machine Learning](https://dl.acm.org/doi/pdf/10.1145/3133956.3133982). NeurIPS, 2016. diff --git a/docs/federated/docs/source_zh_cn/sentiment_classification_application.md b/docs/federated/docs/source_zh_cn/sentiment_classification_application.md deleted file mode 100644 index 5ce55d3acbedb95d57ba32349d65b75ca672bcf9..0000000000000000000000000000000000000000 --- a/docs/federated/docs/source_zh_cn/sentiment_classification_application.md +++ /dev/null @@ -1,551 +0,0 @@ -# 实现一个情感分类应用(Android) - - - -通过端云协同的联邦学习建模方式,可以充分发挥端侧数据的优势,避免用户敏感数据直接上传云侧。由于用户在使用输入法时,十分重视所输入文字的隐私,且输入法的智慧功能对提升用户体验非常需要。因此,联邦学习天然适用于输入法应用场景。 - -MindSpore Federated将联邦语言模型应用到了输入法的表情图片预测功能中。联邦语言模型会根据聊天文本数据推荐出适合当前语境的表情图片。在使用联邦学习建模时,每一张表情图片会被定义为一个情感标签类别,而每个聊天短语会对应一个表情图片。MindSpore Federated将表情图片预测任务定义为联邦情感分类任务。 - -## 准备环节 - -### 环境 - -参考[服务端环境配置](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_server.html)和[客户端环境配置](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_client.html)。 - -### 数据 - -[用于训练的数据](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/supervise/client.tar.gz)包含20个用户聊天文件,其目录结构如下: - -```text -datasets/supervise/client/ - ├── 0.txt # 用户0的训练数据 - ├── 1.txt # 用户1的训练数据 - │ - │ ...... - │ - └── 19.txt # 用户19的训练数据 -``` - -[用于验证的数据](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/supervise/eval.tar.gz)包含1个聊天文件,其目录结构如下: - -```text -datasets/supervise/eval/ - └── eval.txt # 验证数据 -``` - -用于训练和验证的数据中,标签包含4类表情:`good`、`leimu`、`xiaoku`、`xin`。 - -### 模型相关文件 - -模型相关的[词典](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/vocab.txt)和[词典ID映射文件](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/datasets/vocab_map_ids.txt)的目录结构如下: - -```text -models/ - ├── vocab.txt # 词典 - └── vocab_map_ids.txt # 词典ID映射文件 -``` - -## 定义网络 - -联邦学习中的语言模型使用ALBERT模型[1]。客户端上的ALBERT模型包括:embedding层、encoder层和classifier层。 - -具体网络定义请参考[源码](https://gitee.com/mindspore/mindspore/blob/master/tests/st/fl/albert/src/model.py)。 - -### 生成端侧模型文件 - -#### 将模型导出为MindIR格式文件 - -示例代码如下: - -```python -import argparse -import os -import random -from time import time -import numpy as np -import mindspore as ms -from mindspore.nn import AdamWeightDecay -from src.config import train_cfg, client_net_cfg -from src.utils import restore_params -from src.model import AlbertModelCLS -from src.cell_wrapper import NetworkWithCLSLoss, NetworkTrainCell - - -def parse_args(): - """ - parse args - """ - parser = argparse.ArgumentParser(description='export task') - parser.add_argument('--device_target', type=str, default='GPU', choices=['Ascend', 'GPU']) - parser.add_argument('--device_id', type=str, default='0') - parser.add_argument('--init_model_path', type=str, default='none') - parser.add_argument('--output_dir', type=str, default='./models/mindir/') - parser.add_argument('--seed', type=int, default=0) - return parser.parse_args() - - -def supervise_export(args_opt): - ms.set_seed(args_opt.seed), random.seed(args_opt.seed) - start = time() - # 参数配置 - os.environ['CUDA_VISIBLE_DEVICES'] = args_opt.device_id - init_model_path = args_opt.init_model_path - output_dir = args_opt.output_dir - if not os.path.exists(output_dir): - os.makedirs(output_dir) - print('Parameters setting is done! Time cost: {}'.format(time() - start)) - start = time() - - # MindSpore配置 - ms.set_context(mode=ms.GRAPH_MODE, device_target=args_opt.device_target) - print('Context setting is done! Time cost: {}'.format(time() - start)) - start = time() - - # 建立模型 - albert_model_cls = AlbertModelCLS(client_net_cfg) - network_with_cls_loss = NetworkWithCLSLoss(albert_model_cls) - network_with_cls_loss.set_train(True) - print('Model construction is done! Time cost: {}'.format(time() - start)) - start = time() - - # 建立优化器 - client_params = [_ for _ in network_with_cls_loss.trainable_params()] - client_decay_params = list( - filter(train_cfg.optimizer_cfg.AdamWeightDecay.decay_filter, client_params) - ) - client_other_params = list( - filter(lambda x: not train_cfg.optimizer_cfg.AdamWeightDecay.decay_filter(x), client_params) - ) - client_group_params = [ - {'params': client_decay_params, 'weight_decay': train_cfg.optimizer_cfg.AdamWeightDecay.weight_decay}, - {'params': client_other_params, 'weight_decay': 0.0}, - {'order_params': client_params} - ] - client_optimizer = AdamWeightDecay(client_group_params, - learning_rate=train_cfg.client_cfg.learning_rate, - eps=train_cfg.optimizer_cfg.AdamWeightDecay.eps) - client_network_train_cell = NetworkTrainCell(network_with_cls_loss, optimizer=client_optimizer) - print('Optimizer construction is done! Time cost: {}'.format(time() - start)) - start = time() - - # 构造数据 - input_ids = ms.Tensor(np.zeros((train_cfg.batch_size, client_net_cfg.seq_length), np.int32)) - attention_mask = ms.Tensor(np.zeros((train_cfg.batch_size, client_net_cfg.seq_length), np.int32)) - token_type_ids = ms.Tensor(np.zeros((train_cfg.batch_size, client_net_cfg.seq_length), np.int32)) - label_ids = ms.Tensor(np.zeros((train_cfg.batch_size,), np.int32)) - print('Client data loading is done! Time cost: {}'.format(time() - start)) - start = time() - - # 读取checkpoint - if init_model_path != 'none': - init_param_dict = ms.load_checkpoint(init_model_path) - restore_params(client_network_train_cell, init_param_dict) - print('Checkpoint loading is done! Time cost: {}'.format(time() - start)) - start = time() - - # 导出 - ms.export(client_network_train_cell, input_ids, attention_mask, token_type_ids, label_ids, - file_name=os.path.join(output_dir, 'albert_supervise'), file_format='MINDIR') - print('Supervise model export process is done! Time cost: {}'.format(time() - start)) - - -if __name__ == '__main__': - total_time_start = time() - args = parse_args() - supervise_export(args) - print('All is done! Time cost: {}'.format(time() - total_time_start)) - -``` - -#### 将MindIR文件转化为联邦学习端侧框架可用的ms文件 - -参考[图像分类应用](https://www.mindspore.cn/federated/docs/zh-CN/master/image_classification_application.html)中生成端侧模型文件部分。 - -## 启动联邦学习流程 - -首先在服务端启动脚本,参考[云端部署方式](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_server.html)。 - -以ALBERT模型的训练与推理任务为基础,整体流程为: - -1. Android新建工程; - -2. 编译MindSpore Lite AAR包; - -3. Android实例程序结构说明; - -4. 编写代码; - -5. Android工程配置依赖项; - -6. Android构建与运行。 - -### Android新建工程 - -在Android Studio中新建项目工程,并安装相应的SDK(指定SDK版本后,由Android Studio自动安装)。 - -![新建工程](./images/create_android_project.png) - -### 编译MindSpore Lite AAR包 - -1. 参考[端侧部署](https://www.mindspore.cn/federated/docs/zh-CN/master/deploy_federated_client.html)完成部署。 - -2. 获取生成的Android AAR包。 - - ```text - mindspore-lite-full-{version}.aar - ``` - -3. 将AAR包放置安卓工程的app/libs/目录下。 - -### Android实例程序结构说明 - -```text -app -│ ├── libs # Android库项目的二进制归档文件 -| | └── mindspore-lite-full-{version}.aar # MindSpore Lite针对Android版本的归档文件 -├── src/main -│ ├── assets # 资源目录 -| | └── model # 模型目录 -| | └── albert_supervise.mindir.ms # 存放的预训练模型文件 -│ | └── albert_inference.mindir.ms # 存放的推理模型文件 -│ | └── data # 数据目录 -| | └── 0.txt # 训练数据文件 -| | └── vocab.txt # 词典文件 -| | └── vocab_map_ids.txt # 词典ID映射文件 -| | └── eval.txt # 训练结果评估文件 -| | └── eval_no_label.txt # 推理数据文件 -│ | -│ ├── java # java层应用代码 -│ │ └── ... 存放Android代码文件,相关目录可以自定义 -│ │ -│ ├── res # 存放Android相关的资源文件 -│ └── AndroidManifest.xml # Android配置文件 -│ -│ -├── build.gradle # Android工程构建配置文件 -├── download.gradle # 工程依赖文件下载 -└── ... -``` - -### 编写代码 - -1. AssetCopyer.java:该代码文件作用是把Android工程的app/src/main/assets目录下的资源文件存放到Android系统的磁盘中,以便在模型训练与推理时联邦学习框架的接口能够根据绝对路径读取到资源文件。 - - ```java - import android.content.Context; - import java.io.File; - import java.io.FileOutputStream; - import java.io.InputStream; - import java.util.logging.Logger; - public class AssetCopyer { - private static final Logger LOGGER = Logger.getLogger(AssetCopyer.class.toString()); - public static void copyAllAssets(Context context,String destination) { - LOGGER.info("destination: " + destination); - copyAssetsToDst(context,"",destination); - } - // copy assets目录下面的资源文件到Android系统的磁盘中,具体的路径可打印destination查看 - private static void copyAssetsToDst(Context context,String srcPath, String dstPath) { - try { - // 递归获取assets目录的所有的文件名 - String[] fileNames =context.getAssets().list(srcPath); - if (fileNames.length > 0) { - // 构建目标file对象 - File file = new File(dstPath); - //创建目标目录 - file.mkdirs(); - for (String fileName : fileNames) { - // copy文件到指定的磁盘 - if(!srcPath.equals("")) { - copyAssetsToDst(context,srcPath + "/" + fileName,dstPath+"/"+fileName); - }else{ - copyAssetsToDst(context, fileName,dstPath+"/"+fileName); - } - } - } else { - // 构建源文件的输入流 - InputStream is = context.getAssets().open(srcPath); - // 构建目标文件的输出流 - FileOutputStream fos = new FileOutputStream(new File(dstPath)); - // 定义1024大小的缓冲数组 - byte[] buffer = new byte[1024]; - int byteCount=0; - // 源文件写到目标文件 - while((byteCount=is.read(buffer))!=-1) { - fos.write(buffer, 0, byteCount); - } - // 刷新输出流 - fos.flush(); - // 关闭输入流 - is.close(); - // 关闭输出流 - fos.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - ``` - -2. FlJob.java:该代码文件作用是定义训练与推理任务的内容,具体的联邦学习接口含义请参考[联邦学习接口介绍](https://www.mindspore.cn/federated/docs/zh-CN/master/interface_description_federated_client.html)。 - - ```java - import android.annotation.SuppressLint; - import android.os.Build; - import androidx.annotation.RequiresApi; - import com.mindspore.flAndroid.utils.AssetCopyer; - import com.mindspore.flclient.FLParameter; - import com.mindspore.flclient.SyncFLJob; - import java.util.Arrays; - import java.util.UUID; - import java.util.logging.Logger; - public class FlJob { - private static final Logger LOGGER = Logger.getLogger(AssetCopyer.class.toString()); - private final String parentPath; - public FlJob(String parentPath) { - this.parentPath = parentPath; - } - // Android的联邦学习训练任务 - @SuppressLint("NewApi") - @RequiresApi(api = Build.VERSION_CODES.M) - public void syncJobTrain() { - // 构造dataMap - String trainTxtPath = "data/albert/supervise/client/1.txt"; - String evalTxtPath = "data/albert/supervise/eval/eval.txt"; // 非必须,getModel之后不进行验证可不设置 - String vocabFile = "data/albert/supervise/vocab.txt"; // 数据预处理的词典文件路径 - String idsFile = "data/albert/supervise/vocab_map_ids.txt" // 词典的映射id文件路径 - Map> dataMap = new HashMap<>(); - List trainPath = new ArrayList<>(); - trainPath.add(trainTxtPath); - trainPath.add(vocabFile); - trainPath.add(idsFile); - List evalPath = new ArrayList<>(); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(evalTxtPath); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(vocabFile); // 非必须,getModel之后不进行验证可不设置 - evalPath.add(idsFile); // 非必须,getModel之后不进行验证可不设置 - dataMap.put(RunType.TRAINMODE, trainPath); - dataMap.put(RunType.EVALMODE, evalPath); // 非必须,getModel之后不进行验证可不设置 - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // AlBertClient.java 包路径 - String trainModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // 绝对路径 - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // 绝对路径, 和trainModelPath保持一致 - String sslProtocol = "TLSv1.2"; - String deployEnv = "android"; - - // 端云通信url,请保证Android能够访问到server,否则会出现connection failed - String domainName = "http://10.113.216.106:6668"; - boolean ifUseElb = true; - int serverNum = 4; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setTrainModelPath(trainModelPath); - flParameter.setInferModelPath(inferModelPath); - flParameter.setSslProtocol(sslProtocol); - flParameter.setDeployEnv(deployEnv); - flParameter.setDomainName(domainName); - flParameter.setUseElb(ifUseElb); - flParameter.setServerNum(serverNum); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(BindMode.valueOf(cpuBindMode)); - - // start FLJob - SyncFLJob syncFLJob = new SyncFLJob(); - syncFLJob.flJobRun(); - } - // Android的联邦学习推理任务 - public void syncJobPredict() { - // 构造dataMap - String inferTxtPath = "data/albert/supervise/eval/eval.txt"; - String vocabFile = "data/albert/supervise/vocab.txt"; - String idsFile = "data/albert/supervise/vocab_map_ids.txt"; - Map> dataMap = new HashMap<>(); - List inferPath = new ArrayList<>(); - inferPath.add(inferTxtPath); - inferPath.add(vocabFile); - inferPath.add(idsFile); - dataMap.put(RunType.INFERMODE, inferPath); - - String flName = "com.mindspore.flclient.demo.albert.AlbertClient"; // AlBertClient.java 包路径 - String inferModelPath = "ms/albert/train/albert_ad_train.mindir0.ms"; // 绝对路径, 和trainModelPath保持一致; - int threadNum = 4; - BindMode cpuBindMode = BindMode.NOT_BINDING_CORE; - int batchSize = 32; - - FLParameter flParameter = FLParameter.getInstance(); - flParameter.setFlName(flName); - flParameter.setDataMap(dataMap); - flParameter.setInferModelPath(inferModelPath); - flParameter.setThreadNum(threadNum); - flParameter.setCpuBindMode(cpuBindMode); - flParameter.setBatchSize(batchSize); - - // inference - SyncFLJob syncFLJob = new SyncFLJob(); - int[] labels = syncFLJob.modelInference(); - LOGGER.info("labels = " + Arrays.toString(labels)); - } - } - ``` - - 上面的eval_no_label.txt是指不存在标签的文件,每一行为一条语句,格式参考如下,用户可自由设置: - - ```text - 愿以吾辈之青春 护卫这盛世之中华🇨🇳 - girls help girls - 太美了,祝祖国繁荣昌盛! - 中国人民站起来了 - 难道就我一个人觉得这个是plus版本? - 被安利到啦!明天起来就看!早点睡觉莲莲 - ``` - -3. MainActivity.java:该代码文件作用是启动联邦学习训练与推理任务。 - - ```java - import android.os.Build; - import android.os.Bundle; - import androidx.annotation.RequiresApi; - import androidx.appcompat.app.AppCompatActivity; - import com.mindspore.flAndroid.job.FlJob; - import com.mindspore.flAndroid.utils.AssetCopyer; - @RequiresApi(api = Build.VERSION_CODES.P) - public class MainActivity extends AppCompatActivity { - private String parentPath; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // 获取该应用程序在Android系统中的磁盘路径 - this.parentPath = this.getExternalFilesDir(null).getAbsolutePath(); - // copy assets目录下面的资源文件到Android系统的磁盘中 - AssetCopyer.copyAllAssets(this.getApplicationContext(), parentPath); - // 新建一个线程,启动联邦学习训练与推理任务 - new Thread(() -> { - FlJob flJob = new FlJob(parentPath); - flJob.syncJobTrain(); - flJob.syncJobPredict(); - }).start(); - } - } - ``` - -### Android工程配置依赖项 - -1. AndroidManifest.xml - - ```xml - - - - - - - - - - - - - - - ``` - -2. app/build.gradle - - ```text - plugins { - id 'com.android.application' - } - android { - // Android SDK的编译版本,建议大于27 - compileSdkVersion 30 - buildToolsVersion "30.0.3" - defaultConfig { - applicationId "com.mindspore.flAndroid" - minSdkVersion 27 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" - multiDexEnabled true - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - ndk { - // 不同的手机型号,对应ndk不相同,本人使用的mate20手机是'armeabi-v7a' - abiFilters 'armeabi-v7a' - } - } - //指定ndk版本 - ndkVersion '21.3.6528147' - sourceSets{ - main { - // 指定jni目录 - jniLibs.srcDirs = ['libs'] - jni.srcDirs = [] - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - } - dependencies { - //指定扫描libs目录下的AAR包 - implementation fileTree(dir:'libs',include:['*.aar']) - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation 'com.android.support:multidex:1.0.3' - - //添加联邦学习所依赖的第三方开源软件 - implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.14.9' - implementation group: 'com.google.flatbuffers', name: 'flatbuffers-java', version: '2.0.0' - implementation(group: 'org.bouncycastle',name: 'bcprov-jdk15on', version: '1.68') - } - ``` - -### Android构建与运行 - -1. 连接Android设备,运行联邦学习训练与推理应用程序。通过USB连接Android设备调试,点击`Run 'app'`即可在你的设备上运行联邦学习任务。 - - ![run_app](./images/start_android_project.png) - -2. Android Studio连接设备调试操作,可参考。手机需开启“USB调试模式”,Android Studio才能识别到手机。 华为手机一般在`设置->系统和更新->开发人员选项->USB调试`中打开“USB调试模式”。 - -3. 在Android设备上,点击“继续安装”,安装完即可在APP启动之后执行ALBERT模型的联邦学习的训练与推理任务。 - -4. 程序运行结果如下: - - ```text - I/SyncFLJob: [model inference] inference finish - I/SyncFLJob: labels = [2, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4] - ``` - -## 实验结果 - -联邦学习总迭代数为10,客户端本地训练epoch数为1,batchSize设置为16。 - -```text - total acc:0.44488978 - total acc:0.583166333 - total acc:0.609218437 - total acc:0.645290581 - total acc:0.667334669 - total acc:0.685370741 - total acc:0.70741483 - total acc:0.711422846 - total acc:0.719438878 - total acc:0.733466934 -``` - -## 参考文献 - -[1] Lan Z , Chen M , Goodman S , et al. ALBERT: A Lite BERT for Self-supervised Learning of Language Representations[J]. 2019. diff --git a/docs/golden_stick/docs/source_en/index.rst b/docs/golden_stick/docs/source_en/index.rst index f7ea35d2dbc5e7d60e62f35107b4c1c2c8d427e7..c8d6c46ccba18495a2dfffb6f3942d8684ec836e 100644 --- a/docs/golden_stick/docs/source_en/index.rst +++ b/docs/golden_stick/docs/source_en/index.rst @@ -5,7 +5,7 @@ MindSpore Golden Stick is a model compression algorithm set jointly designed and .. raw:: html - + 1. The underlying MindSpore Rewrite module provides the ability to modify the front-end network. Based on the interface provided by this module, algorithm developers can add, delete, query and modify the nodes and topology relationships of the MindSpore front-end network according to specific rules; @@ -38,7 +38,7 @@ General Process of Applying the MindSpore Golden Stick .. raw:: html - + 1. Training @@ -46,7 +46,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 @@ -54,9 +54,8 @@ 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 "network training or retraining" step in the process, see `MindSpore Training and Evaluation `_ . - - 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 "ms.export" step in the process, see `Exporting MINDIR Model `_ . + - For details about the "MindSpore infer" step in the process, see `MindSpore Inference Runtime `_ . Roadmap --------------------------------------- diff --git a/docs/golden_stick/docs/source_en/install.md b/docs/golden_stick/docs/source_en/install.md index e8c53e1540b3d106b6277a77ddb11230df38c0a0..cb72966a02a807174086c20221fee229d6907159 100644 --- a/docs/golden_stick/docs/source_en/install.md +++ b/docs/golden_stick/docs/source_en/install.md @@ -1,6 +1,6 @@ # Installing MindSpore Golden Stick - + ## Environmental restrictions @@ -11,7 +11,7 @@ The following table lists the environment required for installing, compiling and | Ubuntu | 18.04 | | Python | 3.7-3.9 | -> Please refer to [requirements](https://gitee.com/mindspore/golden-stick/blob/master/requirements.txt) for other third party dependencies. +> Please refer to [requirements](https://gitee.com/mindspore/golden-stick/blob/r0.2/requirements.txt) for other third party dependencies. > MindSpore Golden Stick can only run on Ubuntu18.04. ## Version dependency @@ -20,7 +20,7 @@ The MindSpore Golden Stick depends on the MindSpore training and inference frame | MindSpore Golden Stick Version | Branch | MindSpore version | | :-----------------------------: | :----------------------------------------------------------: | :-------: | -| 0.1.0 | [r0.1](https://gitee.com/mindspore/golden-stick/tree/r0.1/) | 1.8.0 | +| 0.2.0 | [r0.2](https://gitee.com/mindspore/golden-stick/tree/r0.2/) | 1.9.0 | After MindSpore is installed, you can use pip or source code build for MindSpore Golden Stick installation. diff --git a/docs/golden_stick/docs/source_en/pruner/overview.md b/docs/golden_stick/docs/source_en/pruner/overview.md index a8b990184f129094c8b3f6103c4be2fad6ad71c8..1f51b1d4ac9e5e404e1bf559a5b9322574482364 100644 --- a/docs/golden_stick/docs/source_en/pruner/overview.md +++ b/docs/golden_stick/docs/source_en/pruner/overview.md @@ -1,6 +1,6 @@ # Pruning Algorithm Overview - + The following describes some basic concepts of pruning algorithms to help users understand the pruning algorithms. If you have a deep understanding of pruning algorithms, skip to [Examples](#examples). @@ -20,4 +20,4 @@ Channel pruning and filter pruning are generally considered to be structured pru ## Examples -In the current version, the MindSpore Golden Stick provides a structured weight pruning algorithm. For details, see [SCOP Algorithm Example](https://www.mindspore.cn/golden_stick/docs/en/master/pruner/scop.html). +In the current version, the MindSpore Golden Stick provides a structured weight pruning algorithm. For details, see [SCOP Algorithm Example](https://www.mindspore.cn/golden_stick/docs/en/r0.2/pruner/scop.html). diff --git a/docs/golden_stick/docs/source_en/pruner/scop.md b/docs/golden_stick/docs/source_en/pruner/scop.md index 4942a6ea2ee4f565eb24f7cacb511da5654a9536..75777b4bfbbd4fc156466611222115947fadbf9f 100644 --- a/docs/golden_stick/docs/source_en/pruner/scop.md +++ b/docs/golden_stick/docs/source_en/pruner/scop.md @@ -1,6 +1,6 @@ # Applying the SCOP Algorithm - + ## Background @@ -25,7 +25,7 @@ Table 1: SCOP training specifications | Specifications | Description | | ------------ | ------------------------------------------------------------ | | Hardware | GPU and Ascend AI 910 Processor hardware platforms | -| Networks | ResNet series networks. For details, see .| +| Networks | ResNet series networks. For details, see .| | Algorithms | Structured pruning algorithms | | Data types| The Ascend and the GPU platforms support pruning training on FP32 networks.| | Running modes| Graph mode and PyNative mode | @@ -42,11 +42,11 @@ SCOP training consists of the knockoff and fine-tuning phases. In the knockoff p Then, ResNet-50 is used as an example to describe steps related to SCOP training in detail. -> You can find the complete executable sample code here: . +> You can find the complete executable sample code here: . ### Knockoff Data -Initialize the ResNet-50, load the pre-trained model, replace nodes using PrunerKfCompressAlgo to obtain the network in the knockoff phase (For details, users can refer to [API](https://gitee.com/mindspore/golden-stick/blob/master/mindspore_gs/pruner/scop/scop_pruner.py)), and train the network. +Initialize the ResNet-50, load the pre-trained model, replace nodes using PrunerKfCompressAlgo to obtain the network in the knockoff phase (For details, users can refer to [API](https://gitee.com/mindspore/golden-stick/blob/r0.2/mindspore_gs/pruner/scop/scop_pruner.py)), and train the network. ```python from mindspore import ModelCheckpoint, CheckpointConfig, LossMonitor, TimeMonitor @@ -95,7 +95,7 @@ step_5: loss=4.715785 ### Fine-tuning -Determine the redundant convolution kernels in the knockoff phase. Use PrunerFtCompressAlgo to replace nodes (For details, users can refer to [API](https://gitee.com/mindspore/golden-stick/blob/master/mindspore_gs/pruner/scop/scop_pruner.py)) and delete redundant convolution kernels. Perform the complete training and save the model. +Determine the redundant convolution kernels in the knockoff phase. Use PrunerFtCompressAlgo to replace nodes (For details, users can refer to [API](https://gitee.com/mindspore/golden-stick/blob/r0.2/mindspore_gs/pruner/scop/scop_pruner.py)) and delete redundant convolution kernels. Perform the complete training and save the model. ```python from mindspore_gs import Kf_Conv2d @@ -163,7 +163,7 @@ epoch: 1 step: 11, loss is 1.572392225265503 ### Loading the Saved Model for Evaluation ```python -from mindspore import Tensor, context, load_checkpoint, load_param_into_net, export +from mindspore import Tensor, set_context, load_checkpoint, load_param_into_net, export if __name__ == "__main__": ... @@ -200,7 +200,7 @@ The quantization model deployed on the device-side hardware platform is in the g 3. Export the pruned model. ```python -from mindspore import Tensor, context, load_checkpoint, load_param_into_net, export +from mindspore import Tensor, set_context, load_checkpoint, load_param_into_net, export if __name__ == "__main__": ... @@ -218,7 +218,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/tutorials/experts/en/r1.9/infer/inference.html). ## SCOP Effect diff --git a/docs/golden_stick/docs/source_en/quantization/overview.md b/docs/golden_stick/docs/source_en/quantization/overview.md index 1aecc13026cd7f97e86a875fded4f792d8dc1732..1b3fd6c8d805f3bb160a6a92efb589022bb3747d 100644 --- a/docs/golden_stick/docs/source_en/quantization/overview.md +++ b/docs/golden_stick/docs/source_en/quantization/overview.md @@ -1,6 +1,6 @@ # Quantization Algorithm Overview - + The following describes some basic concepts of quantization algorithms to help users understand the quantization algorithms. If you have a deep understanding of the quantization algorithm, skip to [Examples](#examples). @@ -32,5 +32,5 @@ Currently, there are two types of quantization solutions in the industry: **quan ## Examples -- [SimQAT algorithm](https://www.mindspore.cn/golden_stick/docs/en/master/quantization/simqat.html): A basic quantization aware algorithm based on the fake quantization technology -- [SLB quantization algorithm](https://www.mindspore.cn/golden_stick/docs/en/master/quantization/slb.html): A non-linear low-bit quantization aware algorithm +- [SimQAT algorithm](https://www.mindspore.cn/golden_stick/docs/en/r0.2/quantization/simqat.html): A basic quantization aware algorithm based on the fake quantization technology +- [SLB quantization algorithm](https://www.mindspore.cn/golden_stick/docs/en/r0.2/quantization/slb.html): A non-linear low-bit quantization aware algorithm diff --git a/docs/golden_stick/docs/source_en/quantization/simqat.md b/docs/golden_stick/docs/source_en/quantization/simqat.md index 9e21520da523845410a30aac9a983eea7dc0af1d..9b9d6b33a78a616e76d45d26da8fb0d829d2e533 100644 --- a/docs/golden_stick/docs/source_en/quantization/simqat.md +++ b/docs/golden_stick/docs/source_en/quantization/simqat.md @@ -1,6 +1,6 @@ # Applying the SimQAT Algorithm - + ## Background @@ -36,7 +36,7 @@ Table 1: Quantization aware training specifications | Specifications| Description| | --- | --- | | Hardware| GPU | -| Networks| The supported networks include LeNet and ResNet-50. For details, see .| +| Networks| The supported networks include LeNet and ResNet-50. For details, see .| | Algorithms| Asymmetric, symmetric, layer-by-layer, and channel-by-channel quantization algorithms.| | Solutions| 8-bit quantization solution| | Data types| The GPU platform supports FP32.| @@ -55,7 +55,7 @@ The procedure of quantization aware training is basically the same as that of co The following uses the LeNet5 as an example to describe these steps. -> For the complete code, see the [LeNet model repository](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/README.md#apply-algorithm-in-mindspore-golden-stick).The [train.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/golden_stick/quantization/simqat/train.py) is the complete training code, and the [eval.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/golden_stick/quantization/simqat/eval.py) is the accuracy verification code. +> For the complete code, see the [LeNet model repository](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/README.md#apply-algorithm-in-mindspore-golden-stick).The [train.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/golden_stick/quantization/simqat/train.py) is the complete training code, and the [eval.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/golden_stick/quantization/simqat/eval.py) is the accuracy verification code. ### Loading a Dataset @@ -65,8 +65,8 @@ Load MNIST dataset using MindData: ds_train = create_dataset(os.path.join(config.data_path), config.batch_size) ``` -In the code, `create_dataset` is referenced from [dataset.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/src/dataset.py). - `config.data_path` and `config.batch_size` are configured in the [configuration file](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/golden_stick/quantization/simqat/lenet_mnist_config.yaml). +In the code, `create_dataset` is referenced from [dataset.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/src/dataset.py). + `config.data_path` and `config.batch_size` are configured in the [configuration file](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/golden_stick/quantization/simqat/lenet_mnist_config.yaml). ### Defining the Original Network @@ -94,7 +94,7 @@ LeNet5< > ``` -For details about the ResNet-5 definition, see [lenet.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/src/lenet.py). +For details about the ResNet-5 definition, see [lenet.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/src/lenet.py). ### Applying the Quantization Algorithm @@ -109,7 +109,7 @@ quanted_network = algo.apply(network) print(quanted_network) ``` -The quantized network structure is as follows. QuantizerWrapperCell is the encapsulation class of perceptual quantization training for the original Conv2d or Dense, including the original operator and pseudo-quantization nodes of input, output and weight. Users can refer to [API](https://www.mindspore.cn/golden_stick/docs/en/master/quantization/mindspore_gs.quantization.SimulatedQuantizationAwareTraining.html#mindspore_gs.quantization.SimulatedQuantizationAwareTraining) to modify the algorithm configuration, and verify that the algorithm is configured successfully by checking the QuantizeWrapperCell properties. +The quantized network structure is as follows. QuantizerWrapperCell is the encapsulation class of perceptual quantization training for the original Conv2d or Dense, including the original operator and pseudo-quantization nodes of input, output and weight. Users can refer to [API](https://www.mindspore.cn/golden_stick/docs/en/r0.2/quantization/mindspore_gs.quantization.SimulatedQuantizationAwareTraining.html#mindspore_gs.quantization.SimulatedQuantizationAwareTraining) to modify the algorithm configuration, and verify that the algorithm is configured successfully by checking the QuantizeWrapperCell properties. ```text LeNet5Opt< @@ -207,7 +207,7 @@ Train epoch time: 8544.641 ms, per step time: 4.552 ms ### Evaluate network and comparing the accuracy -Obtain the accuracy of the common training network according to the steps in the [LeNet model repository](https://gitee.com/mindspore/models/tree/master/official/cv/lenet). +Obtain the accuracy of the common training network according to the steps in the [LeNet model repository](https://gitee.com/mindspore/models/tree/r1.9/official/cv/lenet). ```text 'Accuracy':0.9842 diff --git a/docs/golden_stick/docs/source_en/quantization/slb.md b/docs/golden_stick/docs/source_en/quantization/slb.md index cc21d62b42493c7a05050c761d0794965efac2f8..e6c69fa2b8bba10316398353d1b3f7c2e6f58964 100644 --- a/docs/golden_stick/docs/source_en/quantization/slb.md +++ b/docs/golden_stick/docs/source_en/quantization/slb.md @@ -1,6 +1,6 @@ # Applying the SLB Algorithm - + ## Background @@ -42,7 +42,7 @@ Table 1: SLB quantization training specifications | Specifications| Description| | --- | --- | | Hardware| GPU | -| Networks| ResNet-18. For details, see .| +| Networks| ResNet-18. For details, see .| | Solutions| Supports 1-, 2-, and 4-bit weight quantization solutions.| | Data types| The GPU platform supports FP32.| | Running modes| Graph mode and PyNative mode| @@ -60,7 +60,7 @@ The procedure of SLB quantization training is the same as that of common trainin The following uses the LeNet-18 as an example to describe these steps. -> For details about the complete code, see [ResNet model repository](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/README.md#apply-algorithm-in-mindspore-golden-stick). [train.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/train.py) is the complete training code, and [eval.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/eval.py) is the accuracy verification code. +> For details about the complete code, see [ResNet model repository](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/README.md#apply-algorithm-in-mindspore-golden-stick). [train.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/train.py) is the complete training code, and [eval.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/eval.py) is the accuracy verification code. ### Loading a Dataset @@ -71,7 +71,7 @@ dataset = create_dataset(dataset_path=config.data_path, do_train=True, distribute=config.run_distribute) ``` -In the code, `create_dataset` is referenced from [dataset.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/src/dataset.py), and `config.data_path` and `config.batch_size` are configured in the [configuration file](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/resnet18_cifar10_config.yaml). +In the code, `create_dataset` is referenced from [dataset.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/src/dataset.py), and `config.data_path` and `config.batch_size` are configured in the [configuration file](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/resnet18_cifar10_config.yaml). ### Defining the Original Network @@ -115,7 +115,7 @@ ResNet< > ``` -For details about the ResNet-18 definition, see [resnet.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/src/resnet.py). +For details about the ResNet-18 definition, see [resnet.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/src/resnet.py). ### Applying the Quantization Algorithm @@ -145,7 +145,7 @@ Print the quantizer. The following information is displayed, including the confi SlbQuantAwareTraining ``` -The quantized network structure is as follows, QuantizeWrapperCell is the encapsulation class of SLB quantization to the original Conv2d, including the pseudo-quantization node of the original operator and weight. Users can modify the algorithm configuration by referring to [API](https://www.mindspore.cn/golden_stick/docs/en/master/quantization/mindspore_gs.quantization.SlbQuantAwareTraining.html#mindspore_gs.quantization.SlbQuantAwareTraining) and confirm whether the algorithm is configured successfully by checking the attributes of the QuantizeWrapperCell. +The quantized network structure is as follows, QuantizeWrapperCell is the encapsulation class of SLB quantization to the original Conv2d, including the pseudo-quantization node of the original operator and weight. Users can modify the algorithm configuration by referring to [API](https://www.mindspore.cn/golden_stick/docs/en/r0.2/quantization/mindspore_gs.quantization.SlbQuantAwareTraining.html#mindspore_gs.quantization.SlbQuantAwareTraining) and confirm whether the algorithm is configured successfully by checking the attributes of the QuantizeWrapperCell. ```text ResNetOpt< @@ -262,7 +262,7 @@ ckpt_cb = ModelCheckpoint(prefix="resnet", directory="./ckpt", config=config_ck) cb += [ckpt_cb] ``` -In the code, `get_lr` is referenced from [lr_generator.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/src/lr_generator.py), and `init_group_params` and `init_loss_scale` are referenced from [train.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/train.py). +In the code, `get_lr` is referenced from [lr_generator.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/src/lr_generator.py), and `init_group_params` and `init_loss_scale` are referenced from [train.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/train.py). ### Training the Model and Saving the Model File @@ -293,7 +293,7 @@ Train epoch time: 94106.722 ms, per step time: 60.248 ms ### Loading the Model and Comparing the Accuracy -Obtain the accuracy of the common training model according to the steps in the [ResNet model repository](https://gitee.com/mindspore/models/tree/master/official/cv/resnet). +Obtain the accuracy of the common training model according to the steps in the [ResNet model repository](https://gitee.com/mindspore/models/tree/r1.9/official/cv/resnet). ```text 'top_1_accuracy': 0.9544270833333334, 'top_5_accuracy': 0.9969951923076923 diff --git a/docs/golden_stick/docs/source_zh_cn/conf.py b/docs/golden_stick/docs/source_zh_cn/conf.py index 83399a7ac757074a4395843ba80de652d27a1544..7f36e7950e06e0898497618cd4e3d144fed17364 100644 --- a/docs/golden_stick/docs/source_zh_cn/conf.py +++ b/docs/golden_stick/docs/source_zh_cn/conf.py @@ -169,11 +169,11 @@ for root,dirs,files in os.walk(src_dir_api): if os.path.exists(os.path.join(moment_dir,file)): os.remove(os.path.join(moment_dir,file)) shutil.copy(os.path.join(root,file),os.path.join(moment_dir,file)) - if '/pruner/' in root: + if '/pruner' in root: if os.path.exists(os.path.join(moment_dir,'pruner',file)): os.remove(os.path.join(moment_dir,'pruner',file)) shutil.copy(os.path.join(root,file),os.path.join(moment_dir,'pruner',file)) - if '/quantization/' in root: + if '/quantization' in root: if os.path.exists(os.path.join(moment_dir,'quantization',file)): os.remove(os.path.join(moment_dir,'quantization',file)) shutil.copy(os.path.join(root,file),os.path.join(moment_dir,'quantization',file)) diff --git a/docs/golden_stick/docs/source_zh_cn/index.rst b/docs/golden_stick/docs/source_zh_cn/index.rst index 92dbfd4c5a6611a98eb9be1c226738c7d2109d0d..771234719c529674a39f0b219640b0f60c683655 100644 --- a/docs/golden_stick/docs/source_zh_cn/index.rst +++ b/docs/golden_stick/docs/source_zh_cn/index.rst @@ -5,7 +5,7 @@ MindSpore Golden Stick是华为诺亚团队和华为MindSpore团队联合设计 .. raw:: html - + 1. 底层的MindSpore Rewrite模块提供修改前端网络的能力,基于此模块提供的接口,算法开发者可以按照特定的规则对MindSpore的前端网络做节点和拓扑关系的增删查改; @@ -38,7 +38,7 @@ MindSpore Golden Stick除了提供丰富的模型压缩算法外,一个重要 .. raw:: html - + 1. 训练阶段 @@ -46,7 +46,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. 部署阶段 @@ -54,9 +54,8 @@ MindSpore Golden Stick除了提供丰富的模型压缩算法外,一个重要 .. note:: - 应用MindSpore Golden Stick算法的细节,可以在每个算法章节中找到详细说明和示例代码。 - - 流程中的"网络训练或重训"步骤可以参考 `MindSpore训练与评估 `_ 章节。 - - 流程中的"ms.export"步骤可以参考 `导出mindir格式文件 `_ 章节。 - - 流程中的"昇思推理优化工具和运行时"步骤可以参考 `昇思推理 `_ 章节。 + - 流程中的"ms.export"步骤可以参考 `导出mindir格式文件 `_ 章节。 + - 流程中的"昇思推理优化工具和运行时"步骤可以参考 `昇思推理 `_ 章节。 未来规划 ---------- diff --git a/docs/golden_stick/docs/source_zh_cn/install.md b/docs/golden_stick/docs/source_zh_cn/install.md index 1718c4a1fc4b0616c40bf2772fd27a128db2c923..3deec68a0037baf29d5fc0c96b66191e16582a79 100644 --- a/docs/golden_stick/docs/source_zh_cn/install.md +++ b/docs/golden_stick/docs/source_zh_cn/install.md @@ -1,6 +1,6 @@ # 安装MindSpore Golden Stick - + ## 环境限制 @@ -11,7 +11,7 @@ | Ubuntu | 18.04 | | Python | 3.7-3.9 | -> 其他的三方依赖请参考[requirements文件](https://gitee.com/mindspore/golden-stick/blob/master/requirements.txt)。 +> 其他的三方依赖请参考[requirements文件](https://gitee.com/mindspore/golden-stick/blob/r0.2/requirements.txt)。 > 当前MindSpore Golden Stick仅能在Ubuntu18.04上运行。 ## MindSpore版本依赖关系 @@ -20,7 +20,7 @@ MindSpore Golden Stick依赖MindSpore训练推理框架,请按照根据下表 | MindSpore Golden Stick版本 | 分支 | MindSpore版本 | | :---------------------: | :----------------------------------------------------------: | :-------: | -| 0.1.0 | [r0.1](https://gitee.com/mindspore/golden-stick/tree/r0.1/) | 1.8.0 | +| 0.2.0 | [r0.2](https://gitee.com/mindspore/golden-stick/tree/r0.2/) | 1.9.0 | 安装完MindSpore后,继续安装MindSpore Golden Stick。可以采用pip安装或者源码编译安装两种方式。 diff --git a/docs/golden_stick/docs/source_zh_cn/pruner/overview.md b/docs/golden_stick/docs/source_zh_cn/pruner/overview.md index aac174e80fa459799f598da04b9e7df98f5a6d6a..40c9d03b41ecb81b08ba9435a1eefdd49af1f6d8 100644 --- a/docs/golden_stick/docs/source_zh_cn/pruner/overview.md +++ b/docs/golden_stick/docs/source_zh_cn/pruner/overview.md @@ -1,6 +1,6 @@ # 剪枝算法概述 - + 本文是在介绍具体的剪枝算法之前,介绍一些剪枝算法的基本概念,帮助用户理解。如果已经对剪枝算法有较深的理解,可以直接跳转到[示例](#示例)小节。 @@ -20,4 +20,4 @@ ## 示例 -当前版本中,MindSpore Golden Stick提供了一个结构化权重剪枝算法,可以参考[SCOP剪枝算法示例](https://www.mindspore.cn/golden_stick/docs/zh-CN/master/pruner/scop.html)了解如何应用MindSpore Golden Stick中的剪枝算法。 +当前版本中,MindSpore Golden Stick提供了一个结构化权重剪枝算法,可以参考[SCOP剪枝算法示例](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/pruner/scop.html)了解如何应用MindSpore Golden Stick中的剪枝算法。 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 27fcdbc9ba1c79f5045f4240ad5f3cb7219b3b73..5bbcb55943253c57c5334edeb90be77ecac52d35 100644 --- a/docs/golden_stick/docs/source_zh_cn/pruner/scop.md +++ b/docs/golden_stick/docs/source_zh_cn/pruner/scop.md @@ -1,6 +1,6 @@ # 应用SCOP算法 - + ## 背景 @@ -25,7 +25,7 @@ SCOP采用数据驱动的方式,通过引入训练数据学习不同卷积核 | 规格 | 规格说明 | | ------------ | ------------------------------------------------------------ | | 硬件支持 | GPU、Ascend AI 910处理器的硬件平台 | -| 网络支持 | ResNet系列网络,具体请参见。 | +| 网络支持 | ResNet系列网络,具体请参见。 | | 算法支持 | 结构化的剪枝算法。 | | 数据类型支持 | Ascend和GPU平台支持精度为FP32的网络进行剪枝训练。 | | 运行模式支持 | Graph模式和PyNative模式 | @@ -42,11 +42,11 @@ SCOP训练分为Knockoff阶段和Finetune阶段,Knockoff阶段对应于前文 接下来,以ResNet50网络为例,展开叙述SCOP剪枝训练的相关步骤。 -> 你可以在这里找到完整可运行的样例代码: 。 +> 你可以在这里找到完整可运行的样例代码: 。 ### Knockoff Data阶段 -初始化ResNet50网络,加载预训练模型,通过PrunerKfCompressAlgo进行节点替换(详情用户可参考[API](https://gitee.com/mindspore/golden-stick/blob/master/mindspore_gs/pruner/scop/scop_pruner.py)),得到Knockoff阶段的网络,并进行训练。 +初始化ResNet50网络,加载预训练模型,通过PrunerKfCompressAlgo进行节点替换(详情用户可参考[API](https://gitee.com/mindspore/golden-stick/blob/r0.2/mindspore_gs/pruner/scop/scop_pruner.py)),得到Knockoff阶段的网络,并进行训练。 ```python from mindspore import ModelCheckpoint, CheckpointConfig, LossMonitor, TimeMonitor @@ -95,7 +95,7 @@ step_5: loss=4.715785 ### Finetune阶段 -通过Knockoff阶段确认冗余的卷积核,通过PrunerFtCompressAlgo进行节点替换(详情用户可参考[API](https://gitee.com/mindspore/golden-stick/blob/master/mindspore_gs/pruner/scop/scop_pruner.py))删除冗余卷积核,进行完整的训练并保存模型。 +通过Knockoff阶段确认冗余的卷积核,通过PrunerFtCompressAlgo进行节点替换(详情用户可参考[API](https://gitee.com/mindspore/golden-stick/blob/r0.2/mindspore_gs/pruner/scop/scop_pruner.py))删除冗余卷积核,进行完整的训练并保存模型。 ```python from mindspore_gs import Kf_Conv2d @@ -163,7 +163,7 @@ epoch: 1 step: 11, loss is 1.572392225265503 ### 加载保存的模型,进行评估 ```python -from mindspore import Tensor, context, load_checkpoint, load_param_into_net, export +from mindspore import Tensor, set_context, load_checkpoint, load_param_into_net, export if __name__ == "__main__": ... @@ -200,7 +200,7 @@ result:{'top_1_accuracy': 0.9273838141025641} prune_rate=0.45 ckpt=~/resnet50_ci 3. 导出剪枝模型。 ```python -from mindspore import Tensor, context, load_checkpoint, load_param_into_net, export +from mindspore import Tensor, set_context, load_checkpoint, load_param_into_net, export if __name__ == "__main__": ... @@ -218,7 +218,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/tutorials/experts/zh-CN/r1.9/infer/inference.html)。 ## SCOP剪枝效果 diff --git a/docs/golden_stick/docs/source_zh_cn/quantization/overview.md b/docs/golden_stick/docs/source_zh_cn/quantization/overview.md index 037ed9140ab4ac4ea4a5f40add72a835f5ab6258..330b3ef219c28a11cdd7b902122279473d3b438f 100644 --- a/docs/golden_stick/docs/source_zh_cn/quantization/overview.md +++ b/docs/golden_stick/docs/source_zh_cn/quantization/overview.md @@ -1,6 +1,6 @@ # 量化算法概述 - + 本文是在介绍具体的量化算法之前,介绍一些量化算法的基本概念,帮助用户理解。如果已经对量化算法有较深的理解,可以直接跳转到[示例](#示例)小节。 @@ -30,6 +30,6 @@ ## 示例 -- [SimQAT算法示例](https://www.mindspore.cn/golden_stick/docs/zh-CN/master/quantization/simqat.html):一种基础的基于伪量化技术的感知量化算法 -- [SLB量化算法示例](https://www.mindspore.cn/golden_stick/docs/zh-CN/master/quantization/slb.html):一种非线性的低比特感知量化算法 +- [SimQAT算法示例](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/quantization/simqat.html):一种基础的基于伪量化技术的感知量化算法 +- [SLB量化算法示例](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/quantization/slb.html):一种非线性的低比特感知量化算法 diff --git a/docs/golden_stick/docs/source_zh_cn/quantization/simqat.md b/docs/golden_stick/docs/source_zh_cn/quantization/simqat.md index 4cb302f3855a3ebe6f8c2b6c5053f39229eb8490..9b16c74a1d79388b6f2e2c433d75a8baf3920624 100644 --- a/docs/golden_stick/docs/source_zh_cn/quantization/simqat.md +++ b/docs/golden_stick/docs/source_zh_cn/quantization/simqat.md @@ -1,6 +1,6 @@ # 应用SimQAT算法 - + ## 背景 @@ -36,7 +36,7 @@ MindSpore的感知量化训练是指在训练时使用伪量化节点来模拟 | 规格 | 规格说明 | | --- | --- | | 硬件支持 | GPU | -| 网络支持 | LeNet、ResNet50,具体请参见。 | +| 网络支持 | LeNet、ResNet50,具体请参见。 | | 算法支持 | 支持非对称和对称的量化算法;支持逐层和逐通道的量化算法。| | 方案支持 | 支持8比特的量化方案。 | | 数据类型支持 | GPU平台支持FP32。 | @@ -55,7 +55,7 @@ MindSpore的感知量化训练是指在训练时使用伪量化节点来模拟 接下来以LeNet5网络为例,分别叙述这些步骤。 -> 完整代码见[lenet模型仓](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/README_CN.md#应用mindspore-golden-stick模型压缩算法),其中[train.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/golden_stick/quantization/simqat/train.py) 为完整的训练代码,[eval.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/golden_stick/quantization/simqat/eval.py) 为精度验证代码。 +> 完整代码见[lenet模型仓](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/README_CN.md#应用mindspore-golden-stick模型压缩算法),其中[train.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/golden_stick/quantization/simqat/train.py) 为完整的训练代码,[eval.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/golden_stick/quantization/simqat/eval.py) 为精度验证代码。 ### 加载数据集 @@ -65,8 +65,8 @@ MindSpore的感知量化训练是指在训练时使用伪量化节点来模拟 ds_train = create_dataset(os.path.join(config.data_path), config.batch_size) ``` -代码中create_dataset引用自[dataset.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/src/dataset.py) - ,config.data_path和config.batch_size分别在[配置文件](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/golden_stick/quantization/simqat/lenet_mnist_config.yaml) 中配置,下同。 +代码中create_dataset引用自[dataset.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/src/dataset.py) + ,config.data_path和config.batch_size分别在[配置文件](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/golden_stick/quantization/simqat/lenet_mnist_config.yaml) 中配置,下同。 ### 定义原网络 @@ -94,7 +94,7 @@ LeNet5< > ``` -LeNet5网络定义见[lenet.py](https://gitee.com/mindspore/models/blob/master/official/cv/lenet/src/lenet.py) 。 +LeNet5网络定义见[lenet.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/lenet/src/lenet.py) 。 ### 应用量化算法 @@ -109,7 +109,7 @@ quanted_network = algo.apply(network) print(quanted_network) ``` -量化网络结构如下,其中QuantizerWrapperCell为感知量化训练对原有Conv2d或者Dense的封装类,包括了原有的算子以及输入输出和权重的伪量化节点,用户可以参考[API](https://www.mindspore.cn/golden_stick/docs/zh-CN/master/quantization/mindspore_gs.quantization.SimulatedQuantizationAwareTraining.html#mindspore_gs.quantization.SimulatedQuantizationAwareTraining) 修改算法配置,并通过检查QuantizeWrapperCell的属性确认算法是否配置成功。 +量化网络结构如下,其中QuantizerWrapperCell为感知量化训练对原有Conv2d或者Dense的封装类,包括了原有的算子以及输入输出和权重的伪量化节点,用户可以参考[API](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/quantization/mindspore_gs.quantization.SimulatedQuantizationAwareTraining.html#mindspore_gs.quantization.SimulatedQuantizationAwareTraining) 修改算法配置,并通过检查QuantizeWrapperCell的属性确认算法是否配置成功。 ```text LeNet5Opt< @@ -207,7 +207,7 @@ Train epoch time: 8544.641 ms, per step time: 4.552 ms ### 评估网络,对比精度 -按照[lenet模型仓](https://gitee.com/mindspore/models/tree/master/official/cv/lenet) 步骤获得普通训练的模型精度: +按照[lenet模型仓](https://gitee.com/mindspore/models/tree/r1.9/official/cv/lenet) 步骤获得普通训练的模型精度: ```text 'Accuracy':0.9842 diff --git a/docs/golden_stick/docs/source_zh_cn/quantization/slb.md b/docs/golden_stick/docs/source_zh_cn/quantization/slb.md index 0dac5430dfe04a315894785070d29cfc0dc0fdbb..240a62fbadada3883ef6c4dce3da8eb0bc1ae934 100644 --- a/docs/golden_stick/docs/source_zh_cn/quantization/slb.md +++ b/docs/golden_stick/docs/source_zh_cn/quantization/slb.md @@ -1,6 +1,6 @@ # 应用SLB算法 - + ## 背景 @@ -42,7 +42,7 @@ SLB量化算法的训练规格如下表所示。 | 规格 | 规格说明 | | --- | --- | | 硬件支持 | GPU | -| 网络支持 | ResNet18,具体请参见。 | +| 网络支持 | ResNet18,具体请参见。 | | 方案支持 | 支持1、2、4比特的权重量化方案。 | | 数据类型支持 | GPU平台支持FP32。 | | 运行模式支持 | Graph模式和PyNative模式。 | @@ -60,7 +60,7 @@ SLB量化训练与一般训练步骤一致,在定义量化网络和生成量 接下来以ResNet18网络为例,分别叙述这些步骤。 -> 完整代码见[resnet模型仓](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/README_CN.md#应用mindspore-golden-stick模型压缩算法),其中[train.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/train.py)为完整的训练代码,[eval.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/eval.py)为精度验证代码。 +> 完整代码见[resnet模型仓](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/README_CN.md#应用mindspore-golden-stick模型压缩算法),其中[train.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/train.py)为完整的训练代码,[eval.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/eval.py)为精度验证代码。 ### 加载数据集 @@ -71,7 +71,7 @@ dataset = create_dataset(dataset_path=config.data_path, do_train=True, distribute=config.run_distribute) ``` -代码中create_dataset引用自[dataset.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/src/dataset.py),config.data_path和config.batch_size分别在[配置文件](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/resnet18_cifar10_config.yaml)中配置,下同。 +代码中create_dataset引用自[dataset.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/src/dataset.py),config.data_path和config.batch_size分别在[配置文件](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/resnet18_cifar10_config.yaml)中配置,下同。 ### 定义原网络 @@ -115,7 +115,7 @@ ResNet< > ``` -ResNet18网络定义见[resnet.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/src/resnet.py)。 +ResNet18网络定义见[resnet.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/src/resnet.py)。 ### 应用量化算法 @@ -145,7 +145,7 @@ print(quant_net) SlbQuantAwareTraining ``` -打印量化后的网络,会得到如下的网络结构,其中QuantizeWrapperCell为SLB量化对原有Conv2d的封装类,包括了原有的算子和权重的伪量化节点,用户可以参考[API](https://www.mindspore.cn/golden_stick/docs/zh-CN/master/quantization/mindspore_gs.quantization.SlbQuantAwareTraining.html#mindspore_gs.quantization.SlbQuantAwareTraining) 修改算法配置,并通过检查QuantizeWrapperCell的属性确认算法是否配置成功。 +打印量化后的网络,会得到如下的网络结构,其中QuantizeWrapperCell为SLB量化对原有Conv2d的封装类,包括了原有的算子和权重的伪量化节点,用户可以参考[API](https://www.mindspore.cn/golden_stick/docs/zh-CN/r0.2/quantization/mindspore_gs.quantization.SlbQuantAwareTraining.html#mindspore_gs.quantization.SlbQuantAwareTraining) 修改算法配置,并通过检查QuantizeWrapperCell的属性确认算法是否配置成功。 ```text ResNetOpt< @@ -262,7 +262,7 @@ ckpt_cb = ModelCheckpoint(prefix="resnet", directory="./ckpt", config=config_ck) cb += [ckpt_cb] ``` -代码中get_lr引用自[lr_generator.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/src/lr_generator.py),init_group_params和init_loss_scale都引用自[train.py](https://gitee.com/mindspore/models/blob/master/official/cv/resnet/golden_stick/quantization/slb/train.py)。 +代码中get_lr引用自[lr_generator.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/src/lr_generator.py),init_group_params和init_loss_scale都引用自[train.py](https://gitee.com/mindspore/models/blob/r1.9/official/cv/resnet/golden_stick/quantization/slb/train.py)。 ### 训练模型,保存模型文件 @@ -293,7 +293,7 @@ Train epoch time: 94106.722 ms, per step time: 60.248 ms ### 加载模型,对比精度 -按照[resnet模型仓](https://gitee.com/mindspore/models/tree/master/official/cv/resnet)步骤获得普通训练的模型精度: +按照[resnet模型仓](https://gitee.com/mindspore/models/tree/r1.9/official/cv/resnet)步骤获得普通训练的模型精度: ```text 'top_1_accuracy': 0.9544270833333334, 'top_5_accuracy': 0.9969951923076923 diff --git a/docs/graphlearning/docs/Makefile b/docs/graphlearning/docs/Makefile deleted file mode 100644 index 1eff8952707bdfa503c8d60c1e9a903053170ba2..0000000000000000000000000000000000000000 --- a/docs/graphlearning/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/graphlearning/docs/requirements.txt b/docs/graphlearning/docs/requirements.txt deleted file mode 100644 index 49a77fdec3a5c745edd40eaa223883c31500e975..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -sphinx >= 2.2.1, <= 2.4.4 -docutils == 0.16 -myst_parser == 0.14.0 -sphinx-markdown-tables -sphinx_rtd_theme == 0.5.2 -numpy -nbsphinx -IPython -ipykernel -jieba diff --git a/docs/graphlearning/docs/source_en/conf.py b/docs/graphlearning/docs/source_en/conf.py deleted file mode 100644 index 646ff5ff34d5b2b11eb302986d69f1dc96f72701..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/conf.py +++ /dev/null @@ -1,123 +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.ext import autodoc as sphinx_autodoc - -import mindspore_gl - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = '2021, 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. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'sphinx_markdown_tables', - 'myst_parser', - 'nbsphinx', - '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. -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' - -# 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'), -} - -# 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/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) diff --git a/docs/graphlearning/docs/source_en/faq.md b/docs/graphlearning/docs/source_en/faq.md deleted file mode 100644 index 74fb99ae1598c85920e6dd43c33565e540cf06c8..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/faq.md +++ /dev/null @@ -1,37 +0,0 @@ -# FAQ - - - -**Q: What should I do if the error message `OSError: could not get source code` is displayed during the execution of the GNNCell command?** - -A: MindSpore Graph Learning parses vertex-centeric programming code through source-to-source translation. The inspect function is called to obtain source code of the translation module. Model definition code needs to be placed in a Python file. Otherwise, an error message is displayed, indicating that the source code cannot be found. - -
    - -**Q: What should I do if the error message `AttributeError: None of backend from {mindspore} is identified. Backend must be imported as a global variable.` is displayed during the execution of GNNCell?** - -A: MindSpore Graph Learning parses vertex-centeric programming code through source-to-source translation. In the GNNCell definition file, the network execution backend is obtained based on global variables. You need to import MindSpore in the header of the GNNCell definition file. Otherwise, an error is reported, indicating that the backend cannot be found. - -
    - -**Q: What should I do if the error message `TypeInferenceError: Line 6: Built-in agg func "avg" only takes expr of EDGE or SRC type. Got None.` is displayed when the graph aggregation APIs 'sum, avg, max, and min' is called?** - -A: The aggregate API provided by MindSpore Graph Learning performs operations on graph nodes. During source-to-source translation, the system checks whether the input of the aggregate API is an edge or a node in the graph. If not, an error is reported, indicating that the required input type cannot be found. - -
    - -**Q: What should I do if the error message `RuntimeError: The 'mul' operation does not support the type.` is displayed when I call the graph API 'dot'?** - -A: The dot API provided by MindSpore Graph Learning is used to perform the dot multiplication operation on graph nodes. The backend includes feature multiplication and aggregation. The frontend translation process does not involve build and cannot determine the input data type. The input type must meet the type requirements of the backend mul operator. Otherwise, an error message is displayed, indicating that the type is not supported. - -
    - -**Q: What should I do if the error message `TypeError: For 'tensor getitem', the types only support 'Slice', 'Ellipsis', 'None', 'Tensor', 'int', 'List', 'Tuple', 'bool', but got String.` is displayed when I call the graph API 'topk_xxx'?** - -A: The topk_xxx API provided by MindSpore Graph Learning is used to obtain k nodes or edges based on node or edge feature sorting. The backend includes three steps: obtaining node or edge features, sorting, and slicing k nodes or edges. The frontend translation process does not involve build and cannot determine the input data type. The input type must meet the sorting dimension sortby and value range k of the sort and slice operators. Otherwise, an error is reported, indicating that the type is not supported. - -
    - -**Q: What should I do if the error message `TypeError: For 'Cell', the function construct need 5 positional argument, but got 2.'` is displayed when a non-GraphField instance or equivalent tensors are passed to the input graph of the construct function?** - -A: The GNNCell class provided by MindSpore Graph Learning is a base class for writing vertex-centeric programming GNN models. It must contain the graph class as the last input parameter. The translated input is four tensor parameters, which are src_idx, dst_idx, n_nodes, and n_edges. If only a non-GraphField instance or four equivalent tensors are passed, an error message is displayed, indicating that the input parameter is incorrect. diff --git a/docs/graphlearning/docs/source_en/full_training_of_gcn.md b/docs/graphlearning/docs/source_en/full_training_of_gcn.md deleted file mode 100644 index 58b94c4b92307eb0070131abaedf4a03b7251014..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/full_training_of_gcn.md +++ /dev/null @@ -1,237 +0,0 @@ -# Entire Graph Training Using Graph Convolutional Network (GCN) - - -   - -## Overview - -MindSpore Graph Learning provides abundant dataset read, graph operation, and network module APIs. To train graph neural networks, perform the following steps: - -1. Define a network model. You can directly call the API provided by mindspore_gl.nn or define your own graph learning model by referring to the implementation of mindspore_gl.nn. -2. Define a loss function. -3. Construct a dataset. mindspore_gl.dataset provides the function of reading and constructing some public datasets for research. -4. Train and validate the network. - -In addition, MindSpore Graph Learning provides a point-centric GNN programming paradigm. Its built-in code parsing functions translate point-centric computing expressions into graph data computing operations. To facilitate debugging, a translation comparison between the user input code and the calculation code is printed during the parsing process. - -This document describes how to use MindSpore Graph Learning to train and verify GCN. If graph nodes and edge features can be stored in a GPU, you do not need to sample the entire graph for training. -For details about the code, see . - -The following is an example of graph training using GCN: - -## GCN Principles - -Paper: - -## Defining a Network Model - -mindspore_gl.nn implements GCNConv, which can be directly imported for use. You can also define your own convolutional layer. The code for implementing a two-layer GCN network using GCNConv is as follows: - -```python -import mindspore -from mindspore_gl.nn import GNNCell -from mindspore_gl import Graph -from mindspore_gl.nn import GCNConv - - -class GCNNet(GNNCell): - def __init__(self, - data_feat_size: int, - hidden_dim_size: int, - n_classes: int, - dropout: float, - activation): - super().__init__() - self.layer0 = GCNConv(data_feat_size, hidden_dim_size, activation(), dropout) - self.layer1 = GCNConv(hidden_dim_size, n_classes, None, dropout) - - def construct(self, x, in_deg, out_deg, g: Graph): - x = self.layer0(x, in_deg, out_deg, g) - x = self.layer1(x, in_deg, out_deg, g) - return x -``` - -GCNNet is inherited from GNNCell. The last input of the construct function in GNNCell must be a graph or BatchedGraph, that is, the graph structure class supported by MindSpore Graph Learning. In addition, you must import mindspore at the header of the file to identify the execution backend when the code is translated. - -In GCNConv, data_feat_size indicates the feature dimension of the input node, hidden_dim_size indicates the feature dimension of the hidden layer, n_classes indicates the dimension of the output classification, and in_deg and out_deg indicate the indegree and outdegree of the node in the graph data, respectively. -For details about GCN implementation, see the API code of mindspore_gl.nn.GCNConv: . - -## Defining a Loss Function - -Define LossNet, including a network backbone net and a loss function. In this example, mindspore.nn.SoftmaxCrossEntropyWithLogits is used to implement a cross entropy loss. - -```python -import mindspore as ms -import mindspore.nn as nn -import mindspore.ops as ops -from mindspore_gl.nn import GNNCell - - -class LossNet(GNNCell): - """ LossNet definition """ - - def __init__(self, net): - super().__init__() - self.net = net - self.loss_fn = nn.loss.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='none') - - def construct(self, x, in_deg, out_deg, train_mask, target, g: Graph): - predict = self.net(x, in_deg, out_deg, g) - target = ops.Squeeze()(target) - loss = self.loss_fn(predict, target) - loss = loss * train_mask - return ms.ops.ReduceSum()(loss) / ms.ops.ReduceSum()(train_mask) -``` - -In the preceding code, net can be transferred to GCNNet by constructing a LossNet instance. predict indicates the predicted value output by the net, and target indicates the actual value. Because the training is based on the entire graph, train_mask is used to obtain a part of the entire graph as the training data. Only this part of nodes are involved in the loss calculation. -LossNet and GCNNet are inherited from GNNCell. - -## Constructing a Dataset - -The mindspore_gl.dataset directory contains some dataset class definitions for reference. You can directly read some common datasets. The following uses the CORA dataset as an example. Enter the data path to construct a data class. - -```python -from mindspore_gl.dataset import CoraV2 - -ds = CoraV2(args.data_path) -``` - -The CORA data can be downloaded at and decompressed to args.data_path. - -## Network Training and Validation - -### Setting Environment Variables - -The settings of environment variables are the same as those for other MindSpore network training. Especially, if enable_graph_kernel is set to True, the graph kernel build optimization is enabled to accelerate the graph model training. - -```python -import mindspore as ms - -ms.set_context(device_target="GPU", mode=ms.GRAPH_MODE, enable_graph_kernel=True) -``` - -### Defining a Training Network - -Similar to other supervised learning models, in addition to the instantiation of the model body GCNNet and LossNet, the graph neural network training requires the definition of an optimizer. Here, mindspore.nn.Adam is used. -Input the LossNet instance and optimizer to mindspore.nn.TrainOneStepCell to construct a single-step training network train_net. - -```python -import mindspore.nn as nn - -net = GCNNet(data_feat_size=feature_size, - hidden_dim_size=args.num_hidden, - n_classes=ds.n_classes, - dropout=args.dropout, - activation=ms.nn.ELU) -optimizer = nn.optim.Adam(net.trainable_params(), learning_rate=args.lr, weight_decay=args.weight_decay) -loss = LossNet(net) -train_net = nn.TrainOneStepCell(loss, optimizer) -``` - -### Network Training and Validation - -Because the entire graph is trained, one training step covers the entire dataset. Each epoch is one training step. Similarly, the verification node is obtained through test_mask. To calculate the verification accuracy, you only need to compare the verification node in the entire graph with the actual value label. -If the predicted value is consistent with the actual value, the verification is correct. The ratio of the number of correct nodes (count) to the total number of verification nodes is the verification accuracy. - -```python -for e in range(epochs): - train_net.set_train() - # input Graph with * because graph is a name tuple - train_loss = train_net(ds.x, ds.in_deg, ds.out_deg, ms.Tensor(ds.train_mask, ms.float32), ds.y, *ds.g) - - net.set_train(False) - out = net(ds.x, ds.in_deg, ds.out_deg, *ds.g).asnumpy() - # validation - test_mask = ds.test_mask - labels = ds.y.asnumpy() - predict = np.argmax(out[test_mask], axis=1) - label = labels[test_mask] - count = np.equal(predict, label) - test_acc = np.sum(count) / label.shape[0] - print('Epoch {}, Train loss {}, Test acc {:.3f}'.format(e, train_loss, np.sum(count) / label.shape[0])) -``` - -## Executing Jobs and Viewing Results - -### Running Process - -After running the program, you can view the comparison diagram of all translated functions. By default, the construct function in GNNCell is translated. The following figure shows the GCNConv translation comparison. The left part is the GCNConv source code, and the right part is the translated code. -You can see the code implementation after the graph API is replaced by mindspore_gl. For example, the code implementation after the called graph aggregate function g.sum is replaced by Gather-Scatter. -It can be seen that the node-centric programming paradigm greatly reduces the amount of code implemented by the graph model. - -```bash --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -| def construct(self, x, in_deg, out_deg, g: Graph): 1 || 1 def construct( | -| || self, | -| || x, | -| || in_deg, | -| || out_deg, | -| || src_idx, | -| || dst_idx, | -| || n_nodes, | -| || n_edges, | -| || ver_subgraph_idx=None, | -| || edge_subgraph_idx=None, | -| || graph_mask=None | -| || ): | -| || 2 SCATTER_ADD = ms.ops.TensorScatterAdd() | -| || 3 SCATTER_MAX = ms.ops.TensorScatterMax() | -| || 4 SCATTER_MIN = ms.ops.TensorScatterMin() | -| || 5 GATHER = ms.ops.Gather() | -| || 6 ZEROS = ms.ops.Zeros() | -| || 7 SHAPE = ms.ops.Shape() | -| || 8 RESHAPE = ms.ops.Reshape() | -| || 9 scatter_src_idx = RESHAPE(src_idx, (SHAPE(src_idx)[0], 1)) | -| || 10 scatter_dst_idx = RESHAPE(dst_idx, (SHAPE(dst_idx)[0], 1)) | -| out_deg = ms.ops.clip_by_value(out_deg, self.min_clip, self.max_clip) 2 || 11 out_deg = ms.ops.clip_by_value(out_deg, self.min_clip, self.max_clip) | -| out_deg = ms.ops.Reshape()( 3 || 12 out_deg = ms.ops.Reshape()( | -| ms.ops.Pow()(out_deg, -0.5), || ms.ops.Pow()(out_deg, -0.5), | -| ms.ops.Shape()(out_deg) + (1,) || ms.ops.Shape()(out_deg) + (1,) | -| ) || ) | -| x = self.drop_out(x) 4 || 13 x = self.drop_out(x) | -| x = ms.ops.Squeeze()(x) 5 || 14 x = ms.ops.Squeeze()(x) | -| x = x * out_deg 6 || 15 x = x * out_deg | -| x = self.fc(x) 7 || 16 x = self.fc(x) | -| g.set_vertex_attr({'x': x}) 8 || 17 VERTEX_SHAPE = SHAPE(x)[0] | -| || 18 x, = [x] | -| for v in g.dst_vertex: 9 || | -| v.x = g.sum([u.x for u in v.innbs]) 10 || 19 SCATTER_INPUT_SNAPSHOT2 = GATHER(x, src_idx, 0) | -| || 20 x = SCATTER_ADD( | -| || ZEROS((VERTEX_SHAPE,) + SHAPE(SCATTER_INPUT_SNAPSHOT2)[1:], ms.float32), | -| || scatter_dst_idx, | -| || SCATTER_INPUT_SNAPSHOT2 | -| || ) | -| in_deg = ms.ops.clip_by_value(in_deg, self.min_clip, self.max_clip) 11 || 21 in_deg = ms.ops.clip_by_value(in_deg, self.min_clip, self.max_clip) | -| in_deg = ms.ops.Reshape()(ms.ops.Pow()(in_deg, -0.5), ms.ops.Shape()(in_deg) + (1,)) 12 || 22 in_deg = ms.ops.Reshape()(ms.ops.Pow()(in_deg, -0.5), ms.ops.Shape()(in_deg) + (1,)) | -| x = [v.x for v in g.dst_vertex] * in_deg 13 || 23 x = x * in_deg | -| x = x + self.bias 14 || 24 x = x + self.bias | -| return x 15 || 25 return x | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -``` - -### Execution Results - -Run the vc_gcn_datanet.py script to start training. - -```bash -cd examples -python vc_gcn_datanet.py --data-path={path} --fuse=True -``` - -{path} indicates the dataset storage path. - -The training result (of the last five epochs) is as follows: - -```bash -... -Epoch 196, Train loss 0.30630863, Test acc 0.822 -Epoch 197, Train loss 0.30918056, Test acc 0.819 -Epoch 198, Train loss 0.3299482, Test acc 0.819 -Epoch 199, Train loss 0.2945389, Test acc 0.821 -Epoch 200, Train loss 0.27628058, Test acc 0.819 -``` - -Accuracy verified on CORA: 0.82 (thesis: 0.815) - -The preceding is the usage guide of the entire graph training. For more examples, see [examples directory](). diff --git a/docs/graphlearning/docs/source_en/images/graphlearning_en.png b/docs/graphlearning/docs/source_en/images/graphlearning_en.png deleted file mode 100644 index 9473d28a237f1b43c9aa33df14afcd8bbe39b4a8..0000000000000000000000000000000000000000 Binary files a/docs/graphlearning/docs/source_en/images/graphlearning_en.png and /dev/null differ diff --git a/docs/graphlearning/docs/source_en/index.rst b/docs/graphlearning/docs/source_en/index.rst deleted file mode 100644 index a83ace3f8caba44fc4173605a5f11bbb5a4e4ce6..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/index.rst +++ /dev/null @@ -1,57 +0,0 @@ -MindSpore Graph Learning Documents -=================================== - -MindSpore Graph Learning is an efficient and easy-to-use graph learning framework. Thanks to the MindSpore graph kernel fusion, MindSpore Graph Learning can optimize the build of execution patterns specific to graph models, helping developers shorten the training time. MindSpore Graph Learning also proposes an innovative vertex-centric programming paradigm, which provides native graph neural network expressions and built-in models covering most application scenarios, enabling developers to easily build graph neural networks. - -.. image:: ./images/graphlearning_en.png - :width: 700px - -Design Features ----------------- - -1. Vertex-centric programming paradigm - - A graph neural network model transfers and aggregates information on a given graph structure, which cannot be intuitively expressed through entire graph computing. MindSpore Graph Learning provides a vertex-centric programming paradigm that better complies with the graph learning algorithm logic and Python language style. It can directly translate formulas into code, reducing the gap between algorithm design and implementation. - -2. Accelerated graph models - - MindSpore Graph Learning combines the features of MindSpore graph kernel fusion and auto kernel generator (AKG) to automatically identify the specific execution pattern of graph neural network tasks for fusion and kernel-level optimization, covering the fusion of existing operators and new combined operators in the existing framework. The performance is improved by 3 to 4 times compared with that of the existing popular frameworks. - -Future Roadmap ---------------- - -The initial version of MindSpore Graph Learning includes the point-centric programming paradigm, provides implementation of typical graph models, and provides cases and performance evaluation for single-node training on small datasets. The initial version does not support performance evaluation and distributed training on large datasets, and does not support interconnection with graph databases. These features will be included in later versions of MindSpore Graph Learning. - -Typical MindSpore Graph Learning Application Scenarios -------------------------------------------------------- - -- Graph convolutional neural network (GCN) for entire graph training - - Entire graph training requires that the graph nodes and edge features of the user be stored in the GPU. The GCN is a type of graph neural network that uses convolution operations. - -.. toctree:: - :maxdepth: 1 - :caption: Deployment - - mindspore_graphlearning_install - -.. toctree:: - :maxdepth: 1 - :caption: Guide - - full_training_of_gcn - -.. toctree:: - :maxdepth: 1 - :caption: API References - - mindspore_gl.dataset - mindspore_gl.nn - mindspore_gl.parser - mindspore_gl.sampling - -.. toctree:: - :maxdepth: 1 - :caption: References - - faq diff --git a/docs/graphlearning/docs/source_en/mindspore_gl.dataset.rst b/docs/graphlearning/docs/source_en/mindspore_gl.dataset.rst deleted file mode 100644 index 0134e2415cd49715802e26defd9315aae47b4e2f..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/mindspore_gl.dataset.rst +++ /dev/null @@ -1,5 +0,0 @@ -mindspore_gl.dataset -===================== - -.. automodule:: mindspore_gl.dataset - :members: diff --git a/docs/graphlearning/docs/source_en/mindspore_gl.nn.rst b/docs/graphlearning/docs/source_en/mindspore_gl.nn.rst deleted file mode 100644 index 7e130634b1efc2887754e3caffb19b2e5cbfff95..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/mindspore_gl.nn.rst +++ /dev/null @@ -1,6 +0,0 @@ -mindspore_gl.nn -================ - -.. automodule:: mindspore_gl.nn - :exclude-members: construct - :members: diff --git a/docs/graphlearning/docs/source_en/mindspore_gl.parser.rst b/docs/graphlearning/docs/source_en/mindspore_gl.parser.rst deleted file mode 100644 index e3355e0902758d3b003d5c550e967b55526d96b3..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/mindspore_gl.parser.rst +++ /dev/null @@ -1,5 +0,0 @@ -mindspore_gl.parser -==================== - -.. automodule:: mindspore_gl.parser - :members: diff --git a/docs/graphlearning/docs/source_en/mindspore_gl.sampling.rst b/docs/graphlearning/docs/source_en/mindspore_gl.sampling.rst deleted file mode 100644 index 6018c60aed63048ea98a09e6fd3d5bb2263c325c..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/mindspore_gl.sampling.rst +++ /dev/null @@ -1,5 +0,0 @@ -mindspore_gl.sampling -====================== - -.. automodule:: mindspore_gl.sampling - :members: diff --git a/docs/graphlearning/docs/source_en/mindspore_graphlearning_install.md b/docs/graphlearning/docs/source_en/mindspore_graphlearning_install.md deleted file mode 100644 index 0c624239405e40bc06ae1d62237cd15a3a1670b3..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_en/mindspore_graphlearning_install.md +++ /dev/null @@ -1,55 +0,0 @@ -# Install Graph Learning - -- [Installation](#installation) - - [System Environment Information Confirmation](#system-environment-information-confirmation) - - [Installation Methods](#installation-methods) - - [Installation by pip](#installation-by-pip) - - [Installation by Source Code](#installation-by-source-code) - - [Installation Verification](#installation-verification) - -   - -## Installation - -### System Environment Information Confirmation - -- Ensure that the hardware platform is GPU under the Linux system. -- Refer to [MindSpore Installation Guide](https://www.mindspore.cn/install/en) to complete the installation of MindSpore, which requires at least version 1.6.0. -- For other dependencies, please refer to [requirements.txt](https://gitee.com/mindspore/graphlearning/blob/master/requirements.txt). - -### Installation Methods - -You can install MindSpore Graph Learning either by pip or by source code. - -#### Installation by pip - -```bash -pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/{version}/GraphLearning/any/mindspore_gl_gpu-{version}-cp37-cp37m-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple -``` - -> - When the network is connected, dependency items are automatically downloaded during .whl package installation. For details about other dependency items, see [requirements.txt](https://gitee.com/mindspore/graphlearning/blob/master/requirements.txt). In other cases, you need to manually install dependency items. -> - `{version}` denotes the version of MindSpore Graph Learning. For example, when you are downloading MindSpore Graph Learning 0.1, `{version}` should be 0.1. - -#### Installation by Source Code - -1. Download source code from Gitee. - - ```bash - git clone https://gitee.com/mindspore/graphlearning.git - ``` - -2. Compile and install in MindSpore Graph Learning directory. - - ```bash - cd graphlearning - bash build.sh - pip install ./output/mindspore_gl_gpu-*.whl - ``` - -### Installation Verification - -Successfully installed, if there is no error message such as `No module named 'mindspore_gl'` when execute the following command: - -```bash -python -c 'import mindspore_gl' -``` diff --git a/docs/graphlearning/docs/source_zh_cn/conf.py b/docs/graphlearning/docs/source_zh_cn/conf.py deleted file mode 100644 index 6f1697aada7a2bb8a4e40cb08f613d761b5aa61d..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/conf.py +++ /dev/null @@ -1,127 +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.ext import autodoc as sphinx_autodoc - -import mindspore_gl - -# -- Project information ----------------------------------------------------- - -project = 'MindSpore' -copyright = '2021, 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. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'sphinx_markdown_tables', - 'myst_parser', - 'nbsphinx', - '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. -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' - -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'), -} - -# 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/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) diff --git a/docs/graphlearning/docs/source_zh_cn/faq.md b/docs/graphlearning/docs/source_zh_cn/faq.md deleted file mode 100644 index 7abb31fa9dcdd785f10f74a028a88b150d8dba13..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/faq.md +++ /dev/null @@ -1,37 +0,0 @@ -# FAQ - - - -**Q:命令行执行GNNCell报错`OSError: could not get source code`怎么办?** - -A:MindSpore Graph Learning源到源翻译解析以点为中心的编程代码,中间调用了inspect来获取翻译module的源码,需要将模型定义代码放到Python文件中,否则会报错找不到源码。 - -
    - -**Q:执行GNNCell报错`AttributeError: None of backend from {mindspore} is identified. Backend must be imported as a global variable.`怎么办?** - -A:MindSpore Graph Learning通过源到源翻译解析以点为中心的编程代码,在GNNCell定义的文件根据全局变量获取网络执行后端,需要在GNNCell定义文件头部import mindspore,否则会报错找不到后端。 - -
    - -**Q:调用图聚合接口'sum、avg、max、min'等时`TypeInferenceError: Line 6: Built-in agg func "avg" only takes expr of EDGE or SRC type. Got None.`怎么办?** - -A:MindSpore Graph Learning前端提供的聚合接口均为针对图节点的操作,在源到源翻译过程会判断聚合接口的输入是否为图中的边或节点,否则报错找不到合乎规则的输入类型。 - -
    - -**Q:调用图接口'dot'时`RuntimeError: The 'mul' operation does not support the type.`怎么办?** - -A:MindSpore Graph Learning前端提供的dot接口为针对图节点的点乘操作,后端包含特征乘和聚合加两步,前端翻译过程不涉及编译无法判断输入数据类型,输入类型必须符合后端mul算子的类型要求,否则会报错类型不支持。 - -
    - -**Q:调用图接口'topk_nodes,topk_edges'时`TypeError: For 'tensor getitem', the types only support 'Slice', 'Ellipsis', 'None', 'Tensor', 'int', 'List', 'Tuple', 'bool', but got String.`怎么办?** - -A:MindSpore Graph Learning前端提供的topk_nodes接口为针对图节点/边特征排序取k个节点/边的操作,后端包含获取节点/边特征、排序sort和slice取k个三步,前端翻译过程不涉及编译无法判断输入数据类型,输入类型必须符合sort和slice算子的排序维度sortby和取值范围k的类型要求,否则会报错类型不支持。 - -
    - -**Q:construct的输入graph传入非GraphField实例或等价tensor时`TypeError: For 'Cell', the function construct need 5 positional argument, but got 2.'`怎么办?** - -A:MindSpore Graph Learning前端提供的GNNCell为写以点为中心编程GNN模型的基类,必须包含Graph类为最后一个输入参数,翻译后对应的输入为4个Tensor参数,分别为src_idx, dst_idx, n_nodes, n_edges, 如果仅传入非GraphField实例或等价的4个tensor,就会报参数输入不对的错误。 \ No newline at end of file diff --git a/docs/graphlearning/docs/source_zh_cn/full_training_of_GCN.md b/docs/graphlearning/docs/source_zh_cn/full_training_of_GCN.md deleted file mode 100644 index b4dafc6dae7f9d34f0a3b475ad251585fca34d7c..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/full_training_of_GCN.md +++ /dev/null @@ -1,237 +0,0 @@ -# 整图训练GCN网络 - - -   - -## 概述 - -MindSpore Graph Learning为用户提供了丰富的数据读入、图操作和网络结构模块接口,用户使用MindSpore Graph Learning实现训练图神经网络只需要以下几步: - -1. 定义网络结构,用户可以直接调用mindspore_gl.nn提供的接口,也可以参考这里的实现自定义图学习模块。 -2. 定义loss函数。 -3. 构造数据集,mindspore_gl.dataset提供了一些研究用的公开数据集的读入和构造。 -4. 网络训练和验证。 - -此外MindSpore Graph Learning提供了以点为中心的GNN网络编程范式,内置将以点为中心的计算表达翻译为图数据的计算操作的代码解析函数,为了方便用户调试解析过程将打印出用户输入代码与计算代码的翻译对比图。 - -本文档展示了使用MindSpore Graph Learning训练GCN网络以及验证。当用户的图节点和边特征都能存入GPU时,可以不用采样进行整图训练。 -具体代码参见。 - -下面为GCN整图训练的示范: - -## GCN原理 - -论文链接: - -## 定义网络结构 - -mindspore_gl.nn实现了GCNConv,可以直接导入使用, 用户也可以自己定义卷积层。使用GCNConv实现一个两层的GCN网络代码如下: - -```python -import mindspore -from mindspore_gl.nn import GNNCell -from mindspore_gl import Graph -from mindspore_gl.nn import GCNConv - - -class GCNNet(GNNCell): - def __init__(self, - data_feat_size: int, - hidden_dim_size: int, - n_classes: int, - dropout: float, - activation): - super().__init__() - self.layer0 = GCNConv(data_feat_size, hidden_dim_size, activation(), dropout) - self.layer1 = GCNConv(hidden_dim_size, n_classes, None, dropout) - - def construct(self, x, in_deg, out_deg, g: Graph): - x = self.layer0(x, in_deg, out_deg, g) - x = self.layer1(x, in_deg, out_deg, g) - return x -``` - -其中定义的GCNNet继承于GNNCell。GNNCell中construct函数的最后一项输入必须为Graph或者BatchedGraph,也就是MindSpore Graph Learning内置支持的图结构类。此外必须在文件的头部导入 -mindspore便于代码翻译时识别执行后端。 -GCNConv的参数data_feat_size为输入节点特征维度,hidden_dim_size为隐层特征维度,n_classes为输出分类的维度,in_deg和out_deg分别为图数据中节点的入度和出度。 -具体GCN的实现可以参考mindspore_gl.nn.GCNConv的接口代码。 - -## 定义loss函数 - -接下来定义LossNet,包含了网络主干net和loss function两部分,这里利用mindspore.nn.SoftmaxCrossEntropyWithLogits实现交叉熵loss。 - -```python -import mindspore as ms -import mindspore.nn as nn -import mindspore.ops as ops -from mindspore_gl.nn import GNNCell - - -class LossNet(GNNCell): - """ LossNet definition """ - - def __init__(self, net): - super().__init__() - self.net = net - self.loss_fn = nn.loss.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='none') - - def construct(self, x, in_deg, out_deg, train_mask, target, g: Graph): - predict = self.net(x, in_deg, out_deg, g) - target = ops.Squeeze()(target) - loss = self.loss_fn(predict, target) - loss = loss * train_mask - return ms.ops.ReduceSum()(loss) / ms.ops.ReduceSum()(train_mask) -``` - -其中net可以通过构建一个LossNet的实例传入GCNNet。predict为net输出的预测值,target为预测真实值,由于是整图训练,通过train_mask从整图中获取一部分作为训练数据,仅这部分节点参与loss计算。 -LossNet和GCNNet一样继承自GNNCell。 - -## 构造数据集 - -在mindspore_gl.dataset目录下提供了一些dataset类定义的参考。可以直接读入一些研究常用数据集,这里用cora数据集为例, 输入数据路径data_path即可构建数据类。 - -```python -from mindspore_gl.dataset import CoraV2 - -ds = CoraV2(args.data_path) -``` - -其中cora数据可通过链接下载,解压路径即为args.data_path。 - -## 网络训练和验证 - -### 设置环境变量 - -环境变量的设置同MindSpore其他网络训练,特别的是设置enable_graph_kernel=True可以启动图算编译优化,加速图模型的训练。 - -```python -import mindspore as ms - -ms.set_context(device_target="GPU", mode=ms.GRAPH_MODE, enable_graph_kernel=True) -``` - -### 定义训练网络 - -图神经网络的训练如同其他监督学习模型,除了实例化模型主体GCNNet以及LossNet,还需定义优化器,这里用的mindspore.nn.Adam。 -将LossNet实例和optimizer传入mindspore.nn.TrainOneStepCell构建一个单步训练网络train_net。 - -```python -import mindspore.nn as nn - -net = GCNNet(data_feat_size=feature_size, - hidden_dim_size=args.num_hidden, - n_classes=ds.n_classes, - dropout=args.dropout, - activation=ms.nn.ELU) -optimizer = nn.optim.Adam(net.trainable_params(), learning_rate=args.lr, weight_decay=args.weight_decay) -loss = LossNet(net) -train_net = nn.TrainOneStepCell(loss, optimizer) -``` - -### 网络训练及验证 - -由于是整图训练,一步训练就覆盖了整个数据集,每个epoch即为一步训练,同样验证节点通过test_mask获取,验证准确率的计算只需取出整图中的验证节点与真实值label进行比较计算: -预测值与真实值一致即为正确,正确节点数count与验证节点总数的比值即为验证准确率。 - -```python -for e in range(epochs): - train_net.set_train() - # input Graph with * because graph is a name tuple - train_loss = train_net(ds.x, ds.in_deg, ds.out_deg, ms.Tensor(ds.train_mask, ms.float32), ds.y, *ds.g) - - net.set_train(False) - out = net(ds.x, ds.in_deg, ds.out_deg, *ds.g).asnumpy() - # validation - test_mask = ds.test_mask - labels = ds.y.asnumpy() - predict = np.argmax(out[test_mask], axis=1) - label = labels[test_mask] - count = np.equal(predict, label) - test_acc = np.sum(count) / label.shape[0] - print('Epoch {}, Train loss {}, Test acc {:.3f}'.format(e, train_loss, np.sum(count) / label.shape[0])) -``` - -## 执行并查看结果 - -### 运行过程 - -运行程序后,首先可以看到所有被翻译后的函数的对比图(默认GNNCell中的construct函数会被翻译)。此处展示出GCNConv的翻译对比图,左边为GCNConv的源代码;右边为翻译后的代码。 -可以看到graph的API被mindspore_gl替换后的代码实现。比如调用的graph aggregate函数g.sum将被替换为Gather-Scatter的实现。 -可以看出以节点为中心的编程范式大大降低了图模型实现的代码量。 - -```bash --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -| def construct(self, x, in_deg, out_deg, g: Graph): 1 || 1 def construct( | -| || self, | -| || x, | -| || in_deg, | -| || out_deg, | -| || src_idx, | -| || dst_idx, | -| || n_nodes, | -| || n_edges, | -| || ver_subgraph_idx=None, | -| || edge_subgraph_idx=None, | -| || graph_mask=None | -| || ): | -| || 2 SCATTER_ADD = ms.ops.TensorScatterAdd() | -| || 3 SCATTER_MAX = ms.ops.TensorScatterMax() | -| || 4 SCATTER_MIN = ms.ops.TensorScatterMin() | -| || 5 GATHER = ms.ops.Gather() | -| || 6 ZEROS = ms.ops.Zeros() | -| || 7 SHAPE = ms.ops.Shape() | -| || 8 RESHAPE = ms.ops.Reshape() | -| || 9 scatter_src_idx = RESHAPE(src_idx, (SHAPE(src_idx)[0], 1)) | -| || 10 scatter_dst_idx = RESHAPE(dst_idx, (SHAPE(dst_idx)[0], 1)) | -| out_deg = ms.ops.clip_by_value(out_deg, self.min_clip, self.max_clip) 2 || 11 out_deg = ms.ops.clip_by_value(out_deg, self.min_clip, self.max_clip) | -| out_deg = ms.ops.Reshape()( 3 || 12 out_deg = ms.ops.Reshape()( | -| ms.ops.Pow()(out_deg, -0.5), || ms.ops.Pow()(out_deg, -0.5), | -| ms.ops.Shape()(out_deg) + (1,) || ms.ops.Shape()(out_deg) + (1,) | -| ) || ) | -| x = self.drop_out(x) 4 || 13 x = self.drop_out(x) | -| x = ms.ops.Squeeze()(x) 5 || 14 x = ms.ops.Squeeze()(x) | -| x = x * out_deg 6 || 15 x = x * out_deg | -| x = self.fc(x) 7 || 16 x = self.fc(x) | -| g.set_vertex_attr({'x': x}) 8 || 17 VERTEX_SHAPE = SHAPE(x)[0] | -| || 18 x, = [x] | -| for v in g.dst_vertex: 9 || | -| v.x = g.sum([u.x for u in v.innbs]) 10 || 19 SCATTER_INPUT_SNAPSHOT2 = GATHER(x, src_idx, 0) | -| || 20 x = SCATTER_ADD( | -| || ZEROS((VERTEX_SHAPE,) + SHAPE(SCATTER_INPUT_SNAPSHOT2)[1:], ms.float32), | -| || scatter_dst_idx, | -| || SCATTER_INPUT_SNAPSHOT2 | -| || ) | -| in_deg = ms.ops.clip_by_value(in_deg, self.min_clip, self.max_clip) 11 || 21 in_deg = ms.ops.clip_by_value(in_deg, self.min_clip, self.max_clip) | -| in_deg = ms.ops.Reshape()(ms.ops.Pow()(in_deg, -0.5), ms.ops.Shape()(in_deg) + (1,)) 12 || 22 in_deg = ms.ops.Reshape()(ms.ops.Pow()(in_deg, -0.5), ms.ops.Shape()(in_deg) + (1,)) | -| x = [v.x for v in g.dst_vertex] * in_deg 13 || 23 x = x * in_deg | -| x = x + self.bias 14 || 24 x = x + self.bias | -| return x 15 || 25 return x | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -``` - -### 执行结果 - -执行脚本vc_gcn_datanet.py启动训练。 - -```bash -cd examples -python vc_gcn_datanet.py --data-path={path} --fuse=True -``` - -其中{path}为数据集存放路径。 - -可以看到训练的结果(截取最后五个epoch)如下: - -```bash -... -Epoch 196, Train loss 0.30630863, Test acc 0.822 -Epoch 197, Train loss 0.30918056, Test acc 0.819 -Epoch 198, Train loss 0.3299482, Test acc 0.819 -Epoch 199, Train loss 0.2945389, Test acc 0.821 -Epoch 200, Train loss 0.27628058, Test acc 0.819 -``` - -在cora上验证精度:0.82 (论文:0.815) - -以上就是整图训练的使用指南。更多样例可参考[examples目录]()。 \ No newline at end of file diff --git a/docs/graphlearning/docs/source_zh_cn/images/graphlearning_cn.png b/docs/graphlearning/docs/source_zh_cn/images/graphlearning_cn.png deleted file mode 100644 index 2bdec9d8671dd81ea14e1004499ade2ad9f69f52..0000000000000000000000000000000000000000 Binary files a/docs/graphlearning/docs/source_zh_cn/images/graphlearning_cn.png and /dev/null differ diff --git a/docs/graphlearning/docs/source_zh_cn/index.rst b/docs/graphlearning/docs/source_zh_cn/index.rst deleted file mode 100644 index 6b3f4772968381c0f77a1a23c728696222046028..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/index.rst +++ /dev/null @@ -1,57 +0,0 @@ -MindSpore Graph Learning文档 -============================== - -MindSpore Graph Learning是一个基于MindSpore的高效易用的图学习框架。得益于MindSpore的图算融合能力,MindSpore Graph Learning能够针对图模型特有的执行模式进行编译优化,帮助开发者缩短训练时间。MindSpore Graph Learning还创新提出以点为中心编程范式,提供更原生的图神经网络表达方式,并内置覆盖大部分应用场景的模型,使开发者能够轻松搭建图神经网络。 - -.. image:: ./images/graphlearning_cn.png - :width: 700px - -设计特点 ---------- - -1. 以点为中心的编程范式 - - 图神经网络模型需要在给定的图结构上做信息的传递和聚合,整图计算无法直观表达这些操作。MindSpore Graph Learning提供以点为中心的编程范式,更符合图学习算法逻辑和Python语言风格,可以直接进行公式到代码的翻译,减少算法设计和实现间的差距。 - -2. 高效加速图模型 - - MindSpore Graph Learning结合MindSpore的图算融合和自动算子编译技术(AKG)特性,自动识别图神经网络任务中特有的执行pattern进行融合和kernel level优化,能够覆盖现有框架中已有的算子和新组合算子的融合优化,获得相比现有流行框架平均3到4倍的性能提升。 - -未来路标 ---------- - -MindSpore Graph Learning初始版本包含以点为中心的编程范式,并内置提供了典型图模型的实现,以及在小数据集上单机训练的案例和性能评测。初始版本暂时不包含大数据集上的性能评测和分布式训练,也不支持对接图数据库。MindSpore Graph Learning后续版本将包含这些内容,敬请期待。 - -使用MindSpore Graph Learning的典型场景 ---------------------------------------- - -- 整图训练GCN网络 - - 整图训练需要用户的图节点和边特征都能存入GPU,图卷积神经网络(GCN)是采用卷积操作的一类图神经网络。 - -.. toctree:: - :maxdepth: 1 - :caption: 安装部署 - - mindspore_graphlearning_install - -.. toctree:: - :maxdepth: 1 - :caption: 使用指南 - - full_training_of_GCN - -.. toctree:: - :maxdepth: 1 - :caption: API参考 - - mindspore_gl.dataset - mindspore_gl.nn - mindspore_gl.parser - mindspore_gl.sampling - -.. toctree:: - :maxdepth: 1 - :caption: 参考文档 - - faq diff --git a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.dataset.rst b/docs/graphlearning/docs/source_zh_cn/mindspore_gl.dataset.rst deleted file mode 100644 index 0134e2415cd49715802e26defd9315aae47b4e2f..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.dataset.rst +++ /dev/null @@ -1,5 +0,0 @@ -mindspore_gl.dataset -===================== - -.. automodule:: mindspore_gl.dataset - :members: diff --git a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.nn.rst b/docs/graphlearning/docs/source_zh_cn/mindspore_gl.nn.rst deleted file mode 100644 index 7e130634b1efc2887754e3caffb19b2e5cbfff95..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.nn.rst +++ /dev/null @@ -1,6 +0,0 @@ -mindspore_gl.nn -================ - -.. automodule:: mindspore_gl.nn - :exclude-members: construct - :members: diff --git a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.parser.rst b/docs/graphlearning/docs/source_zh_cn/mindspore_gl.parser.rst deleted file mode 100644 index e3355e0902758d3b003d5c550e967b55526d96b3..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.parser.rst +++ /dev/null @@ -1,5 +0,0 @@ -mindspore_gl.parser -==================== - -.. automodule:: mindspore_gl.parser - :members: diff --git a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.sampling.rst b/docs/graphlearning/docs/source_zh_cn/mindspore_gl.sampling.rst deleted file mode 100644 index 6018c60aed63048ea98a09e6fd3d5bb2263c325c..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/mindspore_gl.sampling.rst +++ /dev/null @@ -1,5 +0,0 @@ -mindspore_gl.sampling -====================== - -.. automodule:: mindspore_gl.sampling - :members: diff --git a/docs/graphlearning/docs/source_zh_cn/mindspore_graphlearning_install.md b/docs/graphlearning/docs/source_zh_cn/mindspore_graphlearning_install.md deleted file mode 100644 index 6b9e2754786d0f80f6ed2db2c08cb56a26127641..0000000000000000000000000000000000000000 --- a/docs/graphlearning/docs/source_zh_cn/mindspore_graphlearning_install.md +++ /dev/null @@ -1,59 +0,0 @@ -# 安装 Graph Learning - -- [安装教程](#安装教程) - - [确认系统环境信息](#确认系统环境信息) - - [安装方式](#安装方式) - - [pip安装](#pip安装) - - [源码安装](#源码安装) - - [验证是否成功安装](#验证是否成功安装) -- [社区](#社区) - - [治理](#治理) -- [贡献](#贡献) -- [许可证](#许可证) - -   - -## 安装指南 - -### 确认系统环境信息 - -- 硬件平台确认为Linux系统下的GPU。 -- 参考[MindSpore安装指南](https://www.mindspore.cn/install),完成MindSpore的安装,要求至少1.6.0版本。 -- 其余依赖请参见[requirements.txt](https://gitee.com/mindspore/graphlearning/blob/master/requirements.txt)。 - -### 安装方式 - -可以采用pip安装或者源码编译安装两种方式。 - -#### pip安装 - -```bash -pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/{version}/GraphLearning/any/mindspore_gl_gpu-{version}-cp37-cp37m-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple -``` - -> - 在联网状态下,安装whl包时会自动下载MindSpore Graph Learning安装包的依赖项(依赖项详情参见[requirements.txt](https://gitee.com/mindspore/graphlearning/blob/master/requirements.txt)),其余情况需自行安装。 -> - `{version}`表示MindSpore Graph Learning版本号,例如下载0.1版本MindSpore Graph Learning时,`{version}`应写为0.1。 - -#### 源码安装 - -1. 从代码仓下载源码 - - ```bash - git clone https://gitee.com/mindspore/graphlearning.git - ``` - -2. 编译安装MindSpore Graph Learning - - ```bash - cd graphlearning - bash build.sh - pip install ./output/mindspore_gl_gpu-*.whl - ``` - -### 验证是否成功安装 - -执行如下命令,如果没有报错`No module named 'mindspore_gl'`,则说明安装成功。 - -```bash -python -c 'import mindspore_gl' -``` diff --git a/docs/hub/docs/source_en/conf.py b/docs/hub/docs/source_en/conf.py index 19fdf83790089465d9efc78530f2d79469f87587..dd98b8e67501eb56f1dddbb7356558b027243c97 100644 --- a/docs/hub/docs/source_en/conf.py +++ b/docs/hub/docs/source_en/conf.py @@ -21,7 +21,7 @@ import mindspore_hub # -- Project information ----------------------------------------------------- project = 'MindSpore' -copyright = '2021, MindSpore' +copyright = '2022, MindSpore' author = 'MindSpore' # The full version, including alpha/beta/rc tags diff --git a/docs/hub/docs/source_en/hub_installation.md b/docs/hub/docs/source_en/hub_installation.md index 5ead89deed7d7d35fa0b3132bce01e964dd180fe..e452674bc36d1e2a6d1ddcb8314a338906642ff0 100644 --- a/docs/hub/docs/source_en/hub_installation.md +++ b/docs/hub/docs/source_en/hub_installation.md @@ -7,7 +7,7 @@ - [Installation by Source Code](#installation-by-source-code) - [Installation Verification](#installation-verification) - + ## System Environment Information Confirmation @@ -38,7 +38,7 @@ pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/{version}/Hub/an 1. Download source code from Gitee. ```bash - git clone https://gitee.com/mindspore/hub.git + git clone https://gitee.com/mindspore/hub.git -b r1.9 ``` 2. Compile and install in MindSpore Hub directory. @@ -61,7 +61,7 @@ model = mshub.load("mindspore/1.6/lenet_mnist", num_class=10) If it prompts the following information, the installation is successful: ```text -Downloading data from url https://gitee.com/mindspore/hub/raw/master/mshub_res/assets/mindspore/1.6/lenet_mnist.md +Downloading data from url https://gitee.com/mindspore/hub/raw/r1.9/mshub_res/assets/mindspore/1.6/lenet_mnist.md Download finished! File size = 0.00 Mb diff --git a/docs/hub/docs/source_en/index.rst b/docs/hub/docs/source_en/index.rst index 141c8f8465b833e3f965687ea0d53bc4e0ef5bcb..92735fc973c214ece94c8a4a13d6e20bc84ca159 100644 --- a/docs/hub/docs/source_en/index.rst +++ b/docs/hub/docs/source_en/index.rst @@ -27,15 +27,15 @@ MindSpore Hub is a pre-trained model application tool of the MindSpore ecosystem Typical Application Scenarios -------------------------------------------- -1. `Inference Validation `_ +1. `Inference Validation `_ With only one line of code, use mindspore_hub.load to load the pre-trained model. -2. `Transfer Learning `_ +2. `Transfer Learning `_ After loading models using mindspore_hub.load, add an extra argument to load the feature extraction of the neural network. This makes it easier to add new layers for transfer learning. -3. `Model Releasing `_ +3. `Model Releasing `_ Release the trained model to MindSpore Hub according to the specified procedure for download and use. 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 19da1734fcf8fe0dccdeb230e7832f4c33455b0b..c19c4296b48db088fa08cd486c1977edd35323f0 100644 --- a/docs/hub/docs/source_en/loading_model_from_hub.md +++ b/docs/hub/docs/source_en/loading_model_from_hub.md @@ -1,6 +1,6 @@ # Loading the Model from Hub - + ## For Inference Validation @@ -34,7 +34,7 @@ ``` -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/tutorials/experts/en/r1.9/infer/inference.html). ## For Transfer Training diff --git a/docs/hub/docs/source_en/publish_model.md b/docs/hub/docs/source_en/publish_model.md index 78315a4f99c22cf68ceffe9ea3222ce1571b7bc4..56df8c10a48d5d14338f39ea4934ff409d32cea5 100644 --- a/docs/hub/docs/source_en/publish_model.md +++ b/docs/hub/docs/source_en/publish_model.md @@ -1,6 +1,6 @@ # Publishing Models using MindSpore Hub - + ## Overview @@ -14,7 +14,7 @@ You can publish models to MindSpore Hub via PR in [hub](https://gitee.com/mindsp 1. Host your pre-trained model in a storage location where we are able to access. -2. Add a model generation python file called `mindspore_hub_conf.py` in your own repo using this [template](https://gitee.com/mindspore/models/blob/master/official/cv/googlenet/mindspore_hub_conf.py). The location of the `mindspore_hub_conf.py` file is shown below: +2. Add a model generation python file called `mindspore_hub_conf.py` in your own repo using this [template](https://gitee.com/mindspore/models/blob/r1.9/official/cv/googlenet/mindspore_hub_conf.py). The location of the `mindspore_hub_conf.py` file is shown below: ```text googlenet @@ -27,7 +27,7 @@ You can publish models to MindSpore Hub via PR in [hub](https://gitee.com/mindsp ├── mindspore_hub_conf.py ``` -3. Create a `{model_name}_{dataset}.md` file in `hub/mshub_res/assets/mindspore/1.6` using this [template](https://gitee.com/mindspore/hub/blob/master/mshub_res/assets/mindspore/1.6/googlenet_cifar10.md#). Here `1.6` indicates the MindSpore version. The structure of the `hub/mshub_res` folder is as follows: +3. Create a `{model_name}_{dataset}.md` file in `hub/mshub_res/assets/mindspore/1.6` using this [template](https://gitee.com/mindspore/hub/blob/r1.9/mshub_res/assets/mindspore/1.6/googlenet_cifar10.md#). Here `1.6` indicates the MindSpore version. The structure of the `hub/mshub_res` folder is as follows: ```text hub @@ -51,10 +51,10 @@ You can publish models to MindSpore Hub via PR in [hub](https://gitee.com/mindsp ``` The MindSpore Hub supports multiple model file formats including: - - [MindSpore CKPT](https://www.mindspore.cn/tutorials/en/master/advanced/model/save.html#saving-the-models) - - [MindIR](https://www.mindspore.cn/tutorials/en/master/advanced/model/save.html#export-mindir-model) - - [AIR](https://www.mindspore.cn/tutorials/en/master/advanced/model/save.html#export-air-model) - - [ONNX](https://www.mindspore.cn/tutorials/en/master/advanced/model/save.html#export-onnx-model) + - [MindSpore CKPT](https://www.mindspore.cn/tutorials/en/r1.9/beginner/save_load.html#saving-and-loading-the-model) + - [MindIR](https://www.mindspore.cn/tutorials/en/r1.9/beginner/save_load.html) + - [AIR](https://www.mindspore.cn/docs/en/r1.9/api_python/mindspore/mindspore.export.html) + - [ONNX](https://www.mindspore.cn/docs/en/r1.9/api_python/mindspore/mindspore.export.html) For each pre-trained model, please run the following command to obtain a hash value required at `asset-sha256` of this `.md` file. Here the pre-trained model `googlenet.ckpt` is accessed from the storage location in step 1 and then saved in `tools` folder. The output hash value is: `b2f7fe14782a3ab88ad3534ed5f419b4bbc3b477706258bd6ed8f90f529775e7`. @@ -69,6 +69,6 @@ You can publish models to MindSpore Hub via PR in [hub](https://gitee.com/mindsp python md_validator.py --check_path ../assets/mindspore/1.6/googlenet_cifar10.md ``` -5. Create a PR in `mindspore/hub` repo. See our [Contributor Wiki](https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md#) for more information about creating a PR. +5. Create a PR in `mindspore/hub` repo. See our [Contributor Wiki](https://gitee.com/mindspore/mindspore/blob/r1.9/CONTRIBUTING.md#) for more information about creating a PR. -Once your PR is merged into master branch here, your model will show up in [MindSpore Hub Website](https://www.mindspore.cn/resources/hub) within 24 hours. Please refer to [README](https://gitee.com/mindspore/hub/blob/master/mshub_res/README.md#) for more information about model submission. +Once your PR is merged into master branch here, your model will show up in [MindSpore Hub Website](https://www.mindspore.cn/resources/hub) within 24 hours. Please refer to [README](https://gitee.com/mindspore/hub/blob/r1.9/mshub_res/README.md#) for more information about model submission. diff --git a/docs/hub/docs/source_zh_cn/conf.py b/docs/hub/docs/source_zh_cn/conf.py index 833bfa21f4bd476670d729a7a4ce194c66885b0f..730898d904fdb17d1bc1d26721ea799377668238 100644 --- a/docs/hub/docs/source_zh_cn/conf.py +++ b/docs/hub/docs/source_zh_cn/conf.py @@ -23,7 +23,7 @@ import mindspore_hub # -- Project information ----------------------------------------------------- project = 'MindSpore' -copyright = '2021, MindSpore' +copyright = '2022, MindSpore' author = 'MindSpore' # The full version, including alpha/beta/rc tags diff --git a/docs/hub/docs/source_zh_cn/hub_installation.md b/docs/hub/docs/source_zh_cn/hub_installation.md index 757c79c9b1e5b2ec3b16a4bf8cede635c561ad53..fb3b845f5cedf3f8067d692e6763695e0440c075 100644 --- a/docs/hub/docs/source_zh_cn/hub_installation.md +++ b/docs/hub/docs/source_zh_cn/hub_installation.md @@ -7,7 +7,7 @@ - [源码安装](#源码安装) - [验证是否成功安装](#验证是否成功安装) - + ## 确认系统环境信息 @@ -36,7 +36,7 @@ pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/{version}/Hub/an 1. 从Gitee下载源码。 ```bash - git clone https://gitee.com/mindspore/hub.git + git clone https://gitee.com/mindspore/hub.git -b r1.9 ``` 2. 编译安装MindSpore Hub。 @@ -59,7 +59,7 @@ model = mshub.load("mindspore/1.6/lenet_mnist", num_class=10) 如果出现下列提示,说明安装成功: ```text -Downloading data from url https://gitee.com/mindspore/hub/raw/master/mshub_res/assets/mindspore/1.6/lenet_mnist.md +Downloading data from url https://gitee.com/mindspore/hub/raw/r1.9/mshub_res/assets/mindspore/1.6/lenet_mnist.md Download finished! File size = 0.00 Mb diff --git a/docs/hub/docs/source_zh_cn/index.rst b/docs/hub/docs/source_zh_cn/index.rst index 2d3201a1e59ab2c26ac5e71bec6b22bec23a7536..a56bc341e468abee602fda9980aff4d0599347de 100644 --- a/docs/hub/docs/source_zh_cn/index.rst +++ b/docs/hub/docs/source_zh_cn/index.rst @@ -29,15 +29,15 @@ MindSpore Hub包含以下功能: 使用MindSpore Hub的典型场景 ---------------------------- -1. `推理验证 `_ +1. `推理验证 `_ mindspore_hub.load用于加载预训练模型,可以实现一行代码完成模型的加载。 -2. `迁移学习 `_ +2. `迁移学习 `_ 通过mindspore_hub.load完成模型加载后,可以增加一个额外的参数项只加载神经网络的特征提取部分,这样就能很容易地在之后增加一些新的层进行迁移学习。 -3. `发布模型 `_ +3. `发布模型 `_ 可以将自己训练好的模型按照指定的步骤发布到MindSpore Hub中,以供其他用户进行下载和使用。 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 25f56340c23a8f738a33e04b7c57a66133050fc9..44364af7f228e5d57d637dddf102228c8b2d887d 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 @@ -1,6 +1,6 @@ # 从Hub加载模型 - + ## 概述 @@ -39,7 +39,7 @@ ``` -3. 完成模型加载后,可以使用MindSpore进行推理,参考[推理模型总览](https://www.mindspore.cn/tutorials/experts/zh-CN/master/infer/inference.html)。 +3. 完成模型加载后,可以使用MindSpore进行推理,参考[推理模型总览](https://www.mindspore.cn/tutorials/experts/zh-CN/r1.9/infer/inference.html)。 ## 用于迁移学习 diff --git a/docs/hub/docs/source_zh_cn/publish_model.md b/docs/hub/docs/source_zh_cn/publish_model.md index 5c6c57585e2c7b4193b16c4bcd693fa695f6c0f8..67887b983ea3be3f2a9060b5cea9a670027c0cff 100644 --- a/docs/hub/docs/source_zh_cn/publish_model.md +++ b/docs/hub/docs/source_zh_cn/publish_model.md @@ -1,6 +1,6 @@ # 发布模型 - + ## 概述 @@ -14,7 +14,7 @@ 1. 将你的预训练模型托管在可以访问的存储位置。 -2. 参照[模板](https://gitee.com/mindspore/models/blob/master/official/cv/googlenet/mindspore_hub_conf.py),在你自己的代码仓中添加模型生成文件`mindspore_hub_conf.py`,文件放置的位置如下: +2. 参照[模板](https://gitee.com/mindspore/models/blob/r1.9/official/cv/googlenet/mindspore_hub_conf.py),在你自己的代码仓中添加模型生成文件`mindspore_hub_conf.py`,文件放置的位置如下: ```text googlenet @@ -27,7 +27,7 @@ ├── mindspore_hub_conf.py ``` -3. 参照[模板](https://gitee.com/mindspore/hub/blob/master/mshub_res/assets/mindspore/1.6/googlenet_cifar10.md#),在`hub/mshub_res/assets/mindspore/1.6`文件夹下创建`{model_name}_{dataset}.md`文件,其中`1.6`为MindSpore的版本号,`hub/mshub_res`的目录结构为: +3. 参照[模板](https://gitee.com/mindspore/hub/blob/r1.9/mshub_res/assets/mindspore/1.6/googlenet_cifar10.md#),在`hub/mshub_res/assets/mindspore/1.6`文件夹下创建`{model_name}_{dataset}.md`文件,其中`1.6`为MindSpore的版本号,`hub/mshub_res`的目录结构为: ```text hub @@ -51,10 +51,10 @@ ``` 其中,MindSpore Hub支持的模型文件格式有: - - [MindSpore CKPT](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/model/save.html#保存模型) - - [MINDIR](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/model/save.html#导出mindir格式文件) - - [AIR](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/model/save.html#导出air格式文件) - - [ONNX](https://www.mindspore.cn/tutorials/zh-CN/master/advanced/model/save.html#导出onnx格式文件) + - [MindSpore CKPT](https://www.mindspore.cn/tutorials/zh-CN/r1.9/beginner/save_load.html#保存与加载) + - [MINDIR](https://www.mindspore.cn/tutorials/zh-CN/r1.9/beginner/save_load.html) + - [AIR](https://www.mindspore.cn/docs/zh-CN/r1.9/api_python/mindspore/mindspore.export.html#mindspore.export) + - [ONNX](https://www.mindspore.cn/docs/zh-CN/r1.9/api_python/mindspore/mindspore.export.html#mindspore.export) 对于每个预训练模型,执行以下命令,用来获得`.md`文件`asset-sha256`处所需的哈希值,其中`googlenet.ckpt`是从步骤1的存储位置处下载并保存到`tools`文件夹的预训练模型,运行后输出的哈希值为`b2f7fe14782a3ab88ad3534ed5f419b4bbc3b477706258bd6ed8f90f529775e7`。 @@ -69,6 +69,6 @@ python md_validator.py --check_path ../assets/mindspore/1.6/googlenet_cifar10.md ``` -5. 在`mindspore/hub`仓创建PR,详细创建方式可以参考[贡献者Wiki](https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md#)。 +5. 在`mindspore/hub`仓创建PR,详细创建方式可以参考[贡献者Wiki](https://gitee.com/mindspore/mindspore/blob/r1.9/CONTRIBUTING.md#)。 -一旦你的PR合入到`mindspore/hub`的master分支,你的模型将于24小时内在[MindSpore Hub 网站](https://www.mindspore.cn/resources/hub)上显示。有关模型上传的更多详细信息,请参考[README](https://gitee.com/mindspore/hub/blob/master/mshub_res/README.md#)。 +一旦你的PR合入到`mindspore/hub`的master分支,你的模型将于24小时内在[MindSpore Hub 网站](https://www.mindspore.cn/resources/hub)上显示。有关模型上传的更多详细信息,请参考[README](https://gitee.com/mindspore/hub/blob/r1.9/mshub_res/README.md#)。 diff --git a/docs/lite/api/_custom/sphinx_builder_html b/docs/lite/api/_custom/sphinx_builder_html index 78f1c969ce277b9f7af156a0eb456e62cfb84741..3f5be5de3333824add4c7ca5b036b4b7e9da13f6 100644 --- a/docs/lite/api/_custom/sphinx_builder_html +++ b/docs/lite/api/_custom/sphinx_builder_html @@ -1078,7 +1078,7 @@ class StandaloneHTMLBuilder(Builder): # Add links to the Python operator interface. if "mindspore.ops." in output: - output = re.sub(r'(mindspore\.ops\.\w+) ', r'\1 ', output, count=0) + output = re.sub(r'(mindspore\.ops\.\w+) ', r'\1 ', output, count=0) except UnicodeError: logger.warning(__("a Unicode error occurred when rendering the page %s. " diff --git a/docs/lite/api/source_en/api_c/lite_c_example.rst b/docs/lite/api/source_en/api_c/lite_c_example.rst index 406cb6834330cda2b63714d189a7657369763892..af69f18da026dcd004516fe7e404b16dca7efcd2 100644 --- a/docs/lite/api/source_en/api_c/lite_c_example.rst +++ b/docs/lite/api/source_en/api_c/lite_c_example.rst @@ -4,4 +4,4 @@ Example .. toctree:: :maxdepth: 1 - Simple Demo↗ + Simple Demo↗ diff --git a/docs/lite/api/source_en/api_cpp/lite_cpp_example.rst b/docs/lite/api/source_en/api_cpp/lite_cpp_example.rst index 829dc58340e8f92c229c02a39c96de99f3ff9f9c..a05f180f7ad571b61e300308639f1fc0c1b3661e 100644 --- a/docs/lite/api/source_en/api_cpp/lite_cpp_example.rst +++ b/docs/lite/api/source_en/api_cpp/lite_cpp_example.rst @@ -4,6 +4,6 @@ Example .. toctree:: :maxdepth: 1 - Simple Demo↗ - Android Application Development Based on JNI Interface↗ - High-level Usage↗ \ No newline at end of file + Simple Demo↗ + Android Application Development Based on JNI Interface↗ + High-level Usage↗ \ No newline at end of file diff --git a/docs/lite/api/source_en/api_java/class_list.md b/docs/lite/api/source_en/api_java/class_list.md index e36636d92d772bd2509a0f2d18bd0ef88fcfdb32..34c3214f037e252711ae48df698596ffa6f1d2de 100644 --- a/docs/lite/api/source_en/api_java/class_list.md +++ b/docs/lite/api/source_en/api_java/class_list.md @@ -1,17 +1,17 @@ # Class List - + | Package | Class Name | Description | | ------------------------- | -------------- | ------------------------------------------------------------ | -| com.mindspore.config | [MSContext](https://www.mindspore.cn/lite/api/en/master/api_java/mscontext.html) | MSContext defines for holding environment variables during runtime. | -| com.mindspore.config | [CpuBindMode](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java) | CpuBindMode defines the CPU binding mode. | -| com.mindspore.config | [DeviceType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java) | DeviceType defines the back-end device type. | -| com.mindspore | [Model](https://www.mindspore.cn/lite/api/en/master/api_java/model.html) | Model defines model in MindSpore for compiling and running compute graph. | -| com.mindspore | [Graph](https://www.mindspore.cn/lite/api/en/master/api_java/graph.html) | Graph defines the compute graph in MindSpore. | -| com.mindspore | [MSTensor](https://www.mindspore.cn/lite/api/en/master/api_java/mstensor.html) | MSTensor defines the tensor in MindSpore. | -| com.mindspore | [ModelParallelRunner](https://www.mindspore.cn/lite/api/en/master/api_java/model_parallel_runner.html) | Defines MindSpore Lite concurrent inference. | -| com.mindspore.config | [DataType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java) | DataType defines the supported data types. | -| com.mindspore.config | [Version](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/Version.java) | Version is used to obtain the version information of MindSpore. | -| com.mindspore.config | [ModelType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/ModelType.java) | ModelType defines the model file type. -| com.mindspore.config | [RunnerConfig](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/RunnerConfig.java) | RunnerConfig defines configuration parameters for concurrent inference. | +| com.mindspore.config | [MSContext](https://www.mindspore.cn/lite/api/en/r1.9/api_java/mscontext.html) | MSContext defines for holding environment variables during runtime. | +| com.mindspore.config | [CpuBindMode](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java) | CpuBindMode defines the CPU binding mode. | +| com.mindspore.config | [DeviceType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java) | DeviceType defines the back-end device type. | +| com.mindspore | [Model](https://www.mindspore.cn/lite/api/en/r1.9/api_java/model.html) | Model defines model in MindSpore for compiling and running compute graph. | +| com.mindspore | [Graph](https://www.mindspore.cn/lite/api/en/r1.9/api_java/graph.html) | Graph defines the compute graph in MindSpore. | +| com.mindspore | [MSTensor](https://www.mindspore.cn/lite/api/en/r1.9/api_java/mstensor.html) | MSTensor defines the tensor in MindSpore. | +| com.mindspore | [ModelParallelRunner](https://www.mindspore.cn/lite/api/en/r1.9/api_java/model_parallel_runner.html) | Defines MindSpore Lite concurrent inference. | +| com.mindspore.config | [DataType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java) | DataType defines the supported data types. | +| com.mindspore.config | [Version](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/Version.java) | Version is used to obtain the version information of MindSpore. | +| com.mindspore.config | [ModelType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/ModelType.java) | ModelType defines the model file type. +| com.mindspore.config | [RunnerConfig](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/RunnerConfig.java) | RunnerConfig defines configuration parameters for concurrent inference. | diff --git a/docs/lite/api/source_en/api_java/graph.md b/docs/lite/api/source_en/api_java/graph.md index 0ab9fbef6283fb45256fb4eb068cb8cfef021ba7..4e35beaf93ff9e5e0f5230a508b506caaa3ec9a7 100644 --- a/docs/lite/api/source_en/api_java/graph.md +++ b/docs/lite/api/source_en/api_java/graph.md @@ -1,6 +1,6 @@ # Graph - + ```java import com.mindspore.Graph; diff --git a/docs/lite/api/source_en/api_java/lite_java_example.rst b/docs/lite/api/source_en/api_java/lite_java_example.rst index b31d7edb0ce0e77331f1b8a92fa617e60144af26..fd9a61204118e4c16fc7fb7e69e19a97a9da3480 100644 --- a/docs/lite/api/source_en/api_java/lite_java_example.rst +++ b/docs/lite/api/source_en/api_java/lite_java_example.rst @@ -4,6 +4,6 @@ Example .. toctree:: :maxdepth: 1 - Simple Demo↗ - Android Application Development Based on Java Interface↗ - High-level Usage↗ \ No newline at end of file + Simple Demo↗ + Android Application Development Based on Java Interface↗ + High-level Usage↗ \ No newline at end of file diff --git a/docs/lite/api/source_en/api_java/model.md b/docs/lite/api/source_en/api_java/model.md index c0b314ad4f3f616a8d9507bc3a491d238a5841a0..873a6b38867cc8bff850ba5c15a7be1cec4fe50b 100644 --- a/docs/lite/api/source_en/api_java/model.md +++ b/docs/lite/api/source_en/api_java/model.md @@ -1,6 +1,6 @@ # Model - + ```java import com.mindspore.model; diff --git a/docs/lite/api/source_en/api_java/model_parallel_runner.md b/docs/lite/api/source_en/api_java/model_parallel_runner.md index 40334cf93d7b80f304fc9e274bc63487659503d3..0b6ae37aa45ebe0de701cecc3611db90fb708c24 100644 --- a/docs/lite/api/source_en/api_java/model_parallel_runner.md +++ b/docs/lite/api/source_en/api_java/model_parallel_runner.md @@ -1,6 +1,6 @@ # ModelParallelRunner - + ```java import com.mindspore.config.RunnerConfig; diff --git a/docs/lite/api/source_en/api_java/mscontext.md b/docs/lite/api/source_en/api_java/mscontext.md index 3ce7c0f31343b80b010d4134190f3815189e9e9f..47751b37543716b6947839cb86f9810000d834cd 100644 --- a/docs/lite/api/source_en/api_java/mscontext.md +++ b/docs/lite/api/source_en/api_java/mscontext.md @@ -1,6 +1,6 @@ # MSContext - + ```java import com.mindspore.config.MSContext; @@ -53,7 +53,7 @@ Initialize MSContext for cpu. - Parameters - `threadNum`: Thread number config for thread pool. - - `cpuBindMode`: A **[CpuBindMode](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)** **enum** variable. + - `cpuBindMode`: A **[CpuBindMode](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)** **enum** variable. - Returns @@ -68,7 +68,7 @@ Initialize MSContext. - Parameters - `threadNum`: Thread number config for thread pool. - - `cpuBindMode`: A **[CpuBindMode](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)** **enum** variable. + - `cpuBindMode`: A **[CpuBindMode](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)** **enum** variable. - `isEnableParallel`: Is enable parallel in different device. - Returns @@ -85,7 +85,7 @@ Add device info for mscontext. - Parameters - - `deviceType`: A **[DeviceType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)** **enum** type. + - `deviceType`: A **[DeviceType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)** **enum** type. - `isEnableFloat16`: Is enable fp16. - Returns @@ -100,7 +100,7 @@ Add device info for mscontext. - Parameters - - `deviceType`: A **[DeviceType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)** **enum** type. + - `deviceType`: A **[DeviceType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)** **enum** type. - `isEnableFloat16`: is enable fp16. - `npuFreq`: Npu frequency. diff --git a/docs/lite/api/source_en/api_java/mstensor.md b/docs/lite/api/source_en/api_java/mstensor.md index 960f7602b9d7d7362f9c6116abc27f7d6bb3d5ca..82075730b8d9713cb295d485852896c3dc43cf89 100644 --- a/docs/lite/api/source_en/api_java/mstensor.md +++ b/docs/lite/api/source_en/api_java/mstensor.md @@ -1,6 +1,6 @@ # MSTensor - + ```java import com.mindspore.MSTensor; @@ -13,6 +13,7 @@ MSTensor defined tensor in MindSpore. | function | | ------------------------------------------ | | [MSTensor createTensor(String tensorName, int dataType, int[] tensorShape, ByteBuffer buffer)](#createtensor) | +| [MSTensor createTensor(String tensorName, Object obj)](#createtensor) | | [int[] getShape()](#getshape) | | [int getDataType()](#getdatatype) | | [byte[] getByteData()](#getbytedata) | @@ -21,6 +22,8 @@ MSTensor defined tensor in MindSpore. | [long[] getLongData()](#getlongdata) | | [void setData(byte[] data)](#setdata) | | [void setData(float[] data)](#setdata) | +| [void setData(int[] data)](#setdata) | +| [void setData(long[] data)](#setdata) | | [void setData(ByteBuffer data)](#setdata) | | [long size()](#size) | | [int elementsNum()](#elementsnum) | @@ -47,6 +50,21 @@ Create MindSpore MSTensor. MindSpore MSTensor. +```java +public static MSTensor createTensor(String tensorName, Object obj) +``` + +Create MindSpore MSTensor. + +- Parameters + + - `tensorName`: tensor name. + - `obj`: Array object or a scalar,support dtype:float, double, int, long, boolean. + +- Returns + + MindSpore MSTensor. + ## getshape ```java @@ -65,7 +83,7 @@ Get the shape of the MindSpore MSTensor. public int getDataType() ``` -DataType is defined in [com.mindspore.DataType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java). +DataType is defined in [com.mindspore.DataType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java). - Returns @@ -141,6 +159,26 @@ Set the input data of MSTensor. - `data`: Input data of float[] type. +```java +public void setData(int[] data) +``` + +Set the input data of MSTensor. + +- Parameters + + - `data`: Input data of int[] type. + +```java +public void setData(long[] data) +``` + +Set the input data of MSTensor. + +- Parameters + + - `data`: Input data of long[] type. + ```java public void setData(ByteBuffer data) ``` diff --git a/docs/lite/api/source_en/api_java/runner_config.md b/docs/lite/api/source_en/api_java/runner_config.md index d0c554b5ab0d0b1bfaa98af2bab5a63eb20343c5..9928f0d4824e5e22dd82973da8b367a137b9d153 100644 --- a/docs/lite/api/source_en/api_java/runner_config.md +++ b/docs/lite/api/source_en/api_java/runner_config.md @@ -1,19 +1,32 @@ # RunnerConfig - + -RunnerConfig定义了MindSpore Lite并发推理的配置参数。 +RunnerConfig defines the configuration parameters of MindSpore Lite concurrent inference. ## Public Member Functions | function | | ------------------------------------------------------------ | | [boolean init()](#init) | -| [boolean setWorkerNum()](#setworkernum) | +| [void setWorkerNum()](#setworkernum) | +| [void setConfigInfo()](#setconfiginfo) | +| [void setConfigPath()](#setconfigpath) | +| [void getConfigPath()](#getconfigpath) | | [long getRunnerConfigPtr()](#getrunnerconfigptr) | ## init +```java +public boolean init() +``` + +Configuration parameter initialization for parallel inference. + +- Returns + + Whether the initialization is successful. + ```java public boolean init(MSContext msContext) ``` @@ -40,6 +53,43 @@ The parameter setting of the number of models in parallel inference. - `workerNum`: Set the number of models in the configuration. +## setConfigInfo + +```java +public void setConfigInfo(String section, HashMap config) +``` + +Model configuration parameter settings in parallel inference. + +- Parameters + + - `section`: Configured chapter name. + - `config`: config pair to update. + +## setConfigPath + +```java +public void setConfigPath(String configPath) +``` + +Set the configuration file path in concurrent inference. + +- Parameters + + - `configPath`: config path. + +## getConfigPath + +```java +public String getConfigPath() +``` + +Get the path to the configuration file set in RunnerConfig. + +- Returns + + config path. + ## getRunnerConfigPtr ```java diff --git a/docs/lite/api/source_en/conf.py b/docs/lite/api/source_en/conf.py index 0d8f9b1e252346ac9fe44dbc6f85930b3d6ee767..f039d820112aa979a667910b924308a56356b4da 100644 --- a/docs/lite/api/source_en/conf.py +++ b/docs/lite/api/source_en/conf.py @@ -360,6 +360,14 @@ for file_name in fileList: with open(file_name, 'w', encoding='utf-8') as p: p.write(file_data) +for file_name in fileList: + file_data = '' + with open(file_name, 'r', encoding='utf-8') as f: + data = f.read() + data = re.sub(r'/\*\*([\s\n\S]*?)\*/', '', data) + with open(file_name, 'w', encoding='utf-8') as p: + p.write(data) + # for file_name in fileList: # file_data = '' # with open(file_name, 'r', encoding='utf-8') as f: diff --git a/docs/lite/api/source_zh_cn/api_c/context_c.md b/docs/lite/api/source_zh_cn/api_c/context_c.md index 5adc48b3985ccb73555bd1d25b7fa508290f6d6b..8247aebdc941f028b4fe02f53b102c998f07c59e 100644 --- a/docs/lite/api/source_zh_cn/api_c/context_c.md +++ b/docs/lite/api/source_zh_cn/api_c/context_c.md @@ -1,6 +1,6 @@ # context_c - + ```c #include @@ -202,7 +202,7 @@ MSDeviceInfoHandle MSDeviceInfoCreate(MSDeviceType device_type) 新建运行设备信息,若创建失败则会返回`nullptr`,并日志中输出信息。 - 参数 - - `device_type`: 设备类型,具体见[MSDeviceType](https://www.mindspore.cn/lite/api/zh-CN/master/api_c/types_c.html#msdevicetype)。 + - `device_type`: 设备类型,具体见[MSDeviceType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_c/types_c.html#msdevicetype)。 - 返回值 diff --git a/docs/lite/api/source_zh_cn/api_c/data_type_c.md b/docs/lite/api/source_zh_cn/api_c/data_type_c.md index 46620d5ae7f212db5dd48d3cf12da76bb09a2fe1..b542a4f3d52c13d49fa7dc4e7732496f0c333b4d 100644 --- a/docs/lite/api/source_zh_cn/api_c/data_type_c.md +++ b/docs/lite/api/source_zh_cn/api_c/data_type_c.md @@ -1,6 +1,6 @@ # data_type_c - + ```C #include diff --git a/docs/lite/api/source_zh_cn/api_c/format_c.md b/docs/lite/api/source_zh_cn/api_c/format_c.md index e17e07910f9746a8a2d3b8a14c3d0a5d63ce46cb..4d5b79903b302fa0181f19ae6ecf73e6d4e57ffc 100644 --- a/docs/lite/api/source_zh_cn/api_c/format_c.md +++ b/docs/lite/api/source_zh_cn/api_c/format_c.md @@ -1,6 +1,6 @@ # format_c - + ```C #include diff --git a/docs/lite/api/source_zh_cn/api_c/lite_c_example.rst b/docs/lite/api/source_zh_cn/api_c/lite_c_example.rst index c465afa48302f193f046b6cd2495d1a3e89af838..7350fb8ac5cc58d65eb6a53e6c74ec67b551c885 100644 --- a/docs/lite/api/source_zh_cn/api_c/lite_c_example.rst +++ b/docs/lite/api/source_zh_cn/api_c/lite_c_example.rst @@ -4,4 +4,4 @@ .. toctree:: :maxdepth: 1 - 极简Demo↗ + 极简Demo↗ diff --git a/docs/lite/api/source_zh_cn/api_c/model_c.md b/docs/lite/api/source_zh_cn/api_c/model_c.md index 01c9de8dbd62592d1817e82ea3e580a646d9efc0..af0a2f8cba96a35f0aa80099bfbfb93749c772b1 100644 --- a/docs/lite/api/source_zh_cn/api_c/model_c.md +++ b/docs/lite/api/source_zh_cn/api_c/model_c.md @@ -1,6 +1,6 @@ # model_c - + ```C #include @@ -76,7 +76,7 @@ MSStatus MSModelBuild(MSModelHandle model, const void *model_data, size_t data_s - `model`: 指向模型对象的指针。 - `model_data`: 内存中已经加载的模型数据地址。 - `data_size`: 模型数据的长度。 - - `model_type`: 模型文件类型,具体见: [MSModelType](https://mindspore.cn/lite/api/zh-CN/master/api_c/types_c.html#msmodeltype)。 + - `model_type`: 模型文件类型,具体见: [MSModelType](https://mindspore.cn/lite/api/zh-CN/r1.9/api_c/types_c.html#msmodeltype)。 - `model_context`: 模型的上下文环境,具体见: [Context](./context_c.md)。 - 返回值 @@ -96,7 +96,7 @@ MSStatus MSModelBuildFromFile(MSModelHandle model, const char *model_path, MSMod - `model`: 指向模型对象的指针。 - `model_path`: 模型文件路径。 - - `model_type`: 模型文件类型,具体见: [MSModelType](https://mindspore.cn/lite/api/zh-CN/master/api_c/types_c.html#msmodeltype)。 + - `model_type`: 模型文件类型,具体见: [MSModelType](https://mindspore.cn/lite/api/zh-CN/r1.9/api_c/types_c.html#msmodeltype)。 - `model_context`: 模型的上下文环境,具体见: [Context](./context_c.md)。 - 返回值 diff --git a/docs/lite/api/source_zh_cn/api_c/tensor_c.md b/docs/lite/api/source_zh_cn/api_c/tensor_c.md index d3d5b3f12967f798ac1792e0c8c452431a335d5b..a94653e57574835d7c4c1819e0822f4430f14178 100644 --- a/docs/lite/api/source_zh_cn/api_c/tensor_c.md +++ b/docs/lite/api/source_zh_cn/api_c/tensor_c.md @@ -1,6 +1,6 @@ # tensor_c - + ```C #include @@ -171,7 +171,7 @@ void MSTensorSetFormat(MSTensorHandle tensor, MSFormat format) - 参数 - `tensor`: 指向MSTensor的指针。 - - `format`: 张量的数据排列,具体见[MSFormat](https://www.mindspore.cn/lite/api/zh-CN/master/api_c/format_c.html#msformat)。 + - `format`: 张量的数据排列,具体见[MSFormat](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_c/format_c.html#msformat)。 - 返回值 @@ -187,7 +187,7 @@ MSFormat MSTensorGetFormat(const MSTensorHandle tensor) - 返回值 - 张量的数据排列,具体见[MSFormat](https://www.mindspore.cn/lite/api/zh-CN/master/api_c/format_c.html#msformat)。 + 张量的数据排列,具体见[MSFormat](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_c/format_c.html#msformat)。 ### MSTensorSetData diff --git a/docs/lite/api/source_zh_cn/api_c/types_c.md b/docs/lite/api/source_zh_cn/api_c/types_c.md index ec3ea0c5f77cb08a2a6e5c538b103d834a6b86fe..66be00d4b09a903d93cc45a8d7eb65582712d6c1 100644 --- a/docs/lite/api/source_zh_cn/api_c/types_c.md +++ b/docs/lite/api/source_zh_cn/api_c/types_c.md @@ -1,6 +1,6 @@ # types_c - + ```C #include diff --git a/docs/lite/api/source_zh_cn/api_cpp/lite_cpp_example.rst b/docs/lite/api/source_zh_cn/api_cpp/lite_cpp_example.rst index 58c80e6e368a4ac049fc99fe6edb1e573755a974..71d8ef74c5d0e168ee79e0c1821d7eb22db62459 100644 --- a/docs/lite/api/source_zh_cn/api_cpp/lite_cpp_example.rst +++ b/docs/lite/api/source_zh_cn/api_cpp/lite_cpp_example.rst @@ -4,6 +4,6 @@ .. toctree:: :maxdepth: 1 - 极简Demo↗ - 基于JNI接口的Android应用开发↗ - 高阶用法↗ \ No newline at end of file + 极简Demo↗ + 基于JNI接口的Android应用开发↗ + 高阶用法↗ \ No newline at end of file diff --git a/docs/lite/api/source_zh_cn/api_cpp/mindspore.md b/docs/lite/api/source_zh_cn/api_cpp/mindspore.md index ed421d4b007316fd3c25c9fc25170d6a26ed8054..f47136a1f73f7fd0ea549a22cb7760ed8ab4f7cd 100644 --- a/docs/lite/api/source_zh_cn/api_cpp/mindspore.md +++ b/docs/lite/api/source_zh_cn/api_cpp/mindspore.md @@ -1,6 +1,6 @@ # mindspore - + ## 接口汇总 @@ -55,8 +55,8 @@ | 接口名 | 描述 | | --- | --- | -| [mindspore::DataType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_datatype.html) | MindSpore MSTensor保存的数据支持的类型。 | -| [mindspore::Format](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_format.html) | MindSpore MSTensor保存的数据支持的排列格式。 | +| [mindspore::DataType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_datatype.html) | MindSpore MSTensor保存的数据支持的类型。 | +| [mindspore::Format](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_format.html) | MindSpore MSTensor保存的数据支持的排列格式。 | ### 全局方法 @@ -83,7 +83,7 @@ ## Context -\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/context.h)> +\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/context.h)> Context类用于保存执行中的环境变量。 @@ -254,7 +254,7 @@ std::vector> &MutableDeviceInfo(); ## DeviceInfoContext -\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/context.h)> +\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/context.h)> DeviceInfoContext类定义不同硬件设备的环境信息。 @@ -365,7 +365,7 @@ std::shared_ptr GetAllocator() const; ## CPUDeviceInfo -\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/context.h)> +\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/context.h)> 派生自[DeviceInfoContext](#deviceinfocontext),模型运行在CPU上的配置,仅MindSpore Lite支持该选项。 @@ -379,7 +379,7 @@ std::shared_ptr GetAllocator() const; ## GPUDeviceInfo -\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/context.h)> +\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/context.h)> 派生自[DeviceInfoContext](#deviceinfocontext),模型运行在GPU上的配置,仅MindSpore Lite支持该选项。 @@ -402,7 +402,7 @@ std::shared_ptr GetAllocator() const; ## KirinNPUDeviceInfo -\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/context.h)> +\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/context.h)> 派生自[DeviceInfoContext](#deviceinfocontext),模型运行在NPU上的配置,仅MindSpore Lite支持该选项。 @@ -416,7 +416,7 @@ std::shared_ptr GetAllocator() const; ## Ascend910DeviceInfo -\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/context.h)> +\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/context.h)> 派生自[DeviceInfoContext](#deviceinfocontext),模型运行在Ascend910上的配置,MindSpore Lite不支持该选项。 @@ -429,7 +429,7 @@ std::shared_ptr GetAllocator() const; ## Ascend310DeviceInfo -\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/context.h)> +\#include <[context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/context.h)> 派生自[DeviceInfoContext](#deviceinfocontext),模型运行在Ascend310上的配置。 @@ -454,7 +454,7 @@ std::shared_ptr GetAllocator() const; ## Serialization -\#include <[serialization.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/serialization.h)> +\#include <[serialization.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/serialization.h)> Serialization类汇总了模型文件读写的方法。 @@ -681,7 +681,7 @@ Buffer Clone() const; ## Model -\#include <[model.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/model.h)> +\#include <[model.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/model.h)> Model定义了MindSpore中的模型,便于计算图管理。 @@ -1161,7 +1161,7 @@ static bool CheckModelSupport(enum DeviceType device_type, ModelType model_type) ## MSTensor -\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/types.h)> +\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/types.h)> `MSTensor`定义了MindSpore中的张量。 @@ -1531,7 +1531,7 @@ const std::shared_ptr impl() ## QuantParam -\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/types.h)> +\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/types.h)> 一个结构体。QuantParam定义了MSTensor的一组量化参数。 @@ -1563,7 +1563,7 @@ zero_point ## MSKernelCallBack -\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/types.h)> +\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/types.h)> ```cpp using MSKernelCallBack = std::function &inputs, const std::vector &outputs, const MSCallBackParam &opInfo)> @@ -1573,7 +1573,7 @@ using MSKernelCallBack = std::function &inputs, ## MSCallBackParam -\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/types.h)> +\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/types.h)> 一个结构体。MSCallBackParam定义了回调函数的输入参数。 @@ -1597,7 +1597,7 @@ node_type ## Delegate -\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/delegate.h)> +\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/delegate.h)> `Delegate`定义了第三方AI框架接入MindSpore Lite的代理接口。 @@ -1640,7 +1640,7 @@ Delegate在线构图。 ## CoreMLDelegate -\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/delegate.h)> +\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/delegate.h)> `CoreMLDelegate`继承自`Delegate`类,定义了CoreML框架接入MindSpore Lite的代理接口。 @@ -1682,7 +1682,7 @@ CoreMLDelegate在线构图,仅在内部图编译阶段调用。 ## SchemaVersion -\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/delegate.h)> +\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/delegate.h)> 定义了Lite执行在线推理时模型文件的版本。 @@ -1696,9 +1696,9 @@ typedef enum { ## KernelIter -\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/delegate.h)> +\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/delegate.h)> -定义了Lite [Kernel](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_kernel.html#mindspore-kernel)列表的迭代器。 +定义了Lite [Kernel](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_kernel.html#mindspore-kernel)列表的迭代器。 ```cpp using KernelIter = std::vector::iterator; @@ -1706,7 +1706,7 @@ using KernelIter = std::vector::iterator; ## DelegateModel -\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/delegate.h)> +\#include <[delegate.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/delegate.h)> `DelegateModel`定义了MindSpore Lite Delegate机制操作的的模型对象。 @@ -1732,7 +1732,7 @@ DelegateModel(std::vector *kernels, const std::vector *kernels_; ``` -[**Kernel**](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_kernel.html#kernel)的列表,保存模型的所有算子。 +[**Kernel**](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_kernel.html#kernel)的列表,保存模型的所有算子。 #### inputs_ @@ -1740,7 +1740,7 @@ std::vector *kernels_; const std::vector &inputs_; ``` -[**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)的列表,保存这个算子的输入tensor。 +[**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)的列表,保存这个算子的输入tensor。 #### outputs_ @@ -1748,7 +1748,7 @@ const std::vector &inputs_; const std::vector &outputs; ``` -[**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)的列表,保存这个算子的输出tensor。 +[**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)的列表,保存这个算子的输出tensor。 #### primitives_ @@ -1756,7 +1756,7 @@ const std::vector &outputs; const std::map &primitives_; ``` -[**Kernel**](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_kernel.html#kernel)和**schema::Primitive**的Map,保存所有算子的属性。 +[**Kernel**](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_kernel.html#kernel)和**schema::Primitive**的Map,保存所有算子的属性。 #### version_ @@ -1836,7 +1836,7 @@ const std::vector &inputs(); - 返回值 - [**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)的列表。 + [**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)的列表。 #### outputs @@ -1848,7 +1848,7 @@ const std::vector &outputs(); - 返回值 - [**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)的列表。 + [**MSTensor**](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)的列表。 #### GetVersion @@ -1864,7 +1864,7 @@ const SchemaVersion GetVersion() { return version_; } ## TrainCfg -\#include <[cfg.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/cfg.h)> +\#include <[cfg.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/cfg.h)> `TrainCfg`MindSpore Lite训练的相关配置参数。 @@ -1912,7 +1912,7 @@ bool accumulate_gradients_; ## MixPrecisionCfg -\#include <[cfg.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/cfg.h)> +\#include <[cfg.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/cfg.h)> `MixPrecisionCfg`MindSpore Lite训练混合精度配置类。 @@ -1954,7 +1954,7 @@ bool is_raw_mix_precision_; ## AccuracyMetrics -\#include <[accuracy.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/metrics/accuracy.h)> +\#include <[accuracy.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/metrics/accuracy.h)> `AccuracyMetrics`MindSpore Lite训练精度类。 @@ -1989,7 +1989,7 @@ float Eval() override; ## Metrics -\#include <[metrics.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/metrics/metrics.h)> +\#include <[metrics.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/metrics/metrics.h)> `Metrics`MindSpore Lite训练指标类。 @@ -2036,7 +2036,7 @@ virtual void Update(std::vector inputs, std::vector outp ## TrainCallBack -\#include <[callback.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/callback.h)> +\#include <[callback.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/callback.h)> `Metrics`MindSpore Lite训练回调类。 @@ -2135,7 +2135,7 @@ virtual void Begin(const TrainCallBackData &cb_data) {} ## TrainCallBackData -\#include <[callback.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/callback.h)> +\#include <[callback.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/callback.h)> 一个结构体。TrainCallBackData定义了训练回调的一组参数。 @@ -2175,7 +2175,7 @@ model_ ## CkptSaver -\#include <[ckpt_saver.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/ckpt_saver.h)> +\#include <[ckpt_saver.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/ckpt_saver.h)> `Metrics`MindSpore Lite训练模型文件保存类。 @@ -2188,7 +2188,7 @@ model_ ## LossMonitor -\#include <[loss_monitor.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/loss_monitor.h)> +\#include <[loss_monitor.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/loss_monitor.h)> `Metrics`MindSpore Lite训练损失函数类。 @@ -2215,7 +2215,7 @@ model_ ## LRScheduler -\#include <[lr_scheduler.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/lr_scheduler.h)> +\#include <[lr_scheduler.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/lr_scheduler.h)> `Metrics`MindSpore Lite训练学习率调度类。 @@ -2228,7 +2228,7 @@ model_ ## StepLRLambda -\#include <[lr_scheduler.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/lr_scheduler.h)> +\#include <[lr_scheduler.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/lr_scheduler.h)> 一个结构体。StepLRLambda定义了训练学习率的一组参数。 @@ -2252,7 +2252,7 @@ gamma ## MultiplicativeLRLambda -\#include <[lr_scheduler.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/lr_scheduler.h)> +\#include <[lr_scheduler.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/lr_scheduler.h)> 每个epoch将学习率乘以一个因子。 @@ -2280,7 +2280,7 @@ int MultiplicativeLRLambda(float *lr, int epoch, void *multiplication); ## TimeMonitor -\#include <[time_monitor.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/time_monitor.h)> +\#include <[time_monitor.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/time_monitor.h)> `Metrics`MindSpore Lite训练时间监测类。 @@ -2326,7 +2326,7 @@ int MultiplicativeLRLambda(float *lr, int epoch, void *multiplication); ## TrainAccuracy -\#include <[train_accuracy.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/callback/train_accuracy.h)> +\#include <[train_accuracy.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/callback/train_accuracy.h)> `Metrics`MindSpore Lite训练学习率调度类。 @@ -2377,7 +2377,7 @@ std::vector CharVersion(); ## Version -\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/types.h)> +\#include <[types.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/types.h)> ```cpp std::string Version() @@ -2391,7 +2391,7 @@ std::string Version() ## Allocator -\#include <[allocator.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/allocator.h)> +\#include <[allocator.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/allocator.h)> 内存管理基类。 @@ -2732,7 +2732,7 @@ static inline std::string CodeAsString(enum StatusCode c); ## Graph -\#include <[graph.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/graph.h)> +\#include <[graph.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/graph.h)> ### 构造函数和析构函数 @@ -2788,7 +2788,7 @@ static inline std::string CodeAsString(enum StatusCode c); ## CellBase -\#include <[cell.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/cell.h)> +\#include <[cell.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/cell.h)> ### 构造函数和析构函数 @@ -2813,7 +2813,7 @@ static inline std::string CodeAsString(enum StatusCode c); ## Cell -\#include <[cell.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/cell.h)> +\#include <[cell.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/cell.h)> ### 析构函数 @@ -2837,7 +2837,7 @@ static inline std::string CodeAsString(enum StatusCode c); ## GraphCell -\#include <[cell.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/cell.h)> +\#include <[cell.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/cell.h)> ### 构造函数和析构函数 @@ -2865,7 +2865,7 @@ static inline std::string CodeAsString(enum StatusCode c); ## RunnerConfig -\#include <[model_parallel_runner.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/model_parallel_runner.h)> +\#include <[model_parallel_runner.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/model_parallel_runner.h)> RunnerConfig定义了ModelParallelRunner中使用的配置选项参数。 @@ -2951,9 +2951,33 @@ std::map> GetConfigInfo() const; `map`类型的配置信息。 +#### SetConfigPath + +```cpp +void SetConfigPath(const std::string &config_path); +``` + +设置RunnerConfig中的配置文件路径。 + +- 参数 + + - `config_path`: 配置文件路径。 + +#### GetConfigPath + +```cpp +std::string GetConfigPath() const; +``` + +获取RunnerConfig中的配置文件的路径。 + +- 返回值 + + RunnerConfig类中的配置文件路径。 + ## ModelParallelRunner -\#include <[model_parallel_runner.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/model_parallel_runner.h)> +\#include <[model_parallel_runner.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/model_parallel_runner.h)> ModelParallelRunner定义了MindSpore的多个Model以及并发策略,便于多个Model的调度与管理。 diff --git a/docs/lite/api/source_zh_cn/api_cpp/mindspore_converter.md b/docs/lite/api/source_zh_cn/api_cpp/mindspore_converter.md index 6733583d2d9abdc16a7adda06de6fabbfe83a445..7abca4aefaffadedb94d3d78516e2aad539d5dbf 100644 --- a/docs/lite/api/source_zh_cn/api_cpp/mindspore_converter.md +++ b/docs/lite/api/source_zh_cn/api_cpp/mindspore_converter.md @@ -1,6 +1,6 @@ # mindspore::converter - + 以下描述了Mindspore Lite转换支持的模型类型及用户扩展所需的必要信息。 @@ -16,7 +16,7 @@ ## FmkType -\#include <[converter_context.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/converter_context.h)> +\#include <[converter_context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/converter_context.h)> **enum**类型变量,定义MindSpore Lite转换支持的框架类型。 @@ -30,7 +30,7 @@ ## ConverterParameters -\#include <[converter_context.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/converter_context.h)> +\#include <[converter_context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/converter_context.h)> **struct**类型结构体,定义模型解析时的转换参数,用于模型解析时的只读参数。 @@ -45,7 +45,7 @@ struct ConverterParameters { ## ConverterContext -\#include <[converter_context.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/converter_context.h)> +\#include <[converter_context.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/converter_context.h)> 模型转换过程中,基本信息的设置与获取。 @@ -93,7 +93,7 @@ static std::vector GetGraphOutputTensorNames(); ## NodeParser -\#include <[node_parser.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/node_parser.h)> +\#include <[node_parser.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/node_parser.h)> op节点的解析基类。 @@ -196,7 +196,7 @@ tflite节点解析接口函数。 ## NodeParserPtr -\#include <[node_parser.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/node_parser.h)> +\#include <[node_parser.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/node_parser.h)> NodeParser类的共享智能指针类型。 @@ -206,7 +206,7 @@ using NodeParserPtr = std::shared_ptr; ## ModelParser -\#include <[model_parser.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/model_parser.h)> +\#include <[model_parser.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/model_parser.h)> 解析原始模型的基类。 @@ -238,7 +238,7 @@ api::FuncGraphPtr Parse(const converter::ConverterParameters &flags); - 参数 - - `flags`: 解析模型时基本信息,具体见[ConverterParameters](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#converterparameters)。 + - `flags`: 解析模型时基本信息,具体见[ConverterParameters](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#converterparameters)。 - 返回值 diff --git a/docs/lite/api/source_zh_cn/api_cpp/mindspore_datatype.md b/docs/lite/api/source_zh_cn/api_cpp/mindspore_datatype.md index 696ddf4c5f98c92de1a7046ab1fdde098378f997..c592f54b846aaddd0d1440f5ded91111306a7e6f 100644 --- a/docs/lite/api/source_zh_cn/api_cpp/mindspore_datatype.md +++ b/docs/lite/api/source_zh_cn/api_cpp/mindspore_datatype.md @@ -1,6 +1,6 @@ # mindspore::DataType - + 以下表格描述了MindSpore MSTensor保存的数据支持的类型。 diff --git a/docs/lite/api/source_zh_cn/api_cpp/mindspore_format.md b/docs/lite/api/source_zh_cn/api_cpp/mindspore_format.md index a49c85291d9c453d38d77e903d3bc16be0203153..747643731914b13d9814c1955410c9e2e4f67455 100644 --- a/docs/lite/api/source_zh_cn/api_cpp/mindspore_format.md +++ b/docs/lite/api/source_zh_cn/api_cpp/mindspore_format.md @@ -1,6 +1,6 @@ # mindspore::Format - + 以下表格描述了MindSpore MSTensor保存的数据支持的排列格式。 diff --git a/docs/lite/api/source_zh_cn/api_cpp/mindspore_kernel.md b/docs/lite/api/source_zh_cn/api_cpp/mindspore_kernel.md index ecb3994ed8bdd21f932324e4158d2955894e9532..1d257bf03074e330ba3bfffbd6ef58b8d1e485f6 100644 --- a/docs/lite/api/source_zh_cn/api_cpp/mindspore_kernel.md +++ b/docs/lite/api/source_zh_cn/api_cpp/mindspore_kernel.md @@ -1,6 +1,6 @@ # mindspore::kernel - + ## 接口汇总 @@ -11,7 +11,7 @@ ## Kernel -\#include <[kernel.h](https://gitee.com/mindspore/mindspore/blob/master/include/api/kernel.h)> +\#include <[kernel.h](https://gitee.com/mindspore/mindspore/blob/r1.9/include/api/kernel.h)> Kernel是算子实现的基类,定义了几个必须实现的接口。 @@ -30,13 +30,13 @@ Kernel的默认与带参构造函数,构造Kernel实例。 - 参数 - - `inputs`: 算子输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)。 + - `inputs`: 算子输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)。 - - `outputs`: 算子输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)。 + - `outputs`: 算子输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)。 - `primitive`: 算子经由flatbuffers反序化为Primitive后的结果。 - - `ctx`: 算子的上下文[Context](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#context)。 + - `ctx`: 算子的上下文[Context](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#context)。 ## 析构函数 @@ -101,7 +101,7 @@ virtual void set_inputs(const std::vector &in_tensors) - 参数 - - `in_tensors`: 算子的所有输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)列表。 + - `in_tensors`: 算子的所有输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)列表。 ### set_input @@ -113,7 +113,7 @@ virtual set_input(mindspore::MSTensor in_tensor, int index) - 参数 - - `in_tensor`: 算子的输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)。 + - `in_tensor`: 算子的输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)。 - `index`: 算子输入在所有输入中的下标,从0开始计数。 @@ -127,7 +127,7 @@ virtual void set_outputs(const std::vector &out_tensors) - 参数 - - `out_tensor`: 算子的所有输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)列表。 + - `out_tensor`: 算子的所有输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)列表。 ### set_output @@ -139,7 +139,7 @@ virtual void set_output(mindspore::MSTensor out_tensor, int index) - 参数 - - `out_tensor`: 算子的输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)。 + - `out_tensor`: 算子的输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)。 - `index`: 算子输出在所有输出中的下标,从0开始计数。 @@ -149,7 +149,7 @@ virtual void set_output(mindspore::MSTensor out_tensor, int index) virtual const std::vector &inputs() ``` -返回算子的所有输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)列表。 +返回算子的所有输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)列表。 ### outputs @@ -157,7 +157,7 @@ virtual const std::vector &inputs() virtual const std::vector &outputs() ``` -返回算子的所有输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)列表。 +返回算子的所有输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)列表。 ### name @@ -185,7 +185,7 @@ void set_name(const std::string &name) const lite::Context *context() const ``` -返回算子对应的[Context](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#context)。 +返回算子对应的[Context](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#context)。 ### primitive @@ -233,7 +233,7 @@ std::map GetConfig(const std::string §ion) const ## KernelInterface -\#include <[kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/kernel_interface.h)> +\#include <[kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/kernel_interface.h)> 算子扩展能力基类。 @@ -265,9 +265,9 @@ virtual int Infer(std::vector *inputs, std::vector *inputs, std::vector + ## 接口汇总 @@ -26,7 +26,7 @@ ## NodeParserRegistry -\#include <[node_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/node_parser_registry.h)> +\#include <[node_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/node_parser_registry.h)> NodeParserRegistry类用于注册及获取NodeParser类型的共享智能指针。 @@ -41,11 +41,11 @@ NodeParserRegistry(converter::FmkType fmk_type, const std::string &node_type, - 参数 - - `fmk_type`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#fmktype)说明。 + - `fmk_type`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#fmktype)说明。 - `node_type`: 节点的类型。 - - `node_parser`: NodeParser类型的共享智能指针实例, 具体见[NodeParserPtr](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#nodeparserptr)说明。 + - `node_parser`: NodeParser类型的共享智能指针实例, 具体见[NodeParserPtr](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#nodeparserptr)说明。 ### ~NodeParserRegistry @@ -67,13 +67,13 @@ static converter::NodeParserPtr GetNodeParser(converter::FmkType fmk_type, const - 参数 - - `fmk_type`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#fmktype)说明。 + - `fmk_type`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#fmktype)说明。 - `node_type`: 节点的类型。 ## REG_NODE_PARSER -\#include <[node_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/node_parser_registry.h)> +\#include <[node_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/node_parser_registry.h)> ```c++ #define REG_NODE_PARSER(fmk_type, node_type, node_parser) @@ -83,25 +83,25 @@ static converter::NodeParserPtr GetNodeParser(converter::FmkType fmk_type, const - 参数 - - `fmk_type`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#fmktype)说明。 + - `fmk_type`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#fmktype)说明。 - `node_type`: 节点的类型。 - - `node_parser`: NodeParser类型的共享智能指针实例, 具体见[NodeParserPtr](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#nodeparserptr)说明。 + - `node_parser`: NodeParser类型的共享智能指针实例, 具体见[NodeParserPtr](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#nodeparserptr)说明。 ## ModelParserCreator -\#include <[model_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/model_parser_registry.h)> +\#include <[model_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/model_parser_registry.h)> ```c++ typedef converter::ModelParser *(*ModelParserCreator)() ``` -创建[ModelParser](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#modelparser)的函数原型声明。 +创建[ModelParser](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#modelparser)的函数原型声明。 ## ModelParserRegistry -\#include <[model_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/model_parser_registry.h)> +\#include <[model_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/model_parser_registry.h)> ModelParserRegistry类用于注册及获取ModelParserCreator类型的函数指针。 @@ -115,7 +115,7 @@ ModelParserRegistry(FmkType fmk, ModelParserCreator creator) - 参数 - - `fmk`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#fmktype)说明。 + - `fmk`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#fmktype)说明。 - `creator`: ModelParserCreator类型的函数指针, 具体见[ModelParserCreator](#modelparsercreator)说明。 @@ -139,11 +139,11 @@ static ModelParser *GetModelParser(FmkType fmk) - 参数 - - `fmk`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#fmktype)说明。 + - `fmk`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#fmktype)说明。 ## REG_MODEL_PARSER -\#include <[model_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/model_parser_registry.h)> +\#include <[model_parser_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/model_parser_registry.h)> ```c++ #define REG_MODEL_PARSER(fmk, parserCreator) @@ -153,15 +153,15 @@ static ModelParser *GetModelParser(FmkType fmk) - 参数 - - `fmk`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#fmktype)说明。 + - `fmk`: 框架类型,具体见[FmkType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#fmktype)说明。 - `creator`: ModelParserCreator类型的函数指针, 具体见[ModelParserCreator](#modelparsercreator)说明。 -> 用户自定义的ModelParser,框架类型必须满足设定支持的框架类型[FmkType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_converter.html#fmktype)。 +> 用户自定义的ModelParser,框架类型必须满足设定支持的框架类型[FmkType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_converter.html#fmktype)。 ## PassBase -\#include <[pass_base.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/pass_base.h)> +\#include <[pass_base.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/pass_base.h)> PassBase定义了图优化的基类,以供用户继承并自定义图优化算法。 @@ -201,7 +201,7 @@ virtual bool Execute(const api::FuncGraphPtr &func_graph) = 0; ## PassBasePtr -\#include <[pass_base.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/pass_base.h)> +\#include <[pass_base.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/pass_base.h)> PassBase类的共享智能指针类型。 @@ -211,7 +211,7 @@ using PassBasePtr = std::shared_ptr ## PassPosition -\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/pass_registry.h)> +\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/pass_registry.h)> **enum**类型变量,定义扩展Pass的运行位置。 @@ -224,7 +224,7 @@ enum PassPosition { ## PassRegistry -\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/pass_registry.h)> +\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/pass_registry.h)> PassRegistry类用于注册及获取Pass类实例。 @@ -290,7 +290,7 @@ static PassBasePtr GetPassFromStoreRoom(const std::string &pass_name) ## REG_PASS -\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/pass_registry.h)> +\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/pass_registry.h)> ```c++ #define REG_PASS(name, pass) @@ -306,7 +306,7 @@ static PassBasePtr GetPassFromStoreRoom(const std::string &pass_name) ## REG_SCHEDULED_PASS -\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/pass_registry.h)> +\#include <[pass_registry.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/pass_registry.h)> ```c++ #define REG_SCHEDULED_PASS(position, names) @@ -322,7 +322,7 @@ static PassBasePtr GetPassFromStoreRoom(const std::string &pass_name) > MindSpore Lite开放了部分内置Pass,请见以下说明。用户可以在`names`参数中添加内置Pass的命名标识,以在指定运行处调用内置Pass。 > -> - `ConstFoldPass`: 将输入均是常量的节点进行离线计算,导出的模型将不含该节点。特别地,针对shape算子,在[inputShape](https://www.mindspore.cn/lite/docs/zh-CN/master/use/converter_tool.html#参数说明)给定的情形下,也会触发预计算。 +> - `ConstFoldPass`: 将输入均是常量的节点进行离线计算,导出的模型将不含该节点。特别地,针对shape算子,在[inputShape](https://www.mindspore.cn/lite/docs/zh-CN/r1.9/use/converter_tool.html#参数说明)给定的情形下,也会触发预计算。 > - `DumpGraph`: 导出当前状态下的模型。请确保当前模型为NHWC或者NCHW格式的模型,例如卷积算子等。 > - `ToNCHWFormat`: 将当前状态下的模型转换为NCHW的格式,例如,四维的图输入、卷积算子等。 > - `ToNHWCFormat`: 将当前状态下的模型转换为NHWC的格式,例如,四维的图输入、卷积算子等。 @@ -334,7 +334,7 @@ static PassBasePtr GetPassFromStoreRoom(const std::string &pass_name) ## KernelDesc -\#include <[registry/register_kernel.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/register_kernel.h)> +\#include <[registry/register_kernel.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel.h)> **struct**类型结构体,定义扩展kernel的基本属性。 @@ -349,7 +349,7 @@ struct KernelDesc { ## RegisterKernel -\#include <[registry/register_kernel.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/register_kernel.h)> +\#include <[registry/register_kernel.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel.h)> ### CreateKernel @@ -363,13 +363,13 @@ using CreateKernel = std::function( - 参数 - - `inputs`: 算子输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)。 + - `inputs`: 算子输入[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)。 - - `outputs`: 算子输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#mstensor)。 + - `outputs`: 算子输出[MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#mstensor)。 - `primitive`: 算子经由flatbuffers反序化为Primitive后的结果。 - - `ctx`: 算子的上下文[Context](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html#context)。 + - `ctx`: 算子的上下文[Context](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html#context)。 ### 公有成员函数 @@ -387,9 +387,9 @@ static Status RegKernel(const std::string &arch, const std::string &provider, Da - `provider`: 生产商名,由用户自定义。 - - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_datatype.html)。 + - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_datatype.html)。 - - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 + - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 - `creator`: 创建算子的函数指针,具体见[CreateKernel](#createkernel)的说明。 @@ -407,7 +407,7 @@ Custom算子注册。 - `provider`: 生产商名,由用户自定义。 - - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_datatype.html)。 + - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_datatype.html)。 - `type`: 算子类型,由用户自定义,确保唯一即可。 @@ -429,7 +429,7 @@ static CreateKernel GetCreator(const schema::Primitive *primitive, KernelDesc *d ## KernelReg -\#include <[registry/register_kernel.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/register_kernel.h)> +\#include <[registry/register_kernel.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel.h)> ### ~KernelReg @@ -453,9 +453,9 @@ KernelReg(const std::string &arch, const std::string &provider, DataType data_ty - `provider`: 生产商名,由用户自定义。 - - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_datatype.html)。 + - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_datatype.html)。 - - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 + - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 - `creator`: 创建算子的函数指针,具体见[CreateKernel](#createkernel)的说明。 @@ -471,7 +471,7 @@ KernelReg(const std::string &arch, const std::string &provider, DataType data_ty - `provider`: 生产商名,由用户自定义。 - - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_datatype.html)。 + - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_datatype.html)。 - `op_type`: 算子类型,由用户自定义,确保唯一即可。 @@ -491,9 +491,9 @@ KernelReg(const std::string &arch, const std::string &provider, DataType data_ty - `provider`: 生产商名,由用户自定义。 - - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_datatype.html)。 + - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_datatype.html)。 - - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 + - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 - `creator`: 创建算子的函数指针,具体见[CreateKernel](#createkernel)的说明。 @@ -511,7 +511,7 @@ KernelReg(const std::string &arch, const std::string &provider, DataType data_ty - `provider`: 生产商名,由用户自定义。 - - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore_datatype.html)。 + - `data_type`: 算子支持的数据类型,具体见[DataType](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore_datatype.html)。 - `op_type`: 算子类型,由用户自定义,确保唯一即可。 @@ -519,7 +519,7 @@ KernelReg(const std::string &arch, const std::string &provider, DataType data_ty ## KernelInterfaceCreator -\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/register_kernel_interface.h)> +\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel_interface.h)> 定义创建算子的函数指针类型。 @@ -529,7 +529,7 @@ using KernelInterfaceCreator = std::function +\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel_interface.h)> 算子扩展能力注册实现类。 @@ -563,7 +563,7 @@ static Status Reg(const std::string &provider, int op_type, const KernelInterfac - `provider`: 生产商,由用户自定义。 - - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 + - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 - `creator`: KernelInterface的创建函数,详细见[KernelInterfaceCreator](#kernelinterfacecreator)的说明。 @@ -585,7 +585,7 @@ static std::shared_ptr GetKernelInterface(const std::st ## KernelInterfaceReg -\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/register_kernel_interface.h)> +\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel_interface.h)> 算子扩展能力注册构造类。 @@ -601,7 +601,7 @@ KernelInterfaceReg(const std::string &provider, int op_type, const KernelInterfa - `provider`: 生产商,由用户自定义。 - - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 + - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 - `creator`: KernelInterface的创建函数,详细见[KernelInterfaceCreator](#kernelinterfacecreator)的说明。 @@ -621,7 +621,7 @@ KernelInterfaceReg(const std::string &provider, const std::string &op_type, cons ## REGISTER_KERNEL_INTERFACE -\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/register_kernel_interface.h)> +\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel_interface.h)> 注册KernelInterface的实现。 @@ -633,13 +633,13 @@ KernelInterfaceReg(const std::string &provider, const std::string &op_type, cons - `provider`: 生产商,由用户自定义。 - - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 + - `op_type`: 算子类型,定义在[ops.fbs](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/schema/ops.fbs)中,编绎时会生成到ops_generated.h,该文件可以在发布件中获取。 - `creator`: 创建KernelInterface的函数指针,具体见[KernelInterfaceCreator](#kernelinterfacecreator)的说明。 ## REGISTER_CUSTOM_KERNEL_INTERFACE -\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/register_kernel_interface.h)> +\#include <[registry/register_kernel_interface.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/register_kernel_interface.h)> 注册Custom算子对应的KernelInterface实现。 diff --git a/docs/lite/api/source_zh_cn/api_cpp/mindspore_registry_opencl.md b/docs/lite/api/source_zh_cn/api_cpp/mindspore_registry_opencl.md index ae2357de7f8625da3c66269adb9954fb49f9a731..df649702274a3aca1d686553a5208a35b0fe589c 100644 --- a/docs/lite/api/source_zh_cn/api_cpp/mindspore_registry_opencl.md +++ b/docs/lite/api/source_zh_cn/api_cpp/mindspore_registry_opencl.md @@ -1,6 +1,6 @@ # mindspore::registry::opencl - + ## 接口汇总 @@ -10,7 +10,7 @@ ## OpenCLRuntimeWrapper -\#include <[include/registry/opencl_runtime_wrapper.h](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/include/registry/opencl_runtime_wrapper.h)> +\#include <[include/registry/opencl_runtime_wrapper.h](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/include/registry/opencl_runtime_wrapper.h)> OpenCLRuntimeWrapper类包装了内部OpenCL的相关接口,用于支持南向GPU算子的开发。 @@ -127,7 +127,7 @@ Status SyncCommandQueue(); std::shared_ptr GetAllocator(); ``` -获取GPU内存分配器的智能指针。通过[Allocator接口](https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html),可申请GPU内存,用于OpenCL内核的运算。 +获取GPU内存分配器的智能指针。通过[Allocator接口](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_cpp/mindspore.html),可申请GPU内存,用于OpenCL内核的运算。 ### MapBuffer diff --git a/docs/lite/api/source_zh_cn/api_java/class_list.md b/docs/lite/api/source_zh_cn/api_java/class_list.md index d09b1c73cc6a7a6904eaa5ca5a0d4d6268e25c5d..b7f579e9cd0e199d021ee0f8b1f3f75bca3e7ddc 100644 --- a/docs/lite/api/source_zh_cn/api_java/class_list.md +++ b/docs/lite/api/source_zh_cn/api_java/class_list.md @@ -1,17 +1,17 @@ # 类列表 - + | 包 | 类 | 描述 | | ------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| com.mindspore.config | [MSContext](https://www.mindspore.cn/lite/api/zh-CN/master/api_java/mscontext.html) | MSContext用于保存执行期间的上下文。 | -| com.mindspore.config | [CpuBindMode](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java) | CpuBindMode定义了CPU绑定模式。 | -| com.mindspore.config | [DeviceType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java) | DeviceType定义了后端设备类型。 | -| com.mindspore | [Model](https://www.mindspore.cn/lite/api/zh-CN/master/api_java/model.html) | Model定义了MindSpore中的模型,用于计算图的编译和执行。 | -| com.mindspore | [Graph](https://www.mindspore.cn/lite/api/zh-CN/master/api_java/graph.html) | Model定义了MindSpore中的计算图。 | -| com.mindspore | [MSTensor](https://www.mindspore.cn/lite/api/zh-CN/master/api_java/mstensor.html) | MSTensor定义了MindSpore中的张量。 | -| com.mindspore | [ModelParallelRunner](https://www.mindspore.cn/lite/api/zh-CN/master/api_java/model_parallel_runner.html) | 定义了MindSpore Lite并发推理。 | -| com.mindspore.config | [DataType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java) | DataType定义了所支持的数据类型。 | -| com.mindspore.config | [Version](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/Version.java) | Version用于获取MindSpore的版本信息。 | -| com.mindspore.config | [ModelType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/ModelType.java) | ModelType 定义了模型文件的类型。 | -| com.mindspore.config | [RunnerConfig](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/RunnerConfig.java) | RunnerConfig 定义并发推理的配置参数。 | +| com.mindspore.config | [MSContext](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_java/mscontext.html) | MSContext用于保存执行期间的上下文。 | +| com.mindspore.config | [CpuBindMode](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java) | CpuBindMode定义了CPU绑定模式。 | +| com.mindspore.config | [DeviceType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java) | DeviceType定义了后端设备类型。 | +| com.mindspore | [Model](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_java/model.html) | Model定义了MindSpore中的模型,用于计算图的编译和执行。 | +| com.mindspore | [Graph](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_java/graph.html) | Model定义了MindSpore中的计算图。 | +| com.mindspore | [MSTensor](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_java/mstensor.html) | MSTensor定义了MindSpore中的张量。 | +| com.mindspore | [ModelParallelRunner](https://www.mindspore.cn/lite/api/zh-CN/r1.9/api_java/model_parallel_runner.html) | 定义了MindSpore Lite并发推理。 | +| com.mindspore.config | [DataType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java) | DataType定义了所支持的数据类型。 | +| com.mindspore.config | [Version](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/Version.java) | Version用于获取MindSpore的版本信息。 | +| com.mindspore.config | [ModelType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/ModelType.java) | ModelType 定义了模型文件的类型。 | +| com.mindspore.config | [RunnerConfig](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/RunnerConfig.java) | RunnerConfig 定义并发推理的配置参数。 | diff --git a/docs/lite/api/source_zh_cn/api_java/graph.md b/docs/lite/api/source_zh_cn/api_java/graph.md index 787064c568ba6c250ff130c2f371673a612647cb..073d08fcc71de32e47ab8175f8997abe86c245f5 100644 --- a/docs/lite/api/source_zh_cn/api_java/graph.md +++ b/docs/lite/api/source_zh_cn/api_java/graph.md @@ -1,6 +1,6 @@ # Graph - + ```java import com.mindspore.Graph; diff --git a/docs/lite/api/source_zh_cn/api_java/lite_java_example.rst b/docs/lite/api/source_zh_cn/api_java/lite_java_example.rst index b095e26e2b88419ae26e8d9444c7203d24dafbf0..bde309ed1335d5842cf40fe5c327066fa3c3177a 100644 --- a/docs/lite/api/source_zh_cn/api_java/lite_java_example.rst +++ b/docs/lite/api/source_zh_cn/api_java/lite_java_example.rst @@ -4,6 +4,6 @@ .. toctree:: :maxdepth: 1 - 极简Demo↗ - 基于Java接口的Android应用开发↗ - 高阶用法↗ \ No newline at end of file + 极简Demo↗ + 基于Java接口的Android应用开发↗ + 高阶用法↗ \ No newline at end of file diff --git a/docs/lite/api/source_zh_cn/api_java/model.md b/docs/lite/api/source_zh_cn/api_java/model.md index bbc6b046823fec2a1fd933e2d8f71f6892c035de..2ae348fd509b348fed28265a8a5570dba222470c 100644 --- a/docs/lite/api/source_zh_cn/api_java/model.md +++ b/docs/lite/api/source_zh_cn/api_java/model.md @@ -1,6 +1,6 @@ # Model - + ```java import com.mindspore.Model; diff --git a/docs/lite/api/source_zh_cn/api_java/model_parallel_runner.md b/docs/lite/api/source_zh_cn/api_java/model_parallel_runner.md index 7bf387f41d291cb83cb4e3e976829989dc2e2afc..9cc544bf9bfcd5a574fa83907e0ed611b65923f3 100644 --- a/docs/lite/api/source_zh_cn/api_java/model_parallel_runner.md +++ b/docs/lite/api/source_zh_cn/api_java/model_parallel_runner.md @@ -1,6 +1,6 @@ # ModelParallelRunner - + ```java import com.mindspore.config.RunnerConfig; diff --git a/docs/lite/api/source_zh_cn/api_java/mscontext.md b/docs/lite/api/source_zh_cn/api_java/mscontext.md index 413a531d70f9aab2743b7b009f7543e93438fe44..d63ccc2a313cf2aec138d9ca2bbc4b77cdfda903 100644 --- a/docs/lite/api/source_zh_cn/api_java/mscontext.md +++ b/docs/lite/api/source_zh_cn/api_java/mscontext.md @@ -1,6 +1,6 @@ # MSContext - + ```java import com.mindspore.config.MSContext; @@ -53,7 +53,7 @@ public boolean init(int threadNum, int cpuBindMode) - 参数 - `threadNum`: 线程数。 - - `cpuBindMode`: CPU绑定模式,`cpuBindMode`在[com.mindspore.config.CpuBindMode](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)中定义。 + - `cpuBindMode`: CPU绑定模式,`cpuBindMode`在[com.mindspore.config.CpuBindMode](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)中定义。 - 返回值 @@ -68,7 +68,7 @@ public boolean init(int threadNum, int cpuBindMode, boolean isEnableParallel) - 参数 - `threadNum`: 线程数。 - - `cpuBindMode`: CPU绑定模式,`cpuBindMode`在[com.mindspore.config.CpuBindMode](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)中定义。 + - `cpuBindMode`: CPU绑定模式,`cpuBindMode`在[com.mindspore.config.CpuBindMode](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/CpuBindMode.java)中定义。 - `isEnableParallel`: 是否开启异构并行。 - 返回值 @@ -85,7 +85,7 @@ boolean addDeviceInfo(int deviceType, boolean isEnableFloat16) - 参数 - - `deviceType`: 设备类型,`deviceType`在[com.mindspore.config.DeviceType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)中定义。 + - `deviceType`: 设备类型,`deviceType`在[com.mindspore.config.DeviceType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)中定义。 - `isEnableFloat16`: 是否开启fp16。 - 返回值 @@ -100,7 +100,7 @@ boolean addDeviceInfo(int deviceType, boolean isEnableFloat16, int npuFreq) - 参数 - - `deviceType`: 设备类型,`deviceType`在[com.mindspore.config.DeviceType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)中定义。 + - `deviceType`: 设备类型,`deviceType`在[com.mindspore.config.DeviceType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DeviceType.java)中定义。 - `isEnableFloat16`: 是否开启fp16。 - `npuFreq`: NPU运行频率,仅当deviceType为npu才需要。 diff --git a/docs/lite/api/source_zh_cn/api_java/mstensor.md b/docs/lite/api/source_zh_cn/api_java/mstensor.md index f3fb3d92a4ca812e9c87945c43618e6fd361bfa7..6b9aca398bc16a520680a6f10a4cf4a70e6555fe 100644 --- a/docs/lite/api/source_zh_cn/api_java/mstensor.md +++ b/docs/lite/api/source_zh_cn/api_java/mstensor.md @@ -1,6 +1,6 @@ # MSTensor - + ```java import com.mindspore.MSTensor; @@ -13,6 +13,7 @@ MSTensor定义了MindSpore中的张量。 | function | | ------------------------------------------ | | [MSTensor createTensor(String tensorName, int dataType, int[] tensorShape, ByteBuffer buffer)](#createtensor) | +| [MSTensor createTensor(String tensorName, Object obj)](#createtensor) | | [int[] getShape()](#getshape) | | [int getDataType()](#getdatatype) | | [byte[] getByteData()](#getbytedata) | @@ -21,6 +22,8 @@ MSTensor定义了MindSpore中的张量。 | [long[] getLongData()](#getlongdata) | | [void setData(byte[] data)](#setdata) | | [void setData(float[] data)](#setdata) | +| [void setData(int[] data)](#setdata) | +| [void setData(long[] data)](#setdata) | | [void setData(ByteBuffer data)](#setdata) | | [long size()](#size) | | [int elementsNum()](#elementsnum) | @@ -47,6 +50,21 @@ public static MSTensor createTensor(String tensorName, int dataType, int[] tenso MindSpore MSTensor。 +```java +public static MSTensor createTensor(String tensorName, Object obj) +``` + +生成MindSpore MSTensor。 + +- 参数 + + - `tensorName`: 张量名称。 + - `obj`: java的Array对象或者一个标量值,支持的数据类型:float、double、int、long、boolean。 + +- 返回值 + + MindSpore MSTensor。 + ## getShape ```java @@ -65,7 +83,7 @@ public int[] getShape() public int getDataType() ``` -DataType在[com.mindspore.DataType](https://gitee.com/mindspore/mindspore/blob/master/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java)中定义。 +DataType在[com.mindspore.DataType](https://gitee.com/mindspore/mindspore/blob/r1.9/mindspore/lite/java/src/main/java/com/mindspore/config/DataType.java)中定义。 - 返回值 @@ -141,6 +159,26 @@ public void setData(float[] data) - `data`: float[]类型的输入数据。 +```java +public void setData(int[] data) +``` + +设定MSTensor的输入数据。 + +- 参数 + + - `data`: int[]类型的输入数据。 + +```java +public void setData(long[] data) +``` + +设定MSTensor的输入数据。 + +- 参数 + + - `data`: long[]类型的输入数据。 + ```java public void setData(ByteBuffer data) ``` diff --git a/docs/lite/api/source_zh_cn/api_java/runner_config.md b/docs/lite/api/source_zh_cn/api_java/runner_config.md index b6f461d932fc49476e56b32d83d1914b63e91ae6..811dbd2715179f6e3550eb4d7eac70eeaa6823a8 100644 --- a/docs/lite/api/source_zh_cn/api_java/runner_config.md +++ b/docs/lite/api/source_zh_cn/api_java/runner_config.md @@ -1,6 +1,6 @@ # RunnerConfig - + RunnerConfig定义了MindSpore Lite并发推理的配置参数。 @@ -9,8 +9,10 @@ RunnerConfig定义了MindSpore Lite并发推理的配置参数。 | function | | ------------------------------------------------------------ | | [boolean init()](#init) | -| [boolean setWorkerNum()](#setworkernum) | -| [boolean setConfigInfo()](#setconfiginfo) | +| [void setWorkerNum()](#setworkernum) | +| [void setConfigInfo()](#setconfiginfo) | +| [void setConfigPath()](#setconfigpath) | +| [void getConfigPath()](#getconfigpath) | | [long getRunnerConfigPtr()](#getrunnerconfigptr) | ## init @@ -49,7 +51,7 @@ public void setWorkerNum(int workerNum) - 参数 - - `workerNum`: 配置文件中设置模型个数。 + - `workerNum`: 模型个数。 ## setConfigInfo @@ -64,6 +66,30 @@ public void setConfigInfo(String section, HashMap config) - `section`: 配置的章节名。 - `config`: 要更新的配置对。 +## setConfigPath + +```java +public void setConfigPath(String configPath) +``` + +并发推理中模型配置文件路径参数设置。 + +- 参数 + + - `configPath`: 配置文件路径。 + +## getConfigPath + +```java +public String getConfigPath() +``` + +获取RunnerConfig中设置的配置文件的路径。 + +- 返回值 + + 配置文件路径。 + ## getRunnerConfigPtr ```java diff --git a/docs/lite/api/source_zh_cn/conf.py b/docs/lite/api/source_zh_cn/conf.py index 53263fda062a360e763089c96575561e82a5d6bb..c6520e9ea5ab8041350269359587e5db7b03e562 100644 --- a/docs/lite/api/source_zh_cn/conf.py +++ b/docs/lite/api/source_zh_cn/conf.py @@ -297,6 +297,19 @@ with open("../_custom/sphinx_builder_html", "r", encoding="utf8") as f: exec(source_code, sphinx_builder_html.__dict__) +fileList = [] +for root, dirs, files in os.walk('../include/'): + for fileObj in files: + fileList.append(os.path.join(root, fileObj)) + +for file_name in fileList: + file_data = '' + with open(file_name, 'r', encoding='utf-8') as f: + data = f.read() + data = re.sub(r'/\*\*([\s\n\S]*?)\*/', '', data) + with open(file_name, 'w', encoding='utf-8') as p: + p.write(data) + #Remove "MS_API" in classes. # files_copyed = glob.glob("../include/*.h") # for file in files_copyed: diff --git a/docs/lite/docs/source_en/architecture_lite.md b/docs/lite/docs/source_en/architecture_lite.md index 9728f0aea5dda759e1dd776bb6850aec50d4478d..0fa89621d6eb8a93e4bf843c0d6e1c4d6a9e89d2 100644 --- a/docs/lite/docs/source_en/architecture_lite.md +++ b/docs/lite/docs/source_en/architecture_lite.md @@ -1,6 +1,6 @@ # Overall Architecture (Lite) - + MindSpore Lite is an ultra-fast, intelligent, and simplified AI engine that enables intelligent applications in all scenarios, provides E2E solutions for users, and helps users enable AI capabilities. diff --git a/docs/lite/docs/source_en/image_classification_lite.md b/docs/lite/docs/source_en/image_classification_lite.md index e75dca1c8144cd8f9173ce69c6e846634ee10456..0e4cd8f904a5d6548750e6ee5da1127c245312cc 100644 --- a/docs/lite/docs/source_en/image_classification_lite.md +++ b/docs/lite/docs/source_en/image_classification_lite.md @@ -1,6 +1,6 @@ # Image Classification Model - + ## Image classification introduction diff --git a/docs/lite/docs/source_en/image_segmentation_lite.md b/docs/lite/docs/source_en/image_segmentation_lite.md index 9f8d92fbd3e99f60687834dd2427607674966b3f..6e05e2563dba73036a264f4b53826f69354283a9 100644 --- a/docs/lite/docs/source_en/image_segmentation_lite.md +++ b/docs/lite/docs/source_en/image_segmentation_lite.md @@ -1,12 +1,12 @@ # Image Segmentation Model - + ## Image Segmentation introduction Image segmentation is used to detect the position of the object in the picture or a pixel belongs to which object. -Using MindSpore Lite to perform image segmentation [example](https://gitee.com/mindspore/models/tree/master/official/lite/image_segmentation). +Using MindSpore Lite to perform image segmentation [example](https://gitee.com/mindspore/models/tree/r1.9/official/lite/image_segmentation). ## Image segmentation model list diff --git a/docs/lite/docs/source_en/index.rst b/docs/lite/docs/source_en/index.rst index d15d07ab92dcbcda44d5b608344e5269d2c539f2..038b60b654489a8af08b12eb950026b44b66378a 100644 --- a/docs/lite/docs/source_en/index.rst +++ b/docs/lite/docs/source_en/index.rst @@ -210,7 +210,7 @@ MindSpore Lite Documentation