


"""simple docstring"""







from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput






class       __A				(       nn.Module			):






 """simple docstring"""




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

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





 def       SCREAMING_SNAKE_CASE							(		self ,    __A ,    __A ,    __A=None ,    __A=None ,    __A=None ,    __A = True ,    )					->     List[Any]:
     a 		=hidden_states

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

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

     if not return_dict:
         return (output_states,)

     return TransformeraDModelOutput(sample=__A						)







from functools import lru_cache






@lru_cache
def 				lowerCamelCase__      (    __lowerCamelCase			:     int		):
  if num < 0:
    raise ValueError("""Number should not be negative."""		)

  return 1 if num in (0, 1) else num * factorial(num - 1		)


if __name__ == "__main__":
       import doctest

       doctest.testmod()


