code: def preprocess_drift(
      x: Union[np.ndarray, list],
      model: Union[nn.Module, nn.Sequential],
      device: TorchDeviceType = None,
      preprocess_batch_fn: Callable = None,
      tokenizer: Optional[Callable] = None,
      max_len: Optional[int] = None,
      batch_size: int = int(1e10),
      dtype: Union[Type[np.generic], torch.dtype] = np.float32,
  ) -> Union[np.ndarray, torch.Tensor, tuple]:
      """
      Prediction function used for preprocessing step of drift detector.
  
      Parameters
      ----------
      x
          Batch of instances.
      model
          Model used for preprocessing.
      device
          Device type used. The default tries to use the GPU and falls back on CPU if needed.
          Can be specified by passing either ``'cuda'``, ``'gpu'``, ``'cpu'`` or an instance of
          ``torch.device``.
      preprocess_batch_fn
          Optional batch preprocessing function. For example to convert a list of objects to a batch which can be
          processed by the PyTorch model.
      tokenizer
          Optional tokenizer for text drift.
      max_len
          Optional max token length for text drift.
      batch_size
          Batch size used during prediction.
      dtype
          Model output type, e.g. np.float32 or torch.float32.
  
      Returns
      -------
      Numpy array or torch tensor with predictions.
      """
      if tokenizer is None:
          return predict_batch(
              x,
              model,
              device=device,
              batch_size=batch_size,
              preprocess_fn=preprocess_batch_fn,
              dtype=dtype,
          )
      else:
          return predict_batch_transformer(
              x,
              model,
              tokenizer,
              max_len,
              device=device,
              batch_size=batch_size,
              dtype=dtype,
          )
  
file_path: alibi-detect/alibi_detect/cd/pytorch/preprocess.py
imports: from typing import Callable, Dict, Optional, Type, Union
  import numpy
  import torch
  import torch.nn
  from alibi_detect.utils.pytorch.prediction import predict_batch, predict_batch_transformer
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 1 for calling a global function with example usage: preprocess_drift(x, model, device, preprocess_batch_fn, tokenizer, max_len, batch_size, dtype) and returns: predict_batch, predict_batch_transformer