-
Notifications
You must be signed in to change notification settings - Fork 552
Implement collective gather op #9435
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
base: master
Are you sure you want to change the base?
Conversation
test/pjrt/test_collective_ops_tpu.py
Outdated
@staticmethod | ||
def _scatter(): | ||
dist.init_process_group("xla", init_method='xla://') | ||
device = torch_xla.device() | ||
world_size = xr.world_size() | ||
tensors = None | ||
if xr.global_ordinal() == 0: | ||
tensors = [ | ||
torch.tensor([i], device=device, dtype=torch.float) | ||
for i in range(world_size) | ||
] | ||
|
||
output_tensor = torch.tensor([-1], dtype=torch.float, device=device) | ||
dist.scatter(output_tensor, tensors, src=0) | ||
return output_tensor.cpu() | ||
|
||
def test_scatter(self): | ||
"""self._scatter instantiates a list of tensors [[0], [1], ..., [n-1]] | ||
on device 0, then scatters it. Device i should therefore receive [i].""" | ||
results = pjrt.run_multiprocess(self._scatter) | ||
for ordinal, value in results.items(): | ||
np.testing.assert_array_equal(value, [ordinal]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moving this test into the appropriate class
test/pjrt/test_collective_ops_tpu.py
Outdated
@staticmethod | ||
def _scatter(): | ||
dist.init_process_group("xla", init_method='xla://') | ||
device = torch_xla.device() | ||
world_size = xr.world_size() | ||
tensors = None | ||
if xr.global_ordinal() == 0: | ||
tensors = [ | ||
torch.tensor([i], device=device, dtype=torch.float) | ||
for i in range(world_size) | ||
] | ||
|
||
output_tensor = torch.tensor([-1], dtype=torch.float, device=device) | ||
dist.scatter(output_tensor, tensors, src=0) | ||
return output_tensor.cpu() | ||
|
||
def test_scatter(self): | ||
"""self._scatter instantiates a list of tensors [[0], [1], ..., [n-1]] | ||
on device 0, then scatters it. Device i should therefore receive [i].""" | ||
results = pjrt.run_multiprocess(self._scatter) | ||
for ordinal, value in results.items(): | ||
np.testing.assert_array_equal(value, [ordinal]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copied from above
Failing tests are expected until the TPU CI cluster is updated to use python 3.12. See #9434 |
…/xla into bfolie/gather-collective
#9315