class_docstr: Local generic trainer executor for the TFX Trainer component.
  
  The Trainer executor supplements TensorFlow training with a component to
  enable warm-start training of any user-specified TF model. The Trainer is
  a library built on top of TensorFlow that is expected to be integrated into a
  custom user-specified binary.
  
  To include Trainer in a TFX pipeline, configure your pipeline similar to
  https://github.com/tensorflow/tfx/blob/master/tfx/examples/chicago_taxi_pipeline/taxi_pipeline_simple.py#L104.
  
  For more details on the Trainer component itself, please refer to
  https://tensorflow.org/tfx/guide/trainer.  For a tutorial on Tensorflow,
  please refer to https://www.tensorflow.org/tutorials.
  
  How to create a trainer callback function to be used by this Trainer executor:
  A model training can be executed by TFX by first creating a run_fn callback
  method that defines, trains an TF Model and saves it to the provided location,
  This becomes the basis of the Executor for GenericTrainer. This Executor will
  then execute the run_fn with correct parameters by resolving the input
  artifacts, output artifacts and execution properties.
class_docstr_tok: ["Local","generic","trainer","executor","for","the","TFX","Trainer","component",".","The","Trainer","executor","supplements","TensorFlow","training","with","a","component","to","enable","warm-start","training","of","any","user-specified","TF","model",".","The","Trainer","is","a","library","built","on","top","of","TensorFlow","that","is","expected","to","be","integrated","into","a","custom","user-specified","binary",".","To","include","Trainer","in","a","TFX","pipeline",",","configure","your","pipeline","similar","to","https",":","\/\/github.com\/tensorflow\/tfx\/blob\/master\/tfx\/examples\/chicago_taxi_pipeline\/taxi_pipeline_simple.py","#","L104",".","For","more","details","on","the","Trainer","component","itself",",","please","refer","to","https",":","\/\/tensorflow.org\/tfx\/guide\/trainer",".","For","a","tutorial","on","Tensorflow",",","please","refer","to","https",":","\/\/www.tensorflow.org\/tutorials",".","How","to","create","a","trainer","callback","function","to","be","used","by","this","Trainer","executor",":","A","model","training","can","be","executed","by","TFX","by","first","creating","a","run_fn","callback","method","that","defines",",","trains","an","TF","Model","and","saves","it","to","the","provided","location",",","This","becomes","the","basis","of","the","Executor","for","GenericTrainer",".","This","Executor","will","then","execute","the","run_fn","with","correct","parameters","by","resolving","the","input","artifacts",",","output","artifacts","and","execution","properties","."]
docstr: Uses a user-supplied run_fn to train a TensorFlow model locally.
  
  The Trainer Executor invokes a run_fn callback function provided by
  the user via the module_file parameter. In this function, user defines the
  model and trains it, then saves the model and training related files
  (e.g, Tensorboard logs) to the provided locations.
  
  Args:
    input_dict: Input dict from input key to a list of ML-Metadata Artifacts.
      - examples: Examples used for training, must include 'train' and 'eval'
        if custom splits is not specified in train_args and eval_args.
      - transform_graph: Optional input transform graph.
      - transform_output: Optional input transform graph, deprecated.
      - schema: Schema of the data.
    output_dict: Output dict from output key to a list of Artifacts.
      - model: Exported model.
      - model_run: Model training related outputs (e.g., Tensorboard logs)
    exec_properties: A dict of execution properties.
      - train_args: JSON string of trainer_pb2.TrainArgs instance, providing
        args for training.
      - eval_args: JSON string of trainer_pb2.EvalArgs instance, providing
        args for eval.
      - module_file: Python module file containing UDF model definition.
        Exactly one of `module_file`, `module_path` and `run_fn` should
        be passed.
      - module_path: Python module path containing UDF model definition.
        Exactly one of `module_file`, `module_path` and `run_fn` should
        be passed.
      - run_fn: Python module path to the run function.
        Exactly one of `module_file`, `module_path` and `run_fn` should
        be passed.
      - warm_starting: Whether or not we need to do warm starting.
      - warm_start_from: Optional. If warm_starting is True, this is the
        directory to find previous model to warm start on.
      - custom_config: Optional. JSON-serialized dict of additional parameters
        to pass to trainer function.
  
  Returns:
    None
  
  Raises:
    ValueError: When not exactly one of `module_file`, `module_path` and
      `run_fn` are present in 'exec_properties'.
    RuntimeError: If run_fn failed to generate model in desired location.
docstr_tok: ["Uses","a","user-supplied","run_fn","to","train","a","TensorFlow","model","locally",".","The","Trainer","Executor","invokes","a","run_fn","callback","function","provided","by","the","user","via","the","module_file","parameter",".","In","this","function",",","user","defines","the","model","and","trains","it",",","then","saves","the","model","and","training","related","files","(","e.g",",","Tensorboard","logs",")","to","the","provided","locations",".","Args",":","input_dict",":","Input","dict","from","input","key","to","a","list","of","ML-Metadata","Artifacts",".","-","examples",":","Examples","used","for","training",",","must","include","'train","'","and","'eval'","if","custom","splits","is","not","specified","in","train_args","and","eval_args",".","-","transform_graph",":","Optional","input","transform","graph",".","-","transform_output",":","Optional","input","transform","graph",",","deprecated",".","-","schema",":","Schema","of","the","data",".","output_dict",":","Output","dict","from","output","key","to","a","list","of","Artifacts",".","-","model",":","Exported","model",".","-","model_run",":","Model","training","related","outputs","(","e.g.",",","Tensorboard","logs",")","exec_properties",":","A","dict","of","execution","properties",".","-","train_args",":","JSON","string","of","trainer_pb2.TrainArgs","instance",",","providing","args","for","training",".","-","eval_args",":","JSON","string","of","trainer_pb2.EvalArgs","instance",",","providing","args","for","eval",".","-","module_file",":","Python","module","file","containing","UDF","model","definition",".","Exactly","one","of","`","module_file","`",",","`","module_path","`","and","`","run_fn","`","should","be","passed",".","-","module_path",":","Python","module","path","containing","UDF","model","definition",".","Exactly","one","of","`","module_file","`",",","`","module_path","`","and","`","run_fn","`","should","be","passed",".","-","run_fn",":","Python","module","path","to","the","run","function",".","Exactly","one","of","`","module_file","`",",","`","module_path","`","and","`","run_fn","`","should","be","passed",".","-","warm_starting",":","Whether","or","not","we","need","to","do","warm","starting",".","-","warm_start_from",":","Optional",".","If","warm_starting","is","True",",","this","is","the","directory","to","find","previous","model","to","warm","start","on",".","-","custom_config",":","Optional",".","JSON-serialized","dict","of","additional","parameters","to","pass","to","trainer","function",".","Returns",":","None","Raises",":","ValueError",":","When","not","exactly","one","of","`","module_file","`",",","`","module_path","`","and","`","run_fn","`","are","present","in","'exec_properties","'",".","RuntimeError",":","If","run_fn","failed","to","generate","model","in","desired","location","."]
code: def Do(
      self,
      input_dict: Dict[str, List[types.Artifact]],
      output_dict: Dict[str, List[types.Artifact]],
      exec_properties: Dict[str, Any],
  ) -> None:
      """Uses a user-supplied run_fn to train a TensorFlow model locally.
  
      The Trainer Executor invokes a run_fn callback function provided by
      the user via the module_file parameter. In this function, user defines the
      model and trains it, then saves the model and training related files
      (e.g, Tensorboard logs) to the provided locations.
  
      Args:
        input_dict: Input dict from input key to a list of ML-Metadata Artifacts.
          - examples: Examples used for training, must include 'train' and 'eval'
            if custom splits is not specified in train_args and eval_args.
          - transform_graph: Optional input transform graph.
          - transform_output: Optional input transform graph, deprecated.
          - schema: Schema of the data.
        output_dict: Output dict from output key to a list of Artifacts.
          - model: Exported model.
          - model_run: Model training related outputs (e.g., Tensorboard logs)
        exec_properties: A dict of execution properties.
          - train_args: JSON string of trainer_pb2.TrainArgs instance, providing
            args for training.
          - eval_args: JSON string of trainer_pb2.EvalArgs instance, providing
            args for eval.
          - module_file: Python module file containing UDF model definition.
            Exactly one of `module_file`, `module_path` and `run_fn` should
            be passed.
          - module_path: Python module path containing UDF model definition.
            Exactly one of `module_file`, `module_path` and `run_fn` should
            be passed.
          - run_fn: Python module path to the run function.
            Exactly one of `module_file`, `module_path` and `run_fn` should
            be passed.
          - warm_starting: Whether or not we need to do warm starting.
          - warm_start_from: Optional. If warm_starting is True, this is the
            directory to find previous model to warm start on.
          - custom_config: Optional. JSON-serialized dict of additional parameters
            to pass to trainer function.
  
      Returns:
        None
  
      Raises:
        ValueError: When not exactly one of `module_file`, `module_path` and
          `run_fn` are present in 'exec_properties'.
        RuntimeError: If run_fn failed to generate model in desired location.
      """
      self._log_startup(input_dict, output_dict, exec_properties)
  
      fn_args = self._GetFnArgs(
          input_dict, output_dict, exec_properties
      )
      run_fn = udf_utils.get_fn(exec_properties, "run_fn")
  
      # Train the model
      absl.logging.info("Training model.")
      run_fn(fn_args)
  
      # Note: If trained with multi-node distribution workers, it is the user
      # module's responsibility to export the model only once.
      if not fileio.exists(fn_args.serving_model_dir):
          raise RuntimeError("run_fn failed to generate model.")
  
      absl.logging.info(
          "Training complete. Model written to %s. ModelRun written to %s",
          fn_args.serving_model_dir,
          fn_args.model_run_dir,
      )
  
imports: import json
  import os
  from typing import Any, Dict, List
  import absl
  from tensorflow import estimator
  import tensorflow_model_analysis
  from tfx import types
  from tfx.components.trainer import constants
  from tfx.components.trainer import fn_args_utils
  from tfx.components.util import udf_utils
  from tfx.dsl.components.base import base_executor
  from tfx.dsl.io import fileio
  from tfx.types import artifact_utils
  from tfx.types import standard_component_specs
  from tfx.utils import deprecation_utils
  from tfx.utils import io_utils
  from tfx.utils import path_utils
  from tensorflow.python.lib.io import file_io
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 2 for calling the GenericExecutor obj's underlying member method code with example usage: obj.Do(input_dict, output_dict, exec_properties) without return types