From 4d36c1c75d2ca46d4785ffc58670060020906051 Mon Sep 17 00:00:00 2001 From: wangchaochaohu Date: Sun, 13 Oct 2019 10:07:48 +0800 Subject: [PATCH] fix the reduce bug test=develop (#20102) (#20557) --- paddle/fluid/operators/reduce_ops/reduce_op.h | 6 ++++++ .../paddle/fluid/tests/unittests/test_imperative_basic.py | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/reduce_ops/reduce_op.h b/paddle/fluid/operators/reduce_ops/reduce_op.h index cbc4adf9588..639ac473bff 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 245c6a6ecc0..d1b5642406d 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 -- GitLab