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

[Bug]: RuntimeError: Error(s) in loading state_dict for XLMRobertaModel: Unexpected key(s) in state_dict: "embeddings.position_ids". #3347

Open
brestok-1 opened this issue Oct 22, 2023 · 2 comments
Labels
Awaiting Response Waiting for new input from the author bug Something isn't working

Comments

@brestok-1
Copy link

Describe the bug

I'm trying to use this model. I even have an example from the site that doesn't work. Unknown error that I do not know how to solve. Please help or fix it

To Reproduce

from flair.data import Sentence
from flair.models import SequenceTagger

# load tagger
tagger = SequenceTagger.load("flair/ner-dutch-large")

# make example sentence
sentence = Sentence("George Washington ging naar Washington")

# predict NER tags
tagger.predict(sentence)

# print sentence
print(sentence)

# print predicted NER spans
print('The following NER tags are found:')
# iterate over entities and print
for entity in sentence.get_spans('ner'):
    print(entity)

Expected behavior

Span [1,2]: "George Washington" [− Labels: PER (1.0)]
Span [5]: "Washington" [− Labels: LOC (1.0)]

Logs and Stack traces

Traceback (most recent call last):
  File "/home/maksim/Development/pythonprojects/gpt_training.py", line 5, in <module>
    tagger = SequenceTagger.load("flair/ner-dutch-large")
  File "/home/maksim/.local/lib/python3.10/site-packages/flair/models/sequence_tagger_model.py", line 1035, in load
    return cast("SequenceTagger", super().load(model_path=model_path))
  File "/home/maksim/.local/lib/python3.10/site-packages/flair/nn/model.py", line 559, in load
    return cast("Classifier", super().load(model_path=model_path))
  File "/home/maksim/.local/lib/python3.10/site-packages/flair/nn/model.py", line 191, in load
    state = load_torch_state(model_file)
  File "/home/maksim/.local/lib/python3.10/site-packages/flair/file_utils.py", line 359, in load_torch_state
    return torch.load(f, map_location="cpu")
  File "/home/maksim/.local/lib/python3.10/site-packages/torch/serialization.py", line 1014, in load
    return _load(opened_zipfile,
  File "/home/maksim/.local/lib/python3.10/site-packages/torch/serialization.py", line 1422, in _load
    result = unpickler.load()
  File "/home/maksim/.local/lib/python3.10/site-packages/flair/embeddings/transformer.py", line 1169, in __setstate__
    self.model.load_state_dict(model_state_dict)
  File "/home/maksim/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2152, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for XLMRobertaModel:
	Unexpected key(s) in state_dict: "embeddings.position_ids".

Screenshots

No response

Additional Context

No response

Environment

Versions:

Flair

0.12.2

Pytorch

2.1.0+cu121

Transformers

4.34.1

GPU

False

@brestok-1 brestok-1 added the bug Something isn't working label Oct 22, 2023
@helpmefindaname
Copy link
Collaborator

Hi @brestok-1
this sounds to me like an issue that was solved in #3346 and works on the current master branch.
Can you please verify this?

@helpmefindaname helpmefindaname added the Awaiting Response Waiting for new input from the author label Oct 23, 2023
@semlommers
Copy link

Still not working for me. Installing the packages as described here solves it for me: #3346 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Response Waiting for new input from the author bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants