Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
7e71a785
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看板
提交
7e71a785
编写于
11月 13, 2021
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add conv bn fusion pass to quanter
上级
b1e04ba7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
0 deletion
+42
-0
paddleslim/quant/quanter.py
paddleslim/quant/quanter.py
+42
-0
未找到文件。
paddleslim/quant/quanter.py
浏览文件 @
7e71a785
...
@@ -173,6 +173,42 @@ def _parse_configs(user_config):
...
@@ -173,6 +173,42 @@ def _parse_configs(user_config):
return
configs
return
configs
def
_remove_unused_var_nodes
(
graph
):
all_used_vars
=
set
()
ops
=
graph
.
all_op_nodes
()
for
op_node
in
ops
:
for
input_node
in
op_node
.
inputs
:
all_used_vars
.
add
(
input_node
)
for
output_node
in
op_node
.
outputs
:
all_used_vars
.
add
(
output_node
)
all_used_vars
=
{
n
.
node
for
n
in
all_used_vars
}
all_unused_vars
=
{
n
for
n
in
filter
(
lambda
node
:
node
.
node
not
in
all_used_vars
,
graph
.
all_var_nodes
())
}
graph
.
safe_remove_nodes
(
all_unused_vars
)
return
graph
def
_apply_pass
(
scope
,
graph
,
pass_name
,
attrs
=
None
,
attr_values
=
None
,
debug
=
False
):
ir_pass
=
core
.
get_pass
(
pass_name
)
cpp_graph
=
graph
.
graph
if
not
cpp_graph
.
has
(
'__param_scope__'
):
cpp_graph
.
set_not_owned
(
'__param_scope__'
,
scope
)
if
attrs
:
assert
attr_values
and
len
(
attrs
)
==
len
(
attr_values
),
"Different number of pass attributes and their values."
for
attr
,
value
in
zip
(
attrs
,
attr_values
):
ir_pass
.
set
(
attr
,
value
)
ir_pass
.
apply
(
cpp_graph
)
if
debug
:
graph
.
draw
(
'.'
,
'qat_fp32_{}'
.
format
(
pass_name
),
graph
.
all_op_nodes
())
_remove_unused_var_nodes
(
graph
)
return
graph
def
quant_aware
(
program
,
def
quant_aware
(
program
,
place
,
place
,
...
@@ -242,6 +278,12 @@ def quant_aware(program,
...
@@ -242,6 +278,12 @@ def quant_aware(program,
main_graph
=
IrGraph
(
core
.
Graph
(
program
.
desc
),
for_test
=
for_test
)
main_graph
=
IrGraph
(
core
.
Graph
(
program
.
desc
),
for_test
=
for_test
)
graph
=
_apply_pass
(
scope
,
main_graph
,
'conv_bn_fuse_pass'
)
graph
=
_apply_pass
(
scope
,
main_graph
,
'depthwise_conv_bn_fuse_pass'
)
graph
=
_apply_pass
(
scope
,
main_graph
,
'conv_eltwiseadd_bn_fuse_pass'
)
graph
=
_apply_pass
(
scope
,
main_graph
,
'depthwise_conv_eltwiseadd_bn_fuse_pass'
)
transform_pass_ops
=
[]
transform_pass_ops
=
[]
quant_dequant_ops
=
[]
quant_dequant_ops
=
[]
for
op_type
in
config
[
'quantize_op_types'
]:
for
op_type
in
config
[
'quantize_op_types'
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录