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

Allow scalar all gather #5797

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Changes from 3 commits
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
6 changes: 5 additions & 1 deletion torch_xla/distributed/xla_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ def allreduce(self, tensors, all_reduce_options):

def allgather(self, output_tensors_list, input_tensors, opts=None):
for input_tensor, output_tensors in zip(input_tensors, output_tensors_list):
is_scalar = (input_tensor.dim() == 0)
if is_scalar:
input_tensor = torch.reshape(input_tensor, (1,))
result = xm.all_gather(input_tensor, groups=self._mesh, pin_layout=False)
for i, slice in enumerate(torch.split(result, input_tensor.shape[0])):
with torch.no_grad():
output_tensors[i].copy_(slice)
output_tensors[i].copy_(
slice if not is_scalar else torch.reshape(slice, ()))

JackCaoG marked this conversation as resolved.
Show resolved Hide resolved
return _ret_work([t for sublist in output_tensors_list for t in sublist])

Expand Down
Loading