


"""simple docstring"""







import torch
from torch import nn

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin






class 						_A  (  _a   ,_a  ):







    """simple docstring"""




    @register_to_config
    def __init__( self    :   List[Any]    ,			*,
        __UpperCAmelCase    :   int = 4    ,			__UpperCAmelCase    :   int = 768    ,			__UpperCAmelCase    :   int    ,			__UpperCAmelCase    :   List[str]    ,			):
      super().__init__()

      a						:		int											=      nn.Parameter(torch.zeros(_lowerCAmelCase))

      # parameters for additional clip time embeddings
      a						:		int											=      nn.Linear(_lowerCAmelCase    ,			_lowerCAmelCase)
      a						:		Any											=      nn.Linear(_lowerCAmelCase    ,			_lowerCAmelCase)

      # parameters for encoder hidden states
      a						:		int											=      clip_extra_context_tokens
      a						:		Union[str, Any]											=      nn.Linear(
          _lowerCAmelCase    ,			self.clip_extra_context_tokens * cross_attention_dim)
      a						:		int											=      nn.Linear(_lowerCAmelCase    ,			_lowerCAmelCase)
      a						:		Optional[Any]											=      nn.LayerNorm(_lowerCAmelCase)






    def      __snake_case							( self    :   Optional[int]    ,			*, __UpperCAmelCase    :   Union[str, Any]    ,			__UpperCAmelCase    :   Dict    ,			__UpperCAmelCase    :   List[str]    ,			__UpperCAmelCase    :   Optional[Any]):

      if do_classifier_free_guidance:
        # Add the classifier free guidance embeddings to the image embeddings
        a						:		List[str]											=      image_embeddings.shape[0]
        a						:		List[str]											=      self.learned_classifier_free_guidance_embeddings.unsqueeze(0)
        a						:		List[str]											=      classifier_free_guidance_embeddings.expand(
            _lowerCAmelCase    ,			-1)
        a						:		Optional[Any]											=      torch.cat([classifier_free_guidance_embeddings, image_embeddings]    ,			dim=0)

      # The image embeddings batch size and the text embeddings batch size are equal
      assert image_embeddings.shape[0] == prompt_embeds.shape[0]

      a						:		int											=      prompt_embeds.shape[0]

      # "Specifically, we modify the architecture described in Nichol et al. (2021) by projecting and
      # adding CLIP embeddings to the existing timestep embedding, ...
      a						:		Dict											=      self.embedding_proj(_lowerCAmelCase)
      a						:		Union[str, Any]											=      self.clip_image_embeddings_project_to_time_embeddings(_lowerCAmelCase)
      a						:		int											=      time_projected_image_embeddings + time_projected_prompt_embeds

      # ... and by projecting CLIP embeddings into four
      # extra tokens of context that are concatenated to the sequence of outputs from the GLIDE text encoder"
      a						:		List[Any]											=      self.clip_extra_context_tokens_proj(_lowerCAmelCase)
      a						:		Optional[Any]											=      clip_extra_context_tokens.reshape(_lowerCAmelCase    ,			-1    ,			self.clip_extra_context_tokens)
      a						:		Dict											=      clip_extra_context_tokens.permute(0    ,			2    ,			1)

      a						:		Optional[Any]											=      self.encoder_hidden_states_proj(_lowerCAmelCase)
      a						:		List[str]											=      self.text_encoder_hidden_states_norm(_lowerCAmelCase)
      a						:		int											=      torch.cat([clip_extra_context_tokens, text_encoder_hidden_states]    ,			dim=1)

      return text_encoder_hidden_states, additive_clip_time_embeddings





"""simple docstring"""







__lowercase    =				frozenset(
    [
        """prompt""",
        """height""",
        """width""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
        """cross_attention_kwargs""",
    ]
)

__lowercase    =				frozenset(["""prompt""", """negative_prompt"""])

__lowercase    =				frozenset([])

__lowercase    =				frozenset(["""image"""])

__lowercase    =				frozenset(
    [
        """image""",
        """height""",
        """width""",
        """guidance_scale""",
    ]
)

__lowercase    =				frozenset(["""image"""])

__lowercase    =				frozenset(
    [
        """prompt""",
        """image""",
        """height""",
        """width""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
    ]
)

__lowercase    =				frozenset(["""prompt""", """image""", """negative_prompt"""])

__lowercase    =				frozenset(
    [
        # Text guided image variation with an image mask
        """prompt""",
        """image""",
        """mask_image""",
        """height""",
        """width""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
    ]
)

__lowercase    =				frozenset(["""prompt""", """image""", """mask_image""", """negative_prompt"""])

__lowercase    =				frozenset(
    [
        # image variation with an image mask
        """image""",
        """mask_image""",
        """height""",
        """width""",
        """guidance_scale""",
    ]
)

__lowercase    =				frozenset(["""image""", """mask_image"""])

__lowercase    =				frozenset(
    [
        """example_image""",
        """image""",
        """mask_image""",
        """height""",
        """width""",
        """guidance_scale""",
    ]
)

__lowercase    =				frozenset(["""example_image""", """image""", """mask_image"""])

__lowercase    =				frozenset(["""class_labels"""])

__lowercase    =				frozenset(["""class_labels"""])

__lowercase    =				frozenset(["""batch_size"""])

__lowercase    =				frozenset([])

__lowercase    =				frozenset(["""batch_size"""])

__lowercase    =				frozenset([])

__lowercase    =				frozenset(
    [
        """prompt""",
        """audio_length_in_s""",
        """guidance_scale""",
        """negative_prompt""",
        """prompt_embeds""",
        """negative_prompt_embeds""",
        """cross_attention_kwargs""",
    ]
)

__lowercase    =				frozenset(["""prompt""", """negative_prompt"""])
__lowercase    =				frozenset(["""input_tokens"""])

__lowercase    =				frozenset(["""input_tokens"""])






