Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
50c43dd3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
50c43dd3
编写于
2月 03, 2023
作者:
R
RedContritio
提交者:
GitHub
2月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix div 0 error of case20: paddle.min (#50013)
上级
97411214
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
77 addition
and
4 deletion
+77
-4
paddle/fluid/operators/reduce_ops/reduce_op.h
paddle/fluid/operators/reduce_ops/reduce_op.h
+29
-2
paddle/phi/kernels/funcs/reduce_function.h
paddle/phi/kernels/funcs/reduce_function.h
+15
-1
paddle/phi/kernels/funcs/reduce_grad_functions.h
paddle/phi/kernels/funcs/reduce_grad_functions.h
+14
-1
paddle/phi/kernels/reduce_min_kernel.cc
paddle/phi/kernels/reduce_min_kernel.cc
+5
-0
python/paddle/fluid/tests/unittests/test_min_op.py
python/paddle/fluid/tests/unittests/test_min_op.py
+14
-0
未找到文件。
paddle/fluid/operators/reduce_ops/reduce_op.h
浏览文件 @
50c43dd3
...
...
@@ -141,8 +141,22 @@ void HandleLargeDim(const framework::ExecutionContext& context,
// transpose to 2D tensor whose shape is {unreduced, reduced}.
const
int64_t
unreduced
=
output
->
numel
();
const
int64_t
reduced
=
shuffled_input
.
numel
()
/
unreduced
;
const
int64_t
input_numel
=
shuffled_input
.
numel
();
// assume: 0 / 0 == 0, which allow process 0 dim tensor
const
int64_t
reduced
=
(
unreduced
!=
0
)
?
(
input_numel
/
unreduced
)
:
0
;
PADDLE_ENFORCE_EQ
(
unreduced
*
reduced
,
input_numel
,
phi
::
errors
::
InvalidArgument
(
"Reducing failed in HandleLargeDim, when try to transpose (%d) "
"operands into 2D tensor with shape (%d, %d)."
,
input_numel
,
unreduced
,
reduced
));
shuffled_input
.
Resize
({
unreduced
,
reduced
});
DDim
output_dim
=
output
->
dims
();
output
->
Resize
({
unreduced
});
paddle
::
operators
::
ReduceFunctor
<
DeviceContext
,
OutT
,
2
,
1
,
Functor
>
(
...
...
@@ -163,7 +177,20 @@ void HandleLargeDimGrad(const framework::ExecutionContext& context,
Functor
functor
,
const
std
::
vector
<
int
>&
dims
)
{
const
int64_t
unreduced
=
out
->
numel
();
const
int64_t
reduced
=
x
->
numel
()
/
unreduced
;
const
int64_t
x_numel
=
x
->
numel
();
// assume: 0 / 0 == 0, which allow process 0 dim tensor
const
int64_t
reduced
=
(
unreduced
!=
0
)
?
(
x_numel
/
unreduced
)
:
0
;
PADDLE_ENFORCE_EQ
(
unreduced
*
reduced
,
x_numel
,
phi
::
errors
::
InvalidArgument
(
"Reducing failed in HandleLargeDimGrad, when try to transpose (%d) "
"operands into 2D tensor with shape (%d, %d)."
,
x_numel
,
unreduced
,
reduced
));
DDim
out_dim
(
out
->
dims
());
DDim
x_dim
(
x
->
dims
());
// transpose and reshape X
...
...
paddle/phi/kernels/funcs/reduce_function.h
浏览文件 @
50c43dd3
...
...
@@ -1228,8 +1228,22 @@ void HandleLargeDim(const DeviceContext& dev_ctx,
// transpose to 2D tensor whose shape is {unreduced, reduced}.
const
int64_t
unreduced
=
output
->
numel
();
const
int64_t
reduced
=
shuffled_input
.
numel
()
/
unreduced
;
const
int64_t
input_numel
=
shuffled_input
.
numel
();
// assume: 0 / 0 == 0, which allow process 0 dim tensor
const
int64_t
reduced
=
(
unreduced
!=
0
)
?
(
input_numel
/
unreduced
)
:
0
;
PADDLE_ENFORCE_EQ
(
unreduced
*
reduced
,
input_numel
,
phi
::
errors
::
InvalidArgument
(
"Reducing failed in HandleLargeDim, when try to transpose (%d) "
"operands into 2D tensor with shape (%d, %d)."
,
input_numel
,
unreduced
,
reduced
));
shuffled_input
.
ResizeAndAllocate
({
unreduced
,
reduced
});
DDim
output_dim
=
output
->
dims
();
output
->
ResizeAndAllocate
({
unreduced
});
ReduceFunctor
<
DeviceContext
,
OutT
,
2
,
1
,
Functor
>
(
...
...
paddle/phi/kernels/funcs/reduce_grad_functions.h
浏览文件 @
50c43dd3
...
...
@@ -87,7 +87,20 @@ void HandleLargeDimGrad(const Context& dev_ctx,
Functor
functor
,
const
std
::
vector
<
int
>&
dims
)
{
const
int64_t
unreduced
=
out
->
numel
();
const
int64_t
reduced
=
x
->
numel
()
/
unreduced
;
const
int64_t
x_numel
=
x
->
numel
();
// assume: 0 / 0 == 0, which allow process 0 dim tensor
const
int64_t
reduced
=
(
unreduced
!=
0
)
?
(
x_numel
/
unreduced
)
:
0
;
PADDLE_ENFORCE_EQ
(
unreduced
*
reduced
,
x_numel
,
phi
::
errors
::
InvalidArgument
(
"Reducing failed in HandleLargeDimGrad, when try to transpose (%d) "
"operands into 2D tensor with shape (%d, %d)."
,
x_numel
,
unreduced
,
reduced
));
DDim
out_dim
(
out
->
dims
());
DDim
x_dim
(
x
->
dims
());
// transpose and reshape X
...
...
paddle/phi/kernels/reduce_min_kernel.cc
浏览文件 @
50c43dd3
...
...
@@ -26,6 +26,11 @@ void MinKernel(const Context& dev_ctx,
bool
keep_dim
,
DenseTensor
*
out
)
{
bool
reduce_all
=
recompute_reduce_all
(
x
,
dims
);
PADDLE_ENFORCE_GT
(
x
.
numel
(),
0
,
errors
::
InvalidArgument
(
"Zero-size tensor to reduction operation minimum "
"which has no identity."
));
MinRawKernel
<
T
>
(
dev_ctx
,
x
,
dims
,
keep_dim
,
reduce_all
,
out
);
}
...
...
python/paddle/fluid/tests/unittests/test_min_op.py
浏览文件 @
50c43dd3
...
...
@@ -20,6 +20,7 @@ from test_sum_op import TestReduceOPTensorAxisBase
import
paddle
import
paddle.fluid.core
as
core
from
paddle
import
fluid
class
ApiMinTest
(
unittest
.
TestCase
):
...
...
@@ -117,5 +118,18 @@ class TestMinWithTensorAxis2(TestReduceOPTensorAxisBase):
self
.
keepdim
=
True
class
TestMinAPIWithEmptyTensor
(
unittest
.
TestCase
):
def
test_empty_tensor
(
self
):
with
fluid
.
dygraph
.
guard
():
with
self
.
assertRaises
(
ValueError
):
data
=
np
.
array
([],
dtype
=
np
.
float32
)
data
=
np
.
reshape
(
data
,
[
0
,
0
,
0
,
0
,
0
,
0
,
0
])
x
=
paddle
.
to_tensor
(
data
,
dtype
=
'float64'
)
np_axis
=
np
.
array
([
0
],
dtype
=
'int64'
)
tensor_axis
=
paddle
.
to_tensor
(
np_axis
,
dtype
=
'int64'
)
out
=
paddle
.
min
(
x
,
tensor_axis
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录