Skip to content
Merged
Changes from all 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
17 changes: 15 additions & 2 deletions test/test_mp_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import torch_xla.distributed.xla_multiprocessing as xmp


def all_reduce(tensor):
return xm.all_reduce(xm.REDUCE_SUM, tensor)


def _mp_fn(index):
device = xm.xla_device()
world_size = xm.xrt_world_size()
Expand All @@ -13,23 +17,32 @@ def _mp_fn(index):
twos = ones + 1.0
threes = ones + 2.0
fours = ones + 3.0
fives = ones + 4.0
scale = 0.5
xones = ones.to(device)
xtwos = twos.to(device)
xthrees = threes.to(device)
xfours = fours.to(device)
xfives = fives.to(device)
xm.all_reduce(xm.REDUCE_SUM, [xones, xtwos])
xthrees = xm.all_reduce(xm.REDUCE_SUM, xthrees)
xthrees = all_reduce(xthrees)
xfours = xm.all_reduce(xm.REDUCE_SUM, xfours, scale=scale)

compiled_all_reduce = torch.compile(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer move dynamo tests under test/dynamo, we can do that in a follow up pr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do that as a follow up.

all_reduce, backend='torchxla_trace_once', fullgraph=True)
xfives = compiled_all_reduce(xfives)

if (not xones.cpu().allclose(ones * float(world_size)) or
not xtwos.cpu().allclose(twos * float(world_size)) or
not xthrees.cpu().allclose(threes * float(world_size)) or
not xfours.cpu().allclose(fours * float(world_size) * scale)):
not xfours.cpu().allclose(fours * float(world_size) * scale) or
not xfives.cpu().allclose(fives * float(world_size))):
print('xm.all_reduce() produced wrong reductions', file=sys.stderr)
print(xones, file=sys.stderr)
print(xtwos, file=sys.stderr)
print(xthrees, file=sys.stderr)
print(xfours, file=sys.stderr)
print(xfives, file=sys.stderr)
sys.exit(1)
else:
print(
Expand Down