torch-mlir/lib/Conversion
Xinyu Yang d4313eed4a
[Torch] Add decomposition of RepeatInterleaveSelfInt Op (#3075)
Decomposition RepeatInterleaveSelfInt with following ops:
```python

def my_repeat_interleave(input, repeats, dim=None):
    if dim is None:
        # Flatten the input and then repeat
        return input.flatten().unsqueeze(-1).tile((1, repeats)).flatten()
    else:
        # Calculate the shape after repeat
        expanded_shape = list(input.shape)
        expanded_shape[dim] *= repeats
        # Repeat the tensor along the specified dimension
        repeat_shape = [1] * (input.dim() + 1)
        repeat_shape[dim + 1] = repeats
        input = input.unsqueeze(-1)

        # Tile and then reshape
        tiled = torch.tile(input, repeat_shape)
        # Rearrange and reshape
        repeated = tiled.reshape(*expanded_shape)
    return repeated

```

I passed the tests of stablehlo and linalg. When testing onnx, strange
things happened.
In torch-mlir's CI **torch_nightly** and my own
environment(torch==2.4.0.dev20240318+cpu), it can **pass the pass**.
In torch-mlir's CI  **torch_stable**, it **failed**.
The test case is `RepeatInterleaveSelfIntNoDimModule_basic`, the result
shape should be [120].
```python
class RepeatInterleaveSelfIntNoDimModule(torch.nn.Module):

    def __init__(self):
        super().__init__()

    @export
    @annotate_args([
        None,
        ([3, 4, 5], torch.float32, True),
    ])
    def forward(self, x):
        return x.repeat_interleave(2)


@register_test_case(module_factory=lambda: RepeatInterleaveSelfIntNoDimModule())
def RepeatInterleaveSelfIntNoDimModule_basic(module, tu: TestUtils):
    module.forward(tu.rand(3, 4, 5))
```
The error log is as follows:
```
  Unexpected outcome summary: (onnx)
  
  ****** Failed tests - 1 tests
      FAIL - "RepeatInterleaveSelfIntNoDimModule_basic"
          @ trace item #0 - call to "forward"
          @ output of call to "forward"
          ERROR: shape (torch.Size([6, 4, 5])) is not equal to golden shape (torch.Size([120]))
```

@rsuderman 
Would you please help me check what's wrong with my PR? Thanks a lot.
2024-04-18 06:27:51 +08:00
..
TorchConversionToMLProgram Clang format refresh (#2812) 2024-01-29 12:59:33 -05:00
TorchOnnxToTorch [onnx][torch][linalg] Implementing align-corner modes for gridsampler (#3171) 2024-04-17 13:38:19 -07:00
TorchToArith Fix deprecated uses of cast/dyn_cast/dyn_cast_or_null/isa (#3130) 2024-04-11 06:47:35 -07:00
TorchToLinalg [onnx][torch][linalg] Implementing align-corner modes for gridsampler (#3171) 2024-04-17 13:38:19 -07:00
TorchToSCF Fix deprecated uses of cast/dyn_cast/dyn_cast_or_null/isa (#3130) 2024-04-11 06:47:35 -07:00
TorchToStablehlo [Torch] Add decomposition of RepeatInterleaveSelfInt Op (#3075) 2024-04-18 06:27:51 +08:00
TorchToTMTensor [torch] Support implicit batch for index_put (#3128) 2024-04-11 10:18:03 -07:00
TorchToTensor [torch] Improve shape inference for `torch-to-linalg` path for reshapes (#3055) 2024-03-26 12:41:40 -07:00
TorchToTosa Fix deprecated uses of cast/dyn_cast/dyn_cast_or_null/isa (#3130) 2024-04-11 06:47:35 -07:00
Utils Fix deprecated uses of cast/dyn_cast/dyn_cast_or_null/isa (#3130) 2024-04-11 06:47:35 -07:00
CMakeLists.txt [torch] Improve shape inference for `torch-to-linalg` path for reshapes (#3055) 2024-03-26 12:41:40 -07:00
PassDetail.h Minor fixes for `ConvertTorchConversionToMLProgram`. (#1991) 2023-04-04 09:09:58 -07:00
Passes.cpp Clang format refresh (#2812) 2024-01-29 12:59:33 -05:00