class_docstr: Pipeline for text-guided image-to-image generation using stable unCLIP.
  
  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.).
  
  Args:
      feature_extractor ([`CLIPImageProcessor`]):
          Feature extractor for image pre-processing before being encoded.
      image_encoder ([`CLIPVisionModelWithProjection`]):
          CLIP vision model for encoding images.
      image_normalizer ([`StableUnCLIPImageNormalizer`]):
          Used to normalize the predicted image embeddings before the noise is applied and un-normalize the image
          embeddings after the noise has been applied.
      image_noising_scheduler ([`KarrasDiffusionSchedulers`]):
          Noise schedule for adding noise to the predicted image embeddings. The amount of noise to add is determined
          by the `noise_level`.
      tokenizer (`~transformers.CLIPTokenizer`):
          A [`~transformers.CLIPTokenizer`)].
      text_encoder ([`~transformers.CLIPTextModel`]):
          Frozen [`~transformers.CLIPTextModel`] text-encoder.
      unet ([`UNet2DConditionModel`]):
          A [`UNet2DConditionModel`] to denoise the encoded image latents.
      scheduler ([`KarrasDiffusionSchedulers`]):
          A scheduler to be used in combination with `unet` to denoise the encoded image latents.
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
class_docstr_tok: ["Pipeline","for","text-guided","image-to-image","generation","using","stable","unCLIP",".","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.",")",".","Args",":","feature_extractor","(","[","`","CLIPImageProcessor","`","]",")",":","Feature","extractor","for","image","pre-processing","before","being","encoded",".","image_encoder","(","[","`","CLIPVisionModelWithProjection","`","]",")",":","CLIP","vision","model","for","encoding","images",".","image_normalizer","(","[","`","StableUnCLIPImageNormalizer","`","]",")",":","Used","to","normalize","the","predicted","image","embeddings","before","the","noise","is","applied","and","un-normalize","the","image","embeddings","after","the","noise","has","been","applied",".","image_noising_scheduler","(","[","`","KarrasDiffusionSchedulers","`","]",")",":","Noise","schedule","for","adding","noise","to","the","predicted","image","embeddings",".","The","amount","of","noise","to","add","is","determined","by","the","`","noise_level","`",".","tokenizer","(","`","~transformers.CLIPTokenizer","`",")",":","A","[","`","~transformers.CLIPTokenizer","`",")","]",".","text_encoder","(","[","`","~transformers.CLIPTextModel","`","]",")",":","Frozen","[","`","~transformers.CLIPTextModel","`","]","text-encoder",".","unet","(","[","`","UNet2DConditionModel","`","]",")",":","A","[","`","UNet2DConditionModel","`","]","to","denoise","the","encoded","image","latents",".","scheduler","(","[","`","KarrasDiffusionSchedulers","`","]",")",":","A","scheduler","to","be","used","in","combination","with","`","unet","`","to","denoise","the","encoded","image","latents",".","vae","(","[","`","AutoencoderKL","`","]",")",":","Variational","Auto-Encoder","(","VAE",")","Model","to","encode","and","decode","images","to","and","from","latent","representations","."]
docstr: Add noise to the image embeddings. The amount of noise is controlled by a `noise_level` input. A higher
  `noise_level` increases the variance in the final un-noised images.
  
  The noise is applied in two ways:
  1. A noise schedule is applied directly to the embeddings.
  2. A vector of sinusoidal time embeddings are appended to the output.
  
  In both cases, the amount of noise is controlled by the same `noise_level`.
  
  The embeddings are normalized before the noise is applied and un-normalized after the noise is applied.
docstr_tok: ["Add","noise","to","the","image","embeddings",".","The","amount","of","noise","is","controlled","by","a","`","noise_level","`","input",".","A","higher","`","noise_level","`","increases","the","variance","in","the","final","un-noised","images",".","The","noise","is","applied","in","two","ways",":","1",".","A","noise","schedule","is","applied","directly","to","the","embeddings",".","2",".","A","vector","of","sinusoidal","time","embeddings","are","appended","to","the","output",".","In","both","cases",",","the","amount","of","noise","is","controlled","by","the","same","`","noise_level","`",".","The","embeddings","are","normalized","before","the","noise","is","applied","and","un-normalized","after","the","noise","is","applied","."]
code: def noise_image_embeddings(
      self,
      image_embeds: torch.Tensor,
      noise_level: int,
      noise: Optional[torch.FloatTensor] = None,
      generator: Optional[torch.Generator] = None,
  ):
      """
      Add noise to the image embeddings. The amount of noise is controlled by a `noise_level` input. A higher
      `noise_level` increases the variance in the final un-noised images.
  
      The noise is applied in two ways:
      1. A noise schedule is applied directly to the embeddings.
      2. A vector of sinusoidal time embeddings are appended to the output.
  
      In both cases, the amount of noise is controlled by the same `noise_level`.
  
      The embeddings are normalized before the noise is applied and un-normalized after the noise is applied.
      """
      if noise is None:
          noise = randn_tensor(
              image_embeds.shape,
              generator=generator,
              device=image_embeds.device,
              dtype=image_embeds.dtype,
          )
  
      noise_level = torch.tensor(
          [noise_level] * image_embeds.shape[0],
          device=image_embeds.device,
      )
  
      self.image_normalizer.to(image_embeds.device)
      image_embeds = self.image_normalizer.scale(image_embeds)
  
      image_embeds = self.image_noising_scheduler.add_noise(
          image_embeds, timesteps=noise_level, noise=noise
      )
  
      image_embeds = self.image_normalizer.unscale(image_embeds)
  
      noise_level = get_timestep_embedding(
          timesteps=noise_level,
          embedding_dim=image_embeds.shape[-1],
          flip_sin_to_cos=True,
          downscale_freq_shift=0,
      )
  
      # `get_timestep_embeddings` does not contain any weights and will always return f32 tensors,
      # but we might actually be running in fp16. so we need to cast here.
      # there might be better ways to encapsulate this.
      noise_level = noise_level.to(image_embeds.dtype)
  
      image_embeds = torch.cat((image_embeds, noise_level), 1)
  
      return image_embeds
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import PIL.Image
  import torch
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer, CLIPVisionModelWithProjection
  from ...image_processor import VaeImageProcessor
  from ...loaders import LoraLoaderMixin, TextualInversionLoaderMixin
  from ...models import AutoencoderKL, UNet2DConditionModel
  from ...models.embeddings import get_timestep_embedding
  from ...models.lora import adjust_lora_scale_text_encoder
  from ...schedulers import KarrasDiffusionSchedulers
  from ...utils import USE_PEFT_BACKEND, deprecate, logging, replace_example_docstring, scale_lora_layers, unscale_lora_layers
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
  from .stable_unclip_image_normalizer import StableUnCLIPImageNormalizer
label_desc: Use image node_id 11 for calling the StableUnCLIPImg2ImgPipeline obj's underlying member method code with example usage: obj.noise_image_embeddings(image_embeds, noise_level, noise, generator) and returns: image_embeds