code: def testDeferredSlotRestoration(self):
      checkpoint_directory = self.get_temp_dir()
  
      root = trackable_utils.Checkpoint()
      root.var = trackable_utils.add_variable(
          root, name="var", initializer=0.0
      )
      optimizer = adam.AdamOptimizer(0.1)
      if context.executing_eagerly():
          optimizer.minimize(root.var.read_value)
      else:
          train_op = optimizer.minimize(root.var)
          # Note that `optimizer` has not been added as a dependency of
          # `root`. Create a one-off grouping so that slot variables for `root.var`
          # get initialized too.
          self.evaluate(
              trackable_utils.gather_initializers(
                  trackable_utils.Checkpoint(
                      root=root, optimizer=optimizer
                  )
              )
          )
          self.evaluate(train_op)
      self.evaluate(state_ops.assign(root.var, 12.0))
      no_slots_path = root.save(
          os.path.join(checkpoint_directory, "no_slots")
      )
      root.optimizer = optimizer
      self.evaluate(state_ops.assign(root.var, 13.0))
      self.evaluate(
          state_ops.assign(
              optimizer.get_slot(name="m", var=root.var), 14.0
          )
      )
      slots_path = root.save(
          os.path.join(checkpoint_directory, "with_slots")
      )
      new_root = trackable_utils.Checkpoint()
      # Load the slot-containing checkpoint (deferred), then immediately overwrite
      # the non-slot variable (also deferred).
      slot_status = new_root.restore(slots_path)
      no_slot_status = new_root.restore(no_slots_path)
      with self.assertRaises(AssertionError):
          no_slot_status.assert_consumed()
      new_root.var = trackable_utils.add_variable(
          new_root, name="var", shape=[]
      )
      no_slot_status.assert_consumed()
      no_slot_status.run_restore_ops()
      self.assertEqual(12.0, self.evaluate(new_root.var))
      new_root.optimizer = adam.AdamOptimizer(0.1)
      slot_status.assert_existing_objects_matched()
      with self.assertRaisesRegex(AssertionError, "beta1_power"):
          slot_status.assert_consumed()
      self.assertEqual(12.0, self.evaluate(new_root.var))
      if context.executing_eagerly():
          # Slot variables are only created with restoring initializers when
          # executing eagerly.
          self.assertEqual(
              14.0,
              self.evaluate(
                  new_root.optimizer.get_slot(
                      name="m", var=new_root.var
                  )
              ),
          )
      else:
          self.assertIs(
              new_root.optimizer.get_slot(name="m", var=new_root.var),
              None,
          )
      if context.executing_eagerly():
          new_root.optimizer.minimize(new_root.var.read_value)
      else:
          train_op = new_root.optimizer.minimize(new_root.var)
          # The slot variable now exists; restore() didn't create it, but we should
          # now have a restore op for it.
          slot_status.run_restore_ops()
          self.assertEqual(
              14.0,
              self.evaluate(
                  new_root.optimizer.get_slot(
                      name="m", var=new_root.var
                  )
              ),
          )
          self.evaluate(train_op)
      slot_status.assert_consumed()
  
imports: import os
  from tensorflow.python.checkpoint import checkpoint
  from tensorflow.python.checkpoint import checkpoint_options
  from tensorflow.python.client import session
  from tensorflow.python.eager import context
  from tensorflow.python.eager import test
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import init_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import state_ops
  from tensorflow.python.ops import template
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.trackable import autotrackable
  from tensorflow.python.training import adam
  from tensorflow.python.training import checkpoint_utils
label_desc: Use image node_id 1 for calling the CheckpointingTests obj's underlying member method code with example usage: obj.testDeferredSlotRestoration() without return types