






'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE							=						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							=						{
    'studio-ousia/luke-base': 'https://huggingface.co/studio-ousia/luke-base/resolve/main/config.json',
    'studio-ousia/luke-large': 'https://huggingface.co/studio-ousia/luke-large/resolve/main/config.json',
}
class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      UpperCamelCase_             =      '''luke'''






      def __init__(			self      :		Any  ,   UpperCAmelCase      :		Union[str, Any]=5_0267  ,   UpperCAmelCase      :		str=50_0000  ,   UpperCAmelCase      :		str=768  ,   UpperCAmelCase      :		Any=256  ,   UpperCAmelCase      :		Optional[Any]=12  ,   UpperCAmelCase      :		Union[str, Any]=12  ,   UpperCAmelCase      :		Optional[Any]=3072  ,   UpperCAmelCase      :		Optional[Any]="gelu"  ,   UpperCAmelCase      :		Optional[Any]=0.1  ,   UpperCAmelCase      :		Any=0.1  ,   UpperCAmelCase      :		List[Any]=512  ,   UpperCAmelCase      :		List[Any]=2  ,   UpperCAmelCase      :		Tuple=0.0_2  ,   UpperCAmelCase      :		Optional[Any]=1e-12  ,   UpperCAmelCase      :		Union[str, Any]=True  ,   UpperCAmelCase      :		str=None  ,   UpperCAmelCase      :		Tuple=1  ,   UpperCAmelCase      :		Optional[int]=0  ,   UpperCAmelCase      :		List[str]=2  ,   **UpperCAmelCase      :		Tuple  ,   )	->	List[Any]:


       '''simple docstring'''

       super().__init__(pad_token_id=UpperCAmelCase  ,   bos_token_id=UpperCAmelCase  ,   eos_token_id=UpperCAmelCase  ,   **UpperCAmelCase		)

       lowercase       : int						=vocab_size
       lowercase       : Tuple						=entity_vocab_size
       lowercase       : Any						=hidden_size
       lowercase       : Union[str, Any]						=entity_emb_size
       lowercase       : int						=num_hidden_layers
       lowercase       : Dict						=num_attention_heads
       lowercase       : Dict						=hidden_act
       lowercase       : List[str]						=intermediate_size
       lowercase       : str						=hidden_dropout_prob
       lowercase       : str						=attention_probs_dropout_prob
       lowercase       : Any						=max_position_embeddings
       lowercase       : int						=type_vocab_size
       lowercase       : List[str]						=initializer_range
       lowercase       : Optional[int]						=layer_norm_eps
       lowercase       : Union[str, Any]						=use_entity_aware_attention
       lowercase       : List[str]						=classifier_dropout








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 	__snake_case   ( SCREAMING_SNAKE_CASE ):
		SCREAMING_SNAKE_CASE__								=	42



class 	__snake_case   ( SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE ):
		@register_to_config
		def __init__(							self    ,a_ = 16    ,a_ = 88    ,a_ = None    ,a_ = None    ,a_ = 1    ,a_ = 0.0    ,a_ = 32    ,a_ = None    ,a_ = False    ,a_ = None    ,a_ = "geglu"    ,a_ = True    ,a_ = True    ,):







						"""simple docstring"""
						super().__init__()
						lowerCAmelCase__		  =  num_attention_heads
						lowerCAmelCase__		  =  attention_head_dim
						lowerCAmelCase__		  =  num_attention_heads * attention_head_dim

						lowerCAmelCase__		  =  in_channels

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

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

						lowerCAmelCase__		  =  nn.Linear(a_    ,a_						)



		def 						SCREAMING_SNAKE_CASE_					(							self    ,a_    ,a_=None    ,a_=None    ,a_=None    ,a_=1    ,a_=None    ,a_ = True    ,):







						"""simple docstring"""
						lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__		  =  hidden_states.shape
						lowerCAmelCase__		  =  batch_frames // num_frames

						lowerCAmelCase__		  =  hidden_states

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

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

						lowerCAmelCase__		  =  self.proj_in(a_						)

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

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

						lowerCAmelCase__		  =  hidden_states + residual

						if not return_dict:
										return (output,)

						return TransformerTemporalModelOutput(sample=a_						)
