Skip to content

[Solved][PyTorch] RuntimeError: Attempting to deserialize object on CUDA device 3 but torch.cuda.device_count() is 1.

This is a strange error message:

RuntimeError: Attempting to deserialize object on CUDA
 device 3 but torch.cuda.device_count() is 1.

This error occurred when I was loading the trained model. My understanding is that because I used the No.3 GPU for training when I was training, but I was on a different device when I was testing, and the device has only on GPU, so I can’t find it when I load the model.

It is worth noting that using to() or cuda() cannot solve this problem, because both of them do the conversion of the device after reading the data in, but the current problem is “the data cannot be read in”.

I checked it on the Internet and found a way to read it successfully.

torch.load("MODEL_NAME", map_location='cpu')



For example, when reading the model, directly set the CPU or other available GPU in the rear parameter map_location, so that the device will be automatically used to access data when reading.


References


Read More

Leave a ReplyCancel reply

Click to Copy
Exit mobile version