hub: USE latest version can't be used with MirroredStrategy ("Trying to access a placeholder that is not supposed to be executed.")
The latest versions of USE throw this error when used in a MirroredStrategy. (tf: 2.1.0, keras: 2.2.4-tf, hub: 0.7.0)
import tensorflow as tf
import tensorflow.keras as keras
import tensorflow_hub as hub
import tensorflow_text as text
#This USE models fail with " InvalidArgumentError: assertion failed: [Trying to access a placeholder that is not supposed to be executed"
LM = "https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3"
#LM = "https://tfhub.dev/google/universal-sentence-encoder-multilingual/3"
#LM = "https://tfhub.dev/google/universal-sentence-encoder-large/5"
#LM = "https://tfhub.dev/google/universal-sentence-encoder/4"
DIM = 512
strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
model = keras.models.Sequential()
model.add(
hub.KerasLayer(LM,
output_shape=DIM,
input_shape=[],
dtype=tf.string)
)
model.add(keras.layers.Dense(1, activation='sigmoid'))
model.compile(optimizer="adam", loss="binary_crossentropy")
model.summary()
Throws:
INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0',)
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
<ipython-input-2-6b41a257fb9c> in <module>()
32 output_shape=DIM,
33 input_shape=[],
---> 34 dtype=tf.string)
35 )
36 model.add(keras.layers.Dense(1, activation='sigmoid'))
12 frames
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)
InvalidArgumentError: assertion failed: [Trying to access a placeholder that is not supposed to be executed. This means you are executing a graph generated from cross-replica context in an in-replica context.]
[[node Assert/Assert (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_hub/module_v2.py:95) ]] [Op:__inference_restored_function_body_45855]
Function call stack:
restored_function_body
Interestingly, NNLM works fine and also USE-large v3 (albeit some warnings, not sure if they affect it’s later performance). Also, if OneDeviceStrategy or no strategy is used everything works.
Check this colab with code and test cases: https://colab.research.google.com/drive/1_YaGYje4tXPyQDx_hYaj9VNLAA5hi3Dg
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (5 by maintainers)
Here is a minimum reproducible example for
tf.distribute.MirroredStrategy()with USE latest version which throws up an error.Output after this :
@arnoegw , @MorganR : Any insights on how to resolve this error.
Hi all, the issue was because this model was converted from TF1 SavedModel to TF2 SavedModel. There’s some tricky issues with loading such models under tf.distribute.Strategy. The team is working on a TF2 native version of the model.
Confirmed: there is an issue. Thank you, @eduardofv, for the very clear and reproducible report!
@mercarikaicheung, there is no useful update yet, sorry.