mindspore.ops.ReduceOp

class mindspore.ops.ReduceOp[source]

Operation options for reducing tensors. This is an enumerated type, not an operator. Mainly used in data parallel mode.

The main calling methods are as follows:

  • SUM: ReduceOp.SUM.

  • MAX: ReduceOp.MAX.

  • MIN: ReduceOp.MIN.

  • PROD: ReduceOp.PROD.

There are four kinds of operation options, “SUM”, “MAX”, “MIN”, and “PROD”.

  • SUM: Take the sum.

  • MAX: Take the maximum.

  • MIN: Take the minimum.

  • PROD: Take the product.

Note

For more, refer to example. This needs to run in an environment with multiple graphics cards.

Supported Platforms:

Ascend GPU

Examples

>>> from mindspore.communication import init
>>> from mindspore import Tensor, ops
>>> from mindspore.ops import ReduceOp
>>> import mindspore.nn as nn
>>>
>>> init()
>>> class Net(nn.Cell):
...     def __init__(self):
...         super(Net, self).__init__()
...         self.allreduce_sum = ops.AllReduce(ReduceOp.SUM, group="nccl_world_group")
...
...     def construct(self, x):
...         return self.allreduce_sum(x)
...
>>> input_ = Tensor(np.ones([2, 8]).astype(np.float32))
>>> net = Net()
>>> output = net(input_)
>>> print(output)
[[4. 5. 6. 0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0.]]