class_docstr: Checkpoints input pipeline state every N steps or seconds.
  
  This hook saves the state of the iterators in the `Graph` so that when
  training is resumed the input pipeline continues from where it left off.
  This could potentially avoid overfitting in certain pipelines where the
  number of training steps per eval are small compared to the dataset
  size or if the training pipeline is pre-empted.
  
  Differences from `CheckpointSaverHook`:
  1. Saves only the input pipelines in the "iterators" collection and not the
     global variables or other saveable objects.
  2. Does not write the `GraphDef` and `MetaGraphDef` to the summary.
  
  Example of checkpointing the training pipeline:
  
  ```python
  est = tf.estimator.Estimator(model_fn)
  while True:
    est.train(
        train_input_fn,
        hooks=[tf.data.experimental.CheckpointInputPipelineHook(est)],
        steps=train_steps_per_eval)
    # Note: We do not pass the hook here.
    metrics = est.evaluate(eval_input_fn)
    if should_stop_the_training(metrics):
      break
  ```
  
  This hook should be used if the input pipeline state needs to be saved
  separate from the model checkpoint. Doing so may be useful for a few reasons:
  1. The input pipeline checkpoint may be large, if there are large shuffle
     or prefetch buffers for instance, and may bloat the checkpoint size.
  2. If the input pipeline is shared between training and validation, restoring
     the checkpoint during validation may override the validation input
     pipeline.
  
  For saving the input pipeline checkpoint alongside the model weights use
  `tf.data.experimental.make_saveable_from_iterator` directly to create a
  `SaveableObject` and add to the `SAVEABLE_OBJECTS` collection. Note, however,
  that you will need to be careful not to restore the training iterator during
  eval. You can do that by not adding the iterator to the SAVEABLE_OBJECTS
  collector when building the eval graph.
class_docstr_tok: ["Checkpoints","input","pipeline","state","every","N","steps","or","seconds",".","This","hook","saves","the","state","of","the","iterators","in","the","`","Graph","`","so","that","when","training","is","resumed","the","input","pipeline","continues","from","where","it","left","off",".","This","could","potentially","avoid","overfitting","in","certain","pipelines","where","the","number","of","training","steps","per","eval","are","small","compared","to","the","dataset","size","or","if","the","training","pipeline","is","pre-empted",".","Differences","from","`","CheckpointSaverHook","`",":","1",".","Saves","only","the","input","pipelines","in","the","``","iterators","''","collection","and","not","the","global","variables","or","other","saveable","objects",".","2",".","Does","not","write","the","`","GraphDef","`","and","`","MetaGraphDef","`","to","the","summary",".","Example","of","checkpointing","the","training","pipeline",":","``","`","python","est","=","tf.estimator.Estimator","(","model_fn",")","while","True",":","est.train","(","train_input_fn",",","hooks=","[","tf.data.experimental.CheckpointInputPipelineHook","(","est",")","]",",","steps=train_steps_per_eval",")","#","Note",":","We","do","not","pass","the","hook","here",".","metrics","=","est.evaluate","(","eval_input_fn",")","if","should_stop_the_training","(","metrics",")",":","break","``","`","This","hook","should","be","used","if","the","input","pipeline","state","needs","to","be","saved","separate","from","the","model","checkpoint",".","Doing","so","may","be","useful","for","a","few","reasons",":","1",".","The","input","pipeline","checkpoint","may","be","large",",","if","there","are","large","shuffle","or","prefetch","buffers","for","instance",",","and","may","bloat","the","checkpoint","size",".","2",".","If","the","input","pipeline","is","shared","between","training","and","validation",",","restoring","the","checkpoint","during","validation","may","override","the","validation","input","pipeline",".","For","saving","the","input","pipeline","checkpoint","alongside","the","model","weights","use","`","tf.data.experimental.make_saveable_from_iterator","`","directly","to","create","a","`","SaveableObject","`","and","add","to","the","`","SAVEABLE_OBJECTS","`","collection",".","Note",",","however",",","that","you","will","need","to","be","careful","not","to","restore","the","training","iterator","during","eval",".","You","can","do","that","by","not","adding","the","iterator","to","the","SAVEABLE_OBJECTS","collector","when","building","the","eval","graph","."]
docstr: Initializes a `CheckpointInputPipelineHook`.
  
  If the input pipeline depends on external state (e.g. seeds for
  RandomUniform) beyond the input pipeline, this hook would be unable to
  serialize and deserialize that state. If its acceptable to ignore that state
  change the external_state_policy argument to 'warn' or 'ignore'. For e.g.
  
  ```python
  est = tf.estimator.Estimator(model_fn)
  while True:
    est.train(
        train_input_fn,
        hooks=[tf.data.experimental.CheckpointInputPipelineHook(
            est, external_state_policy='warn')],
        steps=train_steps_per_eval)
    # Note: We do not pass the hook here.
    metrics = est.evaluate(eval_input_fn)
    if should_stop_the_training(metrics):
      break
  ```
  
  Args:
    estimator: Estimator.
    external_state_policy: A string that identifies how to handle input
      pipelines that depend on external state. Possible values are
      'ignore': The external state is silently ignored.
      'warn': The external state is ignored, logging a warning.
      'fail': The operation fails upon encountering external state.
      By default we set it to 'fail'.
  
  Raises:
    ValueError: One of `save_steps` or `save_secs` should be set.
    ValueError: At most one of saver or scaffold should be set.
    ValueError: If `external_state_policy` is not one of 'warn', 'ignore' or
      'fail'.
docstr_tok: ["Initializes","a","`","CheckpointInputPipelineHook","`",".","If","the","input","pipeline","depends","on","external","state","(","e.g",".","seeds","for","RandomUniform",")","beyond","the","input","pipeline",",","this","hook","would","be","unable","to","serialize","and","deserialize","that","state",".","If","its","acceptable","to","ignore","that","state","change","the","external_state_policy","argument","to","'warn","'","or","'ignore","'",".","For","e.g",".","``","`","python","est","=","tf.estimator.Estimator","(","model_fn",")","while","True",":","est.train","(","train_input_fn",",","hooks=","[","tf.data.experimental.CheckpointInputPipelineHook","(","est",",","external_state_policy='warn","'",")","]",",","steps=train_steps_per_eval",")","#","Note",":","We","do","not","pass","the","hook","here",".","metrics","=","est.evaluate","(","eval_input_fn",")","if","should_stop_the_training","(","metrics",")",":","break","``","`","Args",":","estimator",":","Estimator",".","external_state_policy",":","A","string","that","identifies","how","to","handle","input","pipelines","that","depend","on","external","state",".","Possible","values","are","'ignore","'",":","The","external","state","is","silently","ignored",".","'warn","'",":","The","external","state","is","ignored",",","logging","a","warning",".","'fail","'",":","The","operation","fails","upon","encountering","external","state",".","By","default","we","set","it","to","'fail","'",".","Raises",":","ValueError",":","One","of","`","save_steps","`","or","`","save_secs","`","should","be","set",".","ValueError",":","At","most","one","of","saver","or","scaffold","should","be","set",".","ValueError",":","If","`","external_state_policy","`","is","not","one","of","'warn","'",",","'ignore","'","or","'fail","'","."]
code: def __init__(self, estimator, external_state_policy=None):
      """Initializes a `CheckpointInputPipelineHook`.
  
      If the input pipeline depends on external state (e.g. seeds for
      RandomUniform) beyond the input pipeline, this hook would be unable to
      serialize and deserialize that state. If its acceptable to ignore that state
      change the external_state_policy argument to 'warn' or 'ignore'. For e.g.
  
      ```python
      est = tf.estimator.Estimator(model_fn)
      while True:
        est.train(
            train_input_fn,
            hooks=[tf.data.experimental.CheckpointInputPipelineHook(
                est, external_state_policy='warn')],
            steps=train_steps_per_eval)
        # Note: We do not pass the hook here.
        metrics = est.evaluate(eval_input_fn)
        if should_stop_the_training(metrics):
          break
      ```
  
      Args:
        estimator: Estimator.
        external_state_policy: A string that identifies how to handle input
          pipelines that depend on external state. Possible values are
          'ignore': The external state is silently ignored.
          'warn': The external state is ignored, logging a warning.
          'fail': The operation fails upon encountering external state.
          By default we set it to 'fail'.
  
      Raises:
        ValueError: One of `save_steps` or `save_secs` should be set.
        ValueError: At most one of saver or scaffold should be set.
        ValueError: If `external_state_policy` is not one of 'warn', 'ignore' or
          'fail'.
      """
      if external_state_policy is None:
          external_state_policy = "fail"
      self._external_state_policy = (
          _convert_external_state_policy_to_enum(external_state_policy)
      )
      # `checkpoint_basename` is "input.ckpt" for non-distributed pipelines or
      # of the form "input_<task_type>_<task_id>.ckpt" for distributed pipelines.
      # Note: The default `checkpoint_basename` used by `CheckpointSaverHook` is
      # "model.ckpt". We intentionally choose the input pipeline checkpoint prefix
      # to be different to avoid conflicts with the model checkpoint.
  
      # pylint: disable=protected-access
      checkpoint_prefix = "input"
      if estimator._config.num_worker_replicas > 1:
          # Distributed setting.
          suffix = "_{}_{}".format(
              estimator._config.task_type, estimator._config.task_id
          )
          checkpoint_prefix += suffix
      # pylint: enable=protected-access
  
      # We use a composition paradigm instead of inheriting from
      # `CheckpointSaverHook` because `Estimator` does an `isinstance` check
      # to check whether a `CheckpointSaverHook` is already present in the list
      # of hooks and if not, adds one. Inheriting from `CheckpointSaverHook`
      # would thwart this behavior. This hook checkpoints *only the iterators*
      # and not the graph variables.
      self._checkpoint_saver_hook = basic_session_run_hooks.CheckpointSaverHook(
          estimator.model_dir,
          save_secs=estimator._config.save_checkpoints_secs,  # pylint: disable=protected-access
          save_steps=estimator._config.save_checkpoints_steps,  # pylint: disable=protected-access
          checkpoint_basename=checkpoint_prefix + ".ckpt",
      )
  
      # Name for the protocol buffer file that will contain the list of most
      # recent checkpoints stored as a `CheckpointState` protocol buffer.
      # This file, kept in the same directory as the checkpoint files, is
      # automatically managed by the `Saver` to keep track of recent checkpoints.
      # The default name used by the `Saver` for this file is "checkpoint". Here
      # we use the name "checkpoint_<checkpoint_prefix>" so that in case the
      # `checkpoint_dir` is the same as the model checkpoint directory, there are
      # no conflicts during restore.
      self._latest_filename = "checkpoint_" + checkpoint_prefix
  
imports: from tensorflow.python.checkpoint import checkpoint_management
  from tensorflow.python.data.ops import iterator_ops
  from tensorflow.python.data.ops import options
  from tensorflow.python.framework import ops
  from tensorflow.python.training import basic_session_run_hooks
  from tensorflow.python.training import saver
  from tensorflow.python.training import session_run_hook
  from tensorflow.python.util import deprecation
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 1 to create a new CheckpointInputPipelineHook object from inherited base classes: session_run_hook with example: obj = CheckpointInputPipelineHook(estimator, external_state_policy)