
"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


A__      :	List[Any]          =    logging.get_logger(__name__)

A__      :	List[Any]          =    {"""openai-gpt""": """https://huggingface.co/openai-gpt/resolve/main/config.json"""}







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							'openai-gpt'
     _A								=							{
         'max_position_embeddings': 'n_positions',
         'hidden_size': 'n_embd',
         'num_attention_heads': 'n_head',
         'num_hidden_layers': 'n_layer',
     }



     def __init__(      self ,			__UpperCamelCase=4_04_78 ,			__UpperCamelCase=5_12 ,			__UpperCamelCase=7_68 ,			__UpperCamelCase=12 ,			__UpperCamelCase=12 ,			__UpperCamelCase="gelu" ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=1E-5 ,			__UpperCamelCase=0.02 ,			__UpperCamelCase="cls_index" ,			__UpperCamelCase=True ,			__UpperCamelCase=None ,			__UpperCamelCase=True ,			__UpperCamelCase=0.1 ,			**__UpperCamelCase ,			)->					Union[str, Any]:
          UpperCAmelCase__							: List[Any] 							=						vocab_size
          UpperCAmelCase__							: Optional[Any] 							=						n_positions
          UpperCAmelCase__							: Union[str, Any] 							=						n_embd
          UpperCAmelCase__							: Union[str, Any] 							=						n_layer
          UpperCAmelCase__							: Tuple 							=						n_head
          UpperCAmelCase__							: List[Any] 							=						afn
          UpperCAmelCase__							: Tuple 							=						resid_pdrop
          UpperCAmelCase__							: Optional[int] 							=						embd_pdrop
          UpperCAmelCase__							: Optional[Any] 							=						attn_pdrop
          UpperCAmelCase__							: Dict 							=						layer_norm_epsilon
          UpperCAmelCase__							: List[str] 							=						initializer_range
          UpperCAmelCase__							: Optional[Any] 							=						summary_type
          UpperCAmelCase__							: Optional[Any] 							=						summary_use_proj
          UpperCAmelCase__							: List[Any] 							=						summary_activation
          UpperCAmelCase__							: Any 							=						summary_first_dropout
          UpperCAmelCase__							: str 							=						summary_proj_to_labels
          super().__init__(**__UpperCamelCase  )





"""simple docstring"""




import timeit

import numpy as np

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features.features import _ArrayXD



def 							a__ (				lowerCAmelCase	:       List[str]		):






     '''simple docstring'''
     def wrapper(*lowerCAmelCase	:       Any       ,    **lowerCAmelCase	:       Tuple		):
          UpperCAmelCase__							: Optional[int] 							=						timeit.default_timer()
          UpperCAmelCase__							: int 							=						func(*lowerCAmelCase       ,    **lowerCAmelCase		)
          UpperCAmelCase__							: List[Any] 							=						timeit.default_timer() - starttime
          return delta

     UpperCAmelCase__							: int 							=						func.__name__

     return wrapper



def 							a__ (				lowerCAmelCase	:       dict       ,    lowerCAmelCase	:       Optional[int]=100       ,    lowerCAmelCase	:       List[str]=None		):






     '''simple docstring'''
     UpperCAmelCase__							: str 							=						[]
     UpperCAmelCase__							: Optional[Any] 							=						seq_shapes or {}
     for i in range(lowerCAmelCase		):
          UpperCAmelCase__							: int 							=						{}
          for col_id, (k, v) in enumerate(features.items()		):
               if isinstance(lowerCAmelCase       ,    _ArrayXD		):
                    UpperCAmelCase__							: List[str] 							=						np.random.rand(*v.shape		).astype(v.dtype		)
               elif isinstance(lowerCAmelCase       ,    datasets.Value		):
                    if v.dtype == "string":
                         UpperCAmelCase__							: Dict 							=						"The small grey turtle was surprisingly fast when challenged."
                    else:
                         UpperCAmelCase__							: str 							=						np.random.randint(10       ,    size=1		).astype(v.dtype		).item()
               elif isinstance(lowerCAmelCase       ,    datasets.Sequence		):
                    while isinstance(lowerCAmelCase       ,    datasets.Sequence		):
                         UpperCAmelCase__							: List[str] 							=						v.feature
                    UpperCAmelCase__							: Optional[int] 							=						seq_shapes[k]
                    UpperCAmelCase__							: Optional[int] 							=						np.random.rand(*lowerCAmelCase		).astype(v.dtype		)
               UpperCAmelCase__							: Union[str, Any] 							=						data

          dummy_data.append((i, example)		)

     return dummy_data



def 							a__ (				lowerCAmelCase	:       List[str]       ,    lowerCAmelCase	:       Tuple       ,    lowerCAmelCase	:       List[str]=100       ,    lowerCAmelCase	:       Optional[int]=None		):






     '''simple docstring'''
     UpperCAmelCase__							: int 							=						generate_examples(lowerCAmelCase       ,    num_examples=lowerCAmelCase       ,    seq_shapes=lowerCAmelCase		)

     with ArrowWriter(features=lowerCAmelCase       ,    path=lowerCAmelCase		) as writer:
          for key, record in dummy_data:
               UpperCAmelCase__							: List[Any] 							=						features.encode_example(lowerCAmelCase		)
               writer.write(lowerCAmelCase		)

          UpperCAmelCase__							,	UpperCAmelCase__							: Optional[Any] 							=						writer.finalize()

     if not num_final_examples == num_examples:
          raise ValueError(
              F"Error writing the dataset, wrote {num_final_examples} examples but should have written {num_examples}."		)

     UpperCAmelCase__							: Optional[int] 							=						datasets.Dataset.from_file(filename=lowerCAmelCase       ,    info=datasets.DatasetInfo(features=lowerCAmelCase		)		)

     return dataset



