# Failed to Import transformers.models

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315%3E%5C
**Category:** Models\
**Created:** [June 15, 2023, 4:59am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315 "2023-06-15T04:59:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrkkn](https://avatars.discourse-cdn.com/v4/letter/h/4da419/32.png) [@Henrkkn](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHenrkkn)%5C
**Post date:** [June 15, 2023, 4:59am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315%2F1 "2023-06-15T04:59:40Z")

</div>

Hello!  
I need some help to fix my “RunTimeError” message.  
The code used:  
from transformers import TFAutoModel  
checkpoint=“distilbert-base-uncased-finetuned-sst-2-english”  
model=TFAutoModel.from\_pretrained(checkpoint)

**And the long error message**  
RuntimeError: Failed to import transformers.models.distilbert.modeling\_tf\_distilbert because of the following error (look up to see its traceback):  
No module named ‘keras.saving.hdf5\_format’

I cant see where I have done something wrong, it seems more there is something wrong with the model?

---

<div class="post-metadata">

**Author:** ![chem1](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@chem1](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchem1)%5C
**Post date:** [June 15, 2023, 7:55am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315%2F2 "2023-06-15T07:55:13Z")

</div>

> [@Henrkkn](#):
>
> No module named ‘keras.saving.hdf5\_format’

@Henrkkn Have you tried updating TensorFlow?

```auto
pip install -U tensorflow==2.10 

```

---

<div class="post-metadata">

**Author:** ![Henrkkn](https://avatars.discourse-cdn.com/v4/letter/h/4da419/32.png) [@Henrkkn](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHenrkkn)%5C
**Post date:** [June 15, 2023, 9:35am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315%2F4 "2023-06-15T09:35:14Z")

</div>

After installed the Tensorflow as mentioned, I now receive a new RunTime Error:

"RuntimeError: Failed to import transformers.models.distilbert.modeling\_tf\_distilbert because of the following error (look up to see its traceback):  
Duplicate registrations for type ‘experimentalOptimizer’ "

---

<div class="post-metadata">

**Author:** ![rifazks](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@rifazks](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frifazks)%5C
**Post date:** [September 15, 2023, 3:32am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315%2F5 "2023-09-15T03:32:51Z")

</div>

Rolling back to 2.10 results out with google protobuf disconnect error.

---

<div class="post-metadata">

**Author:** ![Tarzan-07](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@Tarzan-07](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FTarzan-07)%5C
**Post date:** [March 19, 2024, 6:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315%2F6 "2024-03-19T18:55:59Z")

</div>

@chem1 I tried this:  
from transformers import TFAutoModel  
checkpoint = ‘distilbert-base-uncased-finetuned-sst-2-english’  
model = TFAutoModel.from\_pretrained(checkpoint)

I am getting this:  
RuntimeError: Failed to import transformers.models.distilbert.modeling\_tf\_distilbert because of the following error (look up to see its traceback):  
module ‘tensorflow.\_api.v2.compat.v2. **internal** ’ has no attribute ‘register\_load\_context\_function’

I am using latest version of everything. More specifically, transformers = 4.38.2, tensorflow = 2.16, keras = 3.1.1, protobuf = 5.26.0

---

<div class="post-metadata">

**Author:** ![Sandy1857](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Sandy1857](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FSandy1857)%5C
**Post date:** [March 20, 2024, 12:25am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffailed-to-import-transformers-models%2F43315%2F7 "2024-03-20T00:25:40Z")

</div>

Maybe the issue is because of keras 3 which is the default since tf 2.16. suggest trying out with lower tf version.
