Repository: huggingface/transformers

Issue:
OSError: Can't load config for 'bert-base-uncased
## 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](https://user-images.githubusercontent.com/22287008/127519960-114ef793-03f6-494e-ab10-7700b693b87d.png)

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


Discussion:
Was it just a fluke or is the issue still happening? On Colab I have no problem downloading that model.
@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
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)
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.
@WinMinTun Could you share a small collab that reproduces the bug? I'd like to have a look at it.
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.
Thanks so much @jason-weddington. This will help us pinpoint the issue. (@n1t0 @Pierrci)
I have the same problem, but it only happens when the model is private.

![Screenshot](https://user-images.githubusercontent.com/53347273/129016843-01d11fa8-40b0-4155-9405-75dcccfd5a0c.png)

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`.
I think the problem is something else:

![Screenshot 2021-08-11 at 14 34 44](https://user-images.githubusercontent.com/53347273/129029925-a5c4c43d-2f1d-442b-8da0-09d19d2d58a4.png)

Yes, I have come across this as well. I have tracked it down to this line

https://github.com/huggingface/transformers/blob/143738214cb83e471f3a43652617c8881370342c/src/transformers/pipelines/__init__.py#L422

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. 



Resolving patch:
diff --git a/src/transformers/pipelines/__init__.py b/src/transformers/pipelines/__init__.py
--- a/src/transformers/pipelines/__init__.py
+++ b/src/transformers/pipelines/__init__.py
@@ -409,6 +409,9 @@ def pipeline(
         # At that point framework might still be undetermined
         model = get_default_model(targeted_task, framework, task_options)
 
+    # Retrieve use_auth_token and add it to model_kwargs to be used in .from_pretrained
+    model_kwargs["use_auth_token"] = model_kwargs.get("use_auth_token", use_auth_token)
+
     # Config is the primordial information item.
     # Instantiate config if needed
     if isinstance(config, str):
@@ -418,9 +421,6 @@ def pipeline(
 
     model_name = model if isinstance(model, str) else None
 
-    # Retrieve use_auth_token and add it to model_kwargs to be used in .from_pretrained
-    model_kwargs["use_auth_token"] = model_kwargs.get("use_auth_token", use_auth_token)
-
     # Infer the framework from the model
     # Forced if framework already defined, inferred if it's None
     # Will load the correct model if possible


Test patch: