From c46067f493a98f9eed3c62e550aaee63a21800fa Mon Sep 17 00:00:00 2001 From: Chang Xu Date: Thu, 20 May 2021 10:17:08 +0800 Subject: [PATCH] patch nas&dist docs (#761) * update nas and distill docs --- docs/en/api_en/search_space_en.md | 4 +- .../quick_start/distillation_tutorial_en.md | 1 + docs/en/quick_start/nas_tutorial_en.md | 1 + .../dygraph/ofa/convert_supernet_api.rst | 2 +- docs/zh_cn/api_cn/dygraph/ofa/ofa_api.rst | 2 + .../static/dist/single_distiller_api.rst | 15 ++++--- docs/zh_cn/api_cn/static/nas/nas_api.rst | 20 +++++----- .../static/distillation_tutorial.md | 1 + docs/zh_cn/tutorials/nas/dygraph/nas_ofa.md | 40 +++++++++---------- 9 files changed, 48 insertions(+), 38 deletions(-) diff --git a/docs/en/api_en/search_space_en.md b/docs/en/api_en/search_space_en.md index f568bf83..a0ac58f9 100644 --- a/docs/en/api_en/search_space_en.md +++ b/docs/en/api_en/search_space_en.md @@ -47,8 +47,8 @@ For example, how to add a search space with resnet block. New search space can N ```python ### import necessary head file -from .search_space_base import SearchSpaceBase -from .search_space_registry import SEARCHSPACE +from paddleslim.nas import SearchSpaceBase +from paddleslim.nas import SEARCHSPACE import numpy as np ### use decorator SEARCHSPACE.register to register yourself search space to search space NameSpace diff --git a/docs/en/quick_start/distillation_tutorial_en.md b/docs/en/quick_start/distillation_tutorial_en.md index 7fb41065..8da2dcf2 100755 --- a/docs/en/quick_start/distillation_tutorial_en.md +++ b/docs/en/quick_start/distillation_tutorial_en.md @@ -25,6 +25,7 @@ This tutorial trains and verifies distillation model on the MNIST dataset. The i Select `ResNet50` as the teacher to perform distillation training on the students of the` MobileNet` architecture. ```python +import paddleslim as slim model = slim.models.MobileNet() student_program = fluid.Program() student_startup = fluid.Program() diff --git a/docs/en/quick_start/nas_tutorial_en.md b/docs/en/quick_start/nas_tutorial_en.md index 040f4653..622c8224 100644 --- a/docs/en/quick_start/nas_tutorial_en.md +++ b/docs/en/quick_start/nas_tutorial_en.md @@ -111,6 +111,7 @@ archs = sanas.next_archs()[0] ### 7.2 build program Get program according to the function in Step3 and model architecture from Step 7.1. ```python +paddle.enable_static() exe, train_program, eval_program, inputs, avg_cost, acc_top1, acc_top5 = build_program(archs) ``` diff --git a/docs/zh_cn/api_cn/dygraph/ofa/convert_supernet_api.rst b/docs/zh_cn/api_cn/dygraph/ofa/convert_supernet_api.rst index e596f5d8..ced8626b 100644 --- a/docs/zh_cn/api_cn/dygraph/ofa/convert_supernet_api.rst +++ b/docs/zh_cn/api_cn/dygraph/ofa/convert_supernet_api.rst @@ -61,7 +61,7 @@ PaddleSlim提供了三种方式构造超网络,下面分别介绍这三种方 model = mobilenet_v1() sp_net_config = supernet(kernel_size=(3, 5, 7), expand_ratio=[1, 2, 4]) - sp_model = Convert(sp_net_config).convert(self.model) + sp_model = Convert(sp_net_config).convert(model) 方式二 ------------------ diff --git a/docs/zh_cn/api_cn/dygraph/ofa/ofa_api.rst b/docs/zh_cn/api_cn/dygraph/ofa/ofa_api.rst index c6152b98..9a343341 100644 --- a/docs/zh_cn/api_cn/dygraph/ofa/ofa_api.rst +++ b/docs/zh_cn/api_cn/dygraph/ofa/ofa_api.rst @@ -54,6 +54,8 @@ DistillConfig .. code-block:: python from paddleslim.nas.ofa import DistillConfig + from paddle.vision.models import mobilenet_v1 + teacher_model = mobilenet_v1() default_distill_config = { 'lambda_distill': 0.01, 'teacher_model': teacher_model, diff --git a/docs/zh_cn/api_cn/static/dist/single_distiller_api.rst b/docs/zh_cn/api_cn/static/dist/single_distiller_api.rst index dce99541..05d7c108 100644 --- a/docs/zh_cn/api_cn/static/dist/single_distiller_api.rst +++ b/docs/zh_cn/api_cn/static/dist/single_distiller_api.rst @@ -26,9 +26,10 @@ merge **使用示例:** .. code-block:: python - + import paddle import paddle.fluid as fluid import paddleslim.dist as dist + paddle.enable_static() student_program = fluid.Program() with fluid.program_guard(student_program): x = fluid.layers.data(name='x', shape=[1, 28, 28]) @@ -73,9 +74,10 @@ fsp_loss出自论文 `A Gift from Knowledge Distillation: Fast Optimization, Net **使用示例:** .. code-block:: python - + import paddle import paddle.fluid as fluid import paddleslim.dist as dist + paddle.enable_static() student_program = fluid.Program() with fluid.program_guard(student_program): x = fluid.layers.data(name='x', shape=[1, 28, 28]) @@ -119,9 +121,10 @@ l2_loss **使用示例:** .. code-block:: python - + import paddle import paddle.fluid as fluid import paddleslim.dist as dist + paddle.enable_static() student_program = fluid.Program() with fluid.program_guard(student_program): x = fluid.layers.data(name='x', shape=[1, 28, 28]) @@ -169,9 +172,10 @@ soft_label_loss出自论文 `Distilling the Knowledge in a Neural Network