之前我配置了以下项目
https://github.com/zllrunning/face-makeup.PyTorch
使用CUDA=10.2的Pytorch,现在Windows不支持CUDA=10.2Pytorch。因此,当我使用Pytorch配置CUDA=11.3的同一项目时,我会得到以下错误:
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.
请帮我解决这个问题。
我通过在model_zoo.load_url
方法中添加map_location=lambda storage, loc: storage.cuda()
解决了这个问题。我认为在torch 1.12中,他们已经将默认位置从GPU更改为CPU(这没有任何意义(。
编辑:在文件resnet.py中,在函数definit_weight(self(:下
state_dict=modelzoo.load_url(resnet18_url(
使用更改
state_dict=modelzoo.load_url(resnet18_url,map_location=lambda存储,loc:storage.cuda(((
与resnet没有特别的关系,但下面的代码应该适用于与"不知道如何恢复torc.storage_untype storage(用gpu标记(的数据位置
import torch
import whisper
devices = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = whisper.load_model("medium" , device =devices)