Skip to content
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

Introduce int_oo #127693

Closed
wants to merge 20 commits into from
Closed

Introduce int_oo #127693

wants to merge 20 commits into from

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented Jun 1, 2024

Stack from ghstack (oldest at bottom):

In a previous life, we used sympy.oo to represent the lower/upper bounds of integer ranges. Later, we changed this to be sys.maxsize - 1 for a few reasons: (1) sometimes we do tests on a value being exactly sys.maxsize, and we wanted to avoid a data dependent guard in this case, (2) sympy.oo corresponds to floating point infinity, so you get incorrect types for value ranges with oo, and (3) you can do slightly better reasoning if you assume that input sizes fall within representable 64-bit integer range.

After working in the sys.maxsize regime for a bit, I've concluded that this was actually a bad idea. Specifically, the problem is that you end up with sys.maxsize in your upper bound, and then whenever you do any sort of size-increasing computation like size * 2, you end up with 2 * sys.maxsize, and you end up doing a ton of arbitrary precision int computation that is totally unnecessary. A symbolic bound is better.

But especially after #126905, we can't go back to using sympy.oo, because that advertises that it's not an integer, and now your ValueRanges is typed incorrectly. So what do we do? We define a new numeric constant int_oo, which is like sympy.oo but it advertises is_integer. test/test_sympy_utils.py describes some basic properties of the number, and torch/utils/_sympy/numbers.py has the actual implementation.

The rest of the changes of the PR are working out the implications of this change. I'll give more commentary as inline comments.

Fixes #127396

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

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @voznesenskym @penguinwu @EikanWang @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Jun 1, 2024

🔗 Helpful Links

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

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

✅ You can merge normally! (6 Unrelated Failures)

As of commit 0b36b03 with merge base f681e36 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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: fx release notes category labels Jun 1, 2024
ezyang added a commit that referenced this pull request Jun 1, 2024
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

ghstack-source-id: 50bb181cf53418b172ff45389036d2cd55086880
Pull Request resolved: #127693
ezyang added a commit that referenced this pull request Jun 3, 2024
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

ghstack-source-id: 50bb181cf53418b172ff45389036d2cd55086880
Pull Request resolved: #127693
[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jun 3, 2024
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

ghstack-source-id: 838dffaf03e082891db95993c0158f912853a9b2
Pull Request resolved: #127693
[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jun 3, 2024
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

ghstack-source-id: 8c06ad470cd4721d3dd9ef1e0acdd07f7f5be5dd
Pull Request resolved: #127693
[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jun 3, 2024
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

ghstack-source-id: 58a04544490be9a22abfec273277aebca9068e8d
Pull Request resolved: #127693
[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jun 3, 2024
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

ghstack-source-id: ef3063b7f97002dde7e1effbb91961d4997d193d
Pull Request resolved: #127693
[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jun 4, 2024
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

ghstack-source-id: b6d509ef0eddc17f4c1bc9bb10512d1dd08c9898
Pull Request resolved: #127693
return math.inf
if val == -sympy.oo:
if val in (-sympy.oo, -int_oo):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@angelayi @avikchaudhuri This is a bit suspicious, because math.inf is not an integer. But I guess that's what your code used to do? Another option is when you have bounds like this is to return None.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah None would be better.

facebook-github-bot pushed a commit to pytorch/executorch that referenced this pull request Jun 11, 2024
Summary:

In a previous life, we used sympy.oo to represent the lower/upper bounds of integer ranges. Later, we changed this to be sys.maxsize - 1 for a few reasons: (1) sometimes we do tests on a value being exactly sys.maxsize, and we wanted to avoid a data dependent guard in this case, (2) sympy.oo corresponds to floating point infinity, so you get incorrect types for value ranges with oo, and (3) you can do slightly better reasoning if you assume that input sizes fall within representable 64-bit integer range.

After working in the sys.maxsize regime for a bit, I've concluded that this was actually a bad idea. Specifically, the problem is that you end up with sys.maxsize in your upper bound, and then whenever you do any sort of size-increasing computation like size * 2, you end up with 2 * sys.maxsize, and you end up doing a ton of arbitrary precision int computation that is totally unnecessary. A symbolic bound is better.

But especially after #126905, we can't go back to using sympy.oo, because that advertises that it's not an integer, and now your ValueRanges is typed incorrectly. So what do we do? We define a new numeric constant `int_oo`, which is like `sympy.oo` but it advertises `is_integer`. **test/test_sympy_utils.py** describes some basic properties of the number, and **torch/utils/_sympy/numbers.py** has the actual implementation.

The rest of the changes of the PR are working out the implications of this change. I'll give more commentary as inline comments.

Fixes pytorch/pytorch#127396

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

X-link: pytorch/pytorch#127693
Approved by: https://github.com/lezcano
ghstack dependencies: #126905

bypass-github-export-checks pushed new commits to forward fix error

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/9cab5987bdeb66df8efbc581b3469bfe300e168c

Differential Revision: D58394154

Pulled By: clee2000
facebook-github-bot pushed a commit to pytorch/executorch that referenced this pull request Jun 11, 2024
Summary:

In a previous life, we used sympy.oo to represent the lower/upper bounds of integer ranges. Later, we changed this to be sys.maxsize - 1 for a few reasons: (1) sometimes we do tests on a value being exactly sys.maxsize, and we wanted to avoid a data dependent guard in this case, (2) sympy.oo corresponds to floating point infinity, so you get incorrect types for value ranges with oo, and (3) you can do slightly better reasoning if you assume that input sizes fall within representable 64-bit integer range.

After working in the sys.maxsize regime for a bit, I've concluded that this was actually a bad idea. Specifically, the problem is that you end up with sys.maxsize in your upper bound, and then whenever you do any sort of size-increasing computation like size * 2, you end up with 2 * sys.maxsize, and you end up doing a ton of arbitrary precision int computation that is totally unnecessary. A symbolic bound is better.

But especially after #126905, we can't go back to using sympy.oo, because that advertises that it's not an integer, and now your ValueRanges is typed incorrectly. So what do we do? We define a new numeric constant `int_oo`, which is like `sympy.oo` but it advertises `is_integer`. **test/test_sympy_utils.py** describes some basic properties of the number, and **torch/utils/_sympy/numbers.py** has the actual implementation.

The rest of the changes of the PR are working out the implications of this change. I'll give more commentary as inline comments.

Fixes pytorch/pytorch#127396

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

X-link: pytorch/pytorch#127693
Approved by: https://github.com/lezcano
ghstack dependencies: #126905

bypass-github-export-checks pushed new commits to forward fix error

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/9cab5987bdeb66df8efbc581b3469bfe300e168c

Differential Revision: D58394154

Pulled By: clee2000
@clee2000
Copy link
Contributor

@pytorchbot revert -m "sorry executorch CI is a bit weird regarding pins, I'll make a chat with mergen with the choices of what to do and how it'll affect executorch CI, reverting for now to prevent more divergences in the meantime" -c ghfirst

@pytorchmergebot
Copy link
Collaborator

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

pytorchmergebot added a commit that referenced this pull request Jun 11, 2024
This reverts commit 9cab598.

Reverted #127693 on behalf of https://github.com/clee2000 due to sorry executorch CI is a bit weird regarding pins, I'll make a chat with mergen with the choices of what to do and how it'll affect executorch CI, reverting for now to prevent more divergences in the meantime ([comment](#127693 (comment)))
@pytorchmergebot
Copy link
Collaborator

@ezyang your PR has been successfully reverted.

facebook-github-bot pushed a commit to pytorch/executorch that referenced this pull request Jun 12, 2024
Summary: This is needed for pytorch/pytorch#127693 . This code is written so it is compatible before and after this PR.

Differential Revision: D58465158
ezyang added a commit to pytorch/executorch that referenced this pull request Jun 12, 2024
Summary:
Pull Request resolved: #3947

This is needed for pytorch/pytorch#127693 . This code is written so it is compatible before and after this PR.

Differential Revision: D58465158
facebook-github-bot pushed a commit to pytorch/executorch that referenced this pull request Jun 12, 2024
Summary:

This is needed for pytorch/pytorch#127693 . This code is written so it is compatible before and after this PR.

Reviewed By: mergennachin

Differential Revision: D58465158
ezyang added a commit to pytorch/executorch that referenced this pull request Jun 12, 2024
Summary:
Pull Request resolved: #3947

This is needed for pytorch/pytorch#127693 . This code is written so it is compatible before and after this PR.

Reviewed By: mergennachin

Differential Revision: D58465158
facebook-github-bot pushed a commit to pytorch/executorch that referenced this pull request Jun 12, 2024
Summary:
Pull Request resolved: #3947

This is needed for pytorch/pytorch#127693 . This code is written so it is compatible before and after this PR.

Reviewed By: mergennachin, clee2000

Differential Revision: D58465158

fbshipit-source-id: ca0f2a79eb07e78ff2887f78eb62ff38eeea3ede
@ezyang
Copy link
Contributor Author

ezyang commented Jun 13, 2024

@pytorchbot merge

@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

@clee2000 clee2000 mentioned this pull request Jun 13, 2024
pytorchmergebot pushed a commit that referenced this pull request Jun 13, 2024
merge at will
After #125968
and #127693
landrace

Pull Request resolved: #128587
Approved by: https://github.com/huydhn
TharinduRusira pushed a commit to TharinduRusira/pytorch that referenced this pull request Jun 14, 2024
In a previous life, we used sympy.oo to represent the lower/upper bounds of integer ranges. Later, we changed this to be sys.maxsize - 1 for a few reasons: (1) sometimes we do tests on a value being exactly sys.maxsize, and we wanted to avoid a data dependent guard in this case, (2) sympy.oo corresponds to floating point infinity, so you get incorrect types for value ranges with oo, and (3) you can do slightly better reasoning if you assume that input sizes fall within representable 64-bit integer range.

After working in the sys.maxsize regime for a bit, I've concluded that this was actually a bad idea. Specifically, the problem is that you end up with sys.maxsize in your upper bound, and then whenever you do any sort of size-increasing computation like size * 2, you end up with 2 * sys.maxsize, and you end up doing a ton of arbitrary precision int computation that is totally unnecessary. A symbolic bound is better.

But especially after pytorch#126905, we can't go back to using sympy.oo, because that advertises that it's not an integer, and now your ValueRanges is typed incorrectly. So what do we do? We define a new numeric constant `int_oo`, which is like `sympy.oo` but it advertises `is_integer`. **test/test_sympy_utils.py** describes some basic properties of the number, and **torch/utils/_sympy/numbers.py** has the actual implementation.

The rest of the changes of the PR are working out the implications of this change. I'll give more commentary as inline comments.

Fixes pytorch#127396

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

Pull Request resolved: pytorch#127693
Approved by: https://github.com/lezcano
ghstack dependencies: pytorch#126905
TharinduRusira pushed a commit to TharinduRusira/pytorch that referenced this pull request Jun 14, 2024
This reverts commit 9cab598.

Reverted pytorch#127693 on behalf of https://github.com/clee2000 due to sorry executorch CI is a bit weird regarding pins, I'll make a chat with mergen with the choices of what to do and how it'll affect executorch CI, reverting for now to prevent more divergences in the meantime ([comment](pytorch#127693 (comment)))
TharinduRusira pushed a commit to TharinduRusira/pytorch that referenced this pull request Jun 14, 2024
In a previous life, we used sympy.oo to represent the lower/upper bounds of integer ranges. Later, we changed this to be sys.maxsize - 1 for a few reasons: (1) sometimes we do tests on a value being exactly sys.maxsize, and we wanted to avoid a data dependent guard in this case, (2) sympy.oo corresponds to floating point infinity, so you get incorrect types for value ranges with oo, and (3) you can do slightly better reasoning if you assume that input sizes fall within representable 64-bit integer range.

After working in the sys.maxsize regime for a bit, I've concluded that this was actually a bad idea. Specifically, the problem is that you end up with sys.maxsize in your upper bound, and then whenever you do any sort of size-increasing computation like size * 2, you end up with 2 * sys.maxsize, and you end up doing a ton of arbitrary precision int computation that is totally unnecessary. A symbolic bound is better.

But especially after pytorch#126905, we can't go back to using sympy.oo, because that advertises that it's not an integer, and now your ValueRanges is typed incorrectly. So what do we do? We define a new numeric constant `int_oo`, which is like `sympy.oo` but it advertises `is_integer`. **test/test_sympy_utils.py** describes some basic properties of the number, and **torch/utils/_sympy/numbers.py** has the actual implementation.

The rest of the changes of the PR are working out the implications of this change. I'll give more commentary as inline comments.

Fixes pytorch#127396

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

Pull Request resolved: pytorch#127693
Approved by: https://github.com/lezcano
ghstack dependencies: pytorch#126905
TharinduRusira pushed a commit to TharinduRusira/pytorch that referenced this pull request Jun 14, 2024
merge at will
After pytorch#125968
and pytorch#127693
landrace

Pull Request resolved: pytorch#128587
Approved by: https://github.com/huydhn
ignaciobartol pushed a commit to ignaciobartol/pytorch that referenced this pull request Jun 14, 2024
This reverts commit 9cab598.

Reverted pytorch#127693 on behalf of https://github.com/clee2000 due to sorry executorch CI is a bit weird regarding pins, I'll make a chat with mergen with the choices of what to do and how it'll affect executorch CI, reverting for now to prevent more divergences in the meantime ([comment](pytorch#127693 (comment)))
ignaciobartol pushed a commit to ignaciobartol/pytorch that referenced this pull request Jun 14, 2024
In a previous life, we used sympy.oo to represent the lower/upper bounds of integer ranges. Later, we changed this to be sys.maxsize - 1 for a few reasons: (1) sometimes we do tests on a value being exactly sys.maxsize, and we wanted to avoid a data dependent guard in this case, (2) sympy.oo corresponds to floating point infinity, so you get incorrect types for value ranges with oo, and (3) you can do slightly better reasoning if you assume that input sizes fall within representable 64-bit integer range.

After working in the sys.maxsize regime for a bit, I've concluded that this was actually a bad idea. Specifically, the problem is that you end up with sys.maxsize in your upper bound, and then whenever you do any sort of size-increasing computation like size * 2, you end up with 2 * sys.maxsize, and you end up doing a ton of arbitrary precision int computation that is totally unnecessary. A symbolic bound is better.

But especially after pytorch#126905, we can't go back to using sympy.oo, because that advertises that it's not an integer, and now your ValueRanges is typed incorrectly. So what do we do? We define a new numeric constant `int_oo`, which is like `sympy.oo` but it advertises `is_integer`. **test/test_sympy_utils.py** describes some basic properties of the number, and **torch/utils/_sympy/numbers.py** has the actual implementation.

The rest of the changes of the PR are working out the implications of this change. I'll give more commentary as inline comments.

Fixes pytorch#127396

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

Pull Request resolved: pytorch#127693
Approved by: https://github.com/lezcano
ghstack dependencies: pytorch#126905
ignaciobartol pushed a commit to ignaciobartol/pytorch that referenced this pull request Jun 14, 2024
merge at will
After pytorch#125968
and pytorch#127693
landrace

Pull Request resolved: pytorch#128587
Approved by: https://github.com/huydhn
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 Merged module: cpu CPU specific problem (e.g., perf, algorithm) module: dynamo module: inductor release notes: fx release notes category Reverted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants