Skip to content

Commit

Permalink
[inductor] Restore ExpandView sanity checks (pytorch#127251)
Browse files Browse the repository at this point in the history
This restores the assertion removed in pytorch#124864

The handling of unbacked symints is incidental, the main purpose of this assert
was to catch bugs in lowerings.

Pull Request resolved: pytorch#127251
Approved by: https://github.com/lezcano
  • Loading branch information
peterbell10 authored and pytorchmergebot committed May 28, 2024
1 parent db0a0ec commit 26a8fa3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions torch/_inductor/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,7 @@ class ExpandView(BaseView):
@staticmethod
def _normalize_size(x, new_size):
"""Replace `-1` with correct sizes"""
sizevars = V.graph.sizevars
new_size = list(map(sympy.expand, new_size))
old_size = x.get_size()
old_size = [None] * (len(new_size) - len(old_size)) + list(old_size)
Expand All @@ -1948,12 +1949,14 @@ def _normalize_size(x, new_size):
elif old_size[i] is None or old_size[i] == 1:
pass
else:
# NB: new_size[i] == old_size[i] is known because the meta
# formula was expected to have taught us this equality.
# We can't conveniently check it right now because
# statically_known_equals doesn't know to consult preexisting
# guards
pass
# Sanity check: Expect broadcast compatibility
#
# NB: new_size[i] == old_size[i] is expected to already be
# guarded because the meta formula was expected to have taught
# us this equality.
assert (
sizevars.size_hint(new_size[i] - old_size[i], fallback=0) == 0
), "Broadcast failed in ExpandView({x.get_size()}, {new_size}) on dimension {i}"
return new_size

@classmethod
Expand Down

0 comments on commit 26a8fa3

Please sign in to comment.