TensorFlow: AssertionError("Unresolved object in checkpoint

I’m following this tutorial:

in which the encoder, decoder and optimiser are “checkpointed”. When I try to restore the checkpoint as follows:

encoder = Encoder(NUM_WORDS, EMBEDDING_DIM, UNITS, BATCH_SIZE)

decoder = Decoder(NUM_WORDS, 431, EMBEDDING_DIM, UNITS, BATCH_SIZE,
                  'luong')

optimiser = tf.keras.optimizers.Adam()

checkpoint = tf.train.Checkpoint(optimiser=optimiser,
                                 encoder=encoder,
                                 decoder=decoder)

checkpoint.restore(tf.train.latest_checkpoint(checkpoint_dirpath)).assert_consumed()

I have the following error:

AssertionError("Unresolved object in checkpoint {}: {}"
AssertionError: Unresolved object in checkpoint (root).optimiser.iter: attributes {
  name: "VARIABLE_VALUE"
  full_name: "Adam/iter"
  checkpoint_key: "optimiser/iter/.ATTRIBUTES/VARIABLE_VALUE"

Without assert_consumed(), I have no error but encoder, decoder and optimiser are empty, and in doing so, not “checkpointed”.

I tried the solution proposed here:

without success.

Thank you in advance for your help.

Hi @woth , are you following the given collab file ? The collab file given runs just fine as I tested and does not output any error on your given code excerpt (shown in the bellow image). Maybe comparing this file with your own code might help.

Indeed, it works perfectly when you restore the objects, here the encoder, decoder and optimiser, in the same execution context, but execute my code separately as if you wanted to load the objects in a new execution, without having executed the code in the tutorial, and you will normally have the same error.