diff --git a/paddle/fluid/operators/reshape_op.cc b/paddle/fluid/operators/reshape_op.cc index 5dd9dfba43e46ee50d7043a88792ae240700e4d0..cf97eac3fbe87f5b79c421be34210634454ec97f 100644 --- a/paddle/fluid/operators/reshape_op.cc +++ b/paddle/fluid/operators/reshape_op.cc @@ -186,13 +186,16 @@ class ReshapeOp : public framework::OperatorWithKernel { output_shape[unk_dim_idx] = -1; } } else { - PADDLE_ENFORCE_EQ( - capacity, in_size, - "ShapeError: The 'shape' in ReshapeOp is invalid. " - "The input tensor X'size must be equal to the capacity of 'shape'. " - "But received X's shape = [%s], X's size = %d, 'shape' is [%s], the " - "capacity of 'shape' is %d.", - in_dims, in_size, framework::make_ddim(shape), capacity); + if (all_positive) { + PADDLE_ENFORCE_EQ( + capacity, in_size, + "ShapeError: The 'shape' in ReshapeOp is invalid. " + "The input tensor X'size must be equal to the capacity of 'shape'. " + "But received X's shape = [%s], X's size = %d, 'shape' is [%s], " + "the " + "capacity of 'shape' is %d.", + in_dims, in_size, framework::make_ddim(shape), capacity); + } } return framework::make_ddim(output_shape); }