All input tensors must be on the same device. Received cuda:1 and cuda:0

When i tried to test one trained model with torch,it was an error.The error is as follows:
Traceback (most recent call last):
File “run.py”, line 152, in
main()
File “run.py”, line 86, in main
saver.write_test_img(ep, i, model, index_a = index_a, index_b = index_b)
File “/home/zhangwei/LADN/src/saver.py”, line 123, in write_test_img
assembled_images = model.assemble_outputs()
File “/home/zhangwei/LADN/src/model.py”, line 933, in assemble_outputs
row1 = torch.cat((images_a[0:1, ::], images_b1[0:1, ::], images_b2[0:1, ::], images_a4[0:1, ::], images_a3[0:1, ::]),3)
RuntimeError: All input tensors must be on the same device. Received cuda:1 and cuda:0
And my command is

CUDA_DEVICE_ORDER=PCI_BUS_ID CUDA_VISIBLE_DEVICES=0,1 python3 run.py --backup_gpu 1 --dataroot ../datasets/makeup --name makeup_test --resize_size 576 --crop_size 512 --local_style_dis --n_local 12 --phase test --test_forward --test_random --result_dir ../results --test_size 300 --resume ../models/light.pth --no_extreme

i’d really appreacite it if someone could help me with it.

Hi,

As mentioned in the error message, the Tensors you give to the cat operations are on different devices which is not allowed. You need to move all the Tensors to the same device before calling cat.

1 Like

Thanks for you suggestion.But i didn’t call the cat operations actually,did i?I am still a little confused.

From the error message you posted, it seems cat operation has been used here:

File “/home/zhangwei/LADN/src/model.py”, line 933, in assemble_outputs

Thanks.I have found it.

Thanks.I have found it! I try to debug it.

1 Like