pytorch-lightning icon indicating copy to clipboard operation
pytorch-lightning copied to clipboard

Fix device placement when `.cuda()` called without specifying index

Open awaelchli opened this issue 3 years ago • 3 comments

What does this PR do?

The PR #13704 resulted in an unintended change.

The second .cuda() call below should leave the model on the device set by torch.cuda.set_device if it is already on it.

model.cuda(1) 
torch.cuda.set_device(1)
model.cuda()  # On master, model lands on device 0. Expected is device 1

Reported on Slack.

Before submitting

  • [x] Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • [x] Did you read the contributor guideline, Pull Request section?
  • [x] Did you make sure your PR does only one thing, instead of bundling different changes together?
  • [x] Did you make sure to update the documentation with your changes? (if necessary)
  • [x] Did you write any new necessary tests? (not for typos and docs)
  • [x] Did you verify new and existing tests pass locally with your changes?
  • [x] 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:

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

Did you have fun?

I made sure I had fun coding 🙃

cc @tchaton @rohitgr7 @carmocca @justusschock @awaelchli @borda @ananthsub @ninginthecloud @jjenniferdai @akihironitta

awaelchli avatar Aug 09 '22 23:08 awaelchli

Thanks this works, this is breaking change in 1.7.0. Would you be releasing minor version with this patch soon?

nithinraok avatar Aug 10 '22 00:08 nithinraok

@nithinraok Yes, if merged, this would go into 1.7.2 next week (~Tuesday).

awaelchli avatar Aug 10 '22 00:08 awaelchli

Codecov Report

Merging #14128 (8cd35b1) into master (06c255c) will increase coverage by 15%. The diff coverage is 0%.

@@            Coverage Diff            @@
##           master   #14128     +/-   ##
=========================================
+ Coverage      61%      76%    +15%     
=========================================
  Files         324      324             
  Lines       26369    26493    +124     
=========================================
+ Hits        16138    20182   +4044     
+ Misses      10231     6311   -3920     

codecov[bot] avatar Aug 10 '22 02:08 codecov[bot]