class_docstr: Pipeline to generate image variations from an input image using 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:
      text_encoder ([`~transformers.CLIPTextModelWithProjection`]):
          Frozen text-encoder.
      tokenizer ([`~transformers.CLIPTokenizer`]):
          A `CLIPTokenizer` to tokenize text.
      feature_extractor ([`~transformers.CLIPImageProcessor`]):
          Model that extracts features from generated images to be used as inputs for the `image_encoder`.
      image_encoder ([`~transformers.CLIPVisionModelWithProjection`]):
          Frozen CLIP image-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)).
      text_proj ([`UnCLIPTextProjModel`]):
          Utility class to prepare and combine the embeddings before they are passed to the decoder.
      decoder ([`UNet2DConditionModel`]):
          The decoder to invert the image embedding into an image.
      super_res_first ([`UNet2DModel`]):
          Super resolution UNet. Used in all but the last step of the super resolution diffusion process.
      super_res_last ([`UNet2DModel`]):
          Super resolution UNet. Used in the last step of the super resolution diffusion process.
      decoder_scheduler ([`UnCLIPScheduler`]):
          Scheduler used in the decoder denoising process (a modified [`DDPMScheduler`]).
      super_res_scheduler ([`UnCLIPScheduler`]):
          Scheduler used in the super resolution denoising process (a modified [`DDPMScheduler`]).
class_docstr_tok: ["Pipeline","to","generate","image","variations","from","an","input","image","using","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",":","text_encoder","(","[","`","~transformers.CLIPTextModelWithProjection","`","]",")",":","Frozen","text-encoder",".","tokenizer","(","[","`","~transformers.CLIPTokenizer","`","]",")",":","A","`","CLIPTokenizer","`","to","tokenize","text",".","feature_extractor","(","[","`","~transformers.CLIPImageProcessor","`","]",")",":","Model","that","extracts","features","from","generated","images","to","be","used","as","inputs","for","the","`","image_encoder","`",".","image_encoder","(","[","`","~transformers.CLIPVisionModelWithProjection","`","]",")",":","Frozen","CLIP","image-encoder","(","[","clip-vit-large-patch14","]","(","https",":","\/\/huggingface.co\/openai\/clip-vit-large-patch14",")",")",".","text_proj","(","[","`","UnCLIPTextProjModel","`","]",")",":","Utility","class","to","prepare","and","combine","the","embeddings","before","they","are","passed","to","the","decoder",".","decoder","(","[","`","UNet2DConditionModel","`","]",")",":","The","decoder","to","invert","the","image","embedding","into","an","image",".","super_res_first","(","[","`","UNet2DModel","`","]",")",":","Super","resolution","UNet",".","Used","in","all","but","the","last","step","of","the","super","resolution","diffusion","process",".","super_res_last","(","[","`","UNet2DModel","`","]",")",":","Super","resolution","UNet",".","Used","in","the","last","step","of","the","super","resolution","diffusion","process",".","decoder_scheduler","(","[","`","UnCLIPScheduler","`","]",")",":","Scheduler","used","in","the","decoder","denoising","process","(","a","modified","[","`","DDPMScheduler","`","]",")",".","super_res_scheduler","(","[","`","UnCLIPScheduler","`","]",")",":","Scheduler","used","in","the","super","resolution","denoising","process","(","a","modified","[","`","DDPMScheduler","`","]",")","."]
code: def _encode_prompt(
      self,
      prompt,
      device,
      num_images_per_prompt,
      do_classifier_free_guidance,
  ):
      batch_size = len(prompt) if isinstance(prompt, list) else 1
  
      # get prompt text embeddings
      text_inputs = self.tokenizer(
          prompt,
          padding="max_length",
          max_length=self.tokenizer.model_max_length,
          return_tensors="pt",
      )
      text_input_ids = text_inputs.input_ids
      text_mask = text_inputs.attention_mask.bool().to(device)
      text_encoder_output = self.text_encoder(text_input_ids.to(device))
  
      prompt_embeds = text_encoder_output.text_embeds
      text_encoder_hidden_states = text_encoder_output.last_hidden_state
  
      prompt_embeds = prompt_embeds.repeat_interleave(
          num_images_per_prompt, dim=0
      )
      text_encoder_hidden_states = (
          text_encoder_hidden_states.repeat_interleave(
              num_images_per_prompt, dim=0
          )
      )
      text_mask = text_mask.repeat_interleave(
          num_images_per_prompt, dim=0
      )
  
      if do_classifier_free_guidance:
          uncond_tokens = [""] * batch_size
  
          max_length = text_input_ids.shape[-1]
          uncond_input = self.tokenizer(
              uncond_tokens,
              padding="max_length",
              max_length=max_length,
              truncation=True,
              return_tensors="pt",
          )
          uncond_text_mask = uncond_input.attention_mask.bool().to(
              device
          )
          negative_prompt_embeds_text_encoder_output = (
              self.text_encoder(uncond_input.input_ids.to(device))
          )
  
          negative_prompt_embeds = (
              negative_prompt_embeds_text_encoder_output.text_embeds
          )
          uncond_text_encoder_hidden_states = (
              negative_prompt_embeds_text_encoder_output.last_hidden_state
          )
  
          # duplicate unconditional embeddings for each generation per prompt, using mps friendly method
  
          seq_len = negative_prompt_embeds.shape[1]
          negative_prompt_embeds = negative_prompt_embeds.repeat(
              1, num_images_per_prompt
          )
          negative_prompt_embeds = negative_prompt_embeds.view(
              batch_size * num_images_per_prompt, seq_len
          )
  
          seq_len = uncond_text_encoder_hidden_states.shape[1]
          uncond_text_encoder_hidden_states = (
              uncond_text_encoder_hidden_states.repeat(
                  1, num_images_per_prompt, 1
              )
          )
          uncond_text_encoder_hidden_states = (
              uncond_text_encoder_hidden_states.view(
                  batch_size * num_images_per_prompt, seq_len, -1
              )
          )
          uncond_text_mask = uncond_text_mask.repeat_interleave(
              num_images_per_prompt, dim=0
          )
  
          # done duplicates
  
          # For classifier free guidance, we need to do two forward passes.
          # Here we concatenate the unconditional and text embeddings into a single batch
          # to avoid doing two forward passes
          prompt_embeds = torch.cat(
              [negative_prompt_embeds, prompt_embeds]
          )
          text_encoder_hidden_states = torch.cat(
              [
                  uncond_text_encoder_hidden_states,
                  text_encoder_hidden_states,
              ]
          )
  
          text_mask = torch.cat([uncond_text_mask, text_mask])
  
      return prompt_embeds, text_encoder_hidden_states, text_mask
  
file_path: llmga/llmga/diffusers/src/diffusers/pipelines/unclip/pipeline_unclip_image_variation.py
imports: import inspect
  from typing import List, Optional, Union
  import PIL.Image
  import torch
  from torch.nn import functional
  from transformers import CLIPImageProcessor, CLIPTextModelWithProjection, CLIPTokenizer, CLIPVisionModelWithProjection
  from ...models import UNet2DConditionModel, UNet2DModel
  from ...schedulers import UnCLIPScheduler
  from ...utils import logging
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
  from .text_proj import UnCLIPTextProjModel
label_desc: Use image node_id 3 for calling the UnCLIPImageVariationPipeline obj's underlying member method code with example usage: obj._encode_prompt(prompt, device, num_images_per_prompt, do_classifier_free_guidance) and returns: prompt_embeds,  text_encoder_hidden_states,  text_mask