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


lowerCAmelCase_:					int     =					logging.get_logger(__name__)


lowerCAmelCase_:					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    a__    (   _a	):
   snake_case_							=      "codegen"
   snake_case_							=      {
       "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.02,				_UpperCAmelCase=True,				_UpperCAmelCase=5_0256,				_UpperCAmelCase=5_0256,				_UpperCAmelCase=False,				**_UpperCAmelCase,				):
        '''simple docstring'''



        lowercase__				 =							vocab_size
        lowercase__				 =							n_ctx
        lowercase__				 =							n_positions
        lowercase__				 =							n_embd
        lowercase__				 =							n_layer
        lowercase__				 =							n_head
        lowercase__				 =							n_inner
        lowercase__				 =							rotary_dim
        lowercase__				 =							activation_function
        lowercase__				 =							resid_pdrop
        lowercase__				 =							embd_pdrop
        lowercase__				 =							attn_pdrop
        lowercase__				 =							layer_norm_epsilon
        lowercase__				 =							initializer_range
        lowercase__				 =							use_cache

        lowercase__				 =							bos_token_id
        lowercase__				 =							eos_token_id

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






class    a__    (   _a	):


   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?
             lowercase__				 =							0


   @property
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        lowercase__				 =							OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}  )
        if self.use_past:
             self.fill_with_past_key_values_(_UpperCAmelCase,				direction="inputs"  )
             lowercase__				 =							{0: "batch", 1: "past_sequence + sequence"}
        else:
             lowercase__				 =							{0: "batch", 1: "sequence"}

        return common_inputs


   @property
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        return self._config.n_layer


   @property
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        return self._config.n_head


   def 	snake_case__	(     self,				_UpperCAmelCase,				_UpperCAmelCase = -1,				_UpperCAmelCase = -1,				_UpperCAmelCase = False,				_UpperCAmelCase = None,				):
        '''simple docstring'''



        lowercase__				 =							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()
        lowercase__				 =							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

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

        lowercase__				 =							common_inputs["attention_mask"]
        if self.use_past:
             lowercase__				 =							ordered_inputs["attention_mask"].dtype
             lowercase__				 =							torch.cat(
                 [ordered_inputs["attention_mask"], torch.ones(_UpperCAmelCase,				_UpperCAmelCase,				dtype=_UpperCAmelCase  )],				dim=1  )

        return ordered_inputs


   @property
   def 	snake_case__	(     self  ):
        '''simple docstring'''



        return 13





"""simple docstring"""


from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader






class    a__    (   _a	):


   def __init__(     self,				_UpperCAmelCase,				_UpperCAmelCase = None,				_UpperCAmelCase = None,				_UpperCAmelCase = None,				_UpperCAmelCase = False,				_UpperCAmelCase = False,				_UpperCAmelCase = None,				**_UpperCAmelCase,				):
        '''simple docstring'''



        super().__init__(
            _UpperCAmelCase,				split=_UpperCAmelCase,				features=_UpperCAmelCase,				cache_dir=_UpperCAmelCase,				keep_in_memory=_UpperCAmelCase,				streaming=_UpperCAmelCase,				num_proc=_UpperCAmelCase,				**_UpperCAmelCase,				)
        lowercase__				 =							path_or_paths if isinstance(_UpperCAmelCase,				_UpperCAmelCase  ) else {self.split: path_or_paths}
        lowercase__				 =							Text(
            cache_dir=_UpperCAmelCase,				data_files=_UpperCAmelCase,				features=_UpperCAmelCase,				**_UpperCAmelCase,				)


   def 	snake_case__	(     self  ):
        '''simple docstring'''



        if self.streaming:
             lowercase__				 =							self.builder.as_streaming_dataset(split=self.split  )
        # Build regular (map-style) dataset
        else:
             lowercase__				 =							None
             lowercase__				 =							None
             lowercase__				 =							None
             lowercase__				 =							None

             self.builder.download_and_prepare(
                 download_config=_UpperCAmelCase,				download_mode=_UpperCAmelCase,				verification_mode=_UpperCAmelCase,				base_path=_UpperCAmelCase,				num_proc=self.num_proc,				)
             lowercase__				 =							self.builder.as_dataset(
                 split=self.split,				verification_mode=_UpperCAmelCase,				in_memory=self.keep_in_memory  )
        return dataset




