pytorch-seq2seq icon indicating copy to clipboard operation
pytorch-seq2seq copied to clipboard

Error for cuda and cpu

Open lucasjinreal opened this issue 6 years ago • 8 comments

/pytorch-seq2seq/seq2seq/models/EncoderRNN.py", line 68, in forward
    embedded = self.embedding(input_var)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 479, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/sparse.py", line 113, in forward
    self.norm_type, self.scale_grad_by_freq, self.sparse)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 1283, 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'

lucasjinreal avatar Dec 19 '18 12:12 lucasjinreal

@jinfagang could you try running your code with develop branch?

pskrunner14 avatar Dec 25 '18 08:12 pskrunner14

bug bug bug !!!!!!!!!!!!!!!!!!!!!!!!!!!! waste my time!!!!!!!!!!!

Huijun-Cui avatar Dec 26 '18 15:12 Huijun-Cui

@Hujun-Cui I think this repo is not active maintained now.

lucasjinreal avatar Dec 26 '18 16:12 lucasjinreal

@jinfagang this has been a recurring issue, however the fix has already been made on the develop branch. Will update on master soon. Please see #180 for a simple workaround.

pskrunner14 avatar Dec 26 '18 16:12 pskrunner14

The wrong code is at line 75 of supervised_trainer.py and line 38 of evaluator.py. I change them to device = torch.device('cuda:0') if torch.cuda.is_available() else -1 and CUDA is available now.

v587su avatar May 21 '19 03:05 v587su

I think this should be merged in master now.

rain1024 avatar Jul 11 '19 01:07 rain1024

The wrong code is at line 75 of supervised_trainer.py and line 38 of evaluator.py. I change them to device = torch.device('cuda:0') if torch.cuda.is_available() else -1 and CUDA is available now.

Except the two files, is there any other file need to fix? After fix the two files, the code still be incorrect...

Hexagram-King avatar Dec 01 '19 09:12 Hexagram-King

The wrong code is at line 75 of supervised_trainer.py and line 38 of evaluator.py. I change them to device = torch.device('cuda:0') if torch.cuda.is_available() else -1 and CUDA is available now.

Except the two files, is there any other file need to fix? After fix the two files, the code still be incorrect...

No, but you need to re-install the package after you do these corrections. Running python setup.py install again helped in my case.

isekulic avatar May 24 '21 20:05 isekulic