8000 [dynamic shapes] stop writing Max(*, 1) for strides by pianpwk · Pull Request #150376 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[dynamic shapes] stop writing Max(*, 1) for strides #150376

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pianpwk
Copy link
Contributor
@pianpwk pianpwk commented Apr 1, 2025

When handling strides, avoiding generating Max(u0, 1) expressions if we can, since it'll be hard to deal with these once we move away from guard_size_oblivious.

Looking at what the code was before sym_max was introduced (#94400 in _prims_common/__init__.py), this change seems appropriate.

Copy link
pytorch-bot bot commented Apr 1, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/150376

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit 3d7ac71 with merge base 9810488 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

@@ -885,7 +885,7 @@ def test_non_overlapping_and_dense_unbacked(self):
cf(
torch.empty_strided(
(2, 3, 1, u0),
(3 * Max(1, u0), Max(1, u0), Max(1, u0), 1),
(3 * u0, u0, u0, 1),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case is no longer relevant

@pianpwk pianpwk changed the title [WIP][export] stop writing Max(*, 1) for strides [dynamic shapes] stop writing Max(*, 1) for strides Apr 1, 2025
@pianpwk pianpwk marked this pull request as ready for review April 1, 2025 20:46
sym_shape_meta.strides_[last_idx] = c10::SymInt(1);
for (auto i = last_idx - 1; i >= 0; --i) {
sym_shape_meta.strides_[i] = sym_shape_meta.strides_[i + 1] *
sym_shape_meta.sizes_[i + 1].max(1);
if (TORCH_GUARD_OR_TRUE(sym_shape_meta.sizes_[i + 1].sym_gt(1))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we used to generate max(u0, 1)
and now we generate just u0 unconditionally?

can you explain why this is safe?

Copy link
Contributor
@bobrenjc93 bobrenjc93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back to your queue to address @laithsakka's comments around safety

@laithsakka @pianpwk I wonder for these guard_or_true cases if we should by default always add a comment about safety just like how rust does this with unsafe blocks: https://std-dev-guide.rust-lang.org/policy/safety-comments.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0