class_docstr: Pipeline for text-to-audio generation using MusicLDM.
  
  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:
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
      text_encoder ([`~transformers.ClapModel`]):
          Frozen text-audio embedding model (`ClapTextModel`), specifically the
          [laion/clap-htsat-unfused](https://huggingface.co/laion/clap-htsat-unfused) variant.
      tokenizer ([`PreTrainedTokenizer`]):
          A [`~transformers.RobertaTokenizer`] to tokenize text.
      feature_extractor ([`~transformers.ClapFeatureExtractor`]):
          Feature extractor to compute mel-spectrograms from audio waveforms.
      unet ([`UNet2DConditionModel`]):
          A `UNet2DConditionModel` to denoise the encoded audio latents.
      scheduler ([`SchedulerMixin`]):
          A scheduler to be used in combination with `unet` to denoise the encoded audio latents. Can be one of
          [`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
      vocoder ([`~transformers.SpeechT5HifiGan`]):
          Vocoder of class `SpeechT5HifiGan`.
docstr: Encodes the prompt into text encoder hidden states.
  
  Args:
      prompt (`str` or `List[str]`, *optional*):
          prompt to be encoded
      device (`torch.device`):
          torch device
      num_waveforms_per_prompt (`int`):
          number of waveforms 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]`, *optional*):
          The prompt or prompts not to guide the audio generation. If not defined, one has to pass
          `negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `guidance_scale` is
          less than `1`).
      prompt_embeds (`torch.FloatTensor`, *optional*):
          Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
          provided, text embeddings will be generated from `prompt` input argument.
      negative_prompt_embeds (`torch.FloatTensor`, *optional*):
          Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
          weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
          argument.
docstr_tok: ["Encodes","the","prompt","into","text","encoder","hidden","states",".","Args",":","prompt","(","`","str","`","or","`","List","[","str","]","`",",","*","optional","*",")",":","prompt","to","be","encoded","device","(","`","torch.device","`",")",":","torch","device","num_waveforms_per_prompt","(","`","int","`",")",":","number","of","waveforms","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","]","`",",","*","optional","*",")",":","The","prompt","or","prompts","not","to","guide","the","audio","generation",".","If","not","defined",",","one","has","to","pass","`","negative_prompt_embeds","`","instead",".","Ignored","when","not","using","guidance","(","i.e.",",","ignored","if","`","guidance_scale","`","is","less","than","`","1","`",")",".","prompt_embeds","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","text","embeddings",".","Can","be","used","to","easily","tweak","text","inputs",",","*","e.g",".","*","prompt","weighting",".","If","not","provided",",","text","embeddings","will","be","generated","from","`","prompt","`","input","argument",".","negative_prompt_embeds","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","negative","text","embeddings",".","Can","be","used","to","easily","tweak","text","inputs",",","*","e.g",".","*","prompt","weighting",".","If","not","provided",",","negative_prompt_embeds","will","be","generated","from","`","negative_prompt","`","input","argument","."]
code: def _encode_prompt(
      self,
      prompt,
      device,
      num_waveforms_per_prompt,
      do_classifier_free_guidance,
      negative_prompt=None,
      prompt_embeds: Optional[torch.FloatTensor] = None,
      negative_prompt_embeds: Optional[torch.FloatTensor] = None,
  ):
      r"""
      Encodes the prompt into text encoder hidden states.
  
      Args:
          prompt (`str` or `List[str]`, *optional*):
              prompt to be encoded
          device (`torch.device`):
              torch device
          num_waveforms_per_prompt (`int`):
              number of waveforms 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]`, *optional*):
              The prompt or prompts not to guide the audio generation. If not defined, one has to pass
              `negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `guidance_scale` is
              less than `1`).
          prompt_embeds (`torch.FloatTensor`, *optional*):
              Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
              provided, text embeddings will be generated from `prompt` input argument.
          negative_prompt_embeds (`torch.FloatTensor`, *optional*):
              Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
              weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
              argument.
      """
      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:
          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 CLAP can only handle sequences up to"
                  f" {self.tokenizer.model_max_length} tokens: {removed_text}"
              )
  
          prompt_embeds = self.text_encoder.get_text_features(
              text_input_ids.to(device),
              attention_mask=attention_mask.to(device),
          )
  
      prompt_embeds = prompt_embeds.to(
          dtype=self.text_encoder.text_model.dtype, device=device
      )
  
      (
          bs_embed,
          seq_len,
      ) = prompt_embeds.shape
      # duplicate text embeddings for each generation per prompt, using mps friendly method
      prompt_embeds = prompt_embeds.repeat(1, num_waveforms_per_prompt)
      prompt_embeds = prompt_embeds.view(
          bs_embed * num_waveforms_per_prompt, seq_len
      )
  
      # get unconditional embeddings for classifier free guidance
      if do_classifier_free_guidance and negative_prompt_embeds is None:
          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 = prompt_embeds.shape[1]
          uncond_input = self.tokenizer(
              uncond_tokens,
              padding="max_length",
              max_length=max_length,
              truncation=True,
              return_tensors="pt",
          )
  
          uncond_input_ids = uncond_input.input_ids.to(device)
          attention_mask = uncond_input.attention_mask.to(device)
  
          negative_prompt_embeds = self.text_encoder.get_text_features(
              uncond_input_ids,
              attention_mask=attention_mask,
          )
  
      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.text_model.dtype, device=device
          )
  
          negative_prompt_embeds = negative_prompt_embeds.repeat(
              1, num_waveforms_per_prompt
          )
          negative_prompt_embeds = negative_prompt_embeds.view(
              batch_size * num_waveforms_per_prompt, seq_len
          )
  
          # 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]
          )
  
      return prompt_embeds
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import torch
  from transformers import ClapFeatureExtractor, ClapModel, ClapTextModelWithProjection, RobertaTokenizer, RobertaTokenizerFast, SpeechT5HifiGan
  from ...models import AutoencoderKL, UNet2DConditionModel
  from ...schedulers import KarrasDiffusionSchedulers
  from ...utils import is_accelerate_available, is_accelerate_version, is_librosa_available, logging, replace_example_docstring
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import AudioPipelineOutput, DiffusionPipeline
label_desc: Use image node_id 4 for calling the MusicLDMPipeline obj's underlying member method code with example usage: obj._encode_prompt(prompt, device, num_waveforms_per_prompt, do_classifier_free_guidance, negative_prompt, prompt_embeds, negative_prompt_embeds) and returns: prompt_embeds