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.

Unable to load weights from pytorch checkpoint file

See original GitHub issue

šŸ› Bug

Information

I uploaded two models this morning using the transformers-cli. The models can be found on my huggingface page. The folder I uploaded for both models contained a PyTorch model in bin format, a zip file containing the three TF model files, the config.json and the vocab.txt. The PT model was created from TF checkpoints using this code. Iā€™m able to download the tokenizer using:

tokenizer = AutoTokenizer.from_pretrained("mananeau/clinicalcovid-bert-base-cased").

Yet, when trying to download the model using:

model = AutoModel.from_pretrained("mananeau/clinicalcovid-bert-base-cased")

I am getting the following error:


AttributeError Traceback (most recent call last) ~/anaconda3/lib/python3.7/site-packages/torch/serialization.py in _check_seekable(f) 226 try: ā€“> 227 f.seek(f.tell()) 228 return True

AttributeError: ā€˜NoneTypeā€™ object has no attribute ā€˜seekā€™

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last) ~/anaconda3/lib/python3.7/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs) 625 try: ā€“> 626 state_dict = torch.load(resolved_archive_file, map_location=ā€œcpuā€) 627 except Exception:

~/anaconda3/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args) 425 pickle_load_args[ā€˜encodingā€™] = ā€˜utf-8ā€™ ā€“> 426 return _load(f, map_location, pickle_module, **pickle_load_args) 427 finally:

~/anaconda3/lib/python3.7/site-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args) 587 ā€“> 588 _check_seekable(f) 589 f_should_read_directly = _should_read_directly(f)

~/anaconda3/lib/python3.7/site-packages/torch/serialization.py in _check_seekable(f) 229 except (io.UnsupportedOperation, AttributeError) as e: ā€“> 230 raise_err_msg([ā€œseekā€, ā€œtellā€], e) 231

~/anaconda3/lib/python3.7/site-packages/torch/serialization.py in raise_err_msg(patterns, e) 222 " try to load from it instead.") ā€“> 223 raise type(e)(msg) 224 raise e

AttributeError: ā€˜NoneTypeā€™ object has no attribute ā€˜seekā€™. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

During handling of the above exception, another exception occurred:

OSError Traceback (most recent call last) <ipython-input-5-5451ffd9a3b5> in <module> ----> 1 model = AutoModel.from_pretrained(ā€œmananeau/clinicalcovid-bert-base-casedā€)

~/anaconda3/lib/python3.7/site-packages/transformers/modeling_auto.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs) 425 for config_class, model_class in MODEL_MAPPING.items(): 426 if isinstance(config, config_class): ā€“> 427 return model_class.from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs) 428 raise ValueError( 429 ā€œUnrecognized configuration class {} for this kind of AutoModel: {}.\nā€

~/anaconda3/lib/python3.7/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs) 627 except Exception: 628 raise OSError( ā€“> 629 "Unable to load weights from pytorch checkpoint file. " 630 "If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. " 631 )

OSError: Unable to load weights from pytorch checkpoint file. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

Environment info

  • transformers version: 2.9.0
  • Platform: Ubuntu 18.04
  • Python version: 3.7.4
  • PyTorch version (GPU?): 1.3.1
  • Tensorflow version (GPU?): 1.14.0
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

20reactions
brent-lemieuxcommented, Jan 25, 2021

I had this problem when I trained the model with torch==1.6.0 and tried to load the model with 1.3.1. The issue was fixed by upgrading to 1.6.0 in my environment where Iā€™m loading the model.

17reactions
wicebingcommented, May 14, 2020

For this problem I switched to pip install with the repository of tranformers=2.8 which had been download in my old environment.

It normal works to download and load any pretrained weight

I donā€™t know why, but itā€™s work

Read more comments on GitHub >

github_iconTop Results From Across the Web

OSError: Unable to load weights from pytorch checkpoint file
Hi, everyone. I need some help. I have been developing the Flask website that has embedded one of Transformer's fine-tuned models within it....
Read more >
Unable to load weights from pytorch checkpoint after splitting ...
So I split it into chunks using python, transferred and reassembled in the correct order. However, the size of the file increased, and...
Read more >
Help Set tf=True? - PyTorch Forums
OSError: Unable to load weights from pytorch checkpoint file for 'EleutherAI/gpt-neo-2.7B' at 'C:\Users\USER7/.cache\huggingface\transformers\Ā ...
Read more >
Unable to load model weights error - Deploying Streamlit
I am trying to load a PyTorch model to Streamlit from Github but somehow Streamlit returns an error like: OSError: Unable to load...
Read more >
huggingface save model checkpoint - You.com | The Search ...
Everything worked well until the model loading step and it said: OSError: Unable to load weights from PyTorch checkpoint file at <my modelĀ ......
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