Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
1c11f817
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1c11f817
编写于
3月 26, 2019
作者:
Z
Zhen Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the resolve hazard method.
上级
2ccbfd5e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
34 addition
and
33 deletion
+34
-33
python/paddle/fluid/contrib/slim/quantization/quantization_pass.py
...ddle/fluid/contrib/slim/quantization/quantization_pass.py
+6
-33
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+28
-0
未找到文件。
python/paddle/fluid/contrib/slim/quantization/quantization_pass.py
浏览文件 @
1c11f817
...
...
@@ -26,35 +26,6 @@ __all__ = [
]
def
_resolve_hazard
(
graph
):
def
_to_node
(
nodes
,
node_name
):
target_node
=
None
for
n
in
nodes
:
if
n
.
name
()
==
node_name
:
target_node
=
n
.
node
assert
target_node
is
not
None
,
"Cannot find the target node in the giving set."
return
target_node
ordered_nodes
=
graph
.
topology_sort
()
var_nodes
=
dict
()
for
node
in
ordered_nodes
:
if
node
.
is_op
()
and
node
.
op
()
is
not
None
:
for
each_var_name
in
node
.
op
().
input_arg_names
():
if
each_var_name
not
in
var_nodes
:
var_nodes
[
each_var_name
]
=
[
_to_node
(
node
.
inputs
,
each_var_name
)
]
for
each_var_name
in
node
.
op
().
output_arg_names
():
if
each_var_name
not
in
var_nodes
:
var_nodes
[
each_var_name
]
=
[
_to_node
(
node
.
outputs
,
each_var_name
)
]
else
:
var_nodes
[
each_var_name
].
append
(
_to_node
(
node
.
outputs
,
each_var_name
))
graph
.
graph
.
resolve_hazard
(
var_nodes
)
class
QuantizationTransformPass
(
object
):
def
__init__
(
self
,
scope
=
None
,
...
...
@@ -150,8 +121,8 @@ class QuantizationTransformPass(object):
"""
assert
isinstance
(
graph
,
IrGraph
),
'graph must be the instance of IrGraph.'
sequential_execution
=
core
.
get_pass
(
'sequential_execution_pass'
)
sequential_execution
.
apply
(
graph
.
graph
)
#
sequential_execution = core.get_pass('sequential_execution_pass')
#
sequential_execution.apply(graph.graph)
self
.
_is_test
=
graph
.
is_test
()
# marked the variable which has been dequantized.
dequantized_vars
=
collections
.
OrderedDict
()
...
...
@@ -216,7 +187,7 @@ class QuantizationTransformPass(object):
for
op
in
ops
:
if
op
.
name
()
in
self
.
_quantizable_grad_ops
:
_transform_backward
(
graph
,
op
)
_resolve_hazard
(
graph
)
graph
.
resolve_hazard
(
)
return
graph
def
_create_global_step
(
self
,
graph
):
...
...
@@ -652,6 +623,7 @@ class QuantizationFreezePass(object):
# remove the unused var node in the graph
self
.
_remove_unused_var_nodes
(
graph
)
graph
.
resolve_hazard
()
return
graph
def
_remove_fake_quant_and_dequant_op
(
self
,
graph
,
op_node
):
...
...
@@ -895,6 +867,7 @@ class ConvertToInt8Pass(object):
# remove the unused var node in the graph
self
.
_remove_unused_var_nodes
(
graph
)
graph
.
resolve_hazard
()
return
graph
def
_convert_to_int8
(
self
,
graph
,
var_node
):
...
...
@@ -977,5 +950,5 @@ class TransformForMobilePass(object):
for
output_node
in
op_node
.
outputs
:
graph
.
link_to
(
dequant_node
,
output_node
)
graph
.
safe_remove_nodes
(
op_node
)
graph
.
resolve_hazard
()
return
graph
python/paddle/fluid/framework.py
浏览文件 @
1c11f817
...
...
@@ -2253,6 +2253,34 @@ class IrGraph(object):
original_nodes
=
{
n
.
node
for
n
in
remove_nodes
}
core
.
graph_safe_remove_nodes
(
self
.
graph
,
original_nodes
)
def
resolve_hazard
(
self
):
def
_to_node
(
nodes
,
node_name
):
target_node
=
None
for
n
in
nodes
:
if
n
.
name
()
==
node_name
:
target_node
=
n
assert
target_node
is
not
None
,
"Cannot find the target node in the giving set."
return
target_node
ordered_nodes
=
core
.
topology_sort
(
self
.
graph
)
var_nodes
=
dict
()
for
node
in
ordered_nodes
:
if
node
.
is_op
()
and
node
.
op
()
is
not
None
:
for
each_var_name
in
node
.
op
().
input_arg_names
():
if
each_var_name
not
in
var_nodes
:
var_nodes
[
each_var_name
]
=
[
_to_node
(
node
.
inputs
,
each_var_name
)
]
for
each_var_name
in
node
.
op
().
output_arg_names
():
if
each_var_name
not
in
var_nodes
:
var_nodes
[
each_var_name
]
=
[
_to_node
(
node
.
outputs
,
each_var_name
)
]
else
:
var_nodes
[
each_var_name
].
append
(
_to_node
(
node
.
outputs
,
each_var_name
))
self
.
graph
.
resolve_hazard
(
var_nodes
)
def
has_circle
(
self
):
"""
Check if the graph has a circle.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录