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

2022/3/21 23:33:12

本文主要是介绍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 object of device type cuda but got device type cpu...的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程