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: Predict using a trained forecaster.
  
  if you want to predict on a single node(which is common practice), please call
  .to_local().predict(x, ...)
  
  :param data: The data support following formats:
  
         | 1. a numpy ndarray x:
         | 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.
         |
         | 2. a xshard item:
         | each partition can be a dictionary of {'x': x}, where x's shape
         | should follow the shape stated before.
         |
         | 3. pytorch dataloader:
         | the dataloader needs to return at least x 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.
         | If returns x and y only get x.
         |
         | 4. 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 memory.
  
  :param batch_size: predict batch size. The value will not affect predict
         result but will affect resources cost(e.g. memory and time).
  :param quantize: if use the quantized model to predict.
  :param acceleration: bool variable indicates whether use original model.
         Default to True means use accelerated_model to predict, which requires
         to call one of .build_jit(), .build_onnx(), .build_openvino() and
         .optimize(), otherwise the original model will be used to predict.
  
  :return: A numpy array with shape (num_samples, horizon, target_dim)
           if data is a numpy ndarray or a dataloader.
           A xshard item with format {'prediction': result},
           where result is a numpy array with shape (num_samples, horizon, target_dim)
           if data is a xshard item.
code: def predict(
      self,
      data,
      batch_size=32,
      quantize=False,
      acceleration: bool = True,
  ):
      """
      Predict using a trained forecaster.
  
      if you want to predict on a single node(which is common practice), please call
      .to_local().predict(x, ...)
  
      :param data: The data support following formats:
  
             | 1. a numpy ndarray x:
             | 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.
             |
             | 2. a xshard item:
             | each partition can be a dictionary of {'x': x}, where x's shape
             | should follow the shape stated before.
             |
             | 3. pytorch dataloader:
             | the dataloader needs to return at least x 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.
             | If returns x and y only get x.
             |
             | 4. 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 memory.
  
      :param batch_size: predict batch size. The value will not affect predict
             result but will affect resources cost(e.g. memory and time).
      :param quantize: if use the quantized model to predict.
      :param acceleration: bool variable indicates whether use original model.
             Default to True means use accelerated_model to predict, which requires
             to call one of .build_jit(), .build_onnx(), .build_openvino() and
             .optimize(), otherwise the original model will be used to predict.
  
      :return: A numpy array with shape (num_samples, horizon, target_dim)
               if data is a numpy ndarray or a dataloader.
               A xshard item with format {'prediction': result},
               where result is a numpy array with shape (num_samples, horizon, target_dim)
               if data is a xshard item.
      """
      if quantize or acceleration:
          self.thread_num = set_pytorch_thread(
              self.optimized_model_thread_num, self.thread_num
          )
  
      if isinstance(data, TSDataset):
          _rolled = data.numpy_x is None
          data = data.to_torch_data_loader(
              batch_size=batch_size,
              roll=_rolled,
              lookback=self.data_config["past_seq_len"],
              horizon=self.data_config["future_seq_len"],
              feature_col=data.roll_feature,
              target_col=data.roll_target,
              shuffle=False,
          )
      # data transform
      is_local_data = isinstance(data, (np.ndarray, DataLoader))
      if is_local_data and self.distributed:
          if isinstance(data, DataLoader):
              invalidInputError(
                  False, "We will be support input dataloader later."
              )
          data = np_to_xshard(data, self.workers_per_node)
      if not is_local_data and not self.distributed:
          data = xshard_to_np(data, mode="predict")
  
      if self.distributed:
          yhat = self.internal.predict(data, batch_size=batch_size)
          expand_dim = []
          if self.data_config["future_seq_len"] == 1:
              expand_dim.append(1)
          if self.data_config["output_feature_num"] == 1:
              expand_dim.append(2)
          if is_local_data:
              yhat = xshard_to_np(
                  yhat, mode="yhat", expand_dim=expand_dim
              )
          else:
              yhat = yhat.transform_shard(xshard_expand_dim, expand_dim)
          return yhat
      else:
          if not self.fitted:
              invalidInputError(
                  False,
                  "You must call fit or restore first before calling predict!",
              )
          if not self.context_enabled:
              self.cxt_manager = ForecasterContextManager(
                  self, self.thread_num, acceleration
              )
          else:
              self.cxt_manager = DummyForecasterContextManager()
          with self.cxt_manager:
              if quantize:
                  if self.accelerate_method != "pytorch_int8":
                      invalidInputError(
                          False,
                          "Can't find the quantized model, "
                          "please call .quantize() method first",
                      )
                  yhat = _pytorch_fashion_inference(
                      model=self.accelerated_model,
                      input_data=data,
                      batch_size=batch_size,
                  )
              else:
                  if (
                      acceleration is False
                      or self.accelerated_model is None
                  ):
                      self.internal.eval()
                      yhat = _pytorch_fashion_inference(
                          model=self.internal,
                          input_data=data,
                          batch_size=batch_size,
                      )
                  else:
                      self.accelerated_model.eval()
                      yhat = _pytorch_fashion_inference(
                          model=self.accelerated_model,
                          input_data=data,
                          batch_size=batch_size,
                          output_tensor=self.optimized_model_output_tensor,
                      )
          if not is_local_data:
              yhat = np_to_xshard(
                  yhat, self.workers_per_node, prefix="prediction"
              )
          return yhat
  
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 8 for calling the BasePytorchForecaster obj's underlying member method code with example usage: obj.predict(data, batch_size, quantize, acceleration) and returns: yhat, yhat