diff --git a/api/analysis_api/index.html b/api/analysis_api/index.html index bca26b35db77accff2a1911bb0f2cbdcb7aed61f..b672e99aded94a6716661a404ecf60eb1bdb0df9 100644 --- a/api/analysis_api/index.html +++ b/api/analysis_api/index.html @@ -206,59 +206,7 @@

示例:

-
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
-10
-11
-12
-13
-14
-15
-16
-17
-18
-19
-20
-21
-22
-23
-24
-25
-26
-27
-28
-29
-30
-31
-32
-33
-34
-35
-36
-37
-38
-39
-40
-41
-42
-43
-44
-45
-46
-47
-48
-49
-50
-51
-52
-53
import paddle.fluid as fluid
+
import paddle.fluid as fluid
 from paddle.fluid.param_attr import ParamAttr
 from paddleslim.analysis import flops
 
@@ -312,7 +260,6 @@
 
 print("FLOPs: {}".format(flops(main_program)))
 
-

model_size#

paddleslim.analysis.model_size(program) 源代码

@@ -326,51 +273,7 @@
  • model_size(int) - 整个网络的参数数量。
  • 示例:

    -
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    -32
    -33
    -34
    -35
    -36
    -37
    -38
    -39
    -40
    -41
    -42
    -43
    -44
    -45
    import paddle.fluid as fluid
    +
    import paddle.fluid as fluid
     from paddle.fluid.param_attr import ParamAttr
     from paddleslim.analysis import model_size
     
    @@ -416,7 +319,6 @@
     
     print("FLOPs: {}".format(model_size(main_program)))
     
    -

    TableLatencyEvaluator#

    diff --git a/api/nas_api/index.html b/api/nas_api/index.html index bcdf09d105551b68456c38ca1db95533319c75d0..4a442562e7f44190611351b37282e4d26ee0aff4 100644 --- a/api/nas_api/index.html +++ b/api/nas_api/index.html @@ -205,13 +205,10 @@

    返回: 一个SANAS类的实例

    示例代码: -
    1
    -2
    -3
    from paddleslim.nas import SANAS
    +
    from paddleslim.nas import SANAS
     config = [('MobileNetV2Space')]
     sanas = SANAS(config=config)
    -
    -

    +

    paddlesim.nas.SANAS.tokens2arch(tokens)
    通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。
    @@ -225,19 +222,13 @@ tokens是一个列表,token映射到搜索空间转换成相应的网络结构

    返回: 根据传入的token得到一个模型结构实例。

    示例代码: -
    1
    -2
    -3
    -4
    -5
    -6
    import paddle.fluid as fluid
    +
    import paddle.fluid as fluid
     input = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
     archs = sanas.token2arch(tokens)
     for arch in archs:
         output = arch(input)
         input = output
    -
    -

    +

    paddleslim.nas.SANAS.next_archs()
    获取下一组模型结构。
    @@ -245,19 +236,13 @@ tokens是一个列表,token映射到搜索空间转换成相应的网络结构

    返回: 返回模型结构实例的列表,形式为list。

    示例代码: -
    1
    -2
    -3
    -4
    -5
    -6
    import paddle.fluid as fluid
    +
    import paddle.fluid as fluid
     input = fluid.data(name='input', shape=[None, 3, 32, 32], dtype='float32')
     archs = sanas.next_archs()
     for arch in archs:
         output = arch(input)
         input = output
    -
    -

    +

    paddleslim.nas.SANAS.reward(score)
    把当前模型结构的得分情况回传。
    diff --git a/api/prune_api/index.html b/api/prune_api/index.html index 8843994e82b9b819eef7f6d75c5b6ecaaf2e1e84..51ffb312943152700082f46da206e8c0e56640da 100644 --- a/api/prune_api/index.html +++ b/api/prune_api/index.html @@ -196,11 +196,9 @@

    返回: 一个Pruner类的实例

    示例代码:

    -
    1
    -2
    from paddleslim.prune import Pruner
    +
    from paddleslim.prune import Pruner
     pruner = Pruner()
     
    -
    paddleslim.prune.Pruner.prune(program, scope, params, ratios, place=None, lazy=False, only_graph=False, param_backup=False, param_shape_backup=False)源代码
    @@ -218,13 +216,10 @@
  • params(list) - 需要被裁剪的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称: -
    1
    -2
    -3
    for block in program.blocks:
    +
    for block in program.blocks:
         for param in block.all_parameters():
             print("param: {}; shape: {}".format(param.name, param.shape))
    -
    -

    +

  • ratios(list) - 用于裁剪params的剪切率,类型为列表。该列表长度必须与params的长度一致。

    @@ -259,77 +254,7 @@

    示例:

    点击AIStudio执行以下示例代码。 -
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    -32
    -33
    -34
    -35
    -36
    -37
    -38
    -39
    -40
    -41
    -42
    -43
    -44
    -45
    -46
    -47
    -48
    -49
    -50
    -51
    -52
    -53
    -54
    -55
    -56
    -57
    -58
    -59
    -60
    -61
    -62
    -63
    -64
    -65
    -66
    -67
    -68
    -69
    -70
    -71
    import paddle.fluid as fluid
    +
    import paddle.fluid as fluid
     from paddle.fluid.param_attr import ParamAttr
     from paddleslim.prune import Pruner
     
    @@ -400,8 +325,7 @@
     for param in main_program.global_block().all_parameters():
         if "weights" in param.name:
             print("param name: {}; param shape: {}".format(param.name, param.shape))
    -
    -

    +


    sensitivity#

    @@ -422,13 +346,10 @@

    param_names(list) - 待分析的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称:

  • -
    1
    -2
    -3
    for block in program.blocks:
    +
    for block in program.blocks:
         for param in block.all_parameters():
             print("param: {}; shape: {}".format(param.name, param.shape))
     
    -
    • @@ -445,15 +366,7 @@
      • sensitivities(dict) - 存放敏感度信息的dict,其格式为:
      -
      1
      -2
      -3
      -4
      -5
      -6
      -7
      -8
      -9
      {"weight_0":
      +
      {"weight_0":
          {0.1: 0.22,
           0.2: 0.33
          },
      @@ -463,102 +376,11 @@
          }
       }
       
      -

      其中,weight_0是卷积层参数的名称,sensitivities['weight_0']的value为剪裁比例,value为精度损失的比例。

      示例:

      点击AIStudio运行以下示例代码。

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      -21
      -22
      -23
      -24
      -25
      -26
      -27
      -28
      -29
      -30
      -31
      -32
      -33
      -34
      -35
      -36
      -37
      -38
      -39
      -40
      -41
      -42
      -43
      -44
      -45
      -46
      -47
      -48
      -49
      -50
      -51
      -52
      -53
      -54
      -55
      -56
      -57
      -58
      -59
      -60
      -61
      -62
      -63
      -64
      -65
      -66
      -67
      -68
      -69
      -70
      -71
      -72
      -73
      -74
      -75
      -76
      -77
      -78
      -79
      -80
      -81
      -82
      -83
      -84
      -85
      -86
      -87
      -88
      -89
      -90
      -91
      import paddle
      +
      import paddle
       import numpy as np
       import paddle.fluid as fluid
       from paddle.fluid.param_attr import ParamAttr
      @@ -650,7 +472,6 @@
                                   pruned_ratios=[0.1, 0.2, 0.3])
       print(sensitivities)
       
      -

      merge_sensitive#

      @@ -667,15 +488,7 @@
      • sensitivities(dict) - 合并后的敏感度信息。其格式为:
      -
      1
      -2
      -3
      -4
      -5
      -6
      -7
      -8
      -9
      {"weight_0":
      +
      {"weight_0":
          {0.1: 0.22,
           0.2: 0.33
          },
      @@ -685,7 +498,6 @@
          }
       }
       
      -

      其中,weight_0是卷积层参数的名称,sensitivities['weight_0']的value为剪裁比例,value为精度损失的比例。

      示例:

      diff --git a/api/quantization_api/index.html b/api/quantization_api/index.html index aceb0b1143f810ddbb67321f0463c7164ba36d78..2d777bb3db1230b1d9e0df9a8eead30ee4f3f590 100644 --- a/api/quantization_api/index.html +++ b/api/quantization_api/index.html @@ -185,44 +185,7 @@

      量化配置#

      通过字典配置量化参数

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      -21
      -22
      -23
      -24
      -25
      -26
      -27
      -28
      -29
      -30
      -31
      -32
      -33
      -34
      -35
      -36
      -37
      -38
      TENSORRT_OP_TYPES = [
      +
      TENSORRT_OP_TYPES = [
           'mul', 'conv2d', 'pool2d', 'depthwise_conv2d', 'elementwise_add',
           'leaky_relu'
       ]
      @@ -261,7 +224,6 @@
           'is_full_quantize': False
       }
       
      -

      参数:

        @@ -337,43 +299,7 @@

        因为该接口会对opVariable做相应的删除和修改,所以此接口只能在训练完成之后调用。如果想转化训练的中间模型,可加载相应的参数之后再使用此接口。

        代码示例

        -
         1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        -10
        -11
        -12
        -13
        -14
        -15
        -16
        -17
        -18
        -19
        -20
        -21
        -22
        -23
        -24
        -25
        -26
        -27
        -28
        -29
        -30
        -31
        -32
        -33
        -34
        -35
        -36
        -37
        #encoding=utf8
        +
        #encoding=utf8
         import paddle.fluid as fluid
         import paddleslim.quant as quant
         
        @@ -411,7 +337,6 @@
         
         inference_prog = quant.convert(quant_eval_program, place, config)
         
        -

        更详细的用法请参考 量化训练demo

        quant_post#

        @@ -451,23 +376,7 @@

        注: 此示例不能直接运行,因为需要加载${model_dir}下的模型,所以不能直接运行。

        -

         1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        -10
        -11
        -12
        -13
        -14
        -15
        -16
        -17
        import paddle.fluid as fluid
        +

        import paddle.fluid as fluid
         import paddle.dataset.mnist as reader
         from paddleslim.quant import quant_post
         val_reader = reader.train()
        @@ -485,7 +394,6 @@
                 batch_size=16,
                 batch_nums=10)
         
        -
        更详细的用法请参考 离线量化demo

        quant_embedding#

        @@ -511,28 +419,7 @@

        返回类型

        fluid.Program

        代码示例 -
         1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        -10
        -11
        -12
        -13
        -14
        -15
        -16
        -17
        -18
        -19
        -20
        -21
        -22
        import paddle.fluid as fluid
        +
        import paddle.fluid as fluid
         import paddleslim.quant as quant
         
         train_program = fluid.Program()
        @@ -554,8 +441,7 @@
         
         config = {'params_name': 'emb', 'quantize_type': 'abs_max'}
         quant_program = quant.quant_embedding(infer_program, place, config)
        -
        -

        +

        更详细的用法请参考 Embedding量化demo

        diff --git a/api/single_distiller_api/index.html b/api/single_distiller_api/index.html index 1a7863b1d82d54fc7acc20eead6f3b96397d4c57..91b0d4a10e3bd910b242c702aabda4ec706d4a34 100644 --- a/api/single_distiller_api/index.html +++ b/api/single_distiller_api/index.html @@ -205,24 +205,7 @@

        data_name_mapteacher_var name到student_var name的映射,如果写反可能无法正确进行merge

        使用示例:

        -
         1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        -10
        -11
        -12
        -13
        -14
        -15
        -16
        -17
        -18
        import paddle.fluid as fluid
        +
        import paddle.fluid as fluid
         import paddleslim.dist as dist
         student_program = fluid.Program()
         with fluid.program_guard(student_program):
        @@ -241,7 +224,6 @@
         dist.merge(teacher_program, student_program,
                                   data_name_map, place)
         
        -

        fsp_loss#

        @@ -260,26 +242,7 @@

      返回: 由teacher_var1, teacher_var2, student_var1, student_var2组合得到的fsp_loss

      使用示例:

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      import paddle.fluid as fluid
      +
      import paddle.fluid as fluid
       import paddleslim.dist as dist
       student_program = fluid.Program()
       with fluid.program_guard(student_program):
      @@ -300,7 +263,6 @@
           distillation_loss = dist.fsp_loss('teacher_t1.tmp_1', 'teacher_t2.tmp_1',
                                             's1.tmp_1', 's2.tmp_1', main_program)
       
      -

      l2_loss#

      @@ -317,26 +279,7 @@

    返回: 由teacher_var, student_var组合得到的l2_loss

    使用示例:

    -
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    import paddle.fluid as fluid
    +
    import paddle.fluid as fluid
     import paddleslim.dist as dist
     student_program = fluid.Program()
     with fluid.program_guard(student_program):
    @@ -357,7 +300,6 @@
         distillation_loss = dist.l2_loss('teacher_t2.tmp_1', 's2.tmp_1',
                                          main_program)
     
    -

    soft_label_loss#

    @@ -376,26 +318,7 @@

    返回: 由teacher_var, student_var组合得到的soft_label_loss

    使用示例:

    -
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    import paddle.fluid as fluid
    +
    import paddle.fluid as fluid
     import paddleslim.dist as dist
     student_program = fluid.Program()
     with fluid.program_guard(student_program):
    @@ -416,7 +339,6 @@
         distillation_loss = dist.soft_label_loss('teacher_t2.tmp_1',
                                                  's2.tmp_1', main_program, 1., 1.)
     
    -

    loss#

    @@ -433,31 +355,7 @@

    返回:自定义的损失函数loss

    使用示例:

    -
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    import paddle.fluid as fluid
    +
    import paddle.fluid as fluid
     import paddleslim.dist as dist
     student_program = fluid.Program()
     with fluid.program_guard(student_program):
    @@ -483,7 +381,6 @@
         distillation_loss = dist.loss(main_program, adaptation_loss,
                 t_var='teacher_t2.tmp_1', s_var='s2.tmp_1')
     
    -

    注意事项

    diff --git a/extra.css b/extra.css index 2d5018975adace35e3a47009bbf2a9ef09de166c..2a1e1c74214a9f577e564b0d2603419c69c4b20d 100644 --- a/extra.css +++ b/extra.css @@ -1,4 +1,115 @@ -.codehilite { - width: 590px; - overflow: auto; -} +.codehilite code, .codehilite pre{color:#3F3F3F;background-color:#F7F7F7; +overflow: auto; +box-sizing: border-box; + + padding: 0.01em 16px; + padding-top: 0.5em; + padding-right-value: 16px; + padding-bottom: 0.5em; + padding-left-value: 16px; + padding-left-ltr-source: physical; + padding-left-rtl-source: physical; + padding-right-ltr-source: physical; + padding-right-rtl-source: physical; + +border-radius: 10px !important; + border-top-left-radius: 16px; + border-top-right-radius: 16px; + border-bottom-right-radius: 16px; + border-bottom-left-radius: 16px; + +border: 2px solid #CCC !important; + border-top-width: 1px; + border-right-width-value: 1px; + border-right-width-ltr-source: physical; + border-right-width-rtl-source: physical; + border-bottom-width: 1px; + border-left-width-value: 1px; + border-left-width-ltr-source: physical; + border-left-width-rtl-source: physical; + border-top-style: solid; + border-right-style-value: solid; + border-right-style-ltr-source: physical; + border-right-style-rtl-source: physical; + border-bottom-style: solid; + border-left-style-value: solid; + border-left-style-ltr-source: physical; + border-left-style-rtl-source: physical; + border-top-color: #CCC; + border-right-color-value: #CCC; + border-right-color-ltr-source: physical; + border-right-color-rtl-source: physical; + border-bottom-color: #CCC; + border-left-color-value: #CCC; + border-left-color-ltr-source: physical; + border-left-color-rtl-source: physical; + -moz-border-top-colors: none; + -moz-border-right-colors: none; + -moz-border-bottom-colors: none; + -moz-border-left-colors: none; + border-image-source: none; + border-image-slice: 100% 100% 100% 100%; + border-image-width: 1 1 1 1; + border-image-outset: 0 0 0 0; + border-image-repeat: stretch stretch;} +.codehilite .hll { background-color: #ffffcc } +.codehilite .c { color: #999988; font-style: italic } /* Comment */ +.codehilite .err { color: #a61717; background-color: #e3d2d2 } /* Error */ +.codehilite .k { color: #008800; font-weight: bold } /* Keyword */ +.codehilite .o { color: #000000; font-weight: bold } /* Operator */ +.codehilite .cm { color: #999988; font-style: italic } /* Comment.Multiline */ +.codehilite .cp { color: #999999; font-weight: bold; font-style: italic } /* Comment.Preproc */ +.codehilite .c1 { color: #999988; font-style: italic } /* Comment.Single */ +.codehilite .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */ +.codehilite .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ +.codehilite .ge { color: #000000; font-style: italic } /* Generic.Emph */ +.codehilite .gr { color: #aa0000 } /* Generic.Error */ +.codehilite .gh { color: #999999 } /* Generic.Heading */ +.codehilite .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ +.codehilite .go { color: #888888 } /* Generic.Output */ +.codehilite .gp { color: #555555 } /* Generic.Prompt */ +.codehilite .gs { font-weight: bold } /* Generic.Strong */ +.codehilite .gu { color: #aaaaaa } /* Generic.Subheading */ +.codehilite .gt { color: #aa0000 } /* Generic.Traceback */ +.codehilite .kc { color: #000000; font-weight: bold } /* Keyword.Constant */ +.codehilite .kd { color: #000000; font-weight: bold } /* Keyword.Declaration */ +.codehilite .kn { color: #000000; font-weight: bold } /* Keyword.Namespace */ +.codehilite .kp { color: #000000; font-weight: bold } /* Keyword.Pseudo */ +.codehilite .kr { color: #000000; font-weight: bold } /* Keyword.Reserved */ +.codehilite .kt { color: #445588; font-weight: bold } /* Keyword.Type */ +.codehilite .m { color: #009999 } /* Literal.Number */ +.codehilite .s { color: #d01040 } /* Literal.String */ +.codehilite .na { color: #008080 } /* Name.Attribute */ +.codehilite .nb { color: #0086B3 } /* Name.Builtin */ +.codehilite .nc { color: #445588; font-weight: bold } /* Name.Class */ +.codehilite .no { color: #008080 } /* Name.Constant */ +.codehilite .nd { color: #3c5d5d; font-weight: bold } /* Name.Decorator */ +.codehilite .ni { color: #800080 } /* Name.Entity */ +.codehilite .ne { color: #990000; font-weight: bold } /* Name.Exception */ +.codehilite .nf { color: #990000; font-weight: bold } /* Name.Function */ +.codehilite .nl { color: #990000; font-weight: bold } /* Name.Label */ +.codehilite .nn { color: #555555 } /* Name.Namespace */ +.codehilite .nt { color: #000080 } /* Name.Tag */ +.codehilite .nv { color: #008080 } /* Name.Variable */ +.codehilite .ow { color: #000000; font-weight: bold } /* Operator.Word */ +.codehilite .w { color: #bbbbbb } /* Text.Whitespace */ +.codehilite .mf { color: #009999 } /* Literal.Number.Float */ +.codehilite .mh { color: #009999 } /* Literal.Number.Hex */ +.codehilite .mi { color: #009999 } /* Literal.Number.Integer */ +.codehilite .mo { color: #009999 } /* Literal.Number.Oct */ +.codehilite .sb { color: #d01040 } /* Literal.String.Backtick */ +.codehilite .sc { color: #d01040 } /* Literal.String.Char */ +.codehilite .sd { color: #d01040 } /* Literal.String.Doc */ +.codehilite .s2 { color: #d01040 } /* Literal.String.Double */ +.codehilite .se { color: #d01040 } /* Literal.String.Escape */ +.codehilite .sh { color: #d01040 } /* Literal.String.Heredoc */ +.codehilite .si { color: #d01040 } /* Literal.String.Interpol */ +.codehilite .sx { color: #d01040 } /* Literal.String.Other */ +.codehilite .sr { color: #009926 } /* Literal.String.Regex */ +.codehilite .s1 { color: #d01040 } /* Literal.String.Single */ +.codehilite .ss { color: #990073 } /* Literal.String.Symbol */ +.codehilite .bp { color: #999999 } /* Name.Builtin.Pseudo */ +.codehilite .vc { color: #008080 } /* Name.Variable.Class */ +.codehilite .vg { color: #008080 } /* Name.Variable.Global */ +.codehilite .vi { color: #008080 } /* Name.Variable.Instance */ +.codehilite .il { color: #009999 } /* Literal.Number.Integer.Long */ diff --git a/index.html b/index.html index 58a033221e72190117472eb3ddbd8e8c580b5380..876c0480e5776ef0eb4654a2c356f3e7a3d798c0 100644 --- a/index.html +++ b/index.html @@ -212,20 +212,16 @@
    • 安装develop版本
    -
    1
    -2
    -3
    git clone https://github.com/PaddlePaddle/PaddleSlim.git
    +
    git clone https://github.com/PaddlePaddle/PaddleSlim.git
     cd PaddleSlim
     python setup.py install
     
    -
    • 安装官方发布的最新版本
    -
    1
    pip install paddleslim -i https://pypi.org/simple
    +
    pip install paddleslim -i https://pypi.org/simple
     
    -
    diff --git a/sitemap.xml.gz b/sitemap.xml.gz index dfd4ee14b0100b346b385ba0d2626b4f9b18e0c9..b365bca301f5458dcb837be1ad7157bcf0cdf6cb 100644 Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ diff --git a/table_latency/index.html b/table_latency/index.html index 6311c1c41d9e6d9d97916239e3325d71ed646199..c274e9ca707ce35897b6432b4c8b1bc80da4879c 100644 --- a/table_latency/index.html +++ b/table_latency/index.html @@ -209,9 +209,8 @@

    操作信息字段之间以逗号分割。操作信息与延迟信息之间以制表符分割。

    conv2d#

    格式

    -
    1
    op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stride,dilation\tlatency
    +
    op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stride,dilation\tlatency
     
    -

    字段解释

      @@ -232,9 +231,8 @@

    activation#

    格式

    -
    1
    op_type,n_in,c_in,h_in,w_in\tlatency
    +
    op_type,n_in,c_in,h_in,w_in\tlatency
     
    -

    字段解释

      @@ -247,9 +245,8 @@

    batch_norm#

    格式

    -
    1
    op_type,active_type,n_in,c_in,h_in,w_in\tlatency
    +
    op_type,active_type,n_in,c_in,h_in,w_in\tlatency
     
    -

    字段解释

      @@ -263,9 +260,8 @@

    eltwise#

    格式

    -
    1
    op_type,n_in,c_in,h_in,w_in\tlatency
    +
    op_type,n_in,c_in,h_in,w_in\tlatency
     
    -

    字段解释

      @@ -278,9 +274,8 @@

    pooling#

    格式

    -
    1
    op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,pool_type\tlatency
    +
    op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,pool_type\tlatency
     
    -

    字段解释

      @@ -299,9 +294,8 @@

    softmax#

    格式

    -
    1
    op_type,axis,n_in,c_in,h_in,w_in\tlatency
    +
    op_type,axis,n_in,c_in,h_in,w_in\tlatency
     
    -

    字段解释

      diff --git a/tutorials/distillation_demo/index.html b/tutorials/distillation_demo/index.html index cf97ce85fd4724f5cf1e96bf74a6bed76d4aa631..5119b614758b5a3833be8b744fab6d45d08b150e 100644 --- a/tutorials/distillation_demo/index.html +++ b/tutorials/distillation_demo/index.html @@ -195,17 +195,7 @@

      一般情况下,模型参数量越多,结构越复杂,其性能越好,但运算量和资源消耗也越大。知识蒸馏 就是一种将大模型学习到的有用信息(Dark Knowledge)压缩进更小更快的模型,而获得可以匹敌大模型结果的方法。

      在本示例中精度较高的大模型被称为teacher,精度稍逊但速度更快的小模型被称为student。

      1. 定义student_program#

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      student_program = fluid.Program()
      +
      student_program = fluid.Program()
       student_startup = fluid.Program()
       with fluid.program_guard(student_program, student_startup):
           image = fluid.data(
      @@ -217,29 +207,11 @@
           cost = fluid.layers.cross_entropy(input=out, label=label)
           avg_cost = fluid.layers.mean(x=cost)
       
      -

      2. 定义teacher_program#

      在定义好teacher_program后,可以一并加载训练好的pretrained_model。

      teacher_program内需要加上with fluid.unique_name.guard():,保证teacher的变量命名不被student_program影响,从而能够正确地加载预训练参数。

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      teacher_program = fluid.Program()
      +
      teacher_program = fluid.Program()
       teacher_startup = fluid.Program()
       with fluid.program_guard(teacher_program, teacher_startup):
           with fluid.unique_name.guard():
      @@ -258,28 +230,10 @@
           main_program=teacher_program,
           predicate=if_exist)
       
      -

      3.选择特征图#

      定义好student_programteacher_program后,我们需要从中两两对应地挑选出若干个特征图,留待后续为其添加知识蒸馏损失函数。

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      # get all student variables
      +
      # get all student variables
       student_vars = []
       for v in student_program.list_vars():
           try:
      @@ -298,29 +252,18 @@
       print("="*50+"teacher_model_vars"+"="*50)
       print(teacher_vars)
       
      -

      4. 合并Program(merge)#

      PaddlePaddle使用Program来描述计算图,为了同时计算student和teacher两个Program,这里需要将其两者合并(merge)为一个Program。

      merge过程操作较多,具体细节请参考merge API文档

      -
      1
      -2
      data_name_map = {'data': 'image'}
      +
      data_name_map = {'data': 'image'}
       merge(teacher_program, student_program, data_name_map, place)
       
      -

      5.添加蒸馏loss#

      在添加蒸馏loss的过程中,可能还会引入部分变量(Variable),为了避免命名重复这里可以使用with fluid.name_scope("distill"):为新引入的变量加一个命名作用域。

      另外需要注意的是,merge过程为teacher_program的变量统一加了名称前缀,默认是"teacher_", 这里在添加l2_loss时也要为teacher的变量加上这个前缀。

      -
      1
      -2
      -3
      -4
      -5
      -6
      -7
      -8
      -9
      with fluid.program_guard(student_program, student_startup):
      +
      with fluid.program_guard(student_program, student_startup):
           with fluid.name_scope("distill"):
               distill_loss = l2_loss('teacher_bn5c_branch2b.output.1.tmp_3',
                   'depthwise_conv2d_11.tmp_0', student_program)
      @@ -330,7 +273,6 @@
               opt.minimize(loss)
       exe.run(student_startup)
       
      -

      至此,我们就得到了用于蒸馏训练的student_program,后面就可以使用一个普通program一样对其开始训练和评估。

      diff --git a/tutorials/nas_demo/index.html b/tutorials/nas_demo/index.html index 40aa8f14ebf66030145a48de3e50b8a48491eb29..af5d68b63479b68171f9c9509057954df2cf1227 100644 --- a/tutorials/nas_demo/index.html +++ b/tutorials/nas_demo/index.html @@ -183,19 +183,10 @@

      请参考。

      1. 配置搜索空间#

      详细的搜索空间配置可以参考神经网络搜索API文档。 -
      1
      config = [('MobileNetV2Space')]
      -
      -

      +
      config = [('MobileNetV2Space')]
      +

      2. 利用搜索空间初始化SANAS实例#

      -
      1
      -2
      -3
      -4
      -5
      -6
      -7
      -8
      -9
      from paddleslim.nas import SANAS
      +
      from paddleslim.nas import SANAS
       
       sa_nas = SANAS(
           config,
      @@ -205,34 +196,13 @@
           search_steps=300,
           is_server=True)
       
      -

      3. 根据实例化的NAS得到当前的网络结构#

      -
      1
      archs = sa_nas.next_archs()
      +
      archs = sa_nas.next_archs()
       
      -

      4. 根据得到的网络结构和输入构造训练和测试program#

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      import paddle.fluid as fluid
      +
      import paddle.fluid as fluid
       
       train_program = fluid.Program()
       test_program = fluid.Program()
      @@ -253,23 +223,17 @@
           sgd = fluid.optimizer.SGD(learning_rate=1e-3)
           sgd.minimize(avg_cost)
       
      -

      5. 根据构造的训练program添加限制条件#

      -
      1
      -2
      -3
      -4
      from paddleslim.analysis import flops
      +
      from paddleslim.analysis import flops
       
       if flops(train_program) > 321208544:
           continue
       
      -

      6. 回传score#

      -
      1
      sa_nas.reward(score)
      +
      sa_nas.reward(score)
       
      -
      diff --git a/tutorials/pruning_demo/index.html b/tutorials/pruning_demo/index.html index 0478a356462ea2b5f9064d52dc07f4c6bd3b2f50..a9bb55dfc69f6dc35e1c30381bd20265f2c2f806 100644 --- a/tutorials/pruning_demo/index.html +++ b/tutorials/pruning_demo/index.html @@ -174,20 +174,16 @@

      该示例使用了paddleslim.Pruner工具类,用户接口使用介绍请参考:API文档

      确定待裁参数#

      不同模型的参数命名不同,在剪裁前需要确定待裁卷积层的参数名称。可通过以下方法列出所有参数名:

      -
      1
      -2
      for param in program.global_block().all_parameters():
      +
      for param in program.global_block().all_parameters():
           print("param name: {}; shape: {}".format(param.name, param.shape))
       
      -

      train.py脚本中,提供了get_pruned_params方法,根据用户设置的选项--model确定要裁剪的参数。

      启动裁剪任务#

      通过以下命令启动裁剪任务:

      -
      1
      -2
      export CUDA_VISIBLE_DEVICES=0
      +
      export CUDA_VISIBLE_DEVICES=0
       python train.py
       
      -

      执行python train.py --help查看更多选项。

      注意#

      diff --git a/tutorials/quant_aware_demo/index.html b/tutorials/quant_aware_demo/index.html index b2d6f9d729926de08e290905bb111de9ccb6040a..ef17921d0641dec7bde437cd469ab4a473c398b8 100644 --- a/tutorials/quant_aware_demo/index.html +++ b/tutorials/quant_aware_demo/index.html @@ -185,18 +185,7 @@

      请参考 量化API文档

      分类模型的离线量化流程#

      1. 配置量化参数#

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      quant_config = {
      +
      quant_config = {
           'weight_quantize_type': 'abs_max',
           'activation_quantize_type': 'moving_average_abs_max',
           'weight_bits': 8,
      @@ -209,26 +198,15 @@
           'quant_weight_only': False
       }
       
      -

      2. 对训练和测试program插入可训练量化op#

      -
      1
      -2
      -3
      val_program = quant_aware(val_program, place, quant_config, scope=None, for_test=True)
      +
      val_program = quant_aware(val_program, place, quant_config, scope=None, for_test=True)
       
       compiled_train_prog = quant_aware(train_prog, place, quant_config, scope=None, for_test=False)
       
      -

      3.关掉指定build策略#

      -
      1
      -2
      -3
      -4
      -5
      -6
      -7
      -8
      build_strategy = fluid.BuildStrategy()
      +
      build_strategy = fluid.BuildStrategy()
       build_strategy.fuse_all_reduce_ops = False
       build_strategy.sync_batch_norm = False
       exec_strategy = fluid.ExecutionStrategy()
      @@ -237,37 +215,17 @@
               build_strategy=build_strategy,
               exec_strategy=exec_strategy)
       
      -

      4. freeze program#

      -
      1
      -2
      -3
      -4
      -5
      float_program, int8_program = convert(val_program, 
      +
      float_program, int8_program = convert(val_program, 
                                             place,
                                             quant_config,
                                             scope=None,
                                             save_int8=True)
       
      -

      5.保存预测模型#

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      fluid.io.save_inference_model(
      +
      fluid.io.save_inference_model(
           dirname=float_path,
           feeded_var_names=[image.name],
           target_vars=[out], executor=exe,
      @@ -283,7 +241,6 @@
           model_filename=int8_path + '/model',
           params_filename=int8_path + '/params')
       
      -
      diff --git a/tutorials/quant_embedding_demo/index.html b/tutorials/quant_embedding_demo/index.html index a19595c0cf665a854db9c5dc71d29b0ac25336f5..bf7e6b4691a52f681053315ff16e7ba715d9ccb8 100644 --- a/tutorials/quant_embedding_demo/index.html +++ b/tutorials/quant_embedding_demo/index.html @@ -198,16 +198,7 @@

      以下将以 基于skip-gram的word2vector模型 为例来说明如何使用quant_embedding接口。首先介绍 基于skip-gram的word2vector模型 的正常训练和测试流程。

      基于skip-gram的word2vector模型#

      以下是本例的简要目录结构及说明:

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      .
      +
      .
       ├── cluster_train.py    # 分布式训练函数
       ├── cluster_train.sh    # 本地模拟多机脚本
       ├── train.py            # 训练函数
      @@ -218,59 +209,37 @@
       ├── train.py            # 训练函数
       └── utils.py            # 通用函数
       
      -

      介绍#

      本例实现了skip-gram模式的word2vector模型。

      同时推荐用户参考 IPython Notebook demo

      数据下载#

      全量数据集使用的是来自1 Billion Word Language Model Benchmark的(http://www.statmt.org/lm-benchmark) 的数据集.

      -
      1
      -2
      -3
      -4
      mkdir data
      +
      mkdir data
       wget http://www.statmt.org/lm-benchmark/1-billion-word-language-modeling-benchmark-r13output.tar.gz
       tar xzvf 1-billion-word-language-modeling-benchmark-r13output.tar.gz
       mv 1-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/
       
      -

      备用数据地址下载命令如下

      -
      1
      -2
      -3
      -4
      mkdir data
      +
      mkdir data
       wget https://paddlerec.bj.bcebos.com/word2vec/1-billion-word-language-modeling-benchmark-r13output.tar
       tar xvf 1-billion-word-language-modeling-benchmark-r13output.tar
       mv 1-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/
       
      -

      为了方便快速验证,我们也提供了经典的text8样例数据集,包含1700w个词。 下载命令如下

      -
      1
      -2
      -3
      -4
      mkdir data
      +
      mkdir data
       wget https://paddlerec.bj.bcebos.com/word2vec/text.tar
       tar xvf text.tar
       mv text data/
       
      -

      数据预处理#

      以样例数据集为例进行预处理。全量数据集注意解压后以training-monolingual.tokenized.shuffled 目录为预处理目录,和样例数据集的text目录并列。

      词典格式: 词<空格>词频。注意低频词用'UNK'表示

      可以按格式自建词典,如果自建词典跳过第一步。 -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      the 1061396
      +
      the 1061396
       of 593677
       and 416629
       one 411764
      @@ -280,76 +249,43 @@ a 325873
       to 316376
       zero 264975
       nine 250430
      -
      -

      +

      第一步根据英文语料生成词典,中文语料可以通过修改text_strip方法自定义处理方法。

      -
      1
      python preprocess.py --build_dict --build_dict_corpus_dir data/text/ --dict_path data/test_build_dict
      +
      python preprocess.py --build_dict --build_dict_corpus_dir data/text/ --dict_path data/test_build_dict
       
      -

      第二步根据词典将文本转成id, 同时进行downsample,按照概率过滤常见词, 同时生成word和id映射的文件,文件名为词典+"word_to_id"。

      -
      1
      python preprocess.py --filter_corpus --dict_path data/test_build_dict --input_corpus_dir data/text --output_corpus_dir data/convert_text8 --min_count 5 --downsample 0.001
      +
      python preprocess.py --filter_corpus --dict_path data/test_build_dict --input_corpus_dir data/text --output_corpus_dir data/convert_text8 --min_count 5 --downsample 0.001
       
      -

      训练#

      具体的参数配置可运行

      -
      1
      python train.py -h
      +
      python train.py -h
       
      -

      单机多线程训练 -
      1
      OPENBLAS_NUM_THREADS=1 CPU_NUM=5 python train.py --train_data_dir data/convert_text8 --dict_path data/test_build_dict --num_passes 10 --batch_size 100 --model_output_dir v1_cpu5_b100_lr1dir --base_lr 1.0 --print_batch 1000 --with_speed --is_sparse
      -
      -

      +
      OPENBLAS_NUM_THREADS=1 CPU_NUM=5 python train.py --train_data_dir data/convert_text8 --dict_path data/test_build_dict --num_passes 10 --batch_size 100 --model_output_dir v1_cpu5_b100_lr1dir --base_lr 1.0 --print_batch 1000 --with_speed --is_sparse
      +

      本地单机模拟多机训练

      -
      1
      sh cluster_train.sh
      +
      sh cluster_train.sh
       
      -

      本示例中按照单机多线程训练的命令进行训练,训练完毕后,可看到在当前文件夹下保存模型的路径为: v1_cpu5_b100_lr1dir, 运行 ls v1_cpu5_b100_lr1dir可看到该文件夹下保存了训练的10个epoch的模型文件。 -
      1
      pass-0  pass-1  pass-2  pass-3  pass-4  pass-5  pass-6  pass-7  pass-8  pass-9
      -
      -

      +
      pass-0  pass-1  pass-2  pass-3  pass-4  pass-5  pass-6  pass-7  pass-8  pass-9
      +

      预测#

      测试集下载命令如下

      -
      1
      -2
      -3
      -4
      #全量数据集测试集
      +
      #全量数据集测试集
       wget https://paddlerec.bj.bcebos.com/word2vec/test_dir.tar
       #样本数据集测试集
       wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar
       
      -

      预测命令,注意词典名称需要加后缀"word_to_id", 此文件是预处理阶段生成的。 -
      1
      python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/  --start_index 0 --last_index 9
      +
      python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/  --start_index 0 --last_index 9
       
      -
      运行该预测命令, 可看到如下输出 -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      -21
      -22
      ('start index: ', 0, ' last_index:', 9)
      +
      ('start index: ', 0, ' last_index:', 9)
       ('vocab_size:', 63642)
       step:1 249
       epoch:0          acc:0.014
      @@ -371,57 +307,20 @@ step:1 2606
       epoch:8          acc:0.146
       step:1 2722
       epoch:9          acc:0.153
      -
      -

      +

      量化基于skip-gram的word2vector模型#

      量化配置为: -
      1
      -2
      -3
      -4
      config = {
      +
      config = {
               'params_name': 'emb',
               'quantize_type': 'abs_max'
               }
      -
      -

      +

      运行命令为:

      -
      1
      python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/  --start_index 0 --last_index 9 --emb_quant True
      +
      python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/  --start_index 0 --last_index 9 --emb_quant True
       
      -

      运行输出为:

      -
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      -21
      -22
      -23
      -24
      -25
      -26
      -27
      -28
      -29
      -30
      -31
      -32
      ('start index: ', 0, ' last_index:', 9)
      +
      ('start index: ', 0, ' last_index:', 9)
       ('vocab_size:', 63642)
       quant_embedding config {'quantize_type': 'abs_max', 'params_name': 'emb', 'quantize_bits': 8, 'dtype': 'int8'}
       step:1 253
      @@ -454,7 +353,6 @@ quant_embedding config {'quantize_type': 'abs_max', 'params_
       step:1 2719
       epoch:9          acc:0.153
       
      -

      量化后的模型保存在./output_quant中,可看到量化后的参数'emb.int8'的大小为3.9M, 在./v1_cpu5_b100_lr1dir中可看到量化前的参数'emb'的大小为16M。

      diff --git a/tutorials/quant_post_demo/index.html b/tutorials/quant_post_demo/index.html index dec40dc769ef9e06bb35598356323f1ce571c504..cbaedcbbf558322af459cc2b7910d1ac813fec48 100644 --- a/tutorials/quant_post_demo/index.html +++ b/tutorials/quant_post_demo/index.html @@ -196,15 +196,13 @@

      在当前文件夹下创建'pretrain'文件夹,将mobilenetv1模型在该文件夹下解压,解压后的目录为pretrain/MobileNetV1_pretrained

      导出模型#

      通过运行以下命令可将模型转化为离线量化接口可用的模型: -
      1
      python export_model.py --model "MobileNet" --pretrained_model ./pretrain/MobileNetV1_pretrained --data imagenet
      +
      python export_model.py --model "MobileNet" --pretrained_model ./pretrain/MobileNetV1_pretrained --data imagenet
       
      -
      转化之后的模型存储在inference_model/MobileNet/文件夹下,可看到该文件夹下有'model', 'weights'两个文件。

      离线量化#

      接下来对导出的模型文件进行离线量化,离线量化的脚本为quant_post.py,脚本中使用接口paddleslim.quant.quant_post对模型进行离线量化。运行命令为: -
      1
      python quant_post.py --model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights
      -
      -

      +
      python quant_post.py --model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights
      +

      • model_path: 需要量化的模型坐在的文件夹
      • save_path: 量化后的模型保存的路径
      • @@ -218,22 +216,18 @@

        测试精度#

        使用eval.py脚本对量化前后的模型进行测试,得到模型的分类精度进行对比。

        首先测试量化前的模型的精度,运行以下命令: -
        1
        python eval.py --model_path ./inference_model/MobileNet --model_name model --params_name weights
        +
        python eval.py --model_path ./inference_model/MobileNet --model_name model --params_name weights
         
        -
        精度输出为: -
        1
        top1_acc/top5_acc= [0.70913923 0.89548034]
        -
        -

        +
        top1_acc/top5_acc= [0.70913923 0.89548034]
        +

        使用以下命令测试离线量化后的模型的精度:

        -
        1
        python eval.py --model_path ./quant_model_train/MobileNet
        +
        python eval.py --model_path ./quant_model_train/MobileNet
         
        -

        精度输出为 -
        1
        top1_acc/top5_acc= [0.70141864 0.89086477]
        +
        top1_acc/top5_acc= [0.70141864 0.89086477]
         
        -
        从以上精度对比可以看出,对mobilenetimagenet上的分类模型进行离线量化后 top1精度损失为0.77%top5精度损失为0.46%.

        diff --git a/tutorials/sensitivity_demo/index.html b/tutorials/sensitivity_demo/index.html index 4aafeebd0a6d8109504435af003cf00072b7c959..3e5fc373be6d9761e5c2971a12fbc03e77d06de4 100644 --- a/tutorials/sensitivity_demo/index.html +++ b/tutorials/sensitivity_demo/index.html @@ -177,11 +177,9 @@

      2. 运行示例#

      在路径PaddleSlim/demo/sensitive下执行以下代码运行示例:

      -
      1
      -2
      export CUDA_VISIBLE_DEVICES=0
      +
      export CUDA_VISIBLE_DEVICES=0
       python train.py --model "MobileNetV1"
       
      -

      通过python train.py --help查看更多选项。

      3. 重要步骤说明#

      @@ -190,14 +188,7 @@ python train.py --model "MobileNetV1"

      调用paddleslim.prune.sensitivity接口计算敏感度。敏感度信息会追加到sensitivities_file选项所指定的文件中,如果需要重新计算敏感度,需要先删除sensitivities_file文件。

      如果模型评估速度较慢,可以通过多进程的方式加速敏感度计算过程。比如在进程1中设置pruned_ratios=[0.1, 0.2, 0.3, 0.4],并将敏感度信息存放在文件sensitivities_0.data中,然后在进程2中设置pruned_ratios=[0.5, 0.6, 0.7],并将敏感度信息存储在文件sensitivities_1.data中。这样每个进程只会计算指定剪切率下的敏感度信息。多进程可以运行在单机多卡,或多机多卡。

      代码如下:

      -
      1
      -2
      -3
      -4
      -5
      -6
      -7
      -8
      # 进程1
      +
      # 进程1
       sensitivity(
           val_program,
           place,
      @@ -206,16 +197,8 @@ python train.py --model "MobileNetV1"
           sensitivities_file="sensitivities_0.data",
           pruned_ratios=[0.1, 0.2, 0.3, 0.4])
       
      -
      -
      1
      -2
      -3
      -4
      -5
      -6
      -7
      -8
      # 进程2
      +
      # 进程2
       sensitivity(
           val_program,
           place,
      @@ -224,19 +207,16 @@ python train.py --model "MobileNetV1"
           sensitivities_file="sensitivities_1.data",
           pruned_ratios=[0.5, 0.6, 0.7])
       
      -

      3.2 合并敏感度#

      如果用户通过上一节多进程的方式生成了多个存储敏感度信息的文件,可以通过paddleslim.prune.merge_sensitive将其合并,合并后的敏感度信息存储在一个dict中。代码如下:

      -
      1
      sens = merge_sensitive(["./sensitivities_0.data", "./sensitivities_1.data"])
      +
      sens = merge_sensitive(["./sensitivities_0.data", "./sensitivities_1.data"])
       
      -

      3.3 计算剪裁率#

      调用paddleslim.prune.get_ratios_by_loss接口计算一组剪裁率。

      -
      1
      ratios = get_ratios_by_loss(sens, 0.01)
      +
      ratios = get_ratios_by_loss(sens, 0.01)
       
      -

      其中,0.01为一个阈值,对于任意卷积层,其剪裁率为使精度损失低于阈值0.01的最大剪裁率。

      用户在计算出一组剪裁率之后可以通过接口paddleslim.prune.Pruner剪裁网络,并用接口paddleslim.analysis.flops计算FLOPs。如果FLOPs不满足要求,调整阈值重新计算出一组剪裁率。