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

RunTimeError: Error(s) in loading state_dict for RobertaForSequenceClassification even after transformer==2.9.1 #35

Open
Marvy101 opened this issue Dec 23, 2022 · 12 comments

Comments

@Marvy101
Copy link

I get the following error after trying to run

pip install -r requirements.txt
python -m detector.server detector-base.pt

Error:

RuntimeError: Error(s) in loading state_dict for RobertaForSequenceClassification:
        Missing key(s) in state_dict: "roberta.embeddings.position_ids".
        Unexpected key(s) in state_dict: "roberta.pooler.dense.weight", "roberta.pooler.dense.bias"

I have tried transformers==2.9.1 in requirements.txt, still receiving the same error.

Thanks for your help.

@hugoroussel
Copy link

Having the same error too :)

@Marvy101
Copy link
Author

Having the same error too :)

Hey, still waiting on a solution and trying different things.

You wanna have a discussion about AI, and the future?

@ps3-app
Copy link

ps3-app commented Dec 27, 2022

Having the same issues,
RuntimeError: Error(s) in loading state_dict for RobertaForSequenceClassification: Missing key(s) in state_dict: "roberta.embeddings.position_ids". Unexpected key(s) in state_dict: "roberta.pooler.dense.weight", "roberta.pooler.dense.bias"

do you have the solution for it yet?

@AmirFone
Copy link

I am having the exact same issue.

@AmirFone
Copy link

was anyone able to resolve this issue yet?

@hugoroussel
Copy link

No luck on my side :( I think it might be related to #36 (running on macs M1). Also tried running it via docker without luck too.

@AryanGold
Copy link

I confirm that set transformers==2.9.1 resolve issue. I try it in isolated Docker container and rebuilding container from scratch, for to be sure that all packages reinstalled.

@hugoroussel
Copy link

@AryanGold can you give informations about you current setup (OS etc)?

@AryanGold
Copy link

My Host: Ubuntu 20.04, Docker version 20.10.22

I think important to run this repository in isolated Docker container or Python Virtual Environment. Also if you change some version in requirements.txt then need reinstall all pip packages without any cache etc.

I also attache sample of my Docker file.
Docker_sample.zip

@varenc
Copy link

varenc commented Jan 4, 2023

I also ran into the same error and using transformers==2.9.1 fixed it. If you're not using a proper environment, like we all should be, then you can probably fix the problem just by doing pip uninstall transformers and then pip install transformers==2.9.1 but WMMV.

@manueltarouca
Copy link

Make sure that your python version is 3.7.3 and the following package is transformers==2.9.1.

@SachinGanesh
Copy link

replace

self.model.load_state_dict(data['model_state_dict'])

with

self.model.load_state_dict(data['model_state_dict'], strict=False)

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

8 participants