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

RuntimeError: Expected object of backend CUDA but got backend CPU for argument #3 'index' #13

Open
ouening opened this issue Dec 25, 2019 · 1 comment

Comments

@ouening
Copy link

ouening commented Dec 25, 2019

Hi, when I train Quora dataset I got errors like below:

epoch: 1
Traceback (most recent call last):
  File "train.py", line 151, in <module>
    main()
  File "train.py", line 141, in main
    best_model = train(args, data)
  File "train.py", line 70, in train
    pred = model(**kwargs)
  File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/media/gaoya/disk/Applications/pytorch/NLP/BIMPM-pytorch-master/model/BIMPM.py", line 219, in forward
    p = self.word_emb(kwargs['p'])
  File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/torch/nn/modules/sparse.py", line 114, in forward
    self.norm_type, self.scale_grad_by_freq, self.sparse)
  File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 1467, in embedding
    return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected object of backend CUDA but got backend CPU for argument #3 'index'

Can someone help me fix it?

@Howardqlz
Copy link

I met the same problem. I fix it like this:
p = self.word_emb([kwargs['p'].cuda(self.args.gpu)])

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

2 participants