Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information