Skip to content

Commit c35100b

Browse files
authored
test=release/1.8 update op's error info (#24541)
1 parent 10edace commit c35100b

File tree

3 files changed

+72
-29
lines changed

3 files changed

+72
-29
lines changed

paddle/fluid/operators/detection/iou_similarity_op.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,29 @@ class IOUSimilarityOp : public framework::OperatorWithKernel {
2323

2424
protected:
2525
void InferShape(framework::InferShapeContext *ctx) const override {
26-
PADDLE_ENFORCE(ctx->HasInput("X"),
27-
"Input(X) of IOUSimilarityOp should not be null.");
28-
PADDLE_ENFORCE(ctx->HasInput("Y"),
29-
"Input(Y) of IOUSimilarityOp should not be null.");
26+
OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "iou_similarity");
27+
OP_INOUT_CHECK(ctx->HasInput("Y"), "Input", "Y", "iou_similarity");
3028
auto x_dims = ctx->GetInputDim("X");
3129
auto y_dims = ctx->GetInputDim("Y");
3230

33-
PADDLE_ENFORCE_EQ(x_dims.size(), 2UL, "The rank of Input(X) must be 2.");
34-
PADDLE_ENFORCE_EQ(x_dims[1], 4UL, "The shape of X is [N, 4]");
35-
PADDLE_ENFORCE_EQ(y_dims.size(), 2UL, "The rank of Input(Y) must be 2.");
36-
PADDLE_ENFORCE_EQ(y_dims[1], 4UL, "The shape of Y is [M, 4]");
31+
PADDLE_ENFORCE_EQ(
32+
x_dims.size(), 2UL,
33+
platform::errors::InvalidArgument(
34+
"The rank of Input(X) must be 2, but got dimension = %d.",
35+
x_dims.size()));
36+
PADDLE_ENFORCE_EQ(
37+
x_dims[1], 4UL,
38+
platform::errors::InvalidArgument(
39+
"The shape of X is [N, 4], bug got dimension = %d.", x_dims[1]));
40+
PADDLE_ENFORCE_EQ(
41+
y_dims.size(), 2UL,
42+
platform::errors::InvalidArgument(
43+
"The rank of Input(Y) must be 2, but got dimension = %d.",
44+
y_dims.size()));
45+
PADDLE_ENFORCE_EQ(
46+
y_dims[1], 4UL,
47+
platform::errors::InvalidArgument(
48+
"The shape of Y is [M, 4], but got dimension = %d.", y_dims[1]));
3749

3850
ctx->ShareLoD("X", /*->*/ "Out");
3951
ctx->SetOutputDim("Out", framework::make_ddim({x_dims[0], y_dims[0]}));

paddle/fluid/operators/mkldnn/conv_mkldnn_op.cc

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,18 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
130130
auto* output = ctx.Output<Tensor>("Output");
131131

132132
PADDLE_ENFORCE_EQ(input->layout(), DataLayout::kMKLDNN,
133-
"Wrong layout set for Input tensor");
134-
PADDLE_ENFORCE_NE(input->format(), MKLDNNMemoryFormat::undef,
135-
"Wrong format set for Input tensor");
133+
platform::errors::InvalidArgument(
134+
"The input tensor's layout should be %d, but got %d.",
135+
DataLayout::kMKLDNN, input->layout()));
136+
PADDLE_ENFORCE_NE(
137+
input->format(), MKLDNNMemoryFormat::undef,
138+
platform::errors::InvalidArgument("Wrong format set for Input tensor"));
136139

137-
PADDLE_ENFORCE_EQ(filter->layout(), DataLayout::kMKLDNN,
138-
"Wrong layout set for Filter tensor");
140+
PADDLE_ENFORCE_EQ(
141+
filter->layout(), DataLayout::kMKLDNN,
142+
platform::errors::InvalidArgument(
143+
"The Filter tensor's layout should be %d, but got %d.",
144+
DataLayout::kMKLDNN, filter->layout()));
139145
PADDLE_ENFORCE_NE(filter->format(), MKLDNNMemoryFormat::undef,
140146
"Wrong format set for Filter tensor");
141147

@@ -154,8 +160,11 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
154160
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW");
155161

156162
if (bias) {
157-
PADDLE_ENFORCE_EQ(bias->layout(), DataLayout::kMKLDNN,
158-
"Wrong layout set for Bias tensor");
163+
PADDLE_ENFORCE_EQ(
164+
bias->layout(), DataLayout::kMKLDNN,
165+
platform::errors::InvalidArgument(
166+
"The Bias tensor's layout should be %d, but got %d.",
167+
DataLayout::kMKLDNN, bias->layout()));
159168
PADDLE_ENFORCE_NE(bias->format(), MKLDNNMemoryFormat::undef,
160169
"Wrong format set for Bias tensor");
161170

@@ -371,7 +380,9 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
371380
auto* output = ctx.Output<Tensor>("Output");
372381

373382
PADDLE_ENFORCE_EQ(input->layout(), DataLayout::kMKLDNN,
374-
"Wrong layout set for Input tensor");
383+
platform::errors::InvalidArgument(
384+
"The input tensor's layout should be %d, but got %d.",
385+
DataLayout::kMKLDNN, input->layout()));
375386
PADDLE_ENFORCE_NE(input->format(), MKLDNNMemoryFormat::undef,
376387
"Wrong format set for Input tensor");
377388

@@ -438,8 +449,11 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
438449

439450
auto* filter = ctx.Input<Tensor>("Filter");
440451

441-
PADDLE_ENFORCE_EQ(filter->layout(), DataLayout::kMKLDNN,
442-
"Wrong layout set for Filter tensor");
452+
PADDLE_ENFORCE_EQ(
453+
filter->layout(), DataLayout::kMKLDNN,
454+
platform::errors::InvalidArgument(
455+
"The filter tensor's layout should be %d, but got %d.",
456+
DataLayout::kMKLDNN, filter->layout()));
443457
PADDLE_ENFORCE_NE(filter->format(), MKLDNNMemoryFormat::undef,
444458
"Wrong format set for Filter tensor");
445459

@@ -457,8 +471,11 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
457471
auto* bias = ctx.HasInput("Bias") ? ctx.Input<Tensor>("Bias") : nullptr;
458472

459473
if (bias) {
460-
PADDLE_ENFORCE_EQ(bias->layout(), DataLayout::kMKLDNN,
461-
"Wrong layout set for Bias tensor");
474+
PADDLE_ENFORCE_EQ(
475+
bias->layout(), DataLayout::kMKLDNN,
476+
platform::errors::InvalidArgument(
477+
"The bias tensor's layout should be %d, but got %d.",
478+
DataLayout::kMKLDNN, bias->layout()));
462479
PADDLE_ENFORCE_NE(bias->format(), MKLDNNMemoryFormat::undef,
463480
"Wrong format set for Bias tensor");
464481

@@ -743,17 +760,25 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
743760
Tensor* filter_grad = ctx.Output<Tensor>(framework::GradVarName("Filter"));
744761

745762
PADDLE_ENFORCE_EQ(input->layout(), DataLayout::kMKLDNN,
746-
"Wrong layout set for Input tensor");
763+
platform::errors::InvalidArgument(
764+
"The input tensor's layout should be %d, but got %d.",
765+
DataLayout::kMKLDNN, input->layout()));
747766
PADDLE_ENFORCE_NE(input->format(), MKLDNNMemoryFormat::undef,
748767
"Wrong format set for Input tensor");
749768

750-
PADDLE_ENFORCE_EQ(filter->layout(), DataLayout::kMKLDNN,
751-
"Wrong layout set for Filter tensor");
769+
PADDLE_ENFORCE_EQ(
770+
filter->layout(), DataLayout::kMKLDNN,
771+
platform::errors::InvalidArgument(
772+
"The filter tensor's layout should be %d, but got %d.",
773+
DataLayout::kMKLDNN, filter->layout()));
752774
PADDLE_ENFORCE_NE(filter->format(), MKLDNNMemoryFormat::undef,
753775
"Wrong format set for Filter tensor");
754776

755-
PADDLE_ENFORCE_EQ(output_grad->layout(), DataLayout::kMKLDNN,
756-
"Wrong layout set for output_grad tensor");
777+
PADDLE_ENFORCE_EQ(
778+
output_grad->layout(), DataLayout::kMKLDNN,
779+
platform::errors::InvalidArgument(
780+
"The output_grad tensor's layout should be %d, but got %d.",
781+
DataLayout::kMKLDNN, output_grad->layout()));
757782
PADDLE_ENFORCE_NE(output_grad->format(), MKLDNNMemoryFormat::undef,
758783
"Wrong format set for output_grad tensor");
759784

paddle/fluid/operators/mkldnn/conv_transpose_mkldnn_op.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ class ConvTransposeMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
5151
PADDLE_ENFORCE_NE(input->format(), MKLDNNMemoryFormat::undef,
5252
"Wrong format set for Input tensor");
5353

54-
PADDLE_ENFORCE_EQ(filter->layout(), DataLayout::kMKLDNN,
55-
"Wrong layout set for Filter tensor");
54+
PADDLE_ENFORCE_EQ(
55+
filter->layout(), DataLayout::kMKLDNN,
56+
platform::errors::InvalidArgument(
57+
"The filter tensor's laytout should be %d, but got %d.",
58+
DataLayout::kMKLDNN, filter->layout()));
5659
PADDLE_ENFORCE_NE(filter->format(), MKLDNNMemoryFormat::undef,
5760
"Wrong format set for Filter tensor");
5861

@@ -62,8 +65,11 @@ class ConvTransposeMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
6265
"Filter must be with 4 dimensions, i.e. OIHW");
6366

6467
if (bias) {
65-
PADDLE_ENFORCE_EQ(bias->layout(), DataLayout::kMKLDNN,
66-
"Wrong layout set for Bias tensor");
68+
PADDLE_ENFORCE_EQ(
69+
bias->layout(), DataLayout::kMKLDNN,
70+
platform::errors::InvalidArgument(
71+
"The bias tensor's laytout should be %d, but got %d.",
72+
DataLayout::kMKLDNN, bias->layout()));
6773
PADDLE_ENFORCE_NE(bias->format(), MKLDNNMemoryFormat::undef,
6874
"Wrong format set for Bias tensor");
6975

0 commit comments

Comments
 (0)