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

OSError: Can't load config for 'bert-base-uncased #12941

Closed
WinMinTun opened this issue Jul 29, 2021 · 21 comments · Fixed by #13205
Closed

OSError: Can't load config for 'bert-base-uncased #12941

WinMinTun opened this issue Jul 29, 2021 · 21 comments · Fixed by #13205

Comments

@WinMinTun
Copy link

Environment info

It happens in local machine, Colab, and my colleagues also.

  • transformers version:
  • Platform: Window, Colab
  • Python version: 3.7
  • PyTorch version (GPU?): 1.8.1 (GPU yes)
  • Tensorflow version (GPU?):
  • Using GPU in script?: Yes
  • Using distributed or parallel set-up in script?: No

Who can help

@LysandreJik It is to do with 'bert-base-uncased'

Information

Hi, I m having this error suddenly this afternoon. It was all okay before for days. It happens in local machine, Colab and also to my colleagues. I can access this file in browser https://huggingface.co/bert-base-uncased/resolve/main/config.json no problem. Btw, I m from Singapore. Any urgent help will be appreciated because I m rushing some project and stuck there.

Thanks

image

403 Client Error: Forbidden for url: https://huggingface.co/bert-base-uncased/resolve/main/config.json

HTTPError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/transformers/configuration_utils.py in get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
505 use_auth_token=use_auth_token,
--> 506 user_agent=user_agent,
507 )

6 frames
HTTPError: 403 Client Error: Forbidden for url: https://huggingface.co/bert-base-uncased/resolve/main/config.json
During handling of the above exception, another exception occurred:

OSError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/transformers/configuration_utils.py in get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
516 f"- or '{pretrained_model_name_or_path}' is the correct path to a directory containing a {CONFIG_NAME} file\n\n"
517 )
--> 518 raise EnvironmentError(msg)
519
520 except json.JSONDecodeError:

OSError: Can't load config 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 config.json file

@sgugger
Copy link
Collaborator

sgugger commented Jul 29, 2021

Was it just a fluke or is the issue still happening? On Colab I have no problem downloading that model.

@WinMinTun
Copy link
Author

@sgugger Hi it is still happening now. Not just me, many people I know of. I can access the config file from browser, but not through the code. Thanks

@WinMinTun
Copy link
Author

Still not okay online, but I managed to do it locally

git clone https://huggingface.co/bert-base-uncased

#model = AutoModelWithHeads.from_pretrained("bert-base-uncased")
model = AutoModelWithHeads.from_pretrained(BERT_LOCAL_PATH, local_files_only=True)

#tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
tokenizer = AutoTokenizer.from_pretrained(BERT_LOCAL_PATH, local_files_only=True)

adapter_name = model2.load_adapter(localpath, config=config, model_name=BERT_LOCAL_PATH)

@julien-c
Copy link
Member

This, like #12940, is probably related to a change we've made on the infra side (cc @n1t0), which we'll partially revert. Please let us know if this still occurs.

@n1t0
Copy link
Member

n1t0 commented Jul 30, 2021

@WinMinTun Could you share a small collab that reproduces the bug? I'd like to have a look at it.

@jason-weddington
Copy link

With additional testing, I've found that this issue only occurs with adapter-tranformers, the AdapterHub.ml modified version of the transformers module. With the HuggingFace module, we can pull pretrained weights without issue.

Using adapter-transformers this is now working again from Google Colab, but is still failing locally and from servers running in AWS. Interestingly, with adapter-transformers I get a 403 even if I try to load a nonexistent model (e.g. fake-model-that-should-fail). I would expect this to fail with a 401, as there is no corresponding config.json on huggingface.co. The fact that it fails with a 403 seems to indicate that something in front of the web host is rejecting the request before the web host has a change to respond with a not found error.

@julien-c
Copy link
Member

julien-c commented Aug 2, 2021

Thanks so much @jason-weddington. This will help us pinpoint the issue. (@n1t0 @Pierrci)

@lrodrigues-at-navteca
Copy link

I have the same problem, but it only happens when the model is private.

Screenshot

@sgugger
Copy link
Collaborator

sgugger commented Aug 11, 2021

Your token for use_auth_token is not the same as your API token. The easiest way to get it is to login with !huggingface-cli login and then just pass use_auth_token=True.

@lrodrigues-at-navteca
Copy link

I think the problem is something else:

Screenshot 2021-08-11 at 14 34 44

@bennimmo
Copy link
Contributor

Yes, I have come across this as well. I have tracked it down to this line

model_kwargs["use_auth_token"] = model_kwargs.get("use_auth_token", use_auth_token)

It's because the use_auth_token has not been set up early enough in the model_kwargs. The line referenced above needs to be moved above instantiate config section.

@bennimmo
Copy link
Contributor

bennimmo commented Aug 20, 2021

I've added a pull request to which I think will fix this issue. You can get round it for now by adding use_auth_token to the model_kwargs param when creating a pipeline e.g.:
pipeline('zero-shot-classification', model=model, tokenizer=tokenizer, model_kwargs={'use_auth_token': True})

sabinevidal added a commit to sabinevidal/kindly that referenced this issue Oct 29, 2021
Accessing this fix huggingface/transformers#13205
After this error huggingface/transformers#12941 was stopping pretrained path being accessed when model is private
@hemangjoshi37a
Copy link

hemangjoshi37a commented Sep 10, 2022

Still getting the same error
Here is my code :

from transformers import AutoModelForTokenClassification, AutoTokenizer
model = AutoModelForTokenClassification.from_pretrained("hemangjoshi37a/autotrain-ratnakar_600_sample_test-1427753567", use_auth_token=True)
tokenizer = AutoTokenizer.from_pretrained("hemangjoshi37a/autotrain-ratnakar_600_sample_test-1427753567", use_auth_token=True)
inputs = tokenizer("I love AutoTrain", return_tensors="pt")
outputs = model(**inputs)

Error :

----> 3 model = AutoModelForTokenClassification.from_pretrained("hemangjoshi37a/autotrain-ratnakar_600_sample_test-1427753567", use_auth_token=True)
OSError: Can't load config for 'hemangjoshi37a/autotrain-ratnakar_600_sample_test-1427753567'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'hemangjoshi37a/autotrain-ratnakar_600_sample_test-1427753567' is the correct path to a directory containing a config.json file

I have transformers version : 4.21.3
https://hjlabs.in

@hemangjoshi37a
Copy link

runnign this command and authenticating it solved issue: huggingface-cli login
https://hjlabs.in

@PaskalSunari
Copy link

I am facing the same problem in Kaggle too... How can I
Capture
resolve this issue ?

@lyk0013
Copy link

lyk0013 commented Jan 17, 2023

Hello, I had the same problem when using transformers - pipeline in the aws-sagemaker notebook.

I started to think it was the version or the network problem. But, after some local tests, this guess is wrong. So, I just debug the source code. I find that:
image
This will raise any error as EnviromentError. So, from experience, I solve it, by running this pip:
!pip install --upgrade jupyter
!pip install --upgrade ipywidgets

You guys can try it when meeting the problem in aws-notebook or colab!

@VRDJ
Copy link

VRDJ commented Feb 7, 2023

image

I am unable to solve this issues Since Morning .. i had been trying to Solve it ...

Im working on my Final Year Project .. can someone pls help me in it ...

@hemangjoshi37a
Copy link

Just ask chatGPT LOL...😂😂

@VRDJ
Copy link

VRDJ commented Feb 7, 2023

I dont understand it ?? What do u mean ..
The Hugging Face Website is also not working ...

@hemangjoshi37a
Copy link

@VRDJ goto this website chatGPT and enter your error in the chatbox in this website and for the 99% you will get your solution there.

@DuanXiaoyue-LittleMoon
Copy link

Still not okay online, but I managed to do it locally

git clone https://huggingface.co/bert-base-uncased

#model = AutoModelWithHeads.from_pretrained("bert-base-uncased") model = AutoModelWithHeads.from_pretrained(BERT_LOCAL_PATH, local_files_only=True)

#tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased") tokenizer = AutoTokenizer.from_pretrained(BERT_LOCAL_PATH, local_files_only=True)

adapter_name = model2.load_adapter(localpath, config=config, model_name=BERT_LOCAL_PATH)


Hello! Thanks for your sharing. I wonder in
'tokenizer = AutoTokenizer.from_pretrained(BERT_LOCAL_PATH, local_files_only=True)',
which file does 'BERT_LOCAL_PATH' refer to specifically? Is it the path for the directory 'bert-base-uncased', or the 'pytorch_model.bin', or something else?

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

Successfully merging a pull request may close this issue.