'''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 				_lowercase	(      _UpperCAmelCase   ):
 '''simple docstring'''


 UpperCAmelCase_      :      torch.FloatTensor




class 				_lowercase	(      _UpperCAmelCase		,_UpperCAmelCase   ):
 '''simple docstring'''


 @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					,)			->			List[str]:



    '''simple docstring'''



    super().__init__()
    UpperCAmelCase__							:				Tuple   				=  num_attention_heads
    UpperCAmelCase__							:				str   				=  attention_head_dim
    UpperCAmelCase__							:				List[Any]   				=  num_attention_heads * attention_head_dim

    UpperCAmelCase__							:				str   				=  in_channels

    UpperCAmelCase__							:				Dict   				=  torch.nn.GroupNorm(num_groups=A_					,num_channels=A_					,eps=1e-6					,affine=A_							)
    UpperCAmelCase__							:				int   				=  nn.Linear(A_					,A_							)

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

    UpperCAmelCase__							:				Optional[int]   				=  nn.Linear(A_					,A_							)




 def 		lowerCAmelCase__					(				self					,lowerCamelCase_					,lowerCamelCase_=None					,lowerCamelCase_=None					,lowerCamelCase_=None					,lowerCamelCase_=1					,lowerCamelCase_=None					,lowerCamelCase_ = True					,)			->			Tuple:



    '''simple docstring'''



    UpperCAmelCase__				,      UpperCAmelCase__				,      UpperCAmelCase__				,      UpperCAmelCase__							:				Optional[Any]   				=  hidden_states.shape
    UpperCAmelCase__							:				Optional[Any]   				=  batch_frames // num_frames

    UpperCAmelCase__							:				Union[str, Any]   				=  hidden_states

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

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

    UpperCAmelCase__							:				Union[str, Any]   				=  self.proj_in(A_							)

    # 2. Blocks
    for block in self.transformer_blocks:
       UpperCAmelCase__							:				Union[str, Any]   				=  block(
           A_					,encoder_hidden_states=A_					,timestep=A_					,cross_attention_kwargs=A_					,class_labels=A_					,)

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

    UpperCAmelCase__							:				List[Any]   				=  hidden_states + residual

    if not return_dict:
       return (output,)

    return TransformerTemporalModelOutput(sample=A_							)





'''simple docstring'''

import math







def __UpperCamelCase(   _A					:				float  ,			_A					:				float    ):
   '''simple docstring'''
   return math.pow(_A  ,			2    ) - a







def __UpperCamelCase(   _A					:				float    ):
   '''simple docstring'''
   return 2 * x







def __UpperCamelCase(   _A					:				float    ):
   '''simple docstring'''
   UpperCAmelCase__							:				int   				=  2.0

   while start <= a:
      UpperCAmelCase__							:				int   				=  math.pow(_A  ,			2    )

   return start







def __UpperCamelCase(   _A					:				float  ,			_A					:				int = 99_99  ,			_A					:				float = 0.0_0_0_0_0_0_0_0_0_0_0_0_0_1    ):
   '''simple docstring'''

   if a < 0:
      raise ValueError('''math domain error'''    )

   UpperCAmelCase__							:				Any   				=  get_initial_point(_A    )

   for _ in range(_A    ):
      UpperCAmelCase__							:				Optional[Any]   				=  value
      UpperCAmelCase__							:				Tuple   				=  value - fx(_A  ,			_A    ) / fx_derivative(_A    )
      if abs(prev_value - value    ) < tolerance:
         return value

   return value


if __name__ == "__main__":
  from doctest import testmod

  testmod()




