Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error running infersent.py #44

Open
fabrahman opened this issue Aug 15, 2018 · 2 comments
Open

Getting error running infersent.py #44

fabrahman opened this issue Aug 15, 2018 · 2 comments

Comments

@fabrahman
Copy link

fabrahman commented Aug 15, 2018

Hi, I am getting the following error which I believe has something to do with cuda and cpu version. Anyone face the same problem? I would appreciate help.

Traceback (most recent call last):
  File "infersent.py", line 76, in <module>
    results = se.eval(transfer_tasks)
  File "../senteval/engine.py", line 59, in eval
    self.results = {x: self.eval(x) for x in name}
  File "../senteval/engine.py", line 59, in <dictcomp>
    self.results = {x: self.eval(x) for x in name}
  File "../senteval/engine.py", line 121, in eval
    self.results = self.evaluation.run(self.params, self.batcher)
  File "../senteval/mrpc.py", line 74, in run
    embeddings = batcher(params, batch)
  File "infersent.py", line 43, in batcher
    embeddings = params.infersent.encode(sentences, bsize=params.batch_size, tokenize=False)
  File "/tilde/fbrahman/parc/SentEval/examples/models.py", line 226, in encode
    (batch, lengths[stidx:stidx + bsize])).data.cpu().numpy()
  File "/tilde/fbrahman/parc/SentEval/examples/models.py", line 68, in forward
    sent_output = self.enc_lstm(sent_packed)[0]  # seqlen x batch x 2*nhid
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/modules/rnn.py", line 192, in forward
    output, hidden = func(input, self.all_weights, hx, batch_sizes)
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/_functions/rnn.py", line 324, in forward
    return func(input, *fargs, **fkwargs)
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/_functions/rnn.py", line 244, in forward
    nexth, output = func(input, hidden, weight, batch_sizes)
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/_functions/rnn.py", line 87, in forward
    hy, output = inner(input, hidden[l], weight[l], batch_sizes)
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/_functions/rnn.py", line 159, in forward
    hidden = inner(step_input, hidden, *weight)
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/_functions/rnn.py", line 34, in LSTMCell
    gates = F.linear(input, w_ih, b_ih) + F.linear(hx, w_hh, b_hh)
  File "/tilde/fbrahman/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/functional.py", line 1024, in linear
    return torch.addmm(bias, input, weight.t())
RuntimeError: Expected object of type torch.cuda.FloatTensor but found type torch.FloatTensor for argument #4 'mat1'
@fabrahman
Copy link
Author

I tried degrading pytorch to version 0.3.1 and I did not get this error anymore, however, with that version I am getting error with data.items() as follows:

Traceback (most recent call last):
  File "bow.py", line 111, in <module>
    results = se.eval(transfer_tasks)
  File "../senteval/engine.py", line 59, in eval
    self.results = {x: self.eval(x) for x in name}
  File "../senteval/engine.py", line 59, in <dictcomp>
    self.results = {x: self.eval(x) for x in name}
  File "../senteval/engine.py", line 121, in eval
    self.results = self.evaluation.run(self.params, self.batcher)
  File "../senteval/mrpc.py", line 99, in run
    devacc, testacc, yhat = clf.run()
  File "../senteval/tools/validation.py", line 150, in run
    clf.fit(X_train, y_train, validation_data=(X_test, y_test))
  File "../senteval/tools/classifier.py", line 78, in fit
    self.trainepoch(trainX, trainy, epoch_size=self.epoch_size)
  File "../senteval/tools/classifier.py", line 108, in trainepoch
    all_costs.append(loss.data.item())
AttributeError: 'torch.cuda.FloatTensor' object has no attribute 'item'

@aconneau
Copy link
Contributor

aconneau commented Oct 4, 2018

Hi,

thanks for flagging this error. I think this is related to a recent fix in InferSent:

facebookresearch/InferSent@b303643

If you pull again InferSent and incorporate the changes in the commit above about models.py, it should fix your problem.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants