





import math
import time
from typing import Dict, List, Optional

from torch.utils.data import Dataset

from transformers import SeqaSeqTrainer, 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__):







      def __init__(   self		,				*lowerCAmelCase__		,				lowerCAmelCase__=None		,				lowerCAmelCase__=None		,				**lowerCAmelCase__							)       ->						str:



        '''simple docstring'''




        super().__init__(*lowerCAmelCase__		,				**lowerCAmelCase__							)
        a__     : str  =eval_examples
        a__     : List[str]  =post_process_function







      def        _lowercase  (   self		,				lowerCAmelCase__ = None		,				lowerCAmelCase__=None		,				lowerCAmelCase__ = None		,				lowerCAmelCase__ = "eval"		,				**lowerCAmelCase__		,				)       ->						Dict[str, float]:



        '''simple docstring'''




        a__     : List[str]  =gen_kwargs.copy()
        a__     : int  =(
            gen_kwargs["max_length"] if gen_kwargs.get("max_length"							) is not None else self.args.generation_max_length
        )
        a__     : str  =(
            gen_kwargs["num_beams"] if gen_kwargs.get("num_beams"							) is not None else self.args.generation_num_beams
        )
        a__     : Optional[int]  =gen_kwargs

        a__     : int  =self.eval_dataset if eval_dataset is None else eval_dataset
        a__     : Any  =self.get_eval_dataloader(lowerCAmelCase__							)
        a__     : Optional[Any]  =self.eval_examples if eval_examples is None else eval_examples

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

          # Prefix all keys with metric_key_prefix + '_'
          for key in list(metrics.keys()							):
            if not key.startswith(F'''{metric_key_prefix}_'''							):
              a__     : Optional[int]  =metrics.pop(lowerCAmelCase__							)

          metrics.update(output.metrics							)
        else:
          a__     : str  =output.metrics

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

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

        a__     : int  =self.callback_handler.on_evaluate(self.args		,				self.state		,				self.control		,				lowerCAmelCase__							)
        return metrics







      def        _lowercase  (   self		,				lowerCAmelCase__		,				lowerCAmelCase__		,				lowerCAmelCase__=None		,				lowerCAmelCase__ = "test"		,				**lowerCAmelCase__							)       ->						Optional[int]:



        '''simple docstring'''




        a__     : int  =gen_kwargs.copy()

        a__     : Tuple  =self.get_test_dataloader(lowerCAmelCase__							)

        # Temporarily disable metric computation, we will do it in the loop here.
        a__     : str  =self.compute_metrics
        a__     : List[Any]  =None
        a__     : int  =time.time()
        a__     : int  =self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
        try:
          a__     : List[str]  =eval_loop(
              lowerCAmelCase__		,				description="Prediction"		,				prediction_loss_only=True if compute_metrics is None else None		,				ignore_keys=lowerCAmelCase__		,				metric_key_prefix=lowerCAmelCase__		,				)
        finally:
          a__     : Union[str, Any]  =compute_metrics

        a__     : Dict  =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(
                lowerCAmelCase__		,				lowerCAmelCase__		,				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

        a__     : List[str]  =self.post_process_function(lowerCAmelCase__		,				lowerCAmelCase__		,				lowerCAmelCase__		,				"predict"							)
        a__     : str  =self.compute_metrics(lowerCAmelCase__							)

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













import os
def 					_A	(		):





  """simple docstring"""



  a__     : Optional[int]  =os.path.join(os.path.dirname(SCREAMING_SNAKE_CASE						)	,	"num.txt"						)
  with open(SCREAMING_SNAKE_CASE						) as file_hand:
    return str(sum(int(SCREAMING_SNAKE_CASE						) for line in file_hand						)						)[:10]


if __name__ == "__main__":
     print(solution())






