






'''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 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):
      __a	       =42







class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase   ,   _lowerCAmelCase  ):




      @register_to_config
      def __init__(	self			, lowerCamelCase = 16			, lowerCamelCase = 88			, lowerCamelCase = None			, lowerCamelCase = None			, lowerCamelCase = 1			, lowerCamelCase = 0.0			, lowerCamelCase = 32			, lowerCamelCase = None			, lowerCamelCase = False			, lowerCamelCase = None			, lowerCamelCase = "geglu"			, lowerCamelCase = True			, lowerCamelCase = True			, )				->Dict:



         '''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=_SCREAMING_SNAKE_CASE			, num_channels=_SCREAMING_SNAKE_CASE			, eps=1e-6			, affine=_SCREAMING_SNAKE_CASE   )
         __a					  =     nn.Linear(_SCREAMING_SNAKE_CASE			, _SCREAMING_SNAKE_CASE   )

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

         __a					  =     nn.Linear(_SCREAMING_SNAKE_CASE			, _SCREAMING_SNAKE_CASE   )






      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase=None			, lowerCamelCase=None			, lowerCamelCase=None			, lowerCamelCase=1			, lowerCamelCase=None			, lowerCamelCase = True			, )				->Tuple:



         '''simple docstring'''
         __a  ,      __a  ,      __a  ,      __a					  =     hidden_states.shape
         __a					  =     batch_frames // num_frames

         __a					  =     hidden_states

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

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

         __a					  =     self.proj_in(_SCREAMING_SNAKE_CASE   )

         # 2. Blocks
         for block in self.transformer_blocks:
            __a					  =     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
         __a					  =     self.proj_out(_SCREAMING_SNAKE_CASE   )
         __a					  =     (
             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()
         )
         __a					  =     hidden_states.reshape(_SCREAMING_SNAKE_CASE			, _SCREAMING_SNAKE_CASE			, _SCREAMING_SNAKE_CASE			, _SCREAMING_SNAKE_CASE   )

         __a					  =     hidden_states + residual

         if not return_dict:
            return (output,)

         return TransformerTemporalModelOutput(sample=_SCREAMING_SNAKE_CASE   )



from .imports import is_rich_available


if is_rich_available():
		from rich.traceback import install

		install(show_locals=False)

else:
		raise ModuleNotFoundError('''To use the rich extension, install rich with `pip install rich`''')
