diff --git a/paddle/fluid/operators/data_norm_op.cc b/paddle/fluid/operators/data_norm_op.cc index e83b9194c9eef33de4adc4f3af931d44dc542449..5df2bbdf95144de4f7b95b055740fbd3468d7056 100644 --- a/paddle/fluid/operators/data_norm_op.cc +++ b/paddle/fluid/operators/data_norm_op.cc @@ -388,7 +388,8 @@ class DataNormKernel break; } default: - PADDLE_THROW("Unknown storage order: %d", data_layout); + PADDLE_THROW(platform::errors::InvalidArgument( + "Unknown storage order: %d", data_layout)); } } }; @@ -464,7 +465,8 @@ class DataNormGradOp : public framework::OperatorWithKernel { const framework::ExecutionContext &ctx) const override { const auto *var = ctx.InputVar(framework::GradVarName("Y")); if (var == nullptr) { - PADDLE_THROW("can't find Y@GRAD"); + PADDLE_THROW(platform::errors::InvalidArgument( + "Y@GRAD can not be found for computation")); } const Tensor *t = nullptr; if (var->IsType()) { @@ -473,7 +475,8 @@ class DataNormGradOp : public framework::OperatorWithKernel { t = &var->Get(); } if (t == nullptr) { - PADDLE_THROW("can't find Y@GRAD"); + PADDLE_THROW(platform::errors::InvalidArgument( + "Y@GRAD can not be found for computation")); } // TODO(pzelazko-intel): enable MKLDNN layout when it's ready @@ -696,7 +699,8 @@ class DataNormGradKernel break; } default: - PADDLE_THROW("Unknown storage order: %s", data_layout_str); + PADDLE_THROW(platform::errors::InvalidArgument( + "Unknown storage order: %s", data_layout_str)); } } }; diff --git a/paddle/fluid/operators/distributed_ops/merge_ids_op.h b/paddle/fluid/operators/distributed_ops/merge_ids_op.h index 33dfadbe648247ae55c609e7673b7b0e87efdae8..9af014f57a68751484d29adc7e425542225f437e 100644 --- a/paddle/fluid/operators/distributed_ops/merge_ids_op.h +++ b/paddle/fluid/operators/distributed_ops/merge_ids_op.h @@ -16,6 +16,7 @@ limitations under the License. */ #include #include +#include #include #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/tensor_util.h" @@ -30,7 +31,8 @@ class MergeIdsOpKernel : public framework::OpKernel { void Compute(const framework::ExecutionContext &ctx) const override { auto place = ctx.GetPlace(); if (!platform::is_cpu_place(place)) { - PADDLE_THROW("MergeIds do not support GPU kernel"); + PADDLE_THROW(platform::errors::InvalidArgument( + "MergeIds do not support GPU kernel")); } const auto ids = ctx.MultiInput("Ids"); diff --git a/paddle/fluid/operators/lookup_table_op.cu b/paddle/fluid/operators/lookup_table_op.cu index e2c34e64fa6ee53dc1668b1c1c69d760464b9956..3e06e5caed31797b191dabc9846105d7a2480ad5 100644 --- a/paddle/fluid/operators/lookup_table_op.cu +++ b/paddle/fluid/operators/lookup_table_op.cu @@ -161,11 +161,12 @@ class LookupTableGradCUDAKernel : public framework::OpKernel { auto d_output_dims_2d = framework::flatten_to_2d(d_output_dims, d_output_dims.size() - 1); PADDLE_ENFORCE_EQ(d_table_value->dims(), d_output_dims_2d, - "ShapeError: The shape of lookup_table@Grad and " - "output@Grad should be same. " - "But received lookup_table@Grad's shape = [%s], " - "output@Grad's shape = [%s].", - d_table_value->dims(), d_output_dims_2d); + platform::errors::InvalidArgument( + "ShapeError: The shape of lookup_table@Grad and " + "output@Grad should be same. " + "But received lookup_table@Grad's shape = [%s], " + "output@Grad's shape = [%s].", + d_table_value->dims(), d_output_dims_2d)); memory::Copy(gpu_place, d_table_data, gpu_place, d_output_data, d_output->numel() * sizeof(T), stream); diff --git a/paddle/fluid/operators/lookup_table_op.h b/paddle/fluid/operators/lookup_table_op.h index 526631bc82880e8b0a4191e30adfd1c6d4b30bf0..3c30f0469165e2b1897af0200b9467c0029175b5 100644 --- a/paddle/fluid/operators/lookup_table_op.h +++ b/paddle/fluid/operators/lookup_table_op.h @@ -159,9 +159,9 @@ class LookupTableGradKernel : public framework::OpKernel { auto *table_t = context.Input("W"); table_dim = table_t->value().dims(); } else { - PADDLE_THROW( + PADDLE_THROW(platform::errors::InvalidArgument( "The parameter W of a LookupTable " - "must be either LoDTensor or SelectedRows"); + "must be either LoDTensor or SelectedRows")); } int64_t padding_idx = context.Attr("padding_idx"); diff --git a/paddle/fluid/operators/lookup_table_v2_op.cc b/paddle/fluid/operators/lookup_table_v2_op.cc index 4a6680d76c4de7f7f47445b593b1cf50cd6e1311..feaa33e28dfc54cdfac9d55e22b3bdfcf4c587e5 100644 --- a/paddle/fluid/operators/lookup_table_v2_op.cc +++ b/paddle/fluid/operators/lookup_table_v2_op.cc @@ -28,11 +28,15 @@ class LookupTableV2Op : public framework::OperatorWithKernel { void InferShape(framework::InferShapeContext* ctx) const override { PADDLE_ENFORCE_EQ(ctx->HasInput("W"), true, - "Input(W) of LookupTableV2Op should not be null."); + platform::errors::InvalidArgument( + "Input(W) of LookupTableV2Op should not be null.")); PADDLE_ENFORCE_EQ(ctx->HasInput("Ids"), true, - "Input(Ids) of LookupTableV2Op should not be null."); - PADDLE_ENFORCE_EQ(ctx->HasOutput("Out"), true, - "Output(Out) of LookupTableV2Op should not be null."); + platform::errors::InvalidArgument( + "Input(Ids) of LookupTableV2Op should not be null.")); + PADDLE_ENFORCE_EQ( + ctx->HasOutput("Out"), true, + platform::errors::InvalidArgument( + "Output(Out) of LookupTableV2Op should not be null.")); auto table_dims = ctx->GetInputDim("W"); auto ids_dims = ctx->GetInputDim("Ids"); @@ -40,10 +44,11 @@ class LookupTableV2Op : public framework::OperatorWithKernel { VLOG(5) << "ids rank is " << ids_rank << std::endl; PADDLE_ENFORCE_EQ( table_dims.size(), 2, - "ShapeError: The dimensions of the 'lookup table' must be 2. " - "But received lookup table's dimensions = %d, " - "lookup table's shape = [%s].", - table_dims.size(), table_dims); + platform::errors::InvalidArgument( + "ShapeError: The dimensions of the 'lookup table' must be 2. " + "But received lookup table's dimensions = %d, " + "lookup table's shape = [%s].", + table_dims.size(), table_dims)); auto output_dims = framework::vectorize(ids_dims); output_dims.push_back(table_dims[1]); diff --git a/paddle/fluid/operators/lookup_table_v2_op.cu b/paddle/fluid/operators/lookup_table_v2_op.cu index 551f0d3c6412e46deb311fac58e5b9638feb30a6..bd31d7dd1b848cb87bfd8b39a2885bc9c9b06b8d 100644 --- a/paddle/fluid/operators/lookup_table_v2_op.cu +++ b/paddle/fluid/operators/lookup_table_v2_op.cu @@ -191,11 +191,12 @@ class LookupTableV2GradCUDAKernel : public framework::OpKernel { auto d_output_dims_2d = framework::flatten_to_2d(d_output_dims, d_output_dims.size() - 1); PADDLE_ENFORCE_EQ(d_table_value->dims(), d_output_dims_2d, - "ShapeError: The shape of lookup_table@Grad and " - "output@Grad should be same. " - "But received lookup_table@Grad's shape = [%s], " - "output@Grad's shape = [%s].", - d_table_value->dims(), d_output_dims_2d); + platform::errors::InvalidArgument( + "ShapeError: The shape of lookup_table@Grad and " + "output@Grad should be same. " + "But received lookup_table@Grad's shape = [%s], " + "output@Grad's shape = [%s].", + d_table_value->dims(), d_output_dims_2d)); memory::Copy(gpu_place, d_table_data, gpu_place, d_output_data, d_output->numel() * sizeof(T), stream); diff --git a/paddle/fluid/operators/lookup_table_v2_op.h b/paddle/fluid/operators/lookup_table_v2_op.h index 092c5f3b03305608f96fcc2834ad74a3388ed7ed..05da39862b7ee3039a0019cdd9e18a0789db49a6 100644 --- a/paddle/fluid/operators/lookup_table_v2_op.h +++ b/paddle/fluid/operators/lookup_table_v2_op.h @@ -74,16 +74,18 @@ class LookupTableV2Kernel : public framework::OpKernel { } else { PADDLE_ENFORCE_LT( ids[i], row_number, - "Variable value (input) of OP(fluid.layers.embedding) " - "expected >= 0 and < %ld, but got %ld. Please check input " - "value.", - row_number, ids[i]); + platform::errors::InvalidArgument( + "Variable value (input) of OP(fluid.layers.embedding) " + "expected >= 0 and < %ld, but got %ld. Please check input " + "value.", + row_number, ids[i])); PADDLE_ENFORCE_GE( ids[i], 0, - "Variable value (input) of OP(fluid.layers.embedding) " - "expected >= 0 and < %ld, but got %ld. Please check input " - "value.", - row_number, ids[i]); + platform::errors::InvalidArgument( + "Variable value (input) of OP(fluid.layers.embedding) " + "expected >= 0 and < %ld, but got %ld. Please check input " + "value.", + row_number, ids[i])); memcpy(output + i * row_width, table + ids[i] * row_width, row_width * sizeof(T)); } @@ -101,13 +103,16 @@ class LookupTableV2Kernel : public framework::OpKernel { } else { PADDLE_ENFORCE_GE( ids[i], 0, - "Variable value (input) of OP(fluid.layers.embedding) " - "expected >= 0. But received %ld", - ids[i]); + platform::errors::InvalidArgument( + "Variable value (input) of OP(fluid.layers.embedding) " + "expected >= 0. But received %ld", + ids[i])); auto id_index = table_t.Index(ids[i]); - PADDLE_ENFORCE_GE(id_index, 0, - "the input key should be exists. But received %d.", - id_index); + PADDLE_ENFORCE_GE( + id_index, 0, + platform::errors::InvalidArgument( + "the input key should be exists. But received %d.", + id_index)); blas.VCOPY(row_width, table + id_index * row_width, output + i * row_width); } @@ -128,9 +133,9 @@ class LookupTableV2GradKernel : public framework::OpKernel { auto *table_t = context.Input("W"); table_dim = table_t->value().dims(); } else { - PADDLE_THROW( + PADDLE_THROW(platform::errors::InvalidArgument( "The parameter W of a LookupTableV2 " - "must be either LoDTensor or SelectedRows"); + "must be either LoDTensor or SelectedRows")); } int64_t padding_idx = context.Attr("padding_idx"); @@ -170,11 +175,12 @@ class LookupTableV2GradKernel : public framework::OpKernel { auto d_output_dims_2d = framework::flatten_to_2d(d_output_dims, d_output_dims.size() - 1); PADDLE_ENFORCE_EQ(d_table_value->dims(), d_output_dims_2d, - "ShapeError: The shape of lookup_table@Grad and " - "output@Grad should be same. " - "But received lookup_table@Grad's shape = [%s], " - "output@Grad's shape = [%s].", - d_table_value->dims(), d_output_dims_2d); + platform::errors::InvalidArgument( + "ShapeError: The shape of lookup_table@Grad and " + "output@Grad should be same. " + "But received lookup_table@Grad's shape = [%s], " + "output@Grad's shape = [%s].", + d_table_value->dims(), d_output_dims_2d)); memcpy(d_table_data, d_output_data, sizeof(T) * d_output->numel()); } else { @@ -211,14 +217,18 @@ class LookupTableV2GradKernel : public framework::OpKernel { } else { PADDLE_ENFORCE_LT( ids_data[i], N, - "Variable value (input) of OP(fluid.layers.embedding) " - "expected >= 0 and < %ld, but got %ld. Please check input value.", - N, ids_data[i]); + platform::errors::InvalidArgument( + "Variable value (input) of OP(fluid.layers.embedding) " + "expected >= 0 and < %ld, but got %ld. Please check input " + "value.", + N, ids_data[i])); PADDLE_ENFORCE_GE( ids_data[i], 0, - "Variable value (input) of OP(fluid.layers.embedding) " - "expected >= 0 and < %ld, but got %ld. Please check input value.", - N, ids_data[i]); + platform::errors::InvalidArgument( + "Variable value (input) of OP(fluid.layers.embedding) " + "expected >= 0 and < %ld, but got %ld. Please check input " + "value.", + N, ids_data[i])); for (int j = 0; j < D; ++j) { d_table_data[ids_data[i] * D + j] += d_output_data[i * D + j]; }