code: def get_coreml_pipe(
      pytorch_pipe,
      mlpackages_dir,
      model_version,
      compute_unit,
      delete_original_pipe=True,
      scheduler_override=None,
      controlnet_models=None,
      force_zeros_for_empty_prompt=True,
      sources=None,
  ):
      """
      Initializes and returns a `CoreMLStableDiffusionPipeline` from an original
      diffusers PyTorch pipeline
          sources: 'packages' or 'compiled' forces creation of model from specified sources. sources must be in mlpackages_dir
      """
  
      # Ensure `scheduler_override` object is of correct type if specified
      if scheduler_override is not None:
          assert isinstance(scheduler_override, SchedulerMixin)
          logger.warning(
              "Overriding scheduler in pipeline: "
              f"Default={pytorch_pipe.scheduler}, Override={scheduler_override}"
          )
  
      # Gather configured tokenizer and scheduler attributes from the original pipe
      if "xl" in model_version:
          coreml_pipe_kwargs = {
              "tokenizer": pytorch_pipe.tokenizer,
              "tokenizer_2": pytorch_pipe.tokenizer_2,
              "scheduler": pytorch_pipe.scheduler
              if scheduler_override is None
              else scheduler_override,
              "force_zeros_for_empty_prompt": force_zeros_for_empty_prompt,
              "xl": True,
          }
  
          model_packages_to_load = [
              "text_encoder",
              "text_encoder_2",
              "unet",
              "vae_decoder",
          ]
  
      else:
          coreml_pipe_kwargs = {
              "tokenizer": pytorch_pipe.tokenizer,
              "scheduler": pytorch_pipe.scheduler
              if scheduler_override is None
              else scheduler_override,
              "feature_extractor": pytorch_pipe.feature_extractor,
          }
          model_packages_to_load = [
              "text_encoder",
              "unet",
              "vae_decoder",
          ]
  
      if getattr(pytorch_pipe, "safety_checker", None) is not None:
          model_packages_to_load.append("safety_checker")
      else:
          logger.warning(
              f"Original diffusers pipeline for {model_version} does not have a safety_checker, "
              "Core ML pipeline will mirror this behavior."
          )
          coreml_pipe_kwargs["safety_checker"] = None
  
      if delete_original_pipe:
          del pytorch_pipe
          gc.collect()
          logger.info(
              "Removed PyTorch pipe to reduce peak memory consumption"
          )
  
      if controlnet_models:
          model_packages_to_load.remove("unet")
          coreml_pipe_kwargs["unet"] = _load_mlpackage(
              submodule_name="control-unet",
              mlpackages_dir=mlpackages_dir,
              model_version=model_version,
              compute_unit=compute_unit,
          )
          coreml_pipe_kwargs["controlnet"] = [
              _load_mlpackage_controlnet(
                  mlpackages_dir,
                  model_version,
                  compute_unit,
              )
              for model_version in controlnet_models
          ]
      else:
          coreml_pipe_kwargs["controlnet"] = None
  
      # Load Core ML models
      logger.info(
          f"Loading Core ML models in memory from {mlpackages_dir}"
      )
      coreml_pipe_kwargs.update(
          {
              model_name: _load_mlpackage(
                  submodule_name=model_name,
                  mlpackages_dir=mlpackages_dir,
                  model_version=model_version,
                  compute_unit=compute_unit,
                  sources=sources,
              )
              for model_name in model_packages_to_load
          }
      )
      logger.info("Done.")
  
      logger.info("Initializing Core ML pipe for image generation")
      coreml_pipe = CoreMLStableDiffusionPipeline(**coreml_pipe_kwargs)
      logger.info("Done.")
  
      return coreml_pipe
  
imports: import argparse
  from diffusers import StableDiffusionPipeline, StableDiffusionXLPipeline
  from diffusers.pipelines.pipeline_utils import DiffusionPipeline
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
  from diffusers.schedulers import DDIMScheduler, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler, EulerDiscreteScheduler, LMSDiscreteScheduler, PNDMScheduler
  from diffusers.schedulers.scheduling_utils import SchedulerMixin
  import gc
  import inspect
  import logging
  import numpy
  import os
  from python_coreml_stable_diffusion.coreml_model import CoreMLModel, _load_mlpackage, _load_mlpackage_controlnet, get_available_compute_units
  import time
  import torch
  from transformers import CLIPFeatureExtractor, CLIPTokenizer
  from typing import List, Optional, Union, Tuple
  from PIL import Image
label_desc: Use image node_id 2 for calling a global function with example usage: get_coreml_pipe(pytorch_pipe, mlpackages_dir, model_version, compute_unit, delete_original_pipe, scheduler_override, controlnet_models, force_zeros_for_empty_prompt, sources) and returns: coreml_pipe