mindspore.ops.Broadcast
- class mindspore.ops.Broadcast(root_rank, group=GlobalComm.WORLD_COMM_GROUP)[源代码]
对输入数据整组广播。
Note
集合中的所有进程的Tensor的shape和数据格式相同。
参数:
root_rank (int) - 表示发送源的进程编号。除发送数据的进程外,存在于所有进程中。
group (str) - 表示通信域。默认值:”hccl_world_group”。
输入:
input_x (Tensor) - Tensor的shape为 \((x_1, x_2, ..., x_R)\) 。
输出:
Tensor,shape与输入相同,即 \((x_1, x_2, ..., x_R)\) 。内容取决于 root_rank device的数据。
异常:
TypeError - root_rank不是int或group不是str。
- 支持平台:
Ascend
GPU
样例:
>>> # This example should be run with multiple processes. >>> # Please refer to the Programming Guide > Distributed Training -> Distributed Parallel Usage Example >>> # on mindspore.cn and focus on the contents of these three parts: Configuring Distributed Environment >>> # Variables, Calling the Collective Communication Library, Running The Script. >>> from mindspore import Tensor >>> from mindspore import context >>> from mindspore.communication import init >>> import mindspore.nn as nn >>> import mindspore.ops as ops >>> import numpy as np >>> >>> context.set_context(mode=context.GRAPH_MODE) >>> init() >>> class Net(nn.Cell): ... def __init__(self): ... super(Net, self).__init__() ... self.broadcast = ops.Broadcast(1) ... ... def construct(self, x): ... return self.broadcast((x,)) ... >>> input_x = Tensor(np.ones([2, 4]).astype(np.int32)) >>> net = Net() >>> output = net(input_x) >>> print(output) (Tensor(shape[2,4], dtype=Int32, value= [[1, 1, 1, 1], [1, 1, 1, 1]]),)