未验证 提交 633aaea0 编写于 作者: C ceci3 提交者: GitHub

Update err message (#24422)

* update err info, test=develop

* update, test=develop
上级 d0ef9479
...@@ -62,7 +62,9 @@ void BatchNormOp::InferShape(framework::InferShapeContext *ctx) const { ...@@ -62,7 +62,9 @@ void BatchNormOp::InferShape(framework::InferShapeContext *ctx) const {
auto mom = ctx->Inputs("MomentumTensor"); auto mom = ctx->Inputs("MomentumTensor");
PADDLE_ENFORCE_EQ(mom.size(), 1, PADDLE_ENFORCE_EQ(mom.size(), 1,
platform::errors::InvalidArgument( 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( PADDLE_ENFORCE_GE(
...@@ -298,12 +300,18 @@ class BatchNormKernel<platform::CPUDeviceContext, T> ...@@ -298,12 +300,18 @@ class BatchNormKernel<platform::CPUDeviceContext, T>
const auto *x = ctx.Input<Tensor>("X"); const auto *x = ctx.Input<Tensor>("X");
const auto &x_dims = x->dims(); const auto &x_dims = x->dims();
PADDLE_ENFORCE_GE(x_dims.size(), 2, PADDLE_ENFORCE_GE(
x_dims.size(), 2,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"The Input X dim size should be larger than 1.")); "The size of input X's dimensions should be larger than 1."
PADDLE_ENFORCE_LE(x_dims.size(), 5, "But received: the size of input X's dimensions is [%d]",
x_dims.size()));
PADDLE_ENFORCE_LE(
x_dims.size(), 5,
platform::errors::InvalidArgument( 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 N = x_dims[0];
const int C = const int C =
(data_layout == DataLayout::kNCHW ? x_dims[1] (data_layout == DataLayout::kNCHW ? x_dims[1]
...@@ -606,12 +614,18 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T> ...@@ -606,12 +614,18 @@ class BatchNormGradKernel<platform::CPUDeviceContext, T>
// Get the size for each dimension. // Get the size for each dimension.
// NCHW [batch_size, in_channels, in_height, in_width] // NCHW [batch_size, in_channels, in_height, in_width]
const auto &x_dims = x->dims(); const auto &x_dims = x->dims();
PADDLE_ENFORCE_GE(x_dims.size(), 2, PADDLE_ENFORCE_GE(
x_dims.size(), 2,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"The Input X dim size should be larger than 1.")); "The size of input X's dimensions should be larger than 1."
PADDLE_ENFORCE_LE(x_dims.size(), 5, "But received: the size of input X's dimensions is [%d]",
x_dims.size()));
PADDLE_ENFORCE_LE(
x_dims.size(), 5,
platform::errors::InvalidArgument( 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 N = x_dims[0];
const int C = const int C =
(data_layout == DataLayout::kNCHW ? x_dims[1] (data_layout == DataLayout::kNCHW ? x_dims[1]
......
...@@ -58,8 +58,12 @@ class BatchNormKernel<platform::CUDADeviceContext, T> ...@@ -58,8 +58,12 @@ class BatchNormKernel<platform::CUDADeviceContext, T>
// NCHW [batch_size, in_channels, in_height, in_width] // NCHW [batch_size, in_channels, in_height, in_width]
const auto *x = ctx.Input<Tensor>("X"); const auto *x = ctx.Input<Tensor>("X");
const auto &x_dims = x->dims(); const auto &x_dims = x->dims();
PADDLE_ENFORCE(x_dims.size() >= 2 && x_dims.size() <= 5, PADDLE_ENFORCE_EQ(
"The Input dim size should be between 2 and 5"); 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"); auto *y = ctx.Output<Tensor>("Y");
y->mutable_data<T>(ctx.GetPlace()); y->mutable_data<T>(ctx.GetPlace());
...@@ -151,10 +155,34 @@ class BatchNormKernel<platform::CUDADeviceContext, T> ...@@ -151,10 +155,34 @@ class BatchNormKernel<platform::CUDADeviceContext, T>
const auto *est_mean = ctx.Input<Tensor>("Mean"); const auto *est_mean = ctx.Input<Tensor>("Mean");
const auto *est_var = ctx.Input<Tensor>("Variance"); const auto *est_var = ctx.Input<Tensor>("Variance");
// Run inference mode. // Run inference mode.
PADDLE_ENFORCE_EQ(est_mean->dims().size(), 1UL); PADDLE_ENFORCE_EQ(
PADDLE_ENFORCE_EQ(est_var->dims().size(), 1UL); est_mean->dims().size(), 1UL,
PADDLE_ENFORCE_EQ(est_mean->dims()[0], C); platform::errors::InvalidArgument(
PADDLE_ENFORCE_EQ(est_var->dims()[0], C); "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( PADDLE_ENFORCE_CUDA_SUCCESS(
platform::dynload::cudnnBatchNormalizationForwardInference( platform::dynload::cudnnBatchNormalizationForwardInference(
...@@ -503,8 +531,13 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T> ...@@ -503,8 +531,13 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
const auto &x_dims = x->dims(); const auto &x_dims = x->dims();
PADDLE_ENFORCE(x_dims.size() >= 2 && x_dims.size() <= 5, PADDLE_ENFORCE_EQ(
"The Input dim size should be between 2 and 5"); 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; int N, C, H, W, D;
ExtractNCWHD(x_dims, data_layout, &N, &C, &H, &W, &D); ExtractNCWHD(x_dims, data_layout, &N, &C, &H, &W, &D);
...@@ -515,8 +548,19 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T> ...@@ -515,8 +548,19 @@ class BatchNormGradKernel<platform::CUDADeviceContext, T>
d_scale->mutable_data<BatchNormParamType<T>>(ctx.GetPlace()); d_scale->mutable_data<BatchNormParamType<T>>(ctx.GetPlace());
d_bias->mutable_data<BatchNormParamType<T>>(ctx.GetPlace()); d_bias->mutable_data<BatchNormParamType<T>>(ctx.GetPlace());
} }
PADDLE_ENFORCE_EQ(scale->dims().size(), 1UL); PADDLE_ENFORCE_EQ(
PADDLE_ENFORCE_EQ(scale->dims()[0], C); 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; auto dtype = platform::CudnnDataType<T>::type;
const auto *reserve_space = ctx.Input<Tensor>("ReserveSpace"); const auto *reserve_space = ctx.Input<Tensor>("ReserveSpace");
......
...@@ -108,8 +108,9 @@ template <typename DeviceContext, typename T> ...@@ -108,8 +108,9 @@ template <typename DeviceContext, typename T>
class DropoutGradKernel : public framework::OpKernel<T> { class DropoutGradKernel : public framework::OpKernel<T> {
public: public:
void Compute(const framework::ExecutionContext& context) const override { void Compute(const framework::ExecutionContext& context) const override {
PADDLE_ENFORCE(!context.Attr<bool>("is_test"), PADDLE_ENFORCE_EQ(!context.Attr<bool>("is_test"), true,
"GradOp is only callable when is_test is false"); platform::errors::PreconditionNotMet(
"GradOp is only callable when is_test is false"));
auto* grad_x = context.Output<Tensor>(framework::GradVarName("X")); auto* grad_x = context.Output<Tensor>(framework::GradVarName("X"));
auto* grad_y = context.Input<Tensor>(framework::GradVarName("Out")); auto* grad_y = context.Input<Tensor>(framework::GradVarName("Out"));
......
...@@ -247,7 +247,8 @@ framework::OpKernelType InstanceNormGradOp::GetExpectedKernelType( ...@@ -247,7 +247,8 @@ framework::OpKernelType InstanceNormGradOp::GetExpectedKernelType(
const framework::ExecutionContext &ctx) const { const framework::ExecutionContext &ctx) const {
const auto *var = ctx.InputVar(framework::GradVarName("Y")); const auto *var = ctx.InputVar(framework::GradVarName("Y"));
if (var == nullptr) { if (var == nullptr) {
PADDLE_THROW("cannot find Y@GRAD"); PADDLE_THROW(
platform::errors::NotFound("cannot find gradient variable of Y"));
} }
const Tensor *t = nullptr; const Tensor *t = nullptr;
if (var->IsType<Tensor>()) { if (var->IsType<Tensor>()) {
...@@ -256,7 +257,8 @@ framework::OpKernelType InstanceNormGradOp::GetExpectedKernelType( ...@@ -256,7 +257,8 @@ framework::OpKernelType InstanceNormGradOp::GetExpectedKernelType(
t = &var->Get<LoDTensor>(); t = &var->Get<LoDTensor>();
} }
if (t == nullptr) { if (t == nullptr) {
PADDLE_THROW("cannot find Y@GRAD"); PADDLE_THROW(
platform::errors::InvalidArgument("gradient variable of Y is empty"));
} }
return framework::OpKernelType( return framework::OpKernelType(
OperatorWithKernel::IndicateVarDataType(ctx, "X"), ctx.GetPlace()); OperatorWithKernel::IndicateVarDataType(ctx, "X"), ctx.GetPlace());
...@@ -387,7 +389,8 @@ framework::OpKernelType InstanceNormDoubleGradOp::GetExpectedKernelType( ...@@ -387,7 +389,8 @@ framework::OpKernelType InstanceNormDoubleGradOp::GetExpectedKernelType(
const framework::ExecutionContext &ctx) const { const framework::ExecutionContext &ctx) const {
const auto *var = ctx.InputVar("DY"); const auto *var = ctx.InputVar("DY");
if (var == nullptr) { if (var == nullptr) {
PADDLE_THROW("cannot find Y@GRAD"); PADDLE_THROW(
platform::errors::NotFound("cannot find gradient variable of Y"));
} }
const Tensor *t = nullptr; const Tensor *t = nullptr;
if (var->IsType<Tensor>()) { if (var->IsType<Tensor>()) {
...@@ -396,7 +399,8 @@ framework::OpKernelType InstanceNormDoubleGradOp::GetExpectedKernelType( ...@@ -396,7 +399,8 @@ framework::OpKernelType InstanceNormDoubleGradOp::GetExpectedKernelType(
t = &var->Get<LoDTensor>(); t = &var->Get<LoDTensor>();
} }
if (t == nullptr) { if (t == nullptr) {
PADDLE_THROW("cannot find Y@GRAD"); PADDLE_THROW(
platform::errors::InvalidArgument("gradient variable of Y is empty"));
} }
return framework::OpKernelType( return framework::OpKernelType(
OperatorWithKernel::IndicateVarDataType(ctx, "X"), ctx.GetPlace()); OperatorWithKernel::IndicateVarDataType(ctx, "X"), ctx.GetPlace());
......
...@@ -70,18 +70,27 @@ class InstanceNormKernel<platform::CUDADeviceContext, T> ...@@ -70,18 +70,27 @@ class InstanceNormKernel<platform::CUDADeviceContext, T>
: public framework::OpKernel<T> { : public framework::OpKernel<T> {
public: public:
void Compute(const framework::ExecutionContext &ctx) const override { void Compute(const framework::ExecutionContext &ctx) const override {
PADDLE_ENFORCE_EQ(platform::is_gpu_place(ctx.GetPlace()), true, PADDLE_ENFORCE_EQ(
"It must be CUDAPlace."); platform::is_gpu_place(ctx.GetPlace()), true,
platform::errors::PreconditionNotMet("It must be CUDAPlace."));
double epsilon = static_cast<double>(ctx.Attr<float>("epsilon")); double epsilon = static_cast<double>(ctx.Attr<float>("epsilon"));
auto *x = ctx.Input<Tensor>("X"); auto *x = ctx.Input<Tensor>("X");
auto &x_dims = x->dims(); auto &x_dims = x->dims();
PADDLE_ENFORCE_GE( PADDLE_ENFORCE_GE(x_dims.size(), 2,
x_dims.size(), 2, platform::errors::InvalidArgument(
"the dimension of input X must greater than or equal to 2"); "The `shape` in InstanceNormOp is invalid: "
PADDLE_ENFORCE_LE( "the size of X's dimensions must greater than "
x_dims.size(), 5, "or equal to 2. But received: "
"the dimension of input X must smaller than or equal to 5"); "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; int N, C, H, W, D;
ExtractNCWHD(x_dims, DataLayout::kNCHW, &N, &C, &H, &W, &D); ExtractNCWHD(x_dims, DataLayout::kNCHW, &N, &C, &H, &W, &D);
int NxC = N * C; int NxC = N * C;
...@@ -231,8 +240,9 @@ class InstanceNormGradKernel<platform::CUDADeviceContext, T> ...@@ -231,8 +240,9 @@ class InstanceNormGradKernel<platform::CUDADeviceContext, T>
: public framework::OpKernel<T> { : public framework::OpKernel<T> {
public: public:
void Compute(const framework::ExecutionContext &ctx) const override { void Compute(const framework::ExecutionContext &ctx) const override {
PADDLE_ENFORCE_EQ(platform::is_gpu_place(ctx.GetPlace()), true, PADDLE_ENFORCE_EQ(
"It must use CUDAPlace."); platform::is_gpu_place(ctx.GetPlace()), true,
platform::errors::PreconditionNotMet("It must use CUDAPlace."));
double epsilon = static_cast<double>(ctx.Attr<float>("epsilon")); double epsilon = static_cast<double>(ctx.Attr<float>("epsilon"));
const auto *scale = ctx.Input<Tensor>("Scale"); const auto *scale = ctx.Input<Tensor>("Scale");
const auto *x = ctx.Input<Tensor>("X"); const auto *x = ctx.Input<Tensor>("X");
...@@ -257,8 +267,22 @@ class InstanceNormGradKernel<platform::CUDADeviceContext, T> ...@@ -257,8 +267,22 @@ class InstanceNormGradKernel<platform::CUDADeviceContext, T>
d_scale->mutable_data<T>(ctx.GetPlace()); d_scale->mutable_data<T>(ctx.GetPlace());
d_bias->mutable_data<T>(ctx.GetPlace()); d_bias->mutable_data<T>(ctx.GetPlace());
} }
PADDLE_ENFORCE_EQ(scale->dims().size(), 1UL); PADDLE_ENFORCE_EQ(
PADDLE_ENFORCE_EQ(scale->dims()[0], C); 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>(); 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.
先完成此消息的编辑!
想要评论请 注册