mindspore.ops.AllGatherV
- class mindspore.ops.AllGatherV(group=GlobalComm.WORLD_COMM_GROUP)[源代码]
从指定的通信组中收集不均匀的张量,并返回全部收集的张量。
说明
只支持一维的输入,使用该接口前需要将输入数据展开成一维。
- 参数:
group (str,可选) - 工作的通信组,默认值:
GlobalComm.WORLD_COMM_GROUP
(即Ascend平台为"hccl_world_group"
,GPU平台为"nccl_world_group"
)。
- 输入:
input_x (Tensor) - 一维待汇聚的张量,shape为 \((x_1)\)。
output_split_sizes (Union[tuple[int], list[int], Tensor]) - 一维张量,所有rank的汇聚数据量列表,基本单位是Tensor的数据类型。
- 输出:
Tensor,从每张卡上聚合的一维数据结果。如果结果为空,则返回空张量,且值无意义。
- 异常:
RuntimeError - 目标设备无效、后端无效,或者分布式初始化失败。
- 支持平台:
Ascend
GPU
样例:
>>> import mindspore as ms >>> from mindspore.ops import AllGatherV >>> import mindspore.nn as nn >>> from mindspore.communication import init, get_rank >>> from mindspore import Tensor >>> >>> ms.set_context(mode=ms.GRAPH_MODE) >>> init() >>> class Net(nn.Cell): ... def __init__(self): ... super(Net, self).__init__() ... self.allgatherv = AllGatherV() ... ... def construct(self, x, output_split_sizes): ... return self.allgatherv(x, output_split_sizes) ... >>> rank = get_rank() >>> data = [i for i in range(rank + 3)] >>> input_x = Tensor(data) >>> output_split_sizes = [3, 4] >>> net = Net() >>> output = net(input_x, output_split_sizes) >>> print(output) [0 1 2 0 1 2 3]
- 教程样例: