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 			lowerCamelCase_  (     UpperCAmelCase_				):






    '''simple docstring'''






    def __init__(			self				,				*__lowercase				,				__lowercase=None				,				__lowercase=None				,				**__lowercase) ->			int:
        super().__init__(*__lowercase				,				**__lowercase)
        __UpperCamelCase  :Tuple    						=	eval_examples
        __UpperCamelCase  :Optional[Any]    						=	post_process_function







    def     UpperCamelCase__     (			self				,				__lowercase=None				,				__lowercase=None				,				__lowercase=None				,				__lowercase = "eval") ->			Optional[Any]:
        __UpperCamelCase  :str    						=	self.eval_dataset if eval_dataset is None else eval_dataset
        __UpperCamelCase  :Tuple    						=	self.get_eval_dataloader(__lowercase)
        __UpperCamelCase  :Tuple    						=	self.eval_examples if eval_examples is None else eval_examples

        # Temporarily disable metric computation, we will do it in the loop here.
        __UpperCamelCase  :Dict    						=	self.compute_metrics
        __UpperCamelCase  :int    						=	None
        __UpperCamelCase  :List[Any]    						=	self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
        __UpperCamelCase  :Any    						=	time.time()
        try:
            __UpperCamelCase  :Tuple    						=	eval_loop(
                __lowercase				,				description='''Evaluation'''				,				prediction_loss_only=True if compute_metrics is None else None				,				ignore_keys=__lowercase				,				metric_key_prefix=__lowercase				,				)
        finally:
            __UpperCamelCase  :List[str]    						=	compute_metrics
        __UpperCamelCase  :int    						=	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(
                __lowercase				,				__lowercase				,				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
            __UpperCamelCase  :Optional[int]    						=	self.post_process_function(__lowercase				,				__lowercase				,				output.predictions)
            __UpperCamelCase  :List[str]    						=	self.compute_metrics(__lowercase)

            # Prefix all keys with metric_key_prefix + '_'
            for key in list(metrics.keys()):
                if not key.startswith(f"""{metric_key_prefix}_"""):
                    __UpperCamelCase  :List[str]    						=	metrics.pop(__lowercase)
            metrics.update(output.metrics)
        else:
            __UpperCamelCase  :Optional[Any]    						=	output.metrics

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

        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())

        __UpperCamelCase  :Optional[int]    						=	self.callback_handler.on_evaluate(self.args				,				self.state				,				self.control				,				__lowercase)
        return metrics







    def     UpperCamelCase__     (			self				,				__lowercase				,				__lowercase				,				__lowercase=None				,				__lowercase = "test") ->			Dict:
        __UpperCamelCase  :Tuple    						=	self.get_test_dataloader(__lowercase)

        # Temporarily disable metric computation, we will do it in the loop here.
        __UpperCamelCase  :Optional[Any]    						=	self.compute_metrics
        __UpperCamelCase  :List[Any]    						=	None
        __UpperCamelCase  :List[Any]    						=	self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
        __UpperCamelCase  :str    						=	time.time()
        try:
            __UpperCamelCase  :Dict    						=	eval_loop(
                __lowercase				,				description='''Prediction'''				,				prediction_loss_only=True if compute_metrics is None else None				,				ignore_keys=__lowercase				,				metric_key_prefix=__lowercase				,				)
        finally:
            __UpperCamelCase  :Any    						=	compute_metrics
        __UpperCamelCase  :str    						=	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(
                __lowercase				,				__lowercase				,				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

        __UpperCamelCase  :Any    						=	self.post_process_function(__lowercase				,				__lowercase				,				output.predictions				,				'''predict''')
        __UpperCamelCase  :Union[str, Any]    						=	self.compute_metrics(__lowercase)

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






def lowerCamelCase						(     SCREAMING_SNAKE_CASE						,    SCREAMING_SNAKE_CASE			):
    '''simple docstring'''







    return 1 if input_a == input_a else 0



def lowerCamelCase						(     ):
    '''simple docstring'''







    assert xnor_gate(0						,    0			) == 1
    assert xnor_gate(0						,    1			) == 0
    assert xnor_gate(1						,    0			) == 0
    assert xnor_gate(1						,    1			) == 1


if __name__ == "__main__":
    print(xnor_gate(0, 0))
    print(xnor_gate(0, 1))
    print(xnor_gate(1, 0))
    print(xnor_gate(1, 1))





