question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TFMarianModel from_pretrained can't load weights

See original GitHub issue

Environment info

  • transformers version: 4.3.2
  • Platform: Windows-7-6.1.7601-SP1
  • Python version: 3.6.6
  • PyTorch version (GPU?): 1.5.1+cpu (False)
  • Tensorflow version (GPU?): 2.3.0 (False)
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No

Who can help

@patrickvonplaten

Information

Model I am using (Bert, XLNet …): TFMarianMT

The problem arises when using:

  • [+] the official example scripts: (give details below)

To reproduce

from transformers import MarianTokenizer, TFMarianModel
model = TFMarianModel.from_pretrained('Helsinki-NLP/opus-mt-en-de')

Steps to reproduce the behavior:

  1. Run the above code
  2. Get an error:

Exception has occurred: OSError (note: full exception trace is shown but execution is paused at: _run_module_as_main) Can’t load weights for ‘Helsinki-NLP/opus-mt-en-de’. Make sure that:

  • ‘Helsinki-NLP/opus-mt-en-de’ is a correct model identifier listed on ‘https://huggingface.co/models

  • or ‘Helsinki-NLP/opus-mt-en-de’ is the correct path to a directory containing a file named one of tf_model.h5, pytorch_model.bin.

    File “C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\site-packages\transformers\modeling_tf_utils.py”, line 1219, in from_pretrained raise EnvironmentError(msg) File “C:\Users\FA.PROJECTOR-MSK\Google Диск\Colab Notebooks\PoetryTransformer\Unsupervised\translation\paraphrases_translation.py”, line 14, in <module> model = TFMarianModel.from_pretrained(‘Helsinki-NLP/opus-mt-en-de’) File “C:\Users\FA.PROJECTOR-MSK\Google Диск\Colab Notebooks\PoetryTransformer\Unsupervised\translation\run_locally.py”, line 1, in <module> from paraphrases_translation import run File “C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py”, line 85, in _run_code exec(code, run_globals) File “C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py”, line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File “C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py”, line 263, in run_path pkg_name=pkg_name, script_name=fname) File “C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py”, line 85, in _run_code exec(code, run_globals) File “C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py”, line 193, in _run_module_as_main (Current frame) “main”, mod_spec)

Expected behavior

No error

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
patrickvonplatencommented, Feb 24, 2021

There are quite a lot of other models to upload, so this will take some time. I’ll start writing a script to automate this process…

Until then you can make use of this easy fix:

from transformers import MarianTokenizer, TFMarianModel
import tensorflow as tf
tokenizer = MarianTokenizer.from_pretrained('Helsinki-NLP/opus-mt-ru-de')
model = TFMarianModel.from_pretrained('Helsinki-NLP/opus-mt-ru-en', from_pt=True)
inputs = tokenizer("Hello, my dog is cute", return_tensors="tf")
outputs = model(inputs)
0reactions
github-actions[bot]commented, Apr 14, 2021

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue when load pretrained weights #5799 - GitHub
I got the following error when running AutoModelWithLMHead.from_pretrained("bert-base-chinese") OSError: Can't load weights for ...
Read more >
Models - Hugging Face
The warning Weights from XXX not initialized from pretrained model means that the weights of XXX do not come pretrained with the rest...
Read more >
Load a pre-trained model from disk with Huggingface ...
"If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. " ) E OSError: Unable to load...
Read more >
Models API and Pretrained weights | timmdocs
... timm have pretrained weights for these models? My dataset doesn't consist of 3-channel images - what now? ... So how is timm...
Read more >
Load weights from trained models for intialization - vision
Hi, I used a resnet50 model(pretrained=True) for training. I saved the best model in training function like: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found