'''simple docstring'''






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


__a									=   logging.get_logger(__name__)


__a									=   {
    '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__				(			UpperCamelCase  ):





   """simple docstring"""





   UpperCamelCase_			:		Tuple       							=	'''codegen'''
   UpperCamelCase_			:		Tuple       							=	{
       '''max_position_embeddings''': '''n_positions''',
       '''hidden_size''': '''n_embd''',
       '''num_attention_heads''': '''n_head''',
       '''num_hidden_layers''': '''n_layer''',
   }




   def __init__(					self	:						int		,	lowerCAmelCase__	:						List[str]=5_0_4_0_0		,	lowerCAmelCase__	:						Tuple=2_0_4_8		,	lowerCAmelCase__	:						Optional[int]=2_0_4_8		,	lowerCAmelCase__	:						str=4_0_9_6		,	lowerCAmelCase__	:						Optional[int]=2_8		,	lowerCAmelCase__	:						int=1_6		,	lowerCAmelCase__	:						List[Any]=6_4		,	lowerCAmelCase__	:						str=None		,	lowerCAmelCase__	:						Optional[int]="gelu_new"		,	lowerCAmelCase__	:						Dict=0.0		,	lowerCAmelCase__	:						str=0.0		,	lowerCAmelCase__	:						Any=0.0		,	lowerCAmelCase__	:						str=1e-5		,	lowerCAmelCase__	:						str=0.02		,	lowerCAmelCase__	:						Union[str, Any]=True		,	lowerCAmelCase__	:						Tuple=5_0_2_5_6		,	lowerCAmelCase__	:						Any=5_0_2_5_6		,	lowerCAmelCase__	:						Any=False		,	**lowerCAmelCase__	:						List[Any]		,	)			->       Tuple:







      """simple docstring"""




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

      _UpperCAmelCase				:      Union[str, Any]				=  bos_token_id
      _UpperCAmelCase				:      str				=  eos_token_id

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





class        A__				(			UpperCamelCase  ):





   """simple docstring"""





   def __init__(					self	:						Dict		,	lowerCAmelCase__	:						PretrainedConfig		,	lowerCAmelCase__	:						str = "default"		,	lowerCAmelCase__	:						List[PatchingSpec] = None		,	lowerCAmelCase__	:						bool = False		,	)			->       Optional[int]:







      """simple docstring"""




      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?
         _UpperCAmelCase				:      List[str]				=  0




   @property
   def      _lowerCAmelCase						(					self	:						List[Any]     )			->       Dict:







      """simple docstring"""




      _UpperCAmelCase				:      Tuple				=  OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}     )
      if self.use_past:
         self.fill_with_past_key_values_(lowerCamelCase__		,	direction="inputs"     )
         _UpperCAmelCase				:      Union[str, Any]				=  {0: 'batch', 1: 'past_sequence + sequence'}
      else:
         _UpperCAmelCase				:      Tuple				=  {0: 'batch', 1: 'sequence'}

      return common_inputs




   @property
   def      _lowerCAmelCase						(					self	:						List[Any]     )			->       int:







      """simple docstring"""




      return self._config.n_layer




   @property
   def      _lowerCAmelCase						(					self	:						List[Any]     )			->       int:







      """simple docstring"""




      return self._config.n_head




   def      _lowerCAmelCase						(					self	:						int		,	lowerCAmelCase__	:						PreTrainedTokenizer		,	lowerCAmelCase__	:						int = -1		,	lowerCAmelCase__	:						int = -1		,	lowerCAmelCase__	:						bool = False		,	lowerCAmelCase__	:						Optional[TensorType] = None		,	)			->       List[str]:







      """simple docstring"""




      _UpperCAmelCase				:      Optional[Any]				=  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()
      _UpperCAmelCase				:      int				=  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

            _UpperCAmelCase				:      str				=  common_inputs['input_ids'].shape
            # Not using the same length for past_key_values
            _UpperCAmelCase				:      List[Any]				=  seqlen + 2
            _UpperCAmelCase				:      Optional[int]				=  (
                batch,
                self.num_attention_heads,
                past_key_values_length,
                self._config.hidden_size // self.num_attention_heads,
            )
            _UpperCAmelCase				:      Dict				=  [
                (torch.zeros(lowerCamelCase__     ), torch.zeros(lowerCamelCase__     )) for _ in range(self.num_layers     )
            ]

      _UpperCAmelCase				:      List[Any]				=  common_inputs['attention_mask']
      if self.use_past:
         _UpperCAmelCase				:      Tuple				=  ordered_inputs['attention_mask'].dtype
         _UpperCAmelCase				:      Dict				=  torch.cat(
             [ordered_inputs["attention_mask"], torch.ones(lowerCamelCase__		,	lowerCamelCase__		,	dtype=lowerCamelCase__     )]		,	dim=1     )

      return ordered_inputs




   @property
   def      _lowerCAmelCase						(					self	:						List[str]     )			->       Tuple:







      """simple docstring"""




      return 1_3




'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


snake_case_					:      Tuple    			=    {
    'configuration_layoutlmv2': ['LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LayoutLMv2Config'],
    'processing_layoutlmv2': ['LayoutLMv2Processor'],
    'tokenization_layoutlmv2': ['LayoutLMv2Tokenizer'],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_					:      int    			=    ['LayoutLMv2TokenizerFast']

try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_					:      Union[str, Any]    			=    ['LayoutLMv2FeatureExtractor']
					snake_case_					:      str    			=    ['LayoutLMv2ImageProcessor']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_					:      Optional[int]    			=    [
					    'LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'LayoutLMv2ForQuestionAnswering',
					    'LayoutLMv2ForSequenceClassification',
					    'LayoutLMv2ForTokenClassification',
					    'LayoutLMv2Layer',
					    'LayoutLMv2Model',
					    'LayoutLMv2PreTrainedModel',
					]

if TYPE_CHECKING:
					from .configuration_layoutlmva import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMvaConfig
					from .processing_layoutlmva import LayoutLMvaProcessor
					from .tokenization_layoutlmva import LayoutLMvaTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor, LayoutLMvaImageProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_layoutlmva import (
										    LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST,
										    LayoutLMvaForQuestionAnswering,
										    LayoutLMvaForSequenceClassification,
										    LayoutLMvaForTokenClassification,
										    LayoutLMvaLayer,
										    LayoutLMvaModel,
										    LayoutLMvaPreTrainedModel,
										)
else:
					import sys

					snake_case_					:      int    			=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


