Skip to content

[attempt 2] Compute contiguity symbolically to avoid dde, and introduce c++ sym_is_contiguous #157472

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

Closed
wants to merge 1 commit into from

Conversation

laithsakka
Copy link
Contributor

@laithsakka laithsakka commented Jul 2, 2025

Summary:
When we compute contiguity for a tensor with dynamic shapes we first:

  1. Try to compute it without guarding.
  2. If all shapes hinted, compute it with potentially adding guards.
  3. if any input is not hinted, compute it symbolically.

sym_is_contiguous return a SymBool that is then either evaluated or guard_or_false can be called
on it to avoid data dependent errors.

ex:
bool is_contiguous = input.sym_is_contiguous().guard_or_false(FILE, LINE);
is_contiguous_or_false is a helper function that does that.

In this PR I only handle default contiguity, will follow up with changes for other formats like channel_last .
We use this patter in this PR for several locations to avoid DDEs.

Test Plan:
contbuild & OSS CI,

Rollback Plan:

Reviewed By: malfet

Differential Revision: D77639021

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @jerryzh168

@laithsakka laithsakka requested review from a team, albanD and soulitzer as code owners July 2, 2025 17:04
Copy link

pytorch-bot bot commented Jul 2, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit 6dccadf with merge base d5d14ee (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot bot added ciflow/inductor module: cpu CPU specific problem (e.g., perf, algorithm) release notes: releng release notes category labels Jul 2, 2025
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

laithsakka added a commit to laithsakka/pytorch that referenced this pull request Jul 2, 2025
…ce c++ sym_is_contiguous (pytorch#157472)

Summary:
Pull Request resolved: pytorch#157472

When we compute contiguity for a tensor with dynamic shapes we first:
1) Try to compute it without guarding.
2) If all shapes hinted, compute it with potentially adding guards.
3) if any input is not hinted, compute it symbolically.

sym_is_contiguous return a SymBool that is then either evaluated or guard_or_false can be called
on it to avoid data dependent errors.

ex:
 bool is_contiguous = input.sym_is_contiguous().guard_or_false(__FILE__, __LINE__);
is_contiguous_or_false is a helper function that does that.

In this PR I only handle default contiguity, will follow up with changes for other formats like  channel_last .
We use this patter in this PR for several locations to avoid DDEs.

Test Plan:
contbuild & OSS CI,

Rollback Plan:

Reviewed By: huydhn, malfet

Differential Revision: D77639021
@laithsakka laithsakka requested a review from ezyang July 2, 2025 17:19
…ce c++ sym_is_contiguous (pytorch#157472)

Summary:
Pull Request resolved: pytorch#157472

When we compute contiguity for a tensor with dynamic shapes we first:
1) Try to compute it without guarding.
2) If all shapes hinted, compute it with potentially adding guards.
3) if any input is not hinted, compute it symbolically.

sym_is_contiguous return a SymBool that is then either evaluated or guard_or_false can be called
on it to avoid data dependent errors.

ex:
 bool is_contiguous = input.sym_is_contiguous().guard_or_false(__FILE__, __LINE__);
is_contiguous_or_false is a helper function that does that.

In this PR I only handle default contiguity, will follow up with changes for other formats like  channel_last .
We use this patter in this PR for several locations to avoid DDEs.

Test Plan:
contbuild & OSS CI,

Rollback Plan:

Reviewed By: huydhn, malfet

Differential Revision: D77639021
@facebook-github-bot
Copy link
Contributor

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

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 2, 2025
@jeanschmidt
Copy link
Contributor

Seems that the imported diff have multiple red signals internally...

@albanD albanD removed their request for review July 2, 2025 19:38
@facebook-github-bot
Copy link
Contributor

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request fb-exported Merged module: cpu CPU specific problem (e.g., perf, algorithm) release notes: releng release notes category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants