code: def parser_spec():
      parser = argparse.ArgumentParser()
  
      # Select which models to export (All are needed for text-to-image pipeline to function)
      parser.add_argument("--convert-text-encoder", action="store_true")
      parser.add_argument("--convert-vae-decoder", action="store_true")
      parser.add_argument("--convert-vae-encoder", action="store_true")
      parser.add_argument("--convert-unet", action="store_true")
      parser.add_argument(
          "--convert-safety-checker", action="store_true"
      )
      parser.add_argument(
          "--convert-controlnet",
          nargs="*",
          type=str,
          help="Converts a ControlNet model hosted on HuggingFace to coreML format. "
          "To convert multiple models, provide their names separated by spaces.",
      )
      parser.add_argument(
          "--model-version",
          required=True,
          help=(
              "The pre-trained model checkpoint and configuration to restore. "
              "For available versions: https://huggingface.co/models?search=stable-diffusion"
          ),
      )
      parser.add_argument(
          "--refiner-version",
          default=None,
          help=(
              "The pre-trained refiner model checkpoint and configuration to restore. "
              "If specified, this argument will convert and bundle the refiner unet only alongside the model unet. "
              "If you would like to convert a refiner model on it's own, use the --model-version argument instead."
              "For available versions: https://huggingface.co/models?sort=trending&search=stable-diffusion+refiner"
          ),
      )
      parser.add_argument(
          "--custom-vae-version",
          type=str,
          default=None,
          help=(
              "Custom VAE checkpoint to override the pipeline's built-in VAE. "
              "If specified, the specified VAE will be converted instead of the one associated to the `--model-version` checkpoint. "
              "No precision override is applied when using a custom VAE."
          ),
      )
      parser.add_argument(
          "--compute-unit",
          choices=tuple(cu for cu in ct.ComputeUnit._member_names_),
          default="ALL",
      )
      parser.add_argument(
          "--latent-h",
          type=int,
          default=None,
          help="The spatial resolution (number of rows) of the latent space. `Defaults to pipe.unet.config.sample_size`",
      )
      parser.add_argument(
          "--latent-w",
          type=int,
          default=None,
          help="The spatial resolution (number of cols) of the latent space. `Defaults to pipe.unet.config.sample_size`",
      )
      parser.add_argument(
          "--text-token-sequence-length",
          type=int,
          default=None,
          help="The token sequence length for the text encoder. `Defaults to pipe.text_encoder.config.max_position_embeddings`",
      )
      parser.add_argument(
          "--text-encoder-hidden-size",
          type=int,
          default=None,
          help="The hidden size for the text encoder. `Defaults to pipe.text_encoder.config.hidden_size`",
      )
      parser.add_argument(
          "--attention-implementation",
          choices=tuple(
              ai for ai in unet.AttentionImplementations._member_names_
          ),
          default=unet.ATTENTION_IMPLEMENTATION_IN_EFFECT.name,
          help="The enumerated implementations trade off between ANE and GPU performance",
      )
      parser.add_argument(
          "-o",
          default=os.getcwd(),
          help="The resulting mlpackages will be saved into this directory",
      )
      parser.add_argument(
          "--check-output-correctness",
          action="store_true",
          help="If specified, compares the outputs of original PyTorch and final CoreML models and reports PSNR in dB. "
          "Enabling this feature uses more memory. Disable it if your machine runs out of memory.",
      )
      parser.add_argument(
          "--chunk-unet",
          action="store_true",
          help="If specified, generates two mlpackages out of the unet model which approximately equal weights sizes. "
          "This is required for ANE deployment on iOS and iPadOS. Not required for macOS.",
      )
      parser.add_argument(
          "--quantize-nbits",
          default=None,
          choices=(1, 2, 4, 6, 8),
          type=int,
          help="If specified, quantized each model to nbits precision",
      )
      parser.add_argument(
          "--unet-support-controlnet",
          action="store_true",
          help="If specified, enable unet to receive additional inputs from controlnet. "
          "Each input added to corresponding resnet output.",
      )
  
      # Swift CLI Resource Bundling
      parser.add_argument(
          "--bundle-resources-for-swift-cli",
          action="store_true",
          help="If specified, creates a resources directory compatible with the sample Swift CLI. "
          "It compiles all four models and adds them to a StableDiffusionResources directory "
          "along with a `vocab.json` and `merges.txt` for the text tokenizer",
      )
      parser.add_argument(
          "--text-encoder-vocabulary-url",
          default="https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/vocab.json",
          help="The URL to the vocabulary file use by the text tokenizer",
      )
      parser.add_argument(
          "--text-encoder-merges-url",
          default="https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/merges.txt",
          help="The URL to the merged pairs used in by the text tokenizer.",
      )
      parser.add_argument(
          "--xl-version",
          action="store_true",
          help=(
              "If specified, the pre-trained model will be treated as an instantiation of "
              "`diffusers.pipelines.StableDiffusionXLPipeline` instead of `diffusers.pipelines.StableDiffusionPipeline`"
          ),
      )
  
      return parser
  
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 21 for calling a global function with example usage: parser_spec() and returns: parser