RuntimeError: Input type (CUDAFloatTensor) and weight type (CPUFloatTensor) should be the same

I am training a GAN model, i want to train it 200 epochs, but when it comes to the second epoch, an error comes:
RuntimeError: Input type (CUDAFloatTensor) and weight type (CPUFloatTensor) should be the same

I have put the data and model into gpu yet, and the first epoch training is fine, where did this error come?

Could you please provide more context behind what your model looks like? You’re right that it’s strange that after one good epoch of training the model crashes with that assertion.

My model is based on cyclegan model,its about 600 lines, and part of it is here:https://gist.github.com/yingdiLee/de3c8c13a06109249aa78838e584a4e7. If it is not clear enough, I can provide all of the source code, thank you for your help !

I have the same problem …

RuntimeError: Input type (CUDAFloatTensor) and weight type (CPUFloatTensor) should be the same

1 Like

it seems like after first epoch of training the parameters of model changes from torch.cuda.FloatTensor to torch.FloatTensor, I do not know if it is from my definition of model or somewhere else, and it makes me crazy…

Ah. got my problem solve. missing lines

if use_cuda:
    net.cuda()
    net = torch.nn.DataParallel(net, device_ids=range(torch.cuda.device_count()))
    cudnn.benchmark = True
2 Likes