From 192b3033e9ccc0d4cad918f6c64f04246f647608 Mon Sep 17 00:00:00 2001 From: Weilong Wu Date: Tue, 6 Sep 2022 14:08:45 +0800 Subject: [PATCH] [Eager, Performance optimization] reduce_all interface move reduce_all flag from python to C++ (#45744) * [Eager, Performance optimization] move reduce_all flag from python to c++ * polish reduce_all * fix ci error * fix errors --- paddle/phi/kernels/reduce_all_kernel.cc | 3 +++ python/paddle/fluid/layers/nn.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/paddle/phi/kernels/reduce_all_kernel.cc b/paddle/phi/kernels/reduce_all_kernel.cc index 9b4515ee290..5b8d2cbecca 100644 --- a/paddle/phi/kernels/reduce_all_kernel.cc +++ b/paddle/phi/kernels/reduce_all_kernel.cc @@ -26,6 +26,9 @@ void AllKernel(const Context& dev_ctx, bool keep_dim, DenseTensor* out) { bool reduce_all = false; + if (dims.size() == 0 || static_cast(dims.size()) == x.dims().size()) { + reduce_all = true; + } AllRawKernel(dev_ctx, x, dims, keep_dim, reduce_all, out); } diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 53994eed80f..b5615ee1bb7 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -5032,6 +5032,10 @@ def reduce_all(input, dim=None, keep_dim=False, name=None): """ if dim is not None and not isinstance(dim, list): dim = [dim] + + if in_dygraph_mode(): + return _C_ops.all(input, dim if dim != None else [], keep_dim) + check_variable_and_dtype(input, 'input', ('bool'), 'reduce_all') helper = LayerHelper('reduce_all', **locals()) out = helper.create_variable_for_type_inference(dtype=helper.input_dtype()) -- GitLab