

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_a			=       logging.get_logger(__name__)

_a			=       {
    '''mnaylor/mega-base-wikitext''': '''https://huggingface.co/mnaylor/mega-base-wikitext/resolve/main/config.json''',
}






class 							A_			(		snake_case__ ):
     _lowercase      :					Tuple       =     'mega'


     def __init__(							self      :		List[Any]      ,  UpperCAmelCase      :		List[Any]=3_0_5_2_2      ,  UpperCAmelCase      :		Dict=1_2_8      ,  UpperCAmelCase      :		Union[str, Any]=4      ,  UpperCAmelCase      :		Dict=2_5_6      ,  UpperCAmelCase      :		List[Any]=1_6      ,  UpperCAmelCase      :		Any=True      ,  UpperCAmelCase      :		List[Any]=6_4      ,  UpperCAmelCase      :		Dict=False      ,  UpperCAmelCase      :		List[Any]=-1      ,  UpperCAmelCase      :		Optional[int]=None      ,  UpperCAmelCase      :		List[str]=True      ,  UpperCAmelCase      :		Dict="scalenorm"      ,  UpperCAmelCase      :		Optional[int]=True      ,  UpperCAmelCase      :		str="silu"      ,  UpperCAmelCase      :		List[str]="softmax"      ,  UpperCAmelCase      :		List[str]=0.1      ,  UpperCAmelCase      :		Any=0.1      ,  UpperCAmelCase      :		List[str]=0.1      ,  UpperCAmelCase      :		Optional[Any]=False      ,  UpperCAmelCase      :		List[Any]=True      ,  UpperCAmelCase      :		List[str]=2_5_6      ,  UpperCAmelCase      :		int=True      ,  UpperCAmelCase      :		Any=0.1      ,  UpperCAmelCase      :		List[Any]=2_0_4_8      ,  UpperCAmelCase      :		Union[str, Any]=False      ,  UpperCAmelCase      :		Union[str, Any]=2      ,  UpperCAmelCase      :		List[str]=0.02      ,  UpperCAmelCase      :		Any=0.2      ,  UpperCAmelCase      :		Tuple=0.02      ,  UpperCAmelCase      :		Any=1.0      ,  UpperCAmelCase      :		str=1      ,  UpperCAmelCase      :		Optional[Any]=0      ,  UpperCAmelCase      :		List[str]=2      ,  UpperCAmelCase      :		Dict="rotary"      ,  UpperCAmelCase      :		List[str]=None      ,  UpperCAmelCase      :		List[str]=True      ,  UpperCAmelCase      :		List[str]=True      ,  **UpperCAmelCase      :		Union[str, Any]      ,  )							->     Any:
      super().__init__(pad_token_id=UpperCAmelCase      ,  bos_token_id=UpperCAmelCase      ,  eos_token_id=UpperCAmelCase      ,  **UpperCAmelCase )

      __lowerCAmelCase:       Optional[Any]            =				vocab_size
      __lowerCAmelCase:       Any            =				hidden_size
      __lowerCAmelCase:       Any            =				num_hidden_layers
      __lowerCAmelCase:       List[Any]            =				activation
      __lowerCAmelCase:       List[str]            =				attention_activation
      __lowerCAmelCase:       int            =				intermediate_size
      __lowerCAmelCase:       Optional[int]            =				ema_projection_size
      __lowerCAmelCase:       List[Any]            =				bidirectional
      __lowerCAmelCase:       Any            =				shared_representation_size
      __lowerCAmelCase:       Optional[int]            =				use_chunking
      __lowerCAmelCase:       Dict            =				chunk_size
      __lowerCAmelCase:       List[str]            =				truncation
      __lowerCAmelCase:       Tuple            =				normalize_before_mega
      __lowerCAmelCase:       Union[str, Any]            =				normalization_type
      __lowerCAmelCase:       Dict            =				norm_affine
      __lowerCAmelCase:       Any            =				dropout_prob
      __lowerCAmelCase:       List[Any]            =				hidden_dropout_prob
      __lowerCAmelCase:       List[Any]            =				attention_probs_dropout_prob
      __lowerCAmelCase:       Dict            =				use_feature_dropout
      __lowerCAmelCase:       Dict            =				use_normalized_ffn
      __lowerCAmelCase:       Any            =				nffn_hidden_size
      __lowerCAmelCase:       Optional[Any]            =				normalize_before_ffn
      __lowerCAmelCase:       Dict            =				nffn_activation_dropout_prob
      __lowerCAmelCase:       Any            =				max_positions
      __lowerCAmelCase:       List[str]            =				add_token_type_embeddings
      __lowerCAmelCase:       Tuple            =				type_vocab_size
      __lowerCAmelCase:       Optional[int]            =				initializer_range
      __lowerCAmelCase:       Union[str, Any]            =				ema_delta_alpha_range
      __lowerCAmelCase:       Dict            =				ema_beta_range
      __lowerCAmelCase:       Union[str, Any]            =				ema_gamma_omega_range
      __lowerCAmelCase:       Tuple            =				relative_positional_bias
      __lowerCAmelCase:       Tuple            =				use_cache
      __lowerCAmelCase:       List[Any]            =				classifier_dropout
      __lowerCAmelCase:       Optional[Any]            =				add_lm_hidden_dense_layer
      __lowerCAmelCase:       List[Any]            =				1  # not used but required by Hugging Face







class 							A_			(		snake_case__ ):


     @property
     def   UpperCAmelCase  (							self      :		Optional[Any] )							->     Mapping[str, Mapping[int, str]]:
      if self.task == "multiple-choice":
       __lowerCAmelCase:       List[Any]            =				{0: 'batch', 1: 'choice', 2: 'sequence'}
      else:
       __lowerCAmelCase:       List[str]            =				{0: 'batch', 1: 'sequence'}
      return OrderedDict(
          [
              ('input_ids', dynamic_axis),
              ('attention_mask', dynamic_axis),
          ] )








import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


_a			=       1_0_0_0_0_0_0_0_0_0_0_0
_a			=       1_0_0_0_0

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







def _a			(	SCREAMING_SNAKE_CASE		:      int   , SCREAMING_SNAKE_CASE		:      int		)   ->   datasets.Dataset:

 """simple docstring"""






 __lowerCAmelCase:       List[Any]            =				pa.Table.from_pydict({'col': [0] * chunk_size}		)
 __lowerCAmelCase:       Dict            =				pa.concat_tables([table] * (num_examples // chunk_size)		)
 return datasets.Dataset(SCREAMING_SNAKE_CASE   , fingerprint='table_100B'		)






@dataclass
class 							A_			:
     _lowercase      :					int
     _lowercase      :					int
     _lowercase      :					int
     _lowercase      :					int


     def   UpperCAmelCase  (							self      :		Optional[Any] )							->     Dict:
      __lowerCAmelCase:       Dict            =				np.random.default_rng(self.seed )
      __lowerCAmelCase:       List[Any]            =				rng.integers(low=self.low      ,  high=self.high      ,  size=self.size ).tolist()


     def __iter__(							self      :		Any )							->     Optional[int]:
      return iter(self._sampled_values )


     def __len__(							self      :		Union[str, Any] )							->     Dict:
      return self.size







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   List[str]:

 """simple docstring"""






 __lowerCAmelCase:       List[Any]            =				dataset[0]







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   Dict:

 """simple docstring"""






 __lowerCAmelCase:       Dict            =				dataset[-1]







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   Any:

 """simple docstring"""






 __lowerCAmelCase:       Union[str, Any]            =				dataset[range(len(SCREAMING_SNAKE_CASE		) // 2   , len(SCREAMING_SNAKE_CASE		) // 2 + 10_24		)]







@get_duration
def _a			(	SCREAMING_SNAKE_CASE		:      datasets.Dataset		)   ->   Optional[Any]:

 """simple docstring"""






 __lowerCAmelCase:       int            =				dataset[RandIter(0   , len(SCREAMING_SNAKE_CASE		)   , 10_24   , seed=42		)]







def _a			(	)   ->   Tuple:

 """simple docstring"""






 __lowerCAmelCase:       str            =				{'num examples': SPEED_TEST_N_EXAMPLES}
 __lowerCAmelCase:       Tuple            =				(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
 print('generating dataset'		)
 __lowerCAmelCase:       str            =				generate_100B_dataset(num_examples=SCREAMING_SNAKE_CASE   , chunk_size=SCREAMING_SNAKE_CASE		)
 print('Functions'		)
 for func in functions:
  print(func.__name__		)
  __lowerCAmelCase:       Dict            =				func(SCREAMING_SNAKE_CASE		)

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


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





