Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Support gather operation in NCCL backend #1061

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mmengine/dist/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ def gather(data: Tensor,
Calling ``gather`` in non-distributed environment dose nothing
and just returns a list containing :attr:`data` itself.

Note:
``NCCL`` backend does not support ``gather``.

Note:
Unlike PyTorch ``torch.distributed.gather``, :meth:`gather` in
MMEngine does not pass in an empty list ``gather_list`` and returns
Expand Down Expand Up @@ -251,7 +248,14 @@ def gather(data: Tensor,
else:
gather_list = []

torch_dist.gather(data, gather_list, dst, group)
# Check if the backend is NCCL
if get_backend(group) == torch_dist.Backend.NCCL:
if get_rank(group) == dst:
gather_list = torch.cuda.comm.gather(data, dst, group)
else:
torch.cuda.comm.gather(data, dst, group)
else:
torch_dist.gather(data, gather_list, dst, group)

if get_rank(group) == dst:
return cast_data_device(gather_list, input_device) # type: ignore
Expand Down