Conv2d con kernel 1x1 no funciona en la GPU, aunque funciona bien en la CPU:
net = nn.Conv2d(1, 6, kernel_size=(1,1))
net.cuda()
x = Variable(torch.randn(1, 1, 100, 100))
x.cuda()
net(x)
Mensaje de error:
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)
Intenté deshabilitar cudnn con torch.backends.cudnn.enabled = False
pero aún recibí el mismo mensaje de error.
Utilizo Ubuntu 14.04, Cuda 7.5, Cudnn 5.1.5, Python 3.5.2 y Pytorch se instala desde binarios.
Si observa detenidamente los tipos de argumentos que se asignaron a conv, verá que algunos de los tensores son torch.cuda.FloatTensor
s, mientras que los otros son torch.FloatTensor
s. Probablemente olvidó enviar la entrada a la GPU.
Para aclarar, en lugar de:
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
Deberías escribir:
x = Variable(torch.randn(1, 1, 100, 100).cuda())
Creo que es mejor hacer que model.cuda()
y x.cuda()
comporte
Comentario más útil
Para aclarar, en lugar de:
Deberías escribir: