Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
44db219a
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
44db219a
编写于
11月 19, 2021
作者:
0
0x45f
提交者:
GitHub
11月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dy2stat]Support `for i in [1,2,3]` statements in dy2stat (#37259) (#37356)
该PR使得动转静模块能够正确转换如下的for i in [1, 2, 3]语句。
上级
b5594759
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
43 addition
and
1 deletion
+43
-1
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
+2
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py
...d/tests/unittests/dygraph_to_static/test_for_enumerate.py
+41
-0
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
浏览文件 @
44db219a
...
@@ -1044,7 +1044,8 @@ class ForNodeVisitor(object):
...
@@ -1044,7 +1044,8 @@ class ForNodeVisitor(object):
gast
.
Name
)
and
self
.
node
.
iter
.
func
.
id
==
"range"
gast
.
Name
)
and
self
.
node
.
iter
.
func
.
id
==
"range"
def
is_for_iter
(
self
):
def
is_for_iter
(
self
):
if
isinstance
(
self
.
node
.
iter
,
(
gast
.
Name
,
gast
.
Attribute
)):
if
isinstance
(
self
.
node
.
iter
,
(
gast
.
Name
,
gast
.
Attribute
,
gast
.
List
,
gast
.
Tuple
)):
return
True
return
True
elif
isinstance
(
self
.
node
.
iter
,
gast
.
Call
)
and
isinstance
(
elif
isinstance
(
self
.
node
.
iter
,
gast
.
Call
)
and
isinstance
(
self
.
node
.
iter
.
func
,
self
.
node
.
iter
.
func
,
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py
浏览文件 @
44db219a
...
@@ -304,6 +304,24 @@ class ForwardContainsForLayer(paddle.nn.Layer):
...
@@ -304,6 +304,24 @@ class ForwardContainsForLayer(paddle.nn.Layer):
return
z
return
z
# 21. for original list
@
paddle
.
jit
.
to_static
def
for_original_list
():
z
=
fluid
.
layers
.
fill_constant
([
1
],
'int32'
,
0
)
for
x
in
[
1
,
2
,
3
]:
z
=
z
+
x
return
z
# 22. for original tuple
@
paddle
.
jit
.
to_static
def
for_original_tuple
():
z
=
fluid
.
layers
.
fill_constant
([
1
],
'int32'
,
0
)
for
x
in
(
1
,
2
,
3
):
z
=
z
+
x
return
z
class
TestTransformBase
(
unittest
.
TestCase
):
class
TestTransformBase
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
place
=
fluid
.
CUDAPlace
(
0
)
if
fluid
.
is_compiled_with_cuda
(
self
.
place
=
fluid
.
CUDAPlace
(
0
)
if
fluid
.
is_compiled_with_cuda
(
...
@@ -344,6 +362,13 @@ class TestTransform(TestTransformBase):
...
@@ -344,6 +362,13 @@ class TestTransform(TestTransformBase):
self
.
assertTrue
(
np
.
allclose
(
x
.
numpy
(),
y
.
numpy
()))
self
.
assertTrue
(
np
.
allclose
(
x
.
numpy
(),
y
.
numpy
()))
class
TestTransformForOriginalList
(
TestTransform
):
def
_run
(
self
,
to_static
):
program_translator
.
enable
(
to_static
)
with
fluid
.
dygraph
.
guard
():
return
self
.
dygraph_func
()
class
TestTransformError
(
TestTransformBase
):
class
TestTransformError
(
TestTransformBase
):
def
transformed_error
(
self
,
etype
):
def
transformed_error
(
self
,
etype
):
with
self
.
assertRaises
(
etype
):
with
self
.
assertRaises
(
etype
):
...
@@ -471,5 +496,21 @@ class TestForwardContainsForLayer(TestForIterVarNumpy):
...
@@ -471,5 +496,21 @@ class TestForwardContainsForLayer(TestForIterVarNumpy):
self
.
dygraph_func
=
ForwardContainsForLayer
()
self
.
dygraph_func
=
ForwardContainsForLayer
()
class
TestForOriginalList
(
TestTransformForOriginalList
):
def
set_test_func
(
self
):
self
.
dygraph_func
=
for_original_list
def
test_transformed_result_compare
(
self
):
self
.
transformed_result_compare
()
class
TestForOriginalTuple
(
TestTransformForOriginalList
):
def
set_test_func
(
self
):
self
.
dygraph_func
=
for_original_tuple
def
test_transformed_result_compare
(
self
):
self
.
transformed_result_compare
()
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录