Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
bdac9501
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看板
提交
bdac9501
编写于
12月 24, 2019
作者:
C
ceci3
提交者:
whs
12月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix nas print best_tokens (#9)
上级
2a186e9c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
27 deletion
+31
-27
docs/docs/table_latency.md
docs/docs/table_latency.md
+1
-1
paddleslim/analysis/latency.py
paddleslim/analysis/latency.py
+28
-25
paddleslim/common/sa_controller.py
paddleslim/common/sa_controller.py
+2
-1
未找到文件。
docs/docs/table_latency.md
浏览文件 @
bdac9501
...
...
@@ -81,7 +81,7 @@ op_type,active_type,n_in,c_in,h_in,w_in\tlatency
**字段解释**
-
**op_type(str)**
- 当前op类型。
-
**active_type (string)**
- 激活函数类型,包含:relu, prelu, sigmoid, relu6, tanh。
-
**active_type (string
|None
)**
- 激活函数类型,包含:relu, prelu, sigmoid, relu6, tanh。
-
**n_in (int)**
- 输入 Tensor 的批尺寸 (batch size)。
-
**c_in (int)**
- 输入 Tensor 的通道 (channel) 数。
-
**h_in (int)**
- 输入 Tensor 的特征高度。
...
...
paddleslim/analysis/latency.py
浏览文件 @
bdac9501
...
...
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle.fluid
import
Program
from
..core
import
GraphWrapper
,
OpWrapper
__all__
=
[
"LatencyEvaluator"
,
"TableLatencyEvaluator"
]
...
...
@@ -28,33 +30,33 @@ class LatencyEvaluator(object):
i
=
0
for
op
in
graph
.
ops
():
if
op
.
type
()
in
[
'conv2d'
,
'depthwise_conv2d'
]:
tmp
=
_conv_op_args
(
op
)
tmp
=
self
.
_conv_op_args
(
op
)
elif
op
.
type
()
in
[
'elementwise_add'
,
'elementwise_mul'
,
'elementwise_max'
]:
tmp
=
_eltwise_op_args
(
op
)
tmp
=
self
.
_eltwise_op_args
(
op
)
elif
op
.
type
()
in
[
'relu'
,
'prelu'
,
'sigmoid'
,
'relu6'
,
'elu'
,
'brelu'
,
'leaky_relu'
]:
tmp
=
_activation_op_args
(
op
)
tmp
=
self
.
_activation_op_args
(
op
)
elif
op
.
type
()
==
'batch_norm'
:
tmp
=
_batch_norm_op_args
(
op
)
tmp
=
self
.
_batch_norm_op_args
(
op
)
elif
op
.
type
()
==
'pool2d'
:
tmp
=
_pooling_op_args
(
op
)
tmp
=
self
.
_pooling_op_args
(
op
)
elif
op
.
type
()
==
'batch_norm'
:
tmp
=
_batch_norm_op_args
(
op
)
tmp
=
self
.
_batch_norm_op_args
(
op
)
elif
op
.
type
()
==
'softmax'
:
tmp
=
_softmax_op_args
(
op
)
tmp
=
self
.
_softmax_op_args
(
op
)
elif
op
.
type
()
==
'mul'
:
tmp
=
_fc_op_args
(
op
)
tmp
=
self
.
_fc_op_args
(
op
)
else
:
tmp
=
None
if
tmp
:
ops
.
append
(
tmp
)
return
ops
def
_conv_op_args
(
op
):
def
_conv_op_args
(
self
,
op
):
assert
isinstance
(
op
,
OpWrapper
)
tmp
,
res
=
[],
[]
# op_name
...
...
@@ -69,11 +71,11 @@ class LatencyEvaluator(object):
# batch size
tmp
.
append
(
1
)
# channels, height, width
in_shapes
=
op
.
inputs
(
'Input'
)[
0
].
shape
in_shapes
=
op
.
inputs
(
'Input'
)[
0
].
shape
()
tmp
=
tmp
+
[
int
(
in_shapes
[
1
]),
int
(
in_shapes
[
2
]),
int
(
in_shapes
[
3
])]
# output channels
w_shapes
=
op
.
inputs
(
'Filter'
)[
0
].
shape
w_shapes
=
op
.
inputs
(
'Filter'
)[
0
].
shape
()
tmp
.
append
(
int
(
w_shapes
[
0
]))
# group
...
...
@@ -104,7 +106,7 @@ class LatencyEvaluator(object):
tmp
=
tmp
+
res
return
tmp
def
_batch_norm_op_args
(
op
):
def
_batch_norm_op_args
(
self
,
op
):
tmp
=
[]
# op name
tmp
.
append
(
'batch_norm'
)
...
...
@@ -116,11 +118,11 @@ class LatencyEvaluator(object):
# batch size
tmp
.
append
(
1
)
# input channels, height, width
in_shapes
=
op
.
inputs
(
"X"
)[
0
].
shape
in_shapes
=
op
.
inputs
(
"X"
)[
0
].
shape
()
tmp
=
tmp
+
[
int
(
in_shapes
[
1
]),
int
(
in_shapes
[
2
]),
int
(
in_shapes
[
3
])]
return
tmp
def
_eltwise_op_args
(
op
):
def
_eltwise_op_args
(
self
,
op
):
# op name
tmp
=
[
'eltwise'
]
# elementwise type, TODO: add more ops
...
...
@@ -133,7 +135,7 @@ class LatencyEvaluator(object):
# batch size
tmp
.
append
(
1
)
# input channels, height, width
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
()
while
len
(
in_shapes
)
<
4
:
in_shapes
=
in_shapes
+
(
1
,
)
...
...
@@ -141,14 +143,14 @@ class LatencyEvaluator(object):
tmp
.
append
(
int
(
in_shapes
[
i
]))
return
tmp
def
_activation_op_args
(
op
):
def
_activation_op_args
(
self
,
op
):
tmp
=
[]
# activation type
tmp
.
append
(
op
.
type
())
# batch size
tmp
.
append
(
1
)
# input channels, height, width
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
()
while
len
(
in_shapes
)
<
4
:
in_shapes
=
in_shapes
+
(
1
,
)
...
...
@@ -156,7 +158,7 @@ class LatencyEvaluator(object):
tmp
.
append
(
int
(
in_shapes
[
i
]))
return
tmp
def
_pooling_op_args
(
op
):
def
_pooling_op_args
(
self
,
op
):
tmp
,
res
=
[],
[]
# op name
tmp
.
append
(
'pooling'
)
...
...
@@ -165,7 +167,7 @@ class LatencyEvaluator(object):
# batch size
tmp
.
append
(
1
)
# channels, height, width
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
()
tmp
=
tmp
+
[
int
(
in_shapes
[
1
]),
int
(
in_shapes
[
2
]),
int
(
in_shapes
[
3
])]
# kernel size
ksize
=
op
.
attr
(
'ksize'
)
...
...
@@ -201,7 +203,7 @@ class LatencyEvaluator(object):
tmp
=
tmp
+
res
return
tmp
def
_softmax_op_args
(
op
):
def
_softmax_op_args
(
self
,
op
):
# op name
tmp
=
[
'softmax'
]
# axis
...
...
@@ -209,7 +211,7 @@ class LatencyEvaluator(object):
# batch size
tmp
.
append
(
1
)
# input channels, height, width
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
in_shapes
=
op
.
inputs
(
'X'
)[
0
].
shape
()
while
len
(
in_shapes
)
<
4
:
in_shapes
=
in_shapes
+
(
1
,
)
...
...
@@ -218,7 +220,7 @@ class LatencyEvaluator(object):
return
tmp
def
_fc_op_args
(
blocks
,
op
):
def
_fc_op_args
(
self
,
op
):
# op name
tmp
=
[
'conv'
]
# flag bias
...
...
@@ -229,12 +231,12 @@ class LatencyEvaluator(object):
tmp
.
append
(
1
)
# input channels, height, width
channels
=
1
in_shape
=
op
.
inputs
(
'X'
)[
0
].
shape
in_shape
=
op
.
inputs
(
'X'
)[
0
].
shape
()
for
i
in
range
(
1
,
len
(
in_shape
)):
channels
*=
in_shape
[
i
]
tmp
=
tmp
+
[
int
(
channels
),
1
,
1
]
# output channels
tmp
.
append
(
int
(
op
.
outputs
(
'Out'
)[
0
].
shape
[
1
]))
tmp
.
append
(
int
(
op
.
outputs
(
'Out'
)[
0
].
shape
()
[
1
]))
# groups, kernel size, padding, stride, dilation
tmp
=
tmp
+
[
1
,
1
,
0
,
1
,
1
]
return
tmp
...
...
@@ -279,5 +281,6 @@ class TableLatencyEvaluator(LatencyEvaluator):
graph
=
GraphWrapper
(
graph
)
assert
isinstance
(
graph
,
GraphWrapper
)
for
op
in
self
.
_get_ops_from_graph
(
graph
):
total_latency
+=
self
.
_op_latency
(
self
.
_delimiter
.
join
(
op
))
total_latency
+=
self
.
_op_latency
(
self
.
_delimiter
.
join
(
map
(
lambda
x
:
str
(
x
),
op
)))
return
total_latency
paddleslim/common/sa_controller.py
浏览文件 @
bdac9501
...
...
@@ -98,7 +98,8 @@ class SAController(EvolutionaryController):
self
.
_best_tokens
=
tokens
_logger
.
info
(
"Controller - iter: {}; best_reward: {}, best tokens: {}, current_reward: {}; current tokens: {}"
.
format
(
self
.
_iter
,
self
.
_reward
,
self
.
_tokens
,
reward
,
tokens
))
format
(
self
.
_iter
,
self
.
_max_reward
,
self
.
_best_tokens
,
reward
,
tokens
))
if
self
.
_checkpoints
!=
None
:
self
.
_save_checkpoint
(
self
.
_checkpoints
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录