Connection error, and we cannot find the requested files in the cached path. Please try again or make sure your Internet connection is on.
Author: tanhanzhuo
Pull request: no

### System Info

irrespect of version
AutoTokenizer raises connection error

AutoTokenizer.from_pretrained('bert-base-uncased') takes forever and raise the connection error
@ArthurZucker 
thx

### Who can help?

_No response_

### Information

- [X] 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

AutoTokenizer.from_pretrained('bert-base-uncased') 

### Expected behavior

expect return the tokenizer, but got connection error:

'HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/tokenizer_config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0e814eacd0>, 'Connection to huggingface.co timed out. (connect timeout=10)'))' thrown while requesting HEAD https://huggingface.co/bert-base-uncased/resolve/main/tokenizer_config.json
'HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-uncased/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0e91bc2d00>, 'Connection to huggingface.co timed out. (connect timeout=10)'))' thrown while requesting HEAD https://huggingface.co/bert-base-uncased/resolve/main/config.json
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/transformers/utils/hub.py", line 409, in cached_file
    resolved_file = hf_hub_download(
  File "/opt/conda/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 124, in _inner_fn
    return fn(*args, **kwargs)
  File "/opt/conda/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1211, in hf_hub_download
    raise LocalEntryNotFoundError(
huggingface_hub.utils._errors.LocalEntryNotFoundError: Connection error, and we cannot find the requested files in the disk cache. Please try again or make sure your Internet connection is on.

Comments:
Hi @tanhanzhuo, thanks for raising this issue! 

Is seems like there's a connection issue when trying to download from the hub. I've just tested locally by clearing my cache and forcing a download with `AutoTokenizer.from_pretrained('bert-base-uncased')`, which ran successfully. Have you tested the internet connection in the running environment? If so, is this only seen when downloading from the hugging face hub? 

> Hi @tanhanzhuo, thanks for raising this issue!
> 
> Is seems like there's a connection issue when trying to download from the hub. I've just tested locally by clearing my cache and forcing a download with `AutoTokenizer.from_pretrained('bert-base-uncased')`, which ran successfully. Have you tested the internet connection in the running environment? If so, is this only seen when downloading from the hugging face hub?

Thank you for reply! The error exists for around 2 hours, but now everything works well again.

During the error, I could load the model by setting local_files_only=True, but cannot download from the hub. Guess some strange bug occurred

Sorry to ask a little more. I used to meet the same problem as mentioned above. But I found that this error is not always in that way. 

For example, if I want to initialize a pretrained stable diffusion model according to the demo code. The first several trials (usually around 4-5 times) will encounter this error. But if you keep on trying, it runs without any errors. 

I am not sure if it is possible to enhance the pretrained weights loading code, to support try downloading the weights several times, so that the user with this error can set a relatively large times to try on downloading the weights. In that way, someone with this, maybe so-called **random** `ConnectionError`, can avoid it. :pray:

> Sorry to ask a little more. I used to meet the same problem as mentioned above. But I found that this error is not always in that way.
> 
> For example, if I want to initialize a pretrained stable diffusion model according to the demo code. The first several trials (usually around 4-5 times) will encounter this error. But if you keep on trying, it runs without any errors.
> 
> I am not sure if it is possible to enhance the pretrained weights loading code, to support try downloading the weights several times, so that the user with this error can set a relatively large times to try on downloading the weights. In that way, someone with this, maybe so-called **random** `ConnectionError`, can avoid it. 🙏

Same here, just kept trying and everthing went well. 🤣

I'm having the same problem as you

@tanhanzhuo 

just retry multiple times, it works.

>Tks, I retry multiple times, it finally works.



try so many times

> > Sorry to ask a little more. I used to meet the same problem as mentioned above. But I found that this error is not always in that way.
> > For example, if I want to initialize a pretrained stable diffusion model according to the demo code. The first several trials (usually around 4-5 times) will encounter this error. But if you keep on trying, it runs without any errors.
> > I am not sure if it is possible to enhance the pretrained weights loading code, to support try downloading the weights several times, so that the user with this error can set a relatively large times to try on downloading the weights. In that way, someone with this, maybe so-called **random** `ConnectionError`, can avoid it. 🙏
> 
> Same here, just kept trying and everthing went well. 🤣

i have tried for many times ,more than 10......

> just retry multiple times, it works.

i have tried for many times ,more than 10......

If you're hitting this error on kaggle, you need to turn on the internet option in the sidebar.  You'll need to first verify your account (with a phone number) before that option becomes available.  At that point you can also turn on GPU.

i have tried more than 20 times，but it's still not working......