Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
34735e96
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看板
提交
34735e96
编写于
9月 21, 2020
作者:
Z
zhhsplendid
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix unittest, test=develop
上级
ea2ad88f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
31 deletion
+27
-31
python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py
...uid/tests/unittests/dygraph_to_static/test_origin_info.py
+4
-4
python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py
...ts/unittests/dygraph_to_static/test_program_translator.py
+18
-22
python/paddle/fluid/tests/unittests/dygraph_to_static/test_variable_trans_func.py
...s/unittests/dygraph_to_static/test_variable_trans_func.py
+5
-5
未找到文件。
python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py
浏览文件 @
34735e96
...
...
@@ -65,7 +65,7 @@ class TestOriginInfo(unittest.TestCase):
self
.
func
=
simple_func
def
set_static_lineno
(
self
):
self
.
static_abs_lineno_list
=
[
2
,
3
,
4
]
self
.
static_abs_lineno_list
=
[
3
,
4
,
5
]
def
set_dygraph_info
(
self
):
self
.
line_num
=
3
...
...
@@ -149,7 +149,7 @@ class TestOriginInfoWithNestedFunc(TestOriginInfo):
self
.
func
=
nested_func
def
set_static_lineno
(
self
):
self
.
static_abs_lineno_list
=
[
2
,
4
,
5
,
6
,
7
]
self
.
static_abs_lineno_list
=
[
3
,
5
,
6
,
7
,
8
]
def
set_dygraph_info
(
self
):
self
.
line_num
=
5
...
...
@@ -174,7 +174,7 @@ class TestOriginInfoWithDecoratedFunc(TestOriginInfo):
self
.
func
=
decorated_func
def
set_static_lineno
(
self
):
self
.
static_abs_lineno_list
=
[
2
,
3
]
self
.
static_abs_lineno_list
=
[
3
,
4
]
def
set_dygraph_info
(
self
):
self
.
line_num
=
2
...
...
@@ -208,7 +208,7 @@ class TestOriginInfoWithDecoratedFunc2(TestOriginInfo):
self
.
func
=
decorated_func2
def
set_static_lineno
(
self
):
self
.
static_abs_lineno_list
=
[
2
,
3
]
self
.
static_abs_lineno_list
=
[
3
,
4
]
def
set_dygraph_info
(
self
):
self
.
line_num
=
2
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py
浏览文件 @
34735e96
...
...
@@ -63,11 +63,9 @@ def get_source_code(func):
class
StaticCode1
():
# TODO: Transform return statement
def
dyfunc_with_if_else
(
x_v
,
label
=
None
):
__return_1
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_0
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_value_init_0
=
fluid
.
layers
.
fill_constant
(
__return_1
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_0
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_value_init_0
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'float64'
,
value
=
0.0
)
__return_value_0
=
__return_value_init_0
...
...
@@ -79,13 +77,13 @@ class StaticCode1():
x_v
=
x_v
+
1
return
x_v
x_v
=
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
x_v
=
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
fluid
.
layers
.
mean
(
x_v
)[
0
]
>
5
,
true_fn_0
,
false_fn_0
,
(
x_v
,
),
(
x_v
,
),
(
x_v
,
))
def
true_fn_1
(
__return_0
,
__return_value_0
,
label
,
x_v
):
loss
=
fluid
.
layers
.
cross_entropy
(
x_v
,
label
)
__return_0
=
fluid
.
layers
.
fill_constant
(
__return_0
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
True
)
__return_value_0
=
loss
return
__return_0
,
__return_value_0
...
...
@@ -94,13 +92,13 @@ class StaticCode1():
return
__return_0
,
__return_value_0
__return_0
,
__return_value_0
=
(
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
label
is
not
None
,
true_fn_1
,
false_fn_1
,
(
__return_0
,
__return_value_0
,
label
,
x_v
),
(
__return_0
,
__return_value_0
),
(
__return_0
,
__return_value_0
)))
def
true_fn_2
(
__return_1
,
__return_value_0
,
x_v
):
__return_1
=
fluid
.
layers
.
fill_constant
(
__return_1
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
True
)
__return_value_0
=
x_v
return
__return_1
,
__return_value_0
...
...
@@ -109,8 +107,8 @@ class StaticCode1():
return
__return_1
,
__return_value_0
__return_1
,
__return_value_0
=
(
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_logical_not
(
__return_0
),
true_fn_2
,
false_fn_2
,
(
__return_1
,
__return_value_0
,
x_v
),
(
__return_1
,
__return_value_0
),
(
__return_1
,
__return_value_0
)))
...
...
@@ -120,11 +118,9 @@ class StaticCode1():
class
StaticCode2
():
# TODO: Transform return statement
def
dyfunc_with_if_else
(
x_v
,
label
=
None
):
__return_3
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_2
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_value_init_1
=
fluid
.
layers
.
fill_constant
(
__return_3
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_2
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
False
)
__return_value_init_1
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'float64'
,
value
=
0.0
)
__return_value_1
=
__return_value_init_1
...
...
@@ -136,13 +132,13 @@ class StaticCode2():
x_v
=
x_v
+
1
return
x_v
x_v
=
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
x_v
=
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
fluid
.
layers
.
mean
(
x_v
)[
0
]
>
5
,
true_fn_3
,
false_fn_3
,
(
x_v
,
),
(
x_v
,
),
(
x_v
,
))
def
true_fn_4
(
__return_2
,
__return_value_1
,
label
,
x_v
):
loss
=
fluid
.
layers
.
cross_entropy
(
x_v
,
label
)
__return_2
=
fluid
.
layers
.
fill_constant
(
__return_2
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
True
)
__return_value_1
=
loss
return
__return_2
,
__return_value_1
...
...
@@ -151,13 +147,13 @@ class StaticCode2():
return
__return_2
,
__return_value_1
__return_2
,
__return_value_1
=
(
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
label
is
not
None
,
true_fn_4
,
false_fn_4
,
(
__return_2
,
__return_value_1
,
label
,
x_v
),
(
__return_2
,
__return_value_1
),
(
__return_2
,
__return_value_1
)))
def
true_fn_5
(
__return_3
,
__return_value_1
,
x_v
):
__return_3
=
fluid
.
layers
.
fill_constant
(
__return_3
=
paddle
.
fill_constant
(
shape
=
[
1
],
dtype
=
'bool'
,
value
=
True
)
__return_value_1
=
x_v
return
__return_3
,
__return_value_1
...
...
@@ -166,8 +162,8 @@ class StaticCode2():
return
__return_3
,
__return_value_1
__return_3
,
__return_value_1
=
(
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
fluid
.
dygraph
.
dygraph_to_static
.
convert_operators
.
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_ifelse
(
paddle
.
jit
.
dygraph_to_static
.
convert_operators
.
convert_logical_not
(
__return_2
),
true_fn_5
,
false_fn_5
,
(
__return_3
,
__return_value_1
,
x_v
),
(
__return_3
,
__return_value_1
),
(
__return_3
,
__return_value_1
)))
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_variable_trans_func.py
浏览文件 @
34735e96
...
...
@@ -51,24 +51,24 @@ class TestDataLayerNotCheck(unittest.TestCase):
class
TestVariableTransFunc
(
unittest
.
TestCase
):
def
test_create_fill_constant_node
(
self
):
node
=
create_fill_constant_node
(
"a"
,
1.0
)
source
=
"a =
fluid.layers
.fill_constant(shape=[1], dtype='float64', value=1.0)"
source
=
"a =
paddle
.fill_constant(shape=[1], dtype='float64', value=1.0)"
self
.
assertEqual
(
ast_to_source_code
(
node
).
strip
(),
source
)
node
=
create_fill_constant_node
(
"b"
,
True
)
source
=
"b =
fluid.layers
.fill_constant(shape=[1], dtype='bool', value=True)"
source
=
"b =
paddle
.fill_constant(shape=[1], dtype='bool', value=True)"
self
.
assertEqual
(
ast_to_source_code
(
node
).
strip
(),
source
)
if
six
.
PY2
:
node
=
create_fill_constant_node
(
"c"
,
214
)
source
=
"c =
fluid.layers
.fill_constant(shape=[1], dtype='int32', value=214)"
source
=
"c =
paddle
.fill_constant(shape=[1], dtype='int32', value=214)"
self
.
assertEqual
(
ast_to_source_code
(
node
).
strip
(),
source
)
node
=
create_fill_constant_node
(
"d"
,
long
(
10086
))
source
=
"d =
fluid.layers
.fill_constant(shape=[1], dtype='int64', value=10086)"
source
=
"d =
paddle
.fill_constant(shape=[1], dtype='int64', value=10086)"
self
.
assertEqual
(
ast_to_source_code
(
node
).
strip
(),
source
)
else
:
node
=
create_fill_constant_node
(
"c"
,
4293
)
source
=
"c =
fluid.layers
.fill_constant(shape=[1], dtype='int64', value=4293)"
source
=
"c =
paddle
.fill_constant(shape=[1], dtype='int64', value=4293)"
self
.
assertEqual
(
ast_to_source_code
(
node
).
strip
(),
source
)
self
.
assertIsNone
(
create_fill_constant_node
(
"e"
,
None
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录