import torch
from torch import nn

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


class       UpperCAmelCase__     (		SCREAMING_SNAKE_CASE_		,						SCREAMING_SNAKE_CASE_       ):



  """simple docstring"""






  @register_to_config
  def __init__(					self:      Union[str, Any]					,					*,
      __lowerCAmelCase:      int = 4					,					__lowerCAmelCase:      int = 768					,					__lowerCAmelCase:      int					,					__lowerCAmelCase:      List[Any]					,					)			->			str:




    '''simple docstring'''




    super().__init__()

    __UpperCAmelCase         =							nn.Parameter(torch.zeros(__snake_case ) )

    # parameters for additional clip time embeddings
    __UpperCAmelCase         =							nn.Linear(__snake_case					,					__snake_case )
    __UpperCAmelCase         =							nn.Linear(__snake_case					,					__snake_case )

    # parameters for encoder hidden states
    __UpperCAmelCase         =							clip_extra_context_tokens
    __UpperCAmelCase         =							nn.Linear(
        __snake_case					,					self.clip_extra_context_tokens * cross_attention_dim )
    __UpperCAmelCase         =							nn.Linear(__snake_case					,					__snake_case )
    __UpperCAmelCase         =							nn.LayerNorm(__snake_case )






  def 						_UpperCAmelCase					(					self:      Dict					,					*, __lowerCAmelCase:      Any					,					__lowerCAmelCase:      List[Any]					,					__lowerCAmelCase:      str					,					__lowerCAmelCase:      List[str] )			->			Optional[Any]:




    '''simple docstring'''




    if do_classifier_free_guidance:
      # Add the classifier free guidance embeddings to the image embeddings
      __UpperCAmelCase         =							image_embeddings.shape[0]
      __UpperCAmelCase         =							self.learned_classifier_free_guidance_embeddings.unsqueeze(0 )
      __UpperCAmelCase         =							classifier_free_guidance_embeddings.expand(
          __snake_case					,					-1 )
      __UpperCAmelCase         =							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]

    __UpperCAmelCase         =							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, ...
    __UpperCAmelCase         =							self.embedding_proj(__snake_case )
    __UpperCAmelCase         =							self.clip_image_embeddings_project_to_time_embeddings(__snake_case )
    __UpperCAmelCase         =							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"
    __UpperCAmelCase         =							self.clip_extra_context_tokens_proj(__snake_case )
    __UpperCAmelCase         =							clip_extra_context_tokens.reshape(__snake_case					,					-1					,					self.clip_extra_context_tokens )
    __UpperCAmelCase         =							clip_extra_context_tokens.permute(0					,					2					,					1 )

    __UpperCAmelCase         =							self.encoder_hidden_states_proj(__snake_case )
    __UpperCAmelCase         =							self.text_encoder_hidden_states_norm(__snake_case )
    __UpperCAmelCase         =							torch.cat([clip_extra_context_tokens, text_encoder_hidden_states]					,					dim=1 )

    return text_encoder_hidden_states, additive_clip_time_embeddings











"""simple docstring"""





def   a    (     __UpperCAmelCase      :    int      ,   __UpperCAmelCase      :    int  )    ->							int:
						while b:
												__magic_name__,			__magic_name__:	Optional[int]							=       b, a % b
						return a



def   a    (     __UpperCAmelCase      :    int      ,   __UpperCAmelCase      :    int  )    ->							int:
						return a if b == 0 else euclidean_gcd_recursive(__UpperCAmelCase      ,   a % b  )



def   a    (     )    ->							List[Any]:
						print(f'euclidean_gcd(3, 5) = {euclidean_gcd(3      ,   5  )}'  )
						print(f'euclidean_gcd(5, 3) = {euclidean_gcd(5      ,   3  )}'  )
						print(f'euclidean_gcd(1, 3) = {euclidean_gcd(1      ,   3  )}'  )
						print(f'euclidean_gcd(3, 6) = {euclidean_gcd(3      ,   6  )}'  )
						print(f'euclidean_gcd(6, 3) = {euclidean_gcd(6      ,   3  )}'  )

						print(f'euclidean_gcd_recursive(3, 5) = {euclidean_gcd_recursive(3      ,   5  )}'  )
						print(f'euclidean_gcd_recursive(5, 3) = {euclidean_gcd_recursive(5      ,   3  )}'  )
						print(f'euclidean_gcd_recursive(1, 3) = {euclidean_gcd_recursive(1      ,   3  )}'  )
						print(f'euclidean_gcd_recursive(3, 6) = {euclidean_gcd_recursive(3      ,   6  )}'  )
						print(f'euclidean_gcd_recursive(6, 3) = {euclidean_gcd_recursive(6      ,   3  )}'  )


if __name__ == "__main__":
							main()



