Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
67d03bed
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看板
未验证
提交
67d03bed
编写于
8月 26, 2020
作者:
A
Aurelius84
提交者:
GitHub
8月 26, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix jit.to_static usage (#26682)
上级
cb00d504
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
11 addition
and
11 deletion
+11
-11
python/paddle/fluid/dygraph/dygraph_to_static/ast_transformer.py
...paddle/fluid/dygraph/dygraph_to_static/ast_transformer.py
+1
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/test_assert.py
...le/fluid/tests/unittests/dygraph_to_static/test_assert.py
+2
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/test_bmn.py
...addle/fluid/tests/unittests/dygraph_to_static/test_bmn.py
+3
-3
python/paddle/fluid/tests/unittests/dygraph_to_static/test_dict.py
...ddle/fluid/tests/unittests/dygraph_to_static/test_dict.py
+2
-2
python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py
...dle/fluid/tests/unittests/dygraph_to_static/test_mnist.py
+3
-4
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/ast_transformer.py
浏览文件 @
67d03bed
...
...
@@ -38,7 +38,7 @@ from paddle.fluid.dygraph.dygraph_to_static.utils import get_attribute_full_name
__all__
=
[
'DygraphToStaticAst'
]
DECORATOR_NAMES
=
[
'declarative'
,
'dygraph_to_static_func'
]
DECORATOR_NAMES
=
[
'declarative'
,
'
to_static'
,
'
dygraph_to_static_func'
]
class
DygraphToStaticAst
(
gast
.
NodeTransformer
):
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_assert.py
浏览文件 @
67d03bed
...
...
@@ -17,12 +17,13 @@ from __future__ import print_function
import
numpy
import
unittest
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.dygraph.dygraph_to_static
import
ProgramTranslator
from
paddle.fluid.dygraph.jit
import
declarative
@
declarative
@
paddle
.
jit
.
to_static
def
dyfunc_assert_variable
(
x
):
x_v
=
fluid
.
dygraph
.
to_variable
(
x
)
assert
x_v
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_bmn.py
浏览文件 @
67d03bed
...
...
@@ -15,11 +15,11 @@
import
math
import
numpy
as
np
import
unittest
from
paddle.jit
import
to_static
import
paddle.fluid
as
fluid
from
paddle.fluid
import
ParamAttr
from
paddle.fluid.dygraph
import
to_variable
from
paddle.fluid.dygraph
import
declarative
,
ProgramTranslator
from
paddle.fluid.dygraph
import
ProgramTranslator
from
paddle.fluid.dygraph.io
import
VARIABLE_FILENAME
from
predictor_utils
import
PredictorTools
...
...
@@ -242,7 +242,7 @@ class BMN(fluid.dygraph.Layer):
param_attr
=
ParamAttr
(
name
=
"PEM_2d4_w"
),
bias_attr
=
ParamAttr
(
name
=
"PEM_2d4_b"
))
@
declarative
@
to_static
def
forward
(
self
,
x
):
# Base Module
x
=
self
.
b_conv1
(
x
)
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_dict.py
浏览文件 @
67d03bed
...
...
@@ -19,7 +19,7 @@ import numpy as np
import
unittest
import
paddle.fluid
as
fluid
from
paddle.
fluid.dygraph.jit
import
declarative
from
paddle.
jit
import
to_static
from
paddle.fluid.dygraph.dygraph_to_static.program_translator
import
ProgramTranslator
PLACE
=
fluid
.
CUDAPlace
(
0
)
if
fluid
.
is_compiled_with_cuda
()
else
fluid
.
CPUPlace
(
...
...
@@ -76,7 +76,7 @@ class MainNetWithDict(fluid.dygraph.Layer):
self
.
output_size
=
output_size
self
.
sub_net
=
SubNetWithDict
(
hidden_size
,
output_size
)
@
declarative
@
to_static
def
forward
(
self
,
input
,
max_len
=
4
):
input
=
fluid
.
dygraph
.
to_variable
(
input
)
cache
=
{
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py
浏览文件 @
67d03bed
...
...
@@ -25,7 +25,6 @@ from paddle.fluid.dygraph.base import switch_to_static_graph
from
paddle.fluid.dygraph
import
to_variable
from
paddle.fluid.dygraph.nn
import
Conv2D
,
Linear
,
Pool2D
from
paddle.fluid.optimizer
import
AdamOptimizer
from
paddle.fluid.dygraph.jit
import
declarative
from
paddle.fluid.dygraph.io
import
VARIABLE_FILENAME
from
paddle.fluid.dygraph.dygraph_to_static
import
ProgramTranslator
...
...
@@ -102,7 +101,7 @@ class MNIST(fluid.dygraph.Layer):
loc
=
0.0
,
scale
=
scale
)),
act
=
"softmax"
)
@
declarative
@
paddle
.
jit
.
to_static
def
forward
(
self
,
inputs
,
label
=
None
):
x
=
self
.
inference
(
inputs
)
if
label
is
not
None
:
...
...
@@ -134,7 +133,7 @@ class TestMNIST(unittest.TestCase):
drop_last
=
True
)
class
TestMNISTWith
Declarative
(
TestMNIST
):
class
TestMNISTWith
ToStatic
(
TestMNIST
):
"""
Tests model if doesn't change the layers while decorated
by `dygraph_to_static_output`. In this case, everything should
...
...
@@ -147,7 +146,7 @@ class TestMNISTWithDeclarative(TestMNIST):
def
train_dygraph
(
self
):
return
self
.
train
(
to_static
=
False
)
def
test_mnist_
declarative
(
self
):
def
test_mnist_
to_static
(
self
):
dygraph_loss
=
self
.
train_dygraph
()
static_loss
=
self
.
train_static
()
self
.
assertTrue
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录