class_docstr: Inspired by: https://github.com/haofanwang/ControlNet-for-Diffusers/
class_docstr_tok: ["Inspired","by",":","https",":","\/\/github.com\/haofanwang\/ControlNet-for-Diffusers\/"]
docstr: Function invoked when calling the pipeline for generation.
  
  Args:
      prompt (`str` or `List[str]`, *optional*):
          The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
          instead.
      image (`torch.Tensor` or `PIL.Image.Image`):
          `Image`, or tensor representing an image batch which will be inpainted, *i.e.* parts of the image will
          be masked out with `mask_image` and repainted according to `prompt`.
      mask_image (`torch.Tensor` or `PIL.Image.Image`):
          `Image`, or tensor representing an image batch, to mask `image`. White pixels in the mask will be
          repainted, while black pixels will be preserved. If `mask_image` is a PIL image, it will be converted
          to a single channel (luminance) before use. If it's a tensor, it should contain one color channel (L)
          instead of 3, so the expected shape would be `(B, H, W, 1)`.
      controlnet_conditioning_image (`torch.FloatTensor`, `PIL.Image.Image`, `List[torch.FloatTensor]` or `List[PIL.Image.Image]`):
          The ControlNet input condition. ControlNet uses this input condition to generate guidance to Unet. If
          the type is specified as `Torch.FloatTensor`, it is passed to ControlNet as is. PIL.Image.Image` can
          also be accepted as an image. The control image is automatically resized to fit the output image.
      height (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
          The height in pixels of the generated image.
      width (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
          The width in pixels of the generated image.
      num_inference_steps (`int`, *optional*, defaults to 50):
          The number of denoising steps. More denoising steps usually lead to a higher quality image at the
          expense of slower inference.
      guidance_scale (`float`, *optional*, defaults to 7.5):
          Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
          `guidance_scale` is defined as `w` of equation 2. of [Imagen
          Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
          1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`,
          usually at the expense of lower image quality.
      negative_prompt (`str` or `List[str]`, *optional*):
          The prompt or prompts not to guide the image generation. If not defined, one has to pass `negative_prompt_embeds` instead.
          Ignored when not using guidance (i.e., ignored if `guidance_scale` is less than `1`).
      num_images_per_prompt (`int`, *optional*, defaults to 1):
          The number of images to generate per prompt.
      eta (`float`, *optional*, defaults to 0.0):
          Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
          [`schedulers.DDIMScheduler`], will be ignored for others.
      generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
          One or a list of [torch generator(s)](https://pytorch.org/docs/stable/generated/torch.Generator.html)
          to make generation deterministic.
      latents (`torch.FloatTensor`, *optional*):
          Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
          generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
          tensor will ge generated by sampling using the supplied random `generator`.
      prompt_embeds (`torch.FloatTensor`, *optional*):
          Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
          provided, text embeddings will be generated from `prompt` input argument.
      negative_prompt_embeds (`torch.FloatTensor`, *optional*):
          Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
          weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
          argument.
      output_type (`str`, *optional*, defaults to `"pil"`):
          The output format of the generate image. Choose between
          [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`.
      return_dict (`bool`, *optional*, defaults to `True`):
          Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] instead of a
          plain tuple.
      callback (`Callable`, *optional*):
          A function that will be called every `callback_steps` steps during inference. The function will be
          called with the following arguments: `callback(step: int, timestep: int, latents: torch.FloatTensor)`.
      callback_steps (`int`, *optional*, defaults to 1):
          The frequency at which the `callback` function will be called. If not specified, the callback will be
          called at every step.
      cross_attention_kwargs (`dict`, *optional*):
          A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
          `self.processor` in
          [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
      controlnet_conditioning_scale (`float`, *optional*, defaults to 1.0):
          The outputs of the controlnet are multiplied by `controlnet_conditioning_scale` before they are added
          to the residual in the original unet.
  
  Examples:
  
  Returns:
      [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`:
      [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple.
      When returning a tuple, the first element is a list with the generated images, and the second element is a
      list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work"
      (nsfw) content, according to the `safety_checker`.
docstr_tok: ["Function","invoked","when","calling","the","pipeline","for","generation",".","Args",":","prompt","(","`","str","`","or","`","List","[","str","]","`",",","*","optional","*",")",":","The","prompt","or","prompts","to","guide","the","image","generation",".","If","not","defined",",","one","has","to","pass","`","prompt_embeds","`",".","instead",".","image","(","`","torch.Tensor","`","or","`","PIL.Image.Image","`",")",":","`","Image","`",",","or","tensor","representing","an","image","batch","which","will","be","inpainted",",","*","i.e",".","*","parts","of","the","image","will","be","masked","out","with","`","mask_image","`","and","repainted","according","to","`","prompt","`",".","mask_image","(","`","torch.Tensor","`","or","`","PIL.Image.Image","`",")",":","`","Image","`",",","or","tensor","representing","an","image","batch",",","to","mask","`","image","`",".","White","pixels","in","the","mask","will","be","repainted",",","while","black","pixels","will","be","preserved",".","If","`","mask_image","`","is","a","PIL","image",",","it","will","be","converted","to","a","single","channel","(","luminance",")","before","use",".","If","it","'s","a","tensor",",","it","should","contain","one","color","channel","(","L",")","instead","of","3",",","so","the","expected","shape","would","be","`","(","B",",","H",",","W",",","1",")","`",".","controlnet_conditioning_image","(","`","torch.FloatTensor","`",",","`","PIL.Image.Image","`",",","`","List","[","torch.FloatTensor","]","`","or","`","List","[","PIL.Image.Image","]","`",")",":","The","ControlNet","input","condition",".","ControlNet","uses","this","input","condition","to","generate","guidance","to","Unet",".","If","the","type","is","specified","as","`","Torch.FloatTensor","`",",","it","is","passed","to","ControlNet","as","is",".","PIL.Image.Image","`","can","also","be","accepted","as","an","image",".","The","control","image","is","automatically","resized","to","fit","the","output","image",".","height","(","`","int","`",",","*","optional","*",",","defaults","to","self.unet.config.sample_size","*","self.vae_scale_factor",")",":","The","height","in","pixels","of","the","generated","image",".","width","(","`","int","`",",","*","optional","*",",","defaults","to","self.unet.config.sample_size","*","self.vae_scale_factor",")",":","The","width","in","pixels","of","the","generated","image",".","num_inference_steps","(","`","int","`",",","*","optional","*",",","defaults","to","50",")",":","The","number","of","denoising","steps",".","More","denoising","steps","usually","lead","to","a","higher","quality","image","at","the","expense","of","slower","inference",".","guidance_scale","(","`","float","`",",","*","optional","*",",","defaults","to","7.5",")",":","Guidance","scale","as","defined","in","[","Classifier-Free","Diffusion","Guidance","]","(","https",":","\/\/arxiv.org\/abs\/2207.12598",")",".","`","guidance_scale","`","is","defined","as","`","w","`","of","equation","2.","of","[","Imagen","Paper","]","(","https",":","\/\/arxiv.org\/pdf\/2205.11487.pdf",")",".","Guidance","scale","is","enabled","by","setting","`","guidance_scale",">","1","`",".","Higher","guidance","scale","encourages","to","generate","images","that","are","closely","linked","to","the","text","`","prompt","`",",","usually","at","the","expense","of","lower","image","quality",".","negative_prompt","(","`","str","`","or","`","List","[","str","]","`",",","*","optional","*",")",":","The","prompt","or","prompts","not","to","guide","the","image","generation",".","If","not","defined",",","one","has","to","pass","`","negative_prompt_embeds","`","instead",".","Ignored","when","not","using","guidance","(","i.e.",",","ignored","if","`","guidance_scale","`","is","less","than","`","1","`",")",".","num_images_per_prompt","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","The","number","of","images","to","generate","per","prompt",".","eta","(","`","float","`",",","*","optional","*",",","defaults","to","0.0",")",":","Corresponds","to","parameter","eta","(","\u03b7",")","in","the","DDIM","paper",":","https",":","\/\/arxiv.org\/abs\/2010.02502",".","Only","applies","to","[","`","schedulers.DDIMScheduler","`","]",",","will","be","ignored","for","others",".","generator","(","`","torch.Generator","`","or","`","List","[","torch.Generator","]","`",",","*","optional","*",")",":","One","or","a","list","of","[","torch","generator","(","s",")","]","(","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.Generator.html",")","to","make","generation","deterministic",".","latents","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","noisy","latents",",","sampled","from","a","Gaussian","distribution",",","to","be","used","as","inputs","for","image","generation",".","Can","be","used","to","tweak","the","same","generation","with","different","prompts",".","If","not","provided",",","a","latents","tensor","will","ge","generated","by","sampling","using","the","supplied","random","`","generator","`",".","prompt_embeds","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","text","embeddings",".","Can","be","used","to","easily","tweak","text","inputs",",","*","e.g",".","*","prompt","weighting",".","If","not","provided",",","text","embeddings","will","be","generated","from","`","prompt","`","input","argument",".","negative_prompt_embeds","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","negative","text","embeddings",".","Can","be","used","to","easily","tweak","text","inputs",",","*","e.g",".","*","prompt","weighting",".","If","not","provided",",","negative_prompt_embeds","will","be","generated","from","`","negative_prompt","`","input","argument",".","output_type","(","`","str","`",",","*","optional","*",",","defaults","to","`","``","pil","''","`",")",":","The","output","format","of","the","generate","image",".","Choose","between","[","PIL","]","(","https",":","\/\/pillow.readthedocs.io\/en\/stable\/",")",":","`","PIL.Image.Image","`","or","`","np.array","`",".","return_dict","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","to","return","a","[","`","~pipelines.stable_diffusion.StableDiffusionPipelineOutput","`","]","instead","of","a","plain","tuple",".","callback","(","`","Callable","`",",","*","optional","*",")",":","A","function","that","will","be","called","every","`","callback_steps","`","steps","during","inference",".","The","function","will","be","called","with","the","following","arguments",":","`","callback","(","step",":","int",",","timestep",":","int",",","latents",":","torch.FloatTensor",")","`",".","callback_steps","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","The","frequency","at","which","the","`","callback","`","function","will","be","called",".","If","not","specified",",","the","callback","will","be","called","at","every","step",".","cross_attention_kwargs","(","`","dict","`",",","*","optional","*",")",":","A","kwargs","dictionary","that","if","specified","is","passed","along","to","the","`","AttentionProcessor","`","as","defined","under","`","self.processor","`","in","[","diffusers.models.attention_processor","]","(","https",":","\/\/github.com\/huggingface\/diffusers\/blob\/main\/src\/diffusers\/models\/attention_processor.py",")",".","controlnet_conditioning_scale","(","`","float","`",",","*","optional","*",",","defaults","to","1.0",")",":","The","outputs","of","the","controlnet","are","multiplied","by","`","controlnet_conditioning_scale","`","before","they","are","added","to","the","residual","in","the","original","unet",".","Examples",":","Returns",":","[","`","~pipelines.stable_diffusion.StableDiffusionPipelineOutput","`","]","or","`","tuple","`",":","[","`","~pipelines.stable_diffusion.StableDiffusionPipelineOutput","`","]","if","`","return_dict","`","is","True",",","otherwise","a","`","tuple",".","When","returning","a","tuple",",","the","first","element","is","a","list","with","the","generated","images",",","and","the","second","element","is","a","list","of","`","bool","`","s","denoting","whether","the","corresponding","generated","image","likely","represents","``","not-safe-for-work","''","(","nsfw",")","content",",","according","to","the","`","safety_checker","`","."]
code: def __call__(
      self,
      prompt: Union[str, List[str]] = None,
      image: Union[torch.Tensor, PIL.Image.Image] = None,
      mask_image: Union[torch.Tensor, PIL.Image.Image] = None,
      controlnet_conditioning_image: Union[
          torch.FloatTensor,
          PIL.Image.Image,
          List[torch.FloatTensor],
          List[PIL.Image.Image],
      ] = None,
      height: Optional[int] = None,
      width: Optional[int] = None,
      num_inference_steps: int = 50,
      guidance_scale: float = 7.5,
      negative_prompt: Optional[Union[str, List[str]]] = None,
      num_images_per_prompt: Optional[int] = 1,
      eta: float = 0.0,
      generator: Optional[
          Union[torch.Generator, List[torch.Generator]]
      ] = None,
      latents: Optional[torch.FloatTensor] = None,
      prompt_embeds: Optional[torch.FloatTensor] = None,
      negative_prompt_embeds: Optional[torch.FloatTensor] = None,
      output_type: Optional[str] = "pil",
      return_dict: bool = True,
      callback: Optional[
          Callable[[int, int, torch.FloatTensor], None]
      ] = None,
      callback_steps: int = 1,
      cross_attention_kwargs: Optional[Dict[str, Any]] = None,
      controlnet_conditioning_scale: Union[float, List[float]] = 1.0,
  ):
      r"""
      Function invoked when calling the pipeline for generation.
  
      Args:
          prompt (`str` or `List[str]`, *optional*):
              The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
              instead.
          image (`torch.Tensor` or `PIL.Image.Image`):
              `Image`, or tensor representing an image batch which will be inpainted, *i.e.* parts of the image will
              be masked out with `mask_image` and repainted according to `prompt`.
          mask_image (`torch.Tensor` or `PIL.Image.Image`):
              `Image`, or tensor representing an image batch, to mask `image`. White pixels in the mask will be
              repainted, while black pixels will be preserved. If `mask_image` is a PIL image, it will be converted
              to a single channel (luminance) before use. If it's a tensor, it should contain one color channel (L)
              instead of 3, so the expected shape would be `(B, H, W, 1)`.
          controlnet_conditioning_image (`torch.FloatTensor`, `PIL.Image.Image`, `List[torch.FloatTensor]` or `List[PIL.Image.Image]`):
              The ControlNet input condition. ControlNet uses this input condition to generate guidance to Unet. If
              the type is specified as `Torch.FloatTensor`, it is passed to ControlNet as is. PIL.Image.Image` can
              also be accepted as an image. The control image is automatically resized to fit the output image.
          height (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
              The height in pixels of the generated image.
          width (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
              The width in pixels of the generated image.
          num_inference_steps (`int`, *optional*, defaults to 50):
              The number of denoising steps. More denoising steps usually lead to a higher quality image at the
              expense of slower inference.
          guidance_scale (`float`, *optional*, defaults to 7.5):
              Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
              `guidance_scale` is defined as `w` of equation 2. of [Imagen
              Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
              1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`,
              usually at the expense of lower image quality.
          negative_prompt (`str` or `List[str]`, *optional*):
              The prompt or prompts not to guide the image generation. If not defined, one has to pass `negative_prompt_embeds` instead.
              Ignored when not using guidance (i.e., ignored if `guidance_scale` is less than `1`).
          num_images_per_prompt (`int`, *optional*, defaults to 1):
              The number of images to generate per prompt.
          eta (`float`, *optional*, defaults to 0.0):
              Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
              [`schedulers.DDIMScheduler`], will be ignored for others.
          generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
              One or a list of [torch generator(s)](https://pytorch.org/docs/stable/generated/torch.Generator.html)
              to make generation deterministic.
          latents (`torch.FloatTensor`, *optional*):
              Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
              generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
              tensor will ge generated by sampling using the supplied random `generator`.
          prompt_embeds (`torch.FloatTensor`, *optional*):
              Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
              provided, text embeddings will be generated from `prompt` input argument.
          negative_prompt_embeds (`torch.FloatTensor`, *optional*):
              Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
              weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
              argument.
          output_type (`str`, *optional*, defaults to `"pil"`):
              The output format of the generate image. Choose between
              [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`.
          return_dict (`bool`, *optional*, defaults to `True`):
              Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] instead of a
              plain tuple.
          callback (`Callable`, *optional*):
              A function that will be called every `callback_steps` steps during inference. The function will be
              called with the following arguments: `callback(step: int, timestep: int, latents: torch.FloatTensor)`.
          callback_steps (`int`, *optional*, defaults to 1):
              The frequency at which the `callback` function will be called. If not specified, the callback will be
              called at every step.
          cross_attention_kwargs (`dict`, *optional*):
              A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
              `self.processor` in
              [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
          controlnet_conditioning_scale (`float`, *optional*, defaults to 1.0):
              The outputs of the controlnet are multiplied by `controlnet_conditioning_scale` before they are added
              to the residual in the original unet.
  
      Examples:
  
      Returns:
          [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`:
          [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple.
          When returning a tuple, the first element is a list with the generated images, and the second element is a
          list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work"
          (nsfw) content, according to the `safety_checker`.
      """
      # 0. Default height and width to unet
      height, width = self._default_height_width(
          height, width, controlnet_conditioning_image
      )
  
      # 1. Check inputs. Raise error if not correct
      self.check_inputs(
          prompt,
          image,
          mask_image,
          controlnet_conditioning_image,
          height,
          width,
          callback_steps,
          negative_prompt,
          prompt_embeds,
          negative_prompt_embeds,
          controlnet_conditioning_scale,
      )
  
      # 2. Define call parameters
      if prompt is not None and isinstance(prompt, str):
          batch_size = 1
      elif prompt is not None and isinstance(prompt, list):
          batch_size = len(prompt)
      else:
          batch_size = prompt_embeds.shape[0]
  
      device = self._execution_device
      # 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
  
      if isinstance(
          self.controlnet, MultiControlNetModel
      ) and isinstance(controlnet_conditioning_scale, float):
          controlnet_conditioning_scale = [
              controlnet_conditioning_scale
          ] * len(self.controlnet.nets)
  
      # 3. Encode input prompt
      prompt_embeds = self._encode_prompt(
          prompt,
          device,
          num_images_per_prompt,
          do_classifier_free_guidance,
          negative_prompt,
          prompt_embeds=prompt_embeds,
          negative_prompt_embeds=negative_prompt_embeds,
      )
  
      # 4. Prepare mask, image, and controlnet_conditioning_image
      image = prepare_image(image)
  
      mask_image = prepare_mask_image(mask_image)
  
      # condition image(s)
      if isinstance(self.controlnet, ControlNetModel):
          controlnet_conditioning_image = prepare_controlnet_conditioning_image(
              controlnet_conditioning_image=controlnet_conditioning_image,
              width=width,
              height=height,
              batch_size=batch_size * num_images_per_prompt,
              num_images_per_prompt=num_images_per_prompt,
              device=device,
              dtype=self.controlnet.dtype,
              do_classifier_free_guidance=do_classifier_free_guidance,
          )
      elif isinstance(self.controlnet, MultiControlNetModel):
          controlnet_conditioning_images = []
  
          for image_ in controlnet_conditioning_image:
              image_ = prepare_controlnet_conditioning_image(
                  controlnet_conditioning_image=image_,
                  width=width,
                  height=height,
                  batch_size=batch_size * num_images_per_prompt,
                  num_images_per_prompt=num_images_per_prompt,
                  device=device,
                  dtype=self.controlnet.dtype,
                  do_classifier_free_guidance=do_classifier_free_guidance,
              )
              controlnet_conditioning_images.append(image_)
  
          controlnet_conditioning_image = controlnet_conditioning_images
      else:
          assert False
  
      masked_image = image * (mask_image < 0.5)
  
      # 5. Prepare timesteps
      self.scheduler.set_timesteps(num_inference_steps, device=device)
      timesteps = self.scheduler.timesteps
  
      # 6. Prepare latent variables
      num_channels_latents = self.vae.config.latent_channels
      latents = self.prepare_latents(
          batch_size * num_images_per_prompt,
          num_channels_latents,
          height,
          width,
          prompt_embeds.dtype,
          device,
          generator,
          latents,
      )
  
      mask_image_latents = self.prepare_mask_latents(
          mask_image,
          batch_size * num_images_per_prompt,
          height,
          width,
          prompt_embeds.dtype,
          device,
          do_classifier_free_guidance,
      )
  
      masked_image_latents = self.prepare_masked_image_latents(
          masked_image,
          batch_size * num_images_per_prompt,
          height,
          width,
          prompt_embeds.dtype,
          device,
          generator,
          do_classifier_free_guidance,
      )
  
      # 7. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
      extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
  
      # 8. Denoising loop
      num_warmup_steps = (
          len(timesteps) - num_inference_steps * self.scheduler.order
      )
      with self.progress_bar(total=num_inference_steps) as progress_bar:
          for i, t in enumerate(timesteps):
              # expand the latents if we are doing classifier free guidance
              non_inpainting_latent_model_input = (
                  torch.cat([latents] * 2)
                  if do_classifier_free_guidance
                  else latents
              )
  
              non_inpainting_latent_model_input = (
                  self.scheduler.scale_model_input(
                      non_inpainting_latent_model_input, t
                  )
              )
  
              inpainting_latent_model_input = torch.cat(
                  [
                      non_inpainting_latent_model_input,
                      mask_image_latents,
                      masked_image_latents,
                  ],
                  dim=1,
              )
  
              (
                  down_block_res_samples,
                  mid_block_res_sample,
              ) = self.controlnet(
                  non_inpainting_latent_model_input,
                  t,
                  encoder_hidden_states=prompt_embeds,
                  controlnet_cond=controlnet_conditioning_image,
                  conditioning_scale=controlnet_conditioning_scale,
                  return_dict=False,
              )
  
              # predict the noise residual
              noise_pred = self.unet(
                  inpainting_latent_model_input,
                  t,
                  encoder_hidden_states=prompt_embeds,
                  cross_attention_kwargs=cross_attention_kwargs,
                  down_block_additional_residuals=down_block_res_samples,
                  mid_block_additional_residual=mid_block_res_sample,
              ).sample
  
              # perform guidance
              if do_classifier_free_guidance:
                  noise_pred_uncond, noise_pred_text = noise_pred.chunk(
                      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(
                  noise_pred, t, latents, **extra_step_kwargs
              ).prev_sample
  
              # call the callback, if provided
              if i == len(timesteps) - 1 or (
                  (i + 1) > num_warmup_steps
                  and (i + 1) % self.scheduler.order == 0
              ):
                  progress_bar.update()
                  if callback is not None and i % callback_steps == 0:
                      step_idx = i // getattr(
                          self.scheduler, "order", 1
                      )
                      callback(step_idx, t, latents)
  
      # If we do sequential model offloading, let's offload unet and controlnet
      # manually for max memory savings
      if (
          hasattr(self, "final_offload_hook")
          and self.final_offload_hook is not None
      ):
          self.unet.to("cpu")
          self.controlnet.to("cpu")
          torch.cuda.empty_cache()
  
      if output_type == "latent":
          image = latents
          has_nsfw_concept = None
      elif output_type == "pil":
          # 8. Post-processing
          image = self.decode_latents(latents)
  
          # 9. Run safety checker
          image, has_nsfw_concept = self.run_safety_checker(
              image, device, prompt_embeds.dtype
          )
  
          # 10. Convert to PIL
          image = self.numpy_to_pil(image)
      else:
          # 8. Post-processing
          image = self.decode_latents(latents)
  
          # 9. Run safety checker
          image, has_nsfw_concept = self.run_safety_checker(
              image, device, prompt_embeds.dtype
          )
  
      # Offload last model to CPU
      if (
          hasattr(self, "final_offload_hook")
          and self.final_offload_hook is not None
      ):
          self.final_offload_hook.offload()
  
      if not return_dict:
          return (image, has_nsfw_concept)
  
      return StableDiffusionPipelineOutput(
          images=image, nsfw_content_detected=has_nsfw_concept
      )
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  import PIL.Image
  import torch
  import torch.nn.functional
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
  from diffusers import AutoencoderKL, ControlNetModel, DiffusionPipeline, UNet2DConditionModel, logging
  from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel
  from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput, StableDiffusionSafetyChecker
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import PIL_INTERPOLATION, is_accelerate_available, is_accelerate_version, replace_example_docstring
  from diffusers.utils.torch_utils import randn_tensor
label_desc: Use image node_id 17 for calling the StableDiffusionControlNetInpaintPipeline obj's underlying member method code with example usage: obj.__call__(prompt, image, mask_image, controlnet_conditioning_image, height, width, num_inference_steps, guidance_scale, negative_prompt, num_images_per_prompt, eta, generator, latents, prompt_embeds, negative_prompt_embeds, output_type, return_dict, callback, callback_steps, cross_attention_kwargs, controlnet_conditioning_scale) and returns: StableDiffusionPipelineOutput, image,  has_nsfw_concept