Skip to content

[TorchToLinalg] Enable lowering of AtenMaxPool1dWithIndicesOp to linalg dialect #4214

Open
@zahidwx

Description

@zahidwx

Problem

Enable missing lowering of AtenMaxPool1dWithIndicesOp to linalg dialect.

module {
  func.func @MaxPool1dModule(%arg0: !torch.vtensor<[1,1,20],f32>) -> (!torch.vtensor<[1,1,8],f32>, !torch.vtensor<[1,1,8],si64>) {
    %false = torch.constant.bool false
    %int3 = torch.constant.int 3
    %int2 = torch.constant.int 2
    %int6 = torch.constant.int 6
    %0 = torch.prim.ListConstruct %int6 : (!torch.int) -> !torch.list<int>
    %1 = torch.prim.ListConstruct %int2 : (!torch.int) -> !torch.list<int>
    %2 = torch.prim.ListConstruct %int3 : (!torch.int) -> !torch.list<int>
    %3 = torch.prim.ListConstruct %int2 : (!torch.int) -> !torch.list<int>
    %result0, %result1 = torch.aten.max_pool1d_with_indices %arg0, %0, %1, %2, %3, %false : !torch.vtensor<[1,1,20],f32>, !torch.list<int>, !torch.list<int>, !torch.list<int>, !torch.list<int>, !torch.bool -> !torch.vtensor<[1,1,8],f32>, !torch.vtensor<[1,1,8],si64>
    return %result0, %result1 : !torch.vtensor<[1,1,8],f32>, !torch.vtensor<[1,1,8],si64>
  }
}
error: failed to legalize operation 'torch.constant.int'
TORCH_VERSION_FOR_COMPARISON = 2.8.0.dev20250512
error: failed to legalize operation 'torch.constant.int'

Repro steps:
./e2e_test.sh --config=fx_importer -f MaxPool1dWithIndicesModule -s -v

class MaxPool1dWithIndicesModule(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.mp1d_with_indices = torch.nn.MaxPool1d(
            kernel_size=[6], stride=[2], padding=[3], dilation=2, return_indices=True
        )
    @export
    @annotate_args(
        [
            None,
            ([-1, -1, -1], torch.float32, True),
        ]
    )
    def forward(self, x):
        return self.mp1d_with_indices(x)

@register_test_case(module_factory=lambda: MaxPool1dWithIndicesModule())
def MaxPool1dWithIndicesModule_basic(module, tu: TestUtils):
    module.forward(tu.rand(1, 1, 20, low=-1))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions