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 when predicting with the french models #9

Open
maelchiotti opened this issue Jul 8, 2022 · 3 comments
Open

RuntimeError when predicting with the french models #9

maelchiotti opened this issue Jul 8, 2022 · 3 comments

Comments

@maelchiotti
Copy link

maelchiotti commented Jul 8, 2022

I tried to use the french models (both fr.22000 and fr-txt.large.19000) on a very simple text:

j'aime les fleurs les olives et la raclette

When running python3 recasepunc.py predict fr.22000 < input.txt > output.txt (or with the other model), I get the following RuntimeError:

Traceback (most recent call last):
  File "/home/mael/charly/recasepunc/recasepunc.py", line 733, in <module>
    main(config, config.action, config.action_args)
  File "/home/mael/charly/recasepunc/recasepunc.py", line 707, in main
    generate_predictions(config, *args)
  File "/home/mael/charly/recasepunc/recasepunc.py", line 336, in generate_predictions
    model.load_state_dict(loaded['model_state_dict'])
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1497, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Model:
	Unexpected key(s) in state_dict: "bert.position_ids".

I tried the same with the english model, and it worked perfectly. Looks like something is broken with the french ones?

@maelchiotti maelchiotti changed the title RuntimeError when predicting with the french model RuntimeError when predicting with the french models Jul 8, 2022
@benob
Copy link
Owner

benob commented Jul 8, 2022

Did you install the version of transformers from requirements? This kind of error is typical of a mismatch in Bert model class structure.

@maelchiotti
Copy link
Author

That was indeed the issue, and installing the required version of transformers fixed it. Thanks a lot!

I may as well add that I did not use requirements.txt because, when running pip3 install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html, I got the following error:

ERROR: Could not find a version that satisfies the requirement torch==1.9.0+cu111 (from versions: 1.11.0, 1.11.0+cpu, 1.11.0+cu102, 1.11.0+cu113, 1.11.0+cu115, 1.11.0+rocm4.3.1, 1.11.0+rocm4.5.2, 1.12.0, 1.12.0+cpu, 1.12.0+cu102, 1.12.0+cu113, 1.12.0+cu116, 1.12.0+rocm5.0, 1.12.0+rocm5.1.1)

@Breizhux
Copy link

Breizhux commented Feb 23, 2023

I had the same problem for the French language.

I tested several types of configuration files. With the following content as requirements.txt file, the installation is done without problem:

git+https://github.com/benob/mosestokenizer.git
numpy
regex
torch
tqdm
transformers==4.10.0

Then, I can install recasepunc with simple pip install -r requirements.txt.

The version of each library in my current installation is :

  • numpy : 1.24.1
  • regex : 2022.9.13
  • torch : 1.12.1
  • tqdm : 4.64.1
  • transformers : 4.10.0

I would add that the pytorch version required in the original requirements.txt file crashes my computers that don't have enough RAM (8GB + 6GB swap). The latest version doesn't seem to exceed the 3GB of Ram used for the installation.

With this requirements.txt file the installation works very well (I have only tested the French models and the English model...) ! Maybe it deserves a commit ;)

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

3 participants