code: def _generate_state_metrics(
      metrics_config: MetricsConfig,
      state_metrics_mapping: Dict[StateMetricEnum, StateMetric],
  ) -> Dict[str, StateMetric]:
      state_metrics: Dict[str, StateMetric] = {}
      for metric_enum in metrics_config.state_metrics:
          metric_namespace: Optional[
              MetricNamespace
          ] = STATE_METRICS_NAMESPACE_MAPPING.get(metric_enum, None)
          if metric_namespace is None:
              raise ValueError(f"Unknown StateMetrics {metric_enum}")
          full_namespace = compose_metric_namespace(
              metric_namespace, str(metric_namespace)
          )
          state_metrics[full_namespace] = state_metrics_mapping[
              metric_enum
          ]
      return state_metrics
  
imports: import abc
  import logging
  import time
  from typing import Any, Dict, List, Optional, Type, Union
  import torch
  import torch.distributed
  import torch.nn
  from torch.profiler import record_function
  from torchrec.metrics.accuracy import AccuracyMetric
  from torchrec.metrics.auc import AUCMetric
  from torchrec.metrics.auprc import AUPRCMetric
  from torchrec.metrics.calibration import CalibrationMetric
  from torchrec.metrics.ctr import CTRMetric
  from torchrec.metrics.mae import MAEMetric
  from torchrec.metrics.metrics_config import MetricsConfig, RecMetricEnum, RecMetricEnumBase, RecTaskInfo, StateMetricEnum
  from torchrec.metrics.metrics_namespace import compose_customized_metric_key, compose_metric_namespace, MetricNamespace
  from torchrec.metrics.model_utils import parse_task_model_outputs
  from torchrec.metrics.mse import MSEMetric
  from torchrec.metrics.multiclass_recall import MulticlassRecallMetric
  from torchrec.metrics.ndcg import NDCGMetric
  from torchrec.metrics.ne import NEMetric
  from torchrec.metrics.rec_metric import RecMetric, RecMetricList
  from torchrec.metrics.recall_session import RecallSessionMetric
  from torchrec.metrics.segmented_ne import SegmentedNEMetric
  from torchrec.metrics.throughput import ThroughputMetric
  from torchrec.metrics.tower_qps import TowerQPSMetric
  from torchrec.metrics.weighted_avg import WeightedAvgMetric
label_desc: Use image node_id 2 for calling a global function with example usage: _generate_state_metrics(metrics_config, state_metrics_mapping) and returns: state_metrics