class_docstr: DEPRECATED: Please use `Evaluator` instead.
  
  The model validator helps prevent bad models from being pushed to production.
  It does this by validating exported models against known good models (e.g. the
  current production model), and marking the exported model as good ("blessing
  it") only if the exported model's metrics are within predefined thresholds
  around the good model's metrics.
  
  The model validator will validate tf.serving format exported models produced
  by the Trainer component. The validator evaluates the models on examples
  created by the ExampleGen component. The validator will also automatically
  read data written by the Pusher component regarding the latest pushed models
  by using ml.metadata to query the previously pushed artifacts.
  
  To include ModelValidator 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#L110.
class_docstr_tok: ["DEPRECATED",":","Please","use","`","Evaluator","`","instead",".","The","model","validator","helps","prevent","bad","models","from","being","pushed","to","production",".","It","does","this","by","validating","exported","models","against","known","good","models","(","e.g",".","the","current","production","model",")",",","and","marking","the","exported","model","as","good","(","``","blessing","it","''",")","only","if","the","exported","model","'s","metrics","are","within","predefined","thresholds","around","the","good","model","'s","metrics",".","The","model","validator","will","validate","tf.serving","format","exported","models","produced","by","the","Trainer","component",".","The","validator","evaluates","the","models","on","examples","created","by","the","ExampleGen","component",".","The","validator","will","also","automatically","read","data","written","by","the","Pusher","component","regarding","the","latest","pushed","models","by","using","ml.metadata","to","query","the","previously","pushed","artifacts",".","To","include","ModelValidator","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","#","L110","."]
docstr: Validate current model against last blessed model.
  
  Args:
    input_dict: Input dict from input key to a list of Artifacts.
      - examples: examples for eval the model.
      - model: current model for validation.
    output_dict: Output dict from output key to a list of Artifacts.
      - blessing: model blessing result.
    exec_properties: A dict of execution properties.
      - blessed_model: last blessed model for validation.
      - blessed_model_id: last blessed model id.
  
  Returns:
    None
docstr_tok: ["Validate","current","model","against","last","blessed","model",".","Args",":","input_dict",":","Input","dict","from","input","key","to","a","list","of","Artifacts",".","-","examples",":","examples","for","eval","the","model",".","-","model",":","current","model","for","validation",".","output_dict",":","Output","dict","from","output","key","to","a","list","of","Artifacts",".","-","blessing",":","model","blessing","result",".","exec_properties",":","A","dict","of","execution","properties",".","-","blessed_model",":","last","blessed","model","for","validation",".","-","blessed_model_id",":","last","blessed","model","id",".","Returns",":","None"]
code: def Do(
      self,
      input_dict: Dict[str, List[types.Artifact]],
      output_dict: Dict[str, List[types.Artifact]],
      exec_properties: Dict[str, Any],
  ) -> None:
      """Validate current model against last blessed model.
  
      Args:
        input_dict: Input dict from input key to a list of Artifacts.
          - examples: examples for eval the model.
          - model: current model for validation.
        output_dict: Output dict from output key to a list of Artifacts.
          - blessing: model blessing result.
        exec_properties: A dict of execution properties.
          - blessed_model: last blessed model for validation.
          - blessed_model_id: last blessed model id.
  
      Returns:
        None
      """
      self._log_startup(input_dict, output_dict, exec_properties)
      self._temp_path = self._get_tmp_dir()
      absl.logging.info(
          "Using temp path {} for tft.beam".format(self._temp_path)
      )
  
      eval_examples_uri = artifact_utils.get_split_uri(
          input_dict[constants.EXAMPLES_KEY], "eval"
      )
      blessing = artifact_utils.get_single_instance(
          output_dict[constants.BLESSING_KEY]
      )
  
      # Current model to be validated.
      current_model = artifact_utils.get_single_instance(
          input_dict[constants.MODEL_KEY]
      )
      absl.logging.info(
          "Using {} as current model.".format(current_model.uri)
      )
      blessing.set_string_custom_property(
          constants.ARTIFACT_PROPERTY_CURRENT_MODEL_URI_KEY,
          current_model.uri,
      )
      blessing.set_int_custom_property(
          constants.ARTIFACT_PROPERTY_CURRENT_MODEL_ID_KEY,
          current_model.id,
      )
  
      # Denote model component_name.
      component_id = exec_properties["current_component_id"]
      blessing.set_string_custom_property("component_id", component_id)
  
      # Previous blessed model to be validated against.
      blessed_model_dir = exec_properties["blessed_model"]
      blessed_model_id = exec_properties["blessed_model_id"]
      absl.logging.info(
          "Using {} as blessed model.".format(blessed_model_dir)
      )
      if blessed_model_dir:
          blessing.set_string_custom_property(
              constants.ARTIFACT_PROPERTY_BLESSED_MODEL_URI_KEY,
              blessed_model_dir,
          )
          blessing.set_int_custom_property(
              constants.ARTIFACT_PROPERTY_BLESSED_MODEL_ID_KEY,
              blessed_model_id,
          )
  
      absl.logging.info("Validating model.")
      # TODO(b/125853306): support customized slice spec.
      blessed = self._generate_blessing_result(
          eval_examples_uri=eval_examples_uri,
          slice_spec=[tfma.slicer.SingleSliceSpec()],
          current_model_dir=current_model.uri,
          blessed_model_dir=blessed_model_dir,
      )
  
      if blessed:
          io_utils.write_string_file(
              os.path.join(blessing.uri, constants.BLESSED_FILE_NAME),
              "",
          )
          blessing.set_int_custom_property(
              constants.ARTIFACT_PROPERTY_BLESSED_KEY,
              constants.BLESSED_VALUE,
          )
      else:
          io_utils.write_string_file(
              os.path.join(
                  blessing.uri, constants.NOT_BLESSED_FILE_NAME
              ),
              "",
          )
          blessing.set_int_custom_property(
              constants.ARTIFACT_PROPERTY_BLESSED_KEY,
              constants.NOT_BLESSED_VALUE,
          )
      absl.logging.info(
          "Blessing result {} written to {}.".format(
              blessed, blessing.uri
          )
      )
  
      io_utils.delete_dir(self._temp_path)
      absl.logging.info(
          "Cleaned up temp path {} on executor success.".format(
              self._temp_path
          )
      )
  
file_path: tfx/tfx/components/model_validator/executor.py
imports: import os
  from typing import Any, Dict, List
  import absl
  import apache_beam
  import tensorflow_model_analysis
  from tfx import types
  from tfx.components.model_validator import constants
  from tfx.dsl.components.base import base_beam_executor
  from tfx.dsl.io import fileio
  from tfx.types import artifact_utils
  from tfx.utils import io_utils
  from tfx.utils import path_utils
label_desc: Use image node_id 4 for calling the Executor obj's underlying member method code with example usage: obj.Do(input_dict, output_dict, exec_properties) without return types