Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
44def66a
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看板
未验证
提交
44def66a
编写于
12月 01, 2021
作者:
J
Jiabin Yang
提交者:
GitHub
12月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove cpp layer (#37730)
* optimizer __call__ to make dygraph faster * fix return type * remove cpp Layer
上级
0adc2006
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
6 addition
and
42 deletion
+6
-42
paddle/fluid/imperative/layer.h
paddle/fluid/imperative/layer.h
+0
-10
paddle/fluid/pybind/imperative.cc
paddle/fluid/pybind/imperative.cc
+0
-24
python/paddle/fluid/dygraph/layers.py
python/paddle/fluid/dygraph/layers.py
+3
-3
python/paddle/fluid/tests/unittests/test_imperative_basic.py
python/paddle/fluid/tests/unittests/test_imperative_basic.py
+0
-2
python/paddle/framework/io.py
python/paddle/framework/io.py
+3
-3
未找到文件。
paddle/fluid/imperative/layer.h
浏览文件 @
44def66a
...
@@ -281,16 +281,6 @@ class VarBase {
...
@@ -281,16 +281,6 @@ class VarBase {
static
ThreadSafeNameSet
name_set_
;
static
ThreadSafeNameSet
name_set_
;
};
};
class
Layer
{
public:
virtual
~
Layer
()
{}
virtual
std
::
vector
<
std
::
shared_ptr
<
VarBase
>>
Forward
(
const
std
::
vector
<
std
::
shared_ptr
<
VarBase
>>&
inputs
)
{
return
{};
}
};
std
::
shared_ptr
<
GradOpNode
>
CreateGradOpNode
(
std
::
shared_ptr
<
GradOpNode
>
CreateGradOpNode
(
const
framework
::
OperatorBase
&
op
,
const
NameVarBaseMap
&
ins
,
const
framework
::
OperatorBase
&
op
,
const
NameVarBaseMap
&
ins
,
const
NameVarBaseMap
&
outs
,
const
framework
::
AttributeMap
&
attrs
,
const
NameVarBaseMap
&
outs
,
const
framework
::
AttributeMap
&
attrs
,
...
...
paddle/fluid/pybind/imperative.cc
浏览文件 @
44def66a
...
@@ -59,18 +59,6 @@ PyTypeObject *g_varbase_pytype = nullptr;
...
@@ -59,18 +59,6 @@ PyTypeObject *g_varbase_pytype = nullptr;
namespace
py
=
::
pybind11
;
namespace
py
=
::
pybind11
;
class
Layer
:
public
imperative
::
Layer
{
public:
using
imperative
::
Layer
::
Layer
;
// Inherit constructors
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>
Forward
(
const
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>
&
inputs
)
override
{
PYBIND11_OVERLOAD
(
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>
,
Layer
,
Forward
,
inputs
);
// NOLINT
}
};
template
<
typename
T
>
template
<
typename
T
>
static
T
PyObjectCast
(
PyObject
*
obj
)
{
static
T
PyObjectCast
(
PyObject
*
obj
)
{
try
{
try
{
...
@@ -2051,18 +2039,6 @@ void BindImperative(py::module *m_ptr) {
...
@@ -2051,18 +2039,6 @@ void BindImperative(py::module *m_ptr) {
.
def_property_readonly
(
"type"
,
&
imperative
::
VarBase
::
Type
)
.
def_property_readonly
(
"type"
,
&
imperative
::
VarBase
::
Type
)
.
def_property_readonly
(
"dtype"
,
&
imperative
::
VarBase
::
DataType
);
.
def_property_readonly
(
"dtype"
,
&
imperative
::
VarBase
::
DataType
);
// NOTE(zhiqiu): set the metaclass of Layer.
// See details: https://github.com/pybind/pybind11/pull/679
// https://github.com/pybind/pybind11/blob/028812ae7eee307dca5f8f69d467af7b92cc41c8/tests/test_methods_and_attributes.cpp#L284
py
::
class_
<
imperative
::
Layer
,
Layer
/* <--- trampoline*/
>
layer
(
m
,
"Layer"
,
py
::
metaclass
((
PyObject
*
)
&
PyType_Type
));
// NOLINT
layer
.
def
(
py
::
init
<>
())
.
def
(
"forward"
,
[](
imperative
::
Layer
&
self
,
const
std
::
vector
<
std
::
shared_ptr
<
imperative
::
VarBase
>>
&
inputs
)
{
return
self
.
Forward
(
inputs
);
});
py
::
class_
<
imperative
::
jit
::
ProgramDescTracer
>
(
m
,
"ProgramDescTracer"
,
""
)
py
::
class_
<
imperative
::
jit
::
ProgramDescTracer
>
(
m
,
"ProgramDescTracer"
,
""
)
.
def
(
"create_program_desc"
,
.
def
(
"create_program_desc"
,
&
imperative
::
jit
::
ProgramDescTracer
::
CreateProgramDesc
)
&
imperative
::
jit
::
ProgramDescTracer
::
CreateProgramDesc
)
...
...
python/paddle/fluid/dygraph/layers.py
浏览文件 @
44def66a
...
@@ -78,7 +78,7 @@ class HookRemoveHelper(object):
...
@@ -78,7 +78,7 @@ class HookRemoveHelper(object):
del
hooks
[
self
.
_hook_id
]
del
hooks
[
self
.
_hook_id
]
class
Layer
(
core
.
Layer
):
class
Layer
(
object
):
"""
"""
Dynamic graph Layer based on OOD, includes the parameters of the layer, the structure of the forward graph and so on.
Dynamic graph Layer based on OOD, includes the parameters of the layer, the structure of the forward graph and so on.
...
@@ -976,7 +976,7 @@ class Layer(core.Layer):
...
@@ -976,7 +976,7 @@ class Layer(core.Layer):
for prefix, layer in model.named_sublayers():
for prefix, layer in model.named_sublayers():
print(prefix, layer)
print(prefix, layer)
"""
"""
assert
(
isinstance
(
sublayer
,
core
.
Layer
)
or
sublayer
==
None
)
assert
(
isinstance
(
sublayer
,
Layer
)
or
sublayer
==
None
)
self
.
_sub_layers
[
name
]
=
sublayer
self
.
_sub_layers
[
name
]
=
sublayer
return
sublayer
return
sublayer
...
@@ -1143,7 +1143,7 @@ class Layer(core.Layer):
...
@@ -1143,7 +1143,7 @@ class Layer(core.Layer):
params
[
name
]
=
None
params
[
name
]
=
None
else
:
else
:
layers
=
self
.
__dict__
.
get
(
'_sub_layers'
,
None
)
layers
=
self
.
__dict__
.
get
(
'_sub_layers'
,
None
)
if
isinstance
(
value
,
core
.
Layer
):
if
isinstance
(
value
,
Layer
):
if
layers
is
None
:
if
layers
is
None
:
raise
ValueError
(
raise
ValueError
(
"super(YourLayer, self).__init__() should be called first"
"super(YourLayer, self).__init__() should be called first"
...
...
python/paddle/fluid/tests/unittests/test_imperative_basic.py
浏览文件 @
44def66a
...
@@ -400,8 +400,6 @@ class TestImperative(unittest.TestCase):
...
@@ -400,8 +400,6 @@ class TestImperative(unittest.TestCase):
def
test_layer
(
self
):
def
test_layer
(
self
):
with
fluid
.
dygraph
.
guard
():
with
fluid
.
dygraph
.
guard
():
cl
=
core
.
Layer
()
cl
.
forward
([])
l
=
fluid
.
Layer
(
"l"
)
l
=
fluid
.
Layer
(
"l"
)
self
.
assertRaises
(
NotImplementedError
,
l
.
forward
,
[])
self
.
assertRaises
(
NotImplementedError
,
l
.
forward
,
[])
...
...
python/paddle/framework/io.py
浏览文件 @
44def66a
...
@@ -253,7 +253,7 @@ def _pickle_save(obj, f, protocol):
...
@@ -253,7 +253,7 @@ def _pickle_save(obj, f, protocol):
dispatch_table_layer
[
layer
.
__class__
]
=
reduce_Layer
dispatch_table_layer
[
layer
.
__class__
]
=
reduce_Layer
return
layer
return
layer
_parse_every_object
(
obj
,
lambda
v
:
isinstance
(
v
,
core
.
Layer
),
_parse_every_object
(
obj
,
lambda
v
:
isinstance
(
v
,
fluid
.
Layer
),
create_layer_dispatch_table
)
create_layer_dispatch_table
)
def
add_dispatch_table
():
def
add_dispatch_table
():
...
@@ -316,7 +316,7 @@ def _is_state_dict(obj):
...
@@ -316,7 +316,7 @@ def _is_state_dict(obj):
if
isinstance
(
obj
,
dict
):
if
isinstance
(
obj
,
dict
):
def
condition
(
obj
):
def
condition
(
obj
):
return
isinstance
(
obj
,
(
core
.
Layer
,
Program
,
core
.
VarBase
,
return
isinstance
(
obj
,
(
fluid
.
Layer
,
Program
,
core
.
VarBase
,
core
.
LoDTensor
,
core
.
SelectedRows
))
core
.
LoDTensor
,
core
.
SelectedRows
))
# If the value of a dict is a core.VarBase/LoDTensor or a dict
# If the value of a dict is a core.VarBase/LoDTensor or a dict
...
@@ -422,7 +422,7 @@ def _parse_every_object(obj, condition_func, convert_func):
...
@@ -422,7 +422,7 @@ def _parse_every_object(obj, condition_func, convert_func):
def
_parse_load_result
(
obj
,
return_numpy
):
def
_parse_load_result
(
obj
,
return_numpy
):
def
is_layer
(
obj
):
def
is_layer
(
obj
):
return
isinstance
(
obj
,
core
.
Layer
)
return
isinstance
(
obj
,
fluid
.
Layer
)
def
parse_layer
(
obj
):
def
parse_layer
(
obj
):
temp_dict
=
_parse_load_result
(
obj
.
__dict__
,
False
)
temp_dict
=
_parse_load_result
(
obj
.
__dict__
,
False
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录