diff --git a/paddle/fluid/operators/unsqueeze_op.cc b/paddle/fluid/operators/unsqueeze_op.cc index 8a645e871580f2266ff504488ce8c3d5dd49de68..ed7a4f92f092b6a466a557312da262b62cd5be67 100755 --- a/paddle/fluid/operators/unsqueeze_op.cc +++ b/paddle/fluid/operators/unsqueeze_op.cc @@ -253,10 +253,7 @@ class Unsqueeze2Op : public UnsqueezeOp { UnsqueezeOp::InferShape(ctx); const auto &x_dims = ctx->GetInputDim("X"); - PADDLE_ENFORCE_EQ( - ctx->HasOutput("XShape"), true, - platform::errors::InvalidArgument("Output(XShape) of Unsqueeze " - "operator should not be null.")); + if (!ctx->HasOutput("XShape")) return; std::vector xshape_dims(x_dims.size() + 1); xshape_dims[0] = 0; for (int i = 0; i < x_dims.size(); ++i) { @@ -274,7 +271,8 @@ class Unsqueeze2OpMaker : public UnsqueezeOpMaker { AddOutput("XShape", "XShape is just used to store the shape and lod of X, which will " "be used in UnsqueezeGradOp.") - .AsIntermediate(); + .AsIntermediate() + .AsExtra(); } };