class_docstr: Pipeline for generating image prior for Wuerstchen.
  
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
  library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
  
  The pipeline also inherits the following loading methods:
      - [`~loaders.LoraLoaderMixin.load_lora_weights`] for loading LoRA weights
      - [`~loaders.LoraLoaderMixin.save_lora_weights`] for saving LoRA weights
  
  Args:
      prior ([`Prior`]):
          The canonical unCLIP prior to approximate the image embedding from the text embedding.
      text_encoder ([`CLIPTextModelWithProjection`]):
          Frozen text-encoder.
      tokenizer (`CLIPTokenizer`):
          Tokenizer of class
          [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
      scheduler ([`DDPMWuerstchenScheduler`]):
          A scheduler to be used in combination with `prior` to generate image embedding.
      latent_mean ('float', *optional*, defaults to 42.0):
          Mean value for latent diffusers.
      latent_std ('float', *optional*, defaults to 1.0):
          Standard value for latent diffusers.
      resolution_multiple ('float', *optional*, defaults to 42.67):
          Default resolution for multiple images generated.
code: def encode_prompt(
      self,
      device,
      num_images_per_prompt,
      do_classifier_free_guidance,
      prompt=None,
      negative_prompt=None,
      prompt_embeds: Optional[torch.FloatTensor] = None,
      negative_prompt_embeds: Optional[torch.FloatTensor] = None,
  ):
      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]
  
      if prompt_embeds is None:
          # get prompt text embeddings
          text_inputs = self.tokenizer(
              prompt,
              padding="max_length",
              max_length=self.tokenizer.model_max_length,
              truncation=True,
              return_tensors="pt",
          )
          text_input_ids = text_inputs.input_ids
          attention_mask = text_inputs.attention_mask
  
          untruncated_ids = self.tokenizer(
              prompt, padding="longest", return_tensors="pt"
          ).input_ids
  
          if untruncated_ids.shape[-1] >= text_input_ids.shape[
              -1
          ] and not torch.equal(text_input_ids, untruncated_ids):
              removed_text = self.tokenizer.batch_decode(
                  untruncated_ids[
                      :, self.tokenizer.model_max_length - 1 : -1
                  ]
              )
              logger.warning(
                  "The following part of your input was truncated because CLIP can only handle sequences up to"
                  f" {self.tokenizer.model_max_length} tokens: {removed_text}"
              )
              text_input_ids = text_input_ids[
                  :, : self.tokenizer.model_max_length
              ]
              attention_mask = attention_mask[
                  :, : self.tokenizer.model_max_length
              ]
  
          text_encoder_output = self.text_encoder(
              text_input_ids.to(device),
              attention_mask=attention_mask.to(device),
          )
          prompt_embeds = text_encoder_output.last_hidden_state
  
      prompt_embeds = prompt_embeds.to(
          dtype=self.text_encoder.dtype, device=device
      )
      prompt_embeds = prompt_embeds.repeat_interleave(
          num_images_per_prompt, dim=0
      )
  
      if negative_prompt_embeds is None and do_classifier_free_guidance:
          uncond_tokens: List[str]
          if negative_prompt is None:
              uncond_tokens = [""] * batch_size
          elif type(prompt) is not type(negative_prompt):
              raise TypeError(
                  f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
                  f" {type(prompt)}."
              )
          elif isinstance(negative_prompt, str):
              uncond_tokens = [negative_prompt]
          elif batch_size != len(negative_prompt):
              raise ValueError(
                  f"`negative_prompt`: {negative_prompt} has batch size {len(negative_prompt)}, but `prompt`:"
                  f" {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches"
                  " the batch size of `prompt`."
              )
          else:
              uncond_tokens = negative_prompt
  
          uncond_input = self.tokenizer(
              uncond_tokens,
              padding="max_length",
              max_length=self.tokenizer.model_max_length,
              truncation=True,
              return_tensors="pt",
          )
          negative_prompt_embeds_text_encoder_output = (
              self.text_encoder(
                  uncond_input.input_ids.to(device),
                  attention_mask=uncond_input.attention_mask.to(device),
              )
          )
  
          negative_prompt_embeds = (
              negative_prompt_embeds_text_encoder_output.last_hidden_state
          )
  
      if do_classifier_free_guidance:
          # 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.to(
              dtype=self.text_encoder.dtype, device=device
          )
          negative_prompt_embeds = negative_prompt_embeds.repeat(
              1, num_images_per_prompt, 1
          )
          negative_prompt_embeds = negative_prompt_embeds.view(
              batch_size * num_images_per_prompt, seq_len, -1
          )
          # done duplicates
  
      return prompt_embeds, negative_prompt_embeds
  
imports: from dataclasses import dataclass
  from math import ceil
  from typing import Callable, Dict, List, Optional, Union
  import numpy
  import torch
  from transformers import CLIPTextModel, CLIPTokenizer
  from ...loaders import LoraLoaderMixin
  from ...schedulers import DDPMWuerstchenScheduler
  from ...utils import BaseOutput, deprecate, logging, replace_example_docstring
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline
  from .modeling_wuerstchen_prior import WuerstchenPrior
label_desc: Use image node_id 3 for calling the WuerstchenPriorPipeline obj's underlying member method code with example usage: obj.encode_prompt(device, num_images_per_prompt, do_classifier_free_guidance, prompt, negative_prompt, prompt_embeds, negative_prompt_embeds) and returns: prompt_embeds,  negative_prompt_embeds