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

[bugfix] Prevent deepcopy of dataloaders / Trainer in SWA Callback #8472

Merged
merged 16 commits into from
Jul 20, 2021

Conversation

tchaton
Copy link
Contributor

@tchaton tchaton commented Jul 19, 2021

What does this PR do?

This PR introduces a context manager to prevent deecopying trainer / dataloaders from the LightningModule.
This PR uses this context manager to prevent with stochastic weight averaging
This PR improve ModelPruning save_checkpoint to avoid a deepcopy.

Fixes #7089

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

No.

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?
  • 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)
  • Did you list all the breaking changes introduced by this pull request?

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 🙃

@tchaton tchaton self-assigned this Jul 19, 2021
@tchaton tchaton added this to the v1.4 milestone Jul 19, 2021
@tchaton tchaton added the bug Something isn't working label Jul 19, 2021
@codecov
Copy link

codecov bot commented Jul 19, 2021

Codecov Report

Merging #8472 (294307c) into master (8a9ee40) will increase coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #8472   +/-   ##
======================================
  Coverage      92%     92%           
======================================
  Files         217     217           
  Lines       14342   14367   +25     
======================================
+ Hits        13236   13260   +24     
- Misses       1106    1107    +1     

@tchaton tchaton requested a review from carmocca July 19, 2021 18:52
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

Pushed a few commits with some changes

@mergify mergify bot added the ready PRs ready to be merged label Jul 20, 2021
@tchaton tchaton requested a review from carmocca July 20, 2021 08:33
Copy link
Contributor

@kaushikb11 kaushikb11 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 added has conflicts and removed ready PRs ready to be merged labels Jul 20, 2021
Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

If I understand this PR correctly, all the changes are specific to the pruning etc. callbacks. can you confirm the following:

  • pickling behavior unchanged
  • deepcopy(model) still does a real deepcopy unless the context manager is used
  • the context manager is not meant to be used by the user, or is it? any other use cases for deepcopying a lightnignmodule?

@mergify mergify bot removed the has conflicts label Jul 20, 2021
@tchaton
Copy link
Contributor Author

tchaton commented Jul 20, 2021

If I understand this PR correctly, all the changes are specific to the pruning etc. callbacks. can you confirm the following:

  • pickling behavior unchanged
  • deepcopy(model) still does a real deepcopy unless the context manager is used
  • the context manager is not meant to be used by the user, or is it? any other use cases for deepcopying a lightnignmodule?

Yes, exactly !

Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

Great!

Excluding the dataloaders here may not be necessary in the future if we avoid this weird patching of LightningModule methods: #6030

@tchaton tchaton enabled auto-merge (squash) July 20, 2021 17:54
@mergify mergify bot added the ready PRs ready to be merged label Jul 20, 2021
@tchaton tchaton merged commit ea13f60 into master Jul 20, 2021
@tchaton tchaton deleted the saw_deepcopy branch July 20, 2021 18:31
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.

Using SWA callback triggers useless deepcopy of data loaders
5 participants