Skip to content

F.interpolate returns NAN on MPS if align_corner is True. #144245

@benHeid

Description

@benHeid

🐛 Describe the bug

When using interpolate on MPS with align_corner=True, the result consists only of NaN value, which is inconsistent to the CPU implementation.

You can replicate this by the following code snippet:

import torch
import torch.nn.functional as F


test = torch.Tensor([[1],[2],[4]]).to("mps")
result = F.interpolate(test.unsqueeze(1), 3, mode="linear", align_corners=True).squeeze(1)

print(result)
# tensor([[nan, nan, nan],
#         [nan, nan, nan],
#         [nan, nan, nan]], device='mps:0')
test = torch.Tensor([[1],[2],[4]]).to("cpu")
result = F.interpolate(test.unsqueeze(1), 3, mode="linear", align_corners=True).squeeze(1)

print(result)
# tensor([[1., 1., 1.],
#         [2., 2., 2.],
#         [4., 4., 4.]])

Versions

Collecting environment information...
PyTorch version: 2.5.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 15.1 (arm64)
GCC version: Could not collect
Clang version: 16.0.0 (clang-1600.0.26.4)
CMake version: Could not collect
Libc version: N/A

Python version: 3.11.9 (main, Jun 29 2024, 14:01:21) [Clang 15.0.0 (clang-1500.1.0.2.5)] (64-bit runtime)
Python platform: macOS-15.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

CPU:
Apple M2

Versions of relevant libraries:
[pip3] flake8==7.1.1
[pip3] mypy==1.11.2
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.4
[pip3] pytorch-forecasting==1.1.1
[pip3] pytorch-lightning==2.4.0
[pip3] pytorch_optimizer==2.12.0
[pip3] torch==2.5.1
[pip3] torchmetrics==1.4.1
[pip3] torchvision==0.19.0
[conda] Could not collect

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki @kulinseth @malfet @DenisVieriu97 @jhavukainen

Metadata

Metadata

Assignees

Labels

module: correctness (silent)issue that returns an incorrect result silentlymodule: mpsRelated to Apple Metal Performance Shaders frameworkmodule: nnRelated to torch.nntriagedThis 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