From bc6126dd073b2745608f6461ef5bd13c09e495f3 Mon Sep 17 00:00:00 2001 From: wangchaochaohu Date: Thu, 10 Oct 2019 14:47:41 +0800 Subject: [PATCH] fix the reduce bug test=develop (#20102) --- 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 cbc4adf958..639ac473bf 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 245c6a6ecc..d1b5642406 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