简体   繁体   English

Pytorch模型问题:RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0

[英]Pytorch model problem: RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0

I have a problem with finding a place where I can implement sth like that model = model.to(device) .我很难找到一个可以像model = model.to(device)这样实现某事的地方。 Below I add stacktrace:下面我添加堆栈跟踪:

Traceback (most recent call last):
  File "main.py", line 161, in <module>
    algo.train()
  File "C:\Users\mati5\OneDrive\Pulpit\GAN\FAJNE\AttnGAN2(1)\code\trainer.py", line 329, in train
    fake_imgs, _, mu, logvar = netG(noise, sent_em_gpt, words_em_gpt, mask)
  File "C:\Anaconda\envs\attngan-new\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\mati5\OneDrive\Pulpit\GAN\FAJNE\AttnGAN2(1)\code\model.py", line 440, in forward
    c_code, mu, logvar = self.ca_net(sent_emb)
  File "C:\Anaconda\envs\attngan-new\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\mati5\OneDrive\Pulpit\GAN\FAJNE\AttnGAN2(1)\code\model.py", line 311, in forward
    mu, logvar = self.encode(text_embedding)
  File "C:\Users\mati5\OneDrive\Pulpit\GAN\FAJNE\AttnGAN2(1)\code\model.py", line 296, in encode
    x = self.relu(self.fc(text_embedding))
  File "C:\Anaconda\envs\attngan-new\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Anaconda\envs\attngan-new\lib\site-packages\torch\nn\modules\linear.py", line 103, in forward
    return F.linear(input, self.weight, self.bias)
  File "C:\Anaconda\envs\attngan-new\lib\site-packages\torch\nn\functional.py", line 1848, in linear
    return torch._C._nn.linear(input, weight, bias)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking argument for argument mat1 in method wrapper_addmm) 

Thanks for your help :D感谢您的帮助:D

It looks like your model and input tensors aren't on the same device.看起来您的模型和输入张量不在同一设备上。 Please make sure to use请务必使用

.to(device)

On the input too.输入也是。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RuntimeError: Expected all tensors to be on the same device,但发现至少有两个设备,cpu和cuda:0! 用我的 model 预测时 - RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! When predicting with my model google colab pytorch learning-RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 和 cpu - problems on google colab pytorch learning-RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu 卡在协作运行时错误:预计所有张量都在同一设备上,但发​​现至少有两个设备,cpu 和 cuda: - Stuck at Collab RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda: RuntimeError:预期所有张量都在同一设备上,但发现至少有两个设备,cuda:0 和 cpu! 恢复训练时 - RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! when resuming training RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 和 cpu on transormer - RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu on transormer 遇到此错误“RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu” - Stuck at this error "RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu" Pytorch 给出错误 Expected all tensors to be on the same device,但发现至少有两个设备,cuda:0 和 cpu - Pytorch gives error Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu RuntimeError:预期所有张量都在同一设备上 - RuntimeError: Expected all tensors to be on the same device RuntimeError: 期望生成器的“cuda”设备类型,但发现“cpu” - RuntimeError: Expected a 'cuda' device type for generator but found 'cpu' Pytorch 几何期望所有张量都在同一设备上[演示代码不起作用] - Pytorch Geometric Expected all tensors to be on the same device [demo code not working]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM