





'''simple docstring'''





import torch
from torch import nn

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

class        _a    (						snake_case_ , snake_case_							):






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

          _snake_case							=				nn.Parameter(torch.zeros(_A   )   )

          # parameters for additional clip time embeddings
          _snake_case							=				nn.Linear(_A ,_A   )
          _snake_case							=				nn.Linear(_A ,_A   )

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






     def     _lowercase     (			self ,*, _SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   )							->      List[Any]:


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

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

          _snake_case							=				self.encoder_hidden_states_proj(_A   )
          _snake_case							=				self.text_encoder_hidden_states_norm(_A   )
          _snake_case							=				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

from typing import Any





def      __a     (       _UpperCamelCase:   list[Any]   )						->			None:

     """simple docstring"""




     create_state_space_tree(_UpperCamelCase ,						[] ,						0   )





def      __a     (       _UpperCamelCase:   list[Any] ,						_UpperCamelCase:   list[Any] ,						_UpperCamelCase:   int   )						->			None:

     """simple docstring"""




     if index == len(_UpperCamelCase   ):
          print(_UpperCamelCase   )
          return

     create_state_space_tree(_UpperCamelCase ,						_UpperCamelCase ,						index + 1   )
     current_subsequence.append(sequence[index]   )
     create_state_space_tree(_UpperCamelCase ,						_UpperCamelCase ,						index + 1   )
     current_subsequence.pop()


if __name__ == "__main__":
   UpperCamelCase_						:      list[Any]       =						[3, 1, 2, 4]
   generate_all_subsequences(seq)

   seq.clear()
   seq.extend(['''A''', '''B''', '''C'''])
   generate_all_subsequences(seq)


