Skip to content

Conversation

@dvolgyes
Copy link
Contributor

@dvolgyes dvolgyes commented Feb 26, 2021

What does this PR do?

If you use .detach()/to()/cpu(), you need to assign it to a new variable,
it does not change the source variable.

Fixes #6214

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 🙃

@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #6216 (30258e2) into master (925f082) will decrease coverage by 2%.
The diff coverage is 50%.

@@           Coverage Diff           @@
##           master   #6216    +/-   ##
=======================================
- Coverage      93%     91%    -2%     
=======================================
  Files         159     159            
  Lines       11360   11251   -109     
=======================================
- Hits        10603   10257   -346     
- Misses        757     994   +237     

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.

Great catch !

@tchaton tchaton self-requested a review February 26, 2021 12:10
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.

Dear @dvolgyes,

The Result object implements in-place operation. Therefore, your changes won't work.
Therefore, I returned self from to, and cpu functions.

Best,
T.C

@Borda Borda added the bug Something isn't working label Feb 26, 2021
@Borda Borda added this to the 1.2.x milestone Feb 26, 2021
@Borda Borda added the ready PRs ready to be merged label Feb 26, 2021
@Borda
Copy link
Collaborator

Borda commented Feb 26, 2021

@dvolgyes I have applied this to the remaining codebase, mind checkingng it...

@dvolgyes
Copy link
Contributor Author

dvolgyes commented Feb 26, 2021

I see, thank you for the fix.
In place: I would say it is a very confusing behavior, it looks very pytorch-ish,
but using a different approach (in place).
And in this case, it might not matter that much.
(Some objects i assumed to be tensor might have been lightning objects.)

@dvolgyes
Copy link
Contributor Author

I looked through, and it looks good to me.
As a remark, the models (nn.Module) are in-place,
so if you call a .cuda() on them, they return themselves,
but there it is not necessary.
I think it is a good practice, because you don't have to keep it in mind
which one works in-place (model, some PL), and which one doesn't (tensors).
So I think the model = model.cpu() is not strictly necessary, but I support the change.

@dvolgyes
Copy link
Contributor Author

Codecov: I don't understand how could it be that low. Something got accidentally disabled? (Jumping from 80 percent to 20%)

@Borda
Copy link
Collaborator

Borda commented Feb 26, 2021

Codecov: I don't understand how could it be that low. Something got accidentally disabled? (Jumping from 80 percent to 20%)

it just takes time till all tests are finished stat aggregated, so the faster is base pkg testing and full testing takes about 15-20min

@dvolgyes
Copy link
Contributor Author

I see, thanks for the explanation.
I am not familiar with the setup / internals, and I still don't see how this aggregation works,
but I can live without the details. :) Thanks again.

@carmocca carmocca removed the ready PRs ready to be merged label Mar 1, 2021
@mergify mergify bot removed the has conflicts label Mar 1, 2021
@mergify mergify bot added the has conflicts label Mar 1, 2021
@mergify mergify bot removed the has conflicts label Mar 1, 2021
@tchaton tchaton merged commit 651c25f into Lightning-AI:master Mar 1, 2021
kaushikb11 pushed a commit to kaushikb11/pytorch-lightning that referenced this pull request Mar 2, 2021
* Fix for incorrect detach/cpu calls (Lightning-AI#6214)

* Fix incorrect use of detach(), to(), and cpu(), Lightning-AI#6214

* Fix incorrect use of detach() and cpu(), Lightning-AI#6214

* update pr

* add typing

* chlog

* more...

* revert on module

* update on comments

* revert changes on model

Co-authored-by: tchaton <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
@carmocca carmocca mentioned this pull request Mar 2, 2021
kaushikb11 pushed a commit to kaushikb11/pytorch-lightning that referenced this pull request Mar 2, 2021
* Fix for incorrect detach/cpu calls (Lightning-AI#6214)

* Fix incorrect use of detach(), to(), and cpu(), Lightning-AI#6214

* Fix incorrect use of detach() and cpu(), Lightning-AI#6214

* update pr

* add typing

* chlog

* more...

* revert on module

* update on comments

* revert changes on model

Co-authored-by: tchaton <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
lexierule pushed a commit that referenced this pull request Mar 5, 2021
* Fix for incorrect detach/cpu calls (#6214)

* Fix incorrect use of detach(), to(), and cpu(), #6214

* Fix incorrect use of detach() and cpu(), #6214

* update pr

* add typing

* chlog

* more...

* revert on module

* update on comments

* revert changes on model

Co-authored-by: tchaton <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
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.

incorrect usage of detach/cpu/to

6 participants