
lowerCAmelCase__							=				[
    999,
    800,
    799,
    600,
    599,
    500,
    400,
    399,
    377,
    355,
    333,
    311,
    288,
    266,
    244,
    222,
    200,
    199,
    177,
    155,
    133,
    111,
    88,
    66,
    44,
    22,
    0,
]

lowerCAmelCase__							=				[
    999,
    976,
    952,
    928,
    905,
    882,
    858,
    857,
    810,
    762,
    715,
    714,
    572,
    429,
    428,
    286,
    285,
    238,
    190,
    143,
    142,
    118,
    95,
    71,
    47,
    24,
    0,
]

lowerCAmelCase__							=				[
    999,
    988,
    977,
    966,
    955,
    944,
    933,
    922,
    911,
    900,
    899,
    879,
    859,
    840,
    820,
    800,
    799,
    766,
    733,
    700,
    699,
    650,
    600,
    599,
    500,
    499,
    400,
    399,
    350,
    300,
    299,
    266,
    233,
    200,
    199,
    179,
    159,
    140,
    120,
    100,
    99,
    88,
    77,
    66,
    55,
    44,
    33,
    22,
    11,
    0,
]

lowerCAmelCase__							=				[
    999,
    995,
    992,
    989,
    985,
    981,
    978,
    975,
    971,
    967,
    964,
    961,
    957,
    956,
    951,
    947,
    942,
    937,
    933,
    928,
    923,
    919,
    914,
    913,
    908,
    903,
    897,
    892,
    887,
    881,
    876,
    871,
    870,
    864,
    858,
    852,
    846,
    840,
    834,
    828,
    827,
    820,
    813,
    806,
    799,
    792,
    785,
    784,
    777,
    770,
    763,
    756,
    749,
    742,
    741,
    733,
    724,
    716,
    707,
    699,
    698,
    688,
    677,
    666,
    656,
    655,
    645,
    634,
    623,
    613,
    612,
    598,
    584,
    570,
    569,
    555,
    541,
    527,
    526,
    505,
    484,
    483,
    462,
    440,
    439,
    396,
    395,
    352,
    351,
    308,
    307,
    264,
    263,
    220,
    219,
    176,
    132,
    88,
    44,
    0,
]

lowerCAmelCase__							=				[
    999,
    997,
    995,
    992,
    990,
    988,
    986,
    984,
    981,
    979,
    977,
    975,
    972,
    970,
    968,
    966,
    964,
    961,
    959,
    957,
    956,
    954,
    951,
    949,
    946,
    944,
    941,
    939,
    936,
    934,
    931,
    929,
    926,
    924,
    921,
    919,
    916,
    914,
    913,
    910,
    907,
    905,
    902,
    899,
    896,
    893,
    891,
    888,
    885,
    882,
    879,
    877,
    874,
    871,
    870,
    867,
    864,
    861,
    858,
    855,
    852,
    849,
    846,
    843,
    840,
    837,
    834,
    831,
    828,
    827,
    824,
    821,
    817,
    814,
    811,
    808,
    804,
    801,
    798,
    795,
    791,
    788,
    785,
    784,
    780,
    777,
    774,
    770,
    766,
    763,
    760,
    756,
    752,
    749,
    746,
    742,
    741,
    737,
    733,
    730,
    726,
    722,
    718,
    714,
    710,
    707,
    703,
    699,
    698,
    694,
    690,
    685,
    681,
    677,
    673,
    669,
    664,
    660,
    656,
    655,
    650,
    646,
    641,
    636,
    632,
    627,
    622,
    618,
    613,
    612,
    607,
    602,
    596,
    591,
    586,
    580,
    575,
    570,
    569,
    563,
    557,
    551,
    545,
    539,
    533,
    527,
    526,
    519,
    512,
    505,
    498,
    491,
    484,
    483,
    474,
    466,
    457,
    449,
    440,
    439,
    428,
    418,
    407,
    396,
    395,
    381,
    366,
    352,
    351,
    330,
    308,
    307,
    286,
    264,
    263,
    242,
    220,
    219,
    176,
    175,
    132,
    131,
    88,
    44,
    0,
]

lowerCAmelCase__							=				[
    999,
    991,
    982,
    974,
    966,
    958,
    950,
    941,
    933,
    925,
    916,
    908,
    900,
    899,
    874,
    850,
    825,
    800,
    799,
    700,
    600,
    500,
    400,
    300,
    200,
    100,
    0,
]

lowerCAmelCase__							=				[
    999,
    992,
    985,
    978,
    971,
    964,
    957,
    949,
    942,
    935,
    928,
    921,
    914,
    907,
    900,
    899,
    879,
    859,
    840,
    820,
    800,
    799,
    766,
    733,
    700,
    699,
    650,
    600,
    599,
    500,
    499,
    400,
    399,
    300,
    299,
    200,
    199,
    100,
    99,
    0,
]

lowerCAmelCase__							=				[
    999,
    996,
    992,
    989,
    985,
    982,
    979,
    975,
    972,
    968,
    965,
    961,
    958,
    955,
    951,
    948,
    944,
    941,
    938,
    934,
    931,
    927,
    924,
    920,
    917,
    914,
    910,
    907,
    903,
    900,
    899,
    891,
    884,
    876,
    869,
    861,
    853,
    846,
    838,
    830,
    823,
    815,
    808,
    800,
    799,
    788,
    777,
    766,
    755,
    744,
    733,
    722,
    711,
    700,
    699,
    688,
    677,
    666,
    655,
    644,
    633,
    622,
    611,
    600,
    599,
    585,
    571,
    557,
    542,
    528,
    514,
    500,
    499,
    485,
    471,
    457,
    442,
    428,
    414,
    400,
    399,
    379,
    359,
    340,
    320,
    300,
    299,
    279,
    259,
    240,
    220,
    200,
    199,
    166,
    133,
    100,
    99,
    66,
    33,
    0,
]

"""simple docstring"""




import logging
import os
from dataclasses import dataclass, field
from typing import Dict, Optional

import numpy as np
from utils_multiple_choice import MultipleChoiceDataset, Split, processors

import transformers
from transformers import (
    AutoConfig,
    AutoModelForMultipleChoice,
    AutoTokenizer,
    DataCollatorWithPadding,
    EvalPrediction,
    HfArgumentParser,
    Trainer,
    TrainingArguments,
    set_seed,
)
from transformers.trainer_utils import is_main_process


lowerCAmelCase__							=				logging.getLogger(__name__)



def        _lowerCamelCase ( __a,							__a    ):
		return (preds == labels).mean()





@dataclass
class  snake_case     :
							UpperCAmelCase__						     =      field(
							    metadata={'''help''': '''Path to pretrained model or model identifier from huggingface.co/models'''}   )
							UpperCAmelCase__						     =      field(
							    default=__lowercase       ,			metadata={'''help''': '''Pretrained config name or path if not the same as model_name'''}   )
							UpperCAmelCase__						     =      field(
							    default=__lowercase       ,			metadata={'''help''': '''Pretrained tokenizer name or path if not the same as model_name'''}   )
							UpperCAmelCase__						     =      field(
							    default=__lowercase       ,			metadata={'''help''': '''Where do you want to store the pretrained models downloaded from huggingface.co'''}       ,			)







@dataclass
class  snake_case     :
							UpperCAmelCase__						     =      field(metadata={'''help''': '''The name of the task to train on: ''' + ''', '''.join(processors.keys()   )}   )
							UpperCAmelCase__						     =      field(metadata={'''help''': '''Should contain the data files for the task.'''}   )
							UpperCAmelCase__						     =      field(
							    default=128       ,			metadata={
							        '''help''': (
							            '''The maximum total input sequence length after tokenization. Sequences longer '''
							            '''than this will be truncated, sequences shorter will be padded.'''
							        )
							    }       ,			)
							UpperCAmelCase__						     =      field(
							    default=__lowercase       ,			metadata={'''help''': '''Overwrite the cached training and evaluation sets'''}   )







def        _lowerCamelCase ( ):
		# See all possible arguments in src/transformers/training_args.py
		# or by passing the --help flag to this script.
		# We now keep distinct sets of args, for a cleaner separation of concerns.

		SCREAMING_SNAKE_CASE_						 = HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments)    )
		SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_						 = parser.parse_args_into_dataclasses()

		if (
		    os.path.exists(training_args.output_dir    )
		    and os.listdir(training_args.output_dir    )
		    and training_args.do_train
		    and not training_args.overwrite_output_dir
		):
				raise ValueError(
				    F'Output directory ({training_args.output_dir}) already exists and is not empty. Use'
				    ''' --overwrite_output_dir to overcome.'''    )

		# Setup logging
		logging.basicConfig(
		    format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s''',							datefmt='''%m/%d/%Y %H:%M:%S''',							level=logging.INFO if training_args.local_rank in [-1, 0] else logging.WARN,							)
		logger.warning(
		    '''Process rank: %s, device: %s, n_gpu: %s, distributed training: %s, 16-bits training: %s''',							training_args.local_rank,							training_args.device,							training_args.n_gpu,							bool(training_args.local_rank != -1    ),							training_args.fpaa,							)
		# Set the verbosity to info of the Transformers logger (on main process only):
		if is_main_process(training_args.local_rank    ):
				transformers.utils.logging.set_verbosity_info()
				transformers.utils.logging.enable_default_handler()
				transformers.utils.logging.enable_explicit_format()
		logger.info('''Training/evaluation parameters %s''',							__a    )

		# Set seed
		set_seed(training_args.seed    )

		try:
				SCREAMING_SNAKE_CASE_						 = processors[data_args.task_name]()
				SCREAMING_SNAKE_CASE_						 = processor.get_labels()
				SCREAMING_SNAKE_CASE_						 = len(__a    )
		except KeyError:
				raise ValueError('''Task not found: %s''' % (data_args.task_name)    )

		# Load pretrained model and tokenizer
		#
		# Distributed training:
		# The .from_pretrained methods guarantee that only one local process can concurrently
		# download model & vocab.

		SCREAMING_SNAKE_CASE_						 = AutoConfig.from_pretrained(
		    model_args.config_name if model_args.config_name else model_args.model_name_or_path,							num_labels=__a,							finetuning_task=data_args.task_name,							cache_dir=model_args.cache_dir,							)
		SCREAMING_SNAKE_CASE_						 = AutoTokenizer.from_pretrained(
		    model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,							cache_dir=model_args.cache_dir,							)
		SCREAMING_SNAKE_CASE_						 = AutoModelForMultipleChoice.from_pretrained(
		    model_args.model_name_or_path,							from_tf=bool('''.ckpt''' in model_args.model_name_or_path    ),							config=__a,							cache_dir=model_args.cache_dir,							)

		# Get datasets
		SCREAMING_SNAKE_CASE_						 = (
		    MultipleChoiceDataset(
		        data_dir=data_args.data_dir,							tokenizer=__a,							task=data_args.task_name,							max_seq_length=data_args.max_seq_length,							overwrite_cache=data_args.overwrite_cache,							mode=Split.train,							)
		    if training_args.do_train
		    else None
		)
		SCREAMING_SNAKE_CASE_						 = (
		    MultipleChoiceDataset(
		        data_dir=data_args.data_dir,							tokenizer=__a,							task=data_args.task_name,							max_seq_length=data_args.max_seq_length,							overwrite_cache=data_args.overwrite_cache,							mode=Split.dev,							)
		    if training_args.do_eval
		    else None
		)

		def compute_metrics(__a    ) -> Dict:
				SCREAMING_SNAKE_CASE_						 = np.argmax(p.predictions,							axis=1    )
				return {"acc": simple_accuracy(__a,							p.label_ids    )}

		# Data collator
		SCREAMING_SNAKE_CASE_						 = DataCollatorWithPadding(__a,							pad_to_multiple_of=8    ) if training_args.fpaa else None

		# Initialize our Trainer
		SCREAMING_SNAKE_CASE_						 = Trainer(
		    model=__a,							args=__a,							train_dataset=__a,							eval_dataset=__a,							compute_metrics=__a,							data_collator=__a,							)

		# Training
		if training_args.do_train:
				trainer.train(
				    model_path=model_args.model_name_or_path if os.path.isdir(model_args.model_name_or_path    ) else None    )
				trainer.save_model()
				# For convenience, we also re-save the tokenizer to the same directory,
				# so that you can share your model easily on huggingface.co/models =)
				if trainer.is_world_master():
						tokenizer.save_pretrained(training_args.output_dir    )

    # Evaluation
		SCREAMING_SNAKE_CASE_						 = {}
		if training_args.do_eval:
				logger.info('''*** Evaluate ***'''    )

				SCREAMING_SNAKE_CASE_						 = trainer.evaluate()

				SCREAMING_SNAKE_CASE_						 = os.path.join(training_args.output_dir,							'''eval_results.txt'''    )
				if trainer.is_world_master():
						with open(__a,							'''w'''    ) as writer:
								logger.info('''***** Eval results *****'''    )
								for key, value in result.items():
										logger.info('''  %s = %s''',							__a,							__a    )
										writer.write('''%s = %s\n''' % (key, value)    )

								results.update(__a    )

		return results



def        _lowerCamelCase ( __a    ):
		# For xla_spawn (TPUs)
		main()


if __name__ == "__main__":
						main()