Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e4ba5f86
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
e4ba5f86
编写于
3月 14, 2023
作者:
G
gouzil
提交者:
GitHub
3月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Divide by 0 Error] add DataNormKernel check (#51583)
上级
579fb5fd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
0 deletion
+38
-0
paddle/fluid/operators/data_norm_op.cc
paddle/fluid/operators/data_norm_op.cc
+10
-0
paddle/fluid/operators/data_norm_op.cu
paddle/fluid/operators/data_norm_op.cu
+10
-0
python/paddle/fluid/tests/unittests/test_data_norm_op.py
python/paddle/fluid/tests/unittests/test_data_norm_op.py
+18
-0
未找到文件。
paddle/fluid/operators/data_norm_op.cc
浏览文件 @
e4ba5f86
...
@@ -284,6 +284,16 @@ class DataNormKernel<phi::CPUContext, T> : public framework::OpKernel<T> {
...
@@ -284,6 +284,16 @@ class DataNormKernel<phi::CPUContext, T> : public framework::OpKernel<T> {
const
int
C
=
const
int
C
=
(
data_layout
==
DataLayout
::
kNCHW
?
x_dims
[
1
]
(
data_layout
==
DataLayout
::
kNCHW
?
x_dims
[
1
]
:
x_dims
[
x_dims
.
size
()
-
1
]);
:
x_dims
[
x_dims
.
size
()
-
1
]);
PADDLE_ENFORCE_LT
(
0
,
N
,
platform
::
errors
::
InvalidArgument
(
"The dims of Input(X) should be greater than 0."
));
PADDLE_ENFORCE_LT
(
0
,
C
,
platform
::
errors
::
InvalidArgument
(
"The dims of Input(X) should be greater than 0."
));
auto
*
y
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Y"
);
auto
*
y
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Y"
);
auto
*
mean_out
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Means"
);
auto
*
mean_out
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Means"
);
auto
*
scales
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Scales"
);
auto
*
scales
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Scales"
);
...
...
paddle/fluid/operators/data_norm_op.cu
浏览文件 @
e4ba5f86
...
@@ -114,6 +114,16 @@ class DataNormKernel<phi::GPUContext, T> : public framework::OpKernel<T> {
...
@@ -114,6 +114,16 @@ class DataNormKernel<phi::GPUContext, T> : public framework::OpKernel<T> {
platform
::
errors
::
PreconditionNotMet
(
"The Input dim size should be 2"
));
platform
::
errors
::
PreconditionNotMet
(
"The Input dim size should be 2"
));
const
int
N
=
x_dims
[
0
];
const
int
N
=
x_dims
[
0
];
const
int
C
=
x_dims
[
1
];
const
int
C
=
x_dims
[
1
];
PADDLE_ENFORCE_LT
(
0
,
N
,
platform
::
errors
::
InvalidArgument
(
"The dims of Input(X) should be greater than 0."
));
PADDLE_ENFORCE_LT
(
0
,
C
,
platform
::
errors
::
InvalidArgument
(
"The dims of Input(X) should be greater than 0."
));
const
T
*
batch_size_in
=
const
T
*
batch_size_in
=
ctx
.
Input
<
phi
::
DenseTensor
>
(
"BatchSize"
)
->
data
<
T
>
();
ctx
.
Input
<
phi
::
DenseTensor
>
(
"BatchSize"
)
->
data
<
T
>
();
const
T
*
batch_sum_in
=
ctx
.
Input
<
phi
::
DenseTensor
>
(
"BatchSum"
)
->
data
<
T
>
();
const
T
*
batch_sum_in
=
ctx
.
Input
<
phi
::
DenseTensor
>
(
"BatchSum"
)
->
data
<
T
>
();
...
...
python/paddle/fluid/tests/unittests/test_data_norm_op.py
浏览文件 @
e4ba5f86
...
@@ -19,6 +19,7 @@ import numpy as np
...
@@ -19,6 +19,7 @@ import numpy as np
from
eager_op_test
import
OpTest
from
eager_op_test
import
OpTest
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
import
paddle.fluid.core
as
core
from
paddle.fluid
import
Program
,
program_guard
from
paddle.fluid
import
Program
,
program_guard
from
paddle.fluid.op
import
Operator
from
paddle.fluid.op
import
Operator
...
@@ -538,6 +539,23 @@ class TestDataNormOpErrorr(unittest.TestCase):
...
@@ -538,6 +539,23 @@ class TestDataNormOpErrorr(unittest.TestCase):
x3
=
paddle
.
static
.
data
(
""
,
shape
=
[
0
],
dtype
=
"float32"
)
x3
=
paddle
.
static
.
data
(
""
,
shape
=
[
0
],
dtype
=
"float32"
)
self
.
assertRaises
(
ValueError
,
paddle
.
static
.
nn
.
data_norm
,
x3
)
self
.
assertRaises
(
ValueError
,
paddle
.
static
.
nn
.
data_norm
,
x3
)
# The size of input in data_norm should not be 0.
def
test_0_size
():
paddle
.
enable_static
()
x
=
fluid
.
data
(
name
=
'x'
,
shape
=
[
0
,
3
],
dtype
=
'float32'
)
out
=
paddle
.
static
.
nn
.
data_norm
(
x
,
slot_dim
=
1
)
cpu
=
fluid
.
core
.
CPUPlace
()
exe
=
fluid
.
Executor
(
cpu
)
exe
.
run
(
fluid
.
default_startup_program
())
test_program
=
fluid
.
default_main_program
().
clone
(
for_test
=
True
)
exe
.
run
(
test_program
,
fetch_list
=
out
,
feed
=
{
'x'
:
np
.
ones
([
0
,
3
]).
astype
(
'float32'
)},
)
self
.
assertRaises
(
ValueError
,
test_0_size
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录