code: def _load_mlpackage(
      submodule_name,
      mlpackages_dir,
      model_version,
      compute_unit,
      sources=None,
  ):
      """
      Load Core ML (mlpackage) models from disk (As exported by torch2coreml.py)
  
      """
  
      # if sources not provided, attempt to infer `packages` or `compiled` from the
      # resources directory
      if sources is None:
          sources = get_resource_type(mlpackages_dir)
  
      if sources == "packages":
          logger.info(f"Loading {submodule_name} mlpackage")
          fname = f"Stable_Diffusion_version_{model_version}_{submodule_name}.mlpackage".replace(
              "/", "_"
          )
          mlpackage_path = os.path.join(mlpackages_dir, fname)
  
          if not os.path.exists(mlpackage_path):
              raise FileNotFoundError(
                  f"{submodule_name} CoreML model doesn't exist at {mlpackage_path}"
              )
  
      elif sources == "compiled":
          logger.info(f"Loading {submodule_name} mlmodelc")
  
          # FixMe: Submodule names and compiled resources names differ. Can change if names match in the future.
          submodule_names = [
              "text_encoder",
              "text_encoder_2",
              "unet",
              "vae_decoder",
              "vae_encoder",
              "safety_checker",
          ]
          compiled_names = [
              "TextEncoder",
              "TextEncoder2",
              "Unet",
              "VAEDecoder",
              "VAEEncoder",
              "SafetyChecker",
          ]
          name_map = dict(zip(submodule_names, compiled_names))
  
          cname = name_map[submodule_name] + ".mlmodelc"
          mlpackage_path = os.path.join(mlpackages_dir, cname)
  
          if not os.path.exists(mlpackage_path):
              raise FileNotFoundError(
                  f"{submodule_name} CoreML model doesn't exist at {mlpackage_path}"
              )
  
      return CoreMLModel(mlpackage_path, compute_unit, sources=sources)
  
file_path: ml-stable-diffusion/python_coreml_stable_diffusion/coreml_model.py
imports: import coremltools
  import logging
  import json
  import numpy
  import os
  import time
label_desc: Use image node_id 2 for calling a global function with example usage: _load_mlpackage(submodule_name, mlpackages_dir, model_version, compute_unit, sources) and returns: CoreMLModel