Functional Collectives
.. automodule:: torch.distributed.functional_collectives
Functional collectives take the group as an argument. Under torch.compile they are traced into the graph so the compiler can reorder and overlap communication.
import torch.distributed as dist
import torch.distributed.functional_collectives as funcol
# group can be a ProcessGroup, DeviceMesh, (DeviceMesh, dim) or group name.
out = funcol.all_reduce(tensor, "sum", group=dist.group.WORLD)
gathered = funcol.all_gather_single(tensor, gather_dim=0, group=mesh)
.. autofunction:: all_reduce
.. autofunction:: all_reduce_coalesced
.. autofunction:: all_gather_single
.. autofunction:: all_gather_single_coalesced
.. autofunction:: reduce_scatter_single
.. autofunction:: reduce_scatter_single_coalesced
.. autofunction:: all_to_all_single
.. autofunction:: broadcast
.. autofunction:: permute_tensor
.. autofunction:: wait_tensor
.. autofunction:: wait_tensors
.. autoclass:: AsyncCollectiveTensor
:members: wait, trigger_wait, tolist, numpy