-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Introduce int_oo #127693
Conversation
Signed-off-by: Edward Z. Yang <ezyang@meta.com> ghstack-source-id: 50bb181cf53418b172ff45389036d2cd55086880 Pull Request resolved: #127693
Signed-off-by: Edward Z. Yang <ezyang@meta.com> ghstack-source-id: 50bb181cf53418b172ff45389036d2cd55086880 Pull Request resolved: #127693
Signed-off-by: Edward Z. Yang <ezyang@meta.com> ghstack-source-id: 838dffaf03e082891db95993c0158f912853a9b2 Pull Request resolved: #127693
Signed-off-by: Edward Z. Yang <ezyang@meta.com> ghstack-source-id: 8c06ad470cd4721d3dd9ef1e0acdd07f7f5be5dd Pull Request resolved: #127693
Signed-off-by: Edward Z. Yang <ezyang@meta.com> ghstack-source-id: 58a04544490be9a22abfec273277aebca9068e8d Pull Request resolved: #127693
Signed-off-by: Edward Z. Yang <ezyang@meta.com> ghstack-source-id: ef3063b7f97002dde7e1effbb91961d4997d193d Pull Request resolved: #127693
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
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
@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 |
@pytorchbot successfully started a revert job. Check the current status here. |
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)))
@ezyang your PR has been successfully reverted. |
Summary: This is needed for pytorch/pytorch#127693 . This code is written so it is compatible before and after this PR. Differential Revision: D58465158
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
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
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
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
@pytorchbot merge |
Merge startedYour 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 |
merge at will After #125968 and #127693 landrace Pull Request resolved: #128587 Approved by: https://github.com/huydhn
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
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)))
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
merge at will After pytorch#125968 and pytorch#127693 landrace Pull Request resolved: pytorch#128587 Approved by: https://github.com/huydhn
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)))
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
merge at will After pytorch#125968 and pytorch#127693 landrace Pull Request resolved: pytorch#128587 Approved by: https://github.com/huydhn
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 likesympy.oo
but it advertisesis_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