





import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


if TYPE_CHECKING:
      from ... import PreTrainedTokenizerBase, TensorType

SCREAMING_SNAKE_CASE_      = logging.get_logger(__name__)

class 	UpperCamelCase__				(   lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    "vision-encoder-decoder"
     __snake_case					:			List[Any]				=    True






     def __init__(							self		:					Union[str, Any]		,**lowerCamelCase__		:					Optional[Any] )  ->	List[Any]:




           '''simple docstring'''


           super().__init__(**lowerCamelCase__ )
           if "encoder" not in kwargs or "decoder" not in kwargs:
                 raise ValueError(
                     F"""A configuraton of type {self.model_type} cannot be instantiated because """
                     F"""not both `encoder` and `decoder` sub-configurations are passed, but only {kwargs}""" )

           SCREAMING_SNAKE_CASE	=		kwargs.pop("""encoder""" )
           SCREAMING_SNAKE_CASE	=		encoder_config.pop("""model_type""" )
           SCREAMING_SNAKE_CASE	=		kwargs.pop("""decoder""" )
           SCREAMING_SNAKE_CASE	=		decoder_config.pop("""model_type""" )

           SCREAMING_SNAKE_CASE	=		AutoConfig.for_model(lowerCamelCase__		,**lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		AutoConfig.for_model(lowerCamelCase__		,**lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		True






     @classmethod
     def        SCREAMING_SNAKE_CASE__						(							cls		:					Dict		,lowerCamelCase__		:					PretrainedConfig		,lowerCamelCase__		:					PretrainedConfig		,**lowerCamelCase__		:					Dict )  ->	PretrainedConfig:




           '''simple docstring'''


           logger.info("""Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config""" )
           SCREAMING_SNAKE_CASE	=		True
           SCREAMING_SNAKE_CASE	=		True

           return cls(encoder=encoder_config.to_dict()		,decoder=decoder_config.to_dict()		,**lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					Union[str, Any] )  ->	List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		copy.deepcopy(self.__dict__ )
           SCREAMING_SNAKE_CASE	=		self.encoder.to_dict()
           SCREAMING_SNAKE_CASE	=		self.decoder.to_dict()
           SCREAMING_SNAKE_CASE	=		self.__class__.model_type
           return output

class 	UpperCamelCase__				(   lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    version.parse("1.11"     )






     @property
     def        SCREAMING_SNAKE_CASE__						(							self		:					List[str] )  ->	Mapping[str, Mapping[int, str]]:




           '''simple docstring'''


           return OrderedDict(
               [
                   ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
               ] )






     @property
     def        SCREAMING_SNAKE_CASE__						(							self		:					str )  ->	float:




           '''simple docstring'''


           return 1e-4






     @property
     def        SCREAMING_SNAKE_CASE__						(							self		:					List[str] )  ->	Mapping[str, Mapping[int, str]]:




           '''simple docstring'''


           return OrderedDict({"""last_hidden_state""": {0: """batch""", 1: """encoder_sequence"""}} )

class 	UpperCamelCase__				(   lowerCAmelCase_     ):



     '''simple docstring'''

     @property
     def        SCREAMING_SNAKE_CASE__						(							self		:					Union[str, Any] )  ->	Mapping[str, Mapping[int, str]]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		OrderedDict()
           SCREAMING_SNAKE_CASE	=		{0: """batch""", 1: """past_decoder_sequence + sequence"""}
           SCREAMING_SNAKE_CASE	=		{0: """batch""", 1: """past_decoder_sequence + sequence"""}
           SCREAMING_SNAKE_CASE	=		{0: """batch""", 1: """encoder_sequence"""}

           return common_inputs






     def        SCREAMING_SNAKE_CASE__						(							self		:					List[Any]		,lowerCamelCase__		:					"PreTrainedTokenizerBase"		,lowerCamelCase__		:					int = -1		,lowerCamelCase__		:					int = -1		,lowerCamelCase__		:					bool = False		,lowerCamelCase__		:					Optional["TensorType"] = None		,)  ->	Mapping[str, Any]:




           '''simple docstring'''


           import torch

           SCREAMING_SNAKE_CASE	=		OrderedDict()

           SCREAMING_SNAKE_CASE	=		super().generate_dummy_inputs(
               lowerCamelCase__		,batch_size=lowerCamelCase__		,seq_length=lowerCamelCase__		,is_pair=lowerCamelCase__		,framework=lowerCamelCase__ )

           SCREAMING_SNAKE_CASE,      SCREAMING_SNAKE_CASE	=		dummy_input["""input_ids"""].shape
           SCREAMING_SNAKE_CASE	=		(batch, encoder_sequence, self._config.encoder_hidden_size)
           SCREAMING_SNAKE_CASE	=		dummy_input.pop("""input_ids""" )
           SCREAMING_SNAKE_CASE	=		dummy_input.pop("""attention_mask""" )
           SCREAMING_SNAKE_CASE	=		torch.zeros(lowerCamelCase__ )

           return common_inputs

class 	UpperCamelCase__				(   lowerCAmelCase_     ):



     '''simple docstring'''

     @property
     def        SCREAMING_SNAKE_CASE__						(							self		:					List[Any] )  ->	None:




           '''simple docstring'''


           pass






     def        SCREAMING_SNAKE_CASE__						(							self		:					int		,lowerCamelCase__		:					PretrainedConfig )  ->	OnnxConfig:




           '''simple docstring'''


           return VisionEncoderDecoderEncoderOnnxConfig(lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					List[str]		,lowerCamelCase__		:					PretrainedConfig		,lowerCamelCase__		:					PretrainedConfig		,lowerCamelCase__		:					str = "default" )  ->	OnnxConfig:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		encoder_config.hidden_size
           return VisionEncoderDecoderDecoderOnnxConfig(lowerCamelCase__		,lowerCamelCase__ )









import copy

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


SCREAMING_SNAKE_CASE_		     = logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_		     = {
    """ut/deta""": """https://huggingface.co/ut/deta/resolve/main/config.json""",
}

class 	UpperCamelCase__				(   lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    "deta"
     __snake_case					:			int				=    {
         "hidden_size": "d_model",
         "num_attention_heads": "encoder_attention_heads",
     }






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




           '''simple docstring'''


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

           SCREAMING_SNAKE_CASE	=		backbone_config
           SCREAMING_SNAKE_CASE	=		num_queries
           SCREAMING_SNAKE_CASE	=		max_position_embeddings
           SCREAMING_SNAKE_CASE	=		d_model
           SCREAMING_SNAKE_CASE	=		encoder_ffn_dim
           SCREAMING_SNAKE_CASE	=		encoder_layers
           SCREAMING_SNAKE_CASE	=		encoder_attention_heads
           SCREAMING_SNAKE_CASE	=		decoder_ffn_dim
           SCREAMING_SNAKE_CASE	=		decoder_layers
           SCREAMING_SNAKE_CASE	=		decoder_attention_heads
           SCREAMING_SNAKE_CASE	=		dropout
           SCREAMING_SNAKE_CASE	=		attention_dropout
           SCREAMING_SNAKE_CASE	=		activation_dropout
           SCREAMING_SNAKE_CASE	=		activation_function
           SCREAMING_SNAKE_CASE	=		init_std
           SCREAMING_SNAKE_CASE	=		init_xavier_std
           SCREAMING_SNAKE_CASE	=		encoder_layerdrop
           SCREAMING_SNAKE_CASE	=		auxiliary_loss
           SCREAMING_SNAKE_CASE	=		position_embedding_type
           # deformable attributes
           SCREAMING_SNAKE_CASE	=		num_feature_levels
           SCREAMING_SNAKE_CASE	=		encoder_n_points
           SCREAMING_SNAKE_CASE	=		decoder_n_points
           SCREAMING_SNAKE_CASE	=		two_stage
           SCREAMING_SNAKE_CASE	=		two_stage_num_proposals
           SCREAMING_SNAKE_CASE	=		with_box_refine
           SCREAMING_SNAKE_CASE	=		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
           SCREAMING_SNAKE_CASE	=		class_cost
           SCREAMING_SNAKE_CASE	=		bbox_cost
           SCREAMING_SNAKE_CASE	=		giou_cost
           # Loss coefficients
           SCREAMING_SNAKE_CASE	=		mask_loss_coefficient
           SCREAMING_SNAKE_CASE	=		dice_loss_coefficient
           SCREAMING_SNAKE_CASE	=		bbox_loss_coefficient
           SCREAMING_SNAKE_CASE	=		giou_loss_coefficient
           SCREAMING_SNAKE_CASE	=		eos_coefficient
           SCREAMING_SNAKE_CASE	=		focal_alpha
           super().__init__(is_encoder_decoder=lowerCamelCase__		,**lowerCamelCase__ )






     @property
     def        SCREAMING_SNAKE_CASE__						(							self		:					str )  ->	int:




           '''simple docstring'''


           return self.encoder_attention_heads






     @property
     def        SCREAMING_SNAKE_CASE__						(							self		:					List[str] )  ->	int:




           '''simple docstring'''


           return self.d_model






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		copy.deepcopy(self.__dict__ )
           SCREAMING_SNAKE_CASE	=		self.backbone_config.to_dict()
           SCREAMING_SNAKE_CASE	=		self.__class__.model_type
           return output


