Source and weight input channels mismatch

I set the device to ‘mps’
but it shows:

/AppleInternal/Library/BuildRoots/b6051351-c030-11ec-96e9-3e7866fcf3a1/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShadersGraph/mpsgraph/MetalPerformanceShadersGraph/Runtimes/MPSRuntime/Operations/GPUConv2DOps.mm:214: failed assertion `Source and weight input channels mismatch'

and then the program quit.

it also continuous showed me that:

anaconda3/envs/Unet/lib/python3.8/site-packages/torch/amp/autocast_mode.py:198: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling
  warnings.warn('User provided device_type of \'cuda\', but CUDA is not available. Disabling')

What’s wrong with this. How can I solve it. Thank you.

/AppleInternal/Library/BuildRoots/b6051351-c030-11ec-96e9-3e7866fcf3a1/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShadersGraph/mpsgraph/MetalPerformanceShadersGraph/Runtimes/MPSRuntime/Operations/GPUConv2DOps.mm:214: failed assertion `Source and weight input channels mismatch’

Hi,

Are you using AMP? It does not support mps right now I’m afraid (We didn’t had time to work on that yet).
Also the channel mismatch error seems unrelated to mps. Do you get the same thing if you run on CPU?

Yes, I’m using the amp. Really thankful for your contribution.
Maybe there’s something with my code, I didn’t get the mismatch error when I used the device “cpu”

Can you try to run without AMP on MPS and see if that works?

I am getting this same error. As far as I’m aware I’m not using AMP. I do not get the same error if I run on CPU, everything runs fine until I use MPS with 2D convolution.

I was able to write a minimal reproducer.

import numpy as np
device = torch.device("mps")

conv = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=3).to(device)

data = torch.tensor(np.random.uniform(size=(1, 10, 10, 1)), dtype=torch.float32).to(device)
optimizer = torch.optim.Adam(conv.parameters(), lr=0.1)
x = data.permute(0, 3, 1, 2)
out = torch.sum(conv(x))
loss = torch.nn.MSELoss()(out, torch.zeros_like(out))
optimizer.zero_grad()
out.backward()
optimizer.step()

my output is

$ python3 reproducer.py
/AppleInternal/Library/BuildRoots/560148d7-a559-11ec-8c96-4add460b61a6/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShadersGraph/mpsgraph/MetalPerformanceShadersGraph/Runtimes/MPSRuntime/Operations/GPUConv2DOps.mm:214: failed assertion `Source and weight input channels mismatch'
zsh: abort      python3 reproducer.py

If I switch to the “cpu” device it runs without error. My torch versions are

torch 1.13.0.dev20220826
torchaudio 0.13.0.dev20220826
torchvision 0.14.0.dev20220826

1 Like

You forgot to import torch.
I can also reproduce this issue. Could you please issue this in the repository of torch in Github?

I am also seeing the same issue.
It seems like the issue is with permute operation.

Try the below:

import numpy as np
device = torch.device(“mps”)

conv = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=3).to(device)

data = torch.tensor(np.random.uniform(size=(1, 1, 10, 10)), dtype=torch.float32).to(device)

optimizer = torch.optim.Adam(conv.parameters(), lr=0.1)
x = data
out = torch.sum(conv(x))
loss = torch.nn.MSELoss()(out, torch.zeros_like(out))
optimizer.zero_grad()
out.backward()
optimizer.step()