docstr: Search the hyper parameter.
  
  :param data: The data support following formats:
  
         | 1. numpy ndarrays: generate from `TSDataset.roll`,
              be sure to set label_len > 0 and time_enc = True
  
  :param validation_data: validation data, The data support following formats:
  
         | 1. numpy ndarrays: generate from `TSDataset.roll`,
              be sure to set label_len > 0 and time_enc = True
  
  :param target_metric: the target metric to optimize,
         a string or an instance of torchmetrics.metric.Metric, default to 'mse'.
  :param direction: in which direction to optimize the target metric,
         "maximize" - larger the better
         "minimize" - smaller the better
         default to "minimize".
  :param n_trials: number of trials to run
  :param n_parallels: number of parallel processes used to run trials.
         to use parallel tuning you need to use a RDB url for storage and specify study_name.
         For more information, refer to Nano AutoML user guide.
  :param epochs: the number of epochs to run in each trial fit, defaults to 1
  :param batch_size: number of batch size for each trial fit, defaults to 32
  :param acceleration: Whether to automatically consider the model after
      inference acceleration in the search process. It will only take
      effect if target_metric contains "latency". Default value is False.
  :param input_sample: A set of inputs for trace, defaults to None if you have
      trace before or model is a LightningModule with any dataloader attached.
docstr_tok: ["Search","the","hyper","parameter",".",":","param","data",":","The","data","support","following","formats",":","|","1.","numpy","ndarrays",":","generate","from","`","TSDataset.roll","`",",","be","sure","to","set","label_len",">","0","and","time_enc","=","True",":","param","validation_data",":","validation","data",",","The","data","support","following","formats",":","|","1.","numpy","ndarrays",":","generate","from","`","TSDataset.roll","`",",","be","sure","to","set","label_len",">","0","and","time_enc","=","True",":","param","target_metric",":","the","target","metric","to","optimize",",","a","string","or","an","instance","of","torchmetrics.metric.Metric",",","default","to","'mse","'",".",":","param","direction",":","in","which","direction","to","optimize","the","target","metric",",","``","maximize","''","-","larger","the","better","``","minimize","''","-","smaller","the","better","default","to","``","minimize","''",".",":","param","n_trials",":","number","of","trials","to","run",":","param","n_parallels",":","number","of","parallel","processes","used","to","run","trials",".","to","use","parallel","tuning","you","need","to","use","a","RDB","url","for","storage","and","specify","study_name",".","For","more","information",",","refer","to","Nano","AutoML","user","guide",".",":","param","epochs",":","the","number","of","epochs","to","run","in","each","trial","fit",",","defaults","to","1",":","param","batch_size",":","number","of","batch","size","for","each","trial","fit",",","defaults","to","32",":","param","acceleration",":","Whether","to","automatically","consider","the","model","after","inference","acceleration","in","the","search","process",".","It","will","only","take","effect","if","target_metric","contains","``","latency","''",".","Default","value","is","False",".",":","param","input_sample",":","A","set","of","inputs","for","trace",",","defaults","to","None","if","you","have","trace","before","or","model","is","a","LightningModule","with","any","dataloader","attached","."]
code: def tune(
      self,
      data,
      validation_data,
      target_metric="mse",
      direction="minimize",
      directions=None,
      n_trials=2,
      n_parallels=1,
      epochs=1,
      batch_size=32,
      acceleration=False,
      input_sample=None,
      **kwargs,
  ):
      """
      Search the hyper parameter.
  
      :param data: The data support following formats:
  
             | 1. numpy ndarrays: generate from `TSDataset.roll`,
                  be sure to set label_len > 0 and time_enc = True
  
      :param validation_data: validation data, The data support following formats:
  
             | 1. numpy ndarrays: generate from `TSDataset.roll`,
                  be sure to set label_len > 0 and time_enc = True
  
      :param target_metric: the target metric to optimize,
             a string or an instance of torchmetrics.metric.Metric, default to 'mse'.
      :param direction: in which direction to optimize the target metric,
             "maximize" - larger the better
             "minimize" - smaller the better
             default to "minimize".
      :param n_trials: number of trials to run
      :param n_parallels: number of parallel processes used to run trials.
             to use parallel tuning you need to use a RDB url for storage and specify study_name.
             For more information, refer to Nano AutoML user guide.
      :param epochs: the number of epochs to run in each trial fit, defaults to 1
      :param batch_size: number of batch size for each trial fit, defaults to 32
      :param acceleration: Whether to automatically consider the model after
          inference acceleration in the search process. It will only take
          effect if target_metric contains "latency". Default value is False.
      :param input_sample: A set of inputs for trace, defaults to None if you have
          trace before or model is a LightningModule with any dataloader attached.
      """
      invalidInputError(
          not self.distributed,
          "HPO is not supported in distributed mode."
          "Please use AutoTS instead.",
      )
      invalidOperationError(
          self.use_hpo,
          "HPO is disabled for this forecaster."
          "You may specify search space in hyper parameters to enable it.",
      )
      # prepare data
      from bigdl.chronos.pytorch import TSTrainer as Trainer
  
      # data transformation
      if isinstance(data, tuple):
          check_transformer_data(
              data[0], data[1], data[2], data[3], self.data_config
          )
          if validation_data and isinstance(validation_data, tuple):
              check_transformer_data(
                  validation_data[0],
                  validation_data[1],
                  validation_data[2],
                  validation_data[3],
                  self.data_config,
              )
          else:
              invalidInputError(
                  False,
                  "To use tuning, you must provide validation_data"
                  "as numpy arrays.",
              )
      else:
          invalidInputError(
              False, "HPO only supports numpy train input data."
          )
  
      if input_sample is None:
          input_sample = (
              torch.from_numpy(data[0][:1, :, :]),
              torch.from_numpy(data[1][:1, :, :]),
              torch.from_numpy(data[2][:1, :, :]),
              torch.from_numpy(data[3][:1, :, :]),
          )
  
      # prepare target metric
      if validation_data is not None:
          formated_target_metric = _format_metric_str(
              "val", target_metric
          )
      else:
          invalidInputError(
              False,
              "To use tuning, you must provide validation_data"
              "as numpy arrays.",
          )
  
      # build auto model
      self.tune_internal = self._build_automodel(
          data, validation_data, batch_size, epochs
      )
  
      self.trainer = Trainer(
          logger=False,
          max_epochs=epochs,
          checkpoint_callback=self.checkpoint_callback,
          num_processes=self.num_processes,
          use_ipex=self.use_ipex,
          use_hpo=True,
      )
  
      # run hyper parameter search
      self.internal = self.trainer.search(
          self.tune_internal,
          n_trials=n_trials,
          target_metric=formated_target_metric,
          direction=direction,
          directions=directions,
          n_parallels=n_parallels,
          acceleration=acceleration,
          input_sample=input_sample,
          **kwargs,
      )
  
      if self.trainer.hposearcher.objective.mo_hpo:
          return self.internal
  
imports: import torch
  import numpy
  from pandas import Timedelta
  from bigdl.chronos.forecaster.abstract import Forecaster
  from bigdl.chronos.forecaster.utils import read_csv, delete_folder
  from bigdl.chronos.metric.forecast_metrics import Evaluator
  from bigdl.chronos.model.autoformer import model_creator, loss_creator
  from torch.utils.data import TensorDataset, DataLoader
  from bigdl.chronos.model.autoformer.Autoformer import AutoFormer, _transform_config_to_namedtuple
  from bigdl.nano.utils.common import invalidInputError, invalidOperationError
  from bigdl.chronos.forecaster.utils import check_transformer_data
  from bigdl.chronos.pytorch import TSTrainer
  from bigdl.chronos.data import TSDataset
  from bigdl.nano.automl.hpo.space import Space
  from bigdl.chronos.forecaster.utils_hpo import GenericTSTransformerLightningModule, _config_has_search_space
  from bigdl.chronos.pytorch.context_manager import DummyForecasterContextManager, ForecasterContextManager
  from .utils_hpo import _format_metric_str
  import warnings
  from tempfile import TemporaryDirectory
  import os
label_desc: Use image node_id 3 for calling the AutoformerForecaster obj's underlying member method code with example usage: obj.tune(data, validation_data, target_metric, direction, directions, n_trials, n_parallels, epochs, batch_size, acceleration, input_sample) and returns: self