RuntimeError: expected device cuda:0 but got device cpu


While developing my GNNs, I finally faced a problem that I can’t understand without help.
The problem is

/opt/conda/envs/py36/lib/python3.6/site-packages/torch/nn/ in l1_loss(input, target, size_average, reduce, reduction)
2189 else:
2190 expanded_input, expanded_target = torch.broadcast_tensors(input, target)
-> 2191 ret = torch._C._nn.l1_loss(expanded_input, expanded_target, _Reduction.get_enum(reduction))
2192 return ret

RuntimeError: expected device cuda:1 but got device cpu.

I checked that cuda is available and there are three GTX Titan V on a remote server. ( I’m working on this server)
I’m using pytorch 1.4.0, CUDA toolkit 10.1 cuDNN 7603.

There aren’t any errors before that line.
Thank you for your help in advance!

I guess you have to pass tensor to CUDA using input = input.cuda() and target=target.cuda() in your training script

You are right! Thank you so much!