-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Tensor] Detect more cases of symbolic sizes/strides #123696
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
[Tensor] Detect more cases of symbolic sizes/strides #123696
Conversation
Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/123696
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 23cd5b5 with merge base c3de2cc ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. Differential Revision: D55947660 |
Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D55947660 |
Pull Request resolved: #123696 Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. ghstack-source-id: 221944770 Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/)
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 great! Thanks for the fix and unit test!
c10/core/TensorImpl.h
Outdated
return has_symbolic_sizes_strides_; | ||
} | ||
|
||
bool may_have_symbolic_sizes_strides() const { |
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.
So in this change, we add may_have_symbolic_sizes_strides() - which should never return false if the tensor has symbolic sizes and strides
Nit: If this is strictly never, should it be named more strictly?
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, in my opinion this naming more sense, e.g.:
tensor.definitely_has_symbolic_sizes_strides()
-> if it returns true, we know that this tensor definitely has symbolic sizes/strides
tensor.may_have_symbolic_sizes_strides()
-> if this returns true, then maybe the tensor has symbolic sizes/strides; but if this returns false, then we knwo this tensor definitely doesn't have symbolic sizes/strides.
I guess we could call it tensor.definitely_does_not_have_symbolic_sizes_strides()
but that's a bit long...
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.
I would agree that if we're saying we have 3 states now: definitely yes, maybe, definitely no, it would make sense for the existing has_symbolic_sizes_strides
to be renamed to reflect what it is doing.
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.
ok, named it "does_not_have_symbolic_sizes_strides" with a comment explaining (and inverted the return value)
Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D55947660 |
Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/) [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D55947660 |
Pull Request resolved: #123696 Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. ghstack-source-id: 222066277 Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/)
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.
LGTM, thanks for updating the name and adding comments!
// possible that has_symbolic_sizes_strides() returns false, but we do | ||
// not have symbolic sizes/strides. This exists for the case of | ||
// Nested Tensor python subclass, where the sizes are implemented in python | ||
// (TODO: clean this up and just implement sizes in nested tensor without a |
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.
The naming still feels a little confusing to me since has_symbolic_sizes_strides() != !does_not_have_symbolic_sizes_strides()
when the naming suggests that they should be inverses?
If we wanted to do something temporary to block NT (e.g. we were planning to remove this API anyway) and avoid renaming all callsites of has_symbolic_sizes_strides, maybe its just easiest to directly modify the callsite in execution_trace_observer.cpp
to also check matches_policy(SizesStridesPolicy::CustomStrides)
?
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.
sorry, didn't see this after it was edited I think. I think matches_policy
is protected
so it's not accessible outside of TensorImpl
. I guess we could also make that public, but I'm not sure if that's too different from this change?
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.
Thanks for the quick fix!
My only comment is that the naming is still confusing imo and we're leaning on the comment to explain everything.
@soulitzer recommendation for a new name? I'll land it now but can change the name |
I don't think there's a better name unless we want to update all existing callsites too (which seems not worth it if this 3-state thing is temporary anyway) my suggestion was just to avoid adding a new API altogether if we were just going to remove it later (OR if we believe that subclasses in general can be in the situation where a instance can "sometimes" have symbolic shape, I think the naming from your comment here #123696 (comment) makes sense - though I cannot think of any examples of such subclasses) |
@pytorchbot merge -f 'Landed internally' (Initiating merge automatically since Phabricator Diff has merged, using force because this PR might not pass merge_rules.json but landed internally) |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/) Pull Request resolved: pytorch#123696 Approved by: https://github.com/aaronenyeshi, https://github.com/soulitzer
Previously, we'd just check `has_symbolic_sizes_strides()` to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimes `has_symbolic_sizes_strides()` returns false, but we do actually have symbolic sizes or strides. So in this change, we add `may_have_symbolic_sizes_strides()` - which should never return false if the tensor has symbolic sizes and strides Why not change `has_symbolic_sizes_strides()`? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path. Differential Revision: [D55947660](https://our.internmc.facebook.com/intern/diff/D55947660/) Pull Request resolved: pytorch#123696 Approved by: https://github.com/aaronenyeshi, https://github.com/soulitzer
Stack from ghstack (oldest at bottom):
Previously, we'd just check
has_symbolic_sizes_strides()
to know whether a tensor has symbolic sizes or strides; if does, we skip some profiler logic. But sometimeshas_symbolic_sizes_strides()
returns false, but we do actually have symbolic sizes or strides.So in this change, we add
may_have_symbolic_sizes_strides()
- which should never return false if the tensor has symbolic sizes and stridesWhy not change
has_symbolic_sizes_strides()
? It seems like there's preexisting logic that assumes that "if has_symbolic_sizes_strides(), then we can assume that this tensor is guaranteed to have symbolic sizes or strides". In this case, we have python-implemented sizes or strides, which should follow a different code path.Differential Revision: D55947660