diff --git a/paddle/fluid/operators/expand_op.cc b/paddle/fluid/operators/expand_op.cc index 40f7c1c54c861abebc84428f55e2769ac8969f0f..6aa4c76b9ce7f52f5816ea136e04b32a7d2e8d44 100644 --- a/paddle/fluid/operators/expand_op.cc +++ b/paddle/fluid/operators/expand_op.cc @@ -48,7 +48,7 @@ class ExpandOp : public framework::OperatorWithKernel { } // set the first dim to -1 in compile time - if (!ctx->IsRuntime()) { + if (!ctx->IsRuntime() && x_dims[0] < 0) { out_shape[0] = x_dims[0]; } @@ -115,7 +115,7 @@ class ExpandGradOp : public framework::OperatorWithKernel { auto out_dims = ctx->GetInputDim(framework::GradVarName("Out")); size_t start_pos = 0u; - if (!ctx->IsRuntime()) { + if (!ctx->IsRuntime() && x_dims[0] < 0) { PADDLE_ENFORCE_EQ( x_dims[0], out_dims[0], "The first dimension size of Input(Out@GRAD) should be "