
import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import SPIECE_UNDERLINE, logging


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

snake_case :		Optional[Any]							      =  {"vocab_file": "spiece.model"}

snake_case :		Union[str, Any]							      =  {
    "vocab_file": {
        "xlnet-base-cased": "https://huggingface.co/xlnet-base-cased/resolve/main/spiece.model",
        "xlnet-large-cased": "https://huggingface.co/xlnet-large-cased/resolve/main/spiece.model",
    }
}

snake_case :		Any							      =  {
    "xlnet-base-cased": None,
    "xlnet-large-cased": None,
}

# Segments (not really needed)
snake_case :		Optional[int]							      =  0
snake_case :		Any							      =  1
snake_case :		Union[str, Any]							      =  2
snake_case :		List[str]							      =  3
snake_case :		Union[str, Any]							      =  4





class       _snake_case					(     snake_case				):
			UpperCamelCase__          =    VOCAB_FILES_NAMES
			UpperCamelCase__          =    PRETRAINED_VOCAB_FILES_MAP
			UpperCamelCase__          =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			UpperCamelCase__          =    'left'







			def __init__(				self						,   _a						,   _a=False						,   _a=True						,   _a=False						,   _a="<s>"						,   _a="</s>"						,   _a="<unk>"						,   _a="<sep>"						,   _a="<pad>"						,   _a="<cls>"						,   _a="<mask>"						,   _a=["<eop>", "<eod>"]						,   _a = None						,   **_a						,   ):
				# Mask token behave like a normal word, i.e. include the space before it
				__magic_name__		:		Union[str, Any]	   =     AddedToken(_a						,   lstrip=_a						,   rstrip=_a		) if isinstance(_a						,   _a		) else mask_token

				__magic_name__		:		List[Any]	   =     {} if sp_model_kwargs is None else sp_model_kwargs

				super().__init__(
				    do_lower_case=_a						,   remove_space=_a						,   keep_accents=_a						,   bos_token=_a						,   eos_token=_a						,   unk_token=_a						,   sep_token=_a						,   pad_token=_a						,   cls_token=_a						,   mask_token=_a						,   additional_special_tokens=_a						,   sp_model_kwargs=self.sp_model_kwargs						,   **_a						,   )

				__magic_name__		:		Union[str, Any]	   =     3

				__magic_name__		:		Any	   =     do_lower_case
				__magic_name__		:		int	   =     remove_space
				__magic_name__		:		Dict	   =     keep_accents
				__magic_name__		:		Any	   =     vocab_file

				__magic_name__		:		Union[str, Any]	   =     spm.SentencePieceProcessor(**self.sp_model_kwargs		)
				self.sp_model.Load(_a		)







			@property
			def 			SCREAMING_SNAKE_CASE    (				self		):
				return len(self.sp_model		)







			def 			SCREAMING_SNAKE_CASE    (				self		):
				__magic_name__		:		Union[str, Any]	   =     {self.convert_ids_to_tokens(_a		): i for i in range(self.vocab_size		)}
				vocab.update(self.added_tokens_encoder		)
				return vocab







			def __getstate__(				self		):
				__magic_name__		:		List[Any]	   =     self.__dict__.copy()
				__magic_name__		:		List[str]	   =     None
				return state







			def __setstate__(				self						,   _a		):
				__magic_name__		:		Dict	   =     d

				# for backward compatibility
				if not hasattr(self						,   "sp_model_kwargs"		):
					__magic_name__		:		Optional[int]	   =     {}

				__magic_name__		:		Optional[Any]	   =     spm.SentencePieceProcessor(**self.sp_model_kwargs		)
				self.sp_model.Load(self.vocab_file		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				if self.remove_space:
					__magic_name__		:		str	   =     " ".join(inputs.strip().split()		)
				else:
					__magic_name__		:		Optional[Any]	   =     inputs
				__magic_name__		:		Any	   =     outputs.replace("``"						,   "\""		).replace("''"						,   "\""		)

				if not self.keep_accents:
					__magic_name__		:		Any	   =     unicodedata.normalize("NFKD"						,   _a		)
					__magic_name__		:		Tuple	   =     "".join([c for c in outputs if not unicodedata.combining(_a		)]		)
				if self.do_lower_case:
					__magic_name__		:		str	   =     outputs.lower()

				return outputs







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				__magic_name__		:		str	   =     self.preprocess_text(_a		)
				__magic_name__		:		Tuple	   =     self.sp_model.encode(_a						,   out_type=_a		)
				__magic_name__		:		List[str]	   =     []
				for piece in pieces:
					if len(_a		) > 1 and piece[-1] == str(","		) and piece[-2].isdigit():
						__magic_name__		:		Union[str, Any]	   =     self.sp_model.EncodeAsPieces(piece[:-1].replace(_a						,   ""		)		)
						if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
							if len(cur_pieces[0]		) == 1:
								__magic_name__		:		Optional[int]	   =     cur_pieces[1:]
							else:
								__magic_name__		:		List[str]	   =     cur_pieces[0][1:]
						cur_pieces.append(piece[-1]		)
						new_pieces.extend(_a		)
					else:
						new_pieces.append(_a		)

				return new_pieces







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				return self.sp_model.PieceToId(_a		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				return self.sp_model.IdToPiece(_a		)







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a		):
				__magic_name__		:		Tuple	   =     "".join(_a		).replace(_a						,   " "		).strip()
				return out_string







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a = False						,   _a = None						,   _a = True						,   **_a						,   ):
				__magic_name__		:		Optional[Any]	   =     kwargs.pop("use_source_tokenizer"						,   _a		)

				__magic_name__		:		str	   =     self.convert_ids_to_tokens(_a						,   skip_special_tokens=_a		)

				# To avoid mixing byte-level and unicode for byte-level BPT
				# we need to build string separately for added tokens and byte-level tokens
				# cf. https://github.com/huggingface/transformers/issues/1133
				__magic_name__		:		int	   =     []
				__magic_name__		:		Union[str, Any]	   =     []
				for token in filtered_tokens:
					if skip_special_tokens and token in self.all_special_ids:
						continue
					if token in self.added_tokens_encoder:
						if current_sub_text:
							sub_texts.append(self.convert_tokens_to_string(_a		)		)
							__magic_name__		:		Optional[int]	   =     []
						sub_texts.append(_a		)
					else:
						current_sub_text.append(_a		)
				if current_sub_text:
					sub_texts.append(self.convert_tokens_to_string(_a		)		)

				# Mimic the behavior of the Rust tokenizer:
				# By default, there are no spaces between special tokens
				__magic_name__		:		Dict	   =     "".join(_a		)

				__magic_name__		:		Optional[Any]	   =     (
				    clean_up_tokenization_spaces
				    if clean_up_tokenization_spaces is not None
				    else self.clean_up_tokenization_spaces
				)
				if clean_up_tokenization_spaces:
					__magic_name__		:		str	   =     self.clean_up_tokenization(_a		)
					return clean_text
				else:
					return text







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a = None		):
				__magic_name__		:		str	   =     [self.sep_token_id]
				__magic_name__		:		List[str]	   =     [self.cls_token_id]
				if token_ids_a is None:
					return token_ids_a + sep + cls
				return token_ids_a + sep + token_ids_a + sep + cls







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a = None						,   _a = False		):

				if already_has_special_tokens:
					return super().get_special_tokens_mask(
					    token_ids_a=_a						,   token_ids_a=_a						,   already_has_special_tokens=_a		)

				if token_ids_a is not None:
					return ([0] * len(_a		)) + [1] + ([0] * len(_a		)) + [1, 1]
				return ([0] * len(_a		)) + [1, 1]







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a = None		):
				__magic_name__		:		Tuple	   =     [self.sep_token_id]
				__magic_name__		:		Union[str, Any]	   =     [2]

				if token_ids_a is None:
					return len(token_ids_a + sep		) * [0] + cls_segment_id
				return len(token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1] + cls_segment_id







			def 			SCREAMING_SNAKE_CASE    (				self						,   _a						,   _a = None		):
				if not os.path.isdir(_a		):
					logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''		)
					return
				__magic_name__		:		Optional[int]	   =     os.path.join(
				    _a						,   (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]		)

				if os.path.abspath(self.vocab_file		) != os.path.abspath(_a		) and os.path.isfile(self.vocab_file		):
					copyfile(self.vocab_file						,   _a		)
				elif not os.path.isfile(self.vocab_file		):
					with open(_a						,   "wb"		) as fi:
						__magic_name__		:		List[str]	   =     self.sp_model.serialized_model_proto()
						fi.write(_a		)

				return (out_vocab_file,)


import argparse
import csv
import logging
import os
import random

import numpy as np
import torch
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDataset
from tqdm import tqdm, trange

from transformers import (
    CONFIG_NAME,
    WEIGHTS_NAME,
    AdamW,
    OpenAIGPTDoubleHeadsModel,
    OpenAIGPTTokenizer,
    get_linear_schedule_with_warmup,
)


logging.basicConfig(
    format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO
)
snake_case :		Optional[int]							      =  logging.getLogger(__name__)






def   lowerCAmelCase_						(					_snake_case      :  Dict      ,   _snake_case      :  Union[str, Any]   )				->		Tuple:







	'''simple docstring'''


	__magic_name__		:		List[str]	   =     np.argmax(_snake_case      ,   axis=1   )
	return np.sum(outputs == labels   )






def   lowerCAmelCase_						(					_snake_case      :  Optional[Any]   )				->		Dict:







	'''simple docstring'''


	with open(_snake_case      ,   encoding="utf_8"   ) as f:
		__magic_name__		:		List[str]	   =     csv.reader(_snake_case   )
		__magic_name__		:		List[Any]	   =     []
		next(_snake_case   )  # skip the first line
		for line in tqdm(_snake_case   ):
			output.append((" ".join(line[1:5]   ), line[5], line[6], int(line[-1]   ) - 1)   )
	return output






def   lowerCAmelCase_						(					_snake_case      :  str      ,   _snake_case      :  Tuple      ,   _snake_case      :  Union[str, Any]      ,   _snake_case      :  List[Any]      ,   _snake_case      :  Tuple      ,   _snake_case      :  Optional[int]   )				->		int:







	'''simple docstring'''


	__magic_name__		:		Optional[int]	   =     []
	for dataset in encoded_datasets:
		__magic_name__		:		Union[str, Any]	   =     len(_snake_case   )
		__magic_name__		:		Dict	   =     np.zeros((n_batch, 2, input_len)      ,   dtype=np.intaa   )
		__magic_name__		:		List[str]	   =     np.zeros((n_batch, 2)      ,   dtype=np.intaa   )
		__magic_name__		:		Optional[int]	   =     np.full((n_batch, 2, input_len)      ,   fill_value=-100      ,   dtype=np.intaa   )
		__magic_name__		:		int	   =     np.zeros((n_batch,)      ,   dtype=np.intaa   )
		for (
		    i,
		    (story, conta, conta, mc_label),
		) in enumerate(_snake_case   ):
			__magic_name__		:		Dict	   =     [start_token] + story[:cap_length] + [delimiter_token] + conta[:cap_length] + [clf_token]
			__magic_name__		:		Dict	   =     [start_token] + story[:cap_length] + [delimiter_token] + conta[:cap_length] + [clf_token]
			__magic_name__		:		str	   =     with_conta
			__magic_name__		:		Tuple	   =     with_conta
			__magic_name__		:		Union[str, Any]	   =     len(_snake_case   ) - 1
			__magic_name__		:		int	   =     len(_snake_case   ) - 1
			__magic_name__		:		Optional[Any]	   =     with_conta
			__magic_name__		:		Optional[Any]	   =     with_conta
			__magic_name__		:		Optional[int]	   =     mc_label
		__magic_name__		:		str	   =     (input_ids, mc_token_ids, lm_labels, mc_labels)
		tensor_datasets.append(tuple(torch.tensor(_snake_case   ) for t in all_inputs   )   )
	return tensor_datasets






def   lowerCAmelCase_						(					)				->		List[Any]:







	'''simple docstring'''


	__magic_name__		:		Any	   =     argparse.ArgumentParser()
	parser.add_argument("--model_name"      ,   type=_snake_case      ,   default="openai-gpt"      ,   help="pretrained model name"   )
	parser.add_argument("--do_train"      ,   action="store_true"      ,   help="Whether to run training."   )
	parser.add_argument("--do_eval"      ,   action="store_true"      ,   help="Whether to run eval on the dev set."   )
	parser.add_argument(
	    "--output_dir"      ,   default=_snake_case      ,   type=_snake_case      ,   required=_snake_case      ,   help="The output directory where the model predictions and checkpoints will be written."      ,   )
	parser.add_argument("--train_dataset"      ,   type=_snake_case      ,   default=""   )
	parser.add_argument("--eval_dataset"      ,   type=_snake_case      ,   default=""   )
	parser.add_argument("--seed"      ,   type=_snake_case      ,   default=42   )
	parser.add_argument("--num_train_epochs"      ,   type=_snake_case      ,   default=3   )
	parser.add_argument("--train_batch_size"      ,   type=_snake_case      ,   default=8   )
	parser.add_argument("--eval_batch_size"      ,   type=_snake_case      ,   default=16   )
	parser.add_argument("--adam_epsilon"      ,   default=1E-8      ,   type=_snake_case      ,   help="Epsilon for Adam optimizer."   )
	parser.add_argument("--max_grad_norm"      ,   type=_snake_case      ,   default=1   )
	parser.add_argument(
	    "--max_steps"      ,   default=-1      ,   type=_snake_case      ,   help=(
	        "If > 0: set total number of training                         steps to perform. Override num_train_epochs."
	    )      ,   )
	parser.add_argument(
	    "--gradient_accumulation_steps"      ,   type=_snake_case      ,   default=1      ,   help="Number of updates steps to accumulate before                        performing a backward/update pass."      ,   )
	parser.add_argument("--learning_rate"      ,   type=_snake_case      ,   default=6.25E-5   )
	parser.add_argument("--warmup_steps"      ,   default=0      ,   type=_snake_case      ,   help="Linear warmup over warmup_steps."   )
	parser.add_argument("--lr_schedule"      ,   type=_snake_case      ,   default="warmup_linear"   )
	parser.add_argument("--weight_decay"      ,   type=_snake_case      ,   default=0.01   )
	parser.add_argument("--lm_coef"      ,   type=_snake_case      ,   default=0.9   )
	parser.add_argument("--n_valid"      ,   type=_snake_case      ,   default=374   )

	parser.add_argument("--server_ip"      ,   type=_snake_case      ,   default=""      ,   help="Can be used for distant debugging."   )
	parser.add_argument("--server_port"      ,   type=_snake_case      ,   default=""      ,   help="Can be used for distant debugging."   )
	__magic_name__		:		List[Any]	   =     parser.parse_args()
	print(_snake_case   )

	if args.server_ip and args.server_port:
		# Distant debugging - see https://code.visualstudio.com/docs/python/debugging#_attach-to-a-local-script
		import ptvsd

		print("Waiting for debugger attach"   )
		ptvsd.enable_attach(address=(args.server_ip, args.server_port)      ,   redirect_output=_snake_case   )
		ptvsd.wait_for_attach()

	random.seed(args.seed   )
	np.random.seed(args.seed   )
	torch.manual_seed(args.seed   )
	torch.cuda.manual_seed_all(args.seed   )

	__magic_name__		:		Dict	   =     torch.device("cuda" if torch.cuda.is_available() else "cpu"   )
	__magic_name__		:		Optional[int]	   =     torch.cuda.device_count()
	logger.info("device: {}, n_gpu {}".format(_snake_case      ,   _snake_case   )   )

	if not args.do_train and not args.do_eval:
		raise ValueError("At least one of `do_train` or `do_eval` must be True."   )

	if not os.path.exists(args.output_dir   ):
		os.makedirs(args.output_dir   )

	# Load tokenizer and model
	# This loading functions also add new tokens and embeddings called `special tokens`
	# These new embeddings will be fine-tuned on the RocStories dataset
	__magic_name__		:		List[Any]	   =     ["_start_", "_delimiter_", "_classify_"]
	__magic_name__		:		Optional[int]	   =     OpenAIGPTTokenizer.from_pretrained(args.model_name   )
	tokenizer.add_tokens(_snake_case   )
	__magic_name__		:		Optional[Any]	   =     tokenizer.convert_tokens_to_ids(_snake_case   )
	__magic_name__		:		List[str]	   =     OpenAIGPTDoubleHeadsModel.from_pretrained(args.model_name   )
	model.resize_token_embeddings(len(_snake_case   )   )
	model.to(_snake_case   )

	# Load and encode the datasets
	def tokenize_and_encode(_snake_case      :  str   ):
		if isinstance(_snake_case      ,   _snake_case   ):
			return tokenizer.convert_tokens_to_ids(tokenizer.tokenize(_snake_case   )   )
		elif isinstance(_snake_case      ,   _snake_case   ):
			return obj
		return [tokenize_and_encode(_snake_case   ) for o in obj]

	logger.info("Encoding dataset..."   )
	__magic_name__		:		Optional[int]	   =     load_rocstories_dataset(args.train_dataset   )
	__magic_name__		:		str	   =     load_rocstories_dataset(args.eval_dataset   )
	__magic_name__		:		int	   =     (train_dataset, eval_dataset)
	__magic_name__		:		List[str]	   =     tokenize_and_encode(_snake_case   )

	# Compute the max input length for the Transformer
	__magic_name__		:		Optional[Any]	   =     model.config.n_positions // 2 - 2
	__magic_name__		:		Optional[int]	   =     max(
	    len(story[:max_length]   ) + max(len(conta[:max_length]   )      ,   len(conta[:max_length]   )   ) + 3
	    for dataset in encoded_datasets
	    for story, conta, conta, _ in dataset   )
	__magic_name__		:		List[str]	   =     min(_snake_case      ,   model.config.n_positions   )  # Max size of input for the pre-trained model

	# Prepare inputs tensors and dataloaders
	__magic_name__		:		List[Any]	   =     pre_process_datasets(_snake_case      ,   _snake_case      ,   _snake_case      ,   *_snake_case   )
	__magic_name__   ,    __magic_name__		:		Optional[int]	   =     tensor_datasets[0], tensor_datasets[1]

	__magic_name__		:		Tuple	   =     TensorDataset(*_snake_case   )
	__magic_name__		:		Union[str, Any]	   =     RandomSampler(_snake_case   )
	__magic_name__		:		Dict	   =     DataLoader(_snake_case      ,   sampler=_snake_case      ,   batch_size=args.train_batch_size   )

	__magic_name__		:		Any	   =     TensorDataset(*_snake_case   )
	__magic_name__		:		Optional[Any]	   =     SequentialSampler(_snake_case   )
	__magic_name__		:		int	   =     DataLoader(_snake_case      ,   sampler=_snake_case      ,   batch_size=args.eval_batch_size   )

	# Prepare optimizer
	if args.do_train:
		if args.max_steps > 0:
			__magic_name__		:		Tuple	   =     args.max_steps
			__magic_name__		:		List[str]	   =     args.max_steps // (len(_snake_case   ) // args.gradient_accumulation_steps) + 1
		else:
			__magic_name__		:		List[str]	   =     len(_snake_case   ) // args.gradient_accumulation_steps * args.num_train_epochs

		__magic_name__		:		str	   =     list(model.named_parameters()   )
		__magic_name__		:		Dict	   =     ["bias", "LayerNorm.bias", "LayerNorm.weight"]
		__magic_name__		:		str	   =     [
		    {
		        "params": [p for n, p in param_optimizer if not any(nd in n for nd in no_decay   )],
		        "weight_decay": args.weight_decay,
		    },
		    {"params": [p for n, p in param_optimizer if any(nd in n for nd in no_decay   )], "weight_decay": 0.0},
		]
		__magic_name__		:		str	   =     AdamW(_snake_case      ,   lr=args.learning_rate      ,   eps=args.adam_epsilon   )
		__magic_name__		:		List[str]	   =     get_linear_schedule_with_warmup(
		    _snake_case      ,   num_warmup_steps=args.warmup_steps      ,   num_training_steps=_snake_case   )

	if args.do_train:
		__magic_name__   ,    __magic_name__   ,    __magic_name__		:		Union[str, Any]	   =     0, 0, None
		model.train()
		for _ in trange(int(args.num_train_epochs   )      ,   desc="Epoch"   ):
			__magic_name__		:		List[str]	   =     0
			__magic_name__		:		Tuple	   =     0
			__magic_name__		:		Dict	   =     tqdm(_snake_case      ,   desc="Training"   )
			for step, batch in enumerate(_snake_case   ):
				__magic_name__		:		Optional[Any]	   =     tuple(t.to(_snake_case   ) for t in batch   )
				__magic_name__   ,    __magic_name__   ,    __magic_name__   ,    __magic_name__		:		Dict	   =     batch
				__magic_name__		:		Optional[Any]	   =     model(_snake_case      ,   mc_token_ids=_snake_case      ,   lm_labels=_snake_case      ,   mc_labels=_snake_case   )
				__magic_name__		:		Optional[Any]	   =     args.lm_coef * losses[0] + losses[1]
				loss.backward()
				optimizer.step()
				scheduler.step()
				optimizer.zero_grad()
				tr_loss += loss.item()
				__magic_name__		:		List[str]	   =     (
				    loss.item() if exp_average_loss is None else 0.7 * exp_average_loss + 0.3 * loss.item()
				)
				nb_tr_steps += 1
				__magic_name__		:		int	   =     "Training loss: {:.2e} lr: {:.2e}".format(_snake_case      ,   scheduler.get_lr()[0]   )

    # Save a trained model
	if args.do_train:
		# Save a trained model, configuration and tokenizer
		__magic_name__		:		Dict	   =     model.module if hasattr(_snake_case      ,   "module"   ) else model  # Only save the model itself

		# If we save using the predefined names, we can load using `from_pretrained`
		__magic_name__		:		List[Any]	   =     os.path.join(args.output_dir      ,   _snake_case   )
		__magic_name__		:		Dict	   =     os.path.join(args.output_dir      ,   _snake_case   )

		torch.save(model_to_save.state_dict()      ,   _snake_case   )
		model_to_save.config.to_json_file(_snake_case   )
		tokenizer.save_vocabulary(args.output_dir   )

		# Load a trained model and vocabulary that you have fine-tuned
		__magic_name__		:		Dict	   =     OpenAIGPTDoubleHeadsModel.from_pretrained(args.output_dir   )
		__magic_name__		:		Optional[int]	   =     OpenAIGPTTokenizer.from_pretrained(args.output_dir   )
		model.to(_snake_case   )

	if args.do_eval:
		model.eval()
		__magic_name__   ,    __magic_name__		:		Any	   =     0, 0
		__magic_name__   ,    __magic_name__		:		Union[str, Any]	   =     0, 0
		for batch in tqdm(_snake_case      ,   desc="Evaluating"   ):
			__magic_name__		:		int	   =     tuple(t.to(_snake_case   ) for t in batch   )
			__magic_name__   ,    __magic_name__   ,    __magic_name__   ,    __magic_name__		:		Union[str, Any]	   =     batch
			with torch.no_grad():
				__magic_name__   ,    __magic_name__   ,    __magic_name__   ,    __magic_name__		:		Dict	   =     model(
				    _snake_case      ,   mc_token_ids=_snake_case      ,   lm_labels=_snake_case      ,   mc_labels=_snake_case   )

			__magic_name__		:		Tuple	   =     mc_logits.detach().cpu().numpy()
			__magic_name__		:		Any	   =     mc_labels.to("cpu"   ).numpy()
			__magic_name__		:		str	   =     accuracy(_snake_case      ,   _snake_case   )

			eval_loss += mc_loss.mean().item()
			eval_accuracy += tmp_eval_accuracy

			nb_eval_examples += input_ids.size(0   )
			nb_eval_steps += 1

		__magic_name__		:		Tuple	   =     eval_loss / nb_eval_steps
		__magic_name__		:		List[Any]	   =     eval_accuracy / nb_eval_examples
		__magic_name__		:		int	   =     tr_loss / nb_tr_steps if args.do_train else None
		__magic_name__		:		Any	   =     {"eval_loss": eval_loss, "eval_accuracy": eval_accuracy, "train_loss": train_loss}

		__magic_name__		:		int	   =     os.path.join(args.output_dir      ,   "eval_results.txt"   )
		with open(_snake_case      ,   "w"   ) as writer:
			logger.info("***** Eval results *****"   )
			for key in sorted(result.keys()   ):
				logger.info("  %s = %s"      ,   _snake_case      ,   str(result[key]   )   )
				writer.write("%s = %s\n" % (key, str(result[key]   ))   )


if __name__ == "__main__":
				main()
