code: def bundle_resources_for_swift_cli(args):
      """
      - Compiles Core ML models from mlpackage into mlmodelc format
      - Download tokenizer resources for the text encoder
      """
      resources_dir = os.path.join(args.o, "Resources")
      if not os.path.exists(resources_dir):
          os.makedirs(resources_dir, exist_ok=True)
          logger.info(f"Created {resources_dir} for Swift CLI assets")
  
      # Compile model using coremlcompiler (Significantly reduces the load time for unet)
      for source_name, target_name in [
          ("text_encoder", "TextEncoder"),
          ("text_encoder_2", "TextEncoder2"),
          ("vae_decoder", "VAEDecoder"),
          ("vae_encoder", "VAEEncoder"),
          ("unet", "Unet"),
          ("unet_chunk1", "UnetChunk1"),
          ("unet_chunk2", "UnetChunk2"),
          ("refiner", "UnetRefiner"),
          ("refiner_chunk1", "UnetRefinerChunk1"),
          ("refiner_chunk2", "UnetRefinerChunk2"),
          ("control-unet", "ControlledUnet"),
          ("control-unet_chunk1", "ControlledUnetChunk1"),
          ("control-unet_chunk2", "ControlledUnetChunk2"),
          ("safety_checker", "SafetyChecker"),
      ]:
          source_path = _get_out_path(args, source_name)
          if os.path.exists(source_path):
              target_path = _compile_coreml_model(
                  source_path, resources_dir, target_name
              )
              logger.info(f"Compiled {source_path} to {target_path}")
          else:
              logger.warning(
                  f"{source_path} not found, skipping compilation to {target_name}.mlmodelc"
              )
  
      if args.convert_controlnet:
          for controlnet_model_version in args.convert_controlnet:
              controlnet_model_name = controlnet_model_version.replace(
                  "/", "_"
              )
              fname = f"ControlNet_{controlnet_model_name}.mlpackage"
              source_path = os.path.join(args.o, fname)
              controlnet_dir = os.path.join(resources_dir, "controlnet")
              target_name = "".join(
                  [
                      word.title()
                      for word in re.split("_|-", controlnet_model_name)
                  ]
              )
  
              if os.path.exists(source_path):
                  target_path = _compile_coreml_model(
                      source_path, controlnet_dir, target_name
                  )
                  logger.info(
                      f"Compiled {source_path} to {target_path}"
                  )
              else:
                  logger.warning(
                      f"{source_path} not found, skipping compilation to {target_name}.mlmodelc"
                  )
  
      # Fetch and save vocabulary JSON file for text tokenizer
      logger.info("Downloading and saving tokenizer vocab.json")
      with open(os.path.join(resources_dir, "vocab.json"), "wb") as f:
          f.write(
              requests.get(args.text_encoder_vocabulary_url).content
          )
      logger.info("Done")
  
      # Fetch and save merged pairs JSON file for text tokenizer
      logger.info("Downloading and saving tokenizer merges.txt")
      with open(os.path.join(resources_dir, "merges.txt"), "wb") as f:
          f.write(requests.get(args.text_encoder_merges_url).content)
      logger.info("Done")
  
      return resources_dir
  
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 9 for calling a global function with example usage: bundle_resources_for_swift_cli(args) and returns: resources_dir