-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[LT] Support Tensor.is_alias_of #75246
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
Summary: Tensor.is_alias_of relies on Storage to perform. However, LTCTensorImpl was not implemented with that in mind. This commit adds a fake storage to LazyTensor as a marker to mark LazyTensors that point to the same storage. The reason why it's not done at LTCTensorImpl is that LazyTensor maintains the view ops/alias logic in LazyTensor class instead of relying on TensorImpl to do the check. Test Plan: ./build/bin/test_lazy --gtest_filter=LazyOpsTest.IsAliasOf [ghstack-poisoned]
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 3f12fab (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
Summary: Tensor.is_alias_of relies on Storage to perform. However, LTCTensorImpl was not implemented with that in mind. This commit adds a fake storage to LazyTensor as a marker to mark LazyTensors that point to the same storage. The reason why it's not done at LTCTensorImpl is that LazyTensor maintains the view ops/alias logic in LazyTensor class instead of relying on TensorImpl to do the check. Test Plan: ./build/bin/test_lazy --gtest_filter=LazyOpsTest.IsAliasOf ghstack-source-id: 2069b77 Pull Request resolved: #75246
|
@alanwaketan has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
|
Please refer to the #71378 for the discussion on why we support is_alias_of in this way instead of making the method virtual. cc @sujoysaraswati. |
| LazyTensorPtr LazyTensor::CreateViewTensor(ViewInfo view_info) const { | ||
| return Create(CreateView(std::move(view_info)), GetDevice()); | ||
| auto new_tensor = Create(CreateView(std::move(view_info)), GetDevice()); | ||
| new_tensor->storage_ = Storage(); |
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.
hmm, so we explicitly copy the Storage from one LT to another one if we know we are creating a view.
i was actually thinking we could tie it into the 'data()' object in some way, so if 2 LazyTensors happen to point to the same IR value then they also share the same storage. I'm not actually sure if that is a desirable property, and maybe your approach is good enough. It certainly seems to be simpler, which is nice.
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.
if 2 LazyTensors happen to point to the same IR value then they also share the same storage
just curious - are you saying it's possible to be in a state where you have two LTC tensor's that aren't views of each other, but they actually point to the same IR under the hood?
|
I think this change would be OK, but i'll wait for @bdhirsh to stamp |
bdhirsh
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.
Looks ok to me! I'm hoping to have a mini prototype of integration functionalization into LTC pretty soon (where a bunch more changes are needed / stuff breaks, but hopefully I can show what the integration would look like at a high level)
|
I have a question on the LazyTensor data_ptr() access. Since the has_storage() and storage() methods on LazyTensor would now return true and the fake storage, how does it affect APIs like data_ptr() for LazyTensor, is it planned to be supported for lazy tensor? |
Thanks @alanwaketan, we have followed the suggestion to use is_alias_of with a dummy storage and have closed #71378 now. |
It shouldn't affect any exist APIs in the LazyTensor class. Or do you mean data_ptr() APIs somewhere else? |
My question is If we call a tensor.data_ptr() on a LazyTensor, will it work and provide a valid pointer? |
It will return the empty DataPtr that is created in https://github.com/pytorch/pytorch/pull/75246/files#diff-824247c5519c382811fb78f1272745e2f1dfbce4fb85fbb5bb04f550ea836206R83. Not sure about the implications on other functions built on top of the DataPtr API. Before we will throw an assertion which basically means LazyTensor won't touch any of these APIs. And the for the future, we will deprecate this and use functionalization. Maybe worth a TORCH_WARN, but I don't see any particular issues here. @bdhirsh What do you think? |
|
Yes, I was referring to the empty data pointer value that would be returned and if this would create issue for any caller code looking for a valid data pointer. Could you please also give some details on how this is planned to change with functionalization? |
|
That's true that accessing the data ptr won't give you a nice error message anymore. With functionalization (integration with LTC is underway), the lazy tensors will be wrapped in a |
Summary: Tensor.is_alias_of relies on Storage to perform. However, LTCTensorImpl was not implemented with that in mind. This commit adds a fake storage to LazyTensor as a marker to mark LazyTensors that point to the same storage. The reason why it's not done at LTCTensorImpl is that LazyTensor maintains the view ops/alias logic in LazyTensor class instead of relying on TensorImpl to do the check. Test Plan: ./build/bin/test_lazy --gtest_filter=LazyOpsTest.IsAliasOf Differential Revision: [D35389123](https://our.internmc.facebook.com/intern/diff/D35389123) [ghstack-poisoned]
Summary: Tensor.is_alias_of relies on Storage to perform. However, LTCTensorImpl was not implemented with that in mind. This commit adds a fake storage to LazyTensor as a marker to mark LazyTensors that point to the same storage. The reason why it's not done at LTCTensorImpl is that LazyTensor maintains the view ops/alias logic in LazyTensor class instead of relying on TensorImpl to do the check. Test Plan: ./build/bin/test_lazy --gtest_filter=LazyOpsTest.IsAliasOf Differential Revision: [D35389123](https://our.internmc.facebook.com/intern/diff/D35389123) [ghstack-poisoned]
Summary: Tensor.is_alias_of relies on Storage to perform. However, LTCTensorImpl was not implemented with that in mind. This commit adds a fake storage to LazyTensor as a marker to mark LazyTensors that point to the same storage. The reason why it's not done at LTCTensorImpl is that LazyTensor maintains the view ops/alias logic in LazyTensor class instead of relying on TensorImpl to do the check. Test Plan: ./build/bin/test_lazy --gtest_filter=LazyOpsTest.IsAliasOf ghstack-source-id: b6d8a7c Pull Request resolved: #75246
|
@alanwaketan has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
|
@pytorchbot merge this (Initiating merge automatically since Phabricator Diff has merged) |
1 similar comment
|
@pytorchbot merge this (Initiating merge automatically since Phabricator Diff has merged) |
|
Can't merge closed PR #75246 |
|
Hey @alanwaketan. |
Summary: Pull Request resolved: #75246 Tensor.is_alias_of relies on Storage to perform. However, LTCTensorImpl was not implemented with that in mind. This commit adds a fake storage to LazyTensor as a marker to mark LazyTensors that point to the same storage. The reason why it's not done at LTCTensorImpl is that LazyTensor maintains the view ops/alias logic in LazyTensor class instead of relying on TensorImpl to do the check. Test Plan: ./build/bin/test_lazy --gtest_filter=LazyOpsTest.IsAliasOf Reviewed By: bdhirsh Differential Revision: D35389123 Pulled By: alanwaketan fbshipit-source-id: 488fdba84660d8e57bbbe97a775780e1d312fd88
Stack from ghstack (oldest at bottom):
Summary:
Tensor.is_alias_of relies on Storage to perform. However, LTCTensorImpl was
not implemented with that in mind. This commit adds a fake storage to LazyTensor
as a marker to mark LazyTensors that point to the same storage. The reason
why it's not done at LTCTensorImpl is that LazyTensor maintains the view ops/alias
logic in LazyTensor class instead of relying on TensorImpl to do the check.
Test Plan:
./build/bin/test_lazy --gtest_filter=LazyOpsTest.IsAliasOf
Differential Revision: D35389123