0

I'm using google colab for the first time, and I'm testing the TPU. But when I run my keras model, I get the error ValueError: Variable tpu_140268413570632//kernel/0 already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? For transphorming the keras model to tpu model, I use this code model = tf.contrib.tpu.keras_to_tpu_model(keras_model, strategy=tf.contrib.tpu.TPUDistributionStrategy(tf.contrib.cluster_resolver.TPUClusterResolver(tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])))

Here is link to the code https://colab.research.google.com/drive/18uzgCgg1LGGRowgzq997rZSwkL832jpB

Any idea why I get this error?

Hr2944
  • 5
  • 4

1 Answers1

0

The code link isn't active anymore or I don't have access to it.

One issue that I see is the way you configure a TPUStrategy. Here is a code sample to correctly initialize a TPUStrategy. Make sure you have selected TPU in the Colab runtime.

import os
import tensorflow as tf

resolver = tf.distribute.cluster_resolver.TPUClusterResolver(tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])
tf.config.experimental_connect_to_cluster(resolver)
tf.tpu.experimental.initialize_tpu_system(resolver)

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

For more info please have a look at the TPU guide.

Gagik
  • 396
  • 3
  • 6
  • Your code is right, but probably isn't the solution. Since my original post, the initialization method has changed for yours, it is why my code seems wrong now. But I haven't had any errors for a long time now, may be google has solved the problem. – Hr2944 Jun 13 '20 at 08:21