Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
55604248
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看板
未验证
提交
55604248
编写于
1月 11, 2021
作者:
A
Aurelius84
提交者:
GitHub
1月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Skip convert tensor shape while using Paddle.shape (#30223) (#30239)
* fix tensor shape bug * fix op_num * clean code
上级
393a91f1
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
33 addition
and
1 deletion
+33
-1
python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py
...uid/dygraph/dygraph_to_static/tensor_shape_transformer.py
+10
-1
python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py
...id/tests/unittests/dygraph_to_static/test_tensor_shape.py
+23
-0
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py
浏览文件 @
55604248
...
...
@@ -188,6 +188,14 @@ class TensorShapeTransformer(gast.NodeTransformer):
return
need_transformed
def
_used_by_paddle_api
(
self
,
node
):
"""
Whether node is used in paddle api as arguments.
For example:
1) Return True in `paddle.relu(x)` where node is `x` (gast.Name)
2) Return True in `paddle.add(self.x)` where node is `self.x` (gast.Attribute)
3) Return False in `paddle.add(self.x)` where node is `paddle.add` (gast.Attribute),
because the role of node is not arguments but `gast.Call.func`.
"""
assert
isinstance
(
node
,
(
gast
.
Attribute
,
gast
.
Name
))
wrapper_node
=
self
.
node_to_wrapper_map
.
get
(
node
)
if
not
wrapper_node
:
...
...
@@ -196,7 +204,8 @@ class TensorShapeTransformer(gast.NodeTransformer):
while
wrapper_node
.
parent
:
parent_node
=
wrapper_node
.
parent
.
node
if
isinstance
(
parent_node
,
gast
.
Call
):
if
is_paddle_api
(
parent_node
):
# Note(Aurelius84): Filter the case when the role of node is `gast.Call.func`.
if
is_paddle_api
(
parent_node
)
and
parent_node
.
func
!=
node
:
return
True
else
:
return
False
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py
浏览文件 @
55604248
...
...
@@ -75,6 +75,17 @@ def dyfunc_tuple_shape_2(x):
return
res
def
dyfunc_paddle_shape_api
(
x
):
x
=
paddle
.
to_tensor
(
x
)
# paddle.shape will not be converted.
a
=
paddle
.
shape
(
x
)[
0
]
# alias api will also not be converted.
alias_old_api
=
paddle
.
fluid
.
layers
b
=
alias_old_api
.
shape
(
x
)[
1
]
res
=
paddle
.
reshape
(
x
,
shape
=
(
b
,
a
))
return
res
def
dyfunc_with_if_1
(
x
):
x
=
fluid
.
dygraph
.
to_variable
(
x
)
res
=
fluid
.
layers
.
reshape
(
x
,
[
-
1
,
1
])
...
...
@@ -283,6 +294,18 @@ class TestTupleShape2(TestTensorShapeBasic):
self
.
dygraph_func
=
dyfunc_tuple_shape_2
class
TestPaddleShapeApi
(
TestTensorShapeBasic
):
def
init_test_func
(
self
):
self
.
input
=
numpy
.
ones
((
5
,
7
)).
astype
(
"int32"
)
self
.
input_spec
=
[
paddle
.
static
.
InputSpec
(
shape
=
[
5
,
7
],
dtype
=
"int32"
)]
self
.
dygraph_func
=
dyfunc_paddle_shape_api
def
_set_expected_op_num
(
self
):
self
.
expected_op_num
=
6
self
.
expected_shape_op_num
=
2
self
.
expected_slice_op_num
=
2
# 2. Tests with control flow if
class
TestTensorShapeInIf1
(
TestTensorShapeBasic
):
def
init_test_func
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录