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

[bug] Set device on LightningModule after fitting #7188

Merged
merged 14 commits into from
Apr 23, 2021
Merged

Conversation

tchaton
Copy link
Contributor

@tchaton tchaton commented Apr 23, 2021

What does this PR do?

This PR resolve a bug with device placement.
When running with gpu accelerator, the model was correctly put on cpu but the device was still set to cuda.

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)

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 added the bug Something isn't working label Apr 23, 2021
@codecov
Copy link

codecov bot commented Apr 23, 2021

Codecov Report

Merging #7188 (a5e226d) into master (c502e47) will decrease coverage by 5%.
The diff coverage is 50%.

@@           Coverage Diff           @@
##           master   #7188    +/-   ##
=======================================
- Coverage      92%     87%    -5%     
=======================================
  Files         197     197            
  Lines       12622   12667    +45     
=======================================
- Hits        11631   11000   -631     
- Misses        991    1667   +676     

@pep8speaks
Copy link

pep8speaks commented Apr 23, 2021

Hello @tchaton! Thanks for updating this PR.

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

Comment last updated at 2021-04-23 13:45:29 UTC

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.

LGTM.
Minor nit: perhaps the test could have been integrated in an existing test that just runs fit, in one of the tests/models/test_gpu tests perhaps.
but minor

Copy link
Member

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

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

LGTM 😃

tests/core/test_lightning_module.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
tchaton and others added 2 commits April 23, 2021 14:44
@carmocca carmocca merged commit f58865a into master Apr 23, 2021
@carmocca carmocca deleted the device_placement branch April 23, 2021 14:36
@@ -47,9 +47,10 @@ def on_train_start(self) -> None:
with torch.cuda.device(self.root_device):
torch.cuda.empty_cache()

def on_train_end(self) -> None:
def teardown(self) -> None:
self.lightning_module.cpu()
Copy link
Contributor

Choose a reason for hiding this comment

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

@SeanNaren for sharded training, do we need to move both self.model and self.lightning_module? Could this lead to errors like what we saw for eval/train with SDP earlier?

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

Successfully merging this pull request may close these issues.

6 participants