code: def save_model(
      model: nn.Module,
      filepath: Union[str, os.PathLike],
      save_dir: Union[str, os.PathLike] = "model",
  ) -> None:
      """
      Save PyTorch model.
  
      Parameters
      ----------
      model
          The PyTorch model to save.
      filepath
          Save directory.
      save_dir
          Name of folder to save to within the filepath directory.
      """
      # create folder to save model in
      model_path = Path(filepath).joinpath(save_dir)
      if not model_path.is_dir():
          logger.warning(
              "Directory {} does not exist and is now created.".format(
                  model_path
              )
          )
          model_path.mkdir(parents=True, exist_ok=True)
  
      # save model
      model_path = model_path.joinpath("model.pt")
  
      if isinstance(model, nn.Module):
          torch.save(model, model_path, pickle_module=dill)
      else:
          raise ValueError(
              "The extracted model to save is not a `nn.Module`. Cannot save."
          )
  
file_path: alibi-detect/alibi_detect/saving/_pytorch/saving.py
imports: import os
  import logging
  from pathlib import Path
  from typing import Any, Callable, Dict, Optional, Tuple, Union
  import dill
  import torch
  import torch.nn
  from alibi_detect.cd.pytorch import UAE, HiddenOutput
  from alibi_detect.models.pytorch import TransformerEmbedding
  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: save_model(model, filepath, save_dir) without return types