Skip to content

"error: invalid axis (0,-1) for shape of rank 1" calling torch.nn.functional.linear on Mac MPS #84591

@damian0815

Description

@damian0815

🐛 Describe the bug

Calling torch.nn.functional.linear with "mps" tensors of rank 1 works fine on CPU but crashes on macOS M1 MPS:

import torch
import torch.nn.functional as F

#device = "cpu"
device = "mps"
projected = torch.rand([8]).to(device)
x = torch.rand([1, 3598, 4, 8]).to(device)
linear = F.linear(x, projected)

Crashes like this:

loc("mps_transpose"("(mpsFileLoc): /AppleInternal/Library/BuildRoots/20d6c351-ee94-11ec-bcaf-7247572f23b4/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShadersGraph/mpsgraph/MetalPerformanceShadersGraph/Core/Files/MPSGraphUtilities.mm":180:0)): error: invalid axis (0, -1) for shape of rank 1
LLVM ERROR: Failed to infer result type(s).

It works fine if device is "cpu", or if projected has shape [1,8] instead of just [8]:

projected = torch.rand([1,8]).to(device)

Versions

PyTorch version: 1.12.1
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.19.4
Libc version: N/A

Python version: 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:05:16)  [Clang 12.0.1 ] (64-bit runtime)
Python platform: macOS-12.5.1-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
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.2
[pip3] pytorch-lightning==1.7.4
[pip3] torch==1.12.1
[pip3] torchaudio==0.13.0.dev20220906
[pip3] torchmetrics==0.9.3
[pip3] torchvision==0.13.1
[conda] numpy                     1.23.2           py38h579d673_0    conda-forge
[conda] pytorch                   1.12.1                  py3.8_0    pytorch
[conda] pytorch-lightning         1.7.4                    pypi_0    pypi
[conda] torchaudio                0.13.0.dev20220906          pypi_0    pypi
[conda] torchmetrics              0.9.3                    pypi_0    pypi
[conda] torchvision               0.13.1                   pypi_0    pypi

cc @kulinseth @albanD

Metadata

Metadata

Assignees

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