Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False
时间: 2023-09-28 15:08:16 浏览: 144
这个错误意味着你正在尝试将一个在CUDA设备上序列化的对象反序列化,但是torch.cuda.is_available()返回的值为False,即CUDA不可用。
要解决这个问题,你可以在torch.load()函数后面添加map_location=torch.device('cpu')或者map_location='cpu'参数来将存储映射到CPU上。例如:
state_dict = torch.load(self.model_path, map_location=torch.device('cpu')) 或
state_dict = torch.load(self.model_path, map_location='cpu')
如果你看到了"AssertionError: Torch not compiled with CUDA enabled"错误,这意味着你的PyTorch没有启用CUDA。你可以去掉代码中所有的.cuda()函数调用来解决这个问题。你可以注释掉这些代码并保存,然后重新运行程序。
另外,你需要根据你的服务器上的CUDA版本选择适合的PyTorch版本。确保你安装了与服务器CUDA版本兼容的PyTorch版本。比如,如果你的服务器CUDA版本为11.0,你需要找到与之兼容的PyTorch版本,并进行相应的安装。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [pytorch出错: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False](https://blog.csdn.net/qq_27149279/article/details/106037681)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False.](https://blog.csdn.net/weixin_40438421/article/details/130514552)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文