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

DDP sampler #1513

Merged
merged 6 commits into from
Apr 19, 2020
Merged

DDP sampler #1513

merged 6 commits into from
Apr 19, 2020

Conversation

justusschock
Copy link
Member

@justusschock justusschock commented Apr 17, 2020

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

What does this PR do?

Fixes #1506 .

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@justusschock justusschock requested review from williamFalcon, Borda and a team April 17, 2020 07:59
@pep8speaks
Copy link

pep8speaks commented Apr 17, 2020

Hello @justusschock! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-04-17 08:15:31 UTC

@codecov
Copy link

codecov bot commented Apr 17, 2020

Codecov Report

Merging #1513 into master will increase coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #1513   +/-   ##
======================================
  Coverage      91%     91%           
======================================
  Files          67      67           
  Lines        3784    3786    +2     
======================================
+ Hits         3439    3441    +2     
  Misses        345     345           

@Borda Borda added bug Something isn't working discussion In a discussion stage labels Apr 17, 2020
@Borda
Copy link
Member

Borda commented Apr 17, 2020

is there a way how to do it without adding extra parameters in API?
cc: @williamFalcon

@justusschock
Copy link
Member Author

I think this is difficult, since for custom dataloaders it will be hard to determine when it should be set and when not.

Previously we had the check, whether a sampler was set, which was always false since the sampler is internally set by PyTorch.
Any suggestions on this? @Borda @williamFalcon


if need_dist_sampler:
need_dist_sampler = (self.use_ddp or self.use_ddp2 or self.use_tpu)
if self.replace_sampler_ddp and need_dist_sampler:
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than adding a new flag for this, is it possible to just check for the default samplers:
(isinstance(dataloader.sampler, RandomSampler) or isinstance(dataloader.sampler, SequentialSampler) or instance(dataloader.sampler, _InfiniteConstantSampler)) and need_dist_sampler?

I had a hard to find regression that happened because my custom sampler was overridden after #1425. Considering replace_sampler_ddp is set to True by default I think a lot of users will run into similar issues both in terms of regressions and new projects. E.g. users are going to expect that when they write a new sampler and pass it in the dataloader it'll be used without having to change a setting somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand that, but I don't think, that this is a good idea. If I explicitly set a standard sampler and don't want it to be replaced, I can't do anything this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. I'd prefer the trainer flag default to False at least, but let's leave it up to the opinion of others @PyTorchLightning/core-contributors

@mergify mergify bot requested a review from a team April 17, 2020 19:14
@williamFalcon williamFalcon merged commit c71bd73 into master Apr 19, 2020
@williamFalcon
Copy link
Contributor

@justusschock awesome addition.
@tullie i see what you mean, but I prefer to default it to True for now, but happy to change if it doesn't make sense for everyone.

Leaving it True means ddp/etc work without code changes, nor having to remember anything else.
Leaving it False means people with samplers don't spend time trying to figure out why their sampler was replaced or something.

Maybe a solution is a warning to one or the other?

@Borda Borda deleted the ddp_sampler branch April 19, 2020 21:47
@Borda
Copy link
Member

Borda commented Apr 19, 2020

a warning would be nice...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discussion In a discussion stage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.7.3 breaks reusable dataloaders in DDP
5 participants