




"""simple docstring"""

import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


__lowerCamelCase								=						datasets.utils.logging.get_logger(__name__)



@dataclass
class  _snake_case				(							datasets.BuilderConfig       ):

				'''simple docstring'''




				UpperCamelCase__		     =None



class  _snake_case				(							datasets.ArrowBasedBuilder       ):

				'''simple docstring'''




				UpperCamelCase__		     =ArrowConfig





				def 				snake_case_ (							self      :  str     ):
								return datasets.DatasetInfo(features=self.config.features     )





				def 				snake_case_ (							self      :  Union[str, Any]					,							snake_case      :  Union[str, Any]     ):





								if not self.config.data_files:
												raise ValueError(f'At least one data file must be specified, but got data_files={self.config.data_files}'     )
								UpperCAmelCase_					:Dict      			=      dl_manager.download_and_extract(self.config.data_files     )
								if isinstance(__a					,							(str, list, tuple)     ):
												UpperCAmelCase_					:Optional[Any]      			=      data_files
												if isinstance(__a					,							__a     ):
																UpperCAmelCase_					:Tuple      			=      [files]
												# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
												UpperCAmelCase_					:Tuple      			=      [dl_manager.iter_files(__a     ) for file in files]
												return [datasets.SplitGenerator(name=datasets.Split.TRAIN					,							gen_kwargs={'''files''': files}     )]
								UpperCAmelCase_					:int      			=      []
								for split_name, files in data_files.items():
												if isinstance(__a					,							__a     ):
																UpperCAmelCase_					:Optional[int]      			=      [files]
												# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
												UpperCAmelCase_					:List[Any]      			=      [dl_manager.iter_files(__a     ) for file in files]
												# Infer features is they are stoed in the arrow schema
												if self.info.features is None:
																for file in itertools.chain.from_iterable(__a     ):
																				with open(__a					,							'''rb'''     ) as f:
																								UpperCAmelCase_					:List[str]      			=      datasets.Features.from_arrow_schema(pa.ipc.open_stream(__a     ).schema     )
																				break
												splits.append(datasets.SplitGenerator(name=__a					,							gen_kwargs={'''files''': files}     )     )
								return splits





				def 				snake_case_ (							self      :  List[Any]					,							snake_case      :  Optional[Any]     ):





								if self.info.features is not None:
												# more expensive cast to support nested features with keys in a different order
												# allows str <-> int/float or str to Audio for example
												UpperCAmelCase_					:Any      			=      table_cast(__a					,							self.info.features.arrow_schema     )
								return pa_table





				def 				snake_case_ (							self      :  Union[str, Any]					,							snake_case      :  Union[str, Any]     ):





								for file_idx, file in enumerate(itertools.chain.from_iterable(__a     )     ):
												with open(__a					,							'''rb'''     ) as f:
																try:
																				for batch_idx, record_batch in enumerate(pa.ipc.open_stream(__a     )     ):
																								UpperCAmelCase_					:Union[str, Any]      			=      pa.Table.from_batches([record_batch]     )
																								# Uncomment for debugging (will print the Arrow table size and elements)
																								# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
																								# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
																								yield f'{file_idx}_{batch_idx}', self._cast_table(__a     )
																except ValueError as e:
																				logger.error(f'Failed to read file \'{file}\' with error {type(__a     )}: {e}'     )
																				raise












"""simple docstring"""

from collections import OrderedDict
from typing import Mapping

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


__lowerCamelCase								=						logging.get_logger(__name__)

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



class  _snake_case				(							A__       ):

				'''simple docstring'''




				UpperCamelCase__		     ="""mega"""





				def __init__(							self      :  Optional[int]					,							snake_case      :  Union[str, Any]=30_522					,							snake_case      :  Optional[Any]=128					,							snake_case      :  str=4					,							snake_case      :  Dict=256					,							snake_case      :  Optional[Any]=16					,							snake_case      :  Any=True					,							snake_case      :  str=64					,							snake_case      :  Optional[Any]=False					,							snake_case      :  Union[str, Any]=-1					,							snake_case      :  List[str]=None					,							snake_case      :  Any=True					,							snake_case      :  Optional[int]="scalenorm"					,							snake_case      :  Tuple=True					,							snake_case      :  str="silu"					,							snake_case      :  Dict="softmax"					,							snake_case      :  Optional[int]=0.1					,							snake_case      :  Tuple=0.1					,							snake_case      :  Dict=0.1					,							snake_case      :  List[str]=False					,							snake_case      :  Any=True					,							snake_case      :  List[Any]=256					,							snake_case      :  Optional[Any]=True					,							snake_case      :  Optional[int]=0.1					,							snake_case      :  str=2_048					,							snake_case      :  Union[str, Any]=False					,							snake_case      :  List[Any]=2					,							snake_case      :  str=0.02					,							snake_case      :  str=0.2					,							snake_case      :  str=0.02					,							snake_case      :  Union[str, Any]=1.0					,							snake_case      :  Optional[Any]=1					,							snake_case      :  List[Any]=0					,							snake_case      :  List[Any]=2					,							snake_case      :  List[Any]="rotary"					,							snake_case      :  Tuple=None					,							snake_case      :  int=True					,							snake_case      :  Dict=True					,							**snake_case      :  List[str]					,							):
								super().__init__(pad_token_id=snake_case					,							bos_token_id=snake_case					,							eos_token_id=snake_case					,							**snake_case     )

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



class  _snake_case				(							A__       ):

				'''simple docstring'''




				@property
				def 				snake_case_ (							self      :  int     ):
								if self.task == "multiple-choice":
												UpperCAmelCase_					:List[str]      			=      {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
								else:
												UpperCAmelCase_					:Tuple      			=      {0: '''batch''', 1: '''sequence'''}
								return OrderedDict(
								    [
								        ('''input_ids''', dynamic_axis),
								        ('''attention_mask''', dynamic_axis),
								    ]     )


