code: def write_config(cfg: dict, filepath: Union[str, os.PathLike]):
      """
      Save an unresolved detector config dict to a TOML file.
  
      Parameters
      ----------
      cfg
          Unresolved detector config dict.
      filepath
          Filepath to directory to save 'config.toml' file in.
      """
      # Create directory if it doesn't exist
      filepath = Path(filepath)
      if not filepath.is_dir():
          logger.warning(
              "Directory {} does not exist and is now created.".format(
                  filepath
              )
          )
          filepath.mkdir(parents=True, exist_ok=True)
      # Convert pathlib.Path's to str's
      cfg = _path2str(cfg)
      # Validate config before final tweaks
      validate_config(
          cfg
      )  # Must validate here as replacing None w/ str will break validation
      # Replace None with "None", and dicts with integer keys with str keys
      # TODO: Subject to change depending on toml library updates
      cfg = _replace(
          cfg, None, "None"
      )  # Note: None replaced with "None" as None/null not valid TOML
      cfg = _int2str_keys(cfg)
      # Write to TOML file
      logger.info(
          "Writing config to {}".format(
              filepath.joinpath("config.toml")
          )
      )
      with open(filepath.joinpath("config.toml"), "w") as f:
          toml.dump(cfg, f, encoder=toml.TomlNumpyEncoder())
  
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 4 for calling a global function with example usage: write_config(cfg, filepath) without return types