code: def load_model(
      filepath: Union[str, os.PathLike],
      layer: Optional[int] = None,
  ) -> nn.Module:
      """
      Load PyTorch model.
  
      Parameters
      ----------
      filepath
          Saved model filepath.
      layer
          Optional index of a hidden layer to extract. If not `None`, a
          :py:class:`~alibi_detect.cd.pytorch.HiddenOutput` model is returned.
  
      Returns
      -------
      Loaded model.
      """
      filepath = Path(filepath).joinpath("model.pt")
      model = torch.load(filepath, pickle_module=dill)
      # Optionally extract hidden layer
      if isinstance(layer, int):
          model = HiddenOutput(model, layer=layer)
      return model
  
file_path: alibi-detect/alibi_detect/saving/_pytorch/loading.py
imports: import logging
  import os
  from importlib import import_module
  from pathlib import Path
  from typing import Callable, Optional, Union, Type
  import dill
  import torch
  import torch.nn
  from alibi_detect.cd.pytorch import UAE, HiddenOutput
  from alibi_detect.cd.pytorch.preprocess import _Encoder
  from alibi_detect.models.pytorch import TransformerEmbedding
  from alibi_detect.utils.pytorch.kernels import DeepKernel
label_desc: Use image node_id 1 for calling a global function with example usage: load_model(filepath, layer) and returns: model