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: Save the torchscript model file and the whole forecasting pipeline to the disk.
  
  When the whole forecasting pipeline is saved, it can be used without Python environment.
  For example, when you finish developing a forecaster, you could call this method with
  "save_pipeline=True" to save the whole pipeline (data preprocessing, inference, data
  postprocessing) to torchscript (the forecaster will be saved as torchscript model too),
  then you could deploy the pipeline in C++ using libtorch APIs.
  
  Currently the pipeline is similar to the following code:
  
  >>> # preprocess
  >>> tsdata.scale(scaler, fit=False) \
  >>>       .roll(lookback, horizon, is_predict=True)
  >>> preprocess_output = tsdata.to_numpy()
  >>> # inference using trained forecaster
  >>> # forecaster_module is the saved torchscript model
  >>> inference_output = forecaster_module.forward(preprocess_output)
  >>> # postprocess
  >>> postprocess_output = tsdata.unscale_numpy(inference_output)
  
  When deploying, the pipeline can be used by:
  
  >>> // deployment in C++
  >>> #include <torch/torch.h>
  >>> #include <torch/script.h>
  >>> // create input tensor from your data
  >>> // The data to create the input tensor should have the same format as the
  >>> // data used in developing
  >>> torch::Tensor input = create_input_tensor(data);
  >>> // load the pipeline
  >>> torch::jit::script::Module forecasting_pipeline;
  >>> forecasting_pipeline = torch::jit::load(path);
  >>> // run pipeline
  >>> torch::Tensor output = forecasting_pipeline.forward(input_tensor).toTensor();
  
  The limitations of exporting the forecasting pipeline is same as limitations in
  TSDataset.export_jit():
      1. Please make sure the value of each column can be converted to Pytorch tensor,
         for example, id "00" is not allowed because str can not be converted to a tensor,
         you should use integer (0, 1, ..) as id instead of string.
      2. Some features in tsdataset.scale and tsdataset.roll are unavailable in this
         pipeline:
              a. If self.roll_additional_feature is not None, it can't be processed in scale
                 and roll
              b. id_sensitive, time_enc and label_len parameter is not supported in roll
      3. Users are expected to call .scale(scaler, fit=True) before calling export_jit.
         Single roll operation is not supported for converting now.
  
  :param dirname: The dir location you want to save the torchscript file.
  :param quantized_dirname: The dir location you want to save the quantized torchscript model.
  :param save_pipeline: Whether to save the whole forecasting pipeline, defaluts to False.
         If set to True, the whole forecasting pipeline will be saved in
         "dirname/chronos_forecasting_pipeline.pt", if set to False, only the torchscript
         model will be saved.
  :param tsdata: The TSDataset instance used when developing the forecaster. The parameter
         should be used only when save_pipeline is True.
  :param drop_dt_col: Whether to delete the datetime column, defaults to True. The parameter
         is valid only when save_pipeline is True.
         Since datetime value (like "2022-12-12") can't be converted to Pytorch tensor, you
         can choose different ways to workaround this. If set to True, the datetime column
         will be deleted, then you also need to skip the datetime column when reading data
         from data source (like csv files) in deployment environment to keep the same
         structure as the data used in development; if set to False, the datetime column will
         not be deleted, and you need to make sure the datetime colunm can be successfully
         converted to Pytorch tensor when reading data in deployment environment. For
         example, you can set each data in datetime column to an int (or other vaild types)
         value, since datetime column is not necessary in preprocessing and postprocessing,
         the value can be arbitrary.
code: def export_torchscript_file(
      self,
      dirname="fp32_torchscript",
      quantized_dirname=None,
      save_pipeline=False,
      tsdata=None,
      drop_dt_col=True,
  ):
      """
          Save the torchscript model file and the whole forecasting pipeline to the disk.
  
          When the whole forecasting pipeline is saved, it can be used without Python environment.
          For example, when you finish developing a forecaster, you could call this method with
          "save_pipeline=True" to save the whole pipeline (data preprocessing, inference, data
          postprocessing) to torchscript (the forecaster will be saved as torchscript model too),
          then you could deploy the pipeline in C++ using libtorch APIs.
  
          Currently the pipeline is similar to the following code:
  
          >>> # preprocess
          >>> tsdata.scale(scaler, fit=False) \\
          >>>       .roll(lookback, horizon, is_predict=True)
          >>> preprocess_output = tsdata.to_numpy()
          >>> # inference using trained forecaster
          >>> # forecaster_module is the saved torchscript model
          >>> inference_output = forecaster_module.forward(preprocess_output)
          >>> # postprocess
          >>> postprocess_output = tsdata.unscale_numpy(inference_output)
  
          When deploying, the pipeline can be used by:
  
          >>> // deployment in C++
          >>> #include <torch/torch.h>
          >>> #include <torch/script.h>
          >>> // create input tensor from your data
          >>> // The data to create the input tensor should have the same format as the
          >>> // data used in developing
          >>> torch::Tensor input = create_input_tensor(data);
          >>> // load the pipeline
          >>> torch::jit::script::Module forecasting_pipeline;
          >>> forecasting_pipeline = torch::jit::load(path);
          >>> // run pipeline
          >>> torch::Tensor output = forecasting_pipeline.forward(input_tensor).toTensor();
  
          The limitations of exporting the forecasting pipeline is same as limitations in
          TSDataset.export_jit():
              1. Please make sure the value of each column can be converted to Pytorch tensor,
                 for example, id "00" is not allowed because str can not be converted to a tensor,
                 you should use integer (0, 1, ..) as id instead of string.
              2. Some features in tsdataset.scale and tsdataset.roll are unavailable in this
                 pipeline:
                      a. If self.roll_additional_feature is not None, it can't be processed in scale
                         and roll
                      b. id_sensitive, time_enc and label_len parameter is not supported in roll
              3. Users are expected to call .scale(scaler, fit=True) before calling export_jit.
                 Single roll operation is not supported for converting now.
  
          :param dirname: The dir location you want to save the torchscript file.
          :param quantized_dirname: The dir location you want to save the quantized torchscript model.
          :param save_pipeline: Whether to save the whole forecasting pipeline, defaluts to False.
                 If set to True, the whole forecasting pipeline will be saved in
                 "dirname/chronos_forecasting_pipeline.pt", if set to False, only the torchscript
                 model will be saved.
          :param tsdata: The TSDataset instance used when developing the forecaster. The parameter
                 should be used only when save_pipeline is True.
          :param drop_dt_col: Whether to delete the datetime column, defaults to True. The parameter
                 is valid only when save_pipeline is True.
                 Since datetime value (like "2022-12-12") can't be converted to Pytorch tensor, you
                 can choose different ways to workaround this. If set to True, the datetime column
                 will be deleted, then you also need to skip the datetime column when reading data
                 from data source (like csv files) in deployment environment to keep the same
                 structure as the data used in development; if set to False, the datetime column will
                 not be deleted, and you need to make sure the datetime colunm can be successfully
                 converted to Pytorch tensor when reading data in deployment environment. For
                 example, you can set each data in datetime column to an int (or other vaild types)
                 value, since datetime column is not necessary in preprocessing and postprocessing,
                 the value can be arbitrary.
          """
      from bigdl.nano.pytorch import InferenceOptimizer
      from pathlib import Path
  
      if self.distributed:
          invalidInputError(
              False,
              "export_torchscript_file has not been supported for distributed "
              "forecaster. You can call .to_local() to transform the "
              "forecaster to a non-distributed version.",
          )
      if quantized_dirname:
          if self.accelerate_method == "jit_int8":
              InferenceOptimizer.save(
                  self.accelerated_model, quantized_dirname
              )
          else:
              warnings.warn(
                  "Please call .quantize() method to build "
                  "an up-to-date quantized model"
              )
      if dirname:
          if self.accelerate_method != "jit_fp32":
              self.build_jit()
          InferenceOptimizer.save(self.accelerated_model, dirname)
  
          if save_pipeline:
              forecaster_path = Path(dirname) / "ckpt.pth"
              exproted_module = get_exported_module(
                  tsdata, forecaster_path, drop_dt_col
              )
              saved_path = (
                  Path(dirname) / "chronos_forecasting_pipeline.pt"
              )
              torch.jit.save(exproted_module, saved_path)
  
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 24 for calling the BasePytorchForecaster obj's underlying member method code with example usage: obj.export_torchscript_file(dirname, quantized_dirname, save_pipeline, tsdata, drop_dt_col) without return types