diff --git a/paddle/fluid/operators/grid_sampler_op.cc b/paddle/fluid/operators/grid_sampler_op.cc index ea0fc05bbd8c2cc410c89077408077f38f34be8c..5be490379642e8761a6821fa0dc0d332ca5b41ef 100644 --- a/paddle/fluid/operators/grid_sampler_op.cc +++ b/paddle/fluid/operators/grid_sampler_op.cc @@ -28,16 +28,9 @@ class GridSampleOp : public framework::OperatorWithKernel { public: using framework::OperatorWithKernel::OperatorWithKernel; void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE_EQ(ctx->HasInput("X"), true, - platform::errors::NotFound( - "Input(X) of GridSampleOp should not be null.")); - PADDLE_ENFORCE_EQ(ctx->HasInput("Grid"), true, - platform::errors::NotFound( - "Input(Grid) of GridSampleOp should not be null.")); - PADDLE_ENFORCE_EQ( - ctx->HasOutput("Output"), true, - platform::errors::NotFound( - "Output(Output) of GridSampleOp should not be null.")); + OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "GridSampler"); + OP_INOUT_CHECK(ctx->HasInput("Grid"), "Input", "Grid", "GridSampler"); + OP_INOUT_CHECK(ctx->HasOutput("Output"), "Output", "Output", "GridSampler"); auto x_dims = ctx->GetInputDim("X"); auto grid_dims = ctx->GetInputDim("Grid"); diff --git a/paddle/fluid/operators/kldiv_loss_op.cc b/paddle/fluid/operators/kldiv_loss_op.cc index ad333242396e9176f4e90fa5f9bd5bdee32d0781..7286e2e6d3144528d39a3980908aeeddd1ad9823 100644 --- a/paddle/fluid/operators/kldiv_loss_op.cc +++ b/paddle/fluid/operators/kldiv_loss_op.cc @@ -23,15 +23,9 @@ class KLDivLossOp : public framework::OperatorWithKernel { public: using framework::OperatorWithKernel::OperatorWithKernel; void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE_EQ(ctx->HasInput("X"), true, - platform::errors::NotFound( - "Input(X) of KLDivLossOp should not be null.")); - PADDLE_ENFORCE_EQ(ctx->HasInput("Target"), true, - platform::errors::NotFound( - "Input(Target) of KLDivLossOp should not be null.")); - PADDLE_ENFORCE_EQ(ctx->HasOutput("Loss"), true, - platform::errors::NotFound( - "Output(Loss) of KLDivLossOp should not be null.")); + OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "KLDivLoss"); + OP_INOUT_CHECK(ctx->HasInput("Target"), "Input", "Target", "KLDivLoss"); + OP_INOUT_CHECK(ctx->HasOutput("Loss"), "Output", "Loss", "KLDivLoss"); auto dim_x = ctx->GetInputDim("X"); auto dim_target = ctx->GetInputDim("Target"); @@ -135,15 +129,10 @@ class KLDivLossOpGrad : public framework::OperatorWithKernel { public: using framework::OperatorWithKernel::OperatorWithKernel; void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE_EQ( - ctx->HasInput("X"), true, - platform::errors::NotFound("Input(X) should not be null")); - PADDLE_ENFORCE_EQ( - ctx->HasInput("Target"), true, - platform::errors::NotFound("Input(Target) should not be null")); - PADDLE_ENFORCE_EQ( - ctx->HasInput(framework::GradVarName("Loss")), true, - platform::errors::NotFound("Input(Loss@GRAD) should not be null")); + OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "KLDivLossGrad"); + OP_INOUT_CHECK(ctx->HasInput("Target"), "Input", "Target", "KLDivLossGrad"); + OP_INOUT_CHECK(ctx->HasInput(framework::GradVarName("Loss")), "Input", + "Loss@GRAD", "KLDivLossGrad"); auto dim_x = ctx->GetInputDim("X"); if (ctx->HasOutput(framework::GradVarName("X"))) { ctx->SetOutputDim(framework::GradVarName("X"), dim_x); diff --git a/paddle/fluid/operators/spectral_norm_op.cc b/paddle/fluid/operators/spectral_norm_op.cc index a49c25a8fcb141a8a8657a4e74b4b63d5902dd48..71e5c978d79dc5736c8813b9b2735f9d7bc4c522 100644 --- a/paddle/fluid/operators/spectral_norm_op.cc +++ b/paddle/fluid/operators/spectral_norm_op.cc @@ -26,19 +26,10 @@ class SpectralNormOp : public framework::OperatorWithKernel { protected: void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE_EQ( - ctx->HasInput("Weight"), true, - platform::errors::NotFound( - "Input(Weight) of SpectralNormOp should not be null.")); - PADDLE_ENFORCE_EQ(ctx->HasInput("U"), true, - platform::errors::NotFound( - "Input(U) of SpectralNormOp should not be null.")); - PADDLE_ENFORCE_EQ(ctx->HasInput("V"), true, - platform::errors::NotFound( - "Input(V) of SpectralNormOp should not be null.")); - PADDLE_ENFORCE_EQ(ctx->HasOutput("Out"), true, - platform::errors::NotFound( - "Output(Out) of SpectralNormOp should not be null.")); + OP_INOUT_CHECK(ctx->HasInput("Weight"), "Input", "Weight", "SpectralNorm"); + OP_INOUT_CHECK(ctx->HasInput("U"), "Input", "U", "SpectralNorm"); + OP_INOUT_CHECK(ctx->HasInput("V"), "Input", "V", "SpectralNorm"); + OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "SpectralNorm"); auto dim_weight = ctx->GetInputDim("Weight"); auto rank_weight = dim_weight.size(); @@ -220,15 +211,13 @@ class SpectralNormOpGrad : public framework::OperatorWithKernel { protected: void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE_EQ( - ctx->HasInput("Weight"), true, - platform::errors::NotFound("Input(Weight) should not be null")); - PADDLE_ENFORCE_EQ( - ctx->HasInput("U"), true, - platform::errors::NotFound("Input(U) should not be null")); - PADDLE_ENFORCE_EQ( - ctx->HasInput("V"), true, - platform::errors::NotFound("Input(V) should not be null")); + OP_INOUT_CHECK(ctx->HasInput("Weight"), "Input", "Weight", + "SpectralNormGrad"); + OP_INOUT_CHECK(ctx->HasInput("U"), "Input", "U", "SpectralNormGrad"); + OP_INOUT_CHECK(ctx->HasInput("V"), "Input", "V", "SpectralNormGrad"); + OP_INOUT_CHECK(ctx->HasInput(framework::GradVarName("Out")), "Input", + "Out@GRAD", "SpectralNormGrad"); + PADDLE_ENFORCE_EQ( ctx->HasInput(framework::GradVarName("Out")), true, platform::errors::NotFound("Input(Out@GRAD) should not be null")); diff --git a/paddle/fluid/operators/temporal_shift_op.cc b/paddle/fluid/operators/temporal_shift_op.cc index 819cac3ee4d45a0f58e5d3e9b959933d9f05112a..2e87447ed166e9b84d80ab50be1a166047c6d103 100644 --- a/paddle/fluid/operators/temporal_shift_op.cc +++ b/paddle/fluid/operators/temporal_shift_op.cc @@ -26,13 +26,8 @@ class TemporalShiftOp : public framework::OperatorWithKernel { protected: void InferShape(framework::InferShapeContext* ctx) const override { - PADDLE_ENFORCE_EQ(ctx->HasInput("X"), true, - platform::errors::NotFound( - "Input(X) of TemporalShiftOp should not be null.")); - PADDLE_ENFORCE_EQ( - ctx->HasOutput("Out"), true, - platform::errors::NotFound( - "Output(Out) of TemporalShiftOp should not be null.")); + OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "SpectralNorm"); + OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "SpectralNorm"); auto dim_x = ctx->GetInputDim("X"); PADDLE_ENFORCE_EQ(dim_x.size(), 4,