code: def load_sub_model(
      library_name: str,
      class_name: str,
      importable_classes: List[Any],
      pipelines: Any,
      is_pipeline_module: bool,
      pipeline_class: Any,
      torch_dtype: torch.dtype,
      provider: Any,
      sess_options: Any,
      device_map: Optional[Union[Dict[str, torch.device], str]],
      max_memory: Optional[Dict[Union[int, str], Union[int, str]]],
      offload_folder: Optional[Union[str, os.PathLike]],
      offload_state_dict: bool,
      model_variants: Dict[str, str],
      name: str,
      from_flax: bool,
      variant: str,
      low_cpu_mem_usage: bool,
      cached_folder: Union[str, os.PathLike],
      revision: str = None,
  ):
      """Helper method to load the module `name` from `library_name` and `class_name`"""
      # retrieve class candidates
      class_obj, class_candidates = get_class_obj_and_candidates(
          library_name,
          class_name,
          importable_classes,
          pipelines,
          is_pipeline_module,
          component_name=name,
          cache_dir=cached_folder,
      )
  
      load_method_name = None
      # retrive load method name
      for class_name, class_candidate in class_candidates.items():
          if class_candidate is not None and issubclass(
              class_obj, class_candidate
          ):
              load_method_name = importable_classes[class_name][1]
  
      # if load method name is None, then we have a dummy module -> raise Error
      if load_method_name is None:
          none_module = class_obj.__module__
          is_dummy_path = none_module.startswith(
              DUMMY_MODULES_FOLDER
          ) or none_module.startswith(TRANSFORMERS_DUMMY_MODULES_FOLDER)
          if is_dummy_path and "dummy" in none_module:
              # call class_obj for nice error message of missing requirements
              class_obj()
  
          raise ValueError(
              f"The component {class_obj} of {pipeline_class} cannot be loaded as it does not seem to have"
              f" any of the loading methods defined in {ALL_IMPORTABLE_CLASSES}."
          )
  
      load_method = getattr(class_obj, load_method_name)
  
      # add kwargs to loading method
      diffusers_module = importlib.import_module(__name__.split(".")[0])
      loading_kwargs = {}
      if issubclass(class_obj, torch.nn.Module):
          loading_kwargs["torch_dtype"] = torch_dtype
      if issubclass(class_obj, diffusers_module.OnnxRuntimeModel):
          loading_kwargs["provider"] = provider
          loading_kwargs["sess_options"] = sess_options
  
      is_diffusers_model = issubclass(
          class_obj, diffusers_module.ModelMixin
      )
  
      if is_transformers_available():
          transformers_version = version.parse(
              version.parse(transformers.__version__).base_version
          )
      else:
          transformers_version = "N/A"
  
      is_transformers_model = (
          is_transformers_available()
          and issubclass(class_obj, PreTrainedModel)
          and transformers_version >= version.parse("4.20.0")
      )
  
      # When loading a transformers model, if the device_map is None, the weights will be initialized as opposed to diffusers.
      # To make default loading faster we set the `low_cpu_mem_usage=low_cpu_mem_usage` flag which is `True` by default.
      # This makes sure that the weights won't be initialized which significantly speeds up loading.
      if is_diffusers_model or is_transformers_model:
          loading_kwargs["device_map"] = device_map
          loading_kwargs["max_memory"] = max_memory
          loading_kwargs["offload_folder"] = offload_folder
          loading_kwargs["offload_state_dict"] = offload_state_dict
          loading_kwargs["variant"] = model_variants.pop(name, None)
          if from_flax:
              loading_kwargs["from_flax"] = True
  
          # the following can be deleted once the minimum required `transformers` version
          # is higher than 4.27
          if (
              is_transformers_model
              and loading_kwargs["variant"] is not None
              and transformers_version < version.parse("4.27.0")
          ):
              raise ImportError(
                  f"When passing `variant='{variant}'`, please make sure to upgrade your `transformers` version to at least 4.27.0.dev0"
              )
          elif (
              is_transformers_model
              and loading_kwargs["variant"] is None
          ):
              loading_kwargs.pop("variant")
  
          # if `from_flax` and model is transformer model, can currently not load with `low_cpu_mem_usage`
          if not (from_flax and is_transformers_model):
              loading_kwargs["low_cpu_mem_usage"] = low_cpu_mem_usage
          else:
              loading_kwargs["low_cpu_mem_usage"] = False
  
      # check if the module is in a subdirectory
      if os.path.isdir(os.path.join(cached_folder, name)):
          loaded_sub_model = load_method(
              os.path.join(cached_folder, name), **loading_kwargs
          )
      else:
          # else load from the root directory
          loaded_sub_model = load_method(
              cached_folder, **loading_kwargs
          )
  
      return loaded_sub_model
  
imports: import fnmatch
  import importlib
  import inspect
  import os
  import re
  import sys
  import warnings
  from dataclasses import dataclass
  from pathlib import Path
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import PIL.Image
  import requests
  import torch
  from huggingface_hub import ModelCard, create_repo, hf_hub_download, model_info, snapshot_download
  from huggingface_hub.utils import OfflineModeIsEnabled, validate_hf_hub_args
  from packaging import version
  from requests.exceptions import HTTPError
  from tqdm.auto import tqdm
  from ..None import __version__
  from ..configuration_utils import ConfigMixin
  from ..models.modeling_utils import _LOW_CPU_MEM_USAGE_DEFAULT
  from ..schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
  from ..utils import CONFIG_NAME, DEPRECATED_REVISION_ARGS, SAFETENSORS_WEIGHTS_NAME, WEIGHTS_NAME, BaseOutput, deprecate, get_class_from_dynamic_module, is_accelerate_available, is_accelerate_version, is_peft_available, is_torch_version, is_transformers_available, logging, numpy_to_pil
  from ..utils.torch_utils import is_compiled_module
  from ..utils import FLAX_WEIGHTS_NAME, ONNX_EXTERNAL_WEIGHTS_NAME, ONNX_WEIGHTS_NAME, PushToHubMixin
label_desc: Use image node_id 8 for calling a global function with example usage: load_sub_model(library_name, class_name, importable_classes, pipelines, is_pipeline_module, pipeline_class, torch_dtype, provider, sess_options, device_map, max_memory, offload_folder, offload_state_dict, model_variants, name, from_flax, variant, low_cpu_mem_usage, cached_folder, revision) and returns: loaded_sub_model