code: def _load_detector_config(
      filepath: Union[str, os.PathLike],
      enable_unsafe_loading: bool = False,
  ) -> ConfigurableDetector:
      """
      Loads a drift detector specified in a detector config dict. Validation is performed with pydantic.
  
      Parameters
      ----------
      filepath
          Filepath to the `config.toml` file.
      enable_unsafe_loading
          Sets allow_pickle=True when a np.ndarray is loaded from a .npy file (happens if the .toml references one).
          Needed if you have to load objects.
          It has security implications: https://nvd.nist.gov/vuln/detail/cve-2019-6446
  
      Returns
      -------
      The instantiated detector.
      """
      # Load toml if needed
      if isinstance(filepath, (str, os.PathLike)):
          config_file = Path(filepath)
          config_dir = config_file.parent
          cfg = read_config(config_file)
      else:
          raise ValueError(
              "`filepath` should point to a directory containing a 'config.toml' file."
          )
  
      # Resolve and validate config
      cfg = validate_config(cfg)
      logger.info("Validated unresolved config.")
      cfg = resolve_config(
          cfg,
          config_dir=config_dir,
          enable_unsafe_loading=enable_unsafe_loading,
      )
      cfg = validate_config(cfg, resolved=True)
      logger.info("Validated resolved config.")
  
      # Init detector from config
      logger.info("Instantiating detector.")
      detector = _init_detector(cfg)
  
      # Load state if it exists (and detector supports it)
      # TODO - this will be removed in follow-up offline state PR, as loading to be moved to __init__ (w/ state_dir kwarg)
      if isinstance(detector, StatefulDetectorOnline):
          state_dir = config_dir.joinpath(STATE_PATH)
          if state_dir.is_dir():
              detector.load_state(state_dir)
  
      logger.info("Finished loading detector.")
  
      return detector
  
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 2 for calling a global function with example usage: _load_detector_config(filepath, enable_unsafe_loading) and returns: detector