class_docstr: Handles training restarts.
  
  Particularly useful when sharing parameters (and checkpoints) between models.
  
  Args:
    model_mode (str): Model "mode". Different modes have different local step
        counters, but the same global step counter. Also used in log messages.
    checkpoint_dir (str): Model checkpoint directory. Global step is inferred
        from the name of the last checkpoint.
    target_local_step (int): Local step to train the model up to.
  
  Attributes:
    model_mode (str): See args.
    checkpoint_dir (str): See args.
    target_local_step (int): See args.
    target_global_step (int): Calculated global step to train the model up to.
    should_skip (bool): Whether training should be skipped because the number of
        local steps already done is higher than the target. This happens during
        restarts.
    steps_to_go: how many steps to go.
    restarting (bool): Whether the current epoch of training has been
        interrupted and is being restarted.
code: def __init__(self, model_mode, checkpoint_dir, target_local_step):
      self.model_mode = model_mode
      self.checkpoint_dir = checkpoint_dir
      self.target_local_step = target_local_step
      self.target_global_step = None
      self.should_skip = False
      self.restarting = False
  
      self._counter_path = os.path.join(
          checkpoint_dir, "{}_step_counter".format(model_mode)
      )
  
      self._global_step = self._get_global_step()
      tf.logging.info(
          "Will load %s checkpoint %d",
          self.model_mode,
          self._global_step,
      )
  
      (
          self._local_step_at_start,
          global_step_at_start,
      ) = self._read_counters()
  
      self.steps_to_go = target_local_step - self._local_step_at_start
      if self.steps_to_go <= 0:
          tf.logging.info(
              "Skipping training %s, requested %d steps, already done %d",
              self.model_mode,
              target_local_step,
              self._local_step_at_start,
          )
          self.should_skip = True
          return
  
      if global_step_at_start != -1:
          # Restart.
          steps_done_this_epoch = (
              self._global_step - global_step_at_start
          )
          self.steps_to_go -= steps_done_this_epoch
          tf.logging.info(
              "Restarting training %s, %d steps already done this epoch",
              self.model_mode,
              steps_done_this_epoch,
          )
          self.restarting = True
  
      self.target_global_step = self._global_step + self.steps_to_go
  
file_path: tensor2tensor/tensor2tensor/rl/restarter.py
imports: import contextlib
  import os
  import tensorflow.compat.v1
label_desc: Use image node_id 1 to create a new Restarter object from inherited base classes: object with example: obj = Restarter(model_mode, checkpoint_dir, target_local_step)