


'''simple docstring'''



import multiprocessing
import time

from arguments import PretokenizationArguments
from datasets import load_dataset

from transformers import AutoTokenizer, HfArgumentParser



def      UpperCAmelCase__   (      UpperCAmelCase_       :							Union[str, Any]				)	->						Optional[int]:
     __lowerCamelCase  :      int														=						{}
     __lowerCamelCase  :      int														=						tokenizer(example['content'] ,       truncation=UpperCAmelCase_				)['input_ids']
     __lowerCamelCase  :      List[str]														=						len(example['content']				) / len(output['input_ids']				)
     return output


A__						:   Tuple				=    HfArgumentParser(PretokenizationArguments)
A__						:   Dict				=    parser.parse_args()
if args.num_workers is None:
      A__						:   Any				=    multiprocessing.cpu_count()
A__						:   Optional[Any]				=    AutoTokenizer.from_pretrained(args.tokenizer_dir)

A__						:   Union[str, Any]				=    time.time()
A__						:   List[Any]				=    load_dataset(args.dataset_name, split="""train""")
print(f'''Dataset loaded in {time.time()-t_start:.2f}s''')

A__						:   Optional[Any]				=    time.time()
A__						:   Optional[Any]				=    ds.map(
    tokenize,
    num_proc=args.num_workers,
    remove_columns=[
        """repo_name""",
        """path""",
        """copies""",
        """size""",
        """content""",
        """license""",
        """hash""",
        """line_mean""",
        """line_max""",
        """alpha_frac""",
        """autogenerated""",
    ],
)
print(f'''Dataset tokenized in {time.time()-t_start:.2f}s''')

A__						:   Optional[int]				=    time.time()
ds.push_to_hub(args.tokenized_data_repo)

print(f'''Data pushed to the hub in {time.time()-t_start:.2f}s''')









'''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									=     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__   (   _snake_case      ):
    lowercase						       =		"codegen"
    lowercase						       =		{
        "max_position_embeddings": "n_positions",
        "hidden_size": "n_embd",
        "num_attention_heads": "n_head",
        "num_hidden_layers": "n_layer",
    }



    def __init__(       self		,					UpperCamelCase__=50400		,					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__=50256		,					UpperCamelCase__=50256		,					UpperCamelCase__=False		,					**UpperCamelCase__		,					)    ->   Tuple:





           '''simple docstring'''
           A_						       =   vocab_size
           A_						       =   n_ctx
           A_						       =   n_positions
           A_						       =   n_embd
           A_						       =   n_layer
           A_						       =   n_head
           A_						       =   n_inner
           A_						       =   rotary_dim
           A_						       =   activation_function
           A_						       =   resid_pdrop
           A_						       =   embd_pdrop
           A_						       =   attn_pdrop
           A_						       =   layer_norm_epsilon
           A_						       =   initializer_range
           A_						       =   use_cache

           A_						       =   bos_token_id
           A_						       =   eos_token_id

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


class        A__   (   _snake_case      ):



    def __init__(       self		,					UpperCamelCase__		,					UpperCamelCase__ = "default"		,					UpperCamelCase__ = None		,					UpperCamelCase__ = False		,					)    ->   Tuple:





           '''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_						       =   0



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





           '''simple docstring'''
           A_						       =   OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}							)
           if self.use_past:
                  self.fill_with_past_key_values_(UpperCamelCase__		,					direction="""inputs"""							)
                  A_						       =   {0: """batch""", 1: """past_sequence + sequence"""}
           else:
                  A_						       =   {0: """batch""", 1: """sequence"""}

           return common_inputs



    @property
    def        snake_case_      (       self							)    ->   int:





           '''simple docstring'''
           return self._config.n_layer



    @property
    def        snake_case_      (       self							)    ->   int:





           '''simple docstring'''
           return self._config.n_head



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





           '''simple docstring'''
           A_						       =   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_						       =   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_						       =   common_inputs["""input_ids"""].shape
                         # Not using the same length for past_key_values
                         A_						       =   seqlen + 2
                         A_						       =   (
                             batch,
                             self.num_attention_heads,
                             past_key_values_length,
                             self._config.hidden_size // self.num_attention_heads,
                         )
                         A_						       =   [
                             (torch.zeros(UpperCamelCase__							), torch.zeros(UpperCamelCase__							)) for _ in range(self.num_layers							)
                         ]

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

           return ordered_inputs







    @property
    def        snake_case_      (       self							)    ->   int:





           '''simple docstring'''
           return 13
