Closed kootenpv closed 7 years ago
This error is because of this line in attlayer.py
https://github.com/huggingface/torchMoji/blob/7c191048ce906fc0404fe156827d97cb990ebecb/torchmoji/attlayer.py#L56
If you have cuda, idxes
will be converted to cuda.LongTensor. This causes the problem since input_lengths.unsqueeze(1)
is non cuda. You cannot run <
operation on cuda and non-cuda data.
I suggest you to comment line 54 and 55 so that idxes
is not converted to cuda. It works!
Fixed, thanks again !
I tried running examples/encode_texts.py, it yielded the error at the end of the issue.
Story: I installed torch from the original torch downloads, and it appears it expects CUDA even though I assume it will just run with CPU (especially given the notificiation about GPU in the README).
Strangely, looking here: http://pytorch.org/
Whenever I select "pip", "3.6" and "none" (gpu), it still contains cu75 in the url which might indicate it needs CUDA?
Trace
pascal@archbook:~/gits/torchMoji$ python examples/encode_texts.py Tokenizing using dictionary from /home/pascal/gits/torchMoji/model/vocabulary.json Loading model from /home/pascal/gits/torchMoji/model/pytorch_model.bin. Loading weights for embed.weight Loading weights for lstm_0.weight_ih_l0 Loading weights for lstm_0.weight_hh_l0 Loading weights for lstm_0.bias_ih_l0 Loading weights for lstm_0.bias_hh_l0 Loading weights for lstm_0.weight_ih_l0_reverse Loading weights for lstm_0.weight_hh_l0_reverse Loading weights for lstm_0.bias_ih_l0_reverse Loading weights for lstm_0.bias_hh_l0_reverse Loading weights for lstm_1.weight_ih_l0 Loading weights for lstm_1.weight_hh_l0 Loading weights for lstm_1.bias_ih_l0 Loading weights for lstm_1.bias_hh_l0 Loading weights for lstm_1.weight_ih_l0_reverse Loading weights for lstm_1.weight_hh_l0_reverse Loading weights for lstm_1.bias_ih_l0_reverse Loading weights for lstm_1.bias_hh_l0_reverse Loading weights for attention_layer.attention_vector Ignoring weights for output_layer.0.weight Ignoring weights for output_layer.0.bias TorchMoji ( (embed): Embedding(50000, 256) (embed_dropout): Dropout2d (p=0) (lstm_0): LSTMHardSigmoid(256, 512, batch_first=True, bidirectional=True) (lstm_1): LSTMHardSigmoid(1024, 512, batch_first=True, bidirectional=True) (attention_layer): Attention(2304, return attention=False) ) Encoding texts.. Traceback (most recent call last): File "examples/encode_texts.py", line 34, in
encoding = model(tokenized)
File "/home/pascal/.pyenv/versions/3.6.2/lib/python3.6/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(*input, *kwargs)
File "/home/pascal/gits/torchMoji/torchmoji/model_def.py", line 233, in forward
x, att_weights = self.attention_layer(input_seqs, input_lengths)
File "/home/pascal/.pyenv/versions/3.6.2/lib/python3.6/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(input, **kwargs)
File "/home/pascal/gits/torchMoji/torchmoji/attlayer.py", line 56, in forward
mask = Variable((idxes < input_lengths.unsqueeze(1)).float())
File "/home/pascal/.pyenv/versions/3.6.2/lib/python3.6/site-packages/torch/tensor.py", line 351, in lt
return self.lt(other)
TypeError: lt received an invalid combination of arguments - got (torch.LongTensor), but expected one of: