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

Fix support for dataloader with None batches #7342

Merged
merged 7 commits into from
May 4, 2021
Merged

Conversation

ethanwharris
Copy link
Member

@ethanwharris ethanwharris commented May 4, 2021

What does this PR do?

Fixes #6753

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • [N/A] Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented May 4, 2021

Codecov Report

Merging #7342 (108b409) into master (a6aa1a0) will decrease coverage by 5%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #7342    +/-   ##
=======================================
- Coverage      91%     86%    -5%     
=======================================
  Files         200     200            
  Lines       12916   13210   +294     
=======================================
- Hits        11764   11317   -447     
- Misses       1152    1893   +741     

@ethanwharris ethanwharris changed the title Bugfix/none batch Fix support for dataloader with None batches May 4, 2021
@mergify mergify bot added the has conflicts label May 4, 2021
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

LGTM !

@mergify mergify bot removed the has conflicts label May 4, 2021
@ethanwharris ethanwharris added the bug Something isn't working label May 4, 2021
@awaelchli awaelchli added the ready PRs ready to be merged label May 4, 2021
@awaelchli awaelchli added this to the v1.3 milestone May 4, 2021
@SkafteNicki SkafteNicki enabled auto-merge (squash) May 4, 2021 12:20
@SkafteNicki SkafteNicki merged commit 2a740eb into master May 4, 2021
@SkafteNicki SkafteNicki deleted the bugfix/none_batch branch May 4, 2021 12:24
Comment on lines +611 to +616
self.warning_cache.warn("train_dataloader yielded None. If this was on purpose, ignore this warning...")
return AttributeDict(
signal=0,
grad_norm_dic=grad_norm_dic,
training_step_output_for_epoch_end=batch_outputs,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens in distributed training? won't we go out of sync across ranks if the batch is None on some ranks and non-None on others?

Copy link
Member Author

@ethanwharris ethanwharris May 4, 2021

Choose a reason for hiding this comment

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

I'm not sure. It will be closer to working than it was before, but this use case may still need some work for distributed. The new behaviour (that is, after this fix) should be the same as when returning None from a step

Copy link
Contributor

@ananthsub ananthsub May 4, 2021

Choose a reason for hiding this comment

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

There are two options:

  • either the trainer runs an all reduce at each step to determine whether all ranks skip. This is a general solution but wastes perf for any users who won't skip batches
  • the user runs the all reduce in their lightning module and determines when to skip. This way it's specific to just modules which need to skip batches or steps for any reason.

I prefer the latter approach because I don't want to slow down the trainer for everyone to handle a few corner cases

What do you think @tchaton @SeanNaren @awaelchli @carmocca

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think it's fine to make the user responsible for making all ranks skip in sync if they want distributed skipping

Copy link
Contributor

@carmocca carmocca May 4, 2021

Choose a reason for hiding this comment

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

Returning None in any kind of distributed setting or AMP is currently unsupported. We have this (very old) PR to add support but it's currently frozen

#5359

You can have a look at the proposal though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Returning None in training_step generates an error
7 participants