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 replace_sampler missing the batch size under specific conditions #9367

Merged
merged 2 commits into from
Sep 8, 2021

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented Sep 8, 2021

What does this PR do?

Reported in Slack.

Fixes a bug where the batch_size was not properly reset under the following conditions:

  • batch_size is provided to the DataLoader
  • No batch_sampler is present initially
  • The DataLoader signature passes the batch_size through **kwargs.

Does your PR introduce any breaking changes? If yes, please list them.

None

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 list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

  • 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

@carmocca carmocca added bug Something isn't working data handling Generic data-related topic labels Sep 8, 2021
@carmocca carmocca added this to the v1.4.x milestone Sep 8, 2021
@carmocca carmocca self-assigned this Sep 8, 2021
@codecov
Copy link

codecov bot commented Sep 8, 2021

Codecov Report

Merging #9367 (945cf12) into master (a79c351) will decrease coverage by 4%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #9367    +/-   ##
=======================================
- Coverage      92%     88%    -4%     
=======================================
  Files         178     178            
  Lines       14899   14902     +3     
=======================================
- Hits        13752   13142   -610     
- Misses       1147    1760   +613     

Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

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

LGTM. Can you add a simple test with a dummy loader?

Something like

class DummyLoader(torch.utils.data.DataLoader):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

@mergify mergify bot added the ready PRs ready to be merged label Sep 8, 2021
@SeanNaren
Copy link
Contributor

LGTM. Can you add a simple test with a dummy loader?

Something like

class DummyLoader(torch.utils.data.DataLoader):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

May be mistaken, but the CustomDataLoader test already does this:

class CustomDataLoader(DataLoader):
        def __init__(self, num_features, dataset, *args, **kwargs):
            self.num_features = num_features
            super().__init__(dataset, *args, **kwargs)

@justusschock
Copy link
Member

@SeanNaren my bad, overseen this

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 !

pytorch_lightning/trainer/data_loading.py Show resolved Hide resolved
@carmocca carmocca merged commit f239b96 into master Sep 8, 2021
@carmocca carmocca deleted the bugfix/replace-sampler-no-batch-sampler-kwargs branch September 8, 2021 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data handling Generic data-related topic ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants