code: def swap_modules(model: nn.Module, mapping: Dict[str, nn.Module]):
      """
      This function swaps nested modules as specified by "dot paths" in mod with a desired replacement. This allows
      for swapping nested modules through arbitrary levels if children
  
      NOTE: This occurs in place, if you want to preserve model then make sure to copy it first.
  
      """
      for path, new_mod in mapping.items():
          expanded_path = path.split(".")
          parent_mod = model
          for sub_path in expanded_path[:-1]:
              parent_mod = parent_mod._modules[sub_path]  # noqa
          parent_mod._modules[expanded_path[-1]] = new_mod  # noqa
  
      return model
  
imports: import os
  from contextlib import nullcontext
  from enum import Enum
  from typing import Callable, Dict, Optional, Type
  import onnx
  import torch
  import torch.nn
  import torch.nn.functional
  from nemo.utils import CastToFloat, CastToFloatAll, logging
label_desc: Use image node_id 14 for calling a global function with example usage: swap_modules(model, mapping) and returns: model