



"""simple docstring"""





from ..utils import DummyObject, requires_backends




class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							Optional[Any]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Tuple:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							List[Any]:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							str:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Dict:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Dict:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							List[Any]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Dict:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Tuple:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							List[Any]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							List[str]:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Optional[Any]:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							Optional[int]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Optional[Any]:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							str:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							Optional[int]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							int:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Tuple:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							Optional[int]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Optional[int]:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							int:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							Optional[int]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Optional[int]:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Union[str, Any]:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							List[str]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Dict:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Tuple:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							List[str]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							List[str]:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Dict:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							Dict:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							List[str]:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Optional[int]:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							str:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Optional[Any]:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							Tuple:
         requires_backends(cls	,       ['flax']						)







class 			lowercase__			(      metaclass=__lowerCamelCase    ):
       '''simple docstring'''







       _UpperCAmelCase      				=					['''flax''']






       def __init__(  self	,       *snake_case	,       **snake_case						)			->							List[Any]:
         requires_backends(self	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							str:
         requires_backends(cls	,       ['flax']						)






       @classmethod
       def        lowerCamelCase_   (  cls	,       *snake_case	,       **snake_case						)			->							List[Any]:
         requires_backends(cls	,       ['flax']						)







"""simple docstring"""





from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput




class 			lowercase__			(      nn.Module    ):
							'''simple docstring'''







							def __init__(  self	,       snake_case = 16	,       snake_case = 88	,       snake_case = None	,       snake_case = 1	,       snake_case = 0.0	,       snake_case = 32	,       snake_case = None	,       snake_case = False	,       snake_case = None	,       snake_case = None	,       snake_case = "geglu"	,       snake_case = None	,       )			->							str:
									super().__init__()
									_UpperCAmelCase							 =		nn.ModuleList(
									    [
									        TransformeraDModel(
									            num_attention_heads=snake_case	,       attention_head_dim=snake_case	,       in_channels=snake_case	,       num_layers=snake_case	,       dropout=snake_case	,       norm_num_groups=snake_case	,       cross_attention_dim=snake_case	,       attention_bias=snake_case	,       sample_size=snake_case	,       num_vector_embeds=snake_case	,       activation_fn=snake_case	,       num_embeds_ada_norm=snake_case	,       )
									        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
									_UpperCAmelCase							 =		0.5

									# The shape of `encoder_hidden_states` is expected to be
									# `(batch_size, condition_lengths[0]+condition_lengths[1], num_features)`
									_UpperCAmelCase							 =		[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])`
									_UpperCAmelCase							 =		[1, 0]






							def        lowerCamelCase_   (  self	,       snake_case	,       snake_case	,       snake_case=None	,       snake_case=None	,       snake_case=None	,       snake_case = True	,       )			->							Any:
									_UpperCAmelCase							 =		hidden_states

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

									_UpperCAmelCase							 =		encoded_states[0] * self.mix_ratio + encoded_states[1] * (1 - self.mix_ratio)
									_UpperCAmelCase							 =		output_states + input_states

									if not return_dict:
											return (output_states,)

									return TransformeraDModelOutput(sample=snake_case						)


