




import torch
from torch import nn

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







class 						lowercase							(   UpperCamelCase__,UpperCamelCase__		):

     @register_to_config
     def __init__(  self		,     *,
         _a = 4		,     _a = 768		,     _a		,     _a		,     )						->							str:
           super().__init__()

           _A							:     List[Any]			=						nn.Parameter(torch.zeros(_a				)				)

           # parameters for additional clip time embeddings
           _A							:     Union[str, Any]			=						nn.Linear(_a		,     _a				)
           _A							:     List[str]			=						nn.Linear(_a		,     _a				)

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



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

           _A							:     Dict			=						self.encoder_hidden_states_proj(_a				)
           _A							:     Any			=						self.text_encoder_hidden_states_norm(_a				)
           _A							:     Union[str, Any]			=						torch.cat([clip_extra_context_tokens, text_encoder_hidden_states]		,     dim=1				)

           return text_encoder_hidden_states, additive_clip_time_embeddings



"""simple docstring"""





from __future__ import annotations



def       lowerCamelCase__		(			__snake_case,     __snake_case,     __snake_case	)							->		int | float:


					"""simple docstring"""





					if len(__snake_case	) == 0:
										raise ValueError('''find_max() arg is an empty sequence'''	)
					if (
					    left >= len(__snake_case	)
					    or left < -len(__snake_case	)
					    or right >= len(__snake_case	)
					    or right < -len(__snake_case	)
					):
										raise IndexError('''list index out of range'''	)
					if left == right:
										return nums[left]
					_UpperCamelCase							 =  (left + right) >> 1  # the middle
					_UpperCamelCase							 =  find_max(__snake_case,     __snake_case,     __snake_case	)  # find max in range[left, mid]
					_UpperCamelCase							 =  find_max(__snake_case,     mid + 1,     __snake_case	)  # find max in range[mid + 1, right]

					return left_max if left_max >= right_max else right_max


if __name__ == "__main__":
				import doctest

				doctest.testmod(verbose=True)






