其他分享
首页 > 其他分享> > Expected object of device type cuda but got device type cpu...

Expected object of device type cuda but got device type cpu...

作者:互联网

Pytorch RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 ‘self’ in call to _th_index_select

这个报错的原因是:模型的部分参数或数据不在GPU而在CPU上。

遇到这个问题需要仔细排查, 模型是否已经放在在GPU上, 通常使用

model = model.cuda()
data = data.cuda()

把模型和数据分别放到GPU上。 这个一般不会出错, 除此之外, 需要排查在这些操作之后是否又对模型或数据进行了其他操作, 导致部分参数不在GPU上的情况。

标签:...,Expected,cuda,got,device,GPU,type
来源: https://blog.csdn.net/leo0308/article/details/123647265