Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4d0df1fe
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4d0df1fe
编写于
11月 28, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add fields for autograd
test=develop
上级
81383916
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
34 deletion
+72
-34
paddle/fluid/imperative/layer.h
paddle/fluid/imperative/layer.h
+12
-2
paddle/fluid/imperative/tracer.h
paddle/fluid/imperative/tracer.h
+11
-4
paddle/fluid/pybind/imperative.h
paddle/fluid/pybind/imperative.h
+5
-0
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+3
-2
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+41
-26
未找到文件。
paddle/fluid/imperative/layer.h
浏览文件 @
4d0df1fe
...
...
@@ -23,19 +23,29 @@
namespace
paddle
{
namespace
imperative
{
class
OpBase
;
class
VarBase
{
public:
VarBase
()
{}
virtual
~
VarBase
()
{}
OpBase
*
pre_op_
;
framework
::
VarDesc
*
var_desc_
;
};
class
OpBase
{
public:
OpBase
()
{}
virtual
~
OpBase
()
{}
OpBase
()
:
input_vars_
(
new
std
::
vector
<
VarBase
*>
()),
output_vars_
(
new
std
::
vector
<
VarBase
*>
())
{}
virtual
~
OpBase
()
{
delete
input_vars_
;
delete
output_vars_
;
}
std
::
vector
<
VarBase
*>*
input_vars_
;
std
::
vector
<
VarBase
*>*
output_vars_
;
framework
::
OpDesc
*
op_desc_
;
};
...
...
paddle/fluid/imperative/tracer.h
浏览文件 @
4d0df1fe
...
...
@@ -31,15 +31,18 @@ class Tracer {
public:
Tracer
()
{}
void
Trace
(
OpBase
*
op
,
const
std
::
map
<
std
::
string
,
VarBase
*>&
inputs
,
const
std
::
map
<
std
::
string
,
VarBase
*>&
outputs
)
{
void
Trace
(
OpBase
*
op
,
const
std
::
vector
<
VarBase
*>&
inputs
,
const
std
::
vector
<
VarBase
*>&
outputs
)
{
framework
::
OpDesc
*
op_desc
=
op
->
op_desc_
;
LOG
(
ERROR
)
<<
"tracer tracing "
<<
op_desc
->
Type
();
op_desc
->
InferShape
(
*
block_
);
op_desc
->
InferVarType
(
block_
);
std
::
unique_ptr
<
framework
::
OperatorBase
>
op_base
=
framework
::
OpRegistry
::
CreateOp
(
*
op_desc
);
for
(
const
std
::
string
&
vname
:
op_desc
->
InputArgumentNames
())
{
*
op
->
input_vars_
=
inputs
;
for
(
VarBase
*
input
:
inputs
)
{
const
std
::
string
vname
=
input
->
var_desc_
->
Name
();
framework
::
Variable
*
var
=
scope_
->
Var
(
vname
);
if
(
!
var
->
IsInitialized
())
{
framework
::
VarDesc
*
var_desc
=
block_
->
FindVar
(
vname
);
...
...
@@ -50,7 +53,10 @@ class Tracer {
}
}
}
for
(
const
std
::
string
&
vname
:
op_desc
->
OutputArgumentNames
())
{
*
op
->
output_vars_
=
outputs
;
for
(
auto
output
:
outputs
)
{
const
std
::
string
vname
=
output
->
var_desc_
->
Name
();
framework
::
Variable
*
var
=
scope_
->
Var
(
vname
);
if
(
!
var
->
IsInitialized
())
{
framework
::
VarDesc
*
var_desc
=
block_
->
FindVar
(
vname
);
...
...
@@ -60,6 +66,7 @@ class Tracer {
LOG
(
ERROR
)
<<
"tracer doesn't support yet"
;
}
}
output
->
pre_op_
=
op
;
}
op_base
->
Run
(
*
scope_
,
platform
::
CPUPlace
());
}
...
...
paddle/fluid/pybind/imperative.h
浏览文件 @
4d0df1fe
...
...
@@ -37,6 +37,11 @@ class PyLayer : public imperative::Layer {
}
};
class
PyOpBase
:
public
imperative
::
OpBase
{
public:
using
imperative
::
OpBase
::
OpBase
;
// Inherit constructors
};
void
BindTracer
(
pybind11
::
module
*
m
);
}
// namespace pybind
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
4d0df1fe
...
...
@@ -111,8 +111,9 @@ PYBIND11_MODULE(core, m) {
},
py
::
return_value_policy
::
reference
);
py
::
class_
<
imperative
::
OpBase
>
(
m
,
"OpBase"
,
R"DOC()DOC"
)
py
::
class_
<
imperative
::
OpBase
,
PyOpBase
>
(
m
,
"OpBase"
,
R"DOC()DOC"
)
.
def
(
py
::
init
<>
())
.
def_property
(
"desc"
,
[](
const
imperative
::
OpBase
&
self
)
{
return
self
.
op_desc_
;
},
[](
imperative
::
OpBase
&
self
,
framework
::
OpDesc
*
op_desc
)
{
...
...
python/paddle/fluid/framework.py
浏览文件 @
4d0df1fe
...
...
@@ -563,6 +563,7 @@ class Operator(core.OpBase):
inputs
=
None
,
outputs
=
None
,
attrs
=
None
):
core
.
OpBase
.
__init__
(
self
)
self
.
block
=
block
self
.
desc
=
desc
# note: not add self.attrs here:
...
...
@@ -602,33 +603,32 @@ class Operator(core.OpBase):
return
True
return
False
self
.
inputs
=
[]
if
not
inputs
else
inputs
for
in_proto
in
proto
.
inputs
:
found
=
find_name
(
self
.
inputs
,
in_proto
.
name
)
assert
found
or
in_proto
.
dispensable
,
"Input {} not found"
.
format
(
in_proto
.
name
)
if
found
:
in_args
=
self
.
inputs
[
in_proto
.
name
]
if
not
isinstance
(
in_args
,
list
):
in_args
=
[
in_args
]
if
not
in_proto
.
duplicable
and
len
(
in_args
)
>
1
:
raise
ValueError
(
"Input %s expects only one input, but %d are given."
%
(
in_proto
.
name
,
len
(
in_args
)))
in_arg_names
=
[]
for
arg
in
in_args
:
if
isinstance
(
arg
,
six
.
string_types
):
in_arg_names
.
append
(
arg
)
elif
isinstance
(
arg
,
six
.
binary_type
):
in_arg_names
.
append
(
arg
.
decode
())
else
:
in_arg_names
.
append
(
cpt
.
to_text
(
arg
.
name
))
self
.
desc
.
set_input
(
in_proto
.
name
,
in_arg_names
)
else
:
self
.
desc
.
set_input
(
in_proto
.
name
,
[])
if
inputs
is
not
None
:
for
in_proto
in
proto
.
inputs
:
found
=
find_name
(
inputs
,
in_proto
.
name
)
assert
found
or
in_proto
.
dispensable
,
"Input {} not found"
.
format
(
in_proto
.
name
)
if
found
:
in_args
=
inputs
[
in_proto
.
name
]
if
not
isinstance
(
in_args
,
list
):
in_args
=
[
in_args
]
if
not
in_proto
.
duplicable
and
len
(
in_args
)
>
1
:
raise
ValueError
(
"Input %s expects only one input, but %d are given."
%
(
in_proto
.
name
,
len
(
in_args
)))
in_arg_names
=
[]
for
arg
in
in_args
:
if
isinstance
(
arg
,
six
.
string_types
):
in_arg_names
.
append
(
arg
)
elif
isinstance
(
arg
,
six
.
binary_type
):
in_arg_names
.
append
(
arg
.
decode
())
else
:
in_arg_names
.
append
(
cpt
.
to_text
(
arg
.
name
))
self
.
desc
.
set_input
(
in_proto
.
name
,
in_arg_names
)
else
:
self
.
desc
.
set_input
(
in_proto
.
name
,
[])
self
.
outputs
=
[]
if
not
outputs
else
outputs
if
outputs
is
not
None
:
given
=
set
()
need
=
set
()
...
...
@@ -657,6 +657,21 @@ class Operator(core.OpBase):
arg
.
op
=
self
self
.
desc
.
set_output
(
out_proto
.
name
,
out_arg_names
)
input_vars
=
[]
for
inp
in
inputs
.
values
():
if
isinstance
(
inp
,
Variable
):
input_vars
.
append
(
inp
)
elif
isinstance
(
inp
,
list
):
input_vars
.
extend
(
inp
[:])
self
.
inputs
=
input_vars
output_vars
=
[]
for
out
in
outputs
.
values
():
if
isinstance
(
out
,
Variable
):
output_vars
.
append
(
out
)
elif
isinstance
(
inp
,
list
):
output_vars
.
extend
(
out
[:])
self
.
outputs
=
output_vars
if
op_attrs
is
not
None
:
if
not
isinstance
(
op_attrs
,
dict
):
raise
TypeError
(
"'attrs' should be a dict."
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录