-
Notifications
You must be signed in to change notification settings - Fork 20
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
Adds reduce_scatter
into torchft
#102
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
AllreduceOptions, | ||
BroadcastOptions, | ||
ReduceOp, | ||
ReduceScatterOptions, | ||
_resolve_process_group, | ||
) | ||
from torch.distributed import ( | ||
|
@@ -60,6 +61,31 @@ def dummy_init_pg() -> None: | |
) | ||
|
||
|
||
def _should_run_collective(collective_str: str, backend_str: str, device: str) -> bool: | ||
"""Verify if the collective is supported by the backend and device. | ||
|
||
See https://pytorch.org/docs/stable/distributed.html#backends for the | ||
supported collectives / backends / devices matrix. | ||
|
||
""" | ||
if "nccl" in backend_str.lower(): | ||
# all collectives are supported for NCCL/CUDA but none on CPU. | ||
return device == "cuda" | ||
elif "gloo" in backend_str.lower(): | ||
if device == "cuda": | ||
# GLOO/GPU only supports broadcast and all_reduce. | ||
if collective_str in ["broadcast", "all_reduce"]: | ||
return True | ||
return False | ||
else: # cpu | ||
if collective_str in ["reduce_scatter", "all_to_all"]: | ||
return False | ||
return True | ||
else: | ||
# Non defined backends (e.g. ErrorSwallowing) should continue to work. | ||
return True | ||
|
||
|
||
def _test_pg( | ||
pg: ProcessGroup, | ||
example_tensor: torch.Tensor = torch.randn((2, 3), dtype=torch.float32), | ||
|
@@ -94,9 +120,25 @@ def check_tensors(arg: Any) -> None: # pyre-ignore[2] | |
("allgather", (output_tensors, [input_tensor], AllgatherOptions())), | ||
("broadcast", (tensor_list, BroadcastOptions())), | ||
("broadcast_one", (input_tensor, 0)), | ||
( | ||
"reduce_scatter", | ||
(output_tensors[0], [[input_tensor]], ReduceScatterOptions()), | ||
), | ||
] | ||
works: Dict[str, dist._Work] = {} | ||
|
||
try: | ||
backend_str = pg.getBackendName() | ||
device = example_tensor.device | ||
if type(device) is torch.device: | ||
device = device.type | ||
except NotImplementedError as e: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we getting a NotImplementedError? which backend is this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just for the |
||
backend_str = "" | ||
device = "" | ||
|
||
for coll_str, args in collectives: | ||
if not _should_run_collective(coll_str, backend_str=backend_str, device=device): | ||
continue | ||
coll = getattr(pg, coll_str) | ||
work = coll(*args) | ||
works[coll_str] = work | ||
|
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.
oh wow -- didn't realize we don't support these on Gloo, good to know! cc @c-p-i-o
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.
ye, we miss many APIs on Gloo.
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.
this approach seems nice and explicit. but is it possible to instead just try: the test, and except: some specific NYI error? (i'm not sure if we raise a consistent type of NYI exception from backends?)