BertTokenizerFast.from_pretrained() reproducibly freezing during download
Author: lstein
Pull request: no

### System Info


- `transformers` version: 4.26.1
- Platform: Windows-10-10.0.19044-SP0
- Python version: 3.10.10
- Huggingface_hub version: 0.12.1
- PyTorch version (GPU?): 1.13.1+cpu (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no


### Who can help?

@ArthurZucker  @younesbelkada

### Information

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

### Tasks

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

### Reproduction

On Windows systems, the following script hangs forever and never downloads the model to cache:
```
from transformers import BertTokenizerFast
model = BertTokenizerFast.from_pretrained('bert-base-uncased')
```
The same script runs to completion on Linux and Macintosh using the same version of transformers.

Multiple users of the InvokeAI application are having similar problems.

### Expected behavior

I expect the second statement to run to completion, download and cache the BERT model, and return the instantiated model object.

Comments:
Could you upgrade `huggingface_hub` and possibly `transformers` too to the last version? There were some bugs on Windows recently fixed.

Problem persists with `transformers` 4.27.4 and `huggingface-hub` 0.13.3. The code is freezing in file `huggingface_hub/file_download.py` at line 1296, where it tries to obtain a file lock on the path:
```
.cache\huggingface\hub\models--bert-base-uncased\blobs\W/"fb140275c155a9c7c5a3b3e0e77a9e839594a938.lock                                           
```
The lock file is never created on the file system as far as I can tell. The filelock module is working on my system, but apparently FileLock() does not like filenames that start with the quotation mark. If I try to lock a file that starts with the double quote, I get the same freeze experienced with `from_pretrained()`. By any chance did the format of the blob hashes change recently?

Also, at least one other model has the same problem. I confirmed this with CLIPTokenizer.

same problem in Windows 10 latest version when I use "from_pretrained("openai/whisper-tiny").".
The same code worked 2~3 days ago.


Not sure if its similar. First time ever using it with the help of GPT4. Install Uninstall several times. I tried it in Pycharm and Jupyter NB. Windows 11.

from transformers import AutoTokenizer, AutoModelForMaskedLM, TrainingArguments, Trainer
from datasets import load_dataset

txt_file = "path/to/your/text/file.txt"

dataset = load_dataset("text", data_files={"train": txt_file})

model_checkpoint = "distilbert-base-uncased"

tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModelForMaskedLM.from_pretrained(model_checkpoint)

def tokenize_function(examples):
    return tokenizer(examples["text"], truncation=True, padding="max_length", max_length=128)

tokenized_dataset = dataset.map(tokenize_function, batched=True)

training_args = TrainingArguments(
    output_dir="output",
    overwrite_output_dir=True,
    num_train_epochs=3,
    per_device_train_batch_size=8,
    save_steps=10_000,
    save_total_limit=2,
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=tokenized_dataset["train"],
)

trainer.train()

model.save_pretrained("fine_tuned_model")
tokenizer.save_pretrained("fine_tuned_model")


It seems the script runs indefinitely and nothing happens. Tried many examples too from the Huggingface page. Hopefully there is a fix to it. 

Oli



> same problem in Windows 10 latest version when I use "from_pretrained("openai/whisper-tiny").". The same code worked 2~3 days ago.

Now my code is running properly. I haven't do any changes to my code. I think the problem is solved internally.

Yes, there was an internal change in the Hub that made those downloads stop working. That change was reverted so now it should work again if I understand correctly. cc @Wauplin 

Yes exactly. Sorry for the inconvenience, it should be back to normal now. See related issue in `huggingface_hub`: https://github.com/huggingface/huggingface_hub/issues/1423.

@sgugger you can close this one as well now 

Let us know if the problem persist and I'll reopen!

Fixed. Thanks!

fixed. Merci