




import copy
from collections import OrderedDict
from typing import Dict, Mapping

from packaging import version

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


lowerCamelCase__			:       str         =							logging.get_logger(__name__)

lowerCamelCase__			:       Optional[Any]         =							{
    'facebook/detr-resnet-50': 'https://huggingface.co/facebook/detr-resnet-50/resolve/main/config.json',
    # See all DETR models at https://huggingface.co/models?filter=detr
}





class 	lowerCamelCase_							(				_SCREAMING_SNAKE_CASE ):


 '''simple docstring'''







 lowercase_       =   "detr"
 lowercase_       =   ["past_key_values"]
 lowercase_       =   {
     "hidden_size": "d_model",
     "num_attention_heads": "encoder_attention_heads",
 }



 def __init__(							self  :		Optional[Any]    ,    _lowerCAmelCase  :		Optional[Any]=True    ,    _lowerCAmelCase  :		List[Any]=None    ,    _lowerCAmelCase  :		str=3    ,    _lowerCAmelCase  :		Optional[Any]=100    ,    _lowerCAmelCase  :		Dict=6    ,    _lowerCAmelCase  :		str=2_048    ,    _lowerCAmelCase  :		Any=8    ,    _lowerCAmelCase  :		Optional[int]=6    ,    _lowerCAmelCase  :		Union[str, Any]=2_048    ,    _lowerCAmelCase  :		Union[str, Any]=8    ,    _lowerCAmelCase  :		List[Any]=0.0    ,    _lowerCAmelCase  :		Tuple=0.0    ,    _lowerCAmelCase  :		List[Any]=True    ,    _lowerCAmelCase  :		Tuple="relu"    ,    _lowerCAmelCase  :		Any=256    ,    _lowerCAmelCase  :		Optional[Any]=0.1    ,    _lowerCAmelCase  :		Dict=0.0    ,    _lowerCAmelCase  :		Dict=0.0    ,    _lowerCAmelCase  :		Tuple=0.02    ,    _lowerCAmelCase  :		Optional[Any]=1.0    ,    _lowerCAmelCase  :		Optional[Any]=False    ,    _lowerCAmelCase  :		Optional[int]="sine"    ,    _lowerCAmelCase  :		Optional[int]="resnet50"    ,    _lowerCAmelCase  :		Any=True    ,    _lowerCAmelCase  :		Any=False    ,    _lowerCAmelCase  :		Optional[int]=1    ,    _lowerCAmelCase  :		List[str]=5    ,    _lowerCAmelCase  :		Dict=2    ,    _lowerCAmelCase  :		Optional[Any]=1    ,    _lowerCAmelCase  :		Tuple=1    ,    _lowerCAmelCase  :		Dict=5    ,    _lowerCAmelCase  :		List[Any]=2    ,    _lowerCAmelCase  :		Any=0.1    ,    **_lowerCAmelCase  :		Optional[int]    ,    ):
       if backbone_config is not None and use_timm_backbone:
             raise ValueError('You can\'t specify both `backbone_config` and `use_timm_backbone`.'						)

       if not use_timm_backbone:
             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=['stage4']						)
             elif isinstance(_lowerCAmelCase    ,    _lowerCAmelCase						):
                   SCREAMING_SNAKE_CASE_     						=      backbone_config.get('model_type'						)
                   SCREAMING_SNAKE_CASE_     						=      CONFIG_MAPPING[backbone_model_type]
                   SCREAMING_SNAKE_CASE_     						=      config_class.from_dict(_lowerCAmelCase						)
             # set timm attributes to None
             SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_     						=      None, None, None

       SCREAMING_SNAKE_CASE_     						=      use_timm_backbone
       SCREAMING_SNAKE_CASE_     						=      backbone_config
       SCREAMING_SNAKE_CASE_     						=      num_channels
       SCREAMING_SNAKE_CASE_     						=      num_queries
       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_     						=      decoder_layerdrop
       SCREAMING_SNAKE_CASE_     						=      encoder_layers
       SCREAMING_SNAKE_CASE_     						=      auxiliary_loss
       SCREAMING_SNAKE_CASE_     						=      position_embedding_type
       SCREAMING_SNAKE_CASE_     						=      backbone
       SCREAMING_SNAKE_CASE_     						=      use_pretrained_backbone
       SCREAMING_SNAKE_CASE_     						=      dilation
       # 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
       super().__init__(is_encoder_decoder=_lowerCAmelCase    ,    **_lowerCAmelCase						)



 @property
 def 				lowerCAmelCase_  (							self  :		Optional[int]						):
       return self.encoder_attention_heads



 @property
 def 				lowerCAmelCase_  (							self  :		int						):
       return self.d_model



 @classmethod
 def 				lowerCAmelCase_  (							cls  :		Tuple    ,    _lowerCAmelCase  :		PretrainedConfig    ,    **_lowerCAmelCase  :		Tuple						):
       return cls(backbone_config=_lowerCAmelCase    ,    **_lowerCAmelCase						)




 def 				lowerCAmelCase_  (							self  :		Union[str, Any]						):
       SCREAMING_SNAKE_CASE_     						=      copy.deepcopy(self.__dict__						)
       if output["backbone_config"] is not None:
             SCREAMING_SNAKE_CASE_     						=      self.backbone_config.to_dict()
       SCREAMING_SNAKE_CASE_     						=      self.__class__.model_type
       return output





class 	lowerCamelCase_							(				_SCREAMING_SNAKE_CASE ):


 '''simple docstring'''







 lowercase_       =   version.parse("1.11" )



 @property
 def 				lowerCAmelCase_  (							self  :		str						):
       return OrderedDict(
           [
               ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
               ('pixel_mask', {0: 'batch'}),
           ]						)



 @property
 def 				lowerCAmelCase_  (							self  :		Dict						):
       return 1E-5




 @property
 def 				lowerCAmelCase_  (							self  :		Optional[int]						):
       return 12





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


lowerCamelCase__			:       Dict         =							logging.get_logger(__name__)

lowerCamelCase__			:       Any         =							{
    'facebook/s2t-small-librispeech-asr': (
        'https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}





class 	lowerCamelCase_							(				_SCREAMING_SNAKE_CASE ):


 '''simple docstring'''







 lowercase_       =   "speech_to_text"
 lowercase_       =   ["past_key_values"]
 lowercase_       =   {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}



 def __init__(							self  :		Union[str, Any]    ,    _lowerCAmelCase  :		Optional[int]=10_000    ,    _lowerCAmelCase  :		str=12    ,    _lowerCAmelCase  :		Tuple=2_048    ,    _lowerCAmelCase  :		str=4    ,    _lowerCAmelCase  :		Tuple=6    ,    _lowerCAmelCase  :		Optional[int]=2_048    ,    _lowerCAmelCase  :		Dict=4    ,    _lowerCAmelCase  :		List[Any]=0.0    ,    _lowerCAmelCase  :		int=0.0    ,    _lowerCAmelCase  :		Optional[int]=True    ,    _lowerCAmelCase  :		Union[str, Any]=True    ,    _lowerCAmelCase  :		Any="relu"    ,    _lowerCAmelCase  :		Any=256    ,    _lowerCAmelCase  :		List[str]=0.1    ,    _lowerCAmelCase  :		Optional[Any]=0.0    ,    _lowerCAmelCase  :		Optional[int]=0.0    ,    _lowerCAmelCase  :		Tuple=0.02    ,    _lowerCAmelCase  :		List[str]=2    ,    _lowerCAmelCase  :		Tuple=True    ,    _lowerCAmelCase  :		List[str]=1    ,    _lowerCAmelCase  :		Dict=0    ,    _lowerCAmelCase  :		Tuple=2    ,    _lowerCAmelCase  :		Optional[int]=6_000    ,    _lowerCAmelCase  :		Tuple=1_024    ,    _lowerCAmelCase  :		Any=2    ,    _lowerCAmelCase  :		str=(5, 5)    ,    _lowerCAmelCase  :		Optional[int]=1_024    ,    _lowerCAmelCase  :		List[Any]=80    ,    _lowerCAmelCase  :		List[Any]=1    ,    **_lowerCAmelCase  :		List[Any]    ,    ):
       SCREAMING_SNAKE_CASE_     						=      vocab_size
       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_     						=      encoder_layerdrop
       SCREAMING_SNAKE_CASE_     						=      decoder_layerdrop
       SCREAMING_SNAKE_CASE_     						=      use_cache
       SCREAMING_SNAKE_CASE_     						=      encoder_layers
       SCREAMING_SNAKE_CASE_     						=      scale_embedding  # scale factor will be sqrt(d_model) if True
       SCREAMING_SNAKE_CASE_     						=      max_source_positions
       SCREAMING_SNAKE_CASE_     						=      max_target_positions
       SCREAMING_SNAKE_CASE_     						=      num_conv_layers
       SCREAMING_SNAKE_CASE_     						=      list(_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_     						=      conv_channels
       SCREAMING_SNAKE_CASE_     						=      input_feat_per_channel
       SCREAMING_SNAKE_CASE_     						=      input_channels

       if len(self.conv_kernel_sizes						) != self.num_conv_layers:
             raise ValueError(
                 'Configuration for convolutional module is incorrect. '
                 'It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '
                 F"but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes						)}`, "
                 F"`config.num_conv_layers = {self.num_conv_layers}`."						)

       super().__init__(
           pad_token_id=_lowerCAmelCase    ,    bos_token_id=_lowerCAmelCase    ,    eos_token_id=_lowerCAmelCase    ,    is_encoder_decoder=_lowerCAmelCase    ,    decoder_start_token_id=_lowerCAmelCase    ,    **_lowerCAmelCase    ,    )