ТПУ Область применения ValueError - PullRequest
0 голосов
/ 25 февраля 2020

Я добавляю этот код на этот . Это модель

    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) 
    with strategy.scope():
      model = Model(inputs=[encoder_input, decoder_input], outputs=[output])
      model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])

Ошибка:

ValueError                                Traceback (most recent call last)
<ipython-input-6-66476e79d8c4> in <module>()
    501     build_params(input_data = input_data, output_data = output_data, params_path = 'params', max_lenghts=(10, 10))
    502 
--> 503     model, params = build_model(params_path='params')
    504 
    505     input_data, output_data = convert_training_data(input_data, output_data, params)

2 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, distribute, **kwargs)
    398                 'with strategy.scope():\n'
    399                 '  model=_create_model()\n'
--> 400                 '  model.compile(...)'% (v, strategy))
    401 
    402   @trackable.no_automatic_dependency_tracking

ValueError: Variable (<tf.Variable 'embedding_2_1/embeddings:0' shape=(39, 128) dtype=float32>) was not created in the distribution strategy scope of (<tensorflow.python.distribute.tpu_strategy.TPUStrategyV1 object at 0x7f9e623bef98>). It is most likely due to not all layers or the model or optimizer being created outside the distribution strategy scope. Try to make sure your code looks similar to the following.
with strategy.scope():
  model=_create_model()
  model.compile(...)

Я добавляю код ТПУ после. Это порядковый код:

...