mindspore.dataset.Dataset.send
- Dataset.send(tensor=None, dst=0, group=None)[source]
The dataset communication interface sends data to the target Dataset, which can be received through
mindspore.dataset.Dataset.recv.The send operation only send data once.
Note
This is an experimental API that is subject to change or deletion.
- Parameters
tensor (Union[Tensor, list[Tensor]], optional) – List of the Tensor(s) to send. Default:
None, retrieve data from the current dataset and send it.dst (Union[int, list[int]], optional) – List of the dst rank id(s) to send. It cannot be the current Rank ID or contain the current Rank ID. Default:
0, which indicates send data to dst rank 0.group (str, optional) – The communication group to work on. The group is created by
mindspore.communication.create_group(). Default:None, which indicatesGlobalComm.WORLD_COMM_GROUP.
Examples
>>> import mindspore as ms >>> from mindspore.mint.distributed import init_process_group >>> from mindspore.mint.distributed import get_rank >>> from mindspore import Tensor >>> import mindspore.dataset as ds >>> import numpy as np >>> >>> # Launch 8 processes by msrun --worker_num=8 --local_worker_num=8 script.py >>> init_process_group() >>> this_rank = get_rank() >>> >>> # Create a dataset with 3 columns >>> input_columns = ["column1", "column2", "column3"] >>> dataset = ds.GeneratorDataset([(1, 2, 3), (3, 4, 5), (5, 6, 7)], column_names=input_columns) >>> >>> # Send a data from the current dataset to the dst rank: 0 >>> if this_rank == 2: >>> dataset.send() >>> if this_rank == 0: >>> data = dataset.recv(2) >>> >>> # Send the data "send_tensor" to the dst rank: 7 >>> if this_rank == 0: >>> send_tensor = Tensor(np.zeros([2, 2, 3]), ms.float32) >>> dataset.send(send_tensor, 7) >>> if this_rank == 7: >>> recv_tensor = dataset.recv(0) >>> >>> # Send the list of data to dst rank [0, 2, 4, 6] >>> if this_rank in [1, 3, 5, 7]: >>> send_data = Tensor(np.zeros([2, 2, 3]), ms.float32) >>> send_label = Tensor(np.zeros([3,]), ms.bool) >>> dataset.send([send_data, send_label], [0, 2, 4, 6]) >>> if this_rank in [0, 2, 4, 6]: >>> recv_tensors = dataset.recv([1, 3, 5, 7])