# What to do when HuggingFace throws "Can't load tokenizer"

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%3E%5C
**Category:** Models\
**Created:** [September 12, 2022, 10:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046 "2022-09-12T22:31:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![EssamWisam](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/essamwisam/32/6034_2.png) [@EssamWisam](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FEssamWisam)%5C
**Post date:** [September 12, 2022, 10:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F1 "2022-09-12T22:31:24Z")

</div>

Whether upon trying the inference API or running the code in “use with transformers” I get the following long error:

“Can’t load tokenizer using from\_pretrained, please update its configuration: Can’t load tokenizer for ‘remi/bertabs-finetuned-extractive-abstractive-summarization’. If you were trying to load it from ‘[Models - Hugging Face](https://huggingface.co/models)’, make sure you don’t have a local directory with the same name. Otherwise, make sure ‘remi/bertabs-finetuned-extractive-abstractive-summarization’ is the correct path to a directory containing all relevant files for a BertTokenizerFast tokenizer.”

This doesn’t just apply to this specific model but for many models I have tried to run. Is there any solution for this?

---

<div class="post-metadata">

**Author:** ![matthew-edgin](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@matthew-edgin](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmatthew-edgin)%5C
**Post date:** [November 17, 2022, 2:24pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F2 "2022-11-17T14:24:40Z")

</div>

I have this same error. replying to get feedback.

---

<div class="post-metadata">

**Author:** ![stevhliu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/stevhliu/32/18373_2.png) [@stevhliu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fstevhliu)%5C
**Post date:** [November 17, 2022, 3:18pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F3 "2022-11-17T15:18:27Z")

</div>

Hi, can you try:

```auto
from transformers import BertForMaskedLM

model = BertForMaskedLM.from_pretrained("remi/bertabs-finetuned-extractive-abstractive-summarization")

```

This worked for me 🙂

---

<div class="post-metadata">

**Author:** ![kkedia](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@kkedia](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkkedia)%5C
**Post date:** [June 9, 2023, 9:05am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F4 "2023-06-09T09:05:58Z")

</div>

@EssamWisam How were you able to solve this problem. I am facing the same issue. The code is working in one of the GPUs but when i try to run it azure gpu i am getting this issue

---

<div class="post-metadata">

**Author:** ![double-fire](https://avatars.discourse-cdn.com/v4/letter/d/da6949/32.png) [@double-fire](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdouble-fire)%5C
**Post date:** [August 2, 2023, 11:59am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F5 "2023-08-02T11:59:41Z")

</div>

Network issues can also cause this issue.  
In my case I solved it by setting proxy, maybe you can try to check your network.

---

<div class="post-metadata">

**Author:** ![wanghao001](https://avatars.discourse-cdn.com/v4/letter/w/dbc845/32.png) [@wanghao001](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fwanghao001)%5C
**Post date:** [October 12, 2023, 11:17am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F6 "2023-10-12T11:17:50Z")

</div>

Thanks so much!

---

<div class="post-metadata">

**Author:** ![Areeb123](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/areeb123/32/21242_2.png) [@Areeb123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAreeb123)%5C
**Post date:** [November 16, 2023, 2:43pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F7 "2023-11-16T14:43:43Z")

</div>

"I encountered a similar error but was able to resolve it by referring to the Hugging Face documentation.

1. Initially, access the Hugging Face hub via the notebook by executing the following commands:

_!pip install huggingface\_hub_  
_from huggingface\_hub import notebook\_login_  
_notebook\_login()_

**Note:** Two types of tokens, namely ‘read’ and ‘write’, are generated in your huggingface hub. The ‘write’ token should be utilized for authorization.

1. Begin by pushing the files associated with the model to the hub:

_model.push\_to\_hub(“Model\_Name”)_

1. Similarly, push the tokenizer-related files to the hub:

_tokenizer.push\_to\_hub(“Model\_Name”)_

And that’s it, your problem is solved 🤗

---

<div class="post-metadata">

**Author:** ![tunggad](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tunggad](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftunggad)%5C
**Post date:** [December 22, 2023, 10:39pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F8 "2023-12-22T22:39:32Z")

</div>

I got into the reported error above while following the guide [Causal language modeling](https://huggingface.co/docs/transformers/tasks/language_modeling), I tried ONLY step 3 in my notebook and it worked - I can load the model and do inference on it, on hub and local as well, that means the tokenizer was missing, trainer.push\_to\_hub() did not generate/push it to hub. Thank you!

---

<div class="post-metadata">

**Author:** ![Meera-Datey](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/meera-datey/32/26276_2.png) [@Meera-Datey](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMeera-Datey)%5C
**Post date:** [May 5, 2024, 7:33am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-to-do-when-huggingface-throws-cant-load-tokenizer%2F23046%2F9 "2024-05-05T07:33:03Z")

</div>

> [@EssamWisam](#):
>
> remi/bertabs-finetuned-extractive-abstractive-summarization

You may encounter this error if the model is a gated model, and you need to accept the licensing terms before using the model.

Go to the Model Card in hugging face, accept the licensing term, generate key and add the key in your program

```auto
import os
os.environ['HF_TOKEN']='my-key'

```

this worked for me.
