




"""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_  (						snake_case_							):
    lowercase__											=      42






class 	UpperCAmelCase_  (						snake_case_,   snake_case_							):




    @register_to_config
    def __init__(    self						:       int	, snake_case_						:       int = 16	, snake_case_						:       int = 88	, snake_case_						:       Optional[int] = None	, snake_case_						:       Optional[int] = None	, snake_case_						:       int = 1	, snake_case_						:       float = 0.0	, snake_case_						:       int = 32	, snake_case_						:       Optional[int] = None	, snake_case_						:       bool = False	, snake_case_						:       Optional[int] = None	, snake_case_						:       str = "geglu"	, snake_case_						:       bool = True	, snake_case_						:       bool = True	, )      ->							str:




     '''simple docstring'''

     super().__init__()
     A__       =				num_attention_heads
     A__       =				attention_head_dim
     A__       =				num_attention_heads * attention_head_dim

     A__       =				in_channels

     A__       =				torch.nn.GroupNorm(num_groups=UpperCAmelCase__	, num_channels=UpperCAmelCase__	, eps=1e-6	, affine=UpperCAmelCase__      )
     A__       =				nn.Linear(UpperCAmelCase__	, UpperCAmelCase__      )

     # 3. Define transformers blocks
     A__       =				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__      )
         ]      )

     A__       =				nn.Linear(UpperCAmelCase__	, UpperCAmelCase__      )




    def 							__magic_name__							(    self						:       Optional[Any]	, snake_case_						:       int	, snake_case_						:       List[Any]=None	, snake_case_						:       Optional[Any]=None	, snake_case_						:       int=None	, snake_case_						:       Union[str, Any]=1	, snake_case_						:       int=None	, snake_case_						:       bool = True	, )      ->							Dict:




     '''simple docstring'''

     A__       =				hidden_states.shape
     A__       =				batch_frames // num_frames

     A__       =				hidden_states

     A__       =				hidden_states[None, :].reshape(UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__      )
     A__       =				hidden_states.permute(0	, 2	, 1	, 3	, 4      )

     A__       =				self.norm(UpperCAmelCase__      )
     A__       =				hidden_states.permute(0	, 3	, 4	, 2	, 1      ).reshape(batch_size * height * width	, UpperCAmelCase__	, UpperCAmelCase__      )

     A__       =				self.proj_in(UpperCAmelCase__      )

     # 2. Blocks
     for block in self.transformer_blocks:
      A__       =				block(
          UpperCAmelCase__	, encoder_hidden_states=UpperCAmelCase__	, timestep=UpperCAmelCase__	, cross_attention_kwargs=UpperCAmelCase__	, class_labels=UpperCAmelCase__	, )

     # 3. Output
     A__       =				self.proj_out(UpperCAmelCase__      )
     A__       =				(
         hidden_states[None, None, :]
         .reshape(UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__      )
         .permute(0	, 3	, 4	, 1	, 2      )
         .contiguous()
     )
     A__       =				hidden_states.reshape(UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__	, UpperCAmelCase__      )

     A__       =				hidden_states + residual

     if not return_dict:
      return (output,)

     return TransformerTemporalModelOutput(sample=UpperCAmelCase__      )













"""simple docstring"""




_snake_case          =   '\n# Transformers installation\n! pip install transformers datasets\n# To install from source instead of the last release, comment the command above and uncomment the following one.\n# ! pip install git+https://github.com/huggingface/transformers.git\n'

_snake_case          =   [{'type': 'code', 'content': INSTALL_CONTENT}]
_snake_case          =   {
    '{processor_class}': 'FakeProcessorClass',
    '{model_class}': 'FakeModelClass',
    '{object_class}': 'FakeObjectClass',
}

