code: def _filter_by_key_type(
      sliced_metrics_plots_attributions: Tuple[
          SliceKeyTypeVar, Dict[metric_types.MetricKey, Any]
      ],
      key_type: Type[
          Union[
              metric_types.MetricKey,
              metric_types.PlotKey,
              metric_types.AttributionsKey,
          ]
      ],
  ) -> Tuple[SliceKeyTypeVar, Dict[metric_types.MetricKey, Any]]:
      """Filters metrics and plots by key type."""
      (
          slice_value,
          metrics_plots_attributions,
      ) = sliced_metrics_plots_attributions
      output = {}
      for k, v in metrics_plots_attributions.items():
          # PlotKey is a subclass of MetricKey so must check key_type based on PlotKey
          if key_type == metric_types.PlotKey:
              if isinstance(k, metric_types.PlotKey):
                  output[k] = v
          # AttributionsKey is a also subclass of MetricKey
          elif key_type == metric_types.AttributionsKey:
              if isinstance(k, metric_types.AttributionsKey):
                  output[k] = v
          else:
              if not isinstance(
                  k, metric_types.PlotKey
              ) and not isinstance(k, metric_types.AttributionsKey):
                  output[k] = v
      return (slice_value, output)
  
imports: import copy
  import datetime
  import itertools
  import numbers
  from typing import Any, Dict, Iterable, Iterator, List, NamedTuple, Optional, Tuple, Type, TypeVar, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.evaluators import counter_util
  from tensorflow_model_analysis.evaluators import eval_saved_model_util
  from tensorflow_model_analysis.evaluators import evaluator
  from tensorflow_model_analysis.evaluators import jackknife
  from tensorflow_model_analysis.evaluators import keras_util
  from tensorflow_model_analysis.evaluators import metrics_validator
  from tensorflow_model_analysis.evaluators import poisson_bootstrap
  from tensorflow_model_analysis.extractors import slice_key_extractor
  from tensorflow_model_analysis.metrics import metric_specs
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.utils import model_util
  from tensorflow_model_analysis.utils import util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 9 for calling a global function with example usage: _filter_by_key_type(sliced_metrics_plots_attributions, key_type) and returns: slice_value,  output