





'''simple docstring'''




import torch
from torch import nn

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


class 			SCREAMING_SNAKE_CASE   (a__ ,		a__							):


     @register_to_config
     def __init__(						self						,     *,
         _UpperCAmelCase = 4						,     _UpperCAmelCase = 768						,     _UpperCAmelCase						,     _UpperCAmelCase						,     ):

          '''simple docstring'''






          super().__init__()

          __A						:			Tuple								=	nn.Parameter(torch.zeros(_UpperCAmelCase))

          # parameters for additional clip time embeddings
          __A						:			int								=	nn.Linear(_UpperCAmelCase						,     _UpperCAmelCase)
          __A						:			List[str]								=	nn.Linear(_UpperCAmelCase						,     _UpperCAmelCase)

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


     def 							SCREAMING_SNAKE_CASE  (						self						,     *, _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase						,     _UpperCAmelCase):

          '''simple docstring'''






          if do_classifier_free_guidance:
               # Add the classifier free guidance embeddings to the image embeddings
               __A						:			str								=	image_embeddings.shape[0]
               __A						:			Union[str, Any]								=	self.learned_classifier_free_guidance_embeddings.unsqueeze(0)
               __A						:			Optional[Any]								=	classifier_free_guidance_embeddings.expand(
                   _UpperCAmelCase						,     -1)
               __A						:			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						:			int								=	self.embedding_proj(_UpperCAmelCase)
          __A						:			Union[str, Any]								=	self.clip_image_embeddings_project_to_time_embeddings(_UpperCAmelCase)
          __A						:			Any								=	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						:			Tuple								=	self.clip_extra_context_tokens_proj(_UpperCAmelCase)
          __A						:			List[Any]								=	clip_extra_context_tokens.reshape(_UpperCAmelCase						,     -1						,     self.clip_extra_context_tokens)
          __A						:			List[str]								=	clip_extra_context_tokens.permute(0						,     2						,     1)

          __A						:			int								=	self.encoder_hidden_states_proj(_UpperCAmelCase)
          __A						:			Union[str, Any]								=	self.text_encoder_hidden_states_norm(_UpperCAmelCase)
          __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'''




import math






def 	_lowerCAmelCase      (  __snake_case  :			int      )					->					int:

     if not isinstance(__snake_case			,							__snake_case      ):
          __A						:			List[Any]								=	f'Input value of [number={number}] must be an integer'
          raise TypeError(__snake_case      )

     if number < 1:
          __A						:			Union[str, Any]								=	f'Input value of [number={number}] must be > 0'
          raise ValueError(__snake_case      )
     elif number == 1:
          return 3
     elif number == 2:
          return 5
     else:
          __A						:			Optional[Any]								=	int(math.log(number // 3			,							2      )      ) + 2

          __A						:			Union[str, Any]								=	[3, 5]
          __A						:			List[Any]								=	2
          __A						:			Optional[Any]								=	3
          for block in range(1			,							__snake_case      ):
               for _ in range(__snake_case      ):
                    proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1]      )
                    proth_index += 1
               increment *= 2

     return proth_list[number - 1]


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  for number in range(11):
    lowercase__   :				str      =   0
    try:
      lowercase__   :				List[str]      =   proth(number)
    except ValueError:
      print(f"""ValueError: there is no {number}th Proth number""")
      continue

    print(f"""The {number}th Proth number: {value}""")