diff --git a/paddle/fluid/operators/lstm_unit_op.cc b/paddle/fluid/operators/lstm_unit_op.cc index c325c0892ed81810d3620fadd53c716df5156e48..e6ffda201ba0fd717274e76e746b84aab297873d 100644 --- a/paddle/fluid/operators/lstm_unit_op.cc +++ b/paddle/fluid/operators/lstm_unit_op.cc @@ -23,23 +23,23 @@ class LstmUnitOp : public framework::OperatorWithKernel { using framework::OperatorWithKernel::OperatorWithKernel; void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE(ctx->HasInput("X"), "Input(X) of LSTM should not be null."); - PADDLE_ENFORCE(ctx->HasInput("C_prev"), - "Input(C_prev) of LSTM should not be null."); - PADDLE_ENFORCE(ctx->HasOutput("C"), - "Output(C) of LSTM should not be null."); - PADDLE_ENFORCE(ctx->HasOutput("H"), - "Output(H) of LSTM should not be null."); + OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "lstm_unit"); + OP_INOUT_CHECK(ctx->HasInput("C_prev"), "Input", "C_prev", "lstm_unit"); + OP_INOUT_CHECK(ctx->HasInput("C"), "Output", "C", "lstm_unit"); + OP_INOUT_CHECK(ctx->HasInput("H"), "Output", "H", "lstm_unit"); auto x_dims = ctx->GetInputDim("X"); auto c_prev_dims = ctx->GetInputDim("C_prev"); - PADDLE_ENFORCE_EQ(x_dims.size(), 2, "Input(X)'s rank must be 2."); + PADDLE_ENFORCE_EQ(x_dims.size(), 2, platform::errors::InvalidArgument( + "Input(X)'s rank must be 2.")); if (ctx->IsRuntime()) { PADDLE_ENFORCE_EQ(x_dims[0], c_prev_dims[0], - "Batch size of inputs and states must be equal"); + platform::errors::InvalidArgument( + "Batch size of inputs and states must be equal")); PADDLE_ENFORCE_EQ(x_dims[1], c_prev_dims[1] * 4, - "Dimension of FC should equal to prev state * 4"); + platform::errors::InvalidArgument( + "Dimension of FC should equal to prev state * 4")); } int b_size = c_prev_dims[0]; // batch size @@ -85,10 +85,10 @@ class LstmUnitGradOp : public framework::OperatorWithKernel { using framework::OperatorWithKernel::OperatorWithKernel; void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE(ctx->HasInput(framework::GradVarName("C")), - "Input(C@GRAD) should not be null"); - PADDLE_ENFORCE(ctx->HasInput(framework::GradVarName("H")), - "Input(H@GRAD) should not be null"); + OP_INOUT_CHECK(ctx->HasInput(framework::GradVarName("C")), "Input", + framework::GradVarName("C"), "lstm_unit"); + OP_INOUT_CHECK(ctx->HasInput(framework::GradVarName("H")), "Input", + framework::GradVarName("H"), "lstm_unit"); ctx->SetOutputDim(framework::GradVarName("X"), ctx->GetInputDim("X")); ctx->SetOutputDim(framework::GradVarName("C_prev"), ctx->GetInputDim("C_prev")); diff --git a/paddle/fluid/operators/lstm_unit_op.cu b/paddle/fluid/operators/lstm_unit_op.cu index 810b83cb535fecc02bb7ac2e2360217229614d8b..3949a066e08680ac889d18439f0554e8103bcd7b 100644 --- a/paddle/fluid/operators/lstm_unit_op.cu +++ b/paddle/fluid/operators/lstm_unit_op.cu @@ -93,8 +93,9 @@ template class LstmUnitOpCUDAKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - PADDLE_ENFORCE(platform::is_gpu_place(ctx.GetPlace()), - "It must use CUDAPlace."); + PADDLE_ENFORCE_EQ( + platform::is_gpu_place(ctx.GetPlace()), true, + paddle::platform::errors::PreconditionNotMet("It must use CUDAPlace.")); auto* x_tensor = ctx.Input("X"); auto* c_prev_tensor = ctx.Input("C_prev"); @@ -124,8 +125,9 @@ template class LstmUnitGradOpCUDAKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - PADDLE_ENFORCE(platform::is_gpu_place(ctx.GetPlace()), - "It must use CUDAPlace."); + PADDLE_ENFORCE_EQ( + platform::is_gpu_place(ctx.GetPlace()), true, + paddle::platform::errors::PreconditionNotMet("It must use CUDAPlace.")); auto x_tensor = ctx.Input("X"); auto c_prev_tensor = ctx.Input("C_prev"); diff --git a/paddle/fluid/operators/lstm_unit_op.h b/paddle/fluid/operators/lstm_unit_op.h index 3fe7bda39b68d6ab29a4131ccd59b1693bbdb9ea..9faed3ca2ce4bec2cdff02993465bf32397e9338 100644 --- a/paddle/fluid/operators/lstm_unit_op.h +++ b/paddle/fluid/operators/lstm_unit_op.h @@ -39,8 +39,9 @@ template class LstmUnitKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - PADDLE_ENFORCE(platform::is_cpu_place(ctx.GetPlace()), - "It must use CPUPlace."); + PADDLE_ENFORCE( + platform::is_cpu_place(ctx.GetPlace()), + paddle::platform::errors::PreconditionNotMet("It must use CPUPlace.")); auto* x_tensor = ctx.Input("X"); auto* c_prev_tensor = ctx.Input("C_prev"); @@ -82,8 +83,9 @@ template class LstmUnitGradKernel : public framework::OpKernel { public: void Compute(const framework::ExecutionContext& ctx) const override { - PADDLE_ENFORCE(platform::is_cpu_place(ctx.GetPlace()), - "It must use CPUPlace."); + PADDLE_ENFORCE( + platform::is_cpu_place(ctx.GetPlace()), + paddle::platform::errors::PreconditionNotMet("It must use CPUPlace.")); auto x_tensor = ctx.Input("X"); auto c_prev_tensor = ctx.Input("C_prev"); diff --git a/paddle/fluid/operators/lstmp_op.h b/paddle/fluid/operators/lstmp_op.h index f0a727f34fec77ef17eeacfdcaf6565beaa14557..a2d1d5295be82f1e4c328c84005c9c676ccd06aa 100644 --- a/paddle/fluid/operators/lstmp_op.h +++ b/paddle/fluid/operators/lstmp_op.h @@ -91,7 +91,8 @@ class LSTMPKernel : public framework::OpKernel { else if (act_type == math::detail::ActivationType::kReLU) ReluFunctor()(d, x, y); else - PADDLE_THROW("unsupported activation type"); + PADDLE_THROW( + platform::errors::InvalidArgument("unsupported activation type")); } void Compute(const framework::ExecutionContext& ctx) const override { @@ -263,7 +264,8 @@ class LSTMPGradKernel : public framework::OpKernel { else if (act_type == math::detail::ActivationType::kReLU) ReluGradFunctor()(d, x, y, dy, dx); else - PADDLE_THROW("unsupported activation type"); + PADDLE_THROW( + platform::errors::InvalidArgument("unsupported activation type")); } void Compute(const framework::ExecutionContext& ctx) const override { diff --git a/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc b/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc index 99e8064d2446f0d4741713dca0df1e53ee46b8aa..b5ca370088bc6d74226fdb82a3bc080eb4da26d4 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_conv_op.cc @@ -61,7 +61,8 @@ class SequenceConvOp : public framework::OperatorWithKernel { if (ctx->Attrs().Get("paddingTrainable")) { PADDLE_ENFORCE( ctx->HasInput("PaddingData"), - "Input(PaddingData) of SequenceConvOp should not be null."); + platform::errors::InvalidArgument( + "Input(PaddingData) of SequenceConvOp should not be null.")); framework::DDim padding_dim = ctx->GetInputDim("PaddingData"); int up_pad = std::max(0, -context_start); int down_pad = std::max(0, context_start + context_length - 1); @@ -69,9 +70,9 @@ class SequenceConvOp : public framework::OperatorWithKernel { int input_width = static_cast(in_dims[1]); if (context_start == 0 && context_length == 1) { - PADDLE_THROW( + PADDLE_THROW(platform::errors::InvalidArgument( "If context_start is 0 and context_length is 1, paddingTrainable " - "should be false."); + "should be false.")); } PADDLE_ENFORCE_EQ( padding_dim.size(), 2, diff --git a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc index 1dbddfa709d72c5f8c57fb6c1b109462561b7c76..7a488de1de3fde1473add1a2a2e61dc94e5caf33 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc @@ -44,7 +44,8 @@ class SequenceEnumerateOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr("win_size", "(int) The enumerate sequence window size.") .AddCustomChecker([](const int& win_size) { PADDLE_ENFORCE(win_size >= 2, - "The window size should be not less than 2."); + platform::errors::InvalidArgument( + "The window size should be not less than 2.")); }); AddAttr("pad_value", "(int) The enumerate sequence padding value.") .SetDefault(0); diff --git a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cu b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cu index d5deb7582c7c00f3102ea568a716b715611212ce..2790f30a9bdc528180822989d7a0e134da2566dd 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cu +++ b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cu @@ -58,7 +58,8 @@ class SequenceEnumerateOpCUDAKernel : public framework::OpKernel { PADDLE_ENFORCE_EQ( static_cast(in_dims[0]), in_lod[0].back(), - "The actual input data's size mismatched with LoD information."); + platform::errors::InvalidArgument( + "The actual input data's size mismatched with LoD information.")); /* Generate enumerate sequence set */ auto stream = context.cuda_device_context().stream(); diff --git a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.h b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.h index 4807521bc0d92987125c8fe105e5d7e80091a09a..19e0bc1cdebafce9034d0266a7305a5ca04afb31 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.h +++ b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.h @@ -29,21 +29,26 @@ class SequenceEnumerateKernel : public framework::OpKernel { int win_size = context.Attr("win_size"); auto pad_value = static_cast(context.Attr("pad_value")); - PADDLE_ENFORCE_EQ(in->lod().empty(), false, - "Input(X) Tensor of SequenceEnumerateOp does not contain " - "LoD information."); + PADDLE_ENFORCE_EQ( + in->lod().empty(), false, + platform::errors::InvalidArgument( + "Input(X) Tensor of SequenceEnumerateOp does not contain " + "LoD information.")); auto in_dims = in->dims(); auto lod0 = in->lod()[0]; PADDLE_ENFORCE_EQ( static_cast(in_dims[0]), lod0.back(), - "The actual input data's size mismatched with LoD information."); + platform::errors::InvalidArgument( + "The actual input data's size mismatched with LoD information.")); PADDLE_ENFORCE_EQ( in_dims.size(), 2UL, - "Input(X) of SequenceEnumerate operator's rank should be 2."); + platform::errors::InvalidArgument( + "Input(X) of SequenceEnumerate operator's rank should be 2.")); PADDLE_ENFORCE_EQ(in_dims[1], 1, - "Input(X) of SequenceEnumerate operator's 2nd " - "dimension should be 1."); + platform::errors::InvalidArgument( + "Input(X) of SequenceEnumerate operator's 2nd " + "dimension should be 1.")); // Generate enumerate sequence set auto in_data = in->data(); diff --git a/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc b/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc index b8912dd4c796065b8747157267764b1d1c63d216..7cb6edb87ea305fbecc71ae0ca75069ecb8bee13 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_mask_op.cc @@ -69,8 +69,10 @@ class SequenceMaskOpMaker : public framework::OpProtoAndCheckerMaker { "= max(Input(X)).") .SetDefault(-1) .AddCustomChecker([](const int& v) { - PADDLE_ENFORCE(v < 0 || v >= 1, - "Attr(maxlen) must be less than 0 or larger than 1"); + PADDLE_ENFORCE( + v < 0 || v >= 1, + platform::errors::InvalidArgument( + "Attr(maxlen) must be less than 0 or larger than 1")); }); AddAttr("out_dtype", "Output data type"); AddComment(R"DOC(