


"""simple docstring"""
import math
import time

from transformers import Trainer, is_torch_tpu_available
from transformers.trainer_utils import PredictionOutput, speed_metrics


if is_torch_tpu_available(check_device=False):
				import torch_xla.core.xla_model as xm
				import torch_xla.debug.metrics as met





class        __A       (lowerCAmelCase__):





							'''simple docstring'''

							def __init__(			self							: List[Any]						,    *UpperCAmelCase_							: int						,    UpperCAmelCase_							: Dict=None						,    UpperCAmelCase_							: List[Any]=None						,    **UpperCAmelCase_							: Any    )   ->Dict:



														"""simple docstring"""



														super().__init__(*_SCREAMING_SNAKE_CASE						,    **_SCREAMING_SNAKE_CASE    )
														snake_case_          =						eval_examples
														snake_case_          =						post_process_function



							def 						lowerCAmelCase    (			self							: Optional[int]						,    UpperCAmelCase_							: int=None						,    UpperCAmelCase_							: Any=None						,    UpperCAmelCase_							: Dict=None						,    UpperCAmelCase_							: List[Any] = "eval"    )   ->Optional[Any]:



														"""simple docstring"""



														snake_case_          =						self.eval_dataset if eval_dataset is None else eval_dataset
														snake_case_          =						self.get_eval_dataloader(_SCREAMING_SNAKE_CASE    )
														snake_case_          =						self.eval_examples if eval_examples is None else eval_examples

														# Temporarily disable metric computation, we will do it in the loop here.
														snake_case_          =						self.compute_metrics
														snake_case_          =						None
														snake_case_          =						self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
														snake_case_          =						time.time()
														try:
																					snake_case_          =						eval_loop(
																					    _SCREAMING_SNAKE_CASE						,    description="""Evaluation"""						,    prediction_loss_only=True if compute_metrics is None else None						,    ignore_keys=_SCREAMING_SNAKE_CASE						,    metric_key_prefix=_SCREAMING_SNAKE_CASE						,    )
														finally:
																					snake_case_          =						compute_metrics
														snake_case_          =						self.args.eval_batch_size * self.args.world_size
														if F"""{metric_key_prefix}_jit_compilation_time""" in output.metrics:
																					start_time += output.metrics[F"""{metric_key_prefix}_jit_compilation_time"""]
														output.metrics.update(
														    speed_metrics(
														        _SCREAMING_SNAKE_CASE						,    _SCREAMING_SNAKE_CASE						,    num_samples=output.num_samples						,    num_steps=math.ceil(output.num_samples / total_batch_size    )						,    )    )
														if self.post_process_function is not None and self.compute_metrics is not None and self.args.should_save:
																					# Only the main node write the results by default
																					snake_case_          =						self.post_process_function(_SCREAMING_SNAKE_CASE						,    _SCREAMING_SNAKE_CASE						,    output.predictions    )
																					snake_case_          =						self.compute_metrics(_SCREAMING_SNAKE_CASE    )

																					# Prefix all keys with metric_key_prefix + '_'
																					for key in list(metrics.keys()    ):
																												if not key.startswith(F"""{metric_key_prefix}_"""    ):
																																			snake_case_          =						metrics.pop(_SCREAMING_SNAKE_CASE    )
																					metrics.update(output.metrics    )
														else:
																					snake_case_          =						output.metrics

														if self.args.should_log:
																					# Only the main node log the results by default
																					self.log(_SCREAMING_SNAKE_CASE    )

														if self.args.tpu_metrics_debug or self.args.debug:
																					# tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
																					xm.master_print(met.metrics_report()    )

														snake_case_          =						self.callback_handler.on_evaluate(self.args						,    self.state						,    self.control						,    _SCREAMING_SNAKE_CASE    )
														return metrics



							def 						lowerCAmelCase    (			self							: List[str]						,    UpperCAmelCase_							: Optional[int]						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Union[str, Any]=None						,    UpperCAmelCase_							: Tuple = "test"    )   ->Union[str, Any]:



														"""simple docstring"""



														snake_case_          =						self.get_test_dataloader(_SCREAMING_SNAKE_CASE    )

														# Temporarily disable metric computation, we will do it in the loop here.
														snake_case_          =						self.compute_metrics
														snake_case_          =						None
														snake_case_          =						self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
														snake_case_          =						time.time()
														try:
																					snake_case_          =						eval_loop(
																					    _SCREAMING_SNAKE_CASE						,    description="""Prediction"""						,    prediction_loss_only=True if compute_metrics is None else None						,    ignore_keys=_SCREAMING_SNAKE_CASE						,    metric_key_prefix=_SCREAMING_SNAKE_CASE						,    )
														finally:
																					snake_case_          =						compute_metrics
														snake_case_          =						self.args.eval_batch_size * self.args.world_size
														if F"""{metric_key_prefix}_jit_compilation_time""" in output.metrics:
																					start_time += output.metrics[F"""{metric_key_prefix}_jit_compilation_time"""]
														output.metrics.update(
														    speed_metrics(
														        _SCREAMING_SNAKE_CASE						,    _SCREAMING_SNAKE_CASE						,    num_samples=output.num_samples						,    num_steps=math.ceil(output.num_samples / total_batch_size    )						,    )    )

														if self.post_process_function is None or self.compute_metrics is None:
																					return output

														snake_case_          =						self.post_process_function(_SCREAMING_SNAKE_CASE						,    _SCREAMING_SNAKE_CASE						,    output.predictions						,    """predict"""    )
														snake_case_          =						self.compute_metrics(_SCREAMING_SNAKE_CASE    )

														# Prefix all keys with metric_key_prefix + '_'
														for key in list(metrics.keys()    ):
																					if not key.startswith(F"""{metric_key_prefix}_"""    ):
																												snake_case_          =						metrics.pop(_SCREAMING_SNAKE_CASE    )
														metrics.update(output.metrics    )
														return PredictionOutput(predictions=predictions.predictions						,    label_ids=predictions.label_ids						,    metrics=_SCREAMING_SNAKE_CASE    )







"""simple docstring"""
def   _a			( _SCREAMING_SNAKE_CASE			)      ->			int:
							assert column_title.isupper()
							snake_case_          =						0
							snake_case_          =						len(_SCREAMING_SNAKE_CASE			) - 1
							snake_case_          =						0

							while index >= 0:
														snake_case_          =						(ord(column_title[index]			) - 64) * pow(26			,	_SCREAMING_SNAKE_CASE			)
														answer += value
														power += 1
														index -= 1

							return answer


if __name__ == "__main__":
				from doctest import testmod

				testmod()



