Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
c2a5f5a8
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看板
提交
c2a5f5a8
编写于
9月 27, 2020
作者:
Z
zhhsplendid
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Temp commit
上级
5ddc395b
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
21 addition
and
24 deletion
+21
-24
python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py
...dle/fluid/dygraph/dygraph_to_static/assert_transformer.py
+1
-2
python/paddle/fluid/dygraph/dygraph_to_static/call_transformer.py
...addle/fluid/dygraph/dygraph_to_static/call_transformer.py
+1
-2
python/paddle/fluid/dygraph/dygraph_to_static/cast_transformer.py
...addle/fluid/dygraph/dygraph_to_static/cast_transformer.py
+1
-1
python/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py
...dle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py
+4
-4
python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py
...addle/fluid/dygraph/dygraph_to_static/list_transformer.py
+1
-1
python/paddle/fluid/dygraph/dygraph_to_static/logical_transformer.py
...le/fluid/dygraph/dygraph_to_static/logical_transformer.py
+2
-2
python/paddle/fluid/dygraph/dygraph_to_static/loop_transformer.py
...addle/fluid/dygraph/dygraph_to_static/loop_transformer.py
+1
-1
python/paddle/fluid/dygraph/dygraph_to_static/print_transformer.py
...ddle/fluid/dygraph/dygraph_to_static/print_transformer.py
+1
-2
python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py
...uid/dygraph/dygraph_to_static/tensor_shape_transformer.py
+1
-1
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
+1
-1
python/paddle/fluid/dygraph/dygraph_to_static/variable_trans_func.py
...le/fluid/dygraph/dygraph_to_static/variable_trans_func.py
+3
-3
python/paddle/fluid/tests/unittests/dygraph_to_static/ifelse_simple_func.py
...d/tests/unittests/dygraph_to_static/ifelse_simple_func.py
+4
-4
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -37,8 +37,7 @@ class AssertTransformer(gast.NodeTransformer):
def
visit_Assert
(
self
,
node
):
convert_assert_node
=
gast
.
parse
(
'paddle.jit.dygraph_to_static.convert_operators.convert_assert({test}, {msg})'
.
format
(
'paddle.jit.dy2static.convert_assert({test}, {msg})'
.
format
(
test
=
ast_to_source_code
(
node
.
test
),
msg
=
ast_to_source_code
(
node
.
msg
)
if
node
.
msg
else
""
)).
body
[
0
].
value
...
...
python/paddle/fluid/dygraph/dygraph_to_static/call_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -70,8 +70,7 @@ class CallTransformer(gast.NodeTransformer):
if
PDB_SET
in
func_str
:
return
node
new_func_str
=
"paddle.jit.dygraph_to_static.convert_call({})"
.
format
(
func_str
)
new_func_str
=
"paddle.jit.dy2static.convert_call({})"
.
format
(
func_str
)
new_func_ast
=
gast
.
parse
(
new_func_str
).
body
[
0
].
value
node
.
func
=
new_func_ast
...
...
python/paddle/fluid/dygraph/dygraph_to_static/cast_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -39,7 +39,7 @@ class CastTransformer(gast.NodeTransformer):
func_str
=
ast_to_source_code
(
node
.
func
).
strip
()
if
func_str
in
self
.
_castable_type
and
len
(
node
.
args
)
>
0
:
args_str
=
ast_to_source_code
(
node
.
args
[
0
]).
strip
()
new_func_str
=
"paddle.jit.dy
graph_to_static.convert_operators
.convert_var_dtype({}, '{}')"
.
format
(
new_func_str
=
"paddle.jit.dy
2static
.convert_var_dtype({}, '{}')"
.
format
(
args_str
,
func_str
)
new_node
=
gast
.
parse
(
new_func_str
).
body
[
0
].
value
return
new_node
...
...
python/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -310,8 +310,8 @@ def parse_cond_return(parent_vars_dict, if_vars_dict, else_vars_dict,
After transformed, q and z are created in parent scope. For example,
x, y = 5, 10
q = paddle.jit.dy
graph_to_static.variable_trans_fun
c.data_layer_not_check(name='q', shape=[-1], dtype='float32')
z = paddle.jit.dy
graph_to_static.variable_trans_fun
c.data_layer_not_check(name='z', shape=[-1], dtype='float32')
q = paddle.jit.dy
2stati
c.data_layer_not_check(name='q', shape=[-1], dtype='float32')
z = paddle.jit.dy
2stati
c.data_layer_not_check(name='z', shape=[-1], dtype='float32')
def true_func(x, y, q):
x = x+1
...
...
@@ -460,7 +460,7 @@ def create_convert_ifelse_node(return_name_ids,
false_func
,
is_if_expr
=
False
):
"""
Create `paddle.jit.dy
graph_to_static.convert_operators
.convert_ifelse(
Create `paddle.jit.dy
2static
.convert_ifelse(
pred, true_fn, false_fn, true_args, false_args, return_vars)`
to replace original `python if/else` statement.
"""
...
...
@@ -491,7 +491,7 @@ def create_convert_ifelse_node(return_name_ids,
return_vars
=
create_name_nodes
(
return_name_ids
)
convert_ifelse_layer
=
gast
.
parse
(
'paddle.jit.dy
graph_to_static.convert_operators
.convert_ifelse('
'paddle.jit.dy
2static
.convert_ifelse('
'{pred}, {true_fn}, {false_fn}, {true_args}, {false_args}, {return_vars})'
.
format
(
pred
=
ast_to_source_code
(
pred
),
...
...
python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -189,7 +189,7 @@ class ListTransformer(gast.NodeTransformer):
elif
isinstance
(
slice_node
,
gast
.
Index
):
value_code
=
ast_to_source_code
(
node
.
value
)
i
=
"paddle.cast("
\
"x=paddle.jit.dy
graph_to_static.variable_trans_fun
c.to_static_variable({}),"
\
"x=paddle.jit.dy
2stati
c.to_static_variable({}),"
\
"dtype='int64')"
.
format
(
ast_to_source_code
(
slice_node
))
assign_code
=
"{} = fluid.layers.array_write(x={}, i={}, array={})"
\
.
format
(
target_name
,
value_code
,
i
,
target_name
)
...
...
python/paddle/fluid/dygraph/dygraph_to_static/logical_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -34,7 +34,7 @@ class LogicalTransformer(gast.NodeTransformer):
self
.
generic_visit
(
node
)
if
isinstance
(
node
.
op
,
gast
.
Not
):
arg
=
ast_to_source_code
(
node
.
operand
)
new_node_str
=
"paddle.jit.dy
graph_to_static.convert_operators
.convert_logical_not({})"
.
format
(
new_node_str
=
"paddle.jit.dy
2static
.convert_logical_not({})"
.
format
(
arg
)
# NOTE: gast.parse returns Module(body=[expr(value=...)])
new_node
=
gast
.
parse
(
new_node_str
).
body
[
0
].
value
...
...
@@ -67,7 +67,7 @@ class LogicalTransformer(gast.NodeTransformer):
nodes
=
[
pre_logic_node
]
+
[
post_logic_node
]
args
=
[
ast_to_source_code
(
child
)
for
child
in
nodes
]
new_node_str
=
"paddle.jit.dy
graph_to_static.convert_operators
.convert_logical_{}(x={}, y={})"
.
format
(
new_node_str
=
"paddle.jit.dy
2static
.convert_logical_{}(x={}, y={})"
.
format
(
api_type
,
args
[
0
],
args
[
1
])
# NOTE: gast.parse return Module(body=[expr(...)])
new_node
=
gast
.
parse
(
new_node_str
).
body
[
0
].
value
...
...
python/paddle/fluid/dygraph/dygraph_to_static/loop_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -46,7 +46,7 @@ def create_while_node(condition_name, body_name, loop_var_names):
# For example: loop_var_names = [a, b, foo.x], the type of `a` or `b` is gast.Name,
# but the type of `foo.x` gast.Attribute.
while_func_name
=
"paddle.jit.dy
graph_to_static.convert_operators
.convert_while_loop"
while_func_name
=
"paddle.jit.dy
2static
.convert_while_loop"
while_node_str
=
"[{}] = {}({}, {}, [{}])"
.
format
(
","
.
join
(
loop_var_names
),
while_func_name
,
condition_name
,
body_name
,
","
.
join
(
loop_var_names
))
...
...
python/paddle/fluid/dygraph/dygraph_to_static/print_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -51,6 +51,5 @@ class PrintTransformer(gast.NodeTransformer):
def
_create_print_node
(
self
,
print_args
):
convert_print_func
=
gast
.
parse
(
'paddle.jit.dygraph_to_static.convert_operators.convert_print'
).
body
[
0
].
value
'paddle.jit.dy2static.convert_print'
).
body
[
0
].
value
return
gast
.
Call
(
func
=
convert_print_func
,
args
=
print_args
,
keywords
=
[])
python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py
浏览文件 @
c2a5f5a8
...
...
@@ -26,7 +26,7 @@ from paddle.fluid.dygraph.dygraph_to_static.static_analysis import StaticAnalysi
def
create_convert_shape_node
(
var_shape_node
):
assert
isinstance
(
var_shape_node
,
(
gast
.
Attribute
,
gast
.
Subscript
))
convert_var_shape_func
=
"paddle.jit.dy
graph_to_static.convert_operators
.convert_var_shape"
convert_var_shape_func
=
"paddle.jit.dy
2static
.convert_var_shape"
if
isinstance
(
var_shape_node
,
gast
.
Attribute
):
api_shape_node
=
gast
.
Call
(
...
...
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
浏览文件 @
c2a5f5a8
...
...
@@ -922,7 +922,7 @@ class ForNodeVisitor(object):
else
:
iter_var_name
=
ast_to_source_code
(
self
.
iter_node
).
strip
()
convert_len_node_source_str
=
'{} = paddle.jit.dy
graph_to_static.convert_operators
.convert_len({})'
.
format
(
convert_len_node_source_str
=
'{} = paddle.jit.dy
2static
.convert_len({})'
.
format
(
self
.
iter_var_len_name
,
iter_var_name
)
convert_len_node
=
gast
.
parse
(
convert_len_node_source_str
).
body
[
0
]
...
...
python/paddle/fluid/dygraph/dygraph_to_static/variable_trans_func.py
浏览文件 @
c2a5f5a8
...
...
@@ -74,13 +74,13 @@ def data_layer_not_check(name, shape, dtype='float32', lod_level=0):
def
to_static_variable_gast_node
(
name
):
func_code
=
"{} = paddle.jit.dy
graph_to_static.variable_trans_func
\
.to_static_variable({})"
.
format
(
name
,
name
)
func_code
=
"{} = paddle.jit.dy
2static.to_static_variable({})"
.
format
(
name
,
name
)
return
gast
.
parse
(
func_code
).
body
[
0
]
def
create_static_variable_gast_node
(
name
):
func_code
=
"{} = paddle.jit.dy
graph_to_static.variable_trans_fun
c
\
func_code
=
"{} = paddle.jit.dy
2stati
c
\
.data_layer_not_check(name='{}', shape=[-1], dtype='float32')"
.
format
(
name
,
name
)
return
gast
.
parse
(
func_code
).
body
[
0
]
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/ifelse_simple_func.py
浏览文件 @
c2a5f5a8
...
...
@@ -59,9 +59,9 @@ def dyfunc_with_if_else3(x):
# The var is created only in one of If.body or If.orelse node, and it used as gast.Load firstly after gast.If node.
# The transformed code:
"""
q = paddle.jit.dy
graph_to_static.variable_trans_fun
c.
q = paddle.jit.dy
2stati
c.
data_layer_not_check(name='q', shape=[-1], dtype='float32')
z = paddle.jit.dy
graph_to_static.variable_trans_fun
c.
z = paddle.jit.dy
2stati
c.
data_layer_not_check(name='z', shape=[-1], dtype='float32')
def true_fn_0(q, x, y):
...
...
@@ -77,8 +77,8 @@ def dyfunc_with_if_else3(x):
n = x + 3
return q, x, y, z
q, x, y, z = fluid.layers.cond(fluid.layers.mean(x)[0] < 5, lambda :
paddle.jit.dy
graph_to_
static.convert_call(true_fn_0)(q, x, y),
lambda : paddle.jit.dy
graph_to_
static.convert_call(false_fn_0)(q,
paddle.jit.dy
2
static.convert_call(true_fn_0)(q, x, y),
lambda : paddle.jit.dy
2
static.convert_call(false_fn_0)(q,
x, y))
"""
y
=
x
+
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录