


'''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   UpperCAmelCase_    (_UpperCAmelCase    ):





    """simple docstring"""






    lowerCamelCase    :   torch.FloatTensor







class   UpperCAmelCase_    (_UpperCAmelCase   ,						_UpperCAmelCase    ):





    """simple docstring"""






    @register_to_config
    def __init__(				self     ,	SCREAMING_SNAKE_CASE_ = 16     ,	SCREAMING_SNAKE_CASE_ = 88     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = 1     ,	SCREAMING_SNAKE_CASE_ = 0.0     ,	SCREAMING_SNAKE_CASE_ = 32     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = "geglu"     ,	SCREAMING_SNAKE_CASE_ = True     ,	SCREAMING_SNAKE_CASE_ = True     ,	)							->	Optional[Any]:
         super().__init__()
         __lowerCamelCase  :      int														=						num_attention_heads
         __lowerCamelCase  :      str														=						attention_head_dim
         __lowerCamelCase  :      Optional[int]														=						num_attention_heads * attention_head_dim

         __lowerCamelCase  :      Tuple														=						in_channels

         __lowerCamelCase  :      List[str]														=						torch.nn.GroupNorm(num_groups=SCREAMING_SNAKE_CASE_     ,	num_channels=SCREAMING_SNAKE_CASE_     ,	eps=1E-6     ,	affine=SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      List[Any]														=						nn.Linear(SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )

         # 3. Define transformers blocks
         __lowerCamelCase  :      List[str]														=						nn.ModuleList(
             [
                 BasicTransformerBlock(
                     SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	dropout=SCREAMING_SNAKE_CASE_     ,	cross_attention_dim=SCREAMING_SNAKE_CASE_     ,	activation_fn=SCREAMING_SNAKE_CASE_     ,	attention_bias=SCREAMING_SNAKE_CASE_     ,	double_self_attention=SCREAMING_SNAKE_CASE_     ,	norm_elementwise_affine=SCREAMING_SNAKE_CASE_     ,	)
                 for d in range(SCREAMING_SNAKE_CASE_      )
             ]      )

         __lowerCamelCase  :      Union[str, Any]														=						nn.Linear(SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )







    def  lowercase_							(				self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_=1     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_ = True     ,	)							->	Union[str, Any]:
         __lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase  :      Dict														=						hidden_states.shape
         __lowerCamelCase  :      Dict														=						batch_frames // num_frames

         __lowerCamelCase  :      Tuple														=						hidden_states

         __lowerCamelCase  :      Any														=						hidden_states[None, :].reshape(SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      int														=						hidden_states.permute(0     ,	2     ,	1     ,	3     ,	4      )

         __lowerCamelCase  :      List[str]														=						self.norm(SCREAMING_SNAKE_CASE_      )
         __lowerCamelCase  :      Tuple														=						hidden_states.permute(0     ,	3     ,	4     ,	2     ,	1      ).reshape(batch_size * height * width     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_      )

         __lowerCamelCase  :      Any														=						self.proj_in(SCREAMING_SNAKE_CASE_      )

         # 2. Blocks
         for block in self.transformer_blocks:
              __lowerCamelCase  :      List[Any]														=						block(
                  SCREAMING_SNAKE_CASE_     ,	encoder_hidden_states=SCREAMING_SNAKE_CASE_     ,	timestep=SCREAMING_SNAKE_CASE_     ,	cross_attention_kwargs=SCREAMING_SNAKE_CASE_     ,	class_labels=SCREAMING_SNAKE_CASE_     ,	)

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

         __lowerCamelCase  :      Dict														=						hidden_states + residual

         if not return_dict:
              return (output,)

         return TransformerTemporalModelOutput(sample=SCREAMING_SNAKE_CASE_      )










'''simple docstring'''



def      UpperCAmelCase__   (      UpperCAmelCase_       :							int = 1_00				)	->						int:
     __lowerCamelCase  :      Union[str, Any]														=						n * (n + 1) * (2 * n + 1) / 6
     __lowerCamelCase  :      Union[str, Any]														=						(n * (n + 1) / 2) ** 2
     return int(square_of_sum - sum_of_squares				)


if __name__ == "__main__":
      print(f'''{solution() = }''')






