class_docstr: Inspired by: https://github.com/haofanwang/ControlNet-for-Diffusers/
class_docstr_tok: ["Inspired","by",":","https",":","\/\/github.com\/haofanwang\/ControlNet-for-Diffusers\/"]
code: def prepare_mask_latents(
      self,
      mask_image,
      batch_size,
      height,
      width,
      dtype,
      device,
      do_classifier_free_guidance,
  ):
      # resize the mask to latents shape as we concatenate the mask to the latents
      # we do that before converting to dtype to avoid breaking in case we're using cpu_offload
      # and half precision
      mask_image = F.interpolate(
          mask_image,
          size=(
              height // self.vae_scale_factor,
              width // self.vae_scale_factor,
          ),
      )
      mask_image = mask_image.to(device=device, dtype=dtype)
  
      # duplicate mask for each generation per prompt, using mps friendly method
      if mask_image.shape[0] < batch_size:
          if not batch_size % mask_image.shape[0] == 0:
              raise ValueError(
                  "The passed mask and the required batch size don't match. Masks are supposed to be duplicated to"
                  f" a total batch size of {batch_size}, but {mask_image.shape[0]} masks were passed. Make sure the number"
                  " of masks that you pass is divisible by the total requested batch size."
              )
          mask_image = mask_image.repeat(
              batch_size // mask_image.shape[0], 1, 1, 1
          )
  
      mask_image = (
          torch.cat([mask_image] * 2)
          if do_classifier_free_guidance
          else mask_image
      )
  
      mask_image_latents = mask_image
  
      return mask_image_latents
  
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.stable_diffusion import StableDiffusionPipelineOutput, StableDiffusionSafetyChecker
  from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_controlnet import MultiControlNetModel
  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 14 for calling the StableDiffusionControlNetInpaintPipeline obj's underlying member method code with example usage: obj.prepare_mask_latents(mask_image, batch_size, height, width, dtype, device, do_classifier_free_guidance) and returns: mask_image_latents