




import os
from argparse import ArgumentParser
from pathlib import Path
from shutil import copyfile
from typing import List

from datasets import config
from datasets.builder import DatasetBuilder
from datasets.commands import BaseDatasetsCLICommand
from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadMode
from datasets.load import dataset_module_factory, import_main_class
from datasets.utils.info_utils import VerificationMode
def        lowerCamelCase_     (     SCREAMING_SNAKE_CASE       ,						**SCREAMING_SNAKE_CASE ):
			'''simple docstring'''
			return RunBeamCommand(
			    args.dataset       ,						args.name       ,						args.cache_dir       ,						args.beam_pipeline_options       ,						args.data_dir       ,						args.all_configs       ,						args.save_info or args.save_infos       ,						args.ignore_verifications       ,						args.force_redownload       ,						**SCREAMING_SNAKE_CASE       ,						)




class       UpperCAmelCase_   ( A							):




							'''simple docstring'''



							@staticmethod
							def  _UpperCAmelCase  (       a							:						ArgumentParser      )      ->       Any:
										SCREAMING_SNAKE_CASE     =       parser.add_parser("""run_beam"""							,  help="""Run a Beam dataset processing pipeline"""      )
										run_beam_parser.add_argument("""dataset"""							,  type=a							,  help="""Name of the dataset to download"""      )
										run_beam_parser.add_argument("""--name"""							,  type=a							,  default=a							,  help="""Dataset config name"""      )
										run_beam_parser.add_argument(
										    """--cache_dir"""							,  type=a							,  default=a							,  help="""Cache directory where the datasets are stored"""							,  )
										run_beam_parser.add_argument(
										    """--beam_pipeline_options"""							,  type=a							,  default=""""""							,  help="""Beam pipeline options, separated by commas. Example:: `--beam_pipeline_options=job_name=my-job,project=my-project`"""							,  )
										run_beam_parser.add_argument(
										    """--data_dir"""							,  type=a							,  default=a							,  help="""Can be used to specify a manual directory to get the files from"""							,  )
										run_beam_parser.add_argument("""--all_configs"""							,  action="""store_true"""							,  help="""Test all dataset configurations"""      )
										run_beam_parser.add_argument("""--save_info"""							,  action="""store_true"""							,  help="""Save the dataset infos file"""      )
										run_beam_parser.add_argument(
										    """--ignore_verifications"""							,  action="""store_true"""							,  help="""Run the test without checksums and splits checks"""      )
										run_beam_parser.add_argument("""--force_redownload"""							,  action="""store_true"""							,  help="""Force dataset redownload"""      )
										# aliases
										run_beam_parser.add_argument("""--save_infos"""							,  action="""store_true"""							,  help="""alias for save_info"""      )
										run_beam_parser.set_defaults(func=a      )





							def __init__(       self							:						Tuple							,  a							:						str							,  a							:						str							,  a							:						str							,  a							:						str							,  a							:						str							,  a							:						bool							,  a							:						bool							,  a							:						bool							,  a							:						bool							,  **a							:						List[str]							,  )      ->       Any:
										SCREAMING_SNAKE_CASE     =       dataset
										SCREAMING_SNAKE_CASE     =       name
										SCREAMING_SNAKE_CASE     =       cache_dir
										SCREAMING_SNAKE_CASE     =       beam_pipeline_options
										SCREAMING_SNAKE_CASE     =       data_dir
										SCREAMING_SNAKE_CASE     =       all_configs
										SCREAMING_SNAKE_CASE     =       save_infos
										SCREAMING_SNAKE_CASE     =       ignore_verifications
										SCREAMING_SNAKE_CASE     =       force_redownload
										SCREAMING_SNAKE_CASE     =       config_kwargs







							def  _UpperCAmelCase  (       self							:						Dict      )      ->       List[str]:
										import apache_beam as beam

										if self._name is not None and self._all_configs:
													print("""Both parameters `name` and `all_configs` can't be used at once."""      )
													exit(1      )
										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self._dataset, self._name
										SCREAMING_SNAKE_CASE     =       dataset_module_factory(a      )
										SCREAMING_SNAKE_CASE     =       import_main_class(dataset_module.module_path      )
										SCREAMING_SNAKE_CASE     =       []
										if self._beam_pipeline_options:
													SCREAMING_SNAKE_CASE     =       beam.options.pipeline_options.PipelineOptions(
													    flags=[f"""--{opt.strip()}""" for opt in self._beam_pipeline_options.split(""","""      ) if opt]      )
										else:
													SCREAMING_SNAKE_CASE     =       None
										if self._all_configs and len(builder_cls.BUILDER_CONFIGS      ) > 0:
													for builder_config in builder_cls.BUILDER_CONFIGS:
																builders.append(
																    builder_cls(
																        config_name=builder_config.name							,  data_dir=self._data_dir							,  hash=dataset_module.hash							,  beam_options=a							,  cache_dir=self._cache_dir							,  base_path=dataset_module.builder_kwargs.get("""base_path"""      )							,  )      )
										else:
													builders.append(
													    builder_cls(
													        config_name=a							,  data_dir=self._data_dir							,  beam_options=a							,  cache_dir=self._cache_dir							,  base_path=dataset_module.builder_kwargs.get("""base_path"""      )							,  **self._config_kwargs							,  )      )

										for builder in builders:
													builder.download_and_prepare(
													    download_mode=DownloadMode.REUSE_CACHE_IF_EXISTS
													    if not self._force_redownload
													    else DownloadMode.FORCE_REDOWNLOAD							,  download_config=DownloadConfig(cache_dir=config.DOWNLOADED_DATASETS_PATH      )							,  verification_mode=VerificationMode.NO_CHECKS
													    if self._ignore_verifications
													    else VerificationMode.ALL_CHECKS							,  try_from_hf_gcs=a							,  )
													if self._save_infos:
																builder._save_infos()

										print("""Apache beam run successful."""      )

										# If save_infos=True, the dataset infos file is created next to the loaded module file.
										# Let's move it to the original directory of the dataset script, to allow the user to
										# upload them on S3 at the same time afterwards.
										if self._save_infos:
													SCREAMING_SNAKE_CASE     =       os.path.join(builder_cls.get_imported_module_dir()							,  config.DATASETDICT_INFOS_FILENAME      )

													SCREAMING_SNAKE_CASE     =       Path(a      ).name + """.py"""

													SCREAMING_SNAKE_CASE     =       os.path.join(a							,  a      )
													if os.path.isfile(a      ):
																SCREAMING_SNAKE_CASE     =       os.path.dirname(a      )
													elif os.path.isfile(a      ):
																SCREAMING_SNAKE_CASE     =       path
													else:  # in case of a remote dataset
																print(f"""Dataset Infos file saved at {dataset_infos_path}"""      )
																exit(1      )

													# Move datasetinfo back to the user
													SCREAMING_SNAKE_CASE     =       os.path.join(a							,  config.DATASETDICT_INFOS_FILENAME      )
													copyfile(a							,  a      )
													print(f"""Dataset Infos file saved at {user_dataset_infos_path}"""      )












from collections import OrderedDict
from typing import Mapping

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


__A    :				List[str]    						=	logging.get_logger(__name__)

__A    :				List[Any]    						=	{
    """mnaylor/mega-base-wikitext""": """https://huggingface.co/mnaylor/mega-base-wikitext/resolve/main/config.json""",
}




class       UpperCAmelCase_   ( A							):




							'''simple docstring'''



							a__    	=  '''mega'''





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

										SCREAMING_SNAKE_CASE     =       vocab_size
										SCREAMING_SNAKE_CASE     =       hidden_size
										SCREAMING_SNAKE_CASE     =       num_hidden_layers
										SCREAMING_SNAKE_CASE     =       activation
										SCREAMING_SNAKE_CASE     =       attention_activation
										SCREAMING_SNAKE_CASE     =       intermediate_size
										SCREAMING_SNAKE_CASE     =       ema_projection_size
										SCREAMING_SNAKE_CASE     =       bidirectional
										SCREAMING_SNAKE_CASE     =       shared_representation_size
										SCREAMING_SNAKE_CASE     =       use_chunking
										SCREAMING_SNAKE_CASE     =       chunk_size
										SCREAMING_SNAKE_CASE     =       truncation
										SCREAMING_SNAKE_CASE     =       normalize_before_mega
										SCREAMING_SNAKE_CASE     =       normalization_type
										SCREAMING_SNAKE_CASE     =       norm_affine
										SCREAMING_SNAKE_CASE     =       dropout_prob
										SCREAMING_SNAKE_CASE     =       hidden_dropout_prob
										SCREAMING_SNAKE_CASE     =       attention_probs_dropout_prob
										SCREAMING_SNAKE_CASE     =       use_feature_dropout
										SCREAMING_SNAKE_CASE     =       use_normalized_ffn
										SCREAMING_SNAKE_CASE     =       nffn_hidden_size
										SCREAMING_SNAKE_CASE     =       normalize_before_ffn
										SCREAMING_SNAKE_CASE     =       nffn_activation_dropout_prob
										SCREAMING_SNAKE_CASE     =       max_positions
										SCREAMING_SNAKE_CASE     =       add_token_type_embeddings
										SCREAMING_SNAKE_CASE     =       type_vocab_size
										SCREAMING_SNAKE_CASE     =       initializer_range
										SCREAMING_SNAKE_CASE     =       ema_delta_alpha_range
										SCREAMING_SNAKE_CASE     =       ema_beta_range
										SCREAMING_SNAKE_CASE     =       ema_gamma_omega_range
										SCREAMING_SNAKE_CASE     =       relative_positional_bias
										SCREAMING_SNAKE_CASE     =       use_cache
										SCREAMING_SNAKE_CASE     =       classifier_dropout
										SCREAMING_SNAKE_CASE     =       add_lm_hidden_dense_layer
										SCREAMING_SNAKE_CASE     =       1  # not used but required by Hugging Face





class       UpperCAmelCase_   ( A							):




							'''simple docstring'''



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






