class_docstr: Pipeline for text-to-image generation using Stable Diffusion.
  
  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.)
  
  Args:
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
      text_encoder ([`CLIPTextModel`]):
          Frozen text-encoder. Stable Diffusion uses the text portion of
          [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel), specifically
          the [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) variant.
      tokenizer (`CLIPTokenizer`):
          Tokenizer of class
          [CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
      unet ([`UNet2DConditionModel`]): Conditional U-Net architecture 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`].
      safety_checker ([`StableDiffusionSafetyChecker`]):
          Classification module that estimates whether generated images could be considered offensive or harmful.
          Please, refer to the [model card](https://huggingface.co/runwayml/stable-diffusion-v1-5) for details.
      feature_extractor ([`CLIPImageProcessor`]):
          Model that extracts features from generated images to be used as inputs for the `safety_checker`.
class_docstr_tok: ["Pipeline","for","text-to-image","generation","using","Stable","Diffusion",".","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",".",")","Args",":","vae","(","[","`","AutoencoderKL","`","]",")",":","Variational","Auto-Encoder","(","VAE",")","Model","to","encode","and","decode","images","to","and","from","latent","representations",".","text_encoder","(","[","`","CLIPTextModel","`","]",")",":","Frozen","text-encoder",".","Stable","Diffusion","uses","the","text","portion","of","[","CLIP","]","(","https",":","\/\/huggingface.co\/docs\/transformers\/model_doc\/clip","#","transformers.CLIPTextModel",")",",","specifically","the","[","clip-vit-large-patch14","]","(","https",":","\/\/huggingface.co\/openai\/clip-vit-large-patch14",")","variant",".","tokenizer","(","`","CLIPTokenizer","`",")",":","Tokenizer","of","class","[","CLIPTokenizer","]","(","https",":","\/\/huggingface.co\/docs\/transformers\/v4.21.0\/en\/model_doc\/clip","#","transformers.CLIPTokenizer",")",".","unet","(","[","`","UNet2DConditionModel","`","]",")",":","Conditional","U-Net","architecture","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","`","]",".","safety_checker","(","[","`","StableDiffusionSafetyChecker","`","]",")",":","Classification","module","that","estimates","whether","generated","images","could","be","considered","offensive","or","harmful",".","Please",",","refer","to","the","[","model","card","]","(","https",":","\/\/huggingface.co\/runwayml\/stable-diffusion-v1-5",")","for","details",".","feature_extractor","(","[","`","CLIPImageProcessor","`","]",")",":","Model","that","extracts","features","from","generated","images","to","be","used","as","inputs","for","the","`","safety_checker","`","."]
docstr: Encodes the prompt into text encoder hidden states.
  
  Args:
      prompt (`str` or `list(int)`):
          prompt to be encoded
      device: (`torch.device`):
          torch device
      num_images_per_prompt (`int`):
          number of images that should be generated per prompt
      do_classifier_free_guidance (`bool`):
          whether to use classifier free guidance or not
      negative_prompt (`str` or `List[str]`):
          The prompt or prompts not to guide the image generation. Ignored when not using guidance (i.e., ignored
          if `guidance_scale` is less than `1`).
docstr_tok: ["Encodes","the","prompt","into","text","encoder","hidden","states",".","Args",":","prompt","(","`","str","`","or","`","list","(","int",")","`",")",":","prompt","to","be","encoded","device",":","(","`","torch.device","`",")",":","torch","device","num_images_per_prompt","(","`","int","`",")",":","number","of","images","that","should","be","generated","per","prompt","do_classifier_free_guidance","(","`","bool","`",")",":","whether","to","use","classifier","free","guidance","or","not","negative_prompt","(","`","str","`","or","`","List","[","str","]","`",")",":","The","prompt","or","prompts","not","to","guide","the","image","generation",".","Ignored","when","not","using","guidance","(","i.e.",",","ignored","if","`","guidance_scale","`","is","less","than","`","1","`",")","."]
code: def _encode_prompt(
      self,
      prompt,
      device,
      num_images_per_prompt,
      do_classifier_free_guidance,
      negative_prompt,
  ):
      r"""
      Encodes the prompt into text encoder hidden states.
  
      Args:
          prompt (`str` or `list(int)`):
              prompt to be encoded
          device: (`torch.device`):
              torch device
          num_images_per_prompt (`int`):
              number of images that should be generated per prompt
          do_classifier_free_guidance (`bool`):
              whether to use classifier free guidance or not
          negative_prompt (`str` or `List[str]`):
              The prompt or prompts not to guide the image generation. Ignored when not using guidance (i.e., ignored
              if `guidance_scale` is less than `1`).
      """
      batch_size = len(prompt) if isinstance(prompt, list) else 1
  
      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
      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}"
          )
  
      if (
          hasattr(self.text_encoder.config, "use_attention_mask")
          and self.text_encoder.config.use_attention_mask
      ):
          attention_mask = text_inputs.attention_mask.to(device)
      else:
          attention_mask = None
  
      text_embeddings = self.text_encoder(
          text_input_ids.to(device),
          attention_mask=attention_mask,
      )
      text_embeddings = text_embeddings[0]
  
      # duplicate text embeddings for each generation per prompt, using mps friendly method
      bs_embed, seq_len, _ = text_embeddings.shape
      text_embeddings = text_embeddings.repeat(
          1, num_images_per_prompt, 1
      )
      text_embeddings = text_embeddings.view(
          bs_embed * num_images_per_prompt, seq_len, -1
      )
  
      # get unconditional embeddings for classifier free guidance
      if 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
  
          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",
          )
  
          if (
              hasattr(self.text_encoder.config, "use_attention_mask")
              and self.text_encoder.config.use_attention_mask
          ):
              attention_mask = uncond_input.attention_mask.to(device)
          else:
              attention_mask = None
  
          uncond_embeddings = self.text_encoder(
              uncond_input.input_ids.to(device),
              attention_mask=attention_mask,
          )
          uncond_embeddings = uncond_embeddings[0]
  
          # duplicate unconditional embeddings for each generation per prompt, using mps friendly method
          seq_len = uncond_embeddings.shape[1]
          uncond_embeddings = uncond_embeddings.repeat(
              1, num_images_per_prompt, 1
          )
          uncond_embeddings = uncond_embeddings.view(
              batch_size * num_images_per_prompt, seq_len, -1
          )
  
          # 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
          text_embeddings = torch.cat(
              [uncond_embeddings, text_embeddings]
          )
  
      return text_embeddings
  
imports: import inspect
  from typing import Callable, List, Optional, Union
  import torch
  from packaging import version
  from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
  from diffusers import DiffusionPipeline
  from diffusers.configuration_utils import FrozenDict
  from diffusers.models import AutoencoderKL, UNet2DConditionModel
  from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion import StableDiffusionPipelineOutput
  from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
  from diffusers.schedulers import DDIMScheduler, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler, EulerDiscreteScheduler, LMSDiscreteScheduler, PNDMScheduler
  from diffusers.utils import deprecate, is_accelerate_available, logging
label_desc: Use image node_id 6 for calling the ComposableStableDiffusionPipeline obj's underlying member method code with example usage: obj._encode_prompt(prompt, device, num_images_per_prompt, do_classifier_free_guidance, negative_prompt) and returns: text_embeddings