Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
a7fe788c
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
1 年多 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a7fe788c
编写于
1月 17, 2020
作者:
B
baiyfbupt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Deployed
d95da67b
with MkDocs version: 1.0.4
上级
f5fac6bc
变更
18
展开全部
隐藏空白更改
内联
并排
Showing
18 changed file
with
207 addition
and
955 deletion
+207
-955
api/analysis_api/index.html
api/analysis_api/index.html
+2
-100
api/nas_api/index.html
api/nas_api/index.html
+6
-21
api/prune_api/index.html
api/prune_api/index.html
+9
-197
api/quantization_api/index.html
api/quantization_api/index.html
+5
-119
api/single_distiller_api/index.html
api/single_distiller_api/index.html
+5
-108
extra.css
extra.css
+115
-4
index.html
index.html
+3
-7
search/search_index.json
search/search_index.json
+1
-1
search_space/index.html
search_space/index.html
+1
-63
sitemap.xml.gz
sitemap.xml.gz
+0
-0
table_latency/index.html
table_latency/index.html
+6
-12
tutorials/distillation_demo/index.html
tutorials/distillation_demo/index.html
+5
-63
tutorials/nas_demo/index.html
tutorials/nas_demo/index.html
+7
-43
tutorials/pruning_demo/index.html
tutorials/pruning_demo/index.html
+2
-6
tutorials/quant_aware_demo/index.html
tutorials/quant_aware_demo/index.html
+5
-48
tutorials/quant_embedding_demo/index.html
tutorials/quant_embedding_demo/index.html
+22
-124
tutorials/quant_post_demo/index.html
tutorials/quant_post_demo/index.html
+8
-14
tutorials/sensitivity_demo/index.html
tutorials/sensitivity_demo/index.html
+5
-25
未找到文件。
api/analysis_api/index.html
浏览文件 @
a7fe788c
...
@@ -206,59 +206,7 @@
...
@@ -206,59 +206,7 @@
</li>
</li>
</ul>
</ul>
<p><strong>
示例:
</strong></p>
<p><strong>
示例:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.analysis
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
flops
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.analysis
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
flops
</span>
...
@@ -312,7 +260,6 @@
...
@@ -312,7 +260,6 @@
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
FLOPs:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
flops
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)))
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
FLOPs:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
flops
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)))
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h2
id=
"model_size"
>
model_size
<a
class=
"headerlink"
href=
"#model_size"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"model_size"
>
model_size
<a
class=
"headerlink"
href=
"#model_size"
title=
"Permanent link"
>
#
</a></h2>
<p>
paddleslim.analysis.model_size(program)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/model_size.py"
>
源代码
</a></p>
<p>
paddleslim.analysis.model_size(program)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/analysis/model_size.py"
>
源代码
</a></p>
...
@@ -326,51 +273,7 @@
...
@@ -326,51 +273,7 @@
<li><strong>
model_size(int)
</strong>
- 整个网络的参数数量。
</li>
<li><strong>
model_size(int)
</strong>
- 整个网络的参数数量。
</li>
</ul>
</ul>
<p><strong>
示例:
</strong></p>
<p><strong>
示例:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.analysis
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
model_size
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.analysis
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
model_size
</span>
...
@@ -416,7 +319,6 @@
...
@@ -416,7 +319,6 @@
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
FLOPs:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
model_size
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)))
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
FLOPs:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
model_size
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)))
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h2
id=
"tablelatencyevaluator"
>
TableLatencyEvaluator
<a
class=
"headerlink"
href=
"#tablelatencyevaluator"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"tablelatencyevaluator"
>
TableLatencyEvaluator
<a
class=
"headerlink"
href=
"#tablelatencyevaluator"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
...
api/nas_api/index.html
浏览文件 @
a7fe788c
...
@@ -205,13 +205,10 @@
...
@@ -205,13 +205,10 @@
<p><strong>
返回:
</strong>
<p><strong>
返回:
</strong>
一个SANAS类的实例
</p>
一个SANAS类的实例
</p>
<p><strong>
示例代码:
</strong>
<p><strong>
示例代码:
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.nas
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SANAS
</span>
2
3
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.nas
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SANAS
</span>
<span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[(
</span><span
class=
"s1"
>
'
MobileNetV2Space
'
</span><span
class=
"p"
>
)]
</span>
<span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[(
</span><span
class=
"s1"
>
'
MobileNetV2Space
'
</span><span
class=
"p"
>
)]
</span>
<span
class=
"n"
>
sanas
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
SANAS
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
config
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
config
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
sanas
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
SANAS
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
config
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
config
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div></p>
</td></tr></table></p>
<dl>
<dl>
<dt>
paddlesim.nas.SANAS.tokens2arch(tokens)
</dt>
<dt>
paddlesim.nas.SANAS.tokens2arch(tokens)
</dt>
<dd>
通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。
</dd>
<dd>
通过一组token得到实际的模型结构,一般用来把搜索到最优的token转换为模型结构用来做最后的训练。
</dd>
...
@@ -225,19 +222,13 @@ tokens是一个列表,token映射到搜索空间转换成相应的网络结构
...
@@ -225,19 +222,13 @@ tokens是一个列表,token映射到搜索空间转换成相应的网络结构
<p><strong>
返回:
</strong>
<p><strong>
返回:
</strong>
根据传入的token得到一个模型结构实例。
</p>
根据传入的token得到一个模型结构实例。
</p>
<p><strong>
示例代码:
</strong>
<p><strong>
示例代码:
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
name
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
input
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
shape
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
3
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
dtype
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
float32
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
name
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
input
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
shape
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
3
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
dtype
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
float32
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
archs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
sanas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
token2arch
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
tokens
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
archs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
sanas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
token2arch
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
tokens
</span><span
class=
"p"
>
)
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
arch
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
archs
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
arch
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
archs
</span><span
class=
"p"
>
:
</span>
<span
class=
"n"
>
output
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
arch
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
output
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
arch
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
output
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
output
</span>
</pre></div>
</pre></div></p>
</td></tr></table></p>
<dl>
<dl>
<dt>
paddleslim.nas.SANAS.next_archs()
</dt>
<dt>
paddleslim.nas.SANAS.next_archs()
</dt>
<dd>
获取下一组模型结构。
</dd>
<dd>
获取下一组模型结构。
</dd>
...
@@ -245,19 +236,13 @@ tokens是一个列表,token映射到搜索空间转换成相应的网络结构
...
@@ -245,19 +236,13 @@ tokens是一个列表,token映射到搜索空间转换成相应的网络结构
<p><strong>
返回:
</strong>
<p><strong>
返回:
</strong>
返回模型结构实例的列表,形式为list。
</p>
返回模型结构实例的列表,形式为list。
</p>
<p><strong>
示例代码:
</strong>
<p><strong>
示例代码:
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
name
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
input
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
shape
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
3
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
dtype
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
float32
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
name
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
input
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
shape
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
3
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
,
</span>
<span
class=
"mi"
>
32
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
dtype
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
float32
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
archs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
sanas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
next_archs
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
archs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
sanas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
next_archs
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
arch
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
archs
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
arch
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
archs
</span><span
class=
"p"
>
:
</span>
<span
class=
"n"
>
output
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
arch
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
output
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
arch
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
output
</span>
<span
class=
"nb"
>
input
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
output
</span>
</pre></div>
</pre></div></p>
</td></tr></table></p>
<dl>
<dl>
<dt>
paddleslim.nas.SANAS.reward(score)
</dt>
<dt>
paddleslim.nas.SANAS.reward(score)
</dt>
<dd>
把当前模型结构的得分情况回传。
</dd>
<dd>
把当前模型结构的得分情况回传。
</dd>
...
...
api/prune_api/index.html
浏览文件 @
a7fe788c
...
@@ -196,11 +196,9 @@
...
@@ -196,11 +196,9 @@
</ul>
</ul>
<p><strong>
返回:
</strong>
一个Pruner类的实例
</p>
<p><strong>
返回:
</strong>
一个Pruner类的实例
</p>
<p><strong>
示例代码:
</strong></p>
<p><strong>
示例代码:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.prune
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
Pruner
</span>
2
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.prune
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
Pruner
</span>
<span
class=
"n"
>
pruner
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
Pruner
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
pruner
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
Pruner
</span><span
class=
"p"
>
()
</span>
</pre></div>
</pre></div>
</td></tr></table>
<dl>
<dl>
<dt>
paddleslim.prune.Pruner.prune(program, scope, params, ratios, place=None, lazy=False, only_graph=False, param_backup=False, param_shape_backup=False)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/pruner.py#L36"
>
源代码
</a></dt>
<dt>
paddleslim.prune.Pruner.prune(program, scope, params, ratios, place=None, lazy=False, only_graph=False, param_backup=False, param_shape_backup=False)
<a
href=
"https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/prune/pruner.py#L36"
>
源代码
</a></dt>
...
@@ -218,13 +216,10 @@
...
@@ -218,13 +216,10 @@
</li>
</li>
<li>
<li>
<p><strong>
params(list
<str>
)
</strong>
- 需要被裁剪的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称:
<p><strong>
params(list
<str>
)
</strong>
- 需要被裁剪的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称:
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
for
</span>
<span
class=
"n"
>
block
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
blocks
</span><span
class=
"p"
>
:
</span>
2
3
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
for
</span>
<span
class=
"n"
>
block
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
blocks
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
block
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
block
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
</pre></div>
</pre></div></p>
</td></tr></table></p>
</li>
</li>
<li>
<li>
<p><strong>
ratios(list
<float>
)
</strong>
- 用于裁剪
<code>
params
</code>
的剪切率,类型为列表。该列表长度必须与
<code>
params
</code>
的长度一致。
</p>
<p><strong>
ratios(list
<float>
)
</strong>
- 用于裁剪
<code>
params
</code>
的剪切率,类型为列表。该列表长度必须与
<code>
params
</code>
的长度一致。
</p>
...
@@ -259,77 +254,7 @@
...
@@ -259,77 +254,7 @@
</ul>
</ul>
<p><strong>
示例:
</strong></p>
<p><strong>
示例:
</strong></p>
<p>
点击
<a
href=
"https://aistudio.baidu.com/aistudio/projectDetail/200786"
>
AIStudio
</a>
执行以下示例代码。
<p>
点击
<a
href=
"https://aistudio.baidu.com/aistudio/projectDetail/200786"
>
AIStudio
</a>
执行以下示例代码。
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.prune
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
Pruner
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.prune
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
Pruner
</span>
...
@@ -400,8 +325,7 @@
...
@@ -400,8 +325,7 @@
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
main_program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
global_block
</span><span
class=
"p"
>
()
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
main_program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
global_block
</span><span
class=
"p"
>
()
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"s2"
>
"
weights
"
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"s2"
>
"
weights
"
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
:
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param name:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; param shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param name:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; param shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
</pre></div>
</pre></div></p>
</td></tr></table></p>
<hr
/>
<hr
/>
<h2
id=
"sensitivity"
>
sensitivity
<a
class=
"headerlink"
href=
"#sensitivity"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"sensitivity"
>
sensitivity
<a
class=
"headerlink"
href=
"#sensitivity"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
@@ -422,13 +346,10 @@
...
@@ -422,13 +346,10 @@
<p><strong>
param_names(list
<str>
)
</strong>
- 待分析的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称:
</p>
<p><strong>
param_names(list
<str>
)
</strong>
- 待分析的卷积层的参数的名称列表。可以通过以下方式查看模型中所有参数的名称:
</p>
</li>
</li>
</ul>
</ul>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
for
</span>
<span
class=
"n"
>
block
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
blocks
</span><span
class=
"p"
>
:
</span>
2
3
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
for
</span>
<span
class=
"n"
>
block
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
blocks
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
block
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
block
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
</pre></div>
</pre></div>
</td></tr></table>
<ul>
<ul>
<li>
<li>
...
@@ -445,15 +366,7 @@
...
@@ -445,15 +366,7 @@
<ul>
<ul>
<li><strong>
sensitivities(dict)
</strong>
- 存放敏感度信息的dict,其格式为:
</li>
<li><strong>
sensitivities(dict)
</strong>
- 存放敏感度信息的dict,其格式为:
</li>
</ul>
</ul>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"p"
>
{
</span><span
class=
"s2"
>
"
weight_0
"
</span><span
class=
"p"
>
:
</span>
2
3
4
5
6
7
8
9
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"p"
>
{
</span><span
class=
"s2"
>
"
weight_0
"
</span><span
class=
"p"
>
:
</span>
<span
class=
"p"
>
{
</span><span
class=
"mf"
>
0.1
</span><span
class=
"p"
>
:
</span>
<span
class=
"mf"
>
0.22
</span><span
class=
"p"
>
,
</span>
<span
class=
"p"
>
{
</span><span
class=
"mf"
>
0.1
</span><span
class=
"p"
>
:
</span>
<span
class=
"mf"
>
0.22
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.2
</span><span
class=
"p"
>
:
</span>
<span
class=
"mf"
>
0.33
</span>
<span
class=
"mf"
>
0.2
</span><span
class=
"p"
>
:
</span>
<span
class=
"mf"
>
0.33
</span>
<span
class=
"p"
>
},
</span>
<span
class=
"p"
>
},
</span>
...
@@ -463,102 +376,11 @@
...
@@ -463,102 +376,11 @@
<span
class=
"p"
>
}
</span>
<span
class=
"p"
>
}
</span>
<span
class=
"p"
>
}
</span>
<span
class=
"p"
>
}
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
其中,
<code>
weight_0
</code>
是卷积层参数的名称,sensitivities['weight_0']的
<code>
value
</code>
为剪裁比例,
<code>
value
</code>
为精度损失的比例。
</p>
<p>
其中,
<code>
weight_0
</code>
是卷积层参数的名称,sensitivities['weight_0']的
<code>
value
</code>
为剪裁比例,
<code>
value
</code>
为精度损失的比例。
</p>
<p><strong>
示例:
</strong></p>
<p><strong>
示例:
</strong></p>
<p>
点击
<a
href=
"https://aistudio.baidu.com/aistudio/projectdetail/201401"
>
AIStudio
</a>
运行以下示例代码。
</p>
<p>
点击
<a
href=
"https://aistudio.baidu.com/aistudio/projectdetail/201401"
>
AIStudio
</a>
运行以下示例代码。
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle
</span>
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
numpy
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
np
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
numpy
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
np
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddle.fluid.param_attr
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
ParamAttr
</span>
...
@@ -650,7 +472,6 @@
...
@@ -650,7 +472,6 @@
<span
class=
"n"
>
pruned_ratios
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"mf"
>
0.1
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.2
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.3
</span><span
class=
"p"
>
])
</span>
<span
class=
"n"
>
pruned_ratios
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"mf"
>
0.1
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.2
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.3
</span><span
class=
"p"
>
])
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
sensitivities
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
sensitivities
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h2
id=
"merge_sensitive"
>
merge_sensitive
<a
class=
"headerlink"
href=
"#merge_sensitive"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"merge_sensitive"
>
merge_sensitive
<a
class=
"headerlink"
href=
"#merge_sensitive"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
@@ -667,15 +488,7 @@
...
@@ -667,15 +488,7 @@
<ul>
<ul>
<li><strong>
sensitivities(dict)
</strong>
- 合并后的敏感度信息。其格式为:
</li>
<li><strong>
sensitivities(dict)
</strong>
- 合并后的敏感度信息。其格式为:
</li>
</ul>
</ul>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"o"
>
{
</span><span
class=
"s2"
>
"
weight_0
"
</span>
:
2
3
4
5
6
7
8
9
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"o"
>
{
</span><span
class=
"s2"
>
"
weight_0
"
</span>
:
<span
class=
"o"
>
{
</span><span
class=
"m"
>
0
</span>
.1:
<span
class=
"m"
>
0
</span>
.22,
<span
class=
"o"
>
{
</span><span
class=
"m"
>
0
</span>
.1:
<span
class=
"m"
>
0
</span>
.22,
<span
class=
"m"
>
0
</span>
.2:
<span
class=
"m"
>
0
</span>
.33
<span
class=
"m"
>
0
</span>
.2:
<span
class=
"m"
>
0
</span>
.33
<span
class=
"o"
>
}
</span>
,
<span
class=
"o"
>
}
</span>
,
...
@@ -685,7 +498,6 @@
...
@@ -685,7 +498,6 @@
<span
class=
"o"
>
}
</span>
<span
class=
"o"
>
}
</span>
<span
class=
"o"
>
}
</span>
<span
class=
"o"
>
}
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
其中,
<code>
weight_0
</code>
是卷积层参数的名称,sensitivities['weight_0']的
<code>
value
</code>
为剪裁比例,
<code>
value
</code>
为精度损失的比例。
</p>
<p>
其中,
<code>
weight_0
</code>
是卷积层参数的名称,sensitivities['weight_0']的
<code>
value
</code>
为剪裁比例,
<code>
value
</code>
为精度损失的比例。
</p>
<p>
示例:
</p>
<p>
示例:
</p>
...
...
api/quantization_api/index.html
浏览文件 @
a7fe788c
...
@@ -185,44 +185,7 @@
...
@@ -185,44 +185,7 @@
<h2
id=
"_1"
>
量化配置
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"_1"
>
量化配置
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></h2>
<p>
通过字典配置量化参数
</p>
<p>
通过字典配置量化参数
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
TENSORRT_OP_TYPES
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[
</span>
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
TENSORRT_OP_TYPES
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[
</span>
<span
class=
"s1"
>
'
mul
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
conv2d
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
pool2d
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
depthwise_conv2d
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
elementwise_add
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
mul
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
conv2d
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
pool2d
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
depthwise_conv2d
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
elementwise_add
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
leaky_relu
'
</span>
<span
class=
"s1"
>
'
leaky_relu
'
</span>
<span
class=
"p"
>
]
</span>
<span
class=
"p"
>
]
</span>
...
@@ -261,7 +224,6 @@
...
@@ -261,7 +224,6 @@
<span
class=
"s1"
>
'
is_full_quantize
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"s1"
>
'
is_full_quantize
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"p"
>
}
</span>
<span
class=
"p"
>
}
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p><strong>
参数:
</strong></p>
<p><strong>
参数:
</strong></p>
<ul>
<ul>
...
@@ -337,43 +299,7 @@
...
@@ -337,43 +299,7 @@
</div>
</div>
<p>
因为该接口会对
<code>
op
</code>
和
<code>
Variable
</code>
做相应的删除和修改,所以此接口只能在训练完成之后调用。如果想转化训练的中间模型,可加载相应的参数之后再使用此接口。
</p>
<p>
因为该接口会对
<code>
op
</code>
和
<code>
Variable
</code>
做相应的删除和修改,所以此接口只能在训练完成之后调用。如果想转化训练的中间模型,可加载相应的参数之后再使用此接口。
</p>
<p><strong>
代码示例
</strong></p>
<p><strong>
代码示例
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
#encoding=utf8
</span>
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
#encoding=utf8
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.quant
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
quant
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.quant
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
quant
</span>
...
@@ -411,7 +337,6 @@
...
@@ -411,7 +337,6 @@
<span
class=
"n"
>
inference_prog
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
convert
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
quant_eval_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
config
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
inference_prog
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
convert
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
quant_eval_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
config
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
更详细的用法请参考
<a
href=
'https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_aware'
>
量化训练demo
</a>
。
</p>
<p>
更详细的用法请参考
<a
href=
'https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_aware'
>
量化训练demo
</a>
。
</p>
<h2
id=
"quant_post"
>
quant_post
<a
class=
"headerlink"
href=
"#quant_post"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"quant_post"
>
quant_post
<a
class=
"headerlink"
href=
"#quant_post"
title=
"Permanent link"
>
#
</a></h2>
...
@@ -451,23 +376,7 @@
...
@@ -451,23 +376,7 @@
<blockquote>
<blockquote>
<p>
注: 此示例不能直接运行,因为需要加载
<code>
${model_dir}
</code>
下的模型,所以不能直接运行。
</p>
<p>
注: 此示例不能直接运行,因为需要加载
<code>
${model_dir}
</code>
下的模型,所以不能直接运行。
</p>
</blockquote>
</blockquote>
<p><table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<p><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.dataset.mnist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
reader
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.dataset.mnist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
reader
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.quant
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
quant_post
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.quant
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
quant_post
</span>
<span
class=
"n"
>
val_reader
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
reader
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
train
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
val_reader
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
reader
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
train
</span><span
class=
"p"
>
()
</span>
...
@@ -485,7 +394,6 @@
...
@@ -485,7 +394,6 @@
<span
class=
"n"
>
batch_size
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
16
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
batch_size
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
16
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
batch_nums
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
10
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
batch_nums
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
10
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
更详细的用法请参考
<a
href=
'https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_post'
>
离线量化demo
</a>
。
</p>
更详细的用法请参考
<a
href=
'https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_post'
>
离线量化demo
</a>
。
</p>
<h2
id=
"quant_embedding"
>
quant_embedding
<a
class=
"headerlink"
href=
"#quant_embedding"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"quant_embedding"
>
quant_embedding
<a
class=
"headerlink"
href=
"#quant_embedding"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
@@ -511,28 +419,7 @@
...
@@ -511,28 +419,7 @@
<p><strong>
返回类型
</strong></p>
<p><strong>
返回类型
</strong></p>
<p><code>
fluid.Program
</code></p>
<p><code>
fluid.Program
</code></p>
<p><strong>
代码示例
</strong>
<p><strong>
代码示例
</strong>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.quant
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
quant
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.quant
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
quant
</span>
<span
class=
"n"
>
train_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
train_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
...
@@ -554,8 +441,7 @@
...
@@ -554,8 +441,7 @@
<span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span><span
class=
"s1"
>
'
params_name
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
emb
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
abs_max
'
</span><span
class=
"p"
>
}
</span>
<span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span><span
class=
"s1"
>
'
params_name
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
emb
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
abs_max
'
</span><span
class=
"p"
>
}
</span>
<span
class=
"hll"
><span
class=
"n"
>
quant_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
quant_embedding
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
infer_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
config
</span><span
class=
"p"
>
)
</span>
<span
class=
"hll"
><span
class=
"n"
>
quant_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
quant_embedding
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
infer_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
config
</span><span
class=
"p"
>
)
</span>
</span></pre></div>
</span></pre></div></p>
</td></tr></table></p>
<p>
更详细的用法请参考
<a
href=
'https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_embedding'
>
Embedding量化demo
</a>
。
</p>
<p>
更详细的用法请参考
<a
href=
'https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/quant/quant_embedding'
>
Embedding量化demo
</a>
。
</p>
</div>
</div>
...
...
api/single_distiller_api/index.html
浏览文件 @
a7fe788c
...
@@ -205,24 +205,7 @@
...
@@ -205,24 +205,7 @@
<p><em>
data_name_map
</em>
是
<strong>
teacher_var name到student_var name的映射
</strong>
,如果写反可能无法正确进行merge
</p>
<p><em>
data_name_map
</em>
是
<strong>
teacher_var name到student_var name的映射
</strong>
,如果写反可能无法正确进行merge
</p>
</div>
</div>
<p><strong>
使用示例:
</strong></p>
<p><strong>
使用示例:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
...
@@ -241,7 +224,6 @@
...
@@ -241,7 +224,6 @@
<span
class=
"hll"
><span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
merge
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"hll"
><span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
merge
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
</span><span
class=
"hll"
>
<span
class=
"n"
>
data_name_map
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
)
</span>
</span><span
class=
"hll"
>
<span
class=
"n"
>
data_name_map
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
)
</span>
</span></pre></div>
</span></pre></div>
</td></tr></table>
<h2
id=
"fsp_loss"
>
fsp_loss
<a
class=
"headerlink"
href=
"#fsp_loss"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"fsp_loss"
>
fsp_loss
<a
class=
"headerlink"
href=
"#fsp_loss"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
@@ -260,26 +242,7 @@
...
@@ -260,26 +242,7 @@
</ul>
</ul>
<p><strong>
返回:
</strong>
由teacher_var1, teacher_var2, student_var1, student_var2组合得到的fsp_loss
</p>
<p><strong>
返回:
</strong>
由teacher_var1, teacher_var2, student_var1, student_var2组合得到的fsp_loss
</p>
<p><strong>
使用示例:
</strong></p>
<p><strong>
使用示例:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
...
@@ -300,7 +263,6 @@
...
@@ -300,7 +263,6 @@
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
fsp_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_t1.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
fsp_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_t1.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
</span><span
class=
"hll"
>
<span
class=
"s1"
>
'
s1.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)
</span>
</span><span
class=
"hll"
>
<span
class=
"s1"
>
'
s1.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)
</span>
</span></pre></div>
</span></pre></div>
</td></tr></table>
<h2
id=
"l2_loss"
>
l2_loss
<a
class=
"headerlink"
href=
"#l2_loss"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"l2_loss"
>
l2_loss
<a
class=
"headerlink"
href=
"#l2_loss"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
@@ -317,26 +279,7 @@
...
@@ -317,26 +279,7 @@
</ul>
</ul>
<p><strong>
返回:
</strong>
由teacher_var, student_var组合得到的l2_loss
</p>
<p><strong>
返回:
</strong>
由teacher_var, student_var组合得到的l2_loss
</p>
<p><strong>
使用示例:
</strong></p>
<p><strong>
使用示例:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
...
@@ -357,7 +300,6 @@
...
@@ -357,7 +300,6 @@
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
l2_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
l2_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
</span><span
class=
"hll"
>
<span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)
</span>
</span><span
class=
"hll"
>
<span
class=
"n"
>
main_program
</span><span
class=
"p"
>
)
</span>
</span></pre></div>
</span></pre></div>
</td></tr></table>
<h2
id=
"soft_label_loss"
>
soft_label_loss
<a
class=
"headerlink"
href=
"#soft_label_loss"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"soft_label_loss"
>
soft_label_loss
<a
class=
"headerlink"
href=
"#soft_label_loss"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
@@ -376,26 +318,7 @@
...
@@ -376,26 +318,7 @@
</ul>
</ul>
<p><strong>
返回:
</strong>
由teacher_var, student_var组合得到的soft_label_loss
</p>
<p><strong>
返回:
</strong>
由teacher_var, student_var组合得到的soft_label_loss
</p>
<p><strong>
使用示例:
</strong></p>
<p><strong>
使用示例:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
...
@@ -416,7 +339,6 @@
...
@@ -416,7 +339,6 @@
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
soft_label_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
soft_label_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
</span><span
class=
"hll"
>
<span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
main_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
1.
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
1.
</span><span
class=
"p"
>
)
</span>
</span><span
class=
"hll"
>
<span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
main_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
1.
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
1.
</span><span
class=
"p"
>
)
</span>
</span></pre></div>
</span></pre></div>
</td></tr></table>
<h2
id=
"loss"
>
loss
<a
class=
"headerlink"
href=
"#loss"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"loss"
>
loss
<a
class=
"headerlink"
href=
"#loss"
title=
"Permanent link"
>
#
</a></h2>
<dl>
<dl>
...
@@ -433,31 +355,7 @@
...
@@ -433,31 +355,7 @@
</ul>
</ul>
<p><strong>
返回
</strong>
:自定义的损失函数loss
</p>
<p><strong>
返回
</strong>
:自定义的损失函数loss
</p>
<p><strong>
使用示例:
</strong></p>
<p><strong>
使用示例:
</strong></p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddleslim.dist
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
dist
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
):
</span>
...
@@ -483,7 +381,6 @@
...
@@ -483,7 +381,6 @@
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
loss
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
main_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
adaptation_loss
</span><span
class=
"p"
>
,
</span>
<span
class=
"hll"
>
<span
class=
"n"
>
distillation_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
dist
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
loss
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
main_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
adaptation_loss
</span><span
class=
"p"
>
,
</span>
</span><span
class=
"hll"
>
<span
class=
"n"
>
t_var
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
s_var
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
)
</span>
</span><span
class=
"hll"
>
<span
class=
"n"
>
t_var
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
teacher_t2.tmp_1
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
s_var
</span><span
class=
"o"
>
=
</span><span
class=
"s1"
>
'
s2.tmp_1
'
</span><span
class=
"p"
>
)
</span>
</span></pre></div>
</span></pre></div>
</td></tr></table>
<div
class=
"admonition note"
>
<div
class=
"admonition note"
>
<p
class=
"admonition-title"
>
注意事项
</p>
<p
class=
"admonition-title"
>
注意事项
</p>
...
...
extra.css
浏览文件 @
a7fe788c
.codehilite
{
.codehilite
code
,
.codehilite
pre
{
color
:
#3F3F3F
;
background-color
:
#F7F7F7
;
width
:
590px
;
overflow
:
auto
;
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 */
index.html
浏览文件 @
a7fe788c
...
@@ -212,20 +212,16 @@
...
@@ -212,20 +212,16 @@
<ul>
<ul>
<li>
安装develop版本
</li>
<li>
安装develop版本
</li>
</ul>
</ul>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
git clone https://github.com/PaddlePaddle/PaddleSlim.git
2
3
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
git clone https://github.com/PaddlePaddle/PaddleSlim.git
<span
class=
"nb"
>
cd
</span>
PaddleSlim
<span
class=
"nb"
>
cd
</span>
PaddleSlim
python setup.py install
python setup.py install
</pre></div>
</pre></div>
</td></tr></table>
<ul>
<ul>
<li>
安装官方发布的最新版本
</li>
<li>
安装官方发布的最新版本
</li>
</ul>
</ul>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
pip install paddleslim -i https://pypi.org/simple
<div
class=
"codehilite"
><pre><span></span>
pip install paddleslim -i https://pypi.org/simple
</pre></div>
</pre></div>
</td></tr></table>
<ul>
<ul>
<li>
安装历史版本
</li>
<li>
安装历史版本
</li>
...
@@ -294,5 +290,5 @@ python setup.py install
...
@@ -294,5 +290,5 @@ python setup.py install
<!--
<!--
MkDocs version : 1.0.4
MkDocs version : 1.0.4
Build Date UTC : 2020-01-17 0
2:21:20
Build Date UTC : 2020-01-17 0
7:20:03
-->
-->
search/search_index.json
浏览文件 @
a7fe788c
此差异已折叠。
点击以展开。
search_space/index.html
浏览文件 @
a7fe788c
...
@@ -244,68 +244,7 @@
...
@@ -244,68 +244,7 @@
 
2. token中每个数字的搜索列表长度(
<code>
range_table
</code>
函数),tokens中每个token的索引范围。
<br>
 
2. token中每个数字的搜索列表长度(
<code>
range_table
</code>
函数),tokens中每个token的索引范围。
<br>
 
3. 根据token产生模型结构(
<code>
token2arch
</code>
函数),根据搜索到的tokens列表产生模型结构。
<br></p>
 
3. 根据token产生模型结构(
<code>
token2arch
</code>
函数),根据搜索到的tokens列表产生模型结构。
<br></p>
<p>
以新增reset block为例说明如何构造自己的search space。自定义的search space不能和已有的search space同名。
</p>
<p>
以新增reset block为例说明如何构造自己的search space。自定义的search space不能和已有的search space同名。
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
### 引入搜索空间基类函数和search space的注册类函数
</span>
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
### 引入搜索空间基类函数和search space的注册类函数
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
.search_space_base
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SearchSpaceBase
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
.search_space_base
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SearchSpaceBase
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
.search_space_registry
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SEARCHSPACE
</span>
<span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
.search_space_registry
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SEARCHSPACE
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
numpy
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
np
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
numpy
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
np
</span>
...
@@ -368,7 +307,6 @@
...
@@ -368,7 +307,6 @@
<span
class=
"n"
>
bn
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
batch_norm
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
conv
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
act
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
act
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
name
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
name
</span><span
class=
"o"
>
+
</span><span
class=
"s1"
>
'
_bn
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
bn
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
batch_norm
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
conv
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
act
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
act
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
name
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
name
</span><span
class=
"o"
>
+
</span><span
class=
"s1"
>
'
_bn
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"k"
>
return
</span>
<span
class=
"n"
>
bn
</span>
<span
class=
"k"
>
return
</span>
<span
class=
"n"
>
bn
</span>
</pre></div>
</pre></div>
</td></tr></table>
</div>
</div>
</div>
</div>
...
...
sitemap.xml.gz
浏览文件 @
a7fe788c
无法预览此类型文件
table_latency/index.html
浏览文件 @
a7fe788c
...
@@ -209,9 +209,8 @@
...
@@ -209,9 +209,8 @@
<p>
操作信息字段之间以逗号分割。操作信息与延迟信息之间以制表符分割。
</p>
<p>
操作信息字段之间以逗号分割。操作信息与延迟信息之间以制表符分割。
</p>
<h3
id=
"conv2d"
>
conv2d
<a
class=
"headerlink"
href=
"#conv2d"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"conv2d"
>
conv2d
<a
class=
"headerlink"
href=
"#conv2d"
title=
"Permanent link"
>
#
</a></h3>
<p><strong>
格式
</strong></p>
<p><strong>
格式
</strong></p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stride,dilation\tlatency
<div
class=
"codehilite"
><pre><span></span>
op_type,flag_bias,flag_relu,n_in,c_in,h_in,w_in,c_out,groups,kernel,padding,stride,dilation\tlatency
</pre></div>
</pre></div>
</td></tr></table>
<p><strong>
字段解释
</strong></p>
<p><strong>
字段解释
</strong></p>
<ul>
<ul>
...
@@ -232,9 +231,8 @@
...
@@ -232,9 +231,8 @@
</ul>
</ul>
<h3
id=
"activation"
>
activation
<a
class=
"headerlink"
href=
"#activation"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"activation"
>
activation
<a
class=
"headerlink"
href=
"#activation"
title=
"Permanent link"
>
#
</a></h3>
<p><strong>
格式
</strong></p>
<p><strong>
格式
</strong></p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
op_type,n_in,c_in,h_in,w_in\tlatency
<div
class=
"codehilite"
><pre><span></span>
op_type,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</pre></div>
</td></tr></table>
<p><strong>
字段解释
</strong></p>
<p><strong>
字段解释
</strong></p>
<ul>
<ul>
...
@@ -247,9 +245,8 @@
...
@@ -247,9 +245,8 @@
</ul>
</ul>
<h3
id=
"batch_norm"
>
batch_norm
<a
class=
"headerlink"
href=
"#batch_norm"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"batch_norm"
>
batch_norm
<a
class=
"headerlink"
href=
"#batch_norm"
title=
"Permanent link"
>
#
</a></h3>
<p><strong>
格式
</strong></p>
<p><strong>
格式
</strong></p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
op_type,active_type,n_in,c_in,h_in,w_in\tlatency
<div
class=
"codehilite"
><pre><span></span>
op_type,active_type,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</pre></div>
</td></tr></table>
<p><strong>
字段解释
</strong></p>
<p><strong>
字段解释
</strong></p>
<ul>
<ul>
...
@@ -263,9 +260,8 @@
...
@@ -263,9 +260,8 @@
</ul>
</ul>
<h3
id=
"eltwise"
>
eltwise
<a
class=
"headerlink"
href=
"#eltwise"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"eltwise"
>
eltwise
<a
class=
"headerlink"
href=
"#eltwise"
title=
"Permanent link"
>
#
</a></h3>
<p><strong>
格式
</strong></p>
<p><strong>
格式
</strong></p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
op_type,n_in,c_in,h_in,w_in\tlatency
<div
class=
"codehilite"
><pre><span></span>
op_type,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</pre></div>
</td></tr></table>
<p><strong>
字段解释
</strong></p>
<p><strong>
字段解释
</strong></p>
<ul>
<ul>
...
@@ -278,9 +274,8 @@
...
@@ -278,9 +274,8 @@
</ul>
</ul>
<h3
id=
"pooling"
>
pooling
<a
class=
"headerlink"
href=
"#pooling"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"pooling"
>
pooling
<a
class=
"headerlink"
href=
"#pooling"
title=
"Permanent link"
>
#
</a></h3>
<p><strong>
格式
</strong></p>
<p><strong>
格式
</strong></p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,pool_type\tlatency
<div
class=
"codehilite"
><pre><span></span>
op_type,flag_global_pooling,n_in,c_in,h_in,w_in,kernel,padding,stride,ceil_mode,pool_type\tlatency
</pre></div>
</pre></div>
</td></tr></table>
<p><strong>
字段解释
</strong></p>
<p><strong>
字段解释
</strong></p>
<ul>
<ul>
...
@@ -299,9 +294,8 @@
...
@@ -299,9 +294,8 @@
</ul>
</ul>
<h3
id=
"softmax"
>
softmax
<a
class=
"headerlink"
href=
"#softmax"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"softmax"
>
softmax
<a
class=
"headerlink"
href=
"#softmax"
title=
"Permanent link"
>
#
</a></h3>
<p><strong>
格式
</strong></p>
<p><strong>
格式
</strong></p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
op_type,axis,n_in,c_in,h_in,w_in\tlatency
<div
class=
"codehilite"
><pre><span></span>
op_type,axis,n_in,c_in,h_in,w_in\tlatency
</pre></div>
</pre></div>
</td></tr></table>
<p><strong>
字段解释
</strong></p>
<p><strong>
字段解释
</strong></p>
<ul>
<ul>
...
...
tutorials/distillation_demo/index.html
浏览文件 @
a7fe788c
...
@@ -195,17 +195,7 @@
...
@@ -195,17 +195,7 @@
<p>
一般情况下,模型参数量越多,结构越复杂,其性能越好,但运算量和资源消耗也越大。
<strong>
知识蒸馏
</strong>
就是一种将大模型学习到的有用信息(Dark Knowledge)压缩进更小更快的模型,而获得可以匹敌大模型结果的方法。
</p>
<p>
一般情况下,模型参数量越多,结构越复杂,其性能越好,但运算量和资源消耗也越大。
<strong>
知识蒸馏
</strong>
就是一种将大模型学习到的有用信息(Dark Knowledge)压缩进更小更快的模型,而获得可以匹敌大模型结果的方法。
</p>
<p>
在本示例中精度较高的大模型被称为teacher,精度稍逊但速度更快的小模型被称为student。
</p>
<p>
在本示例中精度较高的大模型被称为teacher,精度稍逊但速度更快的小模型被称为student。
</p>
<h3
id=
"1-student_program"
>
1. 定义student_program
<a
class=
"headerlink"
href=
"#1-student_program"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"1-student_program"
>
1. 定义student_program
<a
class=
"headerlink"
href=
"#1-student_program"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
2
3
4
5
6
7
8
9
10
11
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
student_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
student_startup
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
student_startup
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_startup
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_startup
</span><span
class=
"p"
>
):
</span>
<span
class=
"n"
>
image
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
image
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
data
</span><span
class=
"p"
>
(
</span>
...
@@ -217,29 +207,11 @@
...
@@ -217,29 +207,11 @@
<span
class=
"n"
>
cost
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
cross_entropy
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
out
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
label
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
label
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
cost
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
cross_entropy
</span><span
class=
"p"
>
(
</span><span
class=
"nb"
>
input
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
out
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
label
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
label
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
avg_cost
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
mean
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
x
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
cost
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
avg_cost
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
layers
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
mean
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
x
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
cost
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"2-teacher_program"
>
2. 定义teacher_program
<a
class=
"headerlink"
href=
"#2-teacher_program"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"2-teacher_program"
>
2. 定义teacher_program
<a
class=
"headerlink"
href=
"#2-teacher_program"
title=
"Permanent link"
>
#
</a></h3>
<p>
在定义好
<code>
teacher_program
</code>
后,可以一并加载训练好的pretrained_model。
</p>
<p>
在定义好
<code>
teacher_program
</code>
后,可以一并加载训练好的pretrained_model。
</p>
<p>
在
<code>
teacher_program
</code>
内需要加上
<code>
with fluid.unique_name.guard():
</code>
,保证teacher的变量命名不被
<code>
student_program
</code>
影响,从而能够正确地加载预训练参数。
</p>
<p>
在
<code>
teacher_program
</code>
内需要加上
<code>
with fluid.unique_name.guard():
</code>
,保证teacher的变量命名不被
<code>
student_program
</code>
影响,从而能够正确地加载预训练参数。
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
teacher_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
teacher_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
teacher_startup
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
teacher_startup
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
teacher_startup
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
teacher_startup
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
unique_name
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
guard
</span><span
class=
"p"
>
():
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
unique_name
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
guard
</span><span
class=
"p"
>
():
</span>
...
@@ -258,28 +230,10 @@
...
@@ -258,28 +230,10 @@
<span
class=
"n"
>
main_program
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
main_program
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
predicate
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
if_exist
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
predicate
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
if_exist
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"3"
>
3.选择特征图
<a
class=
"headerlink"
href=
"#3"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"3"
>
3.选择特征图
<a
class=
"headerlink"
href=
"#3"
title=
"Permanent link"
>
#
</a></h3>
<p>
定义好
<code>
student_program
</code>
和
<code>
teacher_program
</code>
后,我们需要从中两两对应地挑选出若干个特征图,留待后续为其添加知识蒸馏损失函数。
</p>
<p>
定义好
<code>
student_program
</code>
和
<code>
teacher_program
</code>
后,我们需要从中两两对应地挑选出若干个特征图,留待后续为其添加知识蒸馏损失函数。
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
# get all student variables
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
# get all student variables
</span>
<span
class=
"n"
>
student_vars
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[]
</span>
<span
class=
"n"
>
student_vars
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[]
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
v
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
list_vars
</span><span
class=
"p"
>
():
</span>
<span
class=
"k"
>
for
</span>
<span
class=
"n"
>
v
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
list_vars
</span><span
class=
"p"
>
():
</span>
<span
class=
"k"
>
try
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
try
</span><span
class=
"p"
>
:
</span>
...
@@ -298,29 +252,18 @@
...
@@ -298,29 +252,18 @@
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
=
"
</span><span
class=
"o"
>
*
</span><span
class=
"mi"
>
50
</span><span
class=
"o"
>
+
</span><span
class=
"s2"
>
"
teacher_model_vars
"
</span><span
class=
"o"
>
+
</span><span
class=
"s2"
>
"
=
"
</span><span
class=
"o"
>
*
</span><span
class=
"mi"
>
50
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
=
"
</span><span
class=
"o"
>
*
</span><span
class=
"mi"
>
50
</span><span
class=
"o"
>
+
</span><span
class=
"s2"
>
"
teacher_model_vars
"
</span><span
class=
"o"
>
+
</span><span
class=
"s2"
>
"
=
"
</span><span
class=
"o"
>
*
</span><span
class=
"mi"
>
50
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_vars
</span><span
class=
"p"
>
)
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_vars
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"4-programmerge"
>
4. 合并Program(merge)
<a
class=
"headerlink"
href=
"#4-programmerge"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"4-programmerge"
>
4. 合并Program(merge)
<a
class=
"headerlink"
href=
"#4-programmerge"
title=
"Permanent link"
>
#
</a></h3>
<p>
PaddlePaddle使用Program来描述计算图,为了同时计算student和teacher两个Program,这里需要将其两者合并(merge)为一个Program。
</p>
<p>
PaddlePaddle使用Program来描述计算图,为了同时计算student和teacher两个Program,这里需要将其两者合并(merge)为一个Program。
</p>
<p>
merge过程操作较多,具体细节请参考
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/single_distiller_api/#merge"
>
merge API文档
</a>
。
</p>
<p>
merge过程操作较多,具体细节请参考
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/single_distiller_api/#merge"
>
merge API文档
</a>
。
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
data_name_map
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span><span
class=
"s1"
>
'
data
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
image
'
</span><span
class=
"p"
>
}
</span>
2
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
data_name_map
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span><span
class=
"s1"
>
'
data
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
image
'
</span><span
class=
"p"
>
}
</span>
<span
class=
"n"
>
merge
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
data_name_map
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
merge
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
teacher_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
data_name_map
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"5loss"
>
5.添加蒸馏loss
<a
class=
"headerlink"
href=
"#5loss"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"5loss"
>
5.添加蒸馏loss
<a
class=
"headerlink"
href=
"#5loss"
title=
"Permanent link"
>
#
</a></h3>
<p>
在添加蒸馏loss的过程中,可能还会引入部分变量(Variable),为了避免命名重复这里可以使用
<code>
with fluid.name_scope("distill"):
</code>
为新引入的变量加一个命名作用域。
</p>
<p>
在添加蒸馏loss的过程中,可能还会引入部分变量(Variable),为了避免命名重复这里可以使用
<code>
with fluid.name_scope("distill"):
</code>
为新引入的变量加一个命名作用域。
</p>
<p>
另外需要注意的是,merge过程为
<code>
teacher_program
</code>
的变量统一加了名称前缀,默认是
<code>
"teacher_"
</code>
, 这里在添加
<code>
l2_loss
</code>
时也要为teacher的变量加上这个前缀。
</p>
<p>
另外需要注意的是,merge过程为
<code>
teacher_program
</code>
的变量统一加了名称前缀,默认是
<code>
"teacher_"
</code>
, 这里在添加
<code>
l2_loss
</code>
时也要为teacher的变量加上这个前缀。
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_startup
</span><span
class=
"p"
>
):
</span>
2
3
4
5
6
7
8
9
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
program_guard
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_startup
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name_scope
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
distill
"
</span><span
class=
"p"
>
):
</span>
<span
class=
"k"
>
with
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name_scope
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
distill
"
</span><span
class=
"p"
>
):
</span>
<span
class=
"n"
>
distill_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
l2_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_bn5c_branch2b.output.1.tmp_3
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
distill_loss
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
l2_loss
</span><span
class=
"p"
>
(
</span><span
class=
"s1"
>
'
teacher_bn5c_branch2b.output.1.tmp_3
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
depthwise_conv2d_11.tmp_0
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"p"
>
)
</span>
<span
class=
"s1"
>
'
depthwise_conv2d_11.tmp_0
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
student_program
</span><span
class=
"p"
>
)
</span>
...
@@ -330,7 +273,6 @@
...
@@ -330,7 +273,6 @@
<span
class=
"n"
>
opt
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
minimize
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
loss
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
opt
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
minimize
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
loss
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
exe
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
run
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_startup
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
exe
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
run
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
student_startup
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
至此,我们就得到了用于蒸馏训练的
<code>
student_program
</code>
,后面就可以使用一个普通program一样对其开始训练和评估。
</p>
<p>
至此,我们就得到了用于蒸馏训练的
<code>
student_program
</code>
,后面就可以使用一个普通program一样对其开始训练和评估。
</p>
...
...
tutorials/nas_demo/index.html
浏览文件 @
a7fe788c
...
@@ -183,19 +183,10 @@
...
@@ -183,19 +183,10 @@
<p>
请参考。
</p>
<p>
请参考。
</p>
<h3
id=
"1"
>
1. 配置搜索空间
<a
class=
"headerlink"
href=
"#1"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"1"
>
1. 配置搜索空间
<a
class=
"headerlink"
href=
"#1"
title=
"Permanent link"
>
#
</a></h3>
<p>
详细的搜索空间配置可以参考
<a
href=
'../../../paddleslim/nas/nas_api.md'
>
神经网络搜索API文档
</a>
。
<p>
详细的搜索空间配置可以参考
<a
href=
'../../../paddleslim/nas/nas_api.md'
>
神经网络搜索API文档
</a>
。
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[(
</span><span
class=
"s1"
>
'
MobileNetV2Space
'
</span><span
class=
"p"
>
)]
</span>
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
[(
</span><span
class=
"s1"
>
'
MobileNetV2Space
'
</span><span
class=
"p"
>
)]
</span>
</pre></div>
</pre></div></p>
</td></tr></table></p>
<h3
id=
"2-sanas"
>
2. 利用搜索空间初始化SANAS实例
<a
class=
"headerlink"
href=
"#2-sanas"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"2-sanas"
>
2. 利用搜索空间初始化SANAS实例
<a
class=
"headerlink"
href=
"#2-sanas"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.nas
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SANAS
</span>
2
3
4
5
6
7
8
9
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.nas
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
SANAS
</span>
<span
class=
"n"
>
sa_nas
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
SANAS
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
sa_nas
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
SANAS
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
config
</span><span
class=
"p"
>
,
</span>
...
@@ -205,34 +196,13 @@
...
@@ -205,34 +196,13 @@
<span
class=
"n"
>
search_steps
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
300
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
search_steps
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
300
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
is_server
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
True
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
is_server
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
True
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"3-nas"
>
3. 根据实例化的NAS得到当前的网络结构
<a
class=
"headerlink"
href=
"#3-nas"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"3-nas"
>
3. 根据实例化的NAS得到当前的网络结构
<a
class=
"headerlink"
href=
"#3-nas"
title=
"Permanent link"
>
#
</a></h3>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
archs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
sa_nas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
next_archs
</span><span
class=
"p"
>
()
</span>
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
archs
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
sa_nas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
next_archs
</span><span
class=
"p"
>
()
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"4-program"
>
4. 根据得到的网络结构和输入构造训练和测试program
<a
class=
"headerlink"
href=
"#4-program"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"4-program"
>
4. 根据得到的网络结构和输入构造训练和测试program
<a
class=
"headerlink"
href=
"#4-program"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
import
</span>
<span
class=
"nn"
>
paddle.fluid
</span>
<span
class=
"k"
>
as
</span>
<span
class=
"nn"
>
fluid
</span>
<span
class=
"n"
>
train_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
train_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
test_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
test_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
Program
</span><span
class=
"p"
>
()
</span>
...
@@ -253,23 +223,17 @@
...
@@ -253,23 +223,17 @@
<span
class=
"n"
>
sgd
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
optimizer
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
SGD
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
learning_rate
</span><span
class=
"o"
>
=
</span><span
class=
"mf"
>
1e-3
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
sgd
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
optimizer
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
SGD
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
learning_rate
</span><span
class=
"o"
>
=
</span><span
class=
"mf"
>
1e-3
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
sgd
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
minimize
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
avg_cost
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
sgd
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
minimize
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
avg_cost
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"5-program"
>
5. 根据构造的训练program添加限制条件
<a
class=
"headerlink"
href=
"#5-program"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"5-program"
>
5. 根据构造的训练program添加限制条件
<a
class=
"headerlink"
href=
"#5-program"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.analysis
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
flops
</span>
2
3
4
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"kn"
>
from
</span>
<span
class=
"nn"
>
paddleslim.analysis
</span>
<span
class=
"kn"
>
import
</span>
<span
class=
"n"
>
flops
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"n"
>
flops
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_program
</span><span
class=
"p"
>
)
</span>
<span
class=
"o"
>
>
</span>
<span
class=
"mi"
>
321208544
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
if
</span>
<span
class=
"n"
>
flops
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_program
</span><span
class=
"p"
>
)
</span>
<span
class=
"o"
>
>
</span>
<span
class=
"mi"
>
321208544
</span><span
class=
"p"
>
:
</span>
<span
class=
"k"
>
continue
</span>
<span
class=
"k"
>
continue
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"6-score"
>
6. 回传score
<a
class=
"headerlink"
href=
"#6-score"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"6-score"
>
6. 回传score
<a
class=
"headerlink"
href=
"#6-score"
title=
"Permanent link"
>
#
</a></h3>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
sa_nas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
reward
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
score
</span><span
class=
"p"
>
)
</span>
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
sa_nas
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
reward
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
score
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
</div>
</div>
</div>
</div>
...
...
tutorials/pruning_demo/index.html
浏览文件 @
a7fe788c
...
@@ -174,20 +174,16 @@
...
@@ -174,20 +174,16 @@
<p>
该示例使用了
<code>
paddleslim.Pruner
</code>
工具类,用户接口使用介绍请参考:
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/prune_api/"
>
API文档
</a></p>
<p>
该示例使用了
<code>
paddleslim.Pruner
</code>
工具类,用户接口使用介绍请参考:
<a
href=
"https://paddlepaddle.github.io/PaddleSlim/api/prune_api/"
>
API文档
</a></p>
<h2
id=
"_3"
>
确定待裁参数
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"_3"
>
确定待裁参数
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h2>
<p>
不同模型的参数命名不同,在剪裁前需要确定待裁卷积层的参数名称。可通过以下方法列出所有参数名:
</p>
<p>
不同模型的参数命名不同,在剪裁前需要确定待裁卷积层的参数名称。可通过以下方法列出所有参数名:
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
global_block
</span><span
class=
"p"
>
()
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
2
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"k"
>
for
</span>
<span
class=
"n"
>
param
</span>
<span
class=
"ow"
>
in
</span>
<span
class=
"n"
>
program
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
global_block
</span><span
class=
"p"
>
()
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
all_parameters
</span><span
class=
"p"
>
():
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param name:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
<span
class=
"nb"
>
print
</span><span
class=
"p"
>
(
</span><span
class=
"s2"
>
"
param name:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
; shape:
</span><span
class=
"si"
>
{}
</span><span
class=
"s2"
>
"
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
format
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
param
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
shape
</span><span
class=
"p"
>
))
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
在
<code>
train.py
</code>
脚本中,提供了
<code>
get_pruned_params
</code>
方法,根据用户设置的选项
<code>
--model
</code>
确定要裁剪的参数。
</p>
<p>
在
<code>
train.py
</code>
脚本中,提供了
<code>
get_pruned_params
</code>
方法,根据用户设置的选项
<code>
--model
</code>
确定要裁剪的参数。
</p>
<h2
id=
"_4"
>
启动裁剪任务
<a
class=
"headerlink"
href=
"#_4"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"_4"
>
启动裁剪任务
<a
class=
"headerlink"
href=
"#_4"
title=
"Permanent link"
>
#
</a></h2>
<p>
通过以下命令启动裁剪任务:
</p>
<p>
通过以下命令启动裁剪任务:
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
export
</span>
<span
class=
"n"
>
CUDA_VISIBLE_DEVICES
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
0
</span>
2
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
export
</span>
<span
class=
"n"
>
CUDA_VISIBLE_DEVICES
</span><span
class=
"o"
>
=
</span><span
class=
"mi"
>
0
</span>
<span
class=
"n"
>
python
</span>
<span
class=
"n"
>
train
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
py
</span>
<span
class=
"n"
>
python
</span>
<span
class=
"n"
>
train
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
py
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
执行
<code>
python train.py --help
</code>
查看更多选项。
</p>
<p>
执行
<code>
python train.py --help
</code>
查看更多选项。
</p>
<h2
id=
"_5"
>
注意
<a
class=
"headerlink"
href=
"#_5"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"_5"
>
注意
<a
class=
"headerlink"
href=
"#_5"
title=
"Permanent link"
>
#
</a></h2>
...
...
tutorials/quant_aware_demo/index.html
浏览文件 @
a7fe788c
...
@@ -185,18 +185,7 @@
...
@@ -185,18 +185,7 @@
<p>
请参考
<a
href=
'../../../paddleslim/quant/quantization_api_doc.md'
>
量化API文档
</a>
。
</p>
<p>
请参考
<a
href=
'../../../paddleslim/quant/quantization_api_doc.md'
>
量化API文档
</a>
。
</p>
<h2
id=
"_3"
>
分类模型的离线量化流程
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"_3"
>
分类模型的离线量化流程
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h2>
<h3
id=
"1"
>
1. 配置量化参数
<a
class=
"headerlink"
href=
"#1"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"1"
>
1. 配置量化参数
<a
class=
"headerlink"
href=
"#1"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
quant_config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span>
2
3
4
5
6
7
8
9
10
11
12
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
quant_config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span>
<span
class=
"s1"
>
'
weight_quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
abs_max
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
weight_quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
abs_max
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
activation_quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
moving_average_abs_max
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
activation_quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
moving_average_abs_max
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
weight_bits
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"mi"
>
8
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
weight_bits
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"mi"
>
8
</span><span
class=
"p"
>
,
</span>
...
@@ -209,26 +198,15 @@
...
@@ -209,26 +198,15 @@
<span
class=
"s1"
>
'
quant_weight_only
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"s1"
>
'
quant_weight_only
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"p"
>
}
</span>
<span
class=
"p"
>
}
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"2-programop"
>
2. 对训练和测试program插入可训练量化op
<a
class=
"headerlink"
href=
"#2-programop"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"2-programop"
>
2. 对训练和测试program插入可训练量化op
<a
class=
"headerlink"
href=
"#2-programop"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
val_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant_aware
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
quant_config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
scope
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
for_test
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
True
</span><span
class=
"p"
>
)
</span>
2
3
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
val_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant_aware
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
quant_config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
scope
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
for_test
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
True
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
compiled_train_prog
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant_aware
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_prog
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
quant_config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
scope
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
for_test
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
False
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
compiled_train_prog
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
quant_aware
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
train_prog
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
quant_config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
scope
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
for_test
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
False
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"3build"
>
3.关掉指定build策略
<a
class=
"headerlink"
href=
"#3build"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"3build"
>
3.关掉指定build策略
<a
class=
"headerlink"
href=
"#3build"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
build_strategy
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
BuildStrategy
</span><span
class=
"p"
>
()
</span>
2
3
4
5
6
7
8
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
build_strategy
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
BuildStrategy
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
build_strategy
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
fuse_all_reduce_ops
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"n"
>
build_strategy
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
fuse_all_reduce_ops
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"n"
>
build_strategy
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
sync_batch_norm
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"n"
>
build_strategy
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
sync_batch_norm
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"kc"
>
False
</span>
<span
class=
"n"
>
exec_strategy
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
ExecutionStrategy
</span><span
class=
"p"
>
()
</span>
<span
class=
"n"
>
exec_strategy
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
ExecutionStrategy
</span><span
class=
"p"
>
()
</span>
...
@@ -237,37 +215,17 @@
...
@@ -237,37 +215,17 @@
<span
class=
"n"
>
build_strategy
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
build_strategy
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
build_strategy
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
build_strategy
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
exec_strategy
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
exec_strategy
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
exec_strategy
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
exec_strategy
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"4-freeze-program"
>
4. freeze program
<a
class=
"headerlink"
href=
"#4-freeze-program"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"4-freeze-program"
>
4. freeze program
<a
class=
"headerlink"
href=
"#4-freeze-program"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
float_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
int8_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
convert
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
2
3
4
5
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
float_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
int8_program
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
convert
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
quant_config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
quant_config
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
scope
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
scope
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
None
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
save_int8
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
True
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
save_int8
</span><span
class=
"o"
>
=
</span><span
class=
"kc"
>
True
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"5"
>
5.保存预测模型
<a
class=
"headerlink"
href=
"#5"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"5"
>
5.保存预测模型
<a
class=
"headerlink"
href=
"#5"
title=
"Permanent link"
>
#
</a></h3>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
io
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
save_inference_model
</span><span
class=
"p"
>
(
</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
fluid
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
io
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
save_inference_model
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
dirname
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
float_path
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
dirname
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
float_path
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
feeded_var_names
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
image
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
feeded_var_names
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
image
</span><span
class=
"o"
>
.
</span><span
class=
"n"
>
name
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
target_vars
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
out
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
executor
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
exe
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
target_vars
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"n"
>
out
</span><span
class=
"p"
>
],
</span>
<span
class=
"n"
>
executor
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
exe
</span><span
class=
"p"
>
,
</span>
...
@@ -283,7 +241,6 @@
...
@@ -283,7 +241,6 @@
<span
class=
"n"
>
model_filename
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
int8_path
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"s1"
>
'
/model
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
model_filename
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
int8_path
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"s1"
>
'
/model
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
params_filename
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
int8_path
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"s1"
>
'
/params
'
</span><span
class=
"p"
>
)
</span>
<span
class=
"n"
>
params_filename
</span><span
class=
"o"
>
=
</span><span
class=
"n"
>
int8_path
</span>
<span
class=
"o"
>
+
</span>
<span
class=
"s1"
>
'
/params
'
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
</div>
</div>
</div>
</div>
...
...
tutorials/quant_embedding_demo/index.html
浏览文件 @
a7fe788c
...
@@ -198,16 +198,7 @@
...
@@ -198,16 +198,7 @@
<p>
以下将以
<code>
基于skip-gram的word2vector模型
</code>
为例来说明如何使用
<code>
quant_embedding
</code>
接口。首先介绍
<code>
基于skip-gram的word2vector模型
</code>
的正常训练和测试流程。
</p>
<p>
以下将以
<code>
基于skip-gram的word2vector模型
</code>
为例来说明如何使用
<code>
quant_embedding
</code>
接口。首先介绍
<code>
基于skip-gram的word2vector模型
</code>
的正常训练和测试流程。
</p>
<h2
id=
"skip-gramword2vector"
>
基于skip-gram的word2vector模型
<a
class=
"headerlink"
href=
"#skip-gramword2vector"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"skip-gramword2vector"
>
基于skip-gram的word2vector模型
<a
class=
"headerlink"
href=
"#skip-gramword2vector"
title=
"Permanent link"
>
#
</a></h2>
<p>
以下是本例的简要目录结构及说明:
</p>
<p>
以下是本例的简要目录结构及说明:
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
.
2
3
4
5
6
7
8
9
10
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
.
├── cluster_train.py # 分布式训练函数
├── cluster_train.py # 分布式训练函数
├── cluster_train.sh # 本地模拟多机脚本
├── cluster_train.sh # 本地模拟多机脚本
├── train.py # 训练函数
├── train.py # 训练函数
...
@@ -218,59 +209,37 @@
...
@@ -218,59 +209,37 @@
├── train.py # 训练函数
├── train.py # 训练函数
└── utils.py # 通用函数
└── utils.py # 通用函数
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"_1"
>
介绍
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_1"
>
介绍
<a
class=
"headerlink"
href=
"#_1"
title=
"Permanent link"
>
#
</a></h3>
<p>
本例实现了skip-gram模式的word2vector模型。
</p>
<p>
本例实现了skip-gram模式的word2vector模型。
</p>
<p>
同时推荐用户参考
<a
href=
"https://aistudio.baidu.com/aistudio/projectDetail/124377"
>
IPython Notebook demo
</a></p>
<p>
同时推荐用户参考
<a
href=
"https://aistudio.baidu.com/aistudio/projectDetail/124377"
>
IPython Notebook demo
</a></p>
<h3
id=
"_2"
>
数据下载
<a
class=
"headerlink"
href=
"#_2"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_2"
>
数据下载
<a
class=
"headerlink"
href=
"#_2"
title=
"Permanent link"
>
#
</a></h3>
<p>
全量数据集使用的是来自1 Billion Word Language Model Benchmark的(
<a
href=
"http://www.statmt.org/lm-benchmark"
>
http://www.statmt.org/lm-benchmark
</a>
) 的数据集.
</p>
<p>
全量数据集使用的是来自1 Billion Word Language Model Benchmark的(
<a
href=
"http://www.statmt.org/lm-benchmark"
>
http://www.statmt.org/lm-benchmark
</a>
) 的数据集.
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
mkdir data
2
3
4
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
mkdir data
wget http://www.statmt.org/lm-benchmark/1-billion-word-language-modeling-benchmark-r13output.tar.gz
wget http://www.statmt.org/lm-benchmark/1-billion-word-language-modeling-benchmark-r13output.tar.gz
tar xzvf
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output.tar.gz
tar xzvf
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output.tar.gz
mv
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/
mv
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/
</pre></div>
</pre></div>
</td></tr></table>
<p>
备用数据地址下载命令如下
</p>
<p>
备用数据地址下载命令如下
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
mkdir data
2
3
4
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
mkdir data
wget https://paddlerec.bj.bcebos.com/word2vec/1-billion-word-language-modeling-benchmark-r13output.tar
wget https://paddlerec.bj.bcebos.com/word2vec/1-billion-word-language-modeling-benchmark-r13output.tar
tar xvf
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output.tar
tar xvf
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output.tar
mv
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/
mv
<span
class=
"m"
>
1
</span>
-billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/
</pre></div>
</pre></div>
</td></tr></table>
<p>
为了方便快速验证,我们也提供了经典的text8样例数据集,包含1700w个词。 下载命令如下
</p>
<p>
为了方便快速验证,我们也提供了经典的text8样例数据集,包含1700w个词。 下载命令如下
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
mkdir data
2
3
4
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
mkdir data
wget https://paddlerec.bj.bcebos.com/word2vec/text.tar
wget https://paddlerec.bj.bcebos.com/word2vec/text.tar
tar xvf text.tar
tar xvf text.tar
mv text data/
mv text data/
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"_3"
>
数据预处理
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_3"
>
数据预处理
<a
class=
"headerlink"
href=
"#_3"
title=
"Permanent link"
>
#
</a></h3>
<p>
以样例数据集为例进行预处理。全量数据集注意解压后以training-monolingual.tokenized.shuffled 目录为预处理目录,和样例数据集的text目录并列。
</p>
<p>
以样例数据集为例进行预处理。全量数据集注意解压后以training-monolingual.tokenized.shuffled 目录为预处理目录,和样例数据集的text目录并列。
</p>
<p>
词典格式: 词
<
空格
>
词频。注意低频词用'UNK'表示
</p>
<p>
词典格式: 词
<
空格
>
词频。注意低频词用'UNK'表示
</p>
<p>
可以按格式自建词典,如果自建词典跳过第一步。
<p>
可以按格式自建词典,如果自建词典跳过第一步。
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
the 1061396
2
3
4
5
6
7
8
9
10
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
the 1061396
of 593677
of 593677
and 416629
and 416629
one 411764
one 411764
...
@@ -280,76 +249,43 @@ a 325873
...
@@ -280,76 +249,43 @@ a 325873
to 316376
to 316376
zero 264975
zero 264975
nine 250430
nine 250430
</pre></div>
</pre></div></p>
</td></tr></table></p>
<p>
第一步根据英文语料生成词典,中文语料可以通过修改text_strip方法自定义处理方法。
</p>
<p>
第一步根据英文语料生成词典,中文语料可以通过修改text_strip方法自定义处理方法。
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python preprocess.py --build_dict --build_dict_corpus_dir data/text/ --dict_path data/test_build_dict
<div
class=
"codehilite"
><pre><span></span>
python preprocess.py --build_dict --build_dict_corpus_dir data/text/ --dict_path data/test_build_dict
</pre></div>
</pre></div>
</td></tr></table>
<p>
第二步根据词典将文本转成id, 同时进行downsample,按照概率过滤常见词, 同时生成word和id映射的文件,文件名为词典+"
<em>
word_to_id
</em>
"。
</p>
<p>
第二步根据词典将文本转成id, 同时进行downsample,按照概率过滤常见词, 同时生成word和id映射的文件,文件名为词典+"
<em>
word_to_id
</em>
"。
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python preprocess.py --filter_corpus --dict_path data/test_build_dict --input_corpus_dir data/text --output_corpus_dir data/convert_text8 --min_count
<span
class=
"m"
>
5
</span>
--downsample
<span
class=
"m"
>
0
</span>
.001
<div
class=
"codehilite"
><pre><span></span>
python preprocess.py --filter_corpus --dict_path data/test_build_dict --input_corpus_dir data/text --output_corpus_dir data/convert_text8 --min_count
<span
class=
"m"
>
5
</span>
--downsample
<span
class=
"m"
>
0
</span>
.001
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"_4"
>
训练
<a
class=
"headerlink"
href=
"#_4"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_4"
>
训练
<a
class=
"headerlink"
href=
"#_4"
title=
"Permanent link"
>
#
</a></h3>
<p>
具体的参数配置可运行
</p>
<p>
具体的参数配置可运行
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python train.py -h
<div
class=
"codehilite"
><pre><span></span>
python train.py -h
</pre></div>
</pre></div>
</td></tr></table>
<p>
单机多线程训练
<p>
单机多线程训练
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"nv"
>
OPENBLAS_NUM_THREADS
</span><span
class=
"o"
>
=
</span><span
class=
"m"
>
1
</span>
<span
class=
"nv"
>
CPU_NUM
</span><span
class=
"o"
>
=
</span><span
class=
"m"
>
5
</span>
python train.py --train_data_dir data/convert_text8 --dict_path data/test_build_dict --num_passes
<span
class=
"m"
>
10
</span>
--batch_size
<span
class=
"m"
>
100
</span>
--model_output_dir v1_cpu5_b100_lr1dir --base_lr
<span
class=
"m"
>
1
</span>
.0 --print_batch
<span
class=
"m"
>
1000
</span>
--with_speed --is_sparse
<div
class=
"codehilite"
><pre><span></span><span
class=
"nv"
>
OPENBLAS_NUM_THREADS
</span><span
class=
"o"
>
=
</span><span
class=
"m"
>
1
</span>
<span
class=
"nv"
>
CPU_NUM
</span><span
class=
"o"
>
=
</span><span
class=
"m"
>
5
</span>
python train.py --train_data_dir data/convert_text8 --dict_path data/test_build_dict --num_passes
<span
class=
"m"
>
10
</span>
--batch_size
<span
class=
"m"
>
100
</span>
--model_output_dir v1_cpu5_b100_lr1dir --base_lr
<span
class=
"m"
>
1
</span>
.0 --print_batch
<span
class=
"m"
>
1000
</span>
--with_speed --is_sparse
</pre></div>
</pre></div></p>
</td></tr></table></p>
<p>
本地单机模拟多机训练
</p>
<p>
本地单机模拟多机训练
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
sh cluster_train.sh
<div
class=
"codehilite"
><pre><span></span>
sh cluster_train.sh
</pre></div>
</pre></div>
</td></tr></table>
<p>
本示例中按照单机多线程训练的命令进行训练,训练完毕后,可看到在当前文件夹下保存模型的路径为:
<code>
v1_cpu5_b100_lr1dir
</code>
, 运行
<code>
ls v1_cpu5_b100_lr1dir
</code>
可看到该文件夹下保存了训练的10个epoch的模型文件。
<p>
本示例中按照单机多线程训练的命令进行训练,训练完毕后,可看到在当前文件夹下保存模型的路径为:
<code>
v1_cpu5_b100_lr1dir
</code>
, 运行
<code>
ls v1_cpu5_b100_lr1dir
</code>
可看到该文件夹下保存了训练的10个epoch的模型文件。
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
pass-0 pass-1 pass-2 pass-3 pass-4 pass-5 pass-6 pass-7 pass-8 pass-9
<div
class=
"codehilite"
><pre><span></span>
pass-0 pass-1 pass-2 pass-3 pass-4 pass-5 pass-6 pass-7 pass-8 pass-9
</pre></div>
</pre></div></p>
</td></tr></table></p>
<h3
id=
"_5"
>
预测
<a
class=
"headerlink"
href=
"#_5"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_5"
>
预测
<a
class=
"headerlink"
href=
"#_5"
title=
"Permanent link"
>
#
</a></h3>
<p>
测试集下载命令如下
</p>
<p>
测试集下载命令如下
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
#全量数据集测试集
</span>
2
3
4
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
#全量数据集测试集
</span>
wget https://paddlerec.bj.bcebos.com/word2vec/test_dir.tar
wget https://paddlerec.bj.bcebos.com/word2vec/test_dir.tar
<span
class=
"c1"
>
#样本数据集测试集
</span>
<span
class=
"c1"
>
#样本数据集测试集
</span>
wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar
wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar
</pre></div>
</pre></div>
</td></tr></table>
<p>
预测命令,注意词典名称需要加后缀"
<em>
word_to_id
</em>
", 此文件是预处理阶段生成的。
<p>
预测命令,注意词典名称需要加后缀"
<em>
word_to_id
</em>
", 此文件是预处理阶段生成的。
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size
<span
class=
"m"
>
20000
</span>
--model_dir v1_cpu5_b100_lr1dir/ --start_index
<span
class=
"m"
>
0
</span>
--last_index
<span
class=
"m"
>
9
</span>
<div
class=
"codehilite"
><pre><span></span>
python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size
<span
class=
"m"
>
20000
</span>
--model_dir v1_cpu5_b100_lr1dir/ --start_index
<span
class=
"m"
>
0
</span>
--last_index
<span
class=
"m"
>
9
</span>
</pre></div>
</pre></div>
</td></tr></table>
运行该预测命令, 可看到如下输出
运行该预测命令, 可看到如下输出
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
(
'
start index:
'
, 0,
'
last_index:
'
, 9)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
(
'
start index:
'
, 0,
'
last_index:
'
, 9)
(
'
vocab_size:
'
, 63642)
(
'
vocab_size:
'
, 63642)
step:1 249
step:1 249
epoch:0 acc:0.014
epoch:0 acc:0.014
...
@@ -371,57 +307,20 @@ step:1 2606
...
@@ -371,57 +307,20 @@ step:1 2606
epoch:8 acc:0.146
epoch:8 acc:0.146
step:1 2722
step:1 2722
epoch:9 acc:0.153
epoch:9 acc:0.153
</pre></div>
</pre></div></p>
</td></tr></table></p>
<h2
id=
"skip-gramword2vector_1"
>
量化
<code>
基于skip-gram的word2vector模型
</code><a
class=
"headerlink"
href=
"#skip-gramword2vector_1"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"skip-gramword2vector_1"
>
量化
<code>
基于skip-gram的word2vector模型
</code><a
class=
"headerlink"
href=
"#skip-gramword2vector_1"
title=
"Permanent link"
>
#
</a></h2>
<p>
量化配置为:
<p>
量化配置为:
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span>
2
3
4
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
config
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"p"
>
{
</span>
<span
class=
"s1"
>
'
params_name
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
emb
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
params_name
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
emb
'
</span><span
class=
"p"
>
,
</span>
<span
class=
"s1"
>
'
quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
abs_max
'
</span>
<span
class=
"s1"
>
'
quantize_type
'
</span><span
class=
"p"
>
:
</span>
<span
class=
"s1"
>
'
abs_max
'
</span>
<span
class=
"p"
>
}
</span>
<span
class=
"p"
>
}
</span>
</pre></div>
</pre></div></p>
</td></tr></table></p>
<p>
运行命令为:
</p>
<p>
运行命令为:
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size
<span
class=
"m"
>
20000
</span>
--model_dir v1_cpu5_b100_lr1dir/ --start_index
<span
class=
"m"
>
0
</span>
--last_index
<span
class=
"m"
>
9
</span>
--emb_quant True
<div
class=
"codehilite"
><pre><span></span>
python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size
<span
class=
"m"
>
20000
</span>
--model_dir v1_cpu5_b100_lr1dir/ --start_index
<span
class=
"m"
>
0
</span>
--last_index
<span
class=
"m"
>
9
</span>
--emb_quant True
</pre></div>
</pre></div>
</td></tr></table>
<p>
运行输出为:
</p>
<p>
运行输出为:
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span>
(
'
start index:
'
, 0,
'
last_index:
'
, 9)
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
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
(
'
start index:
'
, 0,
'
last_index:
'
, 9)
(
'
vocab_size:
'
, 63642)
(
'
vocab_size:
'
, 63642)
quant_embedding config {
'
quantize_type
'
:
'
abs_max
'
,
'
params_name
'
:
'
emb
'
,
'
quantize_bits
'
: 8,
'
dtype
'
:
'
int8
'
}
quant_embedding config {
'
quantize_type
'
:
'
abs_max
'
,
'
params_name
'
:
'
emb
'
,
'
quantize_bits
'
: 8,
'
dtype
'
:
'
int8
'
}
step:1 253
step:1 253
...
@@ -454,7 +353,6 @@ quant_embedding config {'quantize_type': 'abs_max', 'params_
...
@@ -454,7 +353,6 @@ quant_embedding config {'quantize_type': 'abs_max', 'params_
step:1 2719
step:1 2719
epoch:9 acc:0.153
epoch:9 acc:0.153
</pre></div>
</pre></div>
</td></tr></table>
<p>
量化后的模型保存在
<code>
./output_quant
</code>
中,可看到量化后的参数
<code>
'emb.int8'
</code>
的大小为3.9M, 在
<code>
./v1_cpu5_b100_lr1dir
</code>
中可看到量化前的参数
<code>
'emb'
</code>
的大小为16M。
</p>
<p>
量化后的模型保存在
<code>
./output_quant
</code>
中,可看到量化后的参数
<code>
'emb.int8'
</code>
的大小为3.9M, 在
<code>
./v1_cpu5_b100_lr1dir
</code>
中可看到量化前的参数
<code>
'emb'
</code>
的大小为16M。
</p>
...
...
tutorials/quant_post_demo/index.html
浏览文件 @
a7fe788c
...
@@ -196,15 +196,13 @@
...
@@ -196,15 +196,13 @@
<p>
在当前文件夹下创建
<code>
'pretrain'
</code>
文件夹,将
<code>
mobilenetv1
</code>
模型在该文件夹下解压,解压后的目录为
<code>
pretrain/MobileNetV1_pretrained
</code></p>
<p>
在当前文件夹下创建
<code>
'pretrain'
</code>
文件夹,将
<code>
mobilenetv1
</code>
模型在该文件夹下解压,解压后的目录为
<code>
pretrain/MobileNetV1_pretrained
</code></p>
<h3
id=
"_6"
>
导出模型
<a
class=
"headerlink"
href=
"#_6"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_6"
>
导出模型
<a
class=
"headerlink"
href=
"#_6"
title=
"Permanent link"
>
#
</a></h3>
<p>
通过运行以下命令可将模型转化为离线量化接口可用的模型:
<p>
通过运行以下命令可将模型转化为离线量化接口可用的模型:
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python export_model.py --model
<span
class=
"s2"
>
"
MobileNet
"
</span>
--pretrained_model ./pretrain/MobileNetV1_pretrained --data imagenet
<div
class=
"codehilite"
><pre><span></span>
python export_model.py --model
<span
class=
"s2"
>
"
MobileNet
"
</span>
--pretrained_model ./pretrain/MobileNetV1_pretrained --data imagenet
</pre></div>
</pre></div>
</td></tr></table>
转化之后的模型存储在
<code>
inference_model/MobileNet/
</code>
文件夹下,可看到该文件夹下有
<code>
'model'
</code>
,
<code>
'weights'
</code>
两个文件。
</p>
转化之后的模型存储在
<code>
inference_model/MobileNet/
</code>
文件夹下,可看到该文件夹下有
<code>
'model'
</code>
,
<code>
'weights'
</code>
两个文件。
</p>
<h3
id=
"_7"
>
离线量化
<a
class=
"headerlink"
href=
"#_7"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_7"
>
离线量化
<a
class=
"headerlink"
href=
"#_7"
title=
"Permanent link"
>
#
</a></h3>
<p>
接下来对导出的模型文件进行离线量化,离线量化的脚本为
<a
href=
"./quant_post.py"
>
quant_post.py
</a>
,脚本中使用接口
<code>
paddleslim.quant.quant_post
</code>
对模型进行离线量化。运行命令为:
<p>
接下来对导出的模型文件进行离线量化,离线量化的脚本为
<a
href=
"./quant_post.py"
>
quant_post.py
</a>
,脚本中使用接口
<code>
paddleslim.quant.quant_post
</code>
对模型进行离线量化。运行命令为:
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
python quant_post.py --model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights
<div
class=
"codehilite"
><pre><span></span>
python quant_post.py --model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights
</pre></div>
</pre></div></p>
</td></tr></table></p>
<ul>
<ul>
<li><code>
model_path
</code>
: 需要量化的模型坐在的文件夹
</li>
<li><code>
model_path
</code>
: 需要量化的模型坐在的文件夹
</li>
<li><code>
save_path
</code>
: 量化后的模型保存的路径
</li>
<li><code>
save_path
</code>
: 量化后的模型保存的路径
</li>
...
@@ -218,22 +216,18 @@
...
@@ -218,22 +216,18 @@
<h3
id=
"_8"
>
测试精度
<a
class=
"headerlink"
href=
"#_8"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"_8"
>
测试精度
<a
class=
"headerlink"
href=
"#_8"
title=
"Permanent link"
>
#
</a></h3>
<p>
使用
<a
href=
"./eval.py"
>
eval.py
</a>
脚本对量化前后的模型进行测试,得到模型的分类精度进行对比。
</p>
<p>
使用
<a
href=
"./eval.py"
>
eval.py
</a>
脚本对量化前后的模型进行测试,得到模型的分类精度进行对比。
</p>
<p>
首先测试量化前的模型的精度,运行以下命令:
<p>
首先测试量化前的模型的精度,运行以下命令:
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python eval.py --model_path ./inference_model/MobileNet --model_name model --params_name weights
<div
class=
"codehilite"
><pre><span></span>
python eval.py --model_path ./inference_model/MobileNet --model_name model --params_name weights
</pre></div>
</pre></div>
</td></tr></table>
精度输出为:
精度输出为:
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span>
top1_acc/top5_acc= [0.70913923 0.89548034]
<div
class=
"codehilite"
><pre><span></span>
top1_acc/top5_acc= [0.70913923 0.89548034]
</pre></div>
</pre></div></p>
</td></tr></table></p>
<p>
使用以下命令测试离线量化后的模型的精度:
</p>
<p>
使用以下命令测试离线量化后的模型的精度:
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
python eval.py --model_path ./quant_model_train/MobileNet
<div
class=
"codehilite"
><pre><span></span>
python eval.py --model_path ./quant_model_train/MobileNet
</pre></div>
</pre></div>
</td></tr></table>
<p>
精度输出为
<p>
精度输出为
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span>
top1_acc/top5_acc= [0.70141864 0.89086477]
<div
class=
"codehilite"
><pre><span></span>
top1_acc/top5_acc= [0.70141864 0.89086477]
</pre></div>
</pre></div>
</td></tr></table>
从以上精度对比可以看出,对
<code>
mobilenet
</code>
在
<code>
imagenet
</code>
上的分类模型进行离线量化后
<code>
top1
</code>
精度损失为
<code>
0.77%
</code>
,
<code>
top5
</code>
精度损失为
<code>
0.46%
</code>
.
</p>
从以上精度对比可以看出,对
<code>
mobilenet
</code>
在
<code>
imagenet
</code>
上的分类模型进行离线量化后
<code>
top1
</code>
精度损失为
<code>
0.77%
</code>
,
<code>
top5
</code>
精度损失为
<code>
0.46%
</code>
.
</p>
</div>
</div>
...
...
tutorials/sensitivity_demo/index.html
浏览文件 @
a7fe788c
...
@@ -177,11 +177,9 @@
...
@@ -177,11 +177,9 @@
</ul>
</ul>
<h2
id=
"2"
>
2. 运行示例
<a
class=
"headerlink"
href=
"#2"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"2"
>
2. 运行示例
<a
class=
"headerlink"
href=
"#2"
title=
"Permanent link"
>
#
</a></h2>
<p>
在路径
<code>
PaddleSlim/demo/sensitive
</code>
下执行以下代码运行示例:
</p>
<p>
在路径
<code>
PaddleSlim/demo/sensitive
</code>
下执行以下代码运行示例:
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"nb"
>
export
</span>
<span
class=
"nv"
>
CUDA_VISIBLE_DEVICES
</span><span
class=
"o"
>
=
</span><span
class=
"m"
>
0
</span>
2
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"nb"
>
export
</span>
<span
class=
"nv"
>
CUDA_VISIBLE_DEVICES
</span><span
class=
"o"
>
=
</span><span
class=
"m"
>
0
</span>
python train.py --model
<span
class=
"s2"
>
"
MobileNetV1
"
</span>
python train.py --model
<span
class=
"s2"
>
"
MobileNetV1
"
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
通过
<code>
python train.py --help
</code>
查看更多选项。
</p>
<p>
通过
<code>
python train.py --help
</code>
查看更多选项。
</p>
<h2
id=
"3"
>
3. 重要步骤说明
<a
class=
"headerlink"
href=
"#3"
title=
"Permanent link"
>
#
</a></h2>
<h2
id=
"3"
>
3. 重要步骤说明
<a
class=
"headerlink"
href=
"#3"
title=
"Permanent link"
>
#
</a></h2>
...
@@ -190,14 +188,7 @@ python train.py --model <span class="s2">"MobileNetV1"</span>
...
@@ -190,14 +188,7 @@ python train.py --model <span class="s2">"MobileNetV1"</span>
<p>
调用
<code>
paddleslim.prune.sensitivity
</code>
接口计算敏感度。敏感度信息会追加到
<code>
sensitivities_file
</code>
选项所指定的文件中,如果需要重新计算敏感度,需要先删除
<code>
sensitivities_file
</code>
文件。
</p>
<p>
调用
<code>
paddleslim.prune.sensitivity
</code>
接口计算敏感度。敏感度信息会追加到
<code>
sensitivities_file
</code>
选项所指定的文件中,如果需要重新计算敏感度,需要先删除
<code>
sensitivities_file
</code>
文件。
</p>
<p>
如果模型评估速度较慢,可以通过多进程的方式加速敏感度计算过程。比如在进程1中设置
<code>
pruned_ratios=[0.1, 0.2, 0.3, 0.4]
</code>
,并将敏感度信息存放在文件
<code>
sensitivities_0.data
</code>
中,然后在进程2中设置
<code>
pruned_ratios=[0.5, 0.6, 0.7]
</code>
,并将敏感度信息存储在文件
<code>
sensitivities_1.data
</code>
中。这样每个进程只会计算指定剪切率下的敏感度信息。多进程可以运行在单机多卡,或多机多卡。
</p>
<p>
如果模型评估速度较慢,可以通过多进程的方式加速敏感度计算过程。比如在进程1中设置
<code>
pruned_ratios=[0.1, 0.2, 0.3, 0.4]
</code>
,并将敏感度信息存放在文件
<code>
sensitivities_0.data
</code>
中,然后在进程2中设置
<code>
pruned_ratios=[0.5, 0.6, 0.7]
</code>
,并将敏感度信息存储在文件
<code>
sensitivities_1.data
</code>
中。这样每个进程只会计算指定剪切率下的敏感度信息。多进程可以运行在单机多卡,或多机多卡。
</p>
<p>
代码如下:
</p>
<p>
代码如下:
</p>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
# 进程1
</span>
2
3
4
5
6
7
8
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
# 进程1
</span>
<span
class=
"n"
>
sensitivity
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
sensitivity
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
...
@@ -206,16 +197,8 @@ python train.py --model <span class="s2">"MobileNetV1"</span>
...
@@ -206,16 +197,8 @@ python train.py --model <span class="s2">"MobileNetV1"</span>
<span
class=
"n"
>
sensitivities_file
</span><span
class=
"o"
>
=
</span><span
class=
"s2"
>
"
sensitivities_0.data
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
sensitivities_file
</span><span
class=
"o"
>
=
</span><span
class=
"s2"
>
"
sensitivities_0.data
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
pruned_ratios
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"mf"
>
0.1
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.2
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.3
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.4
</span><span
class=
"p"
>
])
</span>
<span
class=
"n"
>
pruned_ratios
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"mf"
>
0.1
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.2
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.3
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.4
</span><span
class=
"p"
>
])
</span>
</pre></div>
</pre></div>
</td></tr></table>
<table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
<div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
# 进程2
</span>
2
3
4
5
6
7
8
</pre></div></td><td
class=
"code"
><div
class=
"codehilite"
><pre><span></span><span
class=
"c1"
>
# 进程2
</span>
<span
class=
"n"
>
sensitivity
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
sensitivity
</span><span
class=
"p"
>
(
</span>
<span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
val_program
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
place
</span><span
class=
"p"
>
,
</span>
...
@@ -224,19 +207,16 @@ python train.py --model <span class="s2">"MobileNetV1"</span>
...
@@ -224,19 +207,16 @@ python train.py --model <span class="s2">"MobileNetV1"</span>
<span
class=
"n"
>
sensitivities_file
</span><span
class=
"o"
>
=
</span><span
class=
"s2"
>
"
sensitivities_1.data
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
sensitivities_file
</span><span
class=
"o"
>
=
</span><span
class=
"s2"
>
"
sensitivities_1.data
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"n"
>
pruned_ratios
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"mf"
>
0.5
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.6
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.7
</span><span
class=
"p"
>
])
</span>
<span
class=
"n"
>
pruned_ratios
</span><span
class=
"o"
>
=
</span><span
class=
"p"
>
[
</span><span
class=
"mf"
>
0.5
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.6
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.7
</span><span
class=
"p"
>
])
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"32"
>
3.2 合并敏感度
<a
class=
"headerlink"
href=
"#32"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"32"
>
3.2 合并敏感度
<a
class=
"headerlink"
href=
"#32"
title=
"Permanent link"
>
#
</a></h3>
<p>
如果用户通过上一节多进程的方式生成了多个存储敏感度信息的文件,可以通过
<code>
paddleslim.prune.merge_sensitive
</code>
将其合并,合并后的敏感度信息存储在一个
<code>
dict
</code>
中。代码如下:
</p>
<p>
如果用户通过上一节多进程的方式生成了多个存储敏感度信息的文件,可以通过
<code>
paddleslim.prune.merge_sensitive
</code>
将其合并,合并后的敏感度信息存储在一个
<code>
dict
</code>
中。代码如下:
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
sens
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
merge_sensitive
</span><span
class=
"p"
>
([
</span><span
class=
"s2"
>
"
./sensitivities_0.data
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"s2"
>
"
./sensitivities_1.data
"
</span><span
class=
"p"
>
])
</span>
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
sens
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
merge_sensitive
</span><span
class=
"p"
>
([
</span><span
class=
"s2"
>
"
./sensitivities_0.data
"
</span><span
class=
"p"
>
,
</span>
<span
class=
"s2"
>
"
./sensitivities_1.data
"
</span><span
class=
"p"
>
])
</span>
</pre></div>
</pre></div>
</td></tr></table>
<h3
id=
"33"
>
3.3 计算剪裁率
<a
class=
"headerlink"
href=
"#33"
title=
"Permanent link"
>
#
</a></h3>
<h3
id=
"33"
>
3.3 计算剪裁率
<a
class=
"headerlink"
href=
"#33"
title=
"Permanent link"
>
#
</a></h3>
<p>
调用
<code>
paddleslim.prune.get_ratios_by_loss
</code>
接口计算一组剪裁率。
</p>
<p>
调用
<code>
paddleslim.prune.get_ratios_by_loss
</code>
接口计算一组剪裁率。
</p>
<
table
class=
"codehilitetable"
><tr><td
class=
"linenos"
><div
class=
"linenodiv"
><pre><span></span>
1
</pre></div></td><td
class=
"code"
><
div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
ratios
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
get_ratios_by_loss
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
sens
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.01
</span><span
class=
"p"
>
)
</span>
<div
class=
"codehilite"
><pre><span></span><span
class=
"n"
>
ratios
</span>
<span
class=
"o"
>
=
</span>
<span
class=
"n"
>
get_ratios_by_loss
</span><span
class=
"p"
>
(
</span><span
class=
"n"
>
sens
</span><span
class=
"p"
>
,
</span>
<span
class=
"mf"
>
0.01
</span><span
class=
"p"
>
)
</span>
</pre></div>
</pre></div>
</td></tr></table>
<p>
其中,
<code>
0.01
</code>
为一个阈值,对于任意卷积层,其剪裁率为使精度损失低于阈值
<code>
0.01
</code>
的最大剪裁率。
</p>
<p>
其中,
<code>
0.01
</code>
为一个阈值,对于任意卷积层,其剪裁率为使精度损失低于阈值
<code>
0.01
</code>
的最大剪裁率。
</p>
<p>
用户在计算出一组剪裁率之后可以通过接口
<code>
paddleslim.prune.Pruner
</code>
剪裁网络,并用接口
<code>
paddleslim.analysis.flops
</code>
计算
<code>
FLOPs
</code>
。如果
<code>
FLOPs
</code>
不满足要求,调整阈值重新计算出一组剪裁率。
</p>
<p>
用户在计算出一组剪裁率之后可以通过接口
<code>
paddleslim.prune.Pruner
</code>
剪裁网络,并用接口
<code>
paddleslim.analysis.flops
</code>
计算
<code>
FLOPs
</code>
。如果
<code>
FLOPs
</code>
不满足要求,调整阈值重新计算出一组剪裁率。
</p>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录