未验证 提交 771c3b29 编写于 作者: L Liufang Sang 提交者: GitHub

update enhance error message for Initializer, smooth_l1 (#23912)

* update enhance error message test=develop

* update details test=develop
上级 53fb0e92
...@@ -58,10 +58,12 @@ class GaussianRandomOp : public framework::OperatorWithKernel { ...@@ -58,10 +58,12 @@ class GaussianRandomOp : public framework::OperatorWithKernel {
for (auto dim : shape) { for (auto dim : shape) {
temp.push_back(static_cast<int64_t>(dim)); temp.push_back(static_cast<int64_t>(dim));
} }
PADDLE_ENFORCE_GT(shape.size(), 0UL, PADDLE_ENFORCE_GT(
platform::errors::InvalidArgument( shape.size(), 0UL,
"Attribute(shape) of GaussianRandomOp must be set " platform::errors::InvalidArgument(
"and shape.size() > 0.")); "Attribute(shape) of GaussianRandomOp must be set "
"and shape.size() > 0, but reveived shape.size() is %d",
shape.size()));
ctx->SetOutputDim("Out", framework::make_ddim(temp)); ctx->SetOutputDim("Out", framework::make_ddim(temp));
} }
......
...@@ -34,15 +34,18 @@ class SmoothL1LossOp : public framework::OperatorWithKernel { ...@@ -34,15 +34,18 @@ class SmoothL1LossOp : public framework::OperatorWithKernel {
check = false; check = false;
} }
if (check) { if (check) {
PADDLE_ENFORCE_EQ(x_dims, y_dims, PADDLE_ENFORCE_EQ(
platform::errors::InvalidArgument( x_dims, y_dims,
"Input(X) ans Input(Y) of SmoothL1LossOp should " platform::errors::InvalidArgument(
"have the same size")); "Input(X) ans Input(Y) of SmoothL1LossOp should "
"have the same size, but received X dim is %s, Y dim is %s",
x_dims.to_str(), y_dims.to_str()));
} }
PADDLE_ENFORCE_GE(x_dims.size(), 2, PADDLE_ENFORCE_GE(x_dims.size(), 2,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"The tensor rank of Input(X) of SmoothL1LossOp " "The tensor rank of Input(X) of SmoothL1LossOp "
"should not be less than 2.")); "should not be less than 2, but received %d.",
x_dims.size()));
if (ctx->HasInput("InsideWeight")) { if (ctx->HasInput("InsideWeight")) {
PADDLE_ENFORCE_EQ(ctx->HasInput("OutsideWeight"), true, PADDLE_ENFORCE_EQ(ctx->HasInput("OutsideWeight"), true,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
...@@ -58,7 +61,9 @@ class SmoothL1LossOp : public framework::OperatorWithKernel { ...@@ -58,7 +61,9 @@ class SmoothL1LossOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ(x_dims, dims, PADDLE_ENFORCE_EQ(x_dims, dims,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"Input(X) ans Input(InsideWeight) of " "Input(X) ans Input(InsideWeight) of "
"SmoothL1LossOp should have the same size")); "SmoothL1LossOp should have the same size, but "
"received X dim is %s, InsideWeight dim is %s",
x_dims.to_str(), dims.to_str()));
} }
dims = ctx->GetInputDim("OutsideWeight"); dims = ctx->GetInputDim("OutsideWeight");
...@@ -71,7 +76,9 @@ class SmoothL1LossOp : public framework::OperatorWithKernel { ...@@ -71,7 +76,9 @@ class SmoothL1LossOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ(x_dims, dims, PADDLE_ENFORCE_EQ(x_dims, dims,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"Input(X) ans Input(OutsideWeight) of " "Input(X) ans Input(OutsideWeight) of "
"SmoothL1LossOp should have the same size")); "SmoothL1LossOp should have the same size, but "
"received X dim is %s, OutsideWeight dim is %s",
x_dims.to_str(), dims.to_str()));
} }
} }
...@@ -145,18 +152,23 @@ class SmoothL1LossGradOp : public framework::OperatorWithKernel { ...@@ -145,18 +152,23 @@ class SmoothL1LossGradOp : public framework::OperatorWithKernel {
auto in_dims = ctx->GetInputDim("Diff"); auto in_dims = ctx->GetInputDim("Diff");
auto out_dims = ctx->GetInputDim(framework::GradVarName("Out")); auto out_dims = ctx->GetInputDim(framework::GradVarName("Out"));
PADDLE_ENFORCE_GE(out_dims.size(), 2, PADDLE_ENFORCE_GE(
platform::errors::InvalidArgument( out_dims.size(), 2,
"The tensor rank of Input(Out@Grad) should be 2.")); platform::errors::InvalidArgument(
"The tensor rank of Input(Out@Grad) should be 2, but received %d.",
out_dims.size()));
if (ctx->IsRuntime()) { if (ctx->IsRuntime()) {
PADDLE_ENFORCE_EQ(out_dims[0], in_dims[0], PADDLE_ENFORCE_EQ(
platform::errors::InvalidArgument( out_dims[0], in_dims[0],
"The 1st dimension of Input(Out@Grad) must be " platform::errors::InvalidArgument(
"same as input in SmoothL1LossGradOp.")); "The 1st dimension of Input(Out@Grad) must be "
"same as input in SmoothL1LossGradOp, but received %d and %d.",
out_dims[0], in_dims[0]));
PADDLE_ENFORCE_EQ(out_dims[1], 1, PADDLE_ENFORCE_EQ(out_dims[1], 1,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"The 2nd dimension of Input(Out@Grad) must be 1 in " "The 2nd dimension of Input(Out@Grad) must be 1 in "
"SmoothL1LossGradOp.")); "SmoothL1LossGradOp, but received %d.",
out_dims[1]));
} }
auto x_grad_name = framework::GradVarName("X"); auto x_grad_name = framework::GradVarName("X");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册