code: def config_from_metric(
      metric: _TFOrTFMAMetricOrLoss,
  ) -> config_pb2.MetricConfig:
      """Returns MetricConfig associated with given metric instance."""
      if isinstance(metric, tf.keras.metrics.Metric):
          if _is_supported_tf_metric(metric):
              return _remove_unsupported_tf_settings(
                  _serialize_tf_metric(metric)
              )
          else:
              return _serialize_tf_metric(metric)
      elif isinstance(metric, tf.keras.losses.Loss):
          # For loss like MeanAbsoluteError, TFMA provides native support.
          # The support should be checked here.
          if _is_supported_tf_metric(metric):
              return _remove_unsupported_tf_settings(
                  _serialize_tf_metric(metric)
              )
          else:
              return _serialize_tf_loss(metric)
      elif isinstance(metric, metric_types.Metric):
          return _serialize_tfma_metric(metric)
      else:
          raise NotImplementedError(
              "unknown metric type {}: metric={}".format(
                  type(metric), metric
              )
          )
  
imports: import collections
  import importlib
  import json
  import re
  from typing import Any, Dict, FrozenSet, Iterable, Iterator, List, NamedTuple, Optional, Tuple, Type, Union
  import tensorflow
  from tensorflow_model_analysis.metrics import aggregation
  from tensorflow_model_analysis.metrics import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import calibration
  from tensorflow_model_analysis.metrics import calibration_plot
  from tensorflow_model_analysis.metrics import confusion_matrix_metrics
  from tensorflow_model_analysis.metrics import confusion_matrix_plot
  from tensorflow_model_analysis.metrics import example_count
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.metrics import multi_class_confusion_matrix_plot
  from tensorflow_model_analysis.metrics import tf_metric_wrapper
  from tensorflow_model_analysis.metrics import weighted_example_count
  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_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: config_from_metric(metric) and returns: _remove_unsupported_tf_settings, _serialize_tf_metric, _remove_unsupported_tf_settings, _serialize_tf_loss, _serialize_tfma_metric