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

Error Loading Model RuntimeError: Error(s) in loading state_dict for GPT2LMHeadModel: #3

Closed
raviolli opened this issue Sep 2, 2020 · 7 comments

Comments

@raviolli
Copy link

raviolli commented Sep 2, 2020

Traceback (most recent call last):
  File "train_summary_loop.py", line 59, in <module>
    summarizer = GeneTransformer(max_output_length=args.max_output_length, device=args.device, tokenizer_type='gpt2', starter_model=summarizer_model_start)
  File "/home/tait-dev-0/summary_loop/summary_loop/model_generator.py", line 30, in __init__
    self.reload(starter_model)
  File "/home/tait-dev-0/summary_loop/summary_loop/model_generator.py", line 39, in reload
    print(self.model.load_state_dict(torch.load(from_file)))
  File "/home/tait-dev-0/anaconda2/envs/summary_loop/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1045, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for GPT2LMHeadModel:
	Missing key(s) in state_dict: "transformer.h.0.attn.masked_bias", "transformer.h.1.attn.masked_bias", "transformer.h.2.attn.masked_bias", "transformer.h.3.attn.masked_bias", "transformer.h.4.attn.masked_bias", "transformer.h.5.attn.masked_bias", "transformer.h.6.attn.masked_bias", "transformer.h.7.attn.masked_bias", "transformer.h.8.attn.masked_bias", "transformer.h.9.attn.masked_bias", "transformer.h.10.attn.masked_bias", "transformer.h.11.attn.masked_bias". 

@raviolli
Copy link
Author

raviolli commented Sep 2, 2020

install transformers = 2.9.0

@raviolli raviolli closed this as completed Sep 2, 2020
@jqJordan
Copy link

Hey I am having the same problem, but at line 96, where it loads from the fluency_news_bs32.bin. I tried multiple versions of the transformer, 2.9.0, 2.8.0, 2.9.1. It didn't resolve the issue. Any idea why? Thank you.

@ashutosh-dwivedi-e3502
Copy link

Hi, I can confirm that the issue persists even with multiple version of transformers.
Can you provide a fix for this?

@s103321048
Copy link

s103321048 commented Mar 9, 2021

I'm also facing the same issue. I've also tried multiple version (from 2.8.0 - 3.2.0) of transformers but it seems like changing version won't help.
Found a relate issue here not so sure what version did the author train on?

@s103321048
Copy link

Add strict=False in line 39 of model_generator.py

    def reload(self, from_file):
        print(self.model.load_state_dict(torch.load(from_file),strict=False))

Since there are no such keys in state_dict, just let the model ignore it.

@ahtsham58
Copy link

I solved the issue by adding strict=False as a parameter. Thanks man

@theDikshaSaxena
Copy link

@s103321048 thanks man, it solved my issue

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

6 participants