Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected object of device type cuda but got device type cpu for argument #3 'index' in call to _th_index_select #8

Closed
netblind opened this issue Dec 19, 2019 · 3 comments

Comments

@netblind
Copy link

GPU训练的时候报错:
Expected object of device type cuda but got device type cpu for argument #3 'index' in call to _th_index_select
Traceback (most recent call last):
File "train.py", line 431, in
main()
File "train.py", line 425, in main
train(model, device, train_list, multi_gpu, args)
File "train.py", line 319, in train
raise exception
File "train.py", line 283, in train
outputs = model.forward(input_ids=input_ids)
File "D:\ProgramData\Anaconda3\envs\pytorchspace\lib\site-packages\transformers\modeling_gpt2.py", line 533, in forward
head_mask=head_mask)
File "D:\ProgramData\Anaconda3\envs\pytorchspace\lib\site-packages\torch\nn\modules\module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "D:\ProgramData\Anaconda3\envs\pytorchspace\lib\site-packages\transformers\modeling_gpt2.py", line 420, in forward
inputs_embeds = self.wte(input_ids)
File "D:\ProgramData\Anaconda3\envs\pytorchspace\lib\site-packages\torch\nn\modules\module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "D:\ProgramData\Anaconda3\envs\pytorchspace\lib\site-packages\torch\nn\modules\sparse.py", line 114, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "D:\ProgramData\Anaconda3\envs\pytorchspace\lib\site-packages\torch\nn\functional.py", line 1484, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected object of device type cuda but got device type cpu for argument #3 'index' in call to _th_index_select

解决方案:
train.py第280行:input_ids.to(device) 修改为:input_ids = input_ids.to(device) 即可正常运行

@yangjianxin1
Copy link
Owner

我在训练时这个报错倒是还没有遇到过,谢谢

@pergrand
Copy link

请问这个问题解决了吗

@netblind
Copy link
Author

上面有解决方案
解决方案:
train.py第280行:input_ids.to(device) 修改为:input_ids = input_ids.to(device) 即可正常运行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants