mindspore.communication.comm_func.all_to_all_with_output_shape

View Source On Gitee
mindspore.communication.comm_func.all_to_all_with_output_shape(output_shape_list, input_tensor_list, group=None, async_op=False)[source]

scatter and gather list of tensor to/from all rank according to input/output tensor list.

Note

tensor shape in output_shape_list and input_tensor_list should be match across ranks. Only support PyNative mode, Graph mode is not currently supported.

Parameters
  • output_shape_list (Union[Tuple(Tensor), List(Tensor), Tuple(Tuple(int))]) – List of shape that indicate the gathered tensors shape from remote ranks.

  • input_tensor_list (Union[Tuple(Tensor), List(Tensor)]) – List of tensors to scatter to the remote rank.

  • group (str, optional) – The communication group to work on. Default: None, which means "hccl_world_group" on Ascend, "nccl_world_group" on GPU.

  • async_op (bool, optional) – Whether this operator should be an async operator. Default: False .

Returns

Tuple(Tuple(Tensor), CommHandle), the tensors is gathered from remote ranks. CommHandle is an async work handle, if async_op is set to True. CommHandle will be None, when async_op is False.

Raises
  • TypeError – If input_tensor_list is not list of tensors.

  • TypeError – If output_shape_list is not list of tuple or tensors.

  • TypeError – If tensors in input_tensor_list are not the same type.

Supported Platforms:

Ascend

Examples

Note

Before running the following examples, you need to configure the communication environment variables.

For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.

This example should be run with 2 devices.

>>> import numpy as np
>>> import mindspore as ms
>>> import mindspore.communication as comm
>>>
>>> comm.init()
>>> this_rank = comm.get_rank()
>>> if this_rank == 0:
>>>     send_tensor_list = [ms.Tensor(1.), ms.Tensor([[2, 3], [4, 5.]])]
>>>     recv_tensor_list = [(), (2,)]
>>> if this_rank == 1:
>>>     send_tensor_list = [ms.Tensor([2, 2.]), ms.Tensor([4, 5, 6, 7.])]
>>>     recv_tensor_list = [(2, 2), (4,)]
>>> output = comm.comm_func.all_to_all_with_output_shape(recv_tensor_list, send_tensor_list)
>>> print(output)
rank 0:
(Tensor(shape=[], dtype=Float32, value= 1),
 Tensor(shape=[2], dtype=Float32, value= [2.00000000e+00, 2.00000000e+00]))
rank 1:
(Tensor(shape=[2, 2], dtype=Float32, value=
[[2.00000000e+00, 3.00000000e+00],
 [4.00000000e+00, 5.00000000e+00]]),
 Tensor(shape=[4], dtype=Float32, value=[4.00000000e+00, 5.00000000e+00, 6.00000000e+00, 7.00000000e+00]))