我是靠谱客的博主 谦让小兔子,这篇文章主要介绍RuntimeError: Input, output and indices must be on the current device,现在分享给大家,希望可以做个参考。
我看了一下模型的输入,都放到了GPU上,然后我在网上查了一下,发现我在模型内部创建了新的模型,这些新的模型也要放在GPU上
self.bert = BertModel.from_pretrained(bert_config)
self.multi_head1 = MultiHeadedAttention(8, 768, dropout)
self.multi_head2 = MultiHeadedAttention(8, 768, dropout)
self.linear1 = nn.Linear(768, 1)
self.linear2 = nn.Linear(512, 1)
self.bert = BertModel.from_pretrained(bert_config)
self.multi_head1 = MultiHeadedAttention(8, 768, dropout).to(conf['device'])
self.multi_head2 = MultiHeadedAttention(8, 768, dropout).to(conf['device'])
self.linear1 = nn.Linear(768, 1).to(conf['device'])
self.linear2 = nn.Linear(512, 1).to(conf['device'])
上面一个是报错前的代码,下面是放到GPU上后,运行没毛病的代码。很奇怪欸,bert也没to(conf['device'])呀,为啥就能跑呢
最后
以上就是谦让小兔子最近收集整理的关于RuntimeError: Input, output and indices must be on the current device的全部内容,更多相关RuntimeError:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复