Pytorch: Error when doing CUDA Conv2d with 1x1 kernel.

Created on 23 Jan 2017  ·  3Comments  ·  Source: pytorch/pytorch

Conv2d with 1x1 kernel is not working on GPU, although it works fine on CPU:

net = nn.Conv2d(1, 6, kernel_size=(1,1))
net.cuda()
x = Variable(torch.randn(1, 1, 100, 100))
x.cuda()
net(x)

Error message:

TypeError: FloatSpatialConvolutionMM_updateOutput received an invalid combination of arguments - got (int, torch.FloatTensor, torch.FloatTensor, torch.cuda.FloatTensor, torch.cuda.FloatTensor, torch.FloatTensor, torch.FloatTensor, int, int, int, int, int, int), but expected (int state, torch.FloatTensor input, torch.FloatTensor output, torch.FloatTensor weight, [torch.FloatTensor bias or None], torch.FloatTensor finput, torch.FloatTensor fgradInput, int kW, int kH, int dW, int dH, int padW, int padH)

I tried disabling cudnn with torch.backends.cudnn.enabled = False but still got the same error message.

I use Ubuntu 14.04, Cuda 7.5, Cudnn 5.1.5, Python 3.5.2, and Pytorch is installed from binaries.

Most helpful comment

To clarify, instead of:

x = Variable(torch.randn(1, 1, 100, 100))
x.cuda()  # This creates a copy on the GPU and immediately discards it. "x" is still on the CPU

You should write:

x = Variable(torch.randn(1, 1, 100, 100).cuda())

All 3 comments

If you look closely at the argument types that were given to conv, you'll see that some of the tensors are torch.cuda.FloatTensors, while the others are torch.FloatTensors. You probably forgot to send the input to the GPU.

To clarify, instead of:

x = Variable(torch.randn(1, 1, 100, 100))
x.cuda()  # This creates a copy on the GPU and immediately discards it. "x" is still on the CPU

You should write:

x = Variable(torch.randn(1, 1, 100, 100).cuda())

I think it it better to make model.cuda() and x.cuda() behaves consistently to avoid confusion.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bartolsthoorn picture bartolsthoorn  ·  3Comments

SeparateReality picture SeparateReality  ·  3Comments

soumith picture soumith  ·  3Comments

soumith picture soumith  ·  3Comments

rajarshd picture rajarshd  ·  3Comments