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


UpperCamelCase__  :						int					=      logging.get_logger(__name__)


UpperCamelCase__  :						Union[str, Any]					=      {
    '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 					_lowercase						(   lowerCAmelCase ):
      '''simple docstring'''


      UpperCAmelCase_   :   Any   				= '''codegen'''
      UpperCAmelCase_   :   List[Any]   				= {
          '''max_position_embeddings''': '''n_positions''',
          '''hidden_size''': '''n_embd''',
          '''num_attention_heads''': '''n_head''',
          '''num_hidden_layers''': '''n_layer''',
      }




      def __init__(					self       ,lowerCamelCase_=50400       ,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_=50256       ,lowerCamelCase_=50256       ,lowerCamelCase_=False       ,**lowerCamelCase_       ,)      ->      str:



         '''simple docstring'''



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

         UpperCAmelCase__				:					Tuple 					=	bos_token_id
         UpperCAmelCase__				:					Any 					=	eos_token_id

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




class 					_lowercase						(   lowerCAmelCase ):
      '''simple docstring'''


      def __init__(					self       ,lowerCamelCase_       ,lowerCamelCase_ = "default"       ,lowerCamelCase_ = None       ,lowerCamelCase_ = False       ,)      ->      List[str]:



         '''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__				:					Optional[Any] 					=	0




      @property
      def 		lowerCAmelCase__       (					self				)      ->      Mapping[str, Mapping[int, str]]:



         '''simple docstring'''



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

         return common_inputs




      @property
      def 		lowerCAmelCase__       (					self				)      ->      int:



         '''simple docstring'''



         return self._config.n_layer




      @property
      def 		lowerCAmelCase__       (					self				)      ->      int:



         '''simple docstring'''



         return self._config.n_head




      def 		lowerCAmelCase__       (					self       ,lowerCamelCase_       ,lowerCamelCase_ = -1       ,lowerCamelCase_ = -1       ,lowerCamelCase_ = False       ,lowerCamelCase_ = None       ,)      ->      Mapping[str, Any]:



         '''simple docstring'''



         UpperCAmelCase__				:					List[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__				:					Dict 					=	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__					,   UpperCAmelCase__				:					List[Any] 					=	common_inputs['''input_ids'''].shape
               # Not using the same length for past_key_values
               UpperCAmelCase__				:					Optional[int] 					=	seqlen + 2
               UpperCAmelCase__				:					Optional[int] 					=	(
                   batch,
                   self.num_attention_heads,
                   past_key_values_length,
                   self._config.hidden_size // self.num_attention_heads,
               )
               UpperCAmelCase__				:					Union[str, Any] 					=	[
                   (torch.zeros(lowerCamelCase_				), torch.zeros(lowerCamelCase_				)) for _ in range(self.num_layers				)
               ]

         UpperCAmelCase__				:					Dict 					=	common_inputs['''attention_mask''']
         if self.use_past:
            UpperCAmelCase__				:					Any 					=	ordered_inputs['''attention_mask'''].dtype
            UpperCAmelCase__				:					Optional[int] 					=	torch.cat(
                [ordered_inputs['''attention_mask'''], torch.ones(lowerCamelCase_       ,lowerCamelCase_       ,dtype=lowerCamelCase_				)]       ,dim=1				)

         return ordered_inputs




      @property
      def 		lowerCAmelCase__       (					self				)      ->      int:



         '''simple docstring'''



         return 13





'''simple docstring'''

from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Features, Sequence, Value
from .base import TaskTemplate


@dataclass(frozen=lowerCAmelCase )
class 					_lowercase						(   lowerCAmelCase ):
      '''simple docstring'''


      UpperCAmelCase_   :   str   				= field(default='''question-answering-extractive'''		,metadata={'''include_in_asdict_even_if_is_default''': True} )
      UpperCAmelCase_   :   ClassVar[Features]   				= Features({'''question''': Value('''string''' ), '''context''': Value('''string''' )} )
      UpperCAmelCase_   :   ClassVar[Features]   				= Features(
          {
              '''answers''': Sequence(
                  {
                      '''text''': Value('''string''' ),
                      '''answer_start''': Value('''int32''' ),
                  } )
          } )
      UpperCAmelCase_   :   str   				= "question"
      UpperCAmelCase_   :   str   				= "context"
      UpperCAmelCase_   :   str   				= "answers"




      @property
      def 		lowerCAmelCase__       (					self				)      ->      Dict[str, str]:



         '''simple docstring'''



         return {self.question_column: "question", self.context_column: "context", self.answers_column: "answers"}




