code: def encompass_batching(
      model: Callable,
      backend: str,
      batch_size: int,
      device: TorchDeviceType = None,
      preprocess_batch_fn: Optional[Callable] = None,
      tokenizer: Optional[Callable] = None,
      max_len: Optional[int] = None,
  ) -> Callable:
      """
      Takes a function that must be batch evaluated (on tokenized input) and returns a function
      that handles batching (and tokenization).
      """
  
      backend = backend.lower()
      kwargs = {
          "batch_size": batch_size,
          "tokenizer": tokenizer,
          "max_len": max_len,
          "preprocess_batch_fn": preprocess_batch_fn,
      }
      if backend == Framework.TENSORFLOW:
          from alibi_detect.cd.tensorflow.preprocess import (
              preprocess_drift,
          )
      elif backend == Framework.PYTORCH:
          from alibi_detect.cd.pytorch.preprocess import preprocess_drift  # type: ignore[assignment]
  
          kwargs["device"] = device
      else:
          raise NotImplementedError(
              f"{backend} not implemented. Use tensorflow or pytorch instead."
          )
  
      def model_fn(x: Union[np.ndarray, list]) -> np.ndarray:
          return preprocess_drift(x, model, **kwargs)  # type: ignore[arg-type]
  
      return model_fn
  
file_path: alibi-detect/alibi_detect/cd/utils.py
imports: import logging
  import random
  from typing import Callable, Dict, Optional, Tuple, Union
  import numpy
  from alibi_detect.utils.sampling import reservoir_sampling
  from alibi_detect.utils.frameworks import Framework
  from alibi_detect.utils._types import TorchDeviceType
label_desc: Use image node_id 2 for calling a global function with example usage: encompass_batching(model, backend, batch_size, device, preprocess_batch_fn, tokenizer, max_len) and returns: model_fn, preprocess_drift