diff --git a/paddle/fluid/operators/reduce_ops/reduce_op.h b/paddle/fluid/operators/reduce_ops/reduce_op.h index cbc4adf95881a75ac4dddc15d8e7a369e583c0c7..639ac473bff8dbcd5e4337cd958c431203986efc 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_op.h +++ b/paddle/fluid/operators/reduce_ops/reduce_op.h @@ -171,6 +171,12 @@ class ReduceOp : public framework::OperatorWithKernel { "dimensions = %d, X's shape = [%s].", x_rank, x_dims); auto dims = ctx->Attrs().Get>("dim"); + PADDLE_ENFORCE_GT( + dims.size(), 0, + "ShapeError: The input dim dimensions of Reduce " + "shoud be greater than 0. But received the dim dimesions of Reduce " + " = %d", + dims.size()); for (size_t i = 0; i < dims.size(); ++i) { PADDLE_ENFORCE_LT(dims[i], x_rank, diff --git a/python/paddle/fluid/tests/unittests/test_imperative_basic.py b/python/paddle/fluid/tests/unittests/test_imperative_basic.py index 245c6a6ecc008301964f3baa41370dcbd5793e55..d1b5642406dbbad9edb5d0b590a4060c10309487 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_basic.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_basic.py @@ -138,8 +138,7 @@ class SimpleRNNCell(fluid.Layer): type='reduce_sum', inputs={'X': softmax_out}, outputs={'Out': reduce_out}, - attrs={'dim': [], - 'keep_dim': False, + attrs={'keep_dim': False, 'reduce_all': True}) return reduce_out, hidden