



"""simple docstring"""






import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


__snake_case				:  List[Any] =       logging.get_logger(__name__)

__snake_case				:  Optional[Any] =       {
    'ut/deta': 'https://huggingface.co/ut/deta/resolve/main/config.json',
}



class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'deta'
	SCREAMING_SNAKE_CASE        =      {
	    'hidden_size': 'd_model',
	    'num_attention_heads': 'encoder_attention_heads',
	}

	def __init__(	self:						Union[str, Any]			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=None			,     _SCREAMING_SNAKE_CASE:						int=900			,     _SCREAMING_SNAKE_CASE:						str=2048			,     _SCREAMING_SNAKE_CASE:						Any=6			,     _SCREAMING_SNAKE_CASE:						Tuple=2048			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=8			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=6			,     _SCREAMING_SNAKE_CASE:						str=1024			,     _SCREAMING_SNAKE_CASE:						List[str]=8			,     _SCREAMING_SNAKE_CASE:						List[Any]=0.0			,     _SCREAMING_SNAKE_CASE:						Dict=True			,     _SCREAMING_SNAKE_CASE:						List[str]="relu"			,     _SCREAMING_SNAKE_CASE:						Any=256			,     _SCREAMING_SNAKE_CASE:						Tuple=0.1			,     _SCREAMING_SNAKE_CASE:						Optional[int]=0.0			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=0.0			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=0.02			,     _SCREAMING_SNAKE_CASE:						Any=1.0			,     _SCREAMING_SNAKE_CASE:						Dict=True			,     _SCREAMING_SNAKE_CASE:						Optional[int]=False			,     _SCREAMING_SNAKE_CASE:						int="sine"			,     _SCREAMING_SNAKE_CASE:						Any=5			,     _SCREAMING_SNAKE_CASE:						Optional[int]=4			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=4			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=True			,     _SCREAMING_SNAKE_CASE:						Any=300			,     _SCREAMING_SNAKE_CASE:						int=True			,     _SCREAMING_SNAKE_CASE:						List[str]=True			,     _SCREAMING_SNAKE_CASE:						str=1			,     _SCREAMING_SNAKE_CASE:						int=5			,     _SCREAMING_SNAKE_CASE:						List[str]=2			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=1			,     _SCREAMING_SNAKE_CASE:						Any=1			,     _SCREAMING_SNAKE_CASE:						Any=5			,     _SCREAMING_SNAKE_CASE:						int=2			,     _SCREAMING_SNAKE_CASE:						int=0.1			,     _SCREAMING_SNAKE_CASE:						List[str]=0.25			,     **_SCREAMING_SNAKE_CASE:						int			,     )							->			Dict:

				"""simple docstring"""

				if backbone_config is None:
							logger.info("`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.")
							__lowerCAmelCase :    Any				=			CONFIG_MAPPING["resnet"](out_features=["stage2", "stage3", "stage4"])
				else:
							if isinstance(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE):
										__lowerCAmelCase :    List[str]				=			backbone_config.pop("model_type")
										__lowerCAmelCase :    List[str]				=			CONFIG_MAPPING[backbone_model_type]
										__lowerCAmelCase :    Optional[Any]				=			config_class.from_dict(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    int				=			backbone_config
				__lowerCAmelCase :    List[Any]				=			num_queries
				__lowerCAmelCase :    Any				=			max_position_embeddings
				__lowerCAmelCase :    Optional[Any]				=			d_model
				__lowerCAmelCase :    str				=			encoder_ffn_dim
				__lowerCAmelCase :    Union[str, Any]				=			encoder_layers
				__lowerCAmelCase :    int				=			encoder_attention_heads
				__lowerCAmelCase :    Optional[int]				=			decoder_ffn_dim
				__lowerCAmelCase :    int				=			decoder_layers
				__lowerCAmelCase :    List[str]				=			decoder_attention_heads
				__lowerCAmelCase :    Optional[Any]				=			dropout
				__lowerCAmelCase :    str				=			attention_dropout
				__lowerCAmelCase :    Tuple				=			activation_dropout
				__lowerCAmelCase :    Tuple				=			activation_function
				__lowerCAmelCase :    Dict				=			init_std
				__lowerCAmelCase :    Optional[Any]				=			init_xavier_std
				__lowerCAmelCase :    Any				=			encoder_layerdrop
				__lowerCAmelCase :    Optional[int]				=			auxiliary_loss
				__lowerCAmelCase :    Any				=			position_embedding_type
				# deformable attributes
				__lowerCAmelCase :    List[str]				=			num_feature_levels
				__lowerCAmelCase :    int				=			encoder_n_points
				__lowerCAmelCase :    List[Any]				=			decoder_n_points
				__lowerCAmelCase :    Optional[Any]				=			two_stage
				__lowerCAmelCase :    Optional[int]				=			two_stage_num_proposals
				__lowerCAmelCase :    Any				=			with_box_refine
				__lowerCAmelCase :    Any				=			assign_first_stage
				if two_stage is True and with_box_refine is False:
							raise ValueError("If two_stage is True, with_box_refine must be True.")
				# Hungarian matcher
				__lowerCAmelCase :    Dict				=			class_cost
				__lowerCAmelCase :    Optional[Any]				=			bbox_cost
				__lowerCAmelCase :    Tuple				=			giou_cost
				# Loss coefficients
				__lowerCAmelCase :    str				=			mask_loss_coefficient
				__lowerCAmelCase :    List[Any]				=			dice_loss_coefficient
				__lowerCAmelCase :    List[Any]				=			bbox_loss_coefficient
				__lowerCAmelCase :    Optional[int]				=			giou_loss_coefficient
				__lowerCAmelCase :    List[str]				=			eos_coefficient
				__lowerCAmelCase :    int				=			focal_alpha
				super().__init__(is_encoder_decoder=_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

	@property
	def 				_SCREAMING_SNAKE_CASE  (	self:						Any)							->			int:

				"""simple docstring"""

				return self.encoder_attention_heads

	@property
	def 				_SCREAMING_SNAKE_CASE  (	self:						Any)							->			int:

				"""simple docstring"""

				return self.d_model







	def 				_SCREAMING_SNAKE_CASE  (	self:						Optional[int])							->			List[Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Optional[Any]				=			copy.deepcopy(self.__dict__)
				__lowerCAmelCase :    Union[str, Any]				=			self.backbone_config.to_dict()
				__lowerCAmelCase :    Dict				=			self.__class__.model_type
				return output




"""simple docstring"""






import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class      A__  (    __SCREAMING_SNAKE_CASE    ,						__SCREAMING_SNAKE_CASE    ,						__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	@register_to_config
	def __init__(	self:						List[str]			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						float			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						str			,     _SCREAMING_SNAKE_CASE:						bool = False			,     )							->			Any:

				"""simple docstring"""

				super().__init__()

				__lowerCAmelCase :    str				=			nn.Embedding(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Dict				=			nn.Embedding(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    str				=			False

				__lowerCAmelCase :    Optional[Any]				=			nn.Dropout(p=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Dict				=			TaConfig(
				    vocab_size=_SCREAMING_SNAKE_CASE			,     d_model=_SCREAMING_SNAKE_CASE			,     num_heads=_SCREAMING_SNAKE_CASE			,     d_kv=_SCREAMING_SNAKE_CASE			,     d_ff=_SCREAMING_SNAKE_CASE			,     dropout_rate=_SCREAMING_SNAKE_CASE			,     feed_forward_proj=_SCREAMING_SNAKE_CASE			,     is_decoder=_SCREAMING_SNAKE_CASE			,     is_encoder_decoder=_SCREAMING_SNAKE_CASE			,     )

				__lowerCAmelCase :    str				=			nn.ModuleList()
				for lyr_num in range(_SCREAMING_SNAKE_CASE):
							__lowerCAmelCase :    int				=			TaBlock(_SCREAMING_SNAKE_CASE)
							self.encoders.append(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Dict				=			TaLayerNorm(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Any				=			nn.Dropout(p=_SCREAMING_SNAKE_CASE)







	def 				_SCREAMING_SNAKE_CASE  (	self:						Any			,     _SCREAMING_SNAKE_CASE:						Tuple			,     _SCREAMING_SNAKE_CASE:						str)							->			List[str]:

				"""simple docstring"""

				__lowerCAmelCase :    Union[str, Any]				=			self.token_embedder(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Optional[Any]				=			encoder_input_tokens.shape[1]
				__lowerCAmelCase :    List[Any]				=			torch.arange(_SCREAMING_SNAKE_CASE			,     device=encoder_input_tokens.device)
				x += self.position_encoding(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    List[Any]				=			self.dropout_pre(_SCREAMING_SNAKE_CASE)

				# inverted the attention mask
				__lowerCAmelCase :    List[Any]				=			encoder_input_tokens.size()
				__lowerCAmelCase :    Any				=			self.get_extended_attention_mask(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

				for lyr in self.encoders:
							__lowerCAmelCase :    Union[str, Any]				=			lyr(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)[0]
				__lowerCAmelCase :    int				=			self.layer_norm(_SCREAMING_SNAKE_CASE)

				return self.dropout_post(_SCREAMING_SNAKE_CASE), encoder_inputs_mask