Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
573d2faa
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看板
未验证
提交
573d2faa
编写于
3月 24, 2020
作者:
L
liym27
提交者:
GitHub
3月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug in function `is_to_variable`. test=develop (#23147)
上级
23baf865
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
21 addition
and
7 deletion
+21
-7
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
+9
-2
python/paddle/fluid/tests/unittests/dygraph_to_static/test_basic_api_transformation.py
...ttests/dygraph_to_static/test_basic_api_transformation.py
+12
-5
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
浏览文件 @
573d2faa
...
...
@@ -45,8 +45,15 @@ def is_api_in_module(node, module_prefix):
assert
isinstance
(
node
,
gast
.
Call
),
"Input non-Call node for is_dygraph_api"
func_str
=
astor
.
to_source
(
gast
.
gast_to_ast
(
node
.
func
))
try
:
# TODO(liym27):
# Consider a better to import modules like:
# source_file = inspect.getfile(dyfunc)
# import_statements = ImportVisitor(source_file).transform()
# import_str = "".join(import_statements)
import
paddle.fluid
as
fluid
import
paddle
from
paddle.fluid.dygraph
import
to_variable
import
paddle.fluid.dygraph
as
dygraph
return
eval
(
"_is_api_in_module_helper({}, '{}')"
.
format
(
func_str
,
module_prefix
))
except
NameError
:
...
...
@@ -148,8 +155,8 @@ def _add_keywords_to(node, dygraph_api_name):
def
is_to_variable
(
node
):
assert
isinstance
(
node
,
gast
.
Call
)
if
is_dygraph_api
(
node
):
api_name
=
node
.
func
.
attr
return
api_name
==
"to_variable"
api_name
=
ast_to_source_code
(
node
.
func
).
strip
()
return
api_name
.
endswith
(
"to_variable"
)
return
False
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_basic_api_transformation.py
浏览文件 @
573d2faa
...
...
@@ -15,11 +15,13 @@
from
__future__
import
print_function
import
numpy
as
np
import
paddle.fluid
as
fluid
import
unittest
import
inspect
import
gast
import
paddle.fluid
as
fluid
import
paddle.fluid.dygraph
as
dygraph
from
paddle.fluid.dygraph
import
to_variable
from
paddle.fluid.dygraph.jit
import
dygraph_to_static_graph
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
is_dygraph_api
...
...
@@ -33,14 +35,21 @@ def dyfunc_to_variable(x):
def
dyfunc_to_variable_2
(
x
):
res
=
fluid
.
dygraph
.
to_variable
(
value
=
np
.
zeros
(
shape
=
(
1
),
dtype
=
np
.
int32
))
res
=
dygraph
.
to_variable
(
value
=
np
.
zeros
(
shape
=
(
1
),
dtype
=
np
.
int32
))
return
res
def
dyfunc_to_variable_3
(
x
):
res
=
to_variable
(
x
,
name
=
None
,
zero_copy
=
None
)
return
res
class
TestDygraphBasicApi_ToVariable
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
input
=
np
.
ones
(
5
).
astype
(
"int32"
)
self
.
test_funcs
=
[
dyfunc_to_variable
,
dyfunc_to_variable_2
]
self
.
test_funcs
=
[
dyfunc_to_variable
,
dyfunc_to_variable_2
,
dyfunc_to_variable_3
]
self
.
place
=
fluid
.
CUDAPlace
(
0
)
if
fluid
.
is_compiled_with_cuda
(
)
else
fluid
.
CPUPlace
()
...
...
@@ -72,8 +81,6 @@ class TestDygraphBasicApi_ToVariable(unittest.TestCase):
# 1. test Apis that inherit from layers.Layer
def
dyfunc_BilinearTensorProduct
(
layer1
,
layer2
):
bilinearTensorProduct
=
fluid
.
dygraph
.
nn
.
BilinearTensorProduct
(
input1_dim
=
5
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录