RuntimeError: Input, output and indices must be on the current device

小灰灰 2023-01-13 04:15 113阅读 0赞

我看了一下模型的输入,都放到了GPU上,然后我在网上查了一下,发现我在模型内部创建了新的模型,这些新的模型也要放在GPU上

  1. self.bert = BertModel.from_pretrained(bert_config)
  2. self.multi_head1 = MultiHeadedAttention(8, 768, dropout)
  3. self.multi_head2 = MultiHeadedAttention(8, 768, dropout)
  4. self.linear1 = nn.Linear(768, 1)
  5. self.linear2 = nn.Linear(512, 1)
  6. self.bert = BertModel.from_pretrained(bert_config)
  7. self.multi_head1 = MultiHeadedAttention(8, 768, dropout).to(conf['device'])
  8. self.multi_head2 = MultiHeadedAttention(8, 768, dropout).to(conf['device'])
  9. self.linear1 = nn.Linear(768, 1).to(conf['device'])
  10. self.linear2 = nn.Linear(512, 1).to(conf['device'])

上面一个是报错前的代码,下面是放到GPU上后,运行没毛病的代码。很奇怪欸,bert也没to(conf[‘device’])呀,为啥就能跑呢

发表评论

表情:
评论列表 (有 0 条评论,113人围观)

还没有评论,来说两句吧...

相关阅读