Skip to content

Commit 526a211

Browse files
authored
update conv error info (#24430)
* test=develop update conv error info * test=develop update iou_similarity error info * test=develop update some error info based review
1 parent c2103c4 commit 526a211

File tree

3 files changed

+198
-97
lines changed

3 files changed

+198
-97
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: 135 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
9595
public:
9696
void Compute(const paddle::framework::ExecutionContext& ctx) const override {
9797
PADDLE_ENFORCE(paddle::platform::is_cpu_place(ctx.GetPlace()),
98-
"It must use CPUPlace.");
98+
platform::errors::InvalidArgument("It must use CPUPlace."));
9999
bool is_INT8 =
100100
std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value;
101101
if (!is_INT8) {
@@ -130,37 +130,59 @@ 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,
140-
"Wrong format set for Filter tensor");
141-
142-
PADDLE_ENFORCE_GE(
143-
input->dims().size(), 4,
144-
"Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW");
145-
PADDLE_ENFORCE_LE(
146-
input->dims().size(), 5,
147-
"Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW");
148-
149-
PADDLE_ENFORCE_GE(
150-
filter->dims().size(), 4,
151-
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW");
152-
PADDLE_ENFORCE_LE(
153-
filter->dims().size(), 5,
154-
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW");
146+
platform::errors::InvalidArgument(
147+
"Wrong format set for Filter tensor"));
148+
149+
PADDLE_ENFORCE_GE(input->dims().size(), 4,
150+
platform::errors::InvalidArgument(
151+
"Input must be with 4 or 5 dimensions, i.e. NCHW or "
152+
"NCDHW, but got dimension = %d .",
153+
input->dims().size()));
154+
PADDLE_ENFORCE_LE(input->dims().size(), 5,
155+
platform::errors::InvalidArgument(
156+
"Input must be with 4 or 5 dimensions, i.e. NCHW or "
157+
"NCDHW, but got dimension = %d .",
158+
input->dims().size()));
159+
160+
PADDLE_ENFORCE_GE(filter->dims().size(), 4,
161+
platform::errors::InvalidArgument(
162+
"Filter must be with 4 or 5 dimensions, i.e. OIHW or "
163+
"OIDHW, but got dimension = %d .",
164+
filter->dims().size()));
165+
PADDLE_ENFORCE_LE(filter->dims().size(), 5,
166+
platform::errors::InvalidArgument(
167+
"Filter must be with 4 or 5 dimensions, i.e. OIHW or "
168+
"OIDHW, but got dimension = %d .",
169+
filter->dims().size()));
155170

156171
if (bias) {
157-
PADDLE_ENFORCE_EQ(bias->layout(), DataLayout::kMKLDNN,
158-
"Wrong layout set for Bias tensor");
172+
PADDLE_ENFORCE_EQ(
173+
bias->layout(), DataLayout::kMKLDNN,
174+
platform::errors::InvalidArgument(
175+
"The Bias tensor's layout should be %d, but got %d.",
176+
DataLayout::kMKLDNN, bias->layout()));
159177
PADDLE_ENFORCE_NE(bias->format(), MKLDNNMemoryFormat::undef,
160-
"Wrong format set for Bias tensor");
178+
platform::errors::InvalidArgument(
179+
"Got wrong format for Bias tensor."));
161180

162-
PADDLE_ENFORCE_EQ(bias->dims().size(), 1,
163-
"Bias must only have 1 dimension, i.e. X");
181+
PADDLE_ENFORCE_EQ(
182+
bias->dims().size(), 1,
183+
platform::errors::InvalidArgument("Bias must only have 1 dimension, "
184+
"i.e. X, but got dimension = %d .",
185+
bias->dims().size()));
164186
}
165187

166188
std::vector<int> strides_temp = ctx.Attr<std::vector<int>>("strides");
@@ -295,10 +317,16 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
295317

296318
PADDLE_ENFORCE_NE(
297319
residual_param_data, nullptr,
298-
"Provide data if you want MKLDNN conv+elementwise_add fusion");
299-
PADDLE_ENFORCE_EQ(output->dims(), residual_param->dims(),
300-
"Output and elementwise parameter need to have the "
301-
"same dimension sizes");
320+
platform::errors::InvalidArgument(
321+
"Provide data if you want MKLDNN conv+elementwise_add fusion"));
322+
PADDLE_ENFORCE_EQ(
323+
output->dims(), residual_param->dims(),
324+
platform::errors::InvalidArgument(
325+
"Output and elementwise parameter need to have the "
326+
"same dimension sizes, "
327+
"but got output's dimension = %d and residual param's dimension "
328+
"= %d .",
329+
output->dims().size(), residual_param->dims().size()));
302330

303331
if (residual_param->format() != handler.GetDstFormat()) {
304332
auto output_data =
@@ -371,16 +399,23 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
371399
auto* output = ctx.Output<Tensor>("Output");
372400

373401
PADDLE_ENFORCE_EQ(input->layout(), DataLayout::kMKLDNN,
374-
"Wrong layout set for Input tensor");
402+
platform::errors::InvalidArgument(
403+
"The input tensor's layout should be %d, but got %d.",
404+
DataLayout::kMKLDNN, input->layout()));
375405
PADDLE_ENFORCE_NE(input->format(), MKLDNNMemoryFormat::undef,
376-
"Wrong format set for Input tensor");
377-
378-
PADDLE_ENFORCE_GE(
379-
input->dims().size(), 4,
380-
"Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW");
381-
PADDLE_ENFORCE_LE(
382-
input->dims().size(), 5,
383-
"Input must be with 4 or 5 dimensions, i.e. NCHW or NCDHW");
406+
platform::errors::InvalidArgument(
407+
"Got wrong format for Input tensor."));
408+
409+
PADDLE_ENFORCE_GE(input->dims().size(), 4,
410+
platform::errors::InvalidArgument(
411+
"Input must be with 4 or 5 dimensions, i.e. NCHW or "
412+
"NCDHW, but got dimension = %d .",
413+
input->dims().size()));
414+
PADDLE_ENFORCE_LE(input->dims().size(), 5,
415+
platform::errors::InvalidArgument(
416+
"Input must be with 4 or 5 dimensions, i.e. NCHW or "
417+
"NCDHW, but got dimension = %d .",
418+
input->dims().size()));
384419

385420
std::string fuse_activation = ctx.Attr<std::string>("fuse_activation");
386421
bool fuse_residual_conn = ctx.Attr<bool>("fuse_residual_connection");
@@ -438,17 +473,25 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
438473

439474
auto* filter = ctx.Input<Tensor>("Filter");
440475

441-
PADDLE_ENFORCE_EQ(filter->layout(), DataLayout::kMKLDNN,
442-
"Wrong layout set for Filter tensor");
476+
PADDLE_ENFORCE_EQ(
477+
filter->layout(), DataLayout::kMKLDNN,
478+
platform::errors::InvalidArgument(
479+
"The filter tensor's layout should be %d, but got %d.",
480+
DataLayout::kMKLDNN, filter->layout()));
443481
PADDLE_ENFORCE_NE(filter->format(), MKLDNNMemoryFormat::undef,
444-
"Wrong format set for Filter tensor");
445-
446-
PADDLE_ENFORCE_GE(
447-
filter->dims().size(), 4,
448-
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW");
449-
PADDLE_ENFORCE_LE(
450-
filter->dims().size(), 5,
451-
"Filter must be with 4 or 5 dimensions, i.e. OIHW or OIDHW");
482+
platform::errors::InvalidArgument(
483+
"Got wrong format for Filter tensor."));
484+
485+
PADDLE_ENFORCE_GE(filter->dims().size(), 4,
486+
platform::errors::InvalidArgument(
487+
"Filter must be with 4 or 5 dimensions, i.e. OIHW "
488+
"or OIDHW, but got dimensions = %d .",
489+
filter->dims().size()));
490+
PADDLE_ENFORCE_LE(filter->dims().size(), 5,
491+
platform::errors::InvalidArgument(
492+
"Filter must be with 4 or 5 dimensions, i.e. OIHW "
493+
"or OIDHW, but got dimensions = %d .",
494+
filter->dims().size()));
452495

453496
PADDLE_ENFORCE_EQ(
454497
!fuse_residual_conn || !force_fp32_output, true,
@@ -457,13 +500,20 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
457500
auto* bias = ctx.HasInput("Bias") ? ctx.Input<Tensor>("Bias") : nullptr;
458501

459502
if (bias) {
460-
PADDLE_ENFORCE_EQ(bias->layout(), DataLayout::kMKLDNN,
461-
"Wrong layout set for Bias tensor");
503+
PADDLE_ENFORCE_EQ(
504+
bias->layout(), DataLayout::kMKLDNN,
505+
platform::errors::InvalidArgument(
506+
"The bias tensor's layout should be %d, but got %d.",
507+
DataLayout::kMKLDNN, bias->layout()));
462508
PADDLE_ENFORCE_NE(bias->format(), MKLDNNMemoryFormat::undef,
463-
"Wrong format set for Bias tensor");
509+
platform::errors::InvalidArgument(
510+
"Got wrong format for Bias tensor."));
464511

465512
PADDLE_ENFORCE_EQ(bias->dims().size(), 1,
466-
"Bias must only have 1 dimension, i.e. X");
513+
platform::errors::InvalidArgument(
514+
"Bias must only have 1 dimension, i.e. X, but "
515+
"got dimension = %d .",
516+
bias->dims().size()));
467517
}
468518

469519
std::vector<int> strides_temp = ctx.Attr<std::vector<int>>("strides");
@@ -482,7 +532,9 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
482532
bool is_conv3d = strides.size() == 3U;
483533

484534
PADDLE_ENFORCE_NE(is_conv3d, true,
485-
"int8 does not support conv3d currently");
535+
platform::errors::InvalidArgument(
536+
"int8 does not support conv3d currently, should "
537+
"set param is_conv3d as False"));
486538

487539
auto input_dims = input->dims();
488540
auto data_dims = framework::slice_ddim(input_dims, 2, input_dims.size());
@@ -599,9 +651,13 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
599651

600652
if (fuse_residual_conn) {
601653
auto residual_param = ctx.Input<Tensor>("ResidualData");
602-
PADDLE_ENFORCE_EQ(output->dims(), residual_param->dims(),
603-
"Output and elementwise parameter need to have the "
604-
"same dimension sizes");
654+
PADDLE_ENFORCE_EQ(
655+
output->dims(), residual_param->dims(),
656+
platform::errors::InvalidArgument(
657+
"Output and elementwise parameter need to have the "
658+
"same dimension sizes, but got output's dimension = %d"
659+
" and residual param's dimension =%d .",
660+
output->dims().size(), residual_param->dims().size()));
605661
auto residual_dt =
606662
paddle::framework::ToMKLDNNDataType(residual_param->type());
607663
if (residual_param->format() != handler->GetDstFormat()) {
@@ -729,7 +785,7 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
729785
public:
730786
void Compute(const paddle::framework::ExecutionContext& ctx) const override {
731787
PADDLE_ENFORCE(paddle::platform::is_cpu_place(ctx.GetPlace()),
732-
"It must use CPUPlace.");
788+
platform::errors::InvalidArgument("It must use CPUPlace."));
733789

734790
auto& dev_ctx =
735791
ctx.template device_context<platform::MKLDNNDeviceContext>();
@@ -743,23 +799,34 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
743799
Tensor* filter_grad = ctx.Output<Tensor>(framework::GradVarName("Filter"));
744800

745801
PADDLE_ENFORCE_EQ(input->layout(), DataLayout::kMKLDNN,
746-
"Wrong layout set for Input tensor");
802+
platform::errors::InvalidArgument(
803+
"The input tensor's layout should be %d, but got %d.",
804+
DataLayout::kMKLDNN, input->layout()));
747805
PADDLE_ENFORCE_NE(input->format(), MKLDNNMemoryFormat::undef,
748-
"Wrong format set for Input tensor");
806+
platform::errors::InvalidArgument(
807+
"Got wrong format for Input tensor."));
749808

750-
PADDLE_ENFORCE_EQ(filter->layout(), DataLayout::kMKLDNN,
751-
"Wrong layout set for Filter tensor");
809+
PADDLE_ENFORCE_EQ(
810+
filter->layout(), DataLayout::kMKLDNN,
811+
platform::errors::InvalidArgument(
812+
"The filter tensor's layout should be %d, but got %d.",
813+
DataLayout::kMKLDNN, filter->layout()));
752814
PADDLE_ENFORCE_NE(filter->format(), MKLDNNMemoryFormat::undef,
753-
"Wrong format set for Filter tensor");
815+
platform::errors::InvalidArgument(
816+
"Got wrong format for Filter tensor."));
754817

755-
PADDLE_ENFORCE_EQ(output_grad->layout(), DataLayout::kMKLDNN,
756-
"Wrong layout set for output_grad tensor");
818+
PADDLE_ENFORCE_EQ(
819+
output_grad->layout(), DataLayout::kMKLDNN,
820+
platform::errors::InvalidArgument(
821+
"The output_grad tensor's layout should be %d, but got %d.",
822+
DataLayout::kMKLDNN, output_grad->layout()));
757823
PADDLE_ENFORCE_NE(output_grad->format(), MKLDNNMemoryFormat::undef,
758824
"Wrong format set for output_grad tensor");
759825

760826
PADDLE_ENFORCE_EQ(
761827
ctx.Attr<bool>("is_test"), false,
762-
"is_test attribute should be set to False in training phase.");
828+
platform::errors::InvalidArgument(
829+
"is_test attribute should be set to False in training phase."));
763830

764831
if (!input_grad && !filter_grad) return;
765832

@@ -859,7 +926,8 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
859926
std::static_pointer_cast<mkldnn::convolution_forward::primitive_desc>(
860927
dev_ctx.GetBlob(key_conv_pd));
861928
PADDLE_ENFORCE_NE(conv_pd, nullptr,
862-
"Fail to find conv_pd in device context");
929+
platform::errors::InvalidArgument(
930+
"Fail to find conv_pd in device context"));
863931

864932
auto mkldnn_paddings = platform::ToMkldnnPadding(paddings);
865933

0 commit comments

Comments
 (0)