



"""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


lowercase__       =	logging.get_logger(__name__)

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




class SCREAMING_SNAKE_CASE__       (		__snake_case   ):
						_lowerCAmelCase    						=       "table-transformer"
						_lowerCAmelCase    						=       ["past_key_values"]
						_lowerCAmelCase    						=       {
						    "hidden_size": "d_model",
						    "num_attention_heads": "encoder_attention_heads",
						}



						def __init__(self    ,  _lowercase=True    ,  _lowercase=None    ,  _lowercase=3    ,  _lowercase=100    ,  _lowercase=6    ,  _lowercase=2048    ,  _lowercase=8    ,  _lowercase=6    ,  _lowercase=2048    ,  _lowercase=8    ,  _lowercase=0.0    ,  _lowercase=0.0    ,  _lowercase=True    ,  _lowercase="relu"    ,  _lowercase=256    ,  _lowercase=0.1    ,  _lowercase=0.0    ,  _lowercase=0.0    ,  _lowercase=0.02    ,  _lowercase=1.0    ,  _lowercase=False    ,  _lowercase="sine"    ,  _lowercase="resnet50"    ,  _lowercase=True    ,  _lowercase=False    ,  _lowercase=1    ,  _lowercase=5    ,  _lowercase=2    ,  _lowercase=1    ,  _lowercase=1    ,  _lowercase=5    ,  _lowercase=2    ,  _lowercase=0.1    ,  **_lowercase    ,  ):





													'''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."""				)
																											__a		:		Tuple						=							CONFIG_MAPPING["resnet"](out_features=["""stage4"""]				)
																				elif isinstance(__UpperCAmelCase    ,  __UpperCAmelCase				):
																											__a		:		Any						=							backbone_config.get("""model_type"""				)
																											__a		:		List[str]						=							CONFIG_MAPPING[backbone_model_type]
																											__a		:		Optional[int]						=							config_class.from_dict(__UpperCAmelCase				)
																				# set timm attributes to None
																				__a		:		List[str]						=							None, None, None

													__a		:		Tuple						=							use_timm_backbone
													__a		:		Union[str, Any]						=							backbone_config
													__a		:		str						=							num_channels
													__a		:		Union[str, Any]						=							num_queries
													__a		:		str						=							d_model
													__a		:		int						=							encoder_ffn_dim
													__a		:		Tuple						=							encoder_layers
													__a		:		Dict						=							encoder_attention_heads
													__a		:		Union[str, Any]						=							decoder_ffn_dim
													__a		:		Optional[int]						=							decoder_layers
													__a		:		Dict						=							decoder_attention_heads
													__a		:		Optional[Any]						=							dropout
													__a		:		Tuple						=							attention_dropout
													__a		:		Dict						=							activation_dropout
													__a		:		Tuple						=							activation_function
													__a		:		Optional[int]						=							init_std
													__a		:		Dict						=							init_xavier_std
													__a		:		int						=							encoder_layerdrop
													__a		:		Union[str, Any]						=							decoder_layerdrop
													__a		:		Union[str, Any]						=							encoder_layers
													__a		:		Optional[int]						=							auxiliary_loss
													__a		:		Dict						=							position_embedding_type
													__a		:		Optional[Any]						=							backbone
													__a		:		List[Any]						=							use_pretrained_backbone
													__a		:		int						=							dilation
													# Hungarian matcher
													__a		:		str						=							class_cost
													__a		:		Tuple						=							bbox_cost
													__a		:		List[str]						=							giou_cost
													# Loss coefficients
													__a		:		Any						=							mask_loss_coefficient
													__a		:		Any						=							dice_loss_coefficient
													__a		:		int						=							bbox_loss_coefficient
													__a		:		str						=							giou_loss_coefficient
													__a		:		Optional[Any]						=							eos_coefficient
													super().__init__(is_encoder_decoder=__UpperCAmelCase    ,  **__UpperCAmelCase				)



						@property
						def      lowerCAmelCase__(self				):





													'''simple docstring'''

													return self.encoder_attention_heads





						@property
						def      lowerCAmelCase__(self				):





													'''simple docstring'''

													return self.d_model







class SCREAMING_SNAKE_CASE__       (		__snake_case   ):
						_lowerCAmelCase    						=       version.parse("1.11"   )



						@property
						def      lowerCAmelCase__(self				):





													'''simple docstring'''

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



						@property
						def      lowerCAmelCase__(self				):





													'''simple docstring'''

													return 1e-5





						@property
						def      lowerCAmelCase__(self				):





													'''simple docstring'''

													return 12






from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


lowerCamelCase		       =      logging.get_logger(__name__)


lowerCamelCase		       =      {
    """Salesforce/codegen-350M-nl""": """https://huggingface.co/Salesforce/codegen-350M-nl/resolve/main/config.json""",
    """Salesforce/codegen-350M-multi""": """https://huggingface.co/Salesforce/codegen-350M-multi/resolve/main/config.json""",
    """Salesforce/codegen-350M-mono""": """https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/config.json""",
    """Salesforce/codegen-2B-nl""": """https://huggingface.co/Salesforce/codegen-2B-nl/resolve/main/config.json""",
    """Salesforce/codegen-2B-multi""": """https://huggingface.co/Salesforce/codegen-2B-multi/resolve/main/config.json""",
    """Salesforce/codegen-2B-mono""": """https://huggingface.co/Salesforce/codegen-2B-mono/resolve/main/config.json""",
    """Salesforce/codegen-6B-nl""": """https://huggingface.co/Salesforce/codegen-6B-nl/resolve/main/config.json""",
    """Salesforce/codegen-6B-multi""": """https://huggingface.co/Salesforce/codegen-6B-multi/resolve/main/config.json""",
    """Salesforce/codegen-6B-mono""": """https://huggingface.co/Salesforce/codegen-6B-mono/resolve/main/config.json""",
    """Salesforce/codegen-16B-nl""": """https://huggingface.co/Salesforce/codegen-16B-nl/resolve/main/config.json""",
    """Salesforce/codegen-16B-multi""": """https://huggingface.co/Salesforce/codegen-16B-multi/resolve/main/config.json""",
    """Salesforce/codegen-16B-mono""": """https://huggingface.co/Salesforce/codegen-16B-mono/resolve/main/config.json""",
}


class 				_a						(       SCREAMING_SNAKE_CASE			):





							'''simple docstring'''

							A				:str =       "codegen"
							A				:Tuple =       {
							    "max_position_embeddings": "n_positions",
							    "hidden_size": "n_embd",
							    "num_attention_heads": "n_head",
							    "num_hidden_layers": "n_layer",
							}



							def __init__(							self ,					__UpperCAmelCase=5_0400 ,					__UpperCAmelCase=2048 ,					__UpperCAmelCase=2048 ,					__UpperCAmelCase=4096 ,					__UpperCAmelCase=28 ,					__UpperCAmelCase=16 ,					__UpperCAmelCase=64 ,					__UpperCAmelCase=None ,					__UpperCAmelCase="gelu_new" ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=1E-5 ,					__UpperCAmelCase=0.0_2 ,					__UpperCAmelCase=True ,					__UpperCAmelCase=5_0256 ,					__UpperCAmelCase=5_0256 ,					__UpperCAmelCase=False ,					**__UpperCAmelCase ,					):







											"""simple docstring"""



											a__	:							Dict      						= vocab_size
											a__	:							int      						= n_ctx
											a__	:							str      						= n_positions
											a__	:							Union[str, Any]      						= n_embd
											a__	:							Union[str, Any]      						= n_layer
											a__	:							Optional[int]      						= n_head
											a__	:							Dict      						= n_inner
											a__	:							Optional[Any]      						= rotary_dim
											a__	:							str      						= activation_function
											a__	:							List[Any]      						= resid_pdrop
											a__	:							str      						= embd_pdrop
											a__	:							List[str]      						= attn_pdrop
											a__	:							str      						= layer_norm_epsilon
											a__	:							Any      						= initializer_range
											a__	:							List[str]      						= use_cache

											a__	:							Tuple      						= bos_token_id
											a__	:							List[Any]      						= eos_token_id

											super().__init__(
											    bos_token_id=__UpperCAmelCase ,					eos_token_id=__UpperCAmelCase ,					tie_word_embeddings=__UpperCAmelCase ,					**__UpperCAmelCase				)





class 				_a						(       SCREAMING_SNAKE_CASE			):





							'''simple docstring'''

							def __init__(							self ,					__UpperCAmelCase ,					__UpperCAmelCase = "default" ,					__UpperCAmelCase = None ,					__UpperCAmelCase = False ,					):







											"""simple docstring"""



											super().__init__(__UpperCAmelCase ,					task=__UpperCAmelCase ,					patching_specs=__UpperCAmelCase ,					use_past=__UpperCAmelCase				)
											if not getattr(self._config ,					"pad_token_id" ,					__UpperCAmelCase				):
															# TODO: how to do that better?
															a__	:							Union[str, Any]      						= 0



							@property
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Optional[Any]      						= OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}				)
											if self.use_past:
															self.fill_with_past_key_values_(__UpperCAmelCase ,					direction="inputs"				)
															a__	:							Any      						= {0: "batch", 1: "past_sequence + sequence"}
											else:
															a__	:							List[Any]      						= {0: "batch", 1: "sequence"}

											return common_inputs



							@property
							def 		_A	(							self				):







											"""simple docstring"""



											return self._config.n_layer



							@property
							def 		_A	(							self				):







											"""simple docstring"""



											return self._config.n_head



							def 		_A	(							self ,					__UpperCAmelCase ,					__UpperCAmelCase = -1 ,					__UpperCAmelCase = -1 ,					__UpperCAmelCase = False ,					__UpperCAmelCase = None ,					):







											"""simple docstring"""



											a__	:							Dict      						= super(__UpperCAmelCase ,					self				).generate_dummy_inputs(
											    __UpperCAmelCase ,					batch_size=__UpperCAmelCase ,					seq_length=__UpperCAmelCase ,					is_pair=__UpperCAmelCase ,					framework=__UpperCAmelCase				)

											# We need to order the input in the way they appears in the forward()
											a__	:							Union[str, Any]      						= OrderedDict({"input_ids": common_inputs["input_ids"]}				)

											# Need to add the past_keys
											if self.use_past:
															if not is_torch_available():
																			raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."				)
															else:
																			import torch

																			a__						,   a__	:							Union[str, Any]      						= common_inputs["input_ids"].shape
																			# Not using the same length for past_key_values
																			a__	:							Any      						= seqlen + 2
																			a__	:							str      						= (
																			    batch,
																			    self.num_attention_heads,
																			    past_key_values_length,
																			    self._config.hidden_size // self.num_attention_heads,
																			)
																			a__	:							str      						= [
																			    (torch.zeros(__UpperCAmelCase				), torch.zeros(__UpperCAmelCase				)) for _ in range(self.num_layers				)
																			]

											a__	:							Union[str, Any]      						= common_inputs["attention_mask"]
											if self.use_past:
															a__	:							str      						= ordered_inputs["attention_mask"].dtype
															a__	:							Union[str, Any]      						= torch.cat(
															    [ordered_inputs["attention_mask"], torch.ones(__UpperCAmelCase ,					__UpperCAmelCase ,					dtype=__UpperCAmelCase				)] ,					dim=1				)

											return ordered_inputs




							@property
							def 		_A	(							self				):







											"""simple docstring"""



											return 13


