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.
If you look closely at the argument types that were given to conv, you'll see that some of the tensors are torch.cuda.FloatTensor
s, while the others are torch.FloatTensor
s. 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.
Most helpful comment
To clarify, instead of:
You should write: