mindspore.mint.distributed.all_to_all
- mindspore.mint.distributed.all_to_all(output_tensor_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_tensor_list (List[Tensor]) – List of tensors that indicate the gathered from remote ranks.
input_tensor_list (List[Tensor]) – List of tensors to scatter to the remote rank.
group (str, optional) – The communication group to work on. If
None
, which means"hccl_world_group"
in Ascend. Default:None
.async_op (bool, optional) – Whether this operator should be an async operator. Default:
False
.
- Returns
CommHandle, CommHandle is an async work handle, if async_op is set to True. CommHandle will be None, when async_op is False.
- Raises
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend 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 mindspore as ms >>> from mindspore.mint.distributed import init_process_group, get_rank >>> from mindspore.mint.distributed import all_to_all >>> from mindspore import Tensor >>> >>> init_process_group() >>> this_rank = get_rank() >>> if this_rank == 0: >>> send_tensor_list = [Tensor(1.), Tensor([[2, 3], [4, 5.]])] >>> recv_tensor_list = [Tensor((0), dtype=ms.float32), Tensor([0, 0.])] >>> if this_rank == 1: >>> send_tensor_list = [Tensor([2, 2.]), Tensor([4, 5, 6, 7.])] >>> recv_tensor_list = [Tensor([[0, 0.],[0, 0]]), Tensor([0, 0, 0, 0.])] >>> handle = all_to_all(recv_tensor_list, send_tensor_list) >>> print(recv_tensor_list) 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]))