BertForSequenceClassification : 'module 'Torch' has no attribute 'BoolTensor'
Author: jakobbrown
Pull request: no

Hi there,

error on line:

'''
from transformers import BertForSequenceClassification
'''

Resulting in the following errror:

'''
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\transformers\file_utils.py in _get_module(self, module_name)
   2149         try:
-> 2150             return importlib.import_module("." + module_name, self.__name__)
   2151         except Exception as e:

C:\ProgramData\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _load_unlocked(spec)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap_external.py in exec_module(self, module)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

C:\ProgramData\Anaconda3\lib\site-packages\transformers\models\bert\modeling_bert.py in <module>
     49 )
---> 50 from ...modeling_utils import (
     51     PreTrainedModel,

C:\ProgramData\Anaconda3\lib\site-packages\transformers\modeling_utils.py in <module>
     47 )
---> 48 from .generation_utils import GenerationMixin
     49 from .utils import logging

C:\ProgramData\Anaconda3\lib\site-packages\transformers\generation_utils.py in <module>
     26 from .generation_beam_search import BeamScorer, BeamSearchScorer
---> 27 from .generation_logits_process import (
     28     EncoderNoRepeatNGramLogitsProcessor,

C:\ProgramData\Anaconda3\lib\site-packages\transformers\generation_logits_process.py in <module>
    346 
--> 347 class NoBadWordsLogitsProcessor(LogitsProcessor):
    348     """

C:\ProgramData\Anaconda3\lib\site-packages\transformers\generation_logits_process.py in NoBadWordsLogitsProcessor()
    397 
--> 398     def _calc_static_bad_word_mask(self, scores: torch.FloatTensor) -> torch.BoolTensor:
    399         static_bad_words_mask = torch.zeros(scores.shape[1])

AttributeError: module 'torch' has no attribute 'BoolTensor'

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-5-b88f39dd1009> in <module>
----> 1 model = transformers.BertForSequenceClassification

C:\ProgramData\Anaconda3\lib\site-packages\transformers\file_utils.py in __getattr__(self, name)
   2139         elif name in self._class_to_module.keys():
   2140             module = self._get_module(self._class_to_module[name])
-> 2141             value = getattr(module, name)
   2142         else:
   2143             raise AttributeError(f"module {self.__name__} has no attribute {name}")

C:\ProgramData\Anaconda3\lib\site-packages\transformers\file_utils.py in __getattr__(self, name)
   2138             value = self._get_module(name)
   2139         elif name in self._class_to_module.keys():
-> 2140             module = self._get_module(self._class_to_module[name])
   2141             value = getattr(module, name)
   2142         else:

C:\ProgramData\Anaconda3\lib\site-packages\transformers\file_utils.py in _get_module(self, module_name)
   2152             raise RuntimeError(
   2153                 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its traceback):\n{e}"
-> 2154             ) from e
   2155 
   2156     def __reduce__(self):

RuntimeError: Failed to import transformers.models.bert.modeling_bert because of the following error (look up to see its traceback):
module 'torch' has no attribute 'BoolTensor'
'''

Unsure as to how to proceed.
PyTorch = 1.0.1
Unsure of the version of transformers as it's not appearing in my anaconda packages. But the rest of transformers can import and work fine so i know it's there.

Any help greatly appreciated, thanks!

Jakob

Comments:
Hi @jakobbrown , the same is working for me with this version of packages.
transformers - '4.6.0'
torch - '1.10.0+cu102'

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.