deeppavlov / DeepPavlov

An open source library for deep learning end-to-end dialog systems and chatbots.
https://deeppavlov.ai
Apache License 2.0
6.68k stars 1.15k forks source link

TypeError: rsub() received an invalid combination of arguments - got (Tensor, str), but expected one of: #1355

Closed vcjob closed 3 years ago

vcjob commented 3 years ago

Want to contribute to DeepPavlov? Please read the contributing guideline first.

Please enter all the information below, otherwise your issue may be closed without a warning.

DeepPavlov version (you can look it up by running pip show deeppavlov): 0.13.0

Python version: 3.6.9

Operating system (ubuntu linux, windows, ...): Ubuntu 16.04

Issue: Can not use bert sentance embedder due to the error. torch version '1.7.0+cpu'

Content or a name of a configuration file:

configs.embedder.bert_sentence_embedder

Command that led to error:

>>> from deeppavlov import build_model, configs
>>> m = build_model(configs.embedder.bert_sentence_embedder, download=True)
>>> texts = ['Hi, i want my embedding.', 'And mine too, please!']
>>> sent_max_embs, sent_mean_embs, bert_pooler_outputs = m(texts)

Error (including full traceback):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/ssd/APIs/venv_bert_sentance_api/lib/python3.6/site-packages/deeppavlov/core/common/chainer.py", line 207, in __call__
    return self._compute(*args, param_names=self.in_x, pipe=self.pipe, targets=self.out_params)
  File "/ssd/APIs/venv_bert_sentance_api/lib/python3.6/site-packages/deeppavlov/core/common/chainer.py", line 230, in _compute
    res = component.__call__(*x)
  File "/ssd/APIs/venv_bert_sentance_api/lib/python3.6/site-packages/deeppavlov/models/embedders/transformers_embedder.py", line 75, in __call__
    max_emb = torch.max(last_hidden - 1e9 * (1 - attention_tensor), dim=1)[0]
  File "/ssd/APIs/venv_bert_sentance_api/lib/python3.6/site-packages/torch/tensor.py", line 511, in __rsub__
    return _C._VariableFunctions.rsub(self, other)
TypeError: rsub() received an invalid combination of arguments - got (Tensor, str), but expected one of:
 * (Tensor input, Tensor other, *, Number alpha)
 * (Tensor input, Number other, Number alpha)
yurakuratov commented 3 years ago

Hi!

DeepPavlov requires torch 1.6.0: https://github.com/deepmipt/DeepPavlov/blob/master/deeppavlov/requirements/pytorch.txt#L1

All needed requirements for a specific model could be installed with

! python -m deeppavlov install bert_sentence_embedder

Does changing torch version work for you?

vcjob commented 3 years ago

Hi!

DeepPavlov requires torch 1.6.0: https://github.com/deepmipt/DeepPavlov/blob/master/deeppavlov/requirements/pytorch.txt#L1

All needed requirements for a specific model could be installed with

! python -m deeppavlov install bert_sentence_embedder

Does changing torch version work for you?

Thank you! It does work now!