code: def load_submodules(
      basemod: ModuleType,
      load_all: bool = True,
      exclude_pattern: str = "(.*[tT]est.*)|(_.*)",
  ) -> tuple[list[ModuleType], list[str]]:
      """
      Traverse the source of the module structure starting with module `basemod`, loading all packages plus all files if
      `load_all` is True, excluding anything whose name matches `exclude_pattern`.
      """
      submodules = []
      err_mod: list[str] = []
      for importer, name, is_pkg in walk_packages(
          basemod.__path__,
          prefix=basemod.__name__ + ".",
          onerror=err_mod.append,
      ):
          if (
              (is_pkg or load_all)
              and name not in sys.modules
              and match(exclude_pattern, name) is None
          ):
              try:
                  mod = import_module(name)
                  importer.find_module(name).load_module(name)  # type: ignore
                  submodules.append(mod)
              except OptionalImportError:
                  pass  # could not import the optional deps., they are ignored
              except ImportError as e:
                  msg = (
                      "\nMultiple versions of MONAI may have been installed?\n"
                      "Please see the installation guide: https://docs.monai.io/en/stable/installation.html\n"
                  )  # issue project-monai/monai#5193
                  raise type(e)(f"{e}\n{msg}").with_traceback(
                      e.__traceback__
                  ) from e  # raise with modified message
  
      return submodules, err_mod
  
imports: from __future__ import annotations
  import enum
  import functools
  import os
  import pdb
  import re
  import sys
  import warnings
  from collections.abc import Callable, Collection, Hashable, Mapping
  from functools import partial, wraps
  from importlib import import_module
  from pkgutil import walk_packages
  from pydoc import locate
  from re import match
  from types import FunctionType, ModuleType
  from typing import Any, Iterable, cast
  import torch
label_desc: Use image node_id 4 for calling a global function with example usage: load_submodules(basemod, load_all, exclude_pattern) and returns: submodules,  err_mod