galsang / BIMPM-pytorch

Re-implementation of BIMPM (Bilateral Multi-Perspective Matching for Natural Language Sentences, Zhiguo Wang et al.) on Pytorch.
106 stars 31 forks source link

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

Open ouening opened 4 years ago

ouening commented 4 years ago

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 commented 4 years ago

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