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


      UpperCAmelCase_   :   torch.FloatTensor




class 					_lowercase						(   lowerCAmelCase		,lowerCAmelCase ):
      '''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       ,)      ->      Dict:



         '''simple docstring'''



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

         UpperCAmelCase__				:					Union[str, Any] 					=	in_channels

         UpperCAmelCase__				:					Dict 					=	torch.nn.GroupNorm(num_groups=lowerCamelCase_       ,num_channels=lowerCamelCase_       ,eps=1e-6       ,affine=lowerCamelCase_				)
         UpperCAmelCase__				:					List[str] 					=	nn.Linear(lowerCamelCase_       ,lowerCamelCase_				)

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

         UpperCAmelCase__				:					Tuple 					=	nn.Linear(lowerCamelCase_       ,lowerCamelCase_				)




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



         '''simple docstring'''



         UpperCAmelCase__					,   UpperCAmelCase__					,   UpperCAmelCase__					,   UpperCAmelCase__				:					Tuple 					=	hidden_states.shape
         UpperCAmelCase__				:					Dict 					=	batch_frames // num_frames

         UpperCAmelCase__				:					Optional[Any] 					=	hidden_states

         UpperCAmelCase__				:					Optional[int] 					=	hidden_states[None, :].reshape(lowerCamelCase_       ,lowerCamelCase_       ,lowerCamelCase_       ,lowerCamelCase_       ,lowerCamelCase_				)
         UpperCAmelCase__				:					Dict 					=	hidden_states.permute(0       ,2       ,1       ,3       ,4				)

         UpperCAmelCase__				:					Union[str, Any] 					=	self.norm(lowerCamelCase_				)
         UpperCAmelCase__				:					Any 					=	hidden_states.permute(0       ,3       ,4       ,2       ,1				).reshape(batch_size * height * width       ,lowerCamelCase_       ,lowerCamelCase_				)

         UpperCAmelCase__				:					List[str] 					=	self.proj_in(lowerCamelCase_				)

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

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

         UpperCAmelCase__				:					Optional[int] 					=	hidden_states + residual

         if not return_dict:
            return (output,)

         return TransformerTemporalModelOutput(sample=lowerCamelCase_				)





'''simple docstring'''

from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Features, Sequence, Value
from .base import TaskTemplate


@dataclass(frozen=lowerCAmelCase )
class 					_lowercase						(   lowerCAmelCase ):
      '''simple docstring'''


      UpperCAmelCase_   :   str   				= field(default='''question-answering-extractive'''		,metadata={'''include_in_asdict_even_if_is_default''': True} )
      UpperCAmelCase_   :   ClassVar[Features]   				= Features({'''question''': Value('''string''' ), '''context''': Value('''string''' )} )
      UpperCAmelCase_   :   ClassVar[Features]   				= Features(
          {
              '''answers''': Sequence(
                  {
                      '''text''': Value('''string''' ),
                      '''answer_start''': Value('''int32''' ),
                  } )
          } )
      UpperCAmelCase_   :   str   				= "question"
      UpperCAmelCase_   :   str   				= "context"
      UpperCAmelCase_   :   str   				= "answers"




      @property
      def 		lowerCAmelCase__       (					self				)      ->      Dict[str, str]:



         '''simple docstring'''



         return {self.question_column: "question", self.context_column: "context", self.answers_column: "answers"}




