code: def _convert_to_coreml(
      submodule_name,
      torchscript_module,
      sample_inputs,
      output_names,
      args,
      out_path=None,
      precision=None,
      compute_unit=None,
  ):
      if out_path is None:
          out_path = _get_out_path(args, submodule_name)
  
      compute_unit = compute_unit or ct.ComputeUnit[args.compute_unit]
  
      if os.path.exists(out_path):
          logger.info(
              f"Skipping export because {out_path} already exists"
          )
          logger.info(f"Loading model from {out_path}")
  
          start = time.time()
          # Note: Note that each model load will trigger a model compilation which takes up to a few minutes.
          # The Swifty CLI we provide uses precompiled Core ML models (.mlmodelc) which incurs compilation only
          # upon first load and mitigates the load time in subsequent runs.
          coreml_model = ct.models.MLModel(
              out_path, compute_units=compute_unit
          )
          logger.info(
              f"Loading {out_path} took {time.time() - start:.1f} seconds"
          )
  
          coreml_model.compute_unit = compute_unit
      else:
          logger.info(f"Converting {submodule_name} to CoreML..")
          coreml_model = ct.convert(
              torchscript_module,
              convert_to="mlprogram",
              minimum_deployment_target=ct.target.macOS13,
              inputs=_get_coreml_inputs(sample_inputs, args),
              outputs=[
                  ct.TensorType(name=name, dtype=np.float32)
                  for name in output_names
              ],
              compute_units=compute_unit,
              compute_precision=precision,
              skip_model_load=not args.check_output_correctness,
          )
  
          del torchscript_module
          gc.collect()
  
      return coreml_model, out_path
  
imports: from python_coreml_stable_diffusion import unet, controlnet, chunk_mlprogram
  import argparse
  from collections import OrderedDict, defaultdict
  from copy import deepcopy
  import coremltools
  from diffusers import StableDiffusionPipeline, DiffusionPipeline, ControlNetModel
  import gc
  import logging
  import numpy
  import os
  import requests
  import shutil
  import time
  import re
  import pathlib
  import torch
  import torch.nn
  import torch.nn.functional
  from types import MethodType
  from transformers.models.clip import modeling_clip
label_desc: Use image node_id 5 for calling a global function with example usage: _convert_to_coreml(submodule_name, torchscript_module, sample_inputs, output_names, args, out_path, precision, compute_unit) and returns: coreml_model,  out_path