Skip to content

Conversation

davidberard98
Copy link
Contributor

@davidberard98 davidberard98 commented Apr 10, 2024

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 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

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]
Copy link

pytorch-bot bot commented Apr 10, 2024

🔗 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 Failures

As of commit 23cd5b5 with merge base c3de2cc (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot
Copy link
Contributor

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]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55947660

davidberard98 added a commit that referenced this pull request Apr 10, 2024
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/)
Copy link
Member

@aaronenyeshi aaronenyeshi left a 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!

return has_symbolic_sizes_strides_;
}

bool may_have_symbolic_sizes_strides() const {
Copy link
Member

@aaronenyeshi aaronenyeshi Apr 10, 2024

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?

Copy link
Contributor Author

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...

Copy link
Contributor

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.

Copy link
Contributor Author

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)

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 10, 2024
@aaronenyeshi aaronenyeshi added release notes: profiler release notes category topic: bug fixes topic category labels Apr 10, 2024
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]
@facebook-github-bot
Copy link
Contributor

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]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55947660

davidberard98 added a commit that referenced this pull request Apr 10, 2024
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/)
Copy link
Member

@aaronenyeshi aaronenyeshi left a 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
Copy link
Contributor

@soulitzer soulitzer Apr 11, 2024

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)?

Copy link
Contributor Author

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?

Copy link
Contributor

@soulitzer soulitzer left a 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.

@davidberard98
Copy link
Contributor Author

@soulitzer recommendation for a new name? I'll land it now but can change the name

@soulitzer
Copy link
Contributor

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)

@facebook-github-bot
Copy link
Contributor

@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)

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

sanketpurandare pushed a commit to sanketpurandare/pytorch that referenced this pull request Apr 22, 2024
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
petrex pushed a commit to petrex/pytorch that referenced this pull request May 3, 2024
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
@github-actions github-actions bot deleted the gh/davidberard98/286/head branch May 31, 2024 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request fb-exported Merged release notes: profiler release notes category topic: bug fixes topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants