code: def _str2optimizer_metric(metric):
      # map metric str to function for InferenceOptimizer
      if isinstance(metric, str):
          metric_name = metric
          from bigdl.chronos.metric.forecast_metrics import (
              REGRESSION_MAP,
          )
  
          metric_func = REGRESSION_MAP[metric_name]
  
          def metric(pred, target):
              if isinstance(pred, torch.Tensor):
                  pred = pred.numpy()
              if isinstance(target, torch.Tensor):
                  target = target.numpy()
              return metric_func(target, pred)
  
          metric.__name__ = metric_name
      return metric
  
imports: from bigdl.chronos.forecaster.abstract import Forecaster
  from bigdl.chronos.forecaster.utils import *
  from bigdl.chronos.metric.forecast_metrics import Evaluator
  from typing import Optional
  import numpy
  import warnings
  import os
  from tempfile import TemporaryDirectory
  import torch
  from torch.utils.data import TensorDataset, DataLoader
  from .utils_hpo import GenericLightningModule, _format_metric_str, _config_has_search_space
  from bigdl.nano.utils.common import invalidOperationError, invalidInputError
  from bigdl.chronos.data.tsdataset import TSDataset
  from bigdl.chronos.pytorch.context_manager import DummyForecasterContextManager, ForecasterContextManager
  from bigdl.chronos.pytorch.utils import _pytorch_fashion_inference
label_desc: Use image node_id 1 for calling a global function with example usage: _str2optimizer_metric(metric) and returns: metric, metric_func