Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
4ffd3395
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4ffd3395
编写于
7月 21, 2021
作者:
0
0x45f
提交者:
GitHub
7月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Cherry-pick][Dy2Stat]Support Nest sequtial container (#34246) #34262
* support Nest sequtial container * rename model path
上级
8db945a9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
8 deletion
+32
-8
python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py
...ddle/fluid/dygraph/dygraph_to_static/convert_call_func.py
+1
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/test_container.py
...fluid/tests/unittests/dygraph_to_static/test_container.py
+31
-7
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py
浏览文件 @
4ffd3395
...
@@ -88,7 +88,7 @@ def is_unsupported(func):
...
@@ -88,7 +88,7 @@ def is_unsupported(func):
for
v
in
m
.
__dict__
.
values
():
for
v
in
m
.
__dict__
.
values
():
func_in_dict
=
func
==
v
func_in_dict
=
func
==
v
if
isinstance
(
func_in_dict
,
(
list
,
numpy
.
ndarray
)):
if
isinstance
(
func_in_dict
,
(
list
,
numpy
.
ndarray
)):
func_in_dict
=
any
(
func_in_dict
)
func_in_dict
=
numpy
.
array
(
func_in_dict
).
any
(
)
if
func_in_dict
:
if
func_in_dict
:
translator_logger
.
log
(
translator_logger
.
log
(
2
,
2
,
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_container.py
浏览文件 @
4ffd3395
...
@@ -47,10 +47,30 @@ class SequentialNet(paddle.nn.Layer):
...
@@ -47,10 +47,30 @@ class SequentialNet(paddle.nn.Layer):
return
out
return
out
class
NestSequentialNet
(
paddle
.
nn
.
Layer
):
def
__init__
(
self
):
super
().
__init__
()
group1
=
paddle
.
nn
.
Sequential
(
paddle
.
nn
.
Linear
(
10
,
10
),
paddle
.
nn
.
Sigmoid
(),
)
group2
=
paddle
.
nn
.
Sequential
(
paddle
.
nn
.
Linear
(
10
,
3
),
paddle
.
nn
.
ReLU
(),
)
self
.
layers
=
paddle
.
nn
.
Sequential
(
group1
,
group2
)
def
forward
(
self
,
x
):
return
self
.
layers
(
x
)
class
TestSequential
(
unittest
.
TestCase
):
class
TestSequential
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
paddle
.
set_device
(
'cpu'
)
paddle
.
set_device
(
'cpu'
)
self
.
seed
=
2021
self
.
seed
=
2021
self
.
_init_config
()
def
_init_config
(
self
):
self
.
net
=
SequentialNet
(
BufferLayers
,
10
,
3
)
self
.
model_path
=
'./sequential_net'
def
_init_seed
(
self
):
def
_init_seed
(
self
):
paddle
.
seed
(
self
.
seed
)
paddle
.
seed
(
self
.
seed
)
...
@@ -58,13 +78,12 @@ class TestSequential(unittest.TestCase):
...
@@ -58,13 +78,12 @@ class TestSequential(unittest.TestCase):
def
_run
(
self
,
to_static
):
def
_run
(
self
,
to_static
):
self
.
_init_seed
()
self
.
_init_seed
()
net
=
SequentialNet
(
BufferLayers
,
10
,
3
)
if
to_static
:
if
to_static
:
net
=
paddle
.
jit
.
to_static
(
net
)
self
.
net
=
paddle
.
jit
.
to_static
(
self
.
net
)
x
=
paddle
.
rand
([
16
,
10
],
'float32'
)
x
=
paddle
.
rand
([
16
,
10
],
'float32'
)
out
=
net
(
x
)
out
=
self
.
net
(
x
)
if
to_static
:
if
to_static
:
load_out
=
self
.
_test_load
(
net
,
x
)
load_out
=
self
.
_test_load
(
self
.
net
,
x
)
self
.
assertTrue
(
self
.
assertTrue
(
np
.
allclose
(
load_out
,
out
),
np
.
allclose
(
load_out
,
out
),
msg
=
'load_out is {}\st_out is {}'
.
format
(
load_out
,
out
))
msg
=
'load_out is {}\st_out is {}'
.
format
(
load_out
,
out
))
...
@@ -80,12 +99,17 @@ class TestSequential(unittest.TestCase):
...
@@ -80,12 +99,17 @@ class TestSequential(unittest.TestCase):
msg
=
'dygraph_res is {}
\n
static_res is {}'
.
format
(
dy_out
,
st_out
))
msg
=
'dygraph_res is {}
\n
static_res is {}'
.
format
(
dy_out
,
st_out
))
def
_test_load
(
self
,
net
,
x
):
def
_test_load
(
self
,
net
,
x
):
model_path
=
'./sequential_net'
paddle
.
jit
.
save
(
net
,
self
.
model_path
)
paddle
.
jit
.
save
(
net
,
model_path
)
load_net
=
paddle
.
jit
.
load
(
self
.
model_path
)
load_net
=
paddle
.
jit
.
load
(
model_path
)
out
=
load_net
(
x
)
out
=
load_net
(
x
)
return
out
return
out
class
TestNestSequential
(
TestSequential
):
def
_init_config
(
self
):
self
.
net
=
NestSequentialNet
()
self
.
model_path
=
'./nested_sequential_net'
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录