Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeError:Mixing different tf.distribute.Strategy objects

Hello!I have encountered some problems when compiling the model using TPU.Some part of codes as follows:

resolver = tf.contrib.cluster_resolver.TPUClusterResolver(TF_MASTER)

tf.contrib.distribute.initialize_tpu_system(resolver)

strategy = tf.contrib.distribute.TPUStrategy(resolver)

with strategy.scope():

  model = create_model()

  model.compile(optimizer=tf.keras.optimizers.Adadelta(),loss='categorical_crossentropy',metrics='accuracy'])

And I got RuntimeError:enter image description here

Can you help me?

like image 554
o sy Avatar asked Oct 15 '22 10:10

o sy


1 Answers

I solved my problem by various chaos trying.You can restart your program or comment the code:

resolver = tf.contrib.cluster_resolver.TPUClusterResolver
tf.contrib.distribute.initialize_tpu_system(resolver)
strategy = tf.contrib.distribute.TPUStrategy(resolver)

with strategy.scope():
  model = create_model()
  model.compile()

to avoid the problem

like image 126
o sy Avatar answered Oct 20 '22 10:10

o sy