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
Fix typing errors in torch.distributed.distributed_c10d.* #47532
Conversation
[ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 23127ef (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages: docker-pytorch-linux-bionic-py3.8-gcc9 (1/2)Step: "Check if image should be built" (full log | diagnosis details | 🔁 rerun)
|
@@ -1335,7 +1360,7 @@ def all_gather_multigpu(output_tensor_lists, | |||
|
|||
def _object_to_tensor(obj): | |||
buffer = pickle.dumps(obj) | |||
byte_storage = torch.ByteStorage.from_buffer(buffer) | |||
byte_storage = torch.ByteStorage.from_buffer(buffer) # type: ignore[attr-defined] |
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.
Neither mypy nor I can find from_buffer() function in torch.ByteStorage.
@@ -1389,7 +1414,7 @@ def all_gather_object(object_list, obj, group=group.WORLD): | |||
input_tensor, local_size = _object_to_tensor(obj) | |||
group_backend = get_backend(group) | |||
is_nccl_backend = group_backend == Backend.NCCL | |||
current_device = torch.device("cpu") | |||
current_device: Union[int, torch.device] = torch.device("cpu") |
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.
torch.cuda.current_device() returns int, and torch.device() returns torch.device.
@@ -1400,7 +1425,7 @@ def all_gather_object(object_list, obj, group=group.WORLD): | |||
# Gather all local sizes. This is so that we can find the max size, and index | |||
# until the correct size when deserializing the tensors. | |||
group_size = get_world_size(group=group) | |||
object_sizes_tensor = torch.zeros(group_size, dtype=int, device=current_device) | |||
object_sizes_tensor = torch.zeros(group_size, dtype=int, device=current_device) # type: ignore[call-overload] |
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.
If is_nccl_backend is set, current_device is an int, which will not be accepted by torch.zeros().
@@ -1410,7 +1435,7 @@ def all_gather_object(object_list, obj, group=group.WORLD): | |||
# Resize tensor to max size across all ranks. | |||
input_tensor.resize_(max_object_size) | |||
coalesced_output_tensor = torch.empty( | |||
max_object_size * group_size, dtype=torch.uint8, device=current_device | |||
max_object_size * group_size, dtype=torch.uint8, device=current_device # type: ignore[arg-type] |
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.
If is_nccl_backend is set, current_device is an int, which will not be accepted by torch.empty().
if is_nccl_backend: | ||
# See note about using torch.cuda.current_device() here in docstring. | ||
# We cannot simply use my_rank since rank == device is not necessarily | ||
# true. | ||
current_device = torch.cuda.current_device() | ||
object_sizes_tensor = object_sizes_tensor.to(current_device) | ||
object_sizes_tensor = object_sizes_tensor.to(current_device) | ||
object_sizes_tensor = object_sizes_tensor.to(current_device) # type: ignore[call-overload] |
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.
If is_nccl_backend is set, current_device is an int, which will not be accepted by torch.Tensor.to().
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Differential Revision: [D24952501](https://our.internmc.facebook.com/intern/diff/D24952501) [ghstack-poisoned]
Differential Revision: [D24952501](https://our.internmc.facebook.com/intern/diff/D24952501) [ghstack-poisoned]
Differential Revision: [D24952501](https://our.internmc.facebook.com/intern/diff/D24952501) [ghstack-poisoned]
Differential Revision: [D24952501](https://our.internmc.facebook.com/intern/diff/D24952501) [ghstack-poisoned]
Differential Revision: [D24952501](https://our.internmc.facebook.com/intern/diff/D24952501) [ghstack-poisoned]
Stack from ghstack:
Differential Revision: D24952501