'''simple docstring'''


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

__snake_case						  =		logging.get_logger(__name__)





class       _a    (		__a      ):


  """simple docstring"""

  A_    							=						'''vision-encoder-decoder'''
  A_    							=						True




  def __init__(		self      :       Union[str, Any]   ,				**lowercase_      :       Dict      ):







    '''simple docstring'''


    super().__init__(**lowercase_      )
    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}"""      )

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

    lowercase_     =       AutoConfig.for_model(lowercase_   ,				**lowercase_      )
    lowercase_     =       AutoConfig.for_model(lowercase_   ,				**lowercase_      )
    lowercase_     =       True




  @classmethod
  def 		lowerCamelCase__  (		cls      :       Optional[Any]   ,				lowercase_      :       PretrainedConfig   ,				lowercase_      :       PretrainedConfig   ,				**lowercase_      :       Tuple      ):







    '''simple docstring'''


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

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





  def 		lowerCamelCase__  (		self      :       List[str]      ):







    '''simple docstring'''


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






class       _a    (		__a      ):


  """simple docstring"""

  A_    							=						version.parse('''1.11'''      )




  @property
  def 		lowerCamelCase__  (		self      :       Dict      ):







    '''simple docstring'''


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




  @property
  def 		lowerCamelCase__  (		self      :       Dict      ):







    '''simple docstring'''


    return 1e-4





  @property
  def 		lowerCamelCase__  (		self      :       Optional[Any]      ):







    '''simple docstring'''


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






class       _a    (		__a      ):


  """simple docstring"""

  @property
  def 		lowerCamelCase__  (		self      :       Union[str, Any]      ):







    '''simple docstring'''


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

    return common_inputs





  def 		lowerCamelCase__  (		self      :       str   ,				lowercase_      :       "PreTrainedTokenizerBase"   ,				lowercase_      :       int = -1   ,				lowercase_      :       int = -1   ,				lowercase_      :       bool = False   ,				lowercase_      :       Optional["TensorType"] = None   ,				):







    '''simple docstring'''


    import torch

    lowercase_     =       OrderedDict()

    lowercase_     =       super().generate_dummy_inputs(
        lowercase_   ,				batch_size=lowercase_   ,				seq_length=lowercase_   ,				is_pair=lowercase_   ,				framework=lowercase_      )

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

    return common_inputs






class       _a    (		__a      ):


  """simple docstring"""

  @property
  def 		lowerCamelCase__  (		self      :       List[Any]      ):







    '''simple docstring'''


    pass




  def 		lowerCamelCase__  (		self      :       Any   ,				lowercase_      :       PretrainedConfig      ):







    '''simple docstring'''


    return VisionEncoderDecoderEncoderOnnxConfig(lowercase_      )





  def 		lowerCamelCase__  (		self      :       Optional[Any]   ,				lowercase_      :       PretrainedConfig   ,				lowercase_      :       PretrainedConfig   ,				lowercase_      :       str = "default"      ):







    '''simple docstring'''


    lowercase_     =       encoder_config.hidden_size
    return VisionEncoderDecoderDecoderOnnxConfig(lowercase_   ,				lowercase_      )


'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

from packaging import version

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


__snake_case						  =		logging.get_logger(__name__)

__snake_case						  =		{
    """microsoft/table-transformer-detection""": (
        """https://huggingface.co/microsoft/table-transformer-detection/resolve/main/config.json"""
    ),
}





class       _a    (		__a      ):


  """simple docstring"""

  A_    							=						'''table-transformer'''
  A_    							=						['''past_key_values''']
  A_    							=						{
      '''hidden_size''': '''d_model''',
      '''num_attention_heads''': '''encoder_attention_heads''',
  }




  def __init__(		self      :       str   ,				lowercase_      :       str=True   ,				lowercase_      :       List[str]=None   ,				lowercase_      :       Dict=3   ,				lowercase_      :       Optional[Any]=100   ,				lowercase_      :       Optional[int]=6   ,				lowercase_      :       Optional[Any]=2_048   ,				lowercase_      :       List[Any]=8   ,				lowercase_      :       Optional[Any]=6   ,				lowercase_      :       int=2_048   ,				lowercase_      :       Any=8   ,				lowercase_      :       Optional[Any]=0.0   ,				lowercase_      :       int=0.0   ,				lowercase_      :       Dict=True   ,				lowercase_      :       int="relu"   ,				lowercase_      :       Tuple=256   ,				lowercase_      :       Dict=0.1   ,				lowercase_      :       List[str]=0.0   ,				lowercase_      :       List[str]=0.0   ,				lowercase_      :       int=0.0_2   ,				lowercase_      :       List[str]=1.0   ,				lowercase_      :       Optional[int]=False   ,				lowercase_      :       List[Any]="sine"   ,				lowercase_      :       Optional[int]="resnet50"   ,				lowercase_      :       Union[str, Any]=True   ,				lowercase_      :       Union[str, Any]=False   ,				lowercase_      :       List[str]=1   ,				lowercase_      :       Any=5   ,				lowercase_      :       Optional[int]=2   ,				lowercase_      :       Dict=1   ,				lowercase_      :       Optional[int]=1   ,				lowercase_      :       Dict=5   ,				lowercase_      :       Optional[int]=2   ,				lowercase_      :       Optional[Any]=0.1   ,				**lowercase_      :       List[str]   ,				):







    '''simple docstring'''


    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."""      )
        lowercase_     =       CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]      )
      elif isinstance(lowercase_   ,				lowercase_      ):
        lowercase_     =       backbone_config.get("""model_type"""      )
        lowercase_     =       CONFIG_MAPPING[backbone_model_type]
        lowercase_     =       config_class.from_dict(lowercase_      )
      # set timm attributes to None
      lowercase_     ,	lowercase_     ,	lowercase_     =       None, None, None

    lowercase_     =       use_timm_backbone
    lowercase_     =       backbone_config
    lowercase_     =       num_channels
    lowercase_     =       num_queries
    lowercase_     =       d_model
    lowercase_     =       encoder_ffn_dim
    lowercase_     =       encoder_layers
    lowercase_     =       encoder_attention_heads
    lowercase_     =       decoder_ffn_dim
    lowercase_     =       decoder_layers
    lowercase_     =       decoder_attention_heads
    lowercase_     =       dropout
    lowercase_     =       attention_dropout
    lowercase_     =       activation_dropout
    lowercase_     =       activation_function
    lowercase_     =       init_std
    lowercase_     =       init_xavier_std
    lowercase_     =       encoder_layerdrop
    lowercase_     =       decoder_layerdrop
    lowercase_     =       encoder_layers
    lowercase_     =       auxiliary_loss
    lowercase_     =       position_embedding_type
    lowercase_     =       backbone
    lowercase_     =       use_pretrained_backbone
    lowercase_     =       dilation
    # Hungarian matcher
    lowercase_     =       class_cost
    lowercase_     =       bbox_cost
    lowercase_     =       giou_cost
    # Loss coefficients
    lowercase_     =       mask_loss_coefficient
    lowercase_     =       dice_loss_coefficient
    lowercase_     =       bbox_loss_coefficient
    lowercase_     =       giou_loss_coefficient
    lowercase_     =       eos_coefficient
    super().__init__(is_encoder_decoder=lowercase_   ,				**lowercase_      )




  @property
  def 		lowerCamelCase__  (		self      :       Tuple      ):







    '''simple docstring'''


    return self.encoder_attention_heads





  @property
  def 		lowerCamelCase__  (		self      :       Dict      ):







    '''simple docstring'''


    return self.d_model






class       _a    (		__a      ):


  """simple docstring"""

  A_    							=						version.parse('''1.11'''      )




  @property
  def 		lowerCamelCase__  (		self      :       int      ):







    '''simple docstring'''


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




  @property
  def 		lowerCamelCase__  (		self      :       List[Any]      ):







    '''simple docstring'''


    return 1e-5





  @property
  def 		lowerCamelCase__  (		self      :       Union[str, Any]      ):







    '''simple docstring'''


    return 12

