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

Fix inductor sub with symbolic integers. #108518

Closed
wants to merge 7 commits into from
2 changes: 0 additions & 2 deletions test/inductor/test_torchinductor_dynamic_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ def div(x):
test(div)

@onlyCPU
@unittest.expectedFailure
# Ref: https://github.com/pytorch/pytorch/issues/108159
def test_sub_constant_folding(self, device):
def sub(x):
return x - torch.zeros(3)
Expand Down
7 changes: 6 additions & 1 deletion torch/_inductor/lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,12 @@ def const_func(x):
)
)
elif isinstance(x, sympy.Expr):
out.append(IndexingConstant(x, ex.get_dtype(), ex.get_device()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

You still need to create an IndexingConstant node here, just wrap it in ExpandView.create.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I see. Thanks for the help, @peterbell10.

out.append(
ExpandView.create(
IndexingConstant(x, ex.get_dtype(), ex.get_device()),
list(ex.get_size()),
)
)
else:
out.append(x)

Expand Down