'RuntimeError: Attempted to set the storage of a tensor on device "cuda:0" to a storage on different device "cpu"

Earlier I have configured the following project

https://github.com/zllrunning/face-makeup.PyTorch

using Pytorch with CUDA=10.2, Now Pytorch with CUDA=10.2 support is not available for Windows. So, when I am configuring the same project using Pytorch with CUDA=11.3, then I am getting the following error:

RuntimeError: Attempted to set the storage of a tensor on device "cuda:0" to a storage on different device "cpu".  This is no longer allowed; the devices must match.

Please help me in solving this problem.



Solution 1:[1]

I solved this by adding map_location=lambda storage, loc: storage.cuda() in the model_zoo.load_url method. I think in torch 1.12 they have changed the default location from GPU to CPU (which does not make any sense)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vinayak Kumar