code: def _cleanup_filepath(orig_files: set, filepath: Path):
      """
      Cleans up the `filepath` directory in the event of a saving failure.
  
      Parameters
      ----------
      orig_files
          Set of original files (not to delete).
      filepath
          The directory to clean up.
      """
      # Find new files
      new_files = set(filepath.iterdir())
      files_to_rm = new_files - orig_files
      # Delete new files
      for file in files_to_rm:
          if file.is_dir():
              shutil.rmtree(file)
          elif file.is_file():
              file.unlink()
  
      # Delete filepath directory if it is now empty
      if filepath is not None:
          if not any(filepath.iterdir()):
              filepath.rmdir()
  
imports: import logging
  import os
  import shutil
  import warnings
  from functools import partial
  from pathlib import Path
  from typing import Callable, Optional, Tuple, Union, Any, Dict, TYPE_CHECKING
  import dill
  import numpy
  import toml
  from transformers import PreTrainedTokenizerBase
  from alibi_detect.saving._typing import VALID_DETECTORS
  from alibi_detect.saving.loading import _replace, validate_config, STATE_PATH
  from alibi_detect.saving.registry import registry
  from alibi_detect.utils._types import supported_models_all, supported_models_tf, supported_models_torch, supported_models_sklearn
  from alibi_detect.base import Detector, ConfigurableDetector, StatefulDetectorOnline
  from alibi_detect.saving._tensorflow import save_detector_legacy, save_model_config_tf, save_optimizer_config_tf
  from alibi_detect.saving._pytorch import save_model_config_pt, save_device_pt
  from alibi_detect.saving._sklearn import save_model_config_sk
label_desc: Use image node_id 2 for calling a global function with example usage: _cleanup_filepath(orig_files, filepath) without return types