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

Add descriptions to accelerator broadcast function/clean up all_gather #6044

Merged
merged 3 commits into from
Feb 18, 2021
Merged
Changes from 2 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
13 changes: 9 additions & 4 deletions pytorch_lightning/accelerators/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,18 @@ def barrier(self, name: Optional[str] = None) -> None:
self.training_type_plugin.barrier(name=name)

def broadcast(self, obj: object, src: int = 0) -> object:
Copy link
Member

Choose a reason for hiding this comment

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

shall we then rather call source_rank?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its called source in the lower level pytorch call that is commonly used outside of TPU/some training type plugin:

https://pytorch.org/docs/stable/distributed.html#torch.distributed.broadcast

So I think it might be alright to keep it as is!

Copy link
Contributor

Choose a reason for hiding this comment

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

I vote for keep :)

"""Broadcasts an object to all processes"""
"""Broadcasts an object to all processes, such that the src object is broadcast to all other ranks if needed.

Args:
obj: Object to broadcast to all process, usually a tensor or collection of tensors.
src: The source rank of which the object will be broadcast from (Default: 0)
SeanNaren marked this conversation as resolved.
Show resolved Hide resolved
"""
return self.training_type_plugin.broadcast(obj, src)

def all_gather(self, tensor: Union[torch.Tensor], group: Optional[Any] = None, sync_grads: bool = False):
"""
Function to gather a tensor from several distributed processes
Function to gather a tensor from several distributed processes.

Args:
tensor: tensor of shape (batch, ...)
group: the process group to gather results from. Defaults to all processes (world)
Expand All @@ -409,8 +415,7 @@ def process_dataloader(self, dataloader: Union[Iterable, DataLoader]) -> Union[I
@property
def results(self) -> Any:
"""
The results of the last training/testing run will be cached here.
The results of the last training/testing run will be cached within the training type plugin.
In distributed training, we make sure to transfer the results to the appropriate master process.
"""
# TODO: improve these docs
return self.training_type_plugin.results