Loading a Gated Repo: Case-Sensitivity issue
Author: nickypro
Pull request: no

### System Info

In `transformers 4.33.3`, when accessing a gated repo with `AutoConfig`, one gets different responses based on case sensitivity when logged in. That is:
- it correctly finds the original repo being referenced and notices that it is a gated repo (case-insensitive)
- it does not correctly find the permissions to the repo when the case does not match (case-sensitive)

Error occurs when loading `meta-llama/llama-2-7b-hf` instead of `meta-llama/Llama-2-7b-hf`

```
OSError: You are trying to access a gated repo.
Make sure to request access at https://huggingface.co/meta-llama/llama-2-7b-hf and pass a token having permission to this repo either by logging in with `huggingface-cli login` or by passing `token=<your_token>`.
```



### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

I show two examples, original case and all lower case.

- Expected behaviour (original capitalization), input:
```
from transformers import AutoConfig
print(AutoConfig.from_pretrained("transformers.AutoConfig.from_pretrained("meta-llama/Llama-2-7b-hf")"))
```
returns:
```
LlamaConfig {
  "_name_or_path": "meta-llama/Llama-2-7b-hf",
  "architectures": [
    "LlamaForCausalLM"
  ],
  "bos_token_id": 1,
  "eos_token_id": 2,
  "hidden_act": "silu",
  "hidden_size": 4096,
  "initializer_range": 0.02,
  "intermediate_size": 11008,
  "max_position_embeddings": 4096,
  "model_type": "llama",
  "num_attention_heads": 32,
  "num_hidden_layers": 32,
  "num_key_value_heads": 32,
  "pretraining_tp": 1,
  "rms_norm_eps": 1e-05,
  "rope_scaling": null,
  "rope_theta": 10000.0,
  "tie_word_embeddings": false,
  "torch_dtype": "float16",
  "transformers_version": "4.33.3",
  "use_cache": true,
  "vocab_size": 32000
}
```

- Unexpected behaviour (all lowercase letters):
```
from transformers import AutoConfig
print(AutoConfig.from_pretrained("transformers.AutoConfig.from_pretrained("meta-llama/llama-2-7b-hf")"))
```

```
Traceback (most recent call last):
...
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/meta-llama/Llama-2-7b-hf/resolve/main/config.json
...
OSError: You are trying to access a gated repo.
Make sure to request access at https://huggingface.co/meta-llama/llama-2-7b-hf and pass a token having permission to this repo either by logging in with `huggingface-cli login` or by passing `token=<your_token>`.
```


### Expected behavior

Possible solutions:
- make the check for gated repos case-insensitive
- Update the error so that one can quickly figure out that the error is due to the case sensitivity issue

Comments:
I replicated this issue with `transformers==4.33.3`. But it does not occur in `transformers==4.30`.

Hey @ceferisbarov, are you sure this was working in v4.30.0? I can't reproduce, for me it always fails:

```py
>>> from transformers import __version__
>>> __version__
'4.30.0'
>>> from transformers import AutoConfig
... print(AutoConfig.from_pretrained("meta-llama/llama-2-7b-hf"))
... 
```
```
Traceback (most recent call last):
  File "/home/lysandre/Workspaces/python/transformers/.env/lib/python3.8/site-packages/huggingface_hub/utils/_errors.py", line 261, in hf_raise_for_status
    response.raise_for_status()
  File "/home/lysandre/Workspaces/python/transformers/.env/lib/python3.8/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/meta-llama/Llama-2-7b-hf/resolve/main/config.json

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/lysandre/Workspaces/python/transformers/src/transformers/utils/hub.py", line 417, in cached_file
    resolved_file = hf_hub_download(
  File "/home/lysandre/Workspaces/python/transformers/.env/lib/python3.8/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
  File "/home/lysandre/Workspaces/python/transformers/.env/lib/python3.8/site-packages/huggingface_hub/file_download.py", line 1364, in hf_hub_download
    http_get(
  File "/home/lysandre/Workspaces/python/transformers/.env/lib/python3.8/site-packages/huggingface_hub/file_download.py", line 514, in http_get
    hf_raise_for_status(r)
  File "/home/lysandre/Workspaces/python/transformers/.env/lib/python3.8/site-packages/huggingface_hub/utils/_errors.py", line 277, in hf_raise_for_status
    raise GatedRepoError(message, response) from e
huggingface_hub.utils._errors.GatedRepoError: 401 Client Error. (Request ID: Root=1-651bd79f-75bbd3a860f084763b855df2;8000b1a7-3451-46c8-88c8-1854459fc8f3)

Cannot access gated repo for url https://huggingface.co/meta-llama/Llama-2-7b-hf/resolve/main/config.json.
Repo model meta-llama/Llama-2-7b-hf is gated. You must be authenticated to access it.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lysandre/.pyenv/versions/3.8.18/lib/python3.8/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 2, in <module>
  File "/home/lysandre/Workspaces/python/transformers/src/transformers/models/auto/configuration_auto.py", line 944, in from_pretrained
    config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/home/lysandre/Workspaces/python/transformers/src/transformers/configuration_utils.py", line 574, in get_config_dict
    config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/home/lysandre/Workspaces/python/transformers/src/transformers/configuration_utils.py", line 629, in _get_config_dict
    resolved_config_file = cached_file(
  File "/home/lysandre/Workspaces/python/transformers/src/transformers/utils/hub.py", line 433, in cached_file
    raise EnvironmentError(
OSError: meta-llama/llama-2-7b-hf is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.
```

I verify I can correctly load it with the right casing though:

```py
>>> from transformers import AutoConfig
... print(AutoConfig.from_pretrained("meta-llama/Llama-2-7b-hf"))
... 
```
```
LlamaConfig {
  "_name_or_path": "meta-llama/Llama-2-7b-hf",
  "architectures": [
    "LlamaForCausalLM"
  ],
  "bos_token_id": 1,
  "eos_token_id": 2,
  "hidden_act": "silu",
  "hidden_size": 4096,
  "initializer_range": 0.02,
  "intermediate_size": 11008,
  "max_position_embeddings": 4096,
  "model_type": "llama",
  "num_attention_heads": 32,
  "num_hidden_layers": 32,
  "num_key_value_heads": 32,
  "pad_token_id": 0,
  "pretraining_tp": 1,
  "rms_norm_eps": 1e-05,
  "rope_scaling": null,
  "tie_word_embeddings": false,
  "torch_dtype": "float16",
  "transformers_version": "4.30.0",
  "use_cache": true,
  "vocab_size": 32000
}
```

Maybe of interest to @Wauplin 

I worded it wrong. Correct casing works. Incorrect casing throws `not a valid model identifier` instead of `gated repo`. TBH, this works for me. @LysandreJik 

(Most APIs are case-insensitive for `repo_id` on the Hugging Face Hub. This can lead to a few discrepancies -maybe the case here?-. But the behavior described in this issue seems ok to me, right?)

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](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.