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: Quantize the forecaster.
  
  :param calib_data: Required for static quantization. Support following formats:
  
         | 1. a numpy ndarray tuple (x, y):
         | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
         | should be the same as past_seq_len and input_feature_num.
         | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
         | should be the same as future_seq_len and output_feature_num.
         |
         | 2. pytorch dataloader:
         | the dataloader should return x, y in each iteration with the shape as following:
         | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
         | should be the same as past_seq_len and input_feature_num.
         | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
         | should be the same as future_seq_len and output_feature_num.
         |
         | 3. A bigdl.chronos.data.tsdataset.TSDataset instance:
         | Forecaster will automatically process the TSDataset.
         | By default, TSDataset will be transformed to a pytorch dataloader,
         | which is memory-friendly while a little bit slower.
         | Users may call `roll` on the TSDataset before calling `fit`
         | Then the training speed will be faster but will consume more memory.
  
  :param val_data: for evaluation. Support following formats:
  
         | 1. a numpy ndarray tuple (x, y):
         | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
         | should be the same as past_seq_len and input_feature_num.
         | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
         | should be the same as future_seq_len and output_feature_num.
         |
         | 2. pytorch dataloader:
         | the dataloader should return x, y in each iteration with the shape as following:
         | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
         | should be the same as past_seq_len and input_feature_num.
         | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
         | should be the same as future_seq_len and output_feature_num.
         |
         | 3. A bigdl.chronos.data.tsdataset.TSDataset instance:
         | Forecaster will automatically process the TSDataset.
         | By default, TSDataset will be transformed to a pytorch dataloader,
         | which is memory-friendly while a little bit slower.
         | Users may call `roll` on the TSDataset before calling `fit`
         | Then the training speed will be faster but will consume more memory.
  
  :param metric: A str represent the metrics for tunning the quality of
         quantization. You may choose from "mse", "mae", "rmse", "r2", "mape", "smape".
  :param conf: A path to conf yaml file for quantization. Default to None,
         using default config.
  :param framework: A str represent the framework for quantization. You may choose from
         "pytorch_fx", "pytorch_ipex", "onnxrt_integerops", "onnxrt_qlinearops", "openvino".
         Default: 'pytorch_fx'. Consistent with Intel Neural Compressor.
  :param approach: str, 'static' or 'dynamic'. Default to 'static'.
         OpenVINO supports static mode only, if set to 'dynamic',
         it will be replaced with 'static'.
  :param tuning_strategy: str, 'bayesian', 'basic', 'mse' or 'sigopt'. Default to 'bayesian'.
  :param relative_drop: Float, tolerable ralative accuracy drop. Default to None,
         e.g. set to 0.1 means that we accept a 10% increase in the metrics error.
  :param absolute_drop: Float, tolerable ralative accuracy drop. Default to None,
         e.g. set to 5 means that we can only accept metrics smaller than 5.
  :param timeout: Tuning timeout (seconds). Default to 0, which means early stop.
         Combine with max_trials field to decide when to exit.
  :param max_trials: Max tune times. Default to 1. Combine with timeout field to
         decide when to exit. "timeout=0, max_trials=1" means it will try quantization
         only once and return satisfying best model.
  :param sess_options: The session option for onnxruntime, only valid when
                       framework contains 'onnxrt_integerops' or 'onnxrt_qlinearops',
                       otherwise will be ignored.
  :param thread_num: int, the num of thread limit. The value is set to None by
         default where no limit is set
code: def quantize(
      self,
      calib_data=None,
      val_data=None,
      metric=None,
      conf=None,
      framework="pytorch_fx",
      approach="static",
      tuning_strategy="bayesian",
      relative_drop=None,
      absolute_drop=None,
      timeout=0,
      max_trials=1,
      sess_options=None,
      thread_num=None,
  ):
      """
      Quantize the forecaster.
  
      :param calib_data: Required for static quantization. Support following formats:
  
             | 1. a numpy ndarray tuple (x, y):
             | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
             | should be the same as past_seq_len and input_feature_num.
             | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
             | should be the same as future_seq_len and output_feature_num.
             |
             | 2. pytorch dataloader:
             | the dataloader should return x, y in each iteration with the shape as following:
             | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
             | should be the same as past_seq_len and input_feature_num.
             | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
             | should be the same as future_seq_len and output_feature_num.
             |
             | 3. A bigdl.chronos.data.tsdataset.TSDataset instance:
             | Forecaster will automatically process the TSDataset.
             | By default, TSDataset will be transformed to a pytorch dataloader,
             | which is memory-friendly while a little bit slower.
             | Users may call `roll` on the TSDataset before calling `fit`
             | Then the training speed will be faster but will consume more memory.
  
      :param val_data: for evaluation. Support following formats:
  
             | 1. a numpy ndarray tuple (x, y):
             | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
             | should be the same as past_seq_len and input_feature_num.
             | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
             | should be the same as future_seq_len and output_feature_num.
             |
             | 2. pytorch dataloader:
             | the dataloader should return x, y in each iteration with the shape as following:
             | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
             | should be the same as past_seq_len and input_feature_num.
             | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
             | should be the same as future_seq_len and output_feature_num.
             |
             | 3. A bigdl.chronos.data.tsdataset.TSDataset instance:
             | Forecaster will automatically process the TSDataset.
             | By default, TSDataset will be transformed to a pytorch dataloader,
             | which is memory-friendly while a little bit slower.
             | Users may call `roll` on the TSDataset before calling `fit`
             | Then the training speed will be faster but will consume more memory.
  
      :param metric: A str represent the metrics for tunning the quality of
             quantization. You may choose from "mse", "mae", "rmse", "r2", "mape", "smape".
      :param conf: A path to conf yaml file for quantization. Default to None,
             using default config.
      :param framework: A str represent the framework for quantization. You may choose from
             "pytorch_fx", "pytorch_ipex", "onnxrt_integerops", "onnxrt_qlinearops", "openvino".
             Default: 'pytorch_fx'. Consistent with Intel Neural Compressor.
      :param approach: str, 'static' or 'dynamic'. Default to 'static'.
             OpenVINO supports static mode only, if set to 'dynamic',
             it will be replaced with 'static'.
      :param tuning_strategy: str, 'bayesian', 'basic', 'mse' or 'sigopt'. Default to 'bayesian'.
      :param relative_drop: Float, tolerable ralative accuracy drop. Default to None,
             e.g. set to 0.1 means that we accept a 10% increase in the metrics error.
      :param absolute_drop: Float, tolerable ralative accuracy drop. Default to None,
             e.g. set to 5 means that we can only accept metrics smaller than 5.
      :param timeout: Tuning timeout (seconds). Default to 0, which means early stop.
             Combine with max_trials field to decide when to exit.
      :param max_trials: Max tune times. Default to 1. Combine with timeout field to
             decide when to exit. "timeout=0, max_trials=1" means it will try quantization
             only once and return satisfying best model.
      :param sess_options: The session option for onnxruntime, only valid when
                           framework contains 'onnxrt_integerops' or 'onnxrt_qlinearops',
                           otherwise will be ignored.
      :param thread_num: int, the num of thread limit. The value is set to None by
             default where no limit is set
      """
      # check model support for quantization
      from bigdl.chronos.pytorch import (
          TSInferenceOptimizer as InferenceOptimizer,
      )
  
      if not self.quantize_available:
          invalidInputError(
              False, "This model has not supported quantization."
          )
  
      # Distributed forecaster does not support quantization
      if self.distributed:
          invalidInputError(
              False,
              "quantization has not been supported for distributed "
              "forecaster. You can call .to_local() to transform the "
              "forecaster to a non-distributed version.",
          )
  
      # calib data should be set correctly according to the approach
      if approach == "static" and calib_data is None:
          invalidInputError(
              False,
              "You must set a `calib_data` for static quantization.",
          )
      if approach == "dynamic" and calib_data is not None:
          invalidInputError(
              False,
              "You must not set a `calib_data` for dynamic quantization.",
          )
  
      # change tsdataset to dataloader
      if isinstance(calib_data, TSDataset):
          _rolled = calib_data.numpy_x is None
          calib_data = calib_data.to_torch_data_loader(
              batch_size=1,
              roll=_rolled,
              lookback=self.data_config["past_seq_len"],
              horizon=self.data_config["future_seq_len"],
              feature_col=calib_data.roll_feature,
              target_col=calib_data.roll_target,
              shuffle=False,
          )
      if isinstance(val_data, TSDataset):
          _rolled = val_data.numpy_x is None
          val_data = val_data.to_torch_data_loader(
              batch_size=1,
              roll=_rolled,
              lookback=self.data_config["past_seq_len"],
              horizon=self.data_config["future_seq_len"],
              feature_col=val_data.roll_feature,
              target_col=val_data.roll_target,
              shuffle=False,
          )
  
      # change data tuple to dataloader
      if isinstance(calib_data, tuple):
          calib_data = DataLoader(
              TensorDataset(
                  torch.from_numpy(calib_data[0]),
                  torch.from_numpy(calib_data[1]),
              )
          )
      if isinstance(val_data, tuple):
          val_data = DataLoader(
              TensorDataset(
                  torch.from_numpy(val_data[0]),
                  torch.from_numpy(val_data[1]),
              )
          )
  
      try:
          metric = _str2optimizer_metric(metric)
      except Exception:
          invalidInputError(
              False,
              "Unable to recognize the metric string you passed in.",
          )
  
      # init acc criterion
      accuracy_criterion = None
      if relative_drop and absolute_drop:
          invalidInputError(
              False,
              "Please unset either `relative_drop` or `absolute_drop`.",
          )
      if relative_drop:
          accuracy_criterion = {
              "relative": relative_drop,
              "higher_is_better": False,
          }
      if absolute_drop:
          accuracy_criterion = {
              "absolute": absolute_drop,
              "higher_is_better": False,
          }
  
      # quantize
      if "_" in framework:
          accelerator, method = framework.split("_")
      else:
          accelerator = framework
      if accelerator == "pytorch":
          accelerator = None
      elif accelerator == "openvino":
          method = None
          approach = "static"
      else:
          accelerator = "onnxruntime"
          method = method[:-3]
      q_model = InferenceOptimizer.quantize(
          self.internal,
          precision="int8",
          accelerator=accelerator,
          method=method,
          calib_data=calib_data,
          metric=metric,
          conf=conf,
          approach=approach,
          tuning_strategy=tuning_strategy,
          accuracy_criterion=accuracy_criterion,
          timeout=timeout,
          max_trials=max_trials,
          onnxruntime_session_options=sess_options,
          thread_num=thread_num,
          output_tensors=False,
      )
      if accelerator == "onnxruntime":
          self.accelerated_model = q_model
          self.optimized_model_output_tensor = False
          self.accelerate_method = "onnxruntime_int8"
      if accelerator == "openvino":
          self.accelerated_model = q_model
          self.optimized_model_output_tensor = False
          self.accelerate_method = "openvino_int8"
      if accelerator is None:
          self.accelerated_model = q_model
          self.accelerate_method = "pytorch_int8"
      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 25 for calling the BasePytorchForecaster obj's underlying member method code with example usage: obj.quantize(calib_data, val_data, metric, conf, framework, approach, tuning_strategy, relative_drop, absolute_drop, timeout, max_trials, sess_options, thread_num) without return types