# Unable to load model using tensorflow hub.KerasLayer

**URL:** <https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194>\
**Category:** General Discussion\
**Tags:** tfhub\
**Created:** [August 18, 2023, 5:03am UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194 "2023-08-18T05:03:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdul\_Rahmaan](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/abdul_rahmaan/32/14408_2.png) [@Abdul\_Rahmaan](https://discuss.ai.google.dev/u/Abdul_Rahmaan)\
**Post date:** [August 18, 2023, 5:03am UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194/1 "2023-08-18T05:03:50Z")

</div>

I am getting this error, when I try to install the bert models:

Code:  
bert\_preprocess = hub.KerasLayer(‘[TensorFlow | bert | Kaggle](https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3)’)  
bert\_encoder = hub.KerasLayer(‘[TensorFlow | bert | Kaggle](https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/4)’)

InvalidArgumentError: Multiple OpKernel registrations match NodeDef at the same priority ‘{{node AssignVariableOp}}’: ‘op: “AssignVariableOp” device\_type: “GPU” constraint { name: “dtype” allowed\_values { list { type: DT\_INT64 } } } host\_memory\_arg: “resource”’ and ‘op: “AssignVariableOp” device\_type: “GPU” constraint { name: “dtype” allowed\_values { list { type: DT\_INT64 } } } host\_memory\_arg: “resource”’  
[[AssignVariableOp]] [Op:AssignVariableOp]

---

<div class="post-metadata">

**Author:** ![Kiran\_Sai\_Ramineni](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kiran_sai_ramineni/32/8859_2.png) [@Kiran\_Sai\_Ramineni](https://discuss.ai.google.dev/u/Kiran_Sai_Ramineni)\
**Post date:** [August 18, 2023, 6:30am UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194/2 "2023-08-18T06:30:34Z")

</div>

Hi @Abdul_Rahmaan, Before importing the bert model from tf hub you have to import tensorflow\_text as text to registers the ops

```auto
import tensorflow_text as text
import tensorflow_hub as hub

preprocessor = hub.KerasLayer("https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3")

```

. Thank You.

---

<div class="post-metadata">

**Author:** ![Abdul\_Rahmaan](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/abdul_rahmaan/32/14408_2.png) [@Abdul\_Rahmaan](https://discuss.ai.google.dev/u/Abdul_Rahmaan)\
**Post date:** [August 18, 2023, 1:46pm UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194/4 "2023-08-18T13:46:40Z")

</div>

Yes, I have done that but still getting the same error.

---

<div class="post-metadata">

**Author:** ![lgusm](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/lgusm/32/6230_2.png) [@lgusm](https://discuss.ai.google.dev/u/lgusm)\
**Post date:** [August 18, 2023, 3:23pm UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194/5 "2023-08-18T15:23:59Z")

</div>

HI Abdul,

I’ve just tested exactly the same code here on colab:

```auto
!pip install tensorflow_text

import tensorflow_text as text
import tensorflow_hub as hub

preprocessor = hub.KerasLayer("https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3")
bert_encoder = hub.KerasLayer("https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/4")

```

and everything works fine.  
Maybe there’s something on the env you are running it?

---

<div class="post-metadata">

**Author:** ![Abdul\_Rahmaan](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/abdul_rahmaan/32/14408_2.png) [@Abdul\_Rahmaan](https://discuss.ai.google.dev/u/Abdul_Rahmaan)\
**Post date:** [August 18, 2023, 3:38pm UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194/6 "2023-08-18T15:38:22Z")

</div>

Hey, I am not sure if there is env issue as I have created a new env. I am adding the logs on anaconda prompt. Hopefully that helps.

To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.  
2023-08-18 19:31:57.154641: I tensorflow/c/logging.cc:34] DirectML: creating device on adapter 0 (NVIDIA GeForce GTX 1650)  
2023-08-18 19:31:57.336691: I tensorflow/c/logging.cc:34] Successfully opened dynamic library Kernel32.dll  
2023-08-18 19:31:57.340141: I tensorflow/core/common\_runtime/pluggable\_device/pluggable\_device\_factory.cc:306] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.  
2023-08-18 19:31:57.340511: W tensorflow/core/common\_runtime/pluggable\_device/pluggable\_device\_bfc\_allocator.cc:28] Overriding allow\_growth setting because force\_memory\_growth was requested by the device.  
2023-08-18 19:31:57.341053: I tensorflow/core/common\_runtime/pluggable\_device/pluggable\_device\_factory.cc:272] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10190 MB memory) → physical PluggableDevice (device: 0, name: DML, pci bus id: )  
2023-08-18 19:31:59.144319: E tensorflow/core/grappler/clusters/utils.cc:87] Failed to get device properties, error code: 302  
[I 2023-08-18 19:32:57.550 ServerApp] Saving file at /NNCodeBasics/Untitled1.ipynb

---

<div class="post-metadata">

**Author:** ![Kiran\_Sai\_Ramineni](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kiran_sai_ramineni/32/8859_2.png) [@Kiran\_Sai\_Ramineni](https://discuss.ai.google.dev/u/Kiran_Sai_Ramineni)\
**Post date:** [September 22, 2023, 6:39am UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194/8 "2023-09-22T06:39:31Z")

</div>

Hi @Abdul_Rahmaan, Could you please share the details of the environment like OS, Tensorflow version you are using, the platform which you are trying to execute the code, etc… Thank You.

---

<div class="post-metadata">

**Author:** ![Abdul\_Rahmaan](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/abdul_rahmaan/32/14408_2.png) [@Abdul\_Rahmaan](https://discuss.ai.google.dev/u/Abdul_Rahmaan)\
**Post date:** [September 22, 2023, 4:38pm UTC](https://discuss.ai.google.dev/t/unable-to-load-model-using-tensorflow-hub-keraslayer/30194/10 "2023-09-22T16:38:42Z")

</div>

Hey, I was able to solve the issue by deleting the environment and creating a new one.  
Thank you.
