class_docstr: Forecaster base model for lstm, seq2seq, tcn and nbeats forecasters.
class_docstr_tok: ["Forecaster","base","model","for","lstm",",","seq2seq",",","tcn","and","nbeats","forecasters","."]
docstr: Build onnx model to speed up inference and reduce latency.
  The method is Not required to call before predict_with_onnx,
  evaluate_with_onnx or export_onnx_file.
  It is recommended to use when you want to:
  
  | 1. Strictly control the thread to be used during inferencing.
  | 2. Alleviate the cold start problem when you call predict_with_onnx
       for the first time.
  
  :param thread_num: int, the num of thread limit. The value is set to None by
         default where no limit is set. Besides, the environment variable
         `OMP_NUM_THREADS` is suggested to be same as `thread_num`.
  :param sess_options: an onnxruntime.SessionOptions instance, if you set this
         other than None, a new onnxruntime session will be built on this setting
         and ignore other settings you assigned(e.g. thread_num...).
  
  Example:
      >>> # to pre build onnx sess
      >>> forecaster.build_onnx(thread_num=2)  # build onnx runtime sess for two threads
      >>> pred = forecaster.predict_with_onnx(data)
      >>> # ------------------------------------------------------
      >>> # directly call onnx related method is also supported
      >>> # default to build onnx runtime sess for single thread
      >>> pred = forecaster.predict_with_onnx(data)
code: def build_onnx(self, thread_num=1, sess_options=None):
      """
      Build onnx model to speed up inference and reduce latency.
      The method is Not required to call before predict_with_onnx,
      evaluate_with_onnx or export_onnx_file.
      It is recommended to use when you want to:
  
      | 1. Strictly control the thread to be used during inferencing.
      | 2. Alleviate the cold start problem when you call predict_with_onnx
           for the first time.
  
      :param thread_num: int, the num of thread limit. The value is set to None by
             default where no limit is set. Besides, the environment variable
             `OMP_NUM_THREADS` is suggested to be same as `thread_num`.
      :param sess_options: an onnxruntime.SessionOptions instance, if you set this
             other than None, a new onnxruntime session will be built on this setting
             and ignore other settings you assigned(e.g. thread_num...).
  
      Example:
          >>> # to pre build onnx sess
          >>> forecaster.build_onnx(thread_num=2)  # build onnx runtime sess for two threads
          >>> pred = forecaster.predict_with_onnx(data)
          >>> # ------------------------------------------------------
          >>> # directly call onnx related method is also supported
          >>> # default to build onnx runtime sess for single thread
          >>> pred = forecaster.predict_with_onnx(data)
      """
      import onnxruntime
      from bigdl.chronos.pytorch import (
          TSInferenceOptimizer as InferenceOptimizer,
      )
  
      if sess_options is not None and not isinstance(
          sess_options, onnxruntime.SessionOptions
      ):
          invalidInputError(
              False,
              "sess_options should be an onnxruntime.SessionOptions instance"
              f", but found {type(sess_options)}",
          )
      if sess_options is None:
          sess_options = onnxruntime.SessionOptions()
          if thread_num is not None:
              sess_options.intra_op_num_threads = thread_num
              sess_options.inter_op_num_threads = thread_num
      if self.distributed:
          invalidInputError(
              False,
              "build_onnx has not been supported for distributed "
              "forecaster. You can call .to_local() to transform the "
              "forecaster to a non-distributed version.",
          )
      try:
          OMP_NUM_THREADS = os.getenv("OMP_NUM_THREADS")
      except KeyError:
          OMP_NUM_THREADS = 0
      if OMP_NUM_THREADS != str(thread_num):
          warnings.warn(
              "The environment variable OMP_NUM_THREADS is suggested to be same "
              f"as thread_num.You can use 'export OMP_NUM_THREADS={thread_num}'."
          )
      dummy_input = torch.rand(
          1,
          self.data_config["past_seq_len"],
          self.data_config["input_feature_num"],
      )
      self.accelerated_model = InferenceOptimizer.trace(
          self.internal,
          input_sample=dummy_input,
          accelerator="onnxruntime",
          onnxruntime_session_options=sess_options,
          output_tensors=False,
      )
      self.optimized_model_output_tensor = False
      self.accelerate_method = "onnxruntime_fp32"
      self.optimized_model_thread_num = thread_num
  
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 19 for calling the BasePytorchForecaster obj's underlying member method code with example usage: obj.build_onnx(thread_num, sess_options) without return types