code: def _metric_keys_and_configs(
      metrics: Dict[str, List[_TFMetricOrLoss]],
      model_name: str,
      sub_key: Optional[metric_types.SubKey],
      aggregation_type: Optional[metric_types.AggregationType],
      example_weighted: bool,
  ) -> Tuple[_KeysBySubKey, _ConfigsBySubKey, _ConfigsBySubKey]:
      """Returns metric keys, metric configs, and loss configs by sub key."""
      metric_keys = collections.defaultdict(list)
      metric_configs = collections.defaultdict(dict)
      loss_configs = collections.defaultdict(dict)
      for output_name, metrics_list in metrics.items():
          for metric in metrics_list:
              updated_sub_key = _verify_and_update_sub_key(
                  model_name, output_name, sub_key, metric
              )
              if output_name not in metric_configs[updated_sub_key]:
                  metric_configs[updated_sub_key][output_name] = []
              if output_name not in loss_configs[updated_sub_key]:
                  loss_configs[updated_sub_key][output_name] = []
              metric_keys[updated_sub_key].append(
                  metric_types.MetricKey(
                      name=metric.name,
                      model_name=model_name,
                      output_name=output_name,
                      sub_key=updated_sub_key,
                      aggregation_type=aggregation_type,
                      example_weighted=example_weighted,
                  )
              )
              if isinstance(metric, tf.keras.metrics.Metric):
                  metric_configs[updated_sub_key][output_name].append(
                      metric_util.serialize_metric(
                          metric, use_legacy_format=True
                      )
                  )
              elif isinstance(metric, tf.keras.losses.Loss):
                  loss_configs[updated_sub_key][output_name].append(
                      metric_util.serialize_loss(
                          metric, use_legacy_format=True
                      )
                  )
      return metric_keys, metric_configs, loss_configs
  
imports: import collections
  import importlib
  import itertools
  from typing import Any, Dict, Iterable, List, Optional, Type, Tuple, Union
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.metrics import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.metrics import tf_metric_accumulators
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import model_util
label_desc: Use image node_id 6 for calling a global function with example usage: _metric_keys_and_configs(metrics, model_name, sub_key, aggregation_type, example_weighted) and returns: metric_keys,  metric_configs,  loss_configs