





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


UpperCAmelCase_      							=     logging.get_logger(__name__)


UpperCAmelCase_      							=     {
    """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 			UpperCamelCase_		(  _lowerCamelCase					):
					lowerCAmelCase_							=	'''codegen'''
					lowerCAmelCase_							=	{
					    '''max_position_embeddings''': '''n_positions''',
					    '''hidden_size''': '''n_embd''',
					    '''num_attention_heads''': '''n_head''',
					    '''num_hidden_layers''': '''n_layer''',
					}




					def __init__(		self				,						lowerCAmelCase_=5_0400				,						lowerCAmelCase_=2048				,						lowerCAmelCase_=2048				,						lowerCAmelCase_=4096				,						lowerCAmelCase_=28				,						lowerCAmelCase_=16				,						lowerCAmelCase_=64				,						lowerCAmelCase_=None				,						lowerCAmelCase_="gelu_new"				,						lowerCAmelCase_=0.0				,						lowerCAmelCase_=0.0				,						lowerCAmelCase_=0.0				,						lowerCAmelCase_=1E-5				,						lowerCAmelCase_=0.02				,						lowerCAmelCase_=True				,						lowerCAmelCase_=5_0256				,						lowerCAmelCase_=5_0256				,						lowerCAmelCase_=False				,						**lowerCAmelCase_				,						)		->							int:
										_snake_case									=				vocab_size
										_snake_case									=				n_ctx
										_snake_case									=				n_positions
										_snake_case									=				n_embd
										_snake_case									=				n_layer
										_snake_case									=				n_head
										_snake_case									=				n_inner
										_snake_case									=				rotary_dim
										_snake_case									=				activation_function
										_snake_case									=				resid_pdrop
										_snake_case									=				embd_pdrop
										_snake_case									=				attn_pdrop
										_snake_case									=				layer_norm_epsilon
										_snake_case									=				initializer_range
										_snake_case									=				use_cache

										_snake_case									=				bos_token_id
										_snake_case									=				eos_token_id

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





class 			UpperCamelCase_		(  _lowerCamelCase					):




					def __init__(		self				,						lowerCAmelCase_				,						lowerCAmelCase_ = "default"				,						lowerCAmelCase_ = None				,						lowerCAmelCase_ = False				,						)		->							Optional[int]:
										super().__init__(lowerCAmelCase_				,						task=lowerCAmelCase_				,						patching_specs=lowerCAmelCase_				,						use_past=lowerCAmelCase_  )
										if not getattr(self._config				,						'pad_token_id'				,						lowerCAmelCase_  ):
															# TODO: how to do that better?
															_snake_case									=				0




					@property
					def 	lowerCAmelCase			(		self  )		->							Mapping[str, Mapping[int, str]]:
										_snake_case									=				OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}  )
										if self.use_past:
															self.fill_with_past_key_values_(lowerCAmelCase_				,						direction='inputs'  )
															_snake_case									=				{0: 'batch', 1: 'past_sequence + sequence'}
										else:
															_snake_case									=				{0: 'batch', 1: 'sequence'}

										return common_inputs




					@property
					def 	lowerCAmelCase			(		self  )		->							int:
										return self._config.n_layer




					@property
					def 	lowerCAmelCase			(		self  )		->							int:
										return self._config.n_head




					def 	lowerCAmelCase			(		self				,						lowerCAmelCase_				,						lowerCAmelCase_ = -1				,						lowerCAmelCase_ = -1				,						lowerCAmelCase_ = False				,						lowerCAmelCase_ = None				,						)		->							Mapping[str, Any]:
										_snake_case									=				super(lowerCAmelCase_				,						self  ).generate_dummy_inputs(
										    lowerCAmelCase_				,						batch_size=lowerCAmelCase_				,						seq_length=lowerCAmelCase_				,						is_pair=lowerCAmelCase_				,						framework=lowerCAmelCase_  )

										# We need to order the input in the way they appears in the forward()
										_snake_case									=				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

																				_snake_case							,     _snake_case									=				common_inputs['input_ids'].shape
																				# Not using the same length for past_key_values
																				_snake_case									=				seqlen + 2
																				_snake_case									=				(
																				    batch,
																				    self.num_attention_heads,
																				    past_key_values_length,
																				    self._config.hidden_size // self.num_attention_heads,
																				)
																				_snake_case									=				[
																				    (torch.zeros(lowerCAmelCase_  ), torch.zeros(lowerCAmelCase_  )) for _ in range(self.num_layers  )
																				]

										_snake_case									=				common_inputs['attention_mask']
										if self.use_past:
															_snake_case									=				ordered_inputs['attention_mask'].dtype
															_snake_case									=				torch.cat(
															    [ordered_inputs['attention_mask'], torch.ones(lowerCAmelCase_				,						lowerCAmelCase_				,						dtype=lowerCAmelCase_  )]				,						dim=1  )

										return ordered_inputs






					@property
					def 	lowerCAmelCase			(		self  )		->							int:
										return 13










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase_      							=     {
    """configuration_luke""": ["""LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LukeConfig"""],
    """tokenization_luke""": ["""LukeTokenizer"""],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase_      							=     [
					    """LUKE_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """LukeForEntityClassification""",
					    """LukeForEntityPairClassification""",
					    """LukeForEntitySpanClassification""",
					    """LukeForMultipleChoice""",
					    """LukeForQuestionAnswering""",
					    """LukeForSequenceClassification""",
					    """LukeForTokenClassification""",
					    """LukeForMaskedLM""",
					    """LukeModel""",
					    """LukePreTrainedModel""",
					]


if TYPE_CHECKING:
					from .configuration_luke import LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP, LukeConfig
					from .tokenization_luke import LukeTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_luke import (
										    LUKE_PRETRAINED_MODEL_ARCHIVE_LIST,
										    LukeForEntityClassification,
										    LukeForEntityPairClassification,
										    LukeForEntitySpanClassification,
										    LukeForMaskedLM,
										    LukeForMultipleChoice,
										    LukeForQuestionAnswering,
										    LukeForSequenceClassification,
										    LukeForTokenClassification,
										    LukeModel,
										    LukePreTrainedModel,
										)

else:
					import sys

					UpperCAmelCase_      							=     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



