Skip to content

Commit

Permalink
Use maxint to bound integers.
Browse files Browse the repository at this point in the history
We don't actually support arbitrary precision integers.

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

ghstack-source-id: cefcf018e6c1fcebc48b1678142711ce09596465
Pull Request resolved: #96121
  • Loading branch information
ezyang committed Mar 6, 2023
1 parent 6fff232 commit f2c750c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions torch/fx/experimental/symbolic_shapes.py
Expand Up @@ -1334,7 +1334,7 @@ def create_unbacked_symfloat(self):
def create_unbacked_symint(self):
symbol = sympy.Symbol(f"i{next(self.unbacked_symint_counter)}", integer=True)
self.var_to_stack[symbol] = ''.join(traceback.format_list(traceback.extract_stack()[:-1]))
self.var_to_range[symbol] = ValueRanges.unknown()
self.var_to_range[symbol] = ValueRanges(-sys.maxsize - 1, sys.maxsize)
return SymInt(SymNode(symbol, self, int, None))

# This is guaranteed to return a symbol or its negation is a sympy.Symbol,
Expand All @@ -1361,7 +1361,10 @@ def create_symbol(self, val: int, source: Source, dyn=False) -> "sympy.Expr":

# We also infer that it must be not 0/1
lower = 2 if self.specialize_zero_one else 0
self.var_to_range[sympy_expr] = ValueRanges(lower, sympy.oo)
# NB: sys.maxsize is NOT allowed for sizes, because we use MAX_INT
# as a sentinel sometimes. Your sizevar isn't going to be
# anywhere near the max 64-bit integer anyway.
self.var_to_range[sympy_expr] = ValueRanges(lower, sys.maxsize - 1)

if not dyn and self.duck_shape:
# This implements duck-shaping: input sizes that match are assigned
Expand Down

0 comments on commit f2c750c

Please sign in to comment.