code: def _load_preprocess_config(cfg: dict) -> Optional[Callable]:
      """
      This function builds a preprocess_fn from the preprocess dict in a detector config dict. The dict format is
      expected to match that generated by serialize_preprocess in alibi_detect.utils.saving (also see pydantic schema).
      The model, tokenizer and preprocess_batch_fn are expected to be already resolved.
  
      Parameters
      ----------
      cfg
          A preprocess_fn config dict. (see pydantic schemas).
  
      Returns
      -------
      The preprocess_fn function.
      """
      preprocess_fn = cfg.pop("src")
  
      if callable(preprocess_fn):
          if preprocess_fn.__name__ == "preprocess_drift":
              # If preprocess_drift function, kwargs is preprocess cfg minus 'src' and 'kwargs'
              cfg.pop("kwargs")
              kwargs = cfg.copy()
  
              # Final processing of model (and/or embedding)
              model = kwargs["model"]
              emb = kwargs.pop(
                  "embedding"
              )  # embedding passed to preprocess_drift as `model` therefore remove
  
              # Backend specifics
              if has_tensorflow and isinstance(
                  model, supported_models_tf
              ):
                  model = prep_model_and_emb_tf(model, emb)
              elif has_pytorch and isinstance(
                  model, supported_models_torch
              ):
                  model = prep_model_and_emb_pt(model, emb)
              elif model is None:
                  model = emb
              if model is None:
                  raise ValueError(
                      "A 'model'  and/or `embedding` must be specified when "
                      "preprocess_fn='preprocess_drift'"
                  )
              kwargs.update({"model": model})
              # Set`device` if a PyTorch model, otherwise remove from kwargs
              if isinstance(model, supported_models_torch):
                  device = get_device(cfg["device"])
                  model = model.to(device).eval()
                  kwargs.update({"device": device})
                  kwargs.update({"model": model})
              else:
                  kwargs.pop("device")
          else:
              kwargs = cfg[
                  "kwargs"
              ]  # If generic callable, kwargs is cfg['kwargs']
  
      else:
          logger.warning(
              "Unable to process preprocess_fn. No preprocessing function is defined."
          )
          return None
  
      if kwargs == {}:
          return preprocess_fn
      else:
          return partial(preprocess_fn, **kwargs)
  
imports: import logging
  import os
  from functools import partial
  from importlib import import_module
  from pathlib import Path
  from typing import Any, Callable, Optional, Union, Type, TYPE_CHECKING
  import dill
  import numpy
  import toml
  from transformers import AutoTokenizer
  from alibi_detect.saving.registry import registry
  from alibi_detect.saving._tensorflow import load_detector_legacy, load_embedding_tf, load_kernel_config_tf, load_model_tf, load_optimizer_tf, prep_model_and_emb_tf, get_tf_dtype
  from alibi_detect.saving._pytorch import load_embedding_pt, load_kernel_config_pt, load_model_pt, load_optimizer_pt, prep_model_and_emb_pt, get_pt_dtype
  from alibi_detect.saving._keops import load_kernel_config_ke
  from alibi_detect.saving._sklearn import load_model_sk
  from alibi_detect.saving.validate import validate_config
  from alibi_detect.base import Detector, ConfigurableDetector, StatefulDetectorOnline
  from alibi_detect.utils.frameworks import has_tensorflow, has_pytorch, Framework
  from alibi_detect.saving.schemas import supported_models_tf, supported_models_torch
  from alibi_detect.utils.missing_optional_dependency import import_optional
label_desc: Use image node_id 5 for calling a global function with example usage: _load_preprocess_config(cfg) and returns: None, preprocess_fn, partial