




'''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					       ={
    'gpt2': 'https://huggingface.co/gpt2/resolve/main/config.json',
    'gpt2-medium': 'https://huggingface.co/gpt2-medium/resolve/main/config.json',
    'gpt2-large': 'https://huggingface.co/gpt2-large/resolve/main/config.json',
    'gpt2-xl': 'https://huggingface.co/gpt2-xl/resolve/main/config.json',
    'distilgpt2': 'https://huggingface.co/distilgpt2/resolve/main/config.json',
}


class      _a    (      __a					):
       __a							:	int  							=   """gpt2"""
       __a							:	Optional[int]  							=   ["""past_key_values"""]
       __a							:	Optional[int]  							=   {
           """hidden_size""": """n_embd""",
           """max_position_embeddings""": """n_positions""",
           """num_attention_heads""": """n_head""",
           """num_hidden_layers""": """n_layer""",
       }
       def __init__(      self		:      Dict  ,							lowercase		:      Dict=50_257  ,							lowercase		:      Tuple=1_024  ,							lowercase		:      Union[str, Any]=768  ,							lowercase		:      int=12  ,							lowercase		:      List[str]=12  ,							lowercase		:      Dict=None  ,							lowercase		:      Dict="gelu_new"  ,							lowercase		:      str=0.1  ,							lowercase		:      Any=0.1  ,							lowercase		:      str=0.1  ,							lowercase		:      Dict=1E-5  ,							lowercase		:      Optional[int]=0.02  ,							lowercase		:      Dict="cls_index"  ,							lowercase		:      Optional[int]=True  ,							lowercase		:      Tuple=None  ,							lowercase		:      Tuple=True  ,							lowercase		:      str=0.1  ,							lowercase		:      Union[str, Any]=True  ,							lowercase		:      int=True  ,							lowercase		:      Optional[Any]=50_256  ,							lowercase		:      str=50_256  ,							lowercase		:      int=False  ,							lowercase		:      Any=False  ,							**lowercase		:      str  ,							):



           '''simple docstring'''

           UpperCAmelCase     			=						vocab_size
           UpperCAmelCase     			=						n_positions
           UpperCAmelCase     			=						n_embd
           UpperCAmelCase     			=						n_layer
           UpperCAmelCase     			=						n_head
           UpperCAmelCase     			=						n_inner
           UpperCAmelCase     			=						activation_function
           UpperCAmelCase     			=						resid_pdrop
           UpperCAmelCase     			=						embd_pdrop
           UpperCAmelCase     			=						attn_pdrop
           UpperCAmelCase     			=						layer_norm_epsilon
           UpperCAmelCase     			=						initializer_range
           UpperCAmelCase     			=						summary_type
           UpperCAmelCase     			=						summary_use_proj
           UpperCAmelCase     			=						summary_activation
           UpperCAmelCase     			=						summary_first_dropout
           UpperCAmelCase     			=						summary_proj_to_labels
           UpperCAmelCase     			=						scale_attn_weights
           UpperCAmelCase     			=						use_cache
           UpperCAmelCase     			=						scale_attn_by_inverse_layer_idx
           UpperCAmelCase     			=						reorder_and_upcast_attn

           UpperCAmelCase     			=						bos_token_id
           UpperCAmelCase     			=						eos_token_id

           super().__init__(bos_token_id=lowercase  ,							eos_token_id=lowercase  ,							**lowercase							)






class      _a    (      __a					):
       def __init__(      self		:      str  ,							lowercase		:      PretrainedConfig  ,							lowercase		:      str = "default"  ,							lowercase		:      List[PatchingSpec] = None  ,							lowercase		:      bool = False  ,							):



           '''simple docstring'''

           super().__init__(lowercase  ,							task=lowercase  ,							patching_specs=lowercase  ,							use_past=lowercase							)
           if not getattr(self._config  ,							'''pad_token_id'''  ,							lowercase							):
               # TODO: how to do that better?
               UpperCAmelCase     			=						0
       @property
       def        A (      self		:      Optional[Any]							):



           '''simple docstring'''

           UpperCAmelCase     			=						OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}							)
           if self.use_past:
               self.fill_with_past_key_values_(lowercase  ,							direction='''inputs'''							)
               UpperCAmelCase     			=						{0: '''batch''', 1: '''past_sequence + sequence'''}
           else:
               UpperCAmelCase     			=						{0: '''batch''', 1: '''sequence'''}

           return common_inputs
       @property
       def        A (      self		:      List[Any]							):



           '''simple docstring'''

           return self._config.n_layer
       @property
       def        A (      self		:      Optional[Any]							):



           '''simple docstring'''

           return self._config.n_head
       def        A (      self		:      Tuple  ,							lowercase		:      PreTrainedTokenizer  ,							lowercase		:      int = -1  ,							lowercase		:      int = -1  ,							lowercase		:      bool = False  ,							lowercase		:      Optional[TensorType] = None  ,							):



           '''simple docstring'''

           UpperCAmelCase     			=						super(lowercase  ,							self							).generate_dummy_inputs(
               lowercase  ,							batch_size=lowercase  ,							seq_length=lowercase  ,							is_pair=lowercase  ,							framework=lowercase							)

           # We need to order the input in the way they appears in the forward()
           UpperCAmelCase     			=						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     			=						common_inputs['''input_ids'''].shape
                   # Not using the same length for past_key_values
                   UpperCAmelCase     			=						seqlen + 2
                   UpperCAmelCase     			=						(
                       batch,
                       self.num_attention_heads,
                       past_key_values_length,
                       self._config.hidden_size // self.num_attention_heads,
                   )
                   UpperCAmelCase     			=						[
                       (torch.zeros(lowercase							), torch.zeros(lowercase							)) for _ in range(self.num_layers							)
                   ]

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

           return ordered_inputs







       @property
       def        A (      self		:      str							):



           '''simple docstring'''

           return 13










'''simple docstring'''







import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


A					       =10_00_00_00_00_00
A					       =1_00_00

A       , A					       =os.path.split(__file__)
A					       =os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))





def 		snake_case_				(_a      :				int       ,  _a      :				int	):
    UpperCAmelCase     			=						pa.Table.from_pydict({'''col''': [0] * chunk_size}	)
    UpperCAmelCase     			=						pa.concat_tables([table] * (num_examples // chunk_size)	)
    return datasets.Dataset(_a       ,  fingerprint='''table_100B'''	)


@dataclass
class      _a    :
       __a							:	int
       __a							:	int
       __a							:	int
       __a							:	int
       def        A (      self		:      List[str]							):



           '''simple docstring'''

           UpperCAmelCase     			=						np.random.default_rng(self.seed							)
           UpperCAmelCase     			=						rng.integers(low=self.low  ,							high=self.high  ,							size=self.size							).tolist()
       def __iter__(      self		:      Tuple							):



           '''simple docstring'''

           return iter(self._sampled_values							)







       def __len__(      self		:      Dict							):



           '''simple docstring'''

           return self.size






@get_duration
def 		snake_case_				(_a      :				datasets.Dataset	):
    UpperCAmelCase     			=						dataset[0]





@get_duration
def 		snake_case_				(_a      :				datasets.Dataset	):
    UpperCAmelCase     			=						dataset[-1]





@get_duration
def 		snake_case_				(_a      :				datasets.Dataset	):
    UpperCAmelCase     			=						dataset[range(len(_a	) // 2       ,  len(_a	) // 2 + 1_0_2_4	)]





@get_duration
def 		snake_case_				(_a      :				datasets.Dataset	):
    UpperCAmelCase     			=						dataset[RandIter(0       ,  len(_a	)       ,  1_0_2_4       ,  seed=4_2	)]





def 		snake_case_				():
    UpperCAmelCase     			=						{'''num examples''': SPEED_TEST_N_EXAMPLES}
    UpperCAmelCase     			=						(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
    print('''generating dataset'''	)
    UpperCAmelCase     			=						generate_100B_dataset(num_examples=_a       ,  chunk_size=_a	)
    print('''Functions'''	)
    for func in functions:
        print(func.__name__	)
        UpperCAmelCase     			=						func(_a	)

    with open(_a       ,  '''wb'''	) as f:
        f.write(json.dumps(_a	).encode('''utf-8'''	)	)


if __name__ == "__main__":  # useful to run the profiler
   benchmark_table_100B()




