Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f8d02146
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f8d02146
编写于
6月 27, 2023
作者:
C
Charles-hit
提交者:
GitHub
6月 27, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support zero_dim for some prim ops (#54892)
上级
abc1c3d4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
46 addition
and
5 deletion
+46
-5
python/paddle/incubate/autograd/composite_rules.py
python/paddle/incubate/autograd/composite_rules.py
+2
-0
test/legacy_test/test_activation_op.py
test/legacy_test/test_activation_op.py
+6
-1
test/legacy_test/test_reduce_op.py
test/legacy_test/test_reduce_op.py
+24
-4
test/legacy_test/test_squeeze2_op.py
test/legacy_test/test_squeeze2_op.py
+14
-0
未找到文件。
python/paddle/incubate/autograd/composite_rules.py
浏览文件 @
f8d02146
...
...
@@ -554,6 +554,8 @@ def squeeze2_composite(x, axis):
axis can only be list, not int
"""
rank
=
len
(
x
.
shape
)
if
rank
==
0
:
return
[
assign
(
x
),
None
]
if
len
(
axis
)
==
0
:
dims
=
set
(
range
(
rank
))
else
:
...
...
test/legacy_test/test_activation_op.py
浏览文件 @
f8d02146
...
...
@@ -1385,6 +1385,11 @@ class TestSqrtCompFp32(TestActivation):
self
.
dtype
=
np
.
float32
class
TestSqrtComp_ZeroDim
(
TestSqrtComp
):
def
init_shape
(
self
):
self
.
shape
=
[]
class
TestRsqrt
(
TestActivation
):
def
setUp
(
self
):
self
.
op_type
=
"rsqrt"
...
...
@@ -2029,7 +2034,7 @@ class TestLeakyRelu_ZeroDim(TestLeakyRelu):
self
.
shape
=
[]
def
if_enable_cinn
(
self
):
self
.
enable_cinn
=
False
pass
class
TestLeakyReluAPI
(
unittest
.
TestCase
):
...
...
test/legacy_test/test_reduce_op.py
浏览文件 @
f8d02146
...
...
@@ -584,10 +584,7 @@ class TestProdOp_ZeroDim(OpTest):
self
.
public_python_api
=
raw_reduce_prod
self
.
op_type
=
"reduce_prod"
self
.
prim_op_type
=
"prim"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
([]).
astype
(
"float64"
)}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
prod
()}
self
.
attrs
=
{
'dim'
:
[],
'reduce_all'
:
True
}
self
.
init_inputs_and_outputs
()
# 0-D tensor doesn't support in cinn
self
.
enable_cinn
=
False
...
...
@@ -603,6 +600,29 @@ class TestProdOp_ZeroDim(OpTest):
self
.
check_grad
([
'X'
],
'Out'
,
check_prim
=
True
)
class
TestProdOp_ZeroDim1
(
TestProdOp
):
def
setUp
(
self
):
self
.
python_api
=
paddle
.
prod
self
.
public_python_api
=
paddle
.
prod
self
.
op_type
=
"reduce_prod"
self
.
prim_op_type
=
"prim"
self
.
init_inputs_and_outputs
()
# 0-D tensor doesn't support in cinn
self
.
enable_cinn
=
False
def
init_inputs_and_outputs
(
self
):
self
.
inputs
=
{
'X'
:
np
.
random
.
random
([
100
]).
astype
(
"float64"
)}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
prod
()}
self
.
attrs
=
{
'dim'
:
[],
'reduce_all'
:
True
}
class
TestProdOp_ZeroDim2
(
TestProdOp_ZeroDim1
):
def
init_inputs_and_outputs
(
self
):
self
.
inputs
=
{
'X'
:
np
.
random
.
random
([
5
,
6
,
10
]).
astype
(
"float64"
)}
self
.
outputs
=
{
'Out'
:
self
.
inputs
[
'X'
].
prod
()}
self
.
attrs
=
{
'dim'
:
[],
'reduce_all'
:
True
}
class
TestProd6DOp
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"reduce_prod"
...
...
test/legacy_test/test_squeeze2_op.py
浏览文件 @
f8d02146
...
...
@@ -100,6 +100,20 @@ class TestSqueezeOp1BF16Op(TestSqueezeOp):
self
.
dtype
=
np
.
uint16
class
TestSqueezeOp_ZeroDim1
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
()
self
.
axes
=
(
0
,)
self
.
new_shape
=
()
class
TestSqueezeOp_ZeroDim2
(
TestSqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
1
,
1
,
1
)
self
.
axes
=
(
0
,
1
,
2
)
self
.
new_shape
=
()
# Correct: No axes input.
class
TestSqueezeOp2
(
TestSqueezeOp
):
def
setUp
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录