Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
633aaea0
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
633aaea0
编写于
5月 13, 2020
作者:
C
ceci3
提交者:
GitHub
5月 13, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update err message (#24422)
* update err info, test=develop * update, test=develop
上级
d0ef9479
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
128 addition
and
41 deletion
+128
-41
paddle/fluid/operators/batch_norm_op.cc
paddle/fluid/operators/batch_norm_op.cc
+27
-13
paddle/fluid/operators/batch_norm_op.cu
paddle/fluid/operators/batch_norm_op.cu
+54
-10
paddle/fluid/operators/dropout_op.h
paddle/fluid/operators/dropout_op.h
+3
-2
paddle/fluid/operators/instance_norm_op.cc
paddle/fluid/operators/instance_norm_op.cc
+8
-4
paddle/fluid/operators/instance_norm_op.cu
paddle/fluid/operators/instance_norm_op.cu
+36
-12
未找到文件。
paddle/fluid/operators/batch_norm_op.cc
浏览文件 @
633aaea0
...
...
@@ -62,7 +62,9 @@ void BatchNormOp::InferShape(framework::InferShapeContext *ctx) const {
auto
mom
=
ctx
->
Inputs
(
"MomentumTensor"
);
PADDLE_ENFORCE_EQ
(
mom
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"Input(MomentumTensor) size must be 1"
));
"The input tensor MomentumTensor's size must be 1"
"But received: MomentumTensor's size is [%d]"
,
mom
.
size
()));
}
PADDLE_ENFORCE_GE
(
...
...
@@ -298,12 +300,18 @@ class BatchNormKernel<platform::CPUDeviceContext, T>
const
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
const
auto
&
x_dims
=
x
->
dims
();
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
platform
::
errors
::
InvalidArgument
(
"The Input X dim size should be larger than 1."
));
PADDLE_ENFORCE_LE
(
x_dims
.
size
(),
5
,
"The size of input X's dimensions should be larger than 1."
"But received: the size of input X's dimensions is [%d]"
,
x_dims
.
size
()));
PADDLE_ENFORCE_LE
(
x_dims
.
size
(),
5
,
platform
::
errors
::
InvalidArgument
(
"The Input X dim size should be less than 6."
));
"The size of input X's dimensions should be less than 6."
"But received: the size of input X's dimensionss is [%d]"
,
x_dims
.
size
()));
const
int
N
=
x_dims
[
0
];
const
int
C
=
(
data_layout
==
DataLayout
::
kNCHW
?
x_dims
[
1
]
...
...
@@ -606,12 +614,18 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
// Get the size for each dimension.
// NCHW [batch_size, in_channels, in_height, in_width]
const
auto
&
x_dims
=
x
->
dims
();
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
platform
::
errors
::
InvalidArgument
(
"The Input X dim size should be larger than 1."
));
PADDLE_ENFORCE_LE
(
x_dims
.
size
(),
5
,
"The size of input X's dimensions should be larger than 1."
"But received: the size of input X's dimensions is [%d]"
,
x_dims
.
size
()));
PADDLE_ENFORCE_LE
(
x_dims
.
size
(),
5
,
platform
::
errors
::
InvalidArgument
(
"The Input X dim size should be less than 6."
));
"The size of input X's dimensions should be less than 6."
"But received: the size of input X's dimensions is [%d]"
,
x_dims
.
size
()));
const
int
N
=
x_dims
[
0
];
const
int
C
=
(
data_layout
==
DataLayout
::
kNCHW
?
x_dims
[
1
]
...
...
paddle/fluid/operators/batch_norm_op.cu
浏览文件 @
633aaea0
...
...
@@ -58,8 +58,12 @@ class BatchNormKernel<platform::CUDADeviceContext, T>
// NCHW [batch_size, in_channels, in_height, in_width]
const
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
const
auto
&
x_dims
=
x
->
dims
();
PADDLE_ENFORCE
(
x_dims
.
size
()
>=
2
&&
x_dims
.
size
()
<=
5
,
"The Input dim size should be between 2 and 5"
);
PADDLE_ENFORCE_EQ
(
x_dims
.
size
()
>=
2
&&
x_dims
.
size
()
<=
5
,
true
,
platform
::
errors
::
InvalidArgument
(
"The size of input's dimensions should be between 2 and 5"
"But received: the size of input's dimensions is [%d]"
,
x_dims
.
size
()));
auto
*
y
=
ctx
.
Output
<
Tensor
>
(
"Y"
);
y
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
...
@@ -151,10 +155,34 @@ class BatchNormKernel<platform::CUDADeviceContext, T>
const
auto
*
est_mean
=
ctx
.
Input
<
Tensor
>
(
"Mean"
);
const
auto
*
est_var
=
ctx
.
Input
<
Tensor
>
(
"Variance"
);
// Run inference mode.
PADDLE_ENFORCE_EQ
(
est_mean
->
dims
().
size
(),
1UL
);
PADDLE_ENFORCE_EQ
(
est_var
->
dims
().
size
(),
1UL
);
PADDLE_ENFORCE_EQ
(
est_mean
->
dims
()[
0
],
C
);
PADDLE_ENFORCE_EQ
(
est_var
->
dims
()[
0
],
C
);
PADDLE_ENFORCE_EQ
(
est_mean
->
dims
().
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"The size of mean's dimensions must equal to 1."
"But received: the size of mean's dimensions mean is [%d],"
"the dimensions of mean is [%s]."
,
est_mean
->
dims
().
size
(),
est_mean
->
dims
()));
PADDLE_ENFORCE_EQ
(
est_var
->
dims
().
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"The size of variance's dimensions must equal to 1."
"But received: the size of variance's dimensions is [%d],"
"the dimensions of variance is [%s]."
,
est_var
->
dims
().
size
(),
est_var
->
dims
()));
PADDLE_ENFORCE_EQ
(
est_mean
->
dims
()[
0
],
C
,
platform
::
errors
::
InvalidArgument
(
"The first dimension of mean must equal to the number of "
"Channels, which is [%d]. But received: the first dimension"
"of mean is [%d], the dimensions of mean is [%s]."
,
C
,
est_mean
->
dims
()[
0
],
est_mean
->
dims
()));
PADDLE_ENFORCE_EQ
(
est_var
->
dims
()[
0
],
C
,
platform
::
errors
::
InvalidArgument
(
"The first dimension of variance must equal to the number"
"of Channels, which is [%d]. But received: the first dimension of"
"variance is [%d], the dimensions of variance is [%s]."
,
C
,
est_var
->
dims
()[
0
],
est_var
->
dims
()));
PADDLE_ENFORCE_CUDA_SUCCESS
(
platform
::
dynload
::
cudnnBatchNormalizationForwardInference
(
...
...
@@ -503,8 +531,13 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
const
auto
&
x_dims
=
x
->
dims
();
PADDLE_ENFORCE
(
x_dims
.
size
()
>=
2
&&
x_dims
.
size
()
<=
5
,
"The Input dim size should be between 2 and 5"
);
PADDLE_ENFORCE_EQ
(
x_dims
.
size
()
>=
2
&&
x_dims
.
size
()
<=
5
,
true
,
platform
::
errors
::
InvalidArgument
(
"The size of input's dimensions should be between 2 and 5."
"But received: the size of input's dimensions is [%d],"
"the dimensions of input is [%s]"
,
x_dims
.
size
(),
x_dims
));
int
N
,
C
,
H
,
W
,
D
;
ExtractNCWHD
(
x_dims
,
data_layout
,
&
N
,
&
C
,
&
H
,
&
W
,
&
D
);
...
...
@@ -515,8 +548,19 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
d_scale
->
mutable_data
<
BatchNormParamType
<
T
>>
(
ctx
.
GetPlace
());
d_bias
->
mutable_data
<
BatchNormParamType
<
T
>>
(
ctx
.
GetPlace
());
}
PADDLE_ENFORCE_EQ
(
scale
->
dims
().
size
(),
1UL
);
PADDLE_ENFORCE_EQ
(
scale
->
dims
()[
0
],
C
);
PADDLE_ENFORCE_EQ
(
scale
->
dims
().
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"The size of scale's dimensions must equal to 1. But received: "
"the size of scale's dimensions is [%d], the dimensions of scale "
"is [%s]."
,
scale
->
dims
().
size
(),
scale
->
dims
()));
PADDLE_ENFORCE_EQ
(
scale
->
dims
()[
0
],
C
,
platform
::
errors
::
InvalidArgument
(
"The first dimension of scale must equal to Channels[%d]. But "
"received: the first dimension of scale is [%d]"
,
C
,
scale
->
dims
()[
0
]));
auto
dtype
=
platform
::
CudnnDataType
<
T
>::
type
;
const
auto
*
reserve_space
=
ctx
.
Input
<
Tensor
>
(
"ReserveSpace"
);
...
...
paddle/fluid/operators/dropout_op.h
浏览文件 @
633aaea0
...
...
@@ -108,8 +108,9 @@ template <typename DeviceContext, typename T>
class
DropoutGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
PADDLE_ENFORCE
(
!
context
.
Attr
<
bool
>
(
"is_test"
),
"GradOp is only callable when is_test is false"
);
PADDLE_ENFORCE_EQ
(
!
context
.
Attr
<
bool
>
(
"is_test"
),
true
,
platform
::
errors
::
PreconditionNotMet
(
"GradOp is only callable when is_test is false"
));
auto
*
grad_x
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
grad_y
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
...
...
paddle/fluid/operators/instance_norm_op.cc
浏览文件 @
633aaea0
...
...
@@ -247,7 +247,8 @@ framework::OpKernelType InstanceNormGradOp::GetExpectedKernelType(
const
framework
::
ExecutionContext
&
ctx
)
const
{
const
auto
*
var
=
ctx
.
InputVar
(
framework
::
GradVarName
(
"Y"
));
if
(
var
==
nullptr
)
{
PADDLE_THROW
(
"cannot find Y@GRAD"
);
PADDLE_THROW
(
platform
::
errors
::
NotFound
(
"cannot find gradient variable of Y"
));
}
const
Tensor
*
t
=
nullptr
;
if
(
var
->
IsType
<
Tensor
>
())
{
...
...
@@ -256,7 +257,8 @@ framework::OpKernelType InstanceNormGradOp::GetExpectedKernelType(
t
=
&
var
->
Get
<
LoDTensor
>
();
}
if
(
t
==
nullptr
)
{
PADDLE_THROW
(
"cannot find Y@GRAD"
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"gradient variable of Y is empty"
));
}
return
framework
::
OpKernelType
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"X"
),
ctx
.
GetPlace
());
...
...
@@ -387,7 +389,8 @@ framework::OpKernelType InstanceNormDoubleGradOp::GetExpectedKernelType(
const
framework
::
ExecutionContext
&
ctx
)
const
{
const
auto
*
var
=
ctx
.
InputVar
(
"DY"
);
if
(
var
==
nullptr
)
{
PADDLE_THROW
(
"cannot find Y@GRAD"
);
PADDLE_THROW
(
platform
::
errors
::
NotFound
(
"cannot find gradient variable of Y"
));
}
const
Tensor
*
t
=
nullptr
;
if
(
var
->
IsType
<
Tensor
>
())
{
...
...
@@ -396,7 +399,8 @@ framework::OpKernelType InstanceNormDoubleGradOp::GetExpectedKernelType(
t
=
&
var
->
Get
<
LoDTensor
>
();
}
if
(
t
==
nullptr
)
{
PADDLE_THROW
(
"cannot find Y@GRAD"
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"gradient variable of Y is empty"
));
}
return
framework
::
OpKernelType
(
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"X"
),
ctx
.
GetPlace
());
...
...
paddle/fluid/operators/instance_norm_op.cu
浏览文件 @
633aaea0
...
...
@@ -70,18 +70,27 @@ class InstanceNormKernel<platform::CUDADeviceContext, T>
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
platform
::
is_gpu_place
(
ctx
.
GetPlace
()),
true
,
"It must be CUDAPlace."
);
PADDLE_ENFORCE_EQ
(
platform
::
is_gpu_place
(
ctx
.
GetPlace
()),
true
,
platform
::
errors
::
PreconditionNotMet
(
"It must be CUDAPlace."
));
double
epsilon
=
static_cast
<
double
>
(
ctx
.
Attr
<
float
>
(
"epsilon"
));
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
auto
&
x_dims
=
x
->
dims
();
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
"the dimension of input X must greater than or equal to 2"
);
PADDLE_ENFORCE_LE
(
x_dims
.
size
(),
5
,
"the dimension of input X must smaller than or equal to 5"
);
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
platform
::
errors
::
InvalidArgument
(
"The `shape` in InstanceNormOp is invalid: "
"the size of X's dimensions must greater than "
"or equal to 2. But received: "
"the size of X's dimensions is [%d]"
,
x_dims
.
size
()));
PADDLE_ENFORCE_LE
(
x_dims
.
size
(),
5
,
platform
::
errors
::
InvalidArgument
(
"The `shape` in InstanceNormOp is invalid: "
"the size of X's dimensions must smaller than"
"or equal to 5. But received: "
"the size of X's dimensions is [%d]"
,
x_dims
.
size
()));
int
N
,
C
,
H
,
W
,
D
;
ExtractNCWHD
(
x_dims
,
DataLayout
::
kNCHW
,
&
N
,
&
C
,
&
H
,
&
W
,
&
D
);
int
NxC
=
N
*
C
;
...
...
@@ -231,8 +240,9 @@ class InstanceNormGradKernel<platform::CUDADeviceContext, T>
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
platform
::
is_gpu_place
(
ctx
.
GetPlace
()),
true
,
"It must use CUDAPlace."
);
PADDLE_ENFORCE_EQ
(
platform
::
is_gpu_place
(
ctx
.
GetPlace
()),
true
,
platform
::
errors
::
PreconditionNotMet
(
"It must use CUDAPlace."
));
double
epsilon
=
static_cast
<
double
>
(
ctx
.
Attr
<
float
>
(
"epsilon"
));
const
auto
*
scale
=
ctx
.
Input
<
Tensor
>
(
"Scale"
);
const
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
...
...
@@ -257,8 +267,22 @@ class InstanceNormGradKernel<platform::CUDADeviceContext, T>
d_scale
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
d_bias
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
}
PADDLE_ENFORCE_EQ
(
scale
->
dims
().
size
(),
1UL
);
PADDLE_ENFORCE_EQ
(
scale
->
dims
()[
0
],
C
);
PADDLE_ENFORCE_EQ
(
scale
->
dims
().
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"The `shape` in InstanceNormOp is invalid: "
"the size of scale's dimensions must be equal to 1. But "
"received: the size of scale's dimensions"
"is [%d]"
,
scale
->
dims
().
size
()));
PADDLE_ENFORCE_EQ
(
scale
->
dims
()[
0
],
C
,
platform
::
errors
::
InvalidArgument
(
"The `shape` in InstanceNormOp is invalid: "
"the first dimension of scale must be equal to "
"Channels([%d]). But received: "
"the first dimension of scale is [%d],"
"the dimensions of scale is [%s], "
,
C
,
scale
->
dims
()[
0
],
scale
->
dims
()));
auto
&
dev_ctx
=
ctx
.
template
device_context
<
platform
::
CUDADeviceContext
>();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录