Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
9abf40c9
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9abf40c9
编写于
2月 22, 2019
作者:
M
minqiyang
提交者:
ceci3
3月 04, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add imperative python tracer
上级
92f3cf42
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
31 addition
and
25 deletion
+31
-25
paddle/fluid/imperative/layer.h
paddle/fluid/imperative/layer.h
+2
-0
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+10
-0
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+13
-24
python/paddle/fluid/imperative/__init__.py
python/paddle/fluid/imperative/__init__.py
+4
-0
python/paddle/fluid/imperative/base.py
python/paddle/fluid/imperative/base.py
+2
-1
未找到文件。
paddle/fluid/imperative/layer.h
浏览文件 @
9abf40c9
...
@@ -205,6 +205,7 @@ class OpBase {
...
@@ -205,6 +205,7 @@ class OpBase {
:
op_desc_
(
nullptr
),
:
op_desc_
(
nullptr
),
forward_id_
(
-
1
),
forward_id_
(
-
1
),
backward_id_
(
-
1
),
backward_id_
(
-
1
),
trace_id_
(
-
1
),
place_
(
platform
::
CPUPlace
())
{}
place_
(
platform
::
CPUPlace
())
{}
virtual
~
OpBase
()
{
virtual
~
OpBase
()
{
...
@@ -225,6 +226,7 @@ class OpBase {
...
@@ -225,6 +226,7 @@ class OpBase {
// Note: each fwd op corresponds to a vector of bwd ops.
// Note: each fwd op corresponds to a vector of bwd ops.
std
::
vector
<
framework
::
OpDesc
*>
grad_op_descs_
;
std
::
vector
<
framework
::
OpDesc
*>
grad_op_descs_
;
int
backward_id_
;
int
backward_id_
;
int
trace_id_
;
platform
::
Place
place_
;
platform
::
Place
place_
;
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
9abf40c9
...
@@ -193,6 +193,16 @@ PYBIND11_MODULE(core, m) {
...
@@ -193,6 +193,16 @@ PYBIND11_MODULE(core, m) {
}
}
},
},
py
::
return_value_policy
::
reference
)
py
::
return_value_policy
::
reference
)
.
def_property
(
"_trace_id"
,
[](
const
imperative
::
OpBase
&
self
)
{
pybind11
::
gil_scoped_release
release
;
return
self
.
trace_id_
;
},
[](
imperative
::
OpBase
&
self
,
int
trace_id
)
{
pybind11
::
gil_scoped_release
release
;
self
.
trace_id_
=
trace_id
;
},
py
::
return_value_policy
::
reference
)
.
def_property
(
.
def_property
(
"forward_id"
,
"forward_id"
,
[](
const
imperative
::
OpBase
&
self
)
{
return
self
.
forward_id_
;
},
[](
const
imperative
::
OpBase
&
self
)
{
return
self
.
forward_id_
;
},
...
...
python/paddle/fluid/framework.py
浏览文件 @
9abf40c9
...
@@ -1201,13 +1201,13 @@ class Block(object):
...
@@ -1201,13 +1201,13 @@ class Block(object):
raise
ValueError
(
"Var {0} is not found recursively"
.
format
(
name
))
raise
ValueError
(
"Var {0} is not found recursively"
.
format
(
name
))
def
_clear_block
(
self
):
def
_clear_block
(
self
):
# TODO(minqiyang): move this to backward_hooks
assert
_in_imperative_mode
()
self
.
desc
.
_clear_block
()
for
name
in
self
.
vars
.
keys
():
# TODO(minqiyang): move this to Variable and Operator's __del__
assert
self
.
vars
[
name
].
persistable
self
.
desc
.
_clear_block
()
del
self
.
ops
[:]
assert
len
(
self
.
vars
)
==
0
assert
len
(
self
.
ops
)
==
0
def
all_parameters
(
self
):
def
all_parameters
(
self
):
return
list
(
self
.
iter_parameters
())
return
list
(
self
.
iter_parameters
())
...
@@ -1345,26 +1345,13 @@ class Block(object):
...
@@ -1345,26 +1345,13 @@ class Block(object):
#
#
# TODO(minqiyang): add op stop_gradient support in static mode too.
# TODO(minqiyang): add op stop_gradient support in static mode too.
# currently, we only support stop_gradient in imperative mode.
# currently, we only support stop_gradient in imperative mode.
self
.
_trace_op
(
op
,
kwargs
.
get
(
"stop_gradient"
,
False
))
_imperative_tracer
().
trace_op
(
op
,
self
.
ops
.
append
(
op
)
kwargs
.
get
(
"stop_gradient"
,
False
))
else
:
self
.
ops
.
append
(
op
)
return
op
return
op
def
_trace_op
(
self
,
op
,
stop_gradient
=
False
):
backward_refs
=
_imperative_tracer
().
trace
(
op
.
iop
,
op
.
inputs
,
op
.
outputs
,
self
.
desc
,
_imperative_current_expected_place_
,
stop_gradient
)
# TODO(minqiyang): support backward_hooks to eager remove backward_refs
op
.
backward_refs
=
defaultdict
(
list
)
for
k
,
v
in
six
.
iteritems
(
op
.
inputs
):
if
k
in
backward_refs
:
op
.
backward_refs
[
k
]
=
op
.
inputs
[
k
]
for
k
,
v
in
six
.
iteritems
(
op
.
outputs
):
if
k
in
backward_refs
:
op
.
backward_refs
[
k
]
=
op
.
outputs
[
k
]
def
_insert_op
(
self
,
index
,
*
args
,
**
kwargs
):
def
_insert_op
(
self
,
index
,
*
args
,
**
kwargs
):
"""
"""
Insert a Operator according to the giving arguments.
Insert a Operator according to the giving arguments.
...
@@ -1417,9 +1404,11 @@ class Block(object):
...
@@ -1417,9 +1404,11 @@ class Block(object):
inputs
=
kwargs
.
get
(
"inputs"
,
None
),
inputs
=
kwargs
.
get
(
"inputs"
,
None
),
outputs
=
kwargs
.
get
(
"outputs"
,
None
),
outputs
=
kwargs
.
get
(
"outputs"
,
None
),
attrs
=
kwargs
.
get
(
"attrs"
,
None
))
attrs
=
kwargs
.
get
(
"attrs"
,
None
))
self
.
ops
.
insert
(
0
,
op
)
if
_in_imperative_mode
():
if
_in_imperative_mode
():
self
.
_trace_op
(
op
,
kwargs
.
get
(
"stop_gradient"
,
False
))
_imperative_tracer
().
trace_op
(
op
,
kwargs
.
get
(
"stop_gradient"
,
False
))
else
:
self
.
ops
.
insert
(
0
,
op
)
return
op
return
op
def
_sync_with_cpp
(
self
):
def
_sync_with_cpp
(
self
):
...
...
python/paddle/fluid/imperative/__init__.py
浏览文件 @
9abf40c9
...
@@ -23,7 +23,11 @@ from .layers import *
...
@@ -23,7 +23,11 @@ from .layers import *
from
.
import
nn
from
.
import
nn
from
.nn
import
*
from
.nn
import
*
from
.
import
tracer
from
.tracer
import
*
__all__
=
[]
__all__
=
[]
__all__
+=
layers
.
__all__
__all__
+=
layers
.
__all__
__all__
+=
base
.
__all__
__all__
+=
base
.
__all__
__all__
+=
nn
.
__all__
__all__
+=
nn
.
__all__
__all__
+=
tracer
.
__all__
python/paddle/fluid/imperative/base.py
浏览文件 @
9abf40c9
...
@@ -16,6 +16,7 @@ import numpy as np
...
@@ -16,6 +16,7 @@ import numpy as np
from
paddle.fluid
import
core
from
paddle.fluid
import
core
from
paddle.fluid
import
framework
from
paddle.fluid
import
framework
from
.tracer
import
Tracer
__all__
=
[
'enabled'
,
'guard'
,
'to_variable'
]
__all__
=
[
'enabled'
,
'guard'
,
'to_variable'
]
...
@@ -28,7 +29,7 @@ def enabled():
...
@@ -28,7 +29,7 @@ def enabled():
def
guard
(
place
=
None
):
def
guard
(
place
=
None
):
train
=
framework
.
Program
()
train
=
framework
.
Program
()
startup
=
framework
.
Program
()
startup
=
framework
.
Program
()
tracer
=
core
.
Tracer
(
train
.
current_block
().
desc
)
tracer
=
Tracer
(
train
.
current_block
().
desc
)
if
place
is
None
:
if
place
is
None
:
if
core
.
is_compiled_with_cuda
():
if
core
.
is_compiled_with_cuda
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录