class_docstr: Test Stable Diffusion text-to-image pipeline for:
  
  - PyTorch to CoreML conversion via coremltools
  - Speed of CoreML runtime across several compute units
  - Integration with `diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.py`
  - Efficacy of the safety_checker
  - Affinity of the generated image with the original prompt via CLIP score
  - The bridge between Python and Swift CLI
  - The signal parity of Swift CLI generated image with that of Python CLI
docstr: Benchmark end-to-end text-to-image generation with the requested compute_unit
          
docstr_tok: ["Benchmark","end-to-end","text-to-image","generation","with","the","requested","compute_unit"]
code: def _coreml_text_to_image_with_compute_unit(self, compute_unit):
      """Benchmark end-to-end text-to-image generation with the requested compute_unit"""
      self._init_coreml_pipe(compute_unit)
  
      # Warm up (not necessary in all settings but improves consistency for benchmarking)
      logger.info(
          f"Warmup image generation with {TEST_WARMUP_INFERENCE_STEPS} inference steps"
      )
      image = self.coreml_pipe(
          TEST_PROMPT, num_inference_steps=TEST_WARMUP_INFERENCE_STEPS
      )
  
      # Test end-to-end speed
      logger.info(
          f"Run full image generation {TEST_TEXT_TO_IMAGE_SPEED_REPEATS} times and report median"
      )
  
      def test_coreml_text_to_image_speed():
          """Execute Core ML based image generation"""
          _reset_seed()
          image = self.coreml_pipe(TEST_PROMPT)["images"][0]
          out_path = pipeline.get_image_path(
              self.cli_args,
              prompt=TEST_PROMPT,
              compute_unit=compute_unit,
          )
          logger.info(f"Saving generated image to {out_path}")
          image.save(out_path)
  
      def collect_timings(callable, n):
          """Collect user latency for callable"""
          user_latencies = []
          for _ in range(n):
              s = time.time()
              callable()
              user_latencies.append(float(f"{time.time() - s:.2f}"))
          return user_latencies
  
      coreml_latencies = collect_timings(
          callable=test_coreml_text_to_image_speed,
          n=TEST_TEXT_TO_IMAGE_SPEED_REPEATS,
      )
      coreml_median_latency = median(coreml_latencies)
  
      logger.info(
          f"End-to-end latencies with coremltools.ComputeUnit.{compute_unit}: median={coreml_median_latency:.2f}"
      )
  
      return coreml_median_latency
  
imports: import argparse
  import contextlib
  import coremltools
  from diffusers import StableDiffusionPipeline
  import json
  import logging
  import numpy
  import os
  import unittest
  from PIL import Image
  from statistics import median
  import tempfile
  import time
  import torch
  from python_coreml_stable_diffusion import torch2coreml, pipeline, coreml_model
label_desc: Use image node_id 9 for calling the TestStableDiffusionForTextToImage obj's underlying member method code with example usage: obj._coreml_text_to_image_with_compute_unit(compute_unit) and returns: coreml_median_latency, user_latencies