code: def prep_model_and_emb(
      model: nn.Module, emb: Optional[TransformerEmbedding]
  ) -> nn.Module:
      """
      Function to perform final preprocessing of model (and/or embedding) before it is passed to preprocess_drift.
  
      Parameters
      ----------
      model
          A compatible model.
      emb
          An optional text embedding model.
  
      Returns
      -------
      The final model ready to passed to preprocess_drift.
      """
      # Process model (and embedding)
      model = (
          model.encoder if isinstance(model, UAE) else model
      )  # This is to avoid nesting UAE's already a UAE
      if emb is not None:
          model = _Encoder(emb, mlp=model)
          model = UAE(encoder_net=model)
      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 2 for calling a global function with example usage: prep_model_and_emb(model, emb) and returns: model