


"""simple docstring"""



from dataclasses import dataclass
from typing import Optional

import torch
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .attention import BasicTransformerBlock
from .modeling_utils import ModelMixin







@dataclass
class _lowerCAmelCase    (				snake_case_     ):
   __UpperCAmelCase			:	torch.FloatTensor







class _lowerCAmelCase    (				snake_case_   ,							snake_case_     ):







   @register_to_config
   def __init__(     self						,     UpperCamelCase__ = 16						,     UpperCamelCase__ = 88						,     UpperCamelCase__ = None						,     UpperCamelCase__ = None						,     UpperCamelCase__ = 1						,     UpperCamelCase__ = 0.0						,     UpperCamelCase__ = 32						,     UpperCamelCase__ = None						,     UpperCamelCase__ = False						,     UpperCamelCase__ = None						,     UpperCamelCase__ = "geglu"						,     UpperCamelCase__ = True						,     UpperCamelCase__ = True						,     )     ->		Union[str, Any]:

       '''simple docstring'''




       super().__init__()
       snake_case   :				Any				 =   num_attention_heads
       snake_case   :				Dict				 =   attention_head_dim
       snake_case   :				Union[str, Any]				 =   num_attention_heads * attention_head_dim

       snake_case   :				List[str]				 =   in_channels

       snake_case   :				int				 =   torch.nn.GroupNorm(num_groups=UpperCamelCase__						,     num_channels=UpperCamelCase__						,     eps=1e-6						,     affine=UpperCamelCase__						)
       snake_case   :				Optional[Any]				 =   nn.Linear(UpperCamelCase__						,     UpperCamelCase__						)

       # 3. Define transformers blocks
       snake_case   :				Union[str, Any]				 =   nn.ModuleList(
           [
               BasicTransformerBlock(
                   UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						,     dropout=UpperCamelCase__						,     cross_attention_dim=UpperCamelCase__						,     activation_fn=UpperCamelCase__						,     attention_bias=UpperCamelCase__						,     double_self_attention=UpperCamelCase__						,     norm_elementwise_affine=UpperCamelCase__						,     )
               for d in range(UpperCamelCase__						)
           ]						)

       snake_case   :				List[str]				 =   nn.Linear(UpperCamelCase__						,     UpperCamelCase__						)







   def 			lowerCamelCase		(     self						,     UpperCamelCase__						,     UpperCamelCase__=None						,     UpperCamelCase__=None						,     UpperCamelCase__=None						,     UpperCamelCase__=1						,     UpperCamelCase__=None						,     UpperCamelCase__ = True						,     )     ->		List[Any]:

       '''simple docstring'''




       snake_case ,snake_case ,snake_case ,snake_case   :				Tuple				 =   hidden_states.shape
       snake_case   :				Union[str, Any]				 =   batch_frames // num_frames

       snake_case   :				Any				 =   hidden_states

       snake_case   :				Tuple				 =   hidden_states[None, :].reshape(UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						)
       snake_case   :				int				 =   hidden_states.permute(0						,     2						,     1						,     3						,     4						)

       snake_case   :				int				 =   self.norm(UpperCamelCase__						)
       snake_case   :				List[Any]				 =   hidden_states.permute(0						,     3						,     4						,     2						,     1						).reshape(batch_size * height * width						,     UpperCamelCase__						,     UpperCamelCase__						)

       snake_case   :				Any				 =   self.proj_in(UpperCamelCase__						)

       # 2. Blocks
       for block in self.transformer_blocks:
           snake_case   :				Tuple				 =   block(
               UpperCamelCase__						,     encoder_hidden_states=UpperCamelCase__						,     timestep=UpperCamelCase__						,     cross_attention_kwargs=UpperCamelCase__						,     class_labels=UpperCamelCase__						,     )

       # 3. Output
       snake_case   :				Tuple				 =   self.proj_out(UpperCamelCase__						)
       snake_case   :				List[str]				 =   (
           hidden_states[None, None, :]
           .reshape(UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						)
           .permute(0						,     3						,     4						,     1						,     2						)
           .contiguous()
       )
       snake_case   :				Any				 =   hidden_states.reshape(UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						,     UpperCamelCase__						)

       snake_case   :				Tuple				 =   hidden_states + residual

       if not return_dict:
           return (output,)

       return TransformerTemporalModelOutput(sample=UpperCamelCase__						)









"""simple docstring"""



def   __lowerCAmelCase						(						lowercase  :  int			)     ->						int:


    """simple docstring"""





    if not isinstance(lowercase						,							lowercase			):
        raise ValueError("Input must be an integer"			)
    if input_num <= 0:
        raise ValueError("Input must be positive"			)
    return sum(
        divisor for divisor in range(1						,							input_num // 2 + 1			) if input_num % divisor == 0			)


if __name__ == "__main__":
  import doctest

  doctest.testmod()





