'''simple docstring'''




class    a__				:






     def __init__(			self		:		List[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  0
         __lowerCamelCase          =  0
         __lowerCamelCase          =  {}






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]  ,    a		:		Tuple   ):





         """simple docstring"""



         if vertex not in self.adjacency:
             __lowerCamelCase          =  {}
             self.num_vertices += 1






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]  ,    a		:		int  ,    a		:		int  ,    a		:		Dict   ):





         """simple docstring"""



         self.add_vertex(a   )
         self.add_vertex(a   )

         if head == tail:
             return

         __lowerCamelCase          =  weight
         __lowerCamelCase          =  weight






     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



         __lowerCamelCase          =  self.get_edges()
         for edge in edges:
             __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  edge
             edges.remove((tail, head, weight)   )
         for i in range(len(a   )   ):
             __lowerCamelCase          =  list(edges[i]   )

         edges.sort(key=lambda a   : e[2]   )
         for i in range(len(a   ) - 1   ):
             if edges[i][2] >= edges[i + 1][2]:
                 __lowerCamelCase          =  edges[i][2] + 1
         for edge in edges:
             __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  edge
             __lowerCamelCase          =  weight
             __lowerCamelCase          =  weight






     def __str__(			self		:		Dict   ):





         """simple docstring"""



         __lowerCamelCase          =  ''''''
         for tail in self.adjacency:
             for head in self.adjacency[tail]:
                 __lowerCamelCase          =  self.adjacency[head][tail]
                 string += f"""{head} -> {tail} == {weight}\n"""
         return string.rstrip('''\n'''   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Union[str, Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  []
         for tail in self.adjacency:
             for head in self.adjacency[tail]:
                 output.append((tail, head, self.adjacency[head][tail])   )
         return output






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[Any]   ):





         """simple docstring"""



         return self.adjacency.keys()






     @staticmethod
     def        SCREAMING_SNAKE_CASE__       (			a		:		List[Any]=None  ,    a		:		Union[str, Any]=None   ):





         """simple docstring"""



         __lowerCamelCase          =  Graph()
         if vertices is None:
             __lowerCamelCase          =  []
         if edges is None:
             __lowerCamelCase          =  []
         for vertex in vertices:
             g.add_vertex(a   )
         for edge in edges:
             g.add_edge(*a   )
         return g




     class    a__				:






          def __init__(			self		:		Optional[Any]   ):





              """simple docstring"""



              __lowerCamelCase          =  {}
              __lowerCamelCase          =  {}






          def __len__(			self		:		List[str]   ):





              """simple docstring"""



              return len(self.parent   )






          def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]  ,    a		:		List[Any]   ):





              """simple docstring"""



              if item in self.parent:
                  return self.find(a   )

              __lowerCamelCase          =  item
              __lowerCamelCase          =  0
              return item






          def        SCREAMING_SNAKE_CASE__       (			self		:		int  ,    a		:		Any   ):





              """simple docstring"""



              if item not in self.parent:
                  return self.make_set(a   )
              if item != self.parent[item]:
                  __lowerCamelCase          =  self.find(self.parent[item]   )
              return self.parent[item]






          def        SCREAMING_SNAKE_CASE__       (			self		:		str  ,    a		:		List[Any]  ,    a		:		List[str]   ):





              """simple docstring"""



              __lowerCamelCase          =  self.find(a   )
              __lowerCamelCase          =  self.find(a   )

              if roota == roota:
                  return roota

              if self.rank[roota] > self.rank[roota]:
                  __lowerCamelCase          =  roota
                  return roota

              if self.rank[roota] < self.rank[roota]:
                  __lowerCamelCase          =  roota
                  return roota

              if self.rank[roota] == self.rank[roota]:
                  self.rank[roota] += 1
                  __lowerCamelCase          =  roota
                  return roota
              return None






     @staticmethod
     def        SCREAMING_SNAKE_CASE__       (			a		:		Union[str, Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  graph.num_vertices

         __lowerCamelCase          =  Graph.UnionFind()
         __lowerCamelCase          =  []
         while num_components > 1:
             __lowerCamelCase          =  {}
             for vertex in graph.get_vertices():
                 __lowerCamelCase          =  -1

             __lowerCamelCase          =  graph.get_edges()
             for edge in edges:
                 __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  edge
                 edges.remove((tail, head, weight)   )
             for edge in edges:
                 __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  edge
                 __lowerCamelCase          =  union_find.find(a   )
                 __lowerCamelCase          =  union_find.find(a   )
                 if seta != seta:
                     if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                         __lowerCamelCase          =  [head, tail, weight]

                     if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                         __lowerCamelCase          =  [head, tail, weight]
             for vertex in cheap_edge:
                 if cheap_edge[vertex] != -1:
                     __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  cheap_edge[vertex]
                     if union_find.find(a   ) != union_find.find(a   ):
                         union_find.union(a  ,    a   )
                         mst_edges.append(cheap_edge[vertex]   )
                         __lowerCamelCase          =  num_components - 1
         __lowerCamelCase          =  Graph.build(edges=a   )
         return mst

'''simple docstring'''




import torch
from torch import nn

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




class    a__				(       UpperCAmelCase__							,       UpperCAmelCase__			):






     @register_to_config
     def __init__(			self		:		Any  ,    *,
         a		:		int = 4  ,    a		:		int = 7_68  ,    a		:		int  ,    a		:		Optional[int]  ,    ):





         """simple docstring"""



         super().__init__()

         __lowerCamelCase          =  nn.Parameter(torch.zeros(a   )   )

         # parameters for additional clip time embeddings
         __lowerCamelCase          =  nn.Linear(a  ,    a   )
         __lowerCamelCase          =  nn.Linear(a  ,    a   )

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






     def        SCREAMING_SNAKE_CASE__       (			self		:		int  ,    *, a		:		Union[str, Any]  ,    a		:		Any  ,    a		:		str  ,    a		:		Any   ):





         """simple docstring"""



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

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

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

         return text_encoder_hidden_states, additive_clip_time_embeddings
