Closed dami23 closed 6 years ago
Hi,
could you try
model = model.cuda()
in cell 2? Thanks, Alexis
@aconneau thank you for your reply, I tried model = model.cuda(), the error: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #4 'mat1' from line "embeddings = model.encode(sentences, bsize=128, tokenize=False, verbose=True)". the problem is the sentences also need to be transformed to a tensor, but fromnumpy() can't convert type numpy.str to a tensor. So, could you give me a solution about this problem? Sincerely thank you for your kindness help!
I tried on my side and it worked so I wasn't able to reproduce the issue. Could you output the full error message?
Which pytorch version are you using?
File "/informatik2/tams/home/mi/lieber_mi/projects/object_affordance/code/InferSent/demo.py", line 36, in
This is the full error. I use python3.5 and pytorch 0.4.0.
Hi,
I think I understand where the error comes from.
In https://github.com/facebookresearch/InferSent/blob/master/models.py#L51 I check whether the model has been put on cuda or not. This might not work anymore since the new version of pytorch. Could you modify this line and print
print(type(self.enc_lstm.bias_hh_l0.data))
right before line 51?
Thanks
the output is <class 'torch.Tensor'>. It is true, the model has not been put on cuda. I tried on pytorch 0.5.0, the error is same. Thank you for your help!
Maybe I find an "answer". I modified the line 51 in model.py to return 'cuda' (the latter part "in str(type(self.enc_lstm.bias_hh_l0.data))" is commented). And now, the embedding can run on GPU.
So in the new pytorch version (>=0.4), the type of a Tensor which is on cuda is not "torch.cudaTensor" anymore but still "torch.Tensor", hence the error.
To fix the issue, could you modify the line : https://github.com/facebookresearch/InferSent/blob/master/models.py#L51
by
return self.enc_lstm.bias_hh_l0.data.is_cuda
and see if it works?
Thanks
@aconneau your solution is the correct answer, it worked. Thank you for reply and help, best regards!!
The demo.ipynb and extract_feature.py in dir encoder/ are run on cpu. Could you give me a cue to run the two codes on GPU? Thank you for your help!