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

Throw error when torch iterable was not split by rank or split by worker #107

Merged
merged 3 commits into from
Feb 10, 2023

Conversation

pzdkn
Copy link
Contributor

@pzdkn pzdkn commented Jan 17, 2023

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
List any dependencies that are required for this change.

Fixes # issue

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring including code style reformatting
  • Other (please describe):

Checklist:

  • I have read the contributing guideline doc (external contributors only)
  • Lint and unit tests pass locally with my changes
  • I have kept the PR small so that it can be easily reviewed
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • All dependency changes have been reflected in the pip requirement files.

Copy link
Contributor

@AlirezaSohofi AlirezaSohofi left a comment

Choose a reason for hiding this comment

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

Looks good in general, left some minor comments

yield from self.source

def _check_for_rank_split(self, source: Composable) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

here we should check if we are actually in the multi-rank environment. If not this check should be skipped.

Would be good to add a test for this case too: we are not in the multi-rank / multi-worker environment and to_torch_iterable is called.

else:
return self._check_for_rank_split(source.source)

def _check_for_worker_split(self, source: Composable) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@@ -66,8 +66,36 @@ def __init__(self) -> None:

def __iter__(self) -> Iterator:
"""Method to iterate over the source"""
if not self._check_for_rank_split(self.source):
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

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

We can have a custom exception for this, PytorchSplittingError

.split_by_worker_pytorch()
.to_torch_iterable()
)
next(iter(it))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the length or items that we get.

@pzdkn pzdkn force-pushed the peng-throw-error-for-omitting-split-in-torch-mp branch from 48462e9 to c028ecc Compare February 2, 2023 09:55
AlirezaSohofi
AlirezaSohofi previously approved these changes Feb 2, 2023
Copy link
Contributor

@AlirezaSohofi AlirezaSohofi left a comment

Choose a reason for hiding this comment

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

LG, thanks a lot, left a few minor comments. Please don't forget to bump the version.

@@ -66,8 +68,40 @@ def __init__(self) -> None:

def __iter__(self) -> Iterator:
"""Method to iterate over the source"""
if _in_multi_rank_env():
warnings.warn("In multi rank environment")
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need warning here

"Add a 'split_by_rank_pytorch' call to your composable to avoid this error. "
)
if _in_multi_worker_env():
warnings.warn("In mulit worker environment")
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need warning here

if torch.distributed.is_available() and torch.distributed.is_initialized():
group = torch.distributed.group.WORLD
size = torch.distributed.get_world_size(group=group)
return True if torch.distributed.is_available() and size > 1 else False
Copy link
Contributor

Choose a reason for hiding this comment

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

torch.distributed.is_available() is already checked in line 139

@pzdkn pzdkn force-pushed the peng-throw-error-for-omitting-split-in-torch-mp branch from 3936284 to ccfcdc8 Compare February 8, 2023 14:31
AlirezaSohofi
AlirezaSohofi previously approved these changes Feb 10, 2023
Copy link
Contributor

@AlirezaSohofi AlirezaSohofi left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Please don't forget to rebase to main and bump the version

@pzdkn pzdkn merged commit 0e19fd5 into main Feb 10, 2023
@pzdkn pzdkn deleted the peng-throw-error-for-omitting-split-in-torch-mp branch February 10, 2023 13:52
@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants