class_docstr: Pipeline for text-guided depth-based image-to-image generation using Stable Diffusion.
  
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
  implemented for all pipelines (downloading, saving, running on a particular device, etc.).
  
  The pipeline also inherits the following loading methods:
      - [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
      - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
      - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
  
  Args:
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
      text_encoder ([`~transformers.CLIPTextModel`]):
          Frozen text-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)).
      tokenizer ([`~transformers.CLIPTokenizer`]):
          A `CLIPTokenizer` to tokenize text.
      unet ([`UNet2DConditionModel`]):
          A `UNet2DConditionModel` to denoise the encoded image latents.
      scheduler ([`SchedulerMixin`]):
          A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
          [`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
code: def prepare_latents(
      self,
      image,
      timestep,
      batch_size,
      num_images_per_prompt,
      dtype,
      device,
      generator=None,
  ):
      if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
          raise ValueError(
              f"`image` has to be of type `torch.Tensor`, `PIL.Image.Image` or list but is {type(image)}"
          )
  
      image = image.to(device=device, dtype=dtype)
  
      batch_size = batch_size * num_images_per_prompt
  
      if image.shape[1] == 4:
          init_latents = image
  
      else:
          if (
              isinstance(generator, list)
              and len(generator) != batch_size
          ):
              raise ValueError(
                  f"You have passed a list of generators of length {len(generator)}, but requested an effective batch"
                  f" size of {batch_size}. Make sure the batch size matches the length of the generators."
              )
  
          elif isinstance(generator, list):
              init_latents = [
                  retrieve_latents(
                      self.vae.encode(image[i : i + 1]),
                      generator=generator[i],
                  )
                  for i in range(batch_size)
              ]
              init_latents = torch.cat(init_latents, dim=0)
          else:
              init_latents = retrieve_latents(
                  self.vae.encode(image), generator=generator
              )
  
          init_latents = self.vae.config.scaling_factor * init_latents
  
      if (
          batch_size > init_latents.shape[0]
          and batch_size % init_latents.shape[0] == 0
      ):
          # expand init_latents for batch_size
          deprecation_message = (
              f"You have passed {batch_size} text prompts (`prompt`), but only {init_latents.shape[0]} initial"
              " images (`image`). Initial images are now duplicating to match the number of text prompts. Note"
              " that this behavior is deprecated and will be removed in a version 1.0.0. Please make sure to update"
              " your script to pass as many initial images as text prompts to suppress this warning."
          )
          deprecate(
              "len(prompt) != len(image)",
              "1.0.0",
              deprecation_message,
              standard_warn=False,
          )
          additional_image_per_prompt = (
              batch_size // init_latents.shape[0]
          )
          init_latents = torch.cat(
              [init_latents] * additional_image_per_prompt, dim=0
          )
      elif (
          batch_size > init_latents.shape[0]
          and batch_size % init_latents.shape[0] != 0
      ):
          raise ValueError(
              f"Cannot duplicate `image` of batch size {init_latents.shape[0]} to {batch_size} text prompts."
          )
      else:
          init_latents = torch.cat([init_latents], dim=0)
  
      shape = init_latents.shape
      noise = randn_tensor(
          shape, generator=generator, device=device, dtype=dtype
      )
  
      # get latents
      init_latents = self.scheduler.add_noise(
          init_latents, noise, timestep
      )
      latents = init_latents
  
      return latents
  
imports: import contextlib
  import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from packaging import version
  from transformers import CLIPTextModel, CLIPTokenizer, DPTFeatureExtractor, DPTForDepthEstimation
  from ...configuration_utils import FrozenDict
  from ...image_processor import PipelineImageInput, VaeImageProcessor
  from ...loaders import LoraLoaderMixin, TextualInversionLoaderMixin
  from ...models import AutoencoderKL, UNet2DConditionModel
  from ...models.lora import adjust_lora_scale_text_encoder
  from ...schedulers import KarrasDiffusionSchedulers
  from ...utils import PIL_INTERPOLATION, USE_PEFT_BACKEND, deprecate, logging, scale_lora_layers, unscale_lora_layers
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
label_desc: Use image node_id 9 for calling the StableDiffusionDepth2ImgPipeline obj's underlying member method code with example usage: obj.prepare_latents(image, timestep, batch_size, num_images_per_prompt, dtype, device, generator) and returns: latents