- class mindspore.ops.ReduceOp
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:
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.
For more, refer to example. This needs to run in an environment with multiple graphics cards. The user needs to preset communication environment variables before running the following example, please check the details on the official website of MindSpore.
- Supported Platforms:
>>> 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) ... ... 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) [[2. 2. 2. 2. 2. 2. 2. 2.] [2. 2. 2. 2. 2. 2. 2. 2.]]