TensorDictBase.recv#
- TensorDictBase.recv(src: int | 'TensorDictPipe' | None = None, *, group: 'torch.distributed.ProcessGroup' | None = None, group_src: int | None = None, init_tag: int = 0, pseudo_rand: bool = False, consolidated: bool = False) int#
Receives the leaves that
send()sends, and writes them into the tensordict in place.The tensordict must have the keys, shapes and dtypes of the tensordict that the sender sends. See
send()for an example, and Distributed tensordicts.- Parameters:
src (int or TensorDictPipe, optional) – the global rank of the sender, or a
TensorDictPipeto receive from with UCXX, which ignores the other arguments. Exclusive withgroup_src: pass exactly one of them. Defaults toNone.- Keyword Arguments:
group (torch.distributed.ProcessGroup, optional) – the process group. Defaults to
None, the default process group.group_src (int, optional) – the rank of the sender in
group, which must be given. Exclusive withsrc. The messages then go through the backend ofgroupdirectly, sogroupcan be a standaloneProcessGroupbuilt on a store, never registered byinit_process_group()ornew_group(). Defaults toNone.init_tag (int, optional) – the
init_tagthat the sender passed. Defaults to0.pseudo_rand (bool, optional) – the
pseudo_randthat the sender passed. Defaults toFalse.consolidated (bool, optional) – if
True, receives one message into the consolidated storage of the tensordict, which updates all its leaves, as sent bysend(consolidated=True). The tensordict must be consolidated already, for example byconsolidate(metadata=True)orfrom_remote_init(); otherwise anAttributeErroris raised.init_tagandpseudo_randare ignored. Defaults toFalse.
- Returns:
With a pipe, the received tensordict, which is
selfonly if the tensordict is consolidated with the layout of the data, so use the return value. Withconsolidated=True,None. Otherwise, the tag of the last leaf received.- Raises:
ValueError – if both or none of
srcandgroup_srcare given, or ifgroup_srcis given withoutgroup.
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.