



'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase	:		Union[str, Any]				=   {
    '''configuration_distilbert''': [
        '''DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''DistilBertConfig''',
        '''DistilBertOnnxConfig''',
    ],
    '''tokenization_distilbert''': ['''DistilBertTokenizer'''],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase	:		Tuple				=   ['''DistilBertTokenizerFast''']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase	:		Tuple				=   [
	    '''DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''DistilBertForMaskedLM''',
	    '''DistilBertForMultipleChoice''',
	    '''DistilBertForQuestionAnswering''',
	    '''DistilBertForSequenceClassification''',
	    '''DistilBertForTokenClassification''',
	    '''DistilBertModel''',
	    '''DistilBertPreTrainedModel''',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase	:		List[str]				=   [
	    '''TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TFDistilBertForMaskedLM''',
	    '''TFDistilBertForMultipleChoice''',
	    '''TFDistilBertForQuestionAnswering''',
	    '''TFDistilBertForSequenceClassification''',
	    '''TFDistilBertForTokenClassification''',
	    '''TFDistilBertMainLayer''',
	    '''TFDistilBertModel''',
	    '''TFDistilBertPreTrainedModel''',
	]

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase	:		Optional[int]				=   [
	    '''FlaxDistilBertForMaskedLM''',
	    '''FlaxDistilBertForMultipleChoice''',
	    '''FlaxDistilBertForQuestionAnswering''',
	    '''FlaxDistilBertForSequenceClassification''',
	    '''FlaxDistilBertForTokenClassification''',
	    '''FlaxDistilBertModel''',
	    '''FlaxDistilBertPreTrainedModel''',
	]


if TYPE_CHECKING:
	from .configuration_distilbert import (
	    DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    DistilBertConfig,
	    DistilBertOnnxConfig,
	)
	from .tokenization_distilbert import DistilBertTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_distilbert_fast import DistilBertTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_distilbert import (
		    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DistilBertForMaskedLM,
		    DistilBertForMultipleChoice,
		    DistilBertForQuestionAnswering,
		    DistilBertForSequenceClassification,
		    DistilBertForTokenClassification,
		    DistilBertModel,
		    DistilBertPreTrainedModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_distilbert import (
		    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFDistilBertForMaskedLM,
		    TFDistilBertForMultipleChoice,
		    TFDistilBertForQuestionAnswering,
		    TFDistilBertForSequenceClassification,
		    TFDistilBertForTokenClassification,
		    TFDistilBertMainLayer,
		    TFDistilBertModel,
		    TFDistilBertPreTrainedModel,
		)

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_flax_distilbert import (
		    FlaxDistilBertForMaskedLM,
		    FlaxDistilBertForMultipleChoice,
		    FlaxDistilBertForQuestionAnswering,
		    FlaxDistilBertForSequenceClassification,
		    FlaxDistilBertForTokenClassification,
		    FlaxDistilBertModel,
		    FlaxDistilBertPreTrainedModel,
		)

else:
	import sys

	lowerCAmelCase	:		List[str]				=   _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




'''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__	(		UpperCamelCase__ ):
					a      :     torch.FloatTensor






class 					UpperCAmelCase__	(		UpperCamelCase__							,       UpperCamelCase__ ):



					@register_to_config
					def __init__(    self			,				UpperCamelCase = 16			,				UpperCamelCase = 88			,				UpperCamelCase = None			,				UpperCamelCase = None			,				UpperCamelCase = 1			,				UpperCamelCase = 0.0			,				UpperCamelCase = 32			,				UpperCamelCase = None			,				UpperCamelCase = False			,				UpperCamelCase = None			,				UpperCamelCase = "geglu"			,				UpperCamelCase = True			,				UpperCamelCase = True			,				)     ->			List[str]:
						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=UpperCamelCase			,				num_channels=UpperCamelCase			,				eps=1E-6			,				affine=UpperCamelCase     )
						__lowerCAmelCase												=  nn.Linear(UpperCamelCase			,				UpperCamelCase     )

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

						__lowerCAmelCase												=  nn.Linear(UpperCamelCase			,				UpperCamelCase     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase=None			,				UpperCamelCase=None			,				UpperCamelCase=None			,				UpperCamelCase=1			,				UpperCamelCase=None			,				UpperCamelCase = True			,				)     ->			List[str]:
						__lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase												=  hidden_states.shape
						__lowerCAmelCase												=  batch_frames // num_frames

						__lowerCAmelCase												=  hidden_states

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

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

						__lowerCAmelCase												=  self.proj_in(UpperCamelCase     )

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

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

						__lowerCAmelCase												=  hidden_states + residual

						if not return_dict:
							return (output,)

						return TransformerTemporalModelOutput(sample=UpperCamelCase     )