Skip to content

Permute followed by torch.nn.functional.interpolate gives wrong results on mps backend #88183

@spiegelball

Description

@spiegelball

🐛 Describe the bug

The following code produces wrong results if interpolate is called after a permute operation on mps device.

def main():
    import torch
    import torch.nn.functional as F
    
    # construct tensor on cpu
    t = torch.ones([1, 1, 1, 2])
    t = t.permute(0, 3, 1, 2)
    t = F.interpolate(t, size=[2, 2], mode="bilinear", align_corners=False)

    #construct on mps
    t_mps = torch.ones([1, 1, 1, 2], device="mps")
    t_mps = t_mps.permute(0, 3, 1, 2).contiguous() # even applying contiguous() doesn't fix the problem
    t_mps = F.interpolate(t_mps, size=[2, 2], mode="bilinear", align_corners=False)

    # construct directly on mps with shape after permute
    t_mps_no_permute = torch.ones([1, 2, 1, 1], device="mps")
    t_mps_no_permute = F.interpolate(t_mps_no_permute, size=[2, 2], mode="bilinear", align_corners=False)

    print("cpu result: ", t)
    print("mps result: ", t_mps.cpu())
    print("mps no permute result: ", t_mps_no_permute.cpu())

    return

produces

cpu result:  tensor([[[[1., 1.],
          [1., 1.]],

         [[1., 1.],
          [1., 1.]]]])
mps result:  tensor([[[[0., 0.],
          [0., 0.]],

         [[0., 0.],
          [0., 0.]]]])
mps no permute result:  tensor([[[[1., 1.],
          [1., 1.]],

         [[1., 1.],
          [1., 1.]]]])

Versions

PyTorch version: 1.13.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 12.5.1 (arm64)
GCC version: Could not collect
Clang version: 13.1.6 (clang-1316.0.21.2.5)
CMake version: version 3.21.3
Libc version: N/A

Python version: 3.8.9 (default, May 17 2022, 12:55:41) [Clang 13.1.6 (clang-1316.0.21.2.5)] (64-bit runtime)
Python platform: macOS-12.5.1-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.23.4
[pip3] torch==1.13.0
[pip3] torchvision==0.14.0
[conda] numpy 1.23.2 pypi_0 pypi
[conda] torch 1.12.1 pypi_0 pypi

cc @kulinseth @albanD @malfet @DenisVieriu97 @razarmehr @abhudev

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: mpsRelated to Apple Metal Performance Shaders frameworktriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions