gpt4 book ai didi

Tensor for ‘out‘ is on CPU, Tensor for argument #1 ‘self‘ is on CPU

转载 作者:知者 更新时间:2024-03-13 03:43:12 31 4
gpt4 key购买 nike

1、问题
模型训练完后进行测试,报错

RuntimeError: Tensor for 'out' is on CPU, Tensor for argument #1 'self' is on CPU, but expected them to be on GPU (while checking arguments for addmm)

2、原因
将模型送入GPU之后才加载之前训练好的模型,导致模型加载到了GPU,然而你的网络权重还在CPU中,此时会报错如下,报错部分代码:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
net.to(device)
net.load_state_dict(torch.load('./results/bestmodel30.pth'),False)

3、解决
换下位置即可

net.load_state_dict(torch.load('./results/bestmodel30.pth'),False)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
net.to(device)

原文链接:https://blog.csdn.net/weixin_43760844/article/details/116047427

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com