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

can't load ner-multi : 'LanguageModel' object has no attribute '_load_state_dict_pre_hooks' #2279

Closed
alexisbenichoux opened this issue May 19, 2021 · 2 comments · Fixed by #2322
Labels
bug Something isn't working

Comments

@alexisbenichoux
Copy link

Describe the bug
Multi lingual models (both ner or pos) fails to load after download inside torch nn.
I don't have any problems with other ner packages

To Reproduce

from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-multi-fast")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/flair/flair/nn.py", line 93, in load
    model = cls._init_model_with_state_dict(state)
  File "/home/flair/flair/models/sequence_tagger_model.py", line 297, in _init_model_with_state_dict
    model.load_state_dict(state["state_dict"])
  File "/root/anaconda3/envs/flair/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1037, in load_state_dict
    load(self)
  File "/root/anaconda3/envs/flair/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1035, in load
    load(child, prefix + name + '.')
  File "/root/anaconda3/envs/flair/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1035, in load
    load(child, prefix + name + '.')
  File "/root/anaconda3/envs/flair/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1035, in load
    load(child, prefix + name + '.')
  File "/root/anaconda3/envs/flair/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1031, in load
    module._load_from_state_dict(
  File "/root/anaconda3/envs/flair/lib/python3.9/site-packages/torch/nn/modules/module.py", line 957, in _load_from_state_dict
    for hook in self._load_state_dict_pre_hooks.values():
  File "/root/anaconda3/envs/flair/lib/python3.9/site-packages/torch/nn/modules/module.py", line 778, in __getattr__
    raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'LanguageModel' object has no attribute '_load_state_dict_pre_hooks'
  • tried on macos 11.1, python 3.8 and python 3.6 and 3.9.4
  • torch 1.7.1 (conda env from requirements)
  • Version flair 0.8.2 (I tried both pip install and pip from github repo)
@alexisbenichoux alexisbenichoux added the bug Something isn't working label May 19, 2021
@alanakbik
Copy link
Collaborator

Hm that's strange. I just checked and it works in Flair 0.7. Have to take a closer look.

@alexisbenichoux
Copy link
Author

Thanks ! it works fine with flair 0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants