From 0c71edc3c6c348644f687b61554e679948444979 Mon Sep 17 00:00:00 2001 From: dyning Date: Tue, 7 Sep 2021 14:49:48 +0800 Subject: [PATCH] operators/flatten_op.cc add AsExtra (#35471) * operators/flatten_op.cc add AsExtra * operators/flatten_op.cc add AsExtra * fix format --- paddle/fluid/operators/flatten_op.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/operators/flatten_op.cc b/paddle/fluid/operators/flatten_op.cc index 778bab9f4dd..0858a43838b 100644 --- a/paddle/fluid/operators/flatten_op.cc +++ b/paddle/fluid/operators/flatten_op.cc @@ -188,8 +188,8 @@ class Flatten2Op : public framework::OperatorWithKernel { // are the same. ctx->ShareLoD("X", "Out"); } - - OP_INOUT_CHECK(ctx->HasOutput("XShape"), "Output", "XShape", "Flatten2"); + if (!ctx->HasOutput("XShape")) return; + // OP_INOUT_CHECK(ctx->HasOutput("XShape"), "Output", "XShape", "Flatten2"); std::vector xshape_dims(in_dims.size() + 1); xshape_dims[0] = 0; for (int i = 0; i < in_dims.size(); ++i) { @@ -207,7 +207,8 @@ class Flatten2OpMaker : public FlattenOpMaker { AddOutput("XShape", "XShape is just used to store the shape and lod of X, which will " "be used in FlattenGradOp.") - .AsIntermediate(); + .AsIntermediate() + .AsExtra(); } }; @@ -281,8 +282,8 @@ class FlattenContiguousRangeOp : public framework::OperatorWithKernel { // are the same. ctx->ShareLoD("X", "Out"); } - - OP_INOUT_CHECK(ctx->HasOutput("XShape"), "Output", "XShape", "Flatten2"); + if (!ctx->HasOutput("XShape")) return; + // OP_INOUT_CHECK(ctx->HasOutput("XShape"), "Output", "XShape", "Flatten2"); std::vector xshape_dims(in_dims.size() + 1); xshape_dims[0] = 0; for (int i = 0; i < in_dims.size(); ++i) { @@ -361,7 +362,8 @@ Case 2: AddOutput("XShape", "XShape is just used to store the shape and lod of X, which will " "be used in FlattenGradOp.") - .AsIntermediate(); + .AsIntermediate() + .AsExtra(); } }; -- GitLab