Skip to content

Introduce constrain_range; remove old expr_subs#95063

Closed
ezyang wants to merge 10 commits intogh/ezyang/1826/basefrom
gh/ezyang/1826/head
Closed

Introduce constrain_range; remove old expr_subs#95063
ezyang wants to merge 10 commits intogh/ezyang/1826/basefrom
gh/ezyang/1826/head

Conversation

@ezyang
Copy link
Copy Markdown
Contributor

@ezyang ezyang commented Feb 17, 2023

Stack from ghstack (oldest at bottom):

This PR introduces a new constrain_range function which can be used to constrain the possible values a SymInt/SymFloat can take on. This knowledge can be then used to discharge potential guards (by running the range analysis, and then seeing if the guard must be true given the original range) without adding another guard.

The usage of ranges is very limited right now; ranges are only constrained when the user explicitly instructs the system so. However, we can also infer range constraints based on guards as well; this is left for future work.

Signed-off-by: Edward Z. Yang ezyang@meta.com

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Feb 17, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit 5185e15:
💚 Looks good so far! There are no failures yet. 💚

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

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

[ghstack-poisoned]
This PR introduces a new `constrain_range` function which can be used to constrain the possible values a SymInt/SymFloat can take on. This knowledge can be then used to discharge potential guards (by running the range analysis, and then seeing if the guard must be true given the original range) without adding another guard.

The usage of ranges is very limited right now; ranges are only constrained when the user explicitly instructs the system so. However, we can also infer range constraints based on guards as well; this is left for future work.

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Feb 17, 2023
Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: 403a7e1
Pull Request resolved: #95063
This PR introduces a new `constrain_range` function which can be used to constrain the possible values a SymInt/SymFloat can take on. This knowledge can be then used to discharge potential guards (by running the range analysis, and then seeing if the guard must be true given the original range) without adding another guard.

The usage of ranges is very limited right now; ranges are only constrained when the user explicitly instructs the system so. However, we can also infer range constraints based on guards as well; this is left for future work.

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Feb 17, 2023
Signed-off-by: Edward Z. Yang <ezyangmeta.com>

ghstack-source-id: 8e82782
Pull Request resolved: #95063
@albanD albanD removed their request for review February 17, 2023 16:09
This PR introduces a new `constrain_range` function which can be used to constrain the possible values a SymInt/SymFloat can take on. This knowledge can be then used to discharge potential guards (by running the range analysis, and then seeing if the guard must be true given the original range) without adding another guard.

The usage of ranges is very limited right now; ranges are only constrained when the user explicitly instructs the system so. However, we can also infer range constraints based on guards as well; this is left for future work.

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

[ghstack-poisoned]
Copy link
Copy Markdown
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Nice. We could start producing a range for Symints like .nonzero() at some point.

if isinstance(expr, sympy.Integer):
return analysis.constant(int(expr), torch.int64)
elif isinstance(expr, sympy.Float):
elif isinstance(expr, sympy.Number):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what caused this change ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1/3 turns into a Rational which is not a float. There's something kind of fishy going on here... I am still feeling like I want to pass the sympy expressions directly to analysis.constant without casting it to float first.

# are conservative: the int MUST fall in the range, but the
# range may contain ints which may not actually appear in
# practice
self.var_to_range: Dict["sympy.Symbol", ValueRanges] = {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we not have a similar range for SymFloats ? any reason to constrict ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It just didn't seem necessary! Also, I view the range analysis on floats as a sort of necessary evil when users do naughty things like sqrt, and for the most part, I only really want to be reasoning about size variables.

if not isinstance(a, SymInt):
assert min <= a <= max
return
if isinstance(a.node.expr, sympy.Integer):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

any reason not to support Floats here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same deal, not supporting constraints on floats for now

This PR introduces a new `constrain_range` function which can be used to constrain the possible values a SymInt/SymFloat can take on. This knowledge can be then used to discharge potential guards (by running the range analysis, and then seeing if the guard must be true given the original range) without adding another guard.

The usage of ranges is very limited right now; ranges are only constrained when the user explicitly instructs the system so. However, we can also infer range constraints based on guards as well; this is left for future work.

Signed-off-by: Edward Z. Yang <ezyangmeta.com>

[ghstack-poisoned]
@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Feb 20, 2023

oops this broke convit_base

@jeanschmidt
Copy link
Copy Markdown
Contributor

@pytorchbot revert -m "Breaking internal builds, more details can be found: https://fburl.com/phabricator/fq5b6k8a" -c nosignal

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

@ezyang your PR has been successfully reverted.

pytorchmergebot added a commit that referenced this pull request Feb 21, 2023
This reverts commit 3711f7c.

Reverted #95063 on behalf of https://github.com/jeanschmidt due to Breaking internal builds, more details can be found: https://fburl.com/phabricator/fq5b6k8a
ezyang added a commit that referenced this pull request Feb 21, 2023
ezyang added a commit that referenced this pull request Feb 21, 2023
…old expr_subs (#95063)""

This reverts commit 4e88547.

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Feb 21, 2023
ezyang added a commit that referenced this pull request Feb 21, 2023
…old expr_subs (#95063)""

This reverts commit 4e88547.

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Feb 21, 2023
pytorchmergebot pushed a commit that referenced this pull request Feb 21, 2023
pytorchmergebot added a commit that referenced this pull request Feb 22, 2023
…)" (#95209)"

This reverts commit f7bf31f.

Reverted #95209 on behalf of https://github.com/ezyang due to internal sympy is too old
pytorchmergebot pushed a commit that referenced this pull request Feb 22, 2023
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Mar 5, 2023
pruthvistony added a commit to ROCm/pytorch that referenced this pull request May 2, 2023
pruthvistony added a commit to ROCm/pytorch that referenced this pull request May 2, 2023
pruthvistony added a commit to ROCm/pytorch that referenced this pull request May 2, 2023
pruthvistony added a commit to ROCm/pytorch that referenced this pull request May 2, 2023
pruthvistony added a commit to ROCm/pytorch that referenced this pull request May 2, 2023
@facebook-github-bot facebook-github-bot deleted the gh/ezyang/1826/head branch June 8, 2023 16:50
jhavukainen pushed a commit to kulinseth/pytorch that referenced this pull request Mar 15, 2024
This PR introduces a new `constrain_range` function which can be used to constrain the possible values a SymInt/SymFloat can take on. This knowledge can be then used to discharge potential guards (by running the range analysis, and then seeing if the guard must be true given the original range) without adding another guard.

The usage of ranges is very limited right now; ranges are only constrained when the user explicitly instructs the system so. However, we can also infer range constraints based on guards as well; this is left for future work.

Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Pull Request resolved: pytorch#95063
Approved by: https://github.com/eellison
jhavukainen pushed a commit to kulinseth/pytorch that referenced this pull request Mar 15, 2024
jhavukainen pushed a commit to kulinseth/pytorch that referenced this pull request Mar 15, 2024
jhavukainen pushed a commit to kulinseth/pytorch that referenced this pull request Mar 15, 2024
jhavukainen pushed a commit to kulinseth/pytorch that referenced this pull request Mar 15, 2024
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 Merged release notes: fx release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants