Closed wasiahmad closed 7 years ago
I solved the issue by using .tolist()
for numpy array as follows.
idx_sort = torch.cuda.LongTensor(idx_sort.tolist()) if self.use_cuda else torch.LongTensor(idx_sort)
line 53. suffers from same issue.
Glad you solved the issue. I'm a bit blind here because I'm using python 2.7 but can you try and replace this line with: "idx_sort = torch.from_numpy(idx_sort).cuda() if self.use_cuda else torch.from_numpy(idx_sort)" and let me know if that fixes the problem? Thanks
Yes, this solves the issue because torch.from_numpy()
returns a torch.LongTensor
and converting it to cuda suffices.
Thanks.
For the record, is this the only thing you needed to change in the models.py to make the model work in python 3.5?
Yes. No other changes are required :)
260bfd45c915529dd5ab75a55d3aa3b94432dee0 : fixed bug in models.py using torch.from_numpy for python 3.5.
I guess my error is due to that line as well: https://github.com/facebookresearch/InferSent/issues/5
what does the error mean?
@wasiahmad is the .tolist()
method a numpy or pytorch thing? [its sort of hard to follow whats going on cuz I can't see the code or the type of ur code that lead to these errors]
just for the record , I too got this error , nothing solved my issue. May be there will be people like me so just giving heads up
When you define a Field in torchtext by default it is torch.LongTensor , so you can pass whatever type you want like this data.Field(sequential=False, use_vocab=False,tensor_type=torch.cuda.FloatTensor)
defining the data.Field as mentioned by @imtiazBDSgit solved my error. thanks.
Traceback (most recent call last):
File "train_nli.py", line 291, in
torch.from_numpy()
it actually returns doubleTensor
I tried to run the train_nli.py file to train your model but got the following error.
Any guess why I am getting this error? I am using python 3.5, can it be a reason?