code: def trace_and_write_v2_saved_model(
      saved_model_dir: str,
      preprocessing_fn: Callable[
          [Mapping[str, common_types.TensorType]],
          Mapping[str, common_types.TensorType],
      ],
      input_signature: Mapping[str, tf.TypeSpec],
      base_temp_dir: Optional[str],
      baseline_analyzers_fingerprint: Mapping[
          str, graph_tools.AnalyzersFingerprint
      ],
      tensor_replacement_map: Optional[Dict[str, tf.Tensor]],
      output_keys_to_name_map: Optional[Dict[str, str]],
  ):
      """Writes out a SavedModelV2 with preprocessing_fn traced using tf.function.
  
      The SavedModel written contains a method called `transform_fn` that
      represents the traced `preprocessing_fn`. Additionally, if this is the final
      SavedModel being written out, it will contain a method called `metadata_fn`
      that provides deferred schema annotations.
  
      Args:
        saved_model_dir: Path to write SavedModel to.
        preprocessing_fn: A user defined python function to be traced.
        input_signature: TypeSpecs describing the inputs to the `preprocessing_fn`.
        base_temp_dir: Base path to write temporary artifacts to.
        baseline_analyzers_fingerprint: A mapping from analyzer name to a set of
          paths that define its fingerprint.
        tensor_replacement_map: A map from placeholder tensor names to their
          evaluated replacement tensors.
        output_keys_to_name_map: A map from output dictionary keys to the names of
          the tensors that they represent.
  
      Returns:
        A tuple containing a pair of `tf.ConcreteFunction`s:
          1. The traced preprocessing_fn.
          2. A metadata_fn that returns a dictionary containing the deferred
          annotations added to the graph when invoked with any valid input.
  
      Raises:
        RuntimeError: if analyzers in `preprocessing_fn` are encountered in a
        non-deterministic order.
      """
      concrete_transform_fn = _trace_and_write_transform_fn(
          saved_model_dir,
          preprocessing_fn,
          input_signature,
          base_temp_dir,
          tensor_replacement_map,
          output_keys_to_name_map,
      )
      structured_inputs = (
          tf2_utils.get_structured_inputs_from_func_graph(
              concrete_transform_fn.graph
          )
      )
      _validate_analyzers_fingerprint(
          baseline_analyzers_fingerprint,
          concrete_transform_fn.graph,
          structured_inputs,
      )
  
      # If the `TENSOR_REPLACEMENTS` graph collection is empty, all TFT analyzers
      # in the `preprocessing_fn` have already been evaluated.
      if not concrete_transform_fn.graph.get_collection(
          analyzer_nodes.TENSOR_REPLACEMENTS
      ):
          metadata = _trace_and_get_metadata(
              concrete_transform_fn,
              structured_inputs,
              preprocessing_fn,
              base_temp_dir,
              tensor_replacement_map,
          )
          metadata_io.write_metadata(
              metadata, os.path.join(saved_model_dir, METADATA_DIR_NAME)
          )
  
imports: import functools
  import os
  import re
  from typing import Callable, Dict, List, Mapping, Optional, FrozenSet
  from absl import logging
  import numpy
  import pyarrow
  import tensorflow
  from tensorflow_transform import analyzer_nodes
  from tensorflow_transform import annotators
  from tensorflow_transform import common_types
  from tensorflow_transform import graph_context
  from tensorflow_transform import graph_tools
  from tensorflow_transform import schema_inference
  from tensorflow_transform import tf2_utils
  from tensorflow_transform import tf_utils
  from tensorflow_transform.output_wrapper import TFTransformOutput
  from tensorflow_transform.saved import saved_transform_io
  from tensorflow_transform.saved import saved_transform_io_v2
  from tensorflow_transform.tf_metadata import dataset_metadata
  from tensorflow_transform.tf_metadata import metadata_io
  from tensorflow_transform.tf_metadata import schema_utils
  from tfx_bsl.coders import example_coder
  from tfx_bsl.tfxio import tensor_to_arrow
  from tensorflow.python.eager import function
  from tensorflow.python.framework import ops
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 18 for calling a global function with example usage: trace_and_write_v2_saved_model(saved_model_dir, preprocessing_fn, input_signature, base_temp_dir, baseline_analyzers_fingerprint, tensor_replacement_map, output_keys_to_name_map) without return types