From bcb2903e605605d9341026394945cacf7280b449 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Thu, 26 Sep 2019 10:04:04 +0800 Subject: [PATCH] enhance shape error message of mul_op (#19998) test=develop --- paddle/fluid/operators/mul_op.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/paddle/fluid/operators/mul_op.cc b/paddle/fluid/operators/mul_op.cc index 0823ea8f4d3..b84833453c9 100644 --- a/paddle/fluid/operators/mul_op.cc +++ b/paddle/fluid/operators/mul_op.cc @@ -47,23 +47,27 @@ class MulOp : public framework::OperatorWithKernel { << " x_num_col_dims=" << x_num_col_dims << " y_num_col_dims=" << y_num_col_dims; - PADDLE_ENFORCE_GT( - x_dims.size(), x_num_col_dims, - "The input tensor X's rank of MulOp should be larger than " - "x_num_col_dims."); - PADDLE_ENFORCE_GT( - y_dims.size(), y_num_col_dims, - "The input tensor Y's rank of MulOp should be larger than " - "y_num_col_dims: %ld vs %ld", - y_dims.size(), y_num_col_dims); + PADDLE_ENFORCE_GT(x_dims.size(), x_num_col_dims, + "ShapeError: The input tensor X's dimensions of MulOp " + "should be larger than x_num_col_dims. But received X's " + "dimensions = %d, X's shape = [%s], x_num_col_dims = %d.", + x_dims.size(), x_dims, x_num_col_dims); + PADDLE_ENFORCE_GT(y_dims.size(), y_num_col_dims, + "ShapeError: The input tensor Y's dimensions of MulOp " + "should be larger than y_num_col_dims. But received Y's " + "dimensions = %d, Y's shape = [%s], y_num_col_dims = %d.", + y_dims.size(), y_dims, y_num_col_dims); auto x_mat_dims = framework::flatten_to_2d(x_dims, x_num_col_dims); auto y_mat_dims = framework::flatten_to_2d(y_dims, y_num_col_dims); - PADDLE_ENFORCE_EQ(x_mat_dims[1], y_mat_dims[0], - "First matrix's width must be equal with second matrix's " - "height. %s, %s", - x_mat_dims[1], y_mat_dims[0]); + PADDLE_ENFORCE_EQ( + x_mat_dims[1], y_mat_dims[0], + "ShapeError: After flatten the input tensor X and Y to 2-D dimensions " + "matrix X1 and Y1, the matrix X1's width must be equal with matrix " + "Y1's height. But received X's shape = [%s], X1's shape = [%s], X1's " + "width = %s; Y's shape = [%s], Y1's shape = [%s], Y1's height = %s.", + x_dims, x_mat_dims, x_mat_dims[1], y_dims, y_mat_dims, y_mat_dims[0]); std::vector output_dims; output_dims.reserve( static_cast(x_num_col_dims + y_dims.size() - y_num_col_dims)); -- GitLab