Can't load the model for 'bert-base-uncased'.
## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.17.0
- Platform: Linux
- Python version: 3.9
- PyTorch version (GPU?): 1.9.1 (yes)
- Tensorflow version (GPU?):
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

Error:
When I used "BertModel.from_pretrained", it would show "raise EnvironmentError(
OSError: Can't load the model for 'bert-base-uncased'. 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 'bert-base-uncased' is the correct path to a directory containing a file named pytorch_model.bin, tf_model.h5, model.ckpt or flax_model.msgpack." 
Hi @xishanhan 👋 In order for us to pinpoint the issue and help you, we need a script that reproduces it. Also, for completeness -- can you confirm that you do **_not_** have a local folder called `bert-base-uncased`?<|||||>> Hi @xishanhan 👋 In order for us to pinpoint the issue and help you, we need a script that reproduces it. Also, for completeness -- can you confirm that you do **_not_** have a local folder called `bert-base-uncased`?

Thanks for your reply! I do not have a local folder called bert-base-uncased. 
I tried this  https://github.com/alirezazareian/ovr-cnn/blob/master/ipynb/003.ipynb to split COCO datasets, and it used BERT to embedding the name of the classes. 
Because my transformer version is 4.17.0, I changed "from transformers.tokenization_bert import BasicTokenizer" to "from transformers.models.bert.tokenization_bert import BasicTokenizer" when using BasicTokenizer, otherwise "no module named transformers.tokenization_bert" would appear. I don't know if this change affected something and caused the error.<|||||>Hi @xishanhan -- precision is important for debugging. Without an exact script to reproduce, I'm afraid I won't be able to help :)<|||||>Do you mean this? It's the py file I run and it needs the source code from https://github.com/alirezazareian/ovr-cnn to import.

```
import json
import numpy as np
import torch
from maskrcnn_benchmark.config import cfg
from maskrcnn_benchmark.modeling.language_backbone.transformers import BERT
 
with open('../datasets/coco/annotations/instances_train2017.json', 'r') as fin:
    coco_train_anno_all = json.load(fin)
with open('../datasets/coco/annotations/instances_train2017.json', 'r') as fin:
    coco_train_anno_seen = json.load(fin)
with open('../datasets/coco/annotations/instances_train2017.json', 'r') as fin:
    coco_train_anno_unseen = json.load(fin)
with open('../datasets/coco/annotations/instances_val2017.json', 'r') as fin:
    coco_val_anno_all = json.load(fin)
with open('../datasets/coco/annotations/instances_val2017.json', 'r') as fin:
    coco_val_anno_seen = json.load(fin)
with open('../datasets/coco/annotations/instances_val2017.json', 'r') as fin:
    coco_val_anno_unseen = json.load(fin)
 
with open('../ovr-cnn-master/mscoco_seen_classes.json', 'r') as fin:
    labels_seen = json.load(fin)
with open('../ovr-cnn-master/mscoco_unseen_classes.json', 'r') as fin:
    labels_unseen = json.load(fin)
print(len(labels_seen), len(labels_unseen))

labels_all = [item['name'] for item in coco_val_anno_all['categories']]
set(labels_seen) - set(labels_all)
set(labels_unseen) - set(labels_all)

class_id_to_split = {}
class_name_to_split = {}
for item in coco_val_anno_all['categories']:
    if item['name'] in labels_seen:
        class_id_to_split[item['id']] = 'seen'
        class_name_to_split[item['name']] = 'seen'
    elif item['name'] in labels_unseen:
        class_id_to_split[item['id']] = 'unseen'
        class_name_to_split[item['name']] = 'unseen'

class_name_to_glove = {}
with open('../datasets/glove_6B/glove.6B.300d.txt', 'r') as fin:
    for row in fin:
        row_tk = row.split()
        if row_tk[0] in class_name_to_split:
            class_name_to_glove[row_tk[0]] = [float(num) for num in row_tk[1:]]

bert = BERT(cfg)
_ = bert.to('cuda')

class_name_to_bertemb = {}
for c in class_name_to_split:
    if c not in bert.tokenizer.vocab:
        print(f'{c} not found')
        continue
    cid = bert.tokenizer.vocab[c]
    class_name_to_bertemb[c] = bert.embeddings[cid]
class_list = list(class_name_to_split.keys())
encoded_class_list = bert(class_list)
mask = (1 - encoded_class_list['special_tokens_mask']).to(torch.float32)
mask.sum(-1)

embeddings = (encoded_class_list['input_embeddings'] * mask[:, :, None]).sum(1) / mask.sum(1)[:, None]
embeddings = embeddings.cpu().numpy()
print(embeddings.shape)

class_name_to_bertemb = {}
for c, emb in zip(class_list, embeddings.tolist()):
    class_name_to_bertemb[c] = emb
print(len(class_name_to_bertemb), len(class_name_to_glove), len(class_name_to_split))

def filter_annotation(anno_dict, split_name_list):
    filtered_categories = []
    for item in anno_dict['categories']:
        if class_id_to_split.get(item['id']) in split_name_list:
            item['embedding'] = {}
            item['embedding']['GloVE'] = class_name_to_glove[item['name']]
            item['embedding']['BertEmb'] = class_name_to_bertemb[item['name']]
            item['split'] = class_id_to_split.get(item['id'])
            filtered_categories.append(item)
    anno_dict['categories'] = filtered_categories
    
    filtered_images = []
    filtered_annotations = []
    useful_image_ids = set()
    for item in anno_dict['annotations']:
        if class_id_to_split.get(item['category_id']) in split_name_list:
            filtered_annotations.append(item)
            useful_image_ids.add(item['image_id'])
    for item in anno_dict['images']:
        if item['id'] in useful_image_ids:
            filtered_images.append(item)
    anno_dict['annotations'] = filtered_annotations
    anno_dict['images'] = filtered_images    

filter_annotation(coco_train_anno_seen, ['seen'])
filter_annotation(coco_train_anno_unseen, ['unseen'])
filter_annotation(coco_train_anno_all, ['seen', 'unseen'])
filter_annotation(coco_val_anno_seen, ['seen'])
filter_annotation(coco_val_anno_unseen, ['unseen'])
filter_annotation(coco_val_anno_all, ['seen', 'unseen'])
print(len(coco_val_anno_seen['categories']), len(coco_val_anno_unseen['categories']), len(coco_val_anno_all['categories']))

with open('../datasets/coco/zero-shot/instances_train2017_seen_2.json', 'w') as fout:
    json.dump(coco_train_anno_seen, fout)
with open('../datasets/coco/zero-shot/instances_train2017_unseen_2.json', 'w') as fout:
    json.dump(coco_train_anno_unseen, fout)
with open('../datasets/coco/zero-shot/instances_train2017_all_2.json', 'w') as fout:
    json.dump(coco_train_anno_all, fout)
with open('../datasets/coco/zero-shot/instances_val2017_seen_2.json', 'w') as fout:
    json.dump(coco_val_anno_seen, fout)
with open('../datasets/coco/zero-shot/instances_val2017_unseen_2.json', 'w') as fout:
    json.dump(coco_val_anno_unseen, fout)
with open('../datasets/coco/zero-shot/instances_val2017_all_2.json', 'w') as fout:
    json.dump(coco_val_anno_all, fout)
```<|||||>@xishanhan that is better :) But I am probably still missing information. I apologize for being assertive about this, providing support without an exact script is near impossible in a large library like this one (our [issues guide](https://github.com/huggingface/transformers/blob/main/ISSUES.md) provides more detail).

One of two things is happening:
1. You are using exactly that script. In that case, you'll have to open an issue in that repo, as they are using an old version of transformers (`3.0.2`), which likely explains the issue;
2. You are using a modified version of the script above, that uses `transformers==4.17.0`. In that case, I'm going to ask you for the part of your script that attempts to load the model, and that raises the error you see, so I can reproduce the issue.<|||||>Sorry, I didn't explain clearly before. I am using this script under transformer version 4.17.0 without any modifying.
The part of my script that attempts to load the model is line 47: `bert = BERT(cfg)`.
'BERT' is import from [class BERT](https://github.com/alirezazareian/ovr-cnn/blob/master/maskrcnn_benchmark/modeling/language_backbone/transformers.py) and in this transformers.py, the part that attempts to load model is line 14:
 `self.bert_model = BertModel.from_pretrained('bert-base-uncased', config=self.bert_config)    `
<|||||>Awesome, all explained now 👍 The root cause stems from the `BERT` class within the repository you linked, and you should try to raise an issue with them.

The error _should_ go away if you remove the `config` argument in [this line in that project](https://github.com/alirezazareian/ovr-cnn/blob/master/maskrcnn_benchmark/modeling/language_backbone/transformers.py#L15), but I have no idea whether the project still makes sense if you make that change -- this is why I'm suggesting raising the issue with the author of the code :)

Since the bug is external to `transformers`, I'm closing this issue (we reserve issues to bugs in the code). Feel free to ask for further help in [our forums](https://discuss.huggingface.co/) or to reopen this issue if you find `transformers`-related bugs 🐛 <|||||>Thanks for your reply! I will try your suggested.<|||||>In my case, tqdm is missing, and it caused the downloading progress failed