How to Solve Error: RuntimeError: all tensors must be on devices[0]

Problem description

The code running Zheng Zhedong’s aicity2020 reported an error. After searching, it was found that the problem is that the code running is more than GPU, but the specified code is a single GPU

Solution:

In test2020.py, the code comments in lines 126 and 129 are replaced by the following code

# set gpu ids
# if len(gpu_ids)>0:
# torch.cuda.set_device(gpu_ids[0])
# cudnn.benchmark = True
os.environ['CUDA_VISIBLE_DEVICES'] = str(gpu_ids[0])

Read More: