




'''simple docstring'''






from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput






class        lowercase_      (						nn.Module							):





     def __init__(     self     :					Union[str, Any]     ,							__lowerCamelCase     :					int = 16     ,							__lowerCamelCase     :					int = 88     ,							__lowerCamelCase     :					Optional[int] = None     ,							__lowerCamelCase     :					int = 1     ,							__lowerCamelCase     :					float = 0.0     ,							__lowerCamelCase     :					int = 32     ,							__lowerCamelCase     :					Optional[int] = None     ,							__lowerCamelCase     :					bool = False     ,							__lowerCamelCase     :					Optional[int] = None     ,							__lowerCamelCase     :					Optional[int] = None     ,							__lowerCamelCase     :					str = "geglu"     ,							__lowerCamelCase     :					Optional[int] = None     ,							):
           super().__init__()
           snake_case__       :   Any	      =    nn.ModuleList(
               [
                   TransformeraDModel(
                       num_attention_heads=__lowerCamelCase     ,							attention_head_dim=__lowerCamelCase     ,							in_channels=__lowerCamelCase     ,							num_layers=__lowerCamelCase     ,							dropout=__lowerCamelCase     ,							norm_num_groups=__lowerCamelCase     ,							cross_attention_dim=__lowerCamelCase     ,							attention_bias=__lowerCamelCase     ,							sample_size=__lowerCamelCase     ,							num_vector_embeds=__lowerCamelCase     ,							activation_fn=__lowerCamelCase     ,							num_embeds_ada_norm=__lowerCamelCase     ,							)
                   for _ in range(2			)
               ]			)

           # Variables that can be set by a pipeline:

           # The ratio of transformer1 to transformer2's output states to be combined during inference
           snake_case__       :   str	      =    0.5

           # The shape of `encoder_hidden_states` is expected to be
           # `(batch_size, condition_lengths[0]+condition_lengths[1], num_features)`
           snake_case__       :   List[str]	      =    [77, 257]

           # Which transformer to use to encode which condition.
           # E.g. `(1, 0)` means that we'll use `transformers[1](conditions[0])` and `transformers[0](conditions[1])`
           snake_case__       :   Optional[Any]	      =    [1, 0]





     def 			_lowerCAmelCase      (     self     :					str     ,							__lowerCamelCase     :					Optional[Any]     ,							__lowerCamelCase     :					List[Any]     ,							__lowerCamelCase     :					str=None     ,							__lowerCamelCase     :					Dict=None     ,							__lowerCamelCase     :					Dict=None     ,							__lowerCamelCase     :					bool = True     ,							):
           snake_case__       :   List[str]	      =    hidden_states

           snake_case__       :   Any	      =    []
           snake_case__       :   Dict	      =    0
           # attention_mask is not used yet
           for i in range(2			):
                 # for each of the two transformers, pass the corresponding condition tokens
                 snake_case__       :   List[Any]	      =    encoder_hidden_states[:, tokens_start : tokens_start + self.condition_lengths[i]]
                 snake_case__       :   Optional[Any]	      =    self.transformer_index_for_condition[i]
                 snake_case__       :   Optional[int]	      =    self.transformers[transformer_index](
                     __lowerCamelCase     ,							encoder_hidden_states=__lowerCamelCase     ,							timestep=__lowerCamelCase     ,							cross_attention_kwargs=__lowerCamelCase     ,							return_dict=__lowerCamelCase     ,							)[0]
                 encoded_states.append(encoded_state - input_states			)
                 tokens_start += self.condition_lengths[i]

           snake_case__       :   Optional[int]	      =    encoded_states[0] * self.mix_ratio + encoded_states[1] * (1 - self.mix_ratio)
           snake_case__       :   str	      =    output_states + input_states

           if not return_dict:
                 return (output_states,)

           return TransformeraDModelOutput(sample=__lowerCamelCase			)






'''simple docstring'''






from ..utils import DummyObject, requires_backends






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Optional[Any]     ,							*__lowerCamelCase     :					Tuple     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Tuple     ,							*__lowerCamelCase     :					str     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Any     ,							*__lowerCamelCase     :					Dict     ,							**__lowerCamelCase     :					List[str]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					int     ,							*__lowerCamelCase     :					str     ,							**__lowerCamelCase     :					Union[str, Any]			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Optional[Any]     ,							*__lowerCamelCase     :					List[str]     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Optional[Any]     ,							*__lowerCamelCase     :					Optional[Any]     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					List[str]     ,							*__lowerCamelCase     :					str     ,							**__lowerCamelCase     :					str			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Union[str, Any]     ,							*__lowerCamelCase     :					str     ,							**__lowerCamelCase     :					str			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Any     ,							*__lowerCamelCase     :					Tuple     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Optional[Any]     ,							*__lowerCamelCase     :					Optional[Any]     ,							**__lowerCamelCase     :					str			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					str     ,							*__lowerCamelCase     :					Dict     ,							**__lowerCamelCase     :					int			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Optional[Any]     ,							*__lowerCamelCase     :					Union[str, Any]     ,							**__lowerCamelCase     :					Union[str, Any]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Optional[int]     ,							*__lowerCamelCase     :					Tuple     ,							**__lowerCamelCase     :					Optional[Any]			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					List[Any]     ,							*__lowerCamelCase     :					Dict     ,							**__lowerCamelCase     :					int			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Tuple     ,							*__lowerCamelCase     :					List[str]     ,							**__lowerCamelCase     :					str			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					List[Any]     ,							*__lowerCamelCase     :					Dict     ,							**__lowerCamelCase     :					Union[str, Any]			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Any     ,							*__lowerCamelCase     :					Union[str, Any]     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					List[Any]     ,							*__lowerCamelCase     :					Optional[Any]     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Dict     ,							*__lowerCamelCase     :					Union[str, Any]     ,							**__lowerCamelCase     :					Any			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					List[Any]     ,							*__lowerCamelCase     :					Optional[int]     ,							**__lowerCamelCase     :					List[str]			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Union[str, Any]     ,							*__lowerCamelCase     :					str     ,							**__lowerCamelCase     :					Any			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Tuple     ,							*__lowerCamelCase     :					Union[str, Any]     ,							**__lowerCamelCase     :					Dict			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					List[Any]     ,							*__lowerCamelCase     :					Tuple     ,							**__lowerCamelCase     :					List[Any]			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					int     ,							*__lowerCamelCase     :					Union[str, Any]     ,							**__lowerCamelCase     :					str			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Union[str, Any]     ,							*__lowerCamelCase     :					Optional[Any]     ,							**__lowerCamelCase     :					int			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Any     ,							*__lowerCamelCase     :					List[str]     ,							**__lowerCamelCase     :					int			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					List[str]     ,							*__lowerCamelCase     :					Optional[Any]     ,							**__lowerCamelCase     :					List[str]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Union[str, Any]     ,							*__lowerCamelCase     :					Optional[Any]     ,							**__lowerCamelCase     :					List[Any]			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Any     ,							*__lowerCamelCase     :					Optional[int]     ,							**__lowerCamelCase     :					int			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					str     ,							*__lowerCamelCase     :					Tuple     ,							**__lowerCamelCase     :					List[Any]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Optional[Any]     ,							*__lowerCamelCase     :					Union[str, Any]     ,							**__lowerCamelCase     :					Union[str, Any]			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Union[str, Any]     ,							*__lowerCamelCase     :					Tuple     ,							**__lowerCamelCase     :					Optional[Any]			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					str     ,							*__lowerCamelCase     :					Dict     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					Union[str, Any]     ,							*__lowerCamelCase     :					List[Any]     ,							**__lowerCamelCase     :					Optional[int]			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Optional[int]     ,							*__lowerCamelCase     :					Tuple     ,							**__lowerCamelCase     :					Tuple			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Dict     ,							*__lowerCamelCase     :					Dict     ,							**__lowerCamelCase     :					Optional[Any]			):
           requires_backends(cls     ,							['flax']			)






class        lowercase_      (						metaclass=lowerCAmelCase_							):
     A_											=			["flax"]





     def __init__(     self     :					str     ,							*__lowerCamelCase     :					int     ,							**__lowerCamelCase     :					Dict			):
           requires_backends(self     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					List[str]     ,							*__lowerCamelCase     :					Optional[int]     ,							**__lowerCamelCase     :					Tuple			):
           requires_backends(cls     ,							['flax']			)





     @classmethod
     def 			_lowerCAmelCase      (     cls     :					Dict     ,							*__lowerCamelCase     :					Optional[int]     ,							**__lowerCamelCase     :					Optional[Any]			):
           requires_backends(cls     ,							['flax']			)
