Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
5e0dde02
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5e0dde02
编写于
9月 11, 2020
作者:
A
Aurelius84
提交者:
GitHub
9月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dy2stat] support usage: to_static(model) (#27040)
* support to_static(model) * add warning and unittest
上级
1b84c0bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
1 deletion
+36
-1
python/paddle/fluid/dygraph/jit.py
python/paddle/fluid/dygraph/jit.py
+10
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/test_declarative.py
...uid/tests/unittests/dygraph_to_static/test_declarative.py
+26
-0
未找到文件。
python/paddle/fluid/dygraph/jit.py
浏览文件 @
5e0dde02
...
@@ -212,7 +212,16 @@ def declarative(function=None, input_spec=None):
...
@@ -212,7 +212,16 @@ def declarative(function=None, input_spec=None):
# for usage: `declarative(foo, ...)`
# for usage: `declarative(foo, ...)`
if
function
is
not
None
:
if
function
is
not
None
:
return
decorated
(
function
)
if
isinstance
(
function
,
Layer
):
if
isinstance
(
function
.
forward
,
StaticLayer
):
class_name
=
function
.
__class__
.
__name__
warnings
.
warn
(
"`{}.forward` has already been decorated somewhere. It will be redecorated to replace previous one."
.
format
(
class_name
))
function
.
forward
=
decorated
(
function
.
forward
)
return
function
else
:
return
decorated
(
function
)
# for usage: `@declarative`
# for usage: `@declarative`
return
decorated
return
decorated
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_declarative.py
浏览文件 @
5e0dde02
...
@@ -332,5 +332,31 @@ class TestDeclarativeAPI(unittest.TestCase):
...
@@ -332,5 +332,31 @@ class TestDeclarativeAPI(unittest.TestCase):
func
(
np
.
ones
(
5
).
astype
(
"int32"
))
func
(
np
.
ones
(
5
).
astype
(
"int32"
))
class
TestDecorateModelDirectly
(
unittest
.
TestCase
):
def
setUp
(
self
):
paddle
.
disable_static
()
program_trans
.
enable
(
True
)
self
.
x
=
to_variable
(
np
.
ones
([
4
,
10
]).
astype
(
'float32'
))
def
test_fake_input
(
self
):
net
=
SimpleNet
()
net
=
declarative
(
net
)
y
=
net
(
self
.
x
)
self
.
assertTrue
(
len
(
net
.
forward
.
program_cache
)
==
1
)
def
test_input_spec
(
self
):
net
=
SimpleNet
()
net
=
declarative
(
net
,
input_spec
=
[
InputSpec
([
None
,
8
,
10
])])
self
.
assertTrue
(
len
(
net
.
forward
.
inputs
)
==
1
)
self
.
assertTrue
(
len
(
net
.
forward
.
program_cache
)
==
1
)
input_shape
=
net
.
forward
.
inputs
[
0
].
shape
self
.
assertListEqual
(
list
(
input_shape
),
[
-
1
,
8
,
10
])
# redecorate
net
=
declarative
(
net
,
input_spec
=
[
InputSpec
([
None
,
16
,
10
])])
input_shape
=
net
.
forward
.
inputs
[
0
].
shape
self
.
assertListEqual
(
list
(
input_shape
),
[
-
1
,
16
,
10
])
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录