class_docstr: Core ML version of
  `diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline`
class_docstr_tok: ["Core","ML","version","of","`","diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline","`"]
code: def __call__(
      self,
      prompt,
      height=512,
      width=512,
      num_inference_steps=50,
      guidance_scale=7.5,
      negative_prompt=None,
      num_images_per_prompt=1,
      eta=0.0,
      latents=None,
      output_type="pil",
      return_dict=True,
      callback=None,
      callback_steps=1,
      controlnet_cond=None,
      original_size: Optional[Tuple[int, int]] = None,
      crops_coords_top_left: Tuple[int, int] = (0, 0),
      target_size: Optional[Tuple[int, int]] = None,
      **kwargs,
  ):
      # 1. Check inputs. Raise error if not correct
      self.check_inputs(prompt, height, width, callback_steps)
      height = height or self.height
      width = width or self.width
  
      original_size = original_size or (height, width)
      target_size = target_size or (height, width)
  
      # 2. Define call parameters
      batch_size = 1 if isinstance(prompt, str) else len(prompt)
      if batch_size > 1 or num_images_per_prompt > 1:
          raise NotImplementedError(
              "For batched generation of multiple images and/or multiple prompts, please refer to the Swift package."
          )
  
      # here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
      # of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
      # corresponds to doing no classifier free guidance.
      do_classifier_free_guidance = guidance_scale > 1.0
  
      # 3. Encode input prompt
      text_embeddings, pooled_prompt_embeds = self._encode_prompt(
          prompt=prompt,
          prompt_2=None,
          do_classifier_free_guidance=do_classifier_free_guidance,
          negative_prompt=negative_prompt,
          negative_prompt_2=None,
      )
  
      # 4. Prepare XL kwargs if needed
      unet_additional_kwargs = {}
  
      # we add pooled prompt embeds + time_ids to unet kwargs
      if self.xl:
          add_text_embeds = pooled_prompt_embeds
          add_time_ids = self._get_add_time_ids(
              original_size,
              crops_coords_top_left,
              target_size,
              text_embeddings.dtype,
          )
          if do_classifier_free_guidance:
              # TODO: This checks if the time_ids input is looking for time_ids.shape == (12,) or (2, 6)
              # Remove once model input shapes are ubiquitous
              if (
                  len(self.unet.expected_inputs["time_ids"]["shape"])
                  > 1
              ):
                  add_time_ids = [add_time_ids]
  
              add_time_ids = np.concatenate(
                  [add_time_ids, add_time_ids]
              )
  
          unet_additional_kwargs.update(
              {
                  "text_embeds": add_text_embeds.astype(np.float16),
                  "time_ids": add_time_ids.astype(np.float16),
              }
          )
  
      # 5. Prepare timesteps
      self.scheduler.set_timesteps(num_inference_steps)
      timesteps = self.scheduler.timesteps
  
      # 6. Prepare latent variables and controlnet cond
      num_channels_latents = self.unet.in_channels
      latents = self.prepare_latents(
          batch_size * num_images_per_prompt,
          num_channels_latents,
          height,
          width,
          latents,
      )
  
      if controlnet_cond:
          controlnet_cond = self.prepare_control_cond(
              controlnet_cond,
              do_classifier_free_guidance,
              batch_size,
              num_images_per_prompt,
          )
  
      # 7. Prepare extra step kwargs
      extra_step_kwargs = self.prepare_extra_step_kwargs(eta)
  
      # 8. Denoising loop
      for i, t in enumerate(self.progress_bar(timesteps)):
          # expand the latents if we are doing classifier free guidance
          latent_model_input = (
              np.concatenate([latents] * 2)
              if do_classifier_free_guidance
              else latents
          )
          latent_model_input = self.scheduler.scale_model_input(
              latent_model_input, t
          )
  
          if isinstance(latent_model_input, torch.Tensor):
              latent_model_input = latent_model_input.numpy()
  
          # controlnet
          if controlnet_cond:
              control_net_additional_residuals = self.run_controlnet(
                  sample=latent_model_input,
                  timestep=np.array([t, t]),
                  encoder_hidden_states=text_embeddings,
                  controlnet_cond=controlnet_cond,
              )
          else:
              control_net_additional_residuals = {}
  
          # predict the noise residual
          unet_additional_kwargs.update(
              control_net_additional_residuals
          )
  
          noise_pred = self.unet(
              sample=latent_model_input.astype(np.float16),
              timestep=np.array([t, t], np.float16),
              encoder_hidden_states=text_embeddings.astype(np.float16),
              **unet_additional_kwargs,
          )["noise_pred"]
  
          # perform guidance
          if do_classifier_free_guidance:
              noise_pred_uncond, noise_pred_text = np.split(
                  noise_pred, 2
              )
              noise_pred = noise_pred_uncond + guidance_scale * (
                  noise_pred_text - noise_pred_uncond
              )
  
          # compute the previous noisy sample x_t -> x_t-1
          latents = self.scheduler.step(
              torch.from_numpy(noise_pred),
              t,
              torch.from_numpy(latents),
              **extra_step_kwargs,
          ).prev_sample.numpy()
  
          # call the callback, if provided
          if callback is not None and i % callback_steps == 0:
              callback(i, t, latents)
  
      # 8. Post-processing
      image = self.decode_latents(latents)
  
      # 9. Run safety checker
      image, has_nsfw_concept = self.run_safety_checker(image)
  
      # 10. Convert to PIL
      if output_type == "pil":
          image = self.numpy_to_pil(image)
  
      if not return_dict:
          return (image, has_nsfw_concept)
  
      return StableDiffusionPipelineOutput(
          images=image, nsfw_content_detected=has_nsfw_concept
      )
  
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 11 for calling the CoreMLStableDiffusionPipeline obj's underlying member method code with example usage: obj.__call__(prompt, height, width, num_inference_steps, guidance_scale, negative_prompt, num_images_per_prompt, eta, latents, output_type, return_dict, callback, callback_steps, controlnet_cond, original_size, crops_coords_top_left, target_size) and returns: StableDiffusionPipelineOutput, image,  has_nsfw_concept