class_docstr: Training state management class.
  
  This class provides apis for backing up and restoring the training state.
  This allows model and epoch information to be saved periodically and restore
  for fault-tolerance, also known as preemption-recovery purpose.
class_docstr_tok: ["Training","state","management","class",".","This","class","provides","apis","for","backing","up","and","restoring","the","training","state",".","This","allows","model","and","epoch","information","to","be","saved","periodically","and","restore","for","fault-tolerance",",","also","known","as","preemption-recovery","purpose","."]
docstr: Maybe load initial epoch from ckpt considering possible worker recovery.
  
  When `_ckpt_saved_epoch` attribute exists and is not
  `CKPT_SAVED_EPOCH_UNUSED_VALUE`, this is under multi-worker training setting
  and indicates the worker is recovering from previous failure. In this case,
  infer `initial_epoch` from `self._ckpt_saved_epoch` to continue previous
  unfinished training from certain epoch.
  
  Args:
    initial_epoch: The original initial_epoch user passes in in `fit()`.
    mode: The mode for running `model.fit()`.
  
  Returns:
    If the training is recovering from previous failure under multi-worker
    training setting, return the epoch the training is supposed to continue
    at. Otherwise, return the `initial_epoch` the user passes in.
docstr_tok: ["Maybe","load","initial","epoch","from","ckpt","considering","possible","worker","recovery",".","When","`","_ckpt_saved_epoch","`","attribute","exists","and","is","not","`","CKPT_SAVED_EPOCH_UNUSED_VALUE","`",",","this","is","under","multi-worker","training","setting","and","indicates","the","worker","is","recovering","from","previous","failure",".","In","this","case",",","infer","`","initial_epoch","`","from","`","self._ckpt_saved_epoch","`","to","continue","previous","unfinished","training","from","certain","epoch",".","Args",":","initial_epoch",":","The","original","initial_epoch","user","passes","in","in","`","fit","(",")","`",".","mode",":","The","mode","for","running","`","model.fit","(",")","`",".","Returns",":","If","the","training","is","recovering","from","previous","failure","under","multi-worker","training","setting",",","return","the","epoch","the","training","is","supposed","to","continue","at",".","Otherwise",",","return","the","`","initial_epoch","`","the","user","passes","in","."]
code: def maybe_load_initial_epoch_from_ckpt(self, initial_epoch, mode):
      """Maybe load initial epoch from ckpt considering possible worker recovery.
  
      When `_ckpt_saved_epoch` attribute exists and is not
      `CKPT_SAVED_EPOCH_UNUSED_VALUE`, this is under multi-worker training setting
      and indicates the worker is recovering from previous failure. In this case,
      infer `initial_epoch` from `self._ckpt_saved_epoch` to continue previous
      unfinished training from certain epoch.
  
      Args:
        initial_epoch: The original initial_epoch user passes in in `fit()`.
        mode: The mode for running `model.fit()`.
  
      Returns:
        If the training is recovering from previous failure under multi-worker
        training setting, return the epoch the training is supposed to continue
        at. Otherwise, return the `initial_epoch` the user passes in.
      """
  
      epoch = backend.eval(self._ckpt_saved_epoch)
      if mode == mode_keys.ModeKeys.TRAIN and epoch >= 0:
          # The most recently saved epoch is one epoch prior to the epoch it
          # failed at, so return the value of 'self._ckpt_saved_epoch' plus one.
          return epoch + 1
      return initial_epoch
  
file_path: tensorflow-upstream/tensorflow/python/keras/distribute/worker_training_state.py
imports: import os
  from tensorflow.python.checkpoint import checkpoint
  from tensorflow.python.checkpoint import checkpoint_management
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.keras import backend
  from tensorflow.python.keras.distribute import distributed_file_utils
  from tensorflow.python.keras.utils import mode_keys
  from tensorflow.python.lib.io import file_io
  from tensorflow.python.ops import variables
label_desc: Use image node_id 5 for calling the WorkerTrainingState obj's underlying member method code with example usage: obj.maybe_load_initial_epoch_from_ckpt(initial_epoch, mode) and returns: initial_epoch, unknown