8000 [Inductor] Fix the lowering of squeeze when input is not contiguous (… · pytorch/pytorch@18d8ee6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18d8ee6

Browse files
leslie-fang-intelRyo-not-rio
authored andcommitted
[Inductor] Fix the lowering of squeeze when input is not contiguous (#146746)
**Summary** Fix issue #143498. The issue happens when we lowering `select = torch.ops.aten.select.int(cat, 1, 0)`. For example, when `cat` is contiguous with size[2, 2] stride[2,1] - for eager, it returns a view of size[2,] stride[2,] - for Inductor lowering, it returns wrong stride 1 instead of 2 ``` TensorBox( ReinterpretView( StorageBox( ConcatKernel(name='buf10', layout=FixedLayout('cpu', torch.int64, size=[u0, 2], stride=[2, 1]), inputs=[ComputedBuffer(name='buf8', layout=NonOwningLayout('cpu', torch.int64, size=[u0, 1], stride=[2, 1]), data=Pointwise(device=device(type='cpu'), dtype=torch.int64, inner_fn=<function ReinterpretView.make_loader.<locals>.loader at 0x7f6b856449d0>, ranges=[u0, 1])), ComputedBuffer(name='buf9', layout=NonOwningLayout('cpu', torch.int64, size=[u0, 1], stride=[2, 1]), data=Pointwise(device=device(type='cpu'), dtype=torch.int64, inner_fn=<function ReinterpretView.make_loader.<locals>.loader at 0x7f6b85644790>, ranges=[u0, 1]))]) ), FixedLayout('cpu', torch.int64, size=[u0], stride=[**1**]), origins=OrderedSet([select]) ) ) ``` To fix this issue, we give the right stride when lowering of `squeeze`. **Test Plan** ``` python -u -m pytest -s -v test/inductor/test_unbacked_symints.py -k test_issue_143498 ``` Pull Request resolved: #146746 Approved by: https://github.com/jgong5, https://github.com/sanchitintel, https://github.com/eellison
1 parent 9ae7fc4 commit 18d8ee6

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

test/inductor/test_unbacked_symints.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,6 @@ def fn(t, start, length):
389389
@skipGPUIf(not HAS_GPU, "requires gpu and triton")
390390
@dynamo_config.patch(capture_dynamic_output_shape_ops=True)
391391
def test_issue_143498(self, device):
392-
if device == "cpu":
393-
raise unittest.SkipTest("CPU Failure")
394-
395392
class Model(torch.nn.Module):
396393
def __init__(self) -> None:
397394
super().__init__()

torch/_inductor/ir.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,9 @@ def fake_reindex(index): # type: ignore[no-untyped-def]
27772777
# TODO: unbacked should not diverge from backed in determining striding
27782778
# Need to require contiguous here instead of realize, see:
27792779
# https://github.com/pytorch/pytorch/issues/145561
2780-
x = ExternKernel.require_contiguous(x)
2780+
x = ExternKernel.require_exact_strides(
2781+
x, FlexibleLayout.contiguous_strides(x.get_size())
2782+
)
27812783

27822784
storage, old_layout = as_storage_and_layout(x, want_contiguous=True)
27832785
new_layout = FixedLayout(

0 commit comments

Comments
 (0)
0