code: def _perform_cache_optimization(
      saved_model_future: nodes.ValueNode,
      dataset_keys: Collection[analyzer_cache.DatasetKey],
      tensor_keys_to_paths: Dict[str, str],
      cache_dict: Optional[analyzer_cache.BeamAnalysisCache],
      num_phases: int,
  ) -> Tuple[
      Tuple[nodes.ValueNode],
      Optional[_IntermediateCacheType],
      Collection[nodes.ValueNode],
  ]:
      """Performs cache optimization on the given graph."""
      cache_output_nodes = {}
      optimize_visitor = _OptimizeVisitor(
          dataset_keys or {},
          cache_dict,
          tensor_keys_to_paths,
          cache_output_nodes,
          num_phases,
      )
      optimize_traverser = nodes.Traverser(optimize_visitor)
      optimized = optimize_traverser.visit_value_node(
          saved_model_future
      ).flattened_view
  
      if cache_dict is None:
          assert not cache_output_nodes
          cache_output_nodes = None
  
      return (
          optimized,
          cache_output_nodes,
          optimize_visitor.get_detached_sideeffect_leafs(),
      )
  
imports: import collections
  import dataclasses
  import hashlib
  from typing import Collection, Dict, Mapping, Optional, Tuple
  from typing import OrderedDict
  import tensorflow
  from tensorflow_transform import analyzer_nodes
  from tensorflow_transform import common_types
  from tensorflow_transform import graph_tools
  from tensorflow_transform import impl_helper
  from tensorflow_transform import nodes
  from tensorflow_transform import tf2_utils
  from tensorflow_transform import tf_utils
  from tensorflow_transform.beam import analyzer_cache
  from tensorflow_transform.beam import beam_nodes
  from tensorflow_transform.beam import combiner_packing_util
label_desc: Use image node_id 2 for calling a global function with example usage: _perform_cache_optimization(saved_model_future, dataset_keys, tensor_keys_to_paths, cache_dict, num_phases) and returns: optimized,  cache_output_nodes,  optimize_visitor