-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[BC-breaking] Fix version counter sharing in set_data() #20391
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
Conversation
|
@pytorchbot retest this please |
| # In-place op on `x` also updates version of `xz`, | ||
| # because they share the version counter | ||
| x.add_(1) | ||
| self.assertTrue(x._version == xz._version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some improvements to this test:
- change the variable through xz.
- check that changes post-set data actually increase the version counter.
2e8cfb3 to
f45dcaf
Compare
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yf225 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
In https://github.com/pytorch/pytorch/pull/18223/files#diff-77a6f3462f2233b921d3042412fed6d3R178, we used
auto saved_version_ = data_.unsafeGetTensorImpl()->version_counter().current_version()and thennew_data_impl_copy->set_version_counter(saved_version_), which actually doesn't preserve the original semantics thatvar.set_data(tensor)should keepvar's version counter object intact. This PR fixes the bug and adds test to make sure it doesn't happen again.This PR is BC-breaking for v1.1.0, because v1.1.0 contains #18223 which introduces the bug. As an example, the following test passes on v1.0.1 and will pass on master after this PR is merged, but doesn't pass on v1.1.0: