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

can't load the model #353

Closed
countback opened this issue Mar 6, 2019 · 28 comments
Closed

can't load the model #353

countback opened this issue Mar 6, 2019 · 28 comments
Labels
Need more information Further information is requested

Comments

@countback
Copy link

model = BertModel.from_pretrained('bert-large-cased')
Model name 'bert-large-cased' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-cased.tar.gz' was a path or url but couldn't find any file associated to this path or url.

@thomwolf
Copy link
Member

thomwolf commented Mar 7, 2019

Strange error.

Can you try:

import pytorch_pretrained_bert as ppb
assert 'bert-large-cased' in ppb.modeling.PRETRAINED_MODEL_ARCHIVE_MAP

Do you have an open internet connection on the server that run the script?

@thomwolf thomwolf added Need more information Further information is requested BERT labels Mar 7, 2019
@erip
Copy link
Contributor

erip commented Mar 7, 2019

@thomwolf Is there a way to point to a model on disk? This question seems related enough to daisychain with this issue. :-)

@martiansideofthemoon
Copy link

I noticed that this error happens when you exceed the disk space in the temporary directory while downloading BERT.

@AmazingGzZc
Copy link

I ran into the same problem. When I used the Chinese pre-training model, it was sometimes good and sometimes bad.

@DuncanCam-Stein
Copy link

@thomwolf I've been having the same error, and I received an AssertionError when I try

assert 'bert-based-uncased' in bert.modeling.PRETRAINED_MODEL_ARCHIVE_MAP

I've tried using both conda install and Pip install to get the package but in both cases I am not able to load any models

@thomwolf
Copy link
Member

Hi @DuncanCam-Stein,
Which version of python do you have?
Can you try to install from source?

@DuncanCam-Stein
Copy link

DuncanCam-Stein commented Mar 14, 2019

@thomwolf @countback
I finally fixed the problem by downloading the tf checkpoints directly from here, and then using the 'convert_tf_checkpoint_to_pytorch.py' function to create a pytorch_model.bin file.
I then used the path to pytorch_model.bin and bert_config.json file in BertModel.from_pretrained('path/to/bin/and/json') instead of 'bert-base-uncased'.
👍
Helpful info was found here.

@thomwolf
Copy link
Member

The network connection check has been relaxed in the now merged #500.
Serialization of the model have also been simplified a lot with #489.

These improvements will be included in the next PyPI release (probably next week).

In the meantime you can install from master and already use the serialization best-practices described in the README here

@astariul
Copy link
Contributor

astariul commented Jun 27, 2019

As @martiansideofthemoon said, I met this error because I didn't have enough space on disk.

Check if you can download the file with :

wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased.tar.gz

@fabrahman
Copy link

@martiansideofthemoon What does that mean if we can download it via wget but not when we use from_pretrained? is it a disk space problem?

@astariul
Copy link
Contributor

@Hannabrahman
If you can download it via wget, it means you have enough disk space, so the issue is from somewhere else.

@fabrahman
Copy link

@colanim Thanks. I figured out it was memory issue on the cache directory.

@raj5287
Copy link

raj5287 commented Sep 16, 2019

@Hannabrahman

@colanim Thanks. I figured out it was memory issue on the cache directory.

how did you solve this issue?

@astariul
Copy link
Contributor

@raj5287
Free some disk space on the cache directory or specify another cache directory

@raj5287
Copy link

raj5287 commented Sep 16, 2019

@colanim i have enough disk space since i have downloaded the file using
wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased.tar.gz but i am not sure how to specify another cache directory or use the downloaded file (i am new to pytorch and ubuntu :| )

@raj5287
Copy link

raj5287 commented Sep 16, 2019

@thomwolf @countback
I finally fixed the problem by downloading the tf checkpoints directly from here, and then using the 'convert_tf_checkpoint_to_pytorch.py' function to create a pytorch_model.bin file.
I then used the path to pytorch_model.bin and bert_config.json file in BertModel.from_pretrained('path/to/bin/and/json') instead of 'bert-base-uncased'.
+1
Helpful info was found here.

@DuncanCam-Stein i have downloaded and placed pytorch_model.bin and bert_config.json in bert_tagger folder but when i am doing tokenizer = BertModel.from_pretrained('home/user/Download/bert_pos_tagger/bert_tagger/') i am still getting the error : Model name 'home/user/Downloads/bert_pos_tagger/bert_tagger/' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'home/user/Downloads/bert_pos_tagger/bert_tagger/' was a path or url but couldn't find any file associated to this path or url.

@sherjy
Copy link

sherjy commented Apr 11, 2020

try to delete cahe file and rerun the command

@predictedblog
Copy link

I noticed that the error appears when I execute my script in debug mode (in Visual Studio Code). I fixed it by executing the script over the terminal python myscriptname.py once. Afterwards Debug mode works fine.

Btw. I got the same problem with the tokenizer and this also fixed it.

@DTW1004
Copy link

DTW1004 commented Aug 16, 2020

model = BertModel.from_pretrained('bert-large-cased')
Model name 'bert-large-cased' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'https://s3.amazonaws.com/models.huggingface.co/bert/bert-large-cased.tar.gz' was a path or url but couldn't find any file associated to this path or url.

hello,I meet the problem when run the torch bert code 👍

OSError: Can't load weights for 'bert-base-uncased'. Make sure that:

  • 'bert-base-uncased' is a correct model identifier listed on 'https://huggingface.co/models'

  • or 'bert-base-uncased' is the correct path to a directory containing a file named one of pytorch_model.bin, tf_model.h5, model.ckpt.
    if I can download the bert-base-uncased weight, where I should put the file in ? hope your reply~

@erip
Copy link
Contributor

erip commented Aug 16, 2020

@DTW1004 check your network connection. This happens when I'm behind a proxy and SSL/proxy isn't configured appropriately.

@1172100222
Copy link

bro,I've been having the same error. and then I try to debug the specific code
BertTokenizer.from_pretrained(MODEL_NAME)
step in to the origin code, I find that I could step every line of the transformer in the debug mode. when step out origin code, the tokenizer tool could be used. what‘s more , the code could be run normaly in the next time I run the code.

@andiShan11
Copy link

I met the issue and I found the reason is that my server connecting was offline.

@dmr07
Copy link

dmr07 commented Jul 23, 2021

Running into the same issue on AWS Lambda. Neither relative and absolute paths will allow the model to load from pre-trained.

@sayakpaul
Copy link
Member

Here's what I am doing:

!wget -q https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-multilingual-cased.tar.gz
!tar xf bert-base-multilingual-cased.tar.gz

Now, if I do:

encoder = TFBertModel.from_pretrained("bert-base-multilingual-cased")

I still get:

OSError: Can't load config for 'bert-base-multilingual-cased'. Make sure that:

- 'bert-base-multilingual-cased' is a correct model identifier listed on 'https://huggingface.co/models'

- or 'bert-base-multilingual-cased' is the correct path to a directory containing a config.json file

@caijie12138
Copy link

Here's what I am doing:

from transformers import pipeline

def corret_sentence(sentence,unmasker):
res = unmasker(sentence)
return res

if name=='main':
sentence = "关小彤"
new_sentence = ""
unmasker = pipeline('fill-mask', model='uer/chinese_roberta_L-2_H-512')
for idx,ch in enumerate(sentence):
new_sentence = sentence[:idx] + "[MASK]" + sentence[idx+1:]
print(corret_sentence(new_sentence,unmasker))

I get:

ValueError: Could not load model uer/chinese_roberta_L-2_H-512 with any of the following classes: (<class 'transformers.models.auto.modeling_auto.AutoModelForMaskedLM'>, <class 'transformers.models.bert.modeling_bert.BertForMaskedLM'>).

@apkbala107
Copy link

Here's what I am doing:

from transformers import pipeline

def corret_sentence(sentence,unmasker): res = unmasker(sentence) return res

if name=='main': sentence = "关小彤" new_sentence = "" unmasker = pipeline('fill-mask', model='uer/chinese_roberta_L-2_H-512') for idx,ch in enumerate(sentence): new_sentence = sentence[:idx] + "[MASK]" + sentence[idx+1:] print(corret_sentence(new_sentence,unmasker))

I get:

ValueError: Could not load model uer/chinese_roberta_L-2_H-512 with any of the following classes: (<class 'transformers.models.auto.modeling_auto.AutoModelForMaskedLM'>, <class 'transformers.models.bert.modeling_bert.BertForMaskedLM'>).

how could solve this?

did you solve this problem?

i am also having sample

@zhanghaok
Copy link

Free some disk space

how can I free some disk space.
which shell command should i use?

@Sharique-stack
Copy link

@thomwolf @countback I finally fixed the problem by downloading the tf checkpoints directly from here, and then using the 'convert_tf_checkpoint_to_pytorch.py' function to create a pytorch_model.bin file. I then used the path to pytorch_model.bin and bert_config.json file in BertModel.from_pretrained('path/to/bin/and/json') instead of 'bert-base-uncased'. 👍 Helpful info was found here.

Can you please specify which model exactly you downloaded and how you ran the function? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Need more information Further information is requested
Projects
None yet
Development

No branches or pull requests