Make sympify'ing SymInt/etc produce their sympy expression (#130166)

There is one huge problem this fixes: today, sympify(symint)
produces a float(!!) because Sympy attempts to see if you can
coerce the symint to float in sympify and of course this works on
SymInt.

However, this also has another nontrivial effect: anywhere in Inductor
where sympy expressions are passed around, it is also valid to pass
around a SymInt now.  I'm ambivalent about this: it's currently a
mistake to be passing around a SymInt when a sympy expression is
expected.  But maybe this is fine?

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

Pull Request resolved: https://github.com/pytorch/pytorch/pull/130166
Approved by: https://github.com/yf225
This commit is contained in:
Edward Z. Yang
2024-07-05 13:35:15 -07:00
committed by PyTorch MergeBot
parent acd03ca2d9
commit 10c831567b
3 changed files with 19 additions and 3 deletions

View File

@ -281,9 +281,7 @@ def convert_shape_to_inductor(
trivial. But for symbolic tensors, we need to map from SymIntNode into
sympy.Expr.
"""
return [
i.node.expr if isinstance(i, torch.SymInt) else sympy.Integer(i) for i in lst
]
return [sympy.sympify(i) for i in lst]
def convert_shape_to_symint(